Skip to content

Commit

Permalink
Refactor enum serialization in CSV, Delta, Iceberg, Json, Parquet, Se…
Browse files Browse the repository at this point in the history
…cret, and Spatial modules (#145)
  • Loading branch information
Weijun-H authored Oct 5, 2024
1 parent b1166df commit e373c70
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 99 deletions.
35 changes: 1 addition & 34 deletions src/duckdb/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,74 +24,41 @@ use crate::fdw::base::OptionValidator;
use super::utils;

#[derive(EnumIter, AsRefStr, PartialEq, Debug)]
#[strum(serialize_all = "snake_case")]
pub enum CsvOption {
#[strum(serialize = "all_varchar")]
AllVarchar,
#[strum(serialize = "allow_quoted_nulls")]
AllowQuotedNulls,
#[strum(serialize = "auto_detect")]
AutoDetect,
#[strum(serialize = "auto_type_candidates")]
AutoTypeCandidates,
#[strum(serialize = "columns")]
Columns,
#[strum(serialize = "compression")]
Compression,
#[strum(serialize = "dateformat")]
Dateformat,
#[strum(serialize = "decimal_separator")]
DecimalSeparator,
#[strum(serialize = "delim")]
Delim,
#[strum(serialize = "escape")]
Escape,
#[strum(serialize = "filename")]
Filename,
#[strum(serialize = "files")]
Files,
#[strum(serialize = "force_not_null")]
ForceNotNull,
#[strum(serialize = "header")]
Header,
#[strum(serialize = "hive_partitioning")]
HivePartitioning,
#[strum(serialize = "hive_types")]
HiveTypes,
#[strum(serialize = "hive_types_autocast")]
HiveTypesAutocast,
#[strum(serialize = "ignore_errors")]
IgnoreErrors,
#[strum(serialize = "max_line_size")]
MaxLineSize,
#[strum(serialize = "names")]
Names,
#[strum(serialize = "new_line")]
NewLine,
#[strum(serialize = "normalize_names")]
NormalizeNames,
#[strum(serialize = "null_padding")]
NullPadding,
#[strum(serialize = "nullstr")]
Nullstr,
#[strum(serialize = "parallel")]
Parallel,
#[strum(serialize = "preserve_casing")]
PreserveCasing,
#[strum(serialize = "quote")]
Quote,
#[strum(serialize = "sample_size")]
SampleSize,
#[strum(serialize = "select")]
Select,
#[strum(serialize = "sep")]
Sep,
#[strum(serialize = "skip")]
Skip,
#[strum(serialize = "timestampformat")]
Timestampformat,
#[strum(serialize = "types")]
Types,
#[strum(serialize = "union_by_name")]
UnionByName,
}

Expand Down
4 changes: 1 addition & 3 deletions src/duckdb/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ use std::collections::HashMap;
use strum::{AsRefStr, EnumIter};

#[derive(EnumIter, AsRefStr, PartialEq, Debug)]
#[strum(serialize_all = "snake_case")]
pub enum DeltaOption {
#[strum(serialize = "files")]
Files,
#[strum(serialize = "preserve_casing")]
PreserveCasing,
#[strum(serialize = "select")]
Select,
}

Expand Down
5 changes: 1 addition & 4 deletions src/duckdb/iceberg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ use strum::{AsRefStr, EnumIter};
use crate::fdw::base::OptionValidator;

#[derive(EnumIter, AsRefStr, PartialEq, Debug)]
#[strum(serialize_all = "snake_case")]
pub enum IcebergOption {
#[strum(serialize = "allow_moved_paths")]
AllowMovedPaths,
#[strum(serialize = "files")]
Files,
#[strum(serialize = "preserve_casing")]
PreserveCasing,
#[strum(serialize = "select")]
Select,
}

Expand Down
18 changes: 1 addition & 17 deletions src/duckdb/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,24 @@ use crate::fdw::base::OptionValidator;
use super::utils;

#[derive(EnumIter, AsRefStr, PartialEq, Debug, Display)]
#[strum(serialize_all = "snake_case")]
pub enum JsonOption {
#[strum(serialize = "auto_detect")]
AutoDetect,
#[strum(serialize = "columns")]
Columns,
#[strum(serialize = "compression")]
Compression,
#[strum(serialize = "convert_strings_to_integers")]
ConvertStringsToIntegers,
#[strum(serialize = "dateformat")]
Dateformat,
#[strum(serialize = "filename")]
Filename,
#[strum(serialize = "files")]
Files,
#[strum(serialize = "format")]
Format,
#[strum(serialize = "hive_partitioning")]
HivePartitioning,
#[strum(serialize = "ignore_errors")]
IgnoreErrors,
#[strum(serialize = "maximum_depth")]
MaximumDepth,
#[strum(serialize = "maximum_object_size")]
MaximumObjectSize,
#[strum(serialize = "records")]
Records,
#[strum(serialize = "sample_size")]
SampleSize,
#[strum(serialize = "select")]
Select,
#[strum(serialize = "timestampformat")]
Timestampformat,
#[strum(serialize = "union_by_name")]
UnionByName,
}

Expand Down
11 changes: 1 addition & 10 deletions src/duckdb/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,17 @@ use crate::fdw::base::OptionValidator;
use super::utils;

#[derive(EnumIter, AsRefStr, PartialEq, Debug)]
#[strum(serialize_all = "snake_case")]
pub enum ParquetOption {
#[strum(serialize = "binary_as_string")]
BinaryAsString,
#[strum(serialize = "filename")]
FileName,
#[strum(serialize = "file_row_number")]
FileRowNumber,
#[strum(serialize = "files")]
Files,
#[strum(serialize = "hive_partitioning")]
HivePartitioning,
#[strum(serialize = "hive_types")]
HiveTypes,
#[strum(serialize = "hive_types_autocast")]
HiveTypesAutocast,
#[strum(serialize = "preserve_casing")]
PreserveCasing,
#[strum(serialize = "union_by_name")]
UnionByName,
#[strum(serialize = "select")]
Select,
// TODO: EncryptionConfig
}
Expand Down
23 changes: 1 addition & 22 deletions src/duckdb/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,32 @@ use strum::{AsRefStr, EnumIter};
use crate::fdw::base::OptionValidator;

#[derive(EnumIter, AsRefStr, PartialEq, Debug)]
#[strum(serialize_all = "snake_case")]
pub enum UserMappingOptions {
// Universal
#[strum(serialize = "type")]
Type,
#[strum(serialize = "provider")]
Provider,
#[strum(serialize = "scope")]
Scope,
#[strum(serialize = "chain")]
Chain,
// S3/GCS/R2
#[strum(serialize = "key_id")]
KeyId,
#[strum(serialize = "secret")]
Secret,
#[strum(serialize = "region")]
Region,
#[strum(serialize = "session_token")]
SessionToken,
#[strum(serialize = "endpoint")]
Endpoint,
#[strum(serialize = "url_style")]
UrlStyle,
#[strum(serialize = "use_ssl")]
UseSsl,
#[strum(serialize = "url_compatibility_mode")]
UrlCompatibilityMode,
#[strum(serialize = "account_id")]
AccountId,
// Azure
#[strum(serialize = "connection_string")]
ConnectionString,
#[strum(serialize = "account_name")]
AccountName,
#[strum(serialize = "tenant_id")]
TenantId,
#[strum(serialize = "client_id")]
ClientId,
#[strum(serialize = "client_secret")]
ClientSecret,
#[strum(serialize = "client_certificate_path")]
ClientCertificatePath,
#[strum(serialize = "http_proxy")]
HttpProxy,
#[strum(serialize = "proxy_user_name")]
ProxyUserName,
#[strum(serialize = "proxy_password")]
ProxyPassword,
}

Expand Down
10 changes: 1 addition & 9 deletions src/duckdb/spatial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,16 @@ use crate::fdw::base::OptionValidator;
/// SpatialOption is an enum that represents the options that can be passed to the st_read function.
/// Reference https://github.com/duckdb/duckdb_spatial/blob/main/docs/functions.md#st_read
#[derive(EnumIter, AsRefStr, PartialEq, Debug)]
#[strum(serialize_all = "snake_case")]
pub enum SpatialOption {
#[strum(serialize = "files")]
Files,
#[strum(serialize = "sequential_layer_scan")]
SequentialLayerScan,
#[strum(serialize = "spatial_filter")]
SpatialFilter,
#[strum(serialize = "open_options")]
OpenOptions,
#[strum(serialize = "layer")]
Layer,
#[strum(serialize = "allowed_drivers")]
AllowedDrivers,
#[strum(serialize = "sibling_files")]
SiblingFiles,
#[strum(serialize = "spatial_filter_box")]
SpatialFilterBox,
#[strum(serialize = "keep_wkb")]
KeepWkb,
}

Expand Down

0 comments on commit e373c70

Please sign in to comment.