From 51e2b6e728de398714f64ca2c6d90aee78c3b45c Mon Sep 17 00:00:00 2001 From: Kelvin Wu Date: Tue, 4 Jun 2024 16:10:44 +0800 Subject: [PATCH] fix: display the PartitionBound and PartitionDef correctly (#4101) * fix: display the PartitionBound and PartitionDef correctly * Update src/partition/src/partition.rs Co-authored-by: dennis zhuang * fix: fix unit test of partition definition --------- Co-authored-by: dennis zhuang --- src/partition/src/partition.rs | 7 +++--- .../cases/standalone/common/partition.result | 24 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/partition/src/partition.rs b/src/partition/src/partition.rs index 6735ccf6d9f1..28cda6a817b4 100644 --- a/src/partition/src/partition.rs +++ b/src/partition/src/partition.rs @@ -63,7 +63,7 @@ impl Display for PartitionBound { match self { Self::Value(v) => write!(f, "{}", v), Self::MaxValue => write!(f, "MAXVALUE"), - Self::Expr(e) => write!(f, "{:?}", e), + Self::Expr(e) => write!(f, "{}", e), } } } @@ -72,8 +72,7 @@ impl Display for PartitionDef { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, - "({}) VALUES LESS THAN ({})", - self.partition_columns.iter().join(", "), + "{}", self.partition_bounds .iter() .map(|b| format!("{b}")) @@ -188,7 +187,7 @@ mod tests { PartitionBound::Value(1_i32.into()), ], }; - assert_eq!("(a, b) VALUES LESS THAN (MAXVALUE, 1)", def.to_string()); + assert_eq!("MAXVALUE, 1", def.to_string()); let partition: MetaPartition = def.try_into().unwrap(); assert_eq!( diff --git a/tests/cases/standalone/common/partition.result b/tests/cases/standalone/common/partition.result index 9c76a87df100..53b30056b879 100644 --- a/tests/cases/standalone/common/partition.result +++ b/tests/cases/standalone/common/partition.result @@ -14,13 +14,13 @@ Affected Rows: 0 -- SQLNESS REPLACE (\d{13}) ID SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name; -+---------------+--------------+------------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+ -| table_catalog | table_schema | table_name | partition_name | partition_expression | greptime_partition_id | -+---------------+--------------+------------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+ -| greptime | public | my_table | p0 | (a) VALUES LESS THAN (PartitionExpr { lhs: Column("a"), op: Lt, rhs: Value(Int32(1000)) }) | ID | -| greptime | public | my_table | p1 | (a) VALUES LESS THAN (PartitionExpr { lhs: Column("a"), op: GtEq, rhs: Value(Int32(2000)) }) | ID | -| greptime | public | my_table | p2 | (a) VALUES LESS THAN (PartitionExpr { lhs: Expr(PartitionExpr { lhs: Column("a"), op: GtEq, rhs: Value(Int32(1000)) }), op: And, rhs: Expr(PartitionExpr { lhs: Column("a"), op: Lt, rhs: Value(Int32(2000)) }) }) | ID | -+---------------+--------------+------------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+ ++---------------+--------------+------------+----------------+------------------------+-----------------------+ +| table_catalog | table_schema | table_name | partition_name | partition_expression | greptime_partition_id | ++---------------+--------------+------------+----------------+------------------------+-----------------------+ +| greptime | public | my_table | p0 | a < 1000 | ID | +| greptime | public | my_table | p1 | a >= 2000 | ID | +| greptime | public | my_table | p2 | a >= 1000 AND a < 2000 | ID | ++---------------+--------------+------------+----------------+------------------------+-----------------------+ -- SQLNESS REPLACE (\d{13}) REGION_ID -- SQLNESS REPLACE (\d{1}) PEER_ID @@ -120,11 +120,11 @@ Affected Rows: 0 -- SQLNESS REPLACE (\d{13}) ID SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name; -+---------------+--------------+------------+----------------+---------------------------------+-----------------------+ -| table_catalog | table_schema | table_name | partition_name | partition_expression | greptime_partition_id | -+---------------+--------------+------------+----------------+---------------------------------+-----------------------+ -| greptime | public | my_table | p0 | (a) VALUES LESS THAN (MAXVALUE) | ID | -+---------------+--------------+------------+----------------+---------------------------------+-----------------------+ ++---------------+--------------+------------+----------------+----------------------+-----------------------+ +| table_catalog | table_schema | table_name | partition_name | partition_expression | greptime_partition_id | ++---------------+--------------+------------+----------------+----------------------+-----------------------+ +| greptime | public | my_table | p0 | MAXVALUE | ID | ++---------------+--------------+------------+----------------+----------------------+-----------------------+ -- SQLNESS REPLACE (\d{13}) REGION_ID -- SQLNESS REPLACE (\d{1}) PEER_ID