diff --git a/src/common/function/src/scalars/math/clamp.rs b/src/common/function/src/scalars/math/clamp.rs index 58a2dcefd4..dc73aed158 100644 --- a/src/common/function/src/scalars/math/clamp.rs +++ b/src/common/function/src/scalars/math/clamp.rs @@ -143,8 +143,6 @@ fn clamp_impl Result { - common_telemetry::info!("[DEBUG] min {min:?}, max {max:?}"); - let iter = ArrayIter::new(input); let result = iter.map(|x| { x.map(|x| { diff --git a/src/common/meta/src/key/datanode_table.rs b/src/common/meta/src/key/datanode_table.rs index c20243bfd7..57ffa6a00c 100644 --- a/src/common/meta/src/key/datanode_table.rs +++ b/src/common/meta/src/key/datanode_table.rs @@ -72,12 +72,8 @@ impl DatanodeTableKey { } } - fn prefix(datanode_id: DatanodeId) -> String { - format!("{}/{datanode_id}", DATANODE_TABLE_KEY_PREFIX) - } - - pub fn range_start_key(datanode_id: DatanodeId) -> String { - format!("{}/", Self::prefix(datanode_id)) + pub fn prefix(datanode_id: DatanodeId) -> String { + format!("{}/{datanode_id}/", DATANODE_TABLE_KEY_PREFIX) } } @@ -114,7 +110,7 @@ impl<'a> MetaKey<'a, DatanodeTableKey> for DatanodeTableKey { impl Display for DatanodeTableKey { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}/{}", Self::prefix(self.datanode_id), self.table_id) + write!(f, "{}{}", Self::prefix(self.datanode_id), self.table_id) } } @@ -164,7 +160,7 @@ impl DatanodeTableManager { &self, datanode_id: DatanodeId, ) -> BoxStream<'static, Result> { - let start_key = DatanodeTableKey::range_start_key(datanode_id); + let start_key = DatanodeTableKey::prefix(datanode_id); let req = RangeRequest::new().with_prefix(start_key.as_bytes()); let stream = PaginationStream::new( diff --git a/src/common/meta/src/key/flow/flownode_flow.rs b/src/common/meta/src/key/flow/flownode_flow.rs index 8bc33c3ef9..d891fbbb05 100644 --- a/src/common/meta/src/key/flow/flownode_flow.rs +++ b/src/common/meta/src/key/flow/flownode_flow.rs @@ -69,8 +69,7 @@ impl FlownodeFlowKey { /// The prefix used to retrieve all [FlownodeFlowKey]s with the specified `flownode_id`. pub fn range_start_key(flownode_id: FlownodeId) -> Vec { - let inner = - BytesAdapter::from(FlownodeFlowKeyInner::range_start_key(flownode_id).into_bytes()); + let inner = BytesAdapter::from(FlownodeFlowKeyInner::prefix(flownode_id).into_bytes()); FlowScoped::new(inner).to_bytes() } @@ -108,13 +107,8 @@ impl FlownodeFlowKeyInner { } } - fn prefix(flownode_id: FlownodeId) -> String { - format!("{}/{flownode_id}", FLOWNODE_FLOW_KEY_PREFIX) - } - - /// The prefix used to retrieve all [FlownodeFlowKey]s with the specified `flownode_id`. - fn range_start_key(flownode_id: FlownodeId) -> String { - format!("{}/", Self::prefix(flownode_id)) + pub fn prefix(flownode_id: FlownodeId) -> String { + format!("{}/{flownode_id}/", FLOWNODE_FLOW_KEY_PREFIX) } } diff --git a/src/common/meta/src/key/flow/table_flow.rs b/src/common/meta/src/key/flow/table_flow.rs index d9aa9cff0b..63dff27bed 100644 --- a/src/common/meta/src/key/flow/table_flow.rs +++ b/src/common/meta/src/key/flow/table_flow.rs @@ -80,7 +80,7 @@ impl TableFlowKey { /// The prefix used to retrieve all [TableFlowKey]s with the specified `table_id`. pub fn range_start_key(table_id: TableId) -> Vec { - let inner = BytesAdapter::from(TableFlowKeyInner::range_start_key(table_id).into_bytes()); + let inner = BytesAdapter::from(TableFlowKeyInner::prefix(table_id).into_bytes()); FlowScoped::new(inner).to_bytes() } @@ -123,12 +123,7 @@ impl TableFlowKeyInner { } fn prefix(table_id: TableId) -> String { - format!("{}/{table_id}", TABLE_FLOW_KEY_PREFIX) - } - - /// The prefix used to retrieve all [TableFlowKey]s with the specified `table_id`. - fn range_start_key(table_id: TableId) -> String { - format!("{}/", Self::prefix(table_id)) + format!("{}/{table_id}/", TABLE_FLOW_KEY_PREFIX) } } diff --git a/src/common/meta/src/key/table_name.rs b/src/common/meta/src/key/table_name.rs index 6c6c51c375..b337fe0866 100644 --- a/src/common/meta/src/key/table_name.rs +++ b/src/common/meta/src/key/table_name.rs @@ -48,7 +48,7 @@ impl<'a> TableNameKey<'a> { } pub fn prefix_to_table(catalog: &str, schema: &str) -> String { - format!("{}/{}/{}", TABLE_NAME_KEY_PREFIX, catalog, schema) + format!("{}/{}/{}/", TABLE_NAME_KEY_PREFIX, catalog, schema) } } @@ -56,7 +56,7 @@ impl Display for TableNameKey<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, - "{}/{}", + "{}{}", Self::prefix_to_table(self.catalog, self.schema), self.table ) @@ -268,7 +268,11 @@ impl TableNameManager { #[cfg(test)] mod tests { + use futures::StreamExt; + use super::*; + use crate::kv_backend::KvBackend; + use crate::rpc::store::PutRequest; #[test] fn test_strip_table_name() { @@ -324,4 +328,39 @@ mod tests { assert_eq!(value.try_as_raw_value().unwrap(), literal); assert_eq!(TableNameValue::try_from_raw_value(literal).unwrap(), value); } + + #[tokio::test] + async fn test_prefix_scan_tables() { + let memory_kv = Arc::new(MemoryKvBackend::::new()); + memory_kv + .put(PutRequest { + key: TableNameKey { + catalog: "greptime", + schema: "👉", + table: "t", + } + .to_bytes(), + value: vec![], + prev_kv: false, + }) + .await + .unwrap(); + memory_kv + .put(PutRequest { + key: TableNameKey { + catalog: "greptime", + schema: "👉👈", + table: "t", + } + .to_bytes(), + value: vec![], + prev_kv: false, + }) + .await + .unwrap(); + + let manager = TableNameManager::new(memory_kv); + let items = manager.tables("greptime", "👉").collect::>().await; + assert_eq!(items.len(), 1); + } } diff --git a/tests/cases/standalone/common/information_schema/tables.result b/tests/cases/standalone/common/information_schema/tables.result new file mode 100644 index 0000000000..d5fd7021e8 --- /dev/null +++ b/tests/cases/standalone/common/information_schema/tables.result @@ -0,0 +1,46 @@ +create schema abc; + +Affected Rows: 1 + +use abc; + +Affected Rows: 0 + +create table t (ts timestamp time index); + +Affected Rows: 0 + +create schema abcde; + +Affected Rows: 1 + +use abcde; + +Affected Rows: 0 + +create table t (ts timestamp time index); + +Affected Rows: 0 + +select table_catalog, table_schema, table_name from information_schema.tables where table_schema != 'information_schema'; + ++---------------+--------------+------------+ +| table_catalog | table_schema | table_name | ++---------------+--------------+------------+ +| greptime | abc | t | +| greptime | abcde | t | +| greptime | public | numbers | ++---------------+--------------+------------+ + +use public; + +Affected Rows: 0 + +drop schema abc; + +Affected Rows: 0 + +drop schema abcde; + +Affected Rows: 0 + diff --git a/tests/cases/standalone/common/information_schema/tables.sql b/tests/cases/standalone/common/information_schema/tables.sql new file mode 100644 index 0000000000..4a03a4a3b6 --- /dev/null +++ b/tests/cases/standalone/common/information_schema/tables.sql @@ -0,0 +1,19 @@ +create schema abc; + +use abc; + +create table t (ts timestamp time index); + +create schema abcde; + +use abcde; + +create table t (ts timestamp time index); + +select table_catalog, table_schema, table_name from information_schema.tables where table_schema != 'information_schema'; + +use public; + +drop schema abc; + +drop schema abcde;