From 0fd8602b505a68a66f07a010d5db4ac76bd927fb Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Tue, 21 Nov 2023 18:00:51 +0000 Subject: [PATCH] nexus/analyzer: remove unnecessary lazy_static Use of Vec can be replaced with slices in QREP_OPTIONS, making it const --- nexus/Cargo.lock | 1 - nexus/analyzer/Cargo.toml | 1 - nexus/analyzer/src/qrep.rs | 155 ++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 81 deletions(-) diff --git a/nexus/Cargo.lock b/nexus/Cargo.lock index 7adbe09214..21d09f0d08 100644 --- a/nexus/Cargo.lock +++ b/nexus/Cargo.lock @@ -56,7 +56,6 @@ dependencies = [ "async-trait", "catalog", "flow-rs", - "lazy_static", "pem 3.0.2", "pt", "serde_json", diff --git a/nexus/analyzer/Cargo.toml b/nexus/analyzer/Cargo.toml index f4f00fa7f1..4db5cb4646 100644 --- a/nexus/analyzer/Cargo.toml +++ b/nexus/analyzer/Cargo.toml @@ -10,7 +10,6 @@ anyhow = "1.0" async-trait = "0.1" catalog = { path = "../catalog" } flow-rs = { path = "../flow-rs" } -lazy_static = "1.4" pem = "3.0" pt = { path = "../pt" } sqlparser = { path = "../sqlparser-rs", features = ["visitor"] } diff --git a/nexus/analyzer/src/qrep.rs b/nexus/analyzer/src/qrep.rs index 8445247da9..88af3da66b 100644 --- a/nexus/analyzer/src/qrep.rs +++ b/nexus/analyzer/src/qrep.rs @@ -8,7 +8,7 @@ enum QRepOptionType { name: &'static str, default_val: Option<&'static str>, required: bool, - accepted_values: Option>, + accepted_values: Option<&'static [&'static str]>, }, Int { name: &'static str, @@ -26,90 +26,87 @@ enum QRepOptionType { }, } -lazy_static::lazy_static! { - static ref QREP_OPTIONS: Vec = { - vec![ - QRepOptionType::String { - name: "destination_table_name", - default_val: None, - required: true, - accepted_values: None, - }, - QRepOptionType::String { - name: "watermark_column", - default_val: None, - required: false, - accepted_values: None, - }, - QRepOptionType::String { - name: "watermark_table_name", - default_val: None, - required: false, - accepted_values: None, - }, - QRepOptionType::String { - name: "mode", - default_val: Some("append"), - required: false, - accepted_values: Some(vec!["upsert", "append", "overwrite"]), - }, - QRepOptionType::StringArray { - name: "unique_key_columns", - }, - QRepOptionType::String { - name: "sync_data_format", - default_val: Some("default"), - required: false, - accepted_values: Some(vec!["default", "avro"]), - }, - QRepOptionType::String { - name: "staging_path", - default_val: None, - required: false, - accepted_values: None, - }, - QRepOptionType::Int { - name: "parallelism", - min_value: Some(1), - default_value: 2, - required: false, - }, - QRepOptionType::Int { - name: "refresh_interval", - min_value: Some(10), - default_value: 10, - required: false, - }, - QRepOptionType::Int { - name: "num_rows_per_partition", - min_value: Some(1), - default_value: 50000, - required: true, - }, - QRepOptionType::Boolean { - name: "initial_copy_only", - default_value: false, - required: false, - }, - QRepOptionType::Boolean { - name: "setup_watermark_table_on_destination", - default_value: false, - required: false - }, - QRepOptionType::Boolean { - name: "dst_table_full_resync", - default_value: false, - required: false - }] - }; -} +const QREP_OPTIONS: &[QRepOptionType] = &[ + QRepOptionType::String { + name: "destination_table_name", + default_val: None, + required: true, + accepted_values: None, + }, + QRepOptionType::String { + name: "watermark_column", + default_val: None, + required: false, + accepted_values: None, + }, + QRepOptionType::String { + name: "watermark_table_name", + default_val: None, + required: false, + accepted_values: None, + }, + QRepOptionType::String { + name: "mode", + default_val: Some("append"), + required: false, + accepted_values: Some(&["upsert", "append", "overwrite"]), + }, + QRepOptionType::StringArray { + name: "unique_key_columns", + }, + QRepOptionType::String { + name: "sync_data_format", + default_val: Some("default"), + required: false, + accepted_values: Some(&["default", "avro"]), + }, + QRepOptionType::String { + name: "staging_path", + default_val: None, + required: false, + accepted_values: None, + }, + QRepOptionType::Int { + name: "parallelism", + min_value: Some(1), + default_value: 2, + required: false, + }, + QRepOptionType::Int { + name: "refresh_interval", + min_value: Some(10), + default_value: 10, + required: false, + }, + QRepOptionType::Int { + name: "num_rows_per_partition", + min_value: Some(1), + default_value: 50000, + required: true, + }, + QRepOptionType::Boolean { + name: "initial_copy_only", + default_value: false, + required: false, + }, + QRepOptionType::Boolean { + name: "setup_watermark_table_on_destination", + default_value: false, + required: false + }, + QRepOptionType::Boolean { + name: "dst_table_full_resync", + default_value: false, + required: false + } +]; pub fn process_options( mut raw_opts: HashMap<&str, &SqlValue>, ) -> anyhow::Result> { let mut opts: HashMap = HashMap::new(); - for opt_type in &*QREP_OPTIONS { + for opt_type in QREP_OPTIONS { match opt_type { QRepOptionType::String { name,