Skip to content

Commit

Permalink
convert all remaining enums to use strum
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiaagarwal committed Jun 19, 2024
1 parent 0ac0dea commit 6c2ae78
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 163 deletions.
2 changes: 1 addition & 1 deletion models/src/models/column_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ pub struct ColumnInfo {
/// Whether field may be Null.
pub nullable: bool,
/// Partition index for column.
#[serde(rename = "partition_index", skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none")]
pub partition_index: Option<i32>,
}
2 changes: 1 addition & 1 deletion models/src/models/create_volume_request_content.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CreateVolumeRequestContent {
/// The name of the catalog where the schema and the volume are
pub catalog_name: String,
Expand Down
113 changes: 74 additions & 39 deletions models/src/models/function_info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::models;
use chrono::{serde::ts_milliseconds, DateTime, Utc};
use serde::{Deserialize, Serialize};
use strum::{Display, IntoStaticStr};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct FunctionInfo {
Expand All @@ -10,28 +11,25 @@ pub struct FunctionInfo {
pub catalog_name: String,
/// Name of parent schema relative to its parent catalog.
pub schema_name: String,
#[serde(rename = "input_params", skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none")]
pub input_params: Option<Box<models::FunctionParameterInfos>>,
#[serde(rename = "data_type", skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none")]
pub data_type: Option<models::ColumnTypeName>,
/// Pretty printed function data type.
#[serde(rename = "full_data_type", skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none")]
pub full_data_type: Option<String>,
#[serde(rename = "return_params", skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none")]
pub return_params: Option<Box<models::FunctionParameterInfos>>,
/// Function language. When **EXTERNAL** is used, the language of the routine function should be specified in the __external_language__ field, and the __return_params__ of the function cannot be used (as **TABLE** return type is not supported), and the __sql_data_access__ field must be **NO_SQL**.
#[serde(rename = "routine_body", skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none")]
pub routine_body: Option<RoutineBody>,
/// Function body.
#[serde(rename = "routine_definition", skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none")]
pub routine_definition: Option<String>,
#[serde(
rename = "routine_dependencies",
skip_serializing_if = "Option::is_none"
)]
pub routine_dependencies: Option<Box<models::DependencyList>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub routine_dependencies: Option<models::DependencyList>,
/// Function parameter style. **S** is the value for SQL.
#[serde(rename = "parameter_style", skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none")]
pub parameter_style: Option<ParameterStyle>,
/// Whether the function is deterministic.
pub is_deterministic: bool,
Expand Down Expand Up @@ -69,23 +67,45 @@ pub struct FunctionInfo {
}

/// Function language. When **EXTERNAL** is used, the language of the routine function should be specified in the __external_language__ field, and the __return_params__ of the function cannot be used (as **TABLE** return type is not supported), and the __sql_data_access__ field must be **NO_SQL**.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
IntoStaticStr,
Display,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RoutineBody {
#[serde(rename = "SQL")]
Sql,
#[serde(rename = "EXTERNAL")]
External,
}

impl Default for RoutineBody {
fn default() -> RoutineBody {
Self::Sql
}
}
/// Function parameter style. **S** is the value for SQL.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
IntoStaticStr,
Display,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ParameterStyle {
#[serde(rename = "S")]
S,
}

Expand All @@ -95,30 +115,45 @@ impl Default for ParameterStyle {
}
}
/// Function SQL data access.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
IntoStaticStr,
Display,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SqlDataAccess {
#[serde(rename = "CONTAINS_SQL")]
ContainsSql,
#[serde(rename = "READS_SQL_DATA")]
ReadsSqlData,
#[serde(rename = "NO_SQL")]
NoSql,
}

impl Default for SqlDataAccess {
fn default() -> SqlDataAccess {
Self::ContainsSql
}
}
/// Function security type.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
IntoStaticStr,
Display,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SecurityType {
#[serde(rename = "DEFINER")]
Definer,
}

impl Default for SecurityType {
fn default() -> SecurityType {
Self::Definer
}
}
33 changes: 17 additions & 16 deletions models/src/models/function_parameter_mode.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use crate::models;
use serde::{Deserialize, Serialize};
use strum::{Display, IntoStaticStr};

/// FunctionParameterMode : The mode of the function parameter.
/// The mode of the function parameter.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
IntoStaticStr,
Display,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum FunctionParameterMode {
#[serde(rename = "IN")]
In,
}

impl std::fmt::Display for FunctionParameterMode {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::In => write!(f, "IN"),
}
}
}

impl Default for FunctionParameterMode {
fn default() -> FunctionParameterMode {
Self::In
}
}
35 changes: 17 additions & 18 deletions models/src/models/function_parameter_type.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
use crate::models;
use serde::{Deserialize, Serialize};
use strum::{Display, IntoStaticStr};

/// FunctionParameterType : The type of function parameter.
/// The type of function parameter.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
IntoStaticStr,
Display,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum FunctionParameterType {
#[serde(rename = "PARAM")]
Param,
#[serde(rename = "COLUMN")]
Column,
}

impl std::fmt::Display for FunctionParameterType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Param => write!(f, "PARAM"),
Self::Column => write!(f, "COLUMN"),
}
}
}

impl Default for FunctionParameterType {
fn default() -> FunctionParameterType {
Self::Param
}
}
2 changes: 1 addition & 1 deletion models/src/models/generate_temporary_table_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::models;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GenerateTemporaryTableCredential {
/// Table id for which temporary credentials are generated. Can be obtained from tables/{full_name} (get table info) API.
pub table_id: Uuid,
Expand Down
2 changes: 1 addition & 1 deletion models/src/models/generate_temporary_volume_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::models;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GenerateTemporaryVolumeCredential {
/// Volume id for which temporary credentials are generated. Can be obtained from volumes/{full_name} (get volume info) API.
pub volume_id: Uuid,
Expand Down
37 changes: 17 additions & 20 deletions models/src/models/table_operation.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
use crate::models;
use serde::{Deserialize, Serialize};
use strum::{Display, IntoStaticStr};

#[allow(clippy::empty_docs)]
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
IntoStaticStr,
Display,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TableOperation {
#[serde(rename = "UNKNOWN_TABLE_OPERATION")]
UnknownTableOperation,
#[serde(rename = "READ")]
Read,
#[serde(rename = "READ_WRITE")]
ReadWrite,
}

impl std::fmt::Display for TableOperation {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::UnknownTableOperation => write!(f, "UNKNOWN_TABLE_OPERATION"),
Self::Read => write!(f, "READ"),
Self::ReadWrite => write!(f, "READ_WRITE"),
}
}
}

impl Default for TableOperation {
fn default() -> TableOperation {
Self::UnknownTableOperation
}
}
35 changes: 17 additions & 18 deletions models/src/models/table_type.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
use crate::models;
use serde::{Deserialize, Serialize};
use strum::{Display, IntoStaticStr};

#[allow(clippy::empty_docs)]
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
IntoStaticStr,
Display,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TableType {
#[serde(rename = "MANAGED")]
Managed,
#[serde(rename = "EXTERNAL")]
External,
}

impl std::fmt::Display for TableType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Managed => write!(f, "MANAGED"),
Self::External => write!(f, "EXTERNAL"),
}
}
}

impl Default for TableType {
fn default() -> TableType {
Self::Managed
}
}
9 changes: 0 additions & 9 deletions models/src/models/update_volume_request_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,3 @@ pub struct UpdateVolumeRequestContent {
#[serde(skip_serializing_if = "Option::is_none")]
pub new_name: Option<String>,
}

impl UpdateVolumeRequestContent {
pub fn new() -> UpdateVolumeRequestContent {
UpdateVolumeRequestContent {
comment: None,
new_name: None,
}
}
}
Loading

0 comments on commit 6c2ae78

Please sign in to comment.