From 53312c0d1b59e77e2ebc4cfd0de03887ca9c319a Mon Sep 17 00:00:00 2001 From: nikoshet Date: Wed, 10 Apr 2024 12:16:43 +0300 Subject: [PATCH] Add start_position argument to DiffPayload struct --- examples/example_diff.rs | 5 +++++ rust-pgdatadiff-client/src/main.rs | 10 ++++++++++ src/diff/diff_payload.rs | 8 ++++++++ src/diff/table/table_differ.rs | 2 +- src/diff/table/table_differ_tests.rs | 3 +++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/examples/example_diff.rs b/examples/example_diff.rs index c1dfba5..6221443 100644 --- a/examples/example_diff.rs +++ b/examples/example_diff.rs @@ -38,6 +38,9 @@ enum Commands { /// The chunk size when comparing data #[arg(long, default_value_t = 10000, required = false)] chunk_size: i64, + /// The start position for the comparison + #[arg(long, default_value_t = 0, required = false)] + start_position: i64, /// Max connections for Postgres pool #[arg(long, default_value_t = 100, required = false)] max_connections: i64, @@ -70,6 +73,7 @@ async fn main() -> Result<()> { only_sequences, only_count, chunk_size, + start_position, max_connections, include_tables, exclude_tables, @@ -82,6 +86,7 @@ async fn main() -> Result<()> { *only_sequences, *only_count, *chunk_size, + *start_position, *max_connections, include_tables.to_vec(), exclude_tables.to_vec(), diff --git a/rust-pgdatadiff-client/src/main.rs b/rust-pgdatadiff-client/src/main.rs index 60bcd7c..e6631c4 100644 --- a/rust-pgdatadiff-client/src/main.rs +++ b/rust-pgdatadiff-client/src/main.rs @@ -39,6 +39,9 @@ enum Commands { /// The chunk size when comparing data #[arg(long, default_value_t = 10000, required = false)] chunk_size: i64, + /// The start position for the comparison + #[arg(long, default_value_t = 0, required = false)] + start_position: i64, /// Max connections for Postgres pool #[arg(long, default_value_t = 100, required = false)] max_connections: i64, @@ -69,6 +72,7 @@ async fn main_clap() -> Result<()> { only_sequences, only_count, chunk_size, + start_position, max_connections, include_tables, exclude_tables, @@ -81,6 +85,7 @@ async fn main_clap() -> Result<()> { *only_sequences, *only_count, *chunk_size, + *start_position, *max_connections, include_tables.to_vec(), exclude_tables.to_vec(), @@ -118,6 +123,10 @@ async fn main_inquire() -> Result<()> { .with_default("10000") .with_help_message("Enter the chunk size when comparing data") .prompt()?; + let start_position = Text::new("Start position for the comparison") + .with_default("0") + .with_help_message("Enter the start position for the comparison") + .prompt()?; let max_connections = Text::new("Number of DB connections to utilize") .with_default("100") .with_help_message("Enter the max connections for Postgres pool") @@ -142,6 +151,7 @@ async fn main_inquire() -> Result<()> { only_sequences, only_count, chunk_size.parse::().unwrap(), + start_position.parse::().unwrap(), max_connections.parse::().unwrap(), include_tables .split_whitespace() diff --git a/src/diff/diff_payload.rs b/src/diff/diff_payload.rs index 701d33f..51beef3 100644 --- a/src/diff/diff_payload.rs +++ b/src/diff/diff_payload.rs @@ -6,6 +6,7 @@ pub struct DiffPayload { only_sequences: bool, only_count: bool, chunk_size: i64, + start_position: i64, max_connections: i64, include_tables: Vec, exclude_tables: Vec, @@ -23,6 +24,7 @@ impl DiffPayload { /// * `only_sequences` - A flag indicating whether to compare only sequences. /// * `count_only` - A flag indicating whether to count differences only. /// * `chunk_size` - The chunk size for processing large tables. + /// * `start_position` - The start position for the comparison. /// * `max_connections` - The maximum number of database connections to use. /// * `include_tables` - A list of tables to include in the comparison. /// * `exclude_tables` - A list of tables to exclude in the comparison. @@ -39,6 +41,7 @@ impl DiffPayload { only_sequences: bool, only_count: bool, chunk_size: i64, + start_position: i64, max_connections: i64, include_tables: Vec>, exclude_tables: Vec>, @@ -58,6 +61,7 @@ impl DiffPayload { only_sequences, only_count, chunk_size, + start_position, max_connections, include_tables: include_tables.into_iter().map(|t| t.into()).collect(), exclude_tables: exclude_tables.into_iter().map(|t| t.into()).collect(), @@ -83,6 +87,9 @@ impl DiffPayload { pub fn chunk_size(&self) -> i64 { self.chunk_size } + pub fn start_position(&self) -> i64 { + self.start_position + } pub fn max_connections(&self) -> u32 { self.max_connections as u32 } @@ -111,6 +118,7 @@ mod tests { false, false, 10000, + 0, 10, vec!["table1"], vec!["table2"], diff --git a/src/diff/table/table_differ.rs b/src/diff/table/table_differ.rs index b9ed4b0..6a3b619 100644 --- a/src/diff/table/table_differ.rs +++ b/src/diff/table/table_differ.rs @@ -227,7 +227,7 @@ impl start: Instant, ) -> Option { // Start data comparison - let mut position = 0; + let mut position = diff_payload.start_position(); while position <= total_rows { let input = QueryHashDataInput::new( schema_name.clone(), diff --git a/src/diff/table/table_differ_tests.rs b/src/diff/table/table_differ_tests.rs index 0df1d1d..4556b35 100644 --- a/src/diff/table/table_differ_tests.rs +++ b/src/diff/table/table_differ_tests.rs @@ -30,6 +30,7 @@ mod tests { false, false, 10000, + 0, 10, vec!["table1", "table2"], EMPTY_STRING_VEC, @@ -74,6 +75,7 @@ mod tests { false, false, 10000, + 0, 10, vec!["table1", "table2"], EMPTY_STRING_VEC, @@ -138,6 +140,7 @@ mod tests { false, false, 10000, + 0, 10, vec!["table1", "table2"], EMPTY_STRING_VEC,