Skip to content

Commit

Permalink
fix: display the PartitionBound and PartitionDef correctly (#4101)
Browse files Browse the repository at this point in the history
* fix: display the PartitionBound and PartitionDef correctly

* Update src/partition/src/partition.rs

Co-authored-by: dennis zhuang <[email protected]>

* fix: fix unit test of partition definition

---------

Co-authored-by: dennis zhuang <[email protected]>
  • Loading branch information
Kelvinyu1117 and killme2008 authored Jun 4, 2024
1 parent d1838fb commit 51e2b6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/partition/src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand All @@ -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}"))
Expand Down Expand Up @@ -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!(
Expand Down
24 changes: 12 additions & 12 deletions tests/cases/standalone/common/partition.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 51e2b6e

Please sign in to comment.