Skip to content

Commit

Permalink
Merge pull request #5994 from zhyass/feature_cluster_table
Browse files Browse the repository at this point in the history
Add cluster_by field in system.tables
  • Loading branch information
BohuTANG authored Jun 15, 2022
2 parents ea5f9b5 + bb415f2 commit 8b55b48
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 39 deletions.
12 changes: 12 additions & 0 deletions query/src/storages/system/tables_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,22 @@ impl AsyncSystemTable for TablesTable {
})
.collect();
let created_ons: Vec<&[u8]> = created_ons.iter().map(|s| s.as_bytes()).collect();
let cluster_bys: Vec<String> = database_tables
.iter()
.map(|(_, v)| {
v.get_table_info()
.meta
.cluster_key
.clone()
.unwrap_or_else(|| "".to_owned())
})
.collect();

Ok(DataBlock::create(self.table_info.schema(), vec![
Series::from_data(databases),
Series::from_data(names),
Series::from_data(engines),
Series::from_data(cluster_bys),
Series::from_data(created_ons),
Series::from_data(dropped_ons),
Series::from_data(num_rows),
Expand All @@ -117,6 +128,7 @@ impl TablesTable {
DataField::new("database", Vu8::to_data_type()),
DataField::new("name", Vu8::to_data_type()),
DataField::new("engine", Vu8::to_data_type()),
DataField::new("cluster_by", Vu8::to_data_type()),
DataField::new("created_on", Vu8::to_data_type()),
DataField::new("dropped_on", Vu8::to_data_type()),
DataField::new_nullable("num_rows", u64::to_data_type()),
Expand Down
2 changes: 1 addition & 1 deletion query/tests/it/servers/http/http_query_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async fn test_simple_sql(v2: u64) -> Result<()> {
assert!(result.schema.is_some(), "{:?}", result);
assert_eq!(
result.schema.as_ref().unwrap().fields().len(),
9,
10,
"{:?}",
result
);
Expand Down
60 changes: 30 additions & 30 deletions query/tests/it/storages/system/tables_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ async fn test_tables_table() -> Result<()> {
let stream = table.read(ctx, &source_plan).await?;
let result = stream.try_collect::<Vec<_>>().await?;
let block = &result[0];
assert_eq!(block.num_columns(), 9);
assert_eq!(block.num_columns(), 10);

// check column "dropped_on"
for x in &result {
for row in 0..x.num_rows() {
// index of column dropped_on is 4
let column = x.column(4);
// index of column dropped_on is 5
let column = x.column(5);
let str = column.get_checked(row)?.to_string();
// All of them should be NULL
assert_eq!("NULL", str)
Expand All @@ -47,33 +47,33 @@ async fn test_tables_table() -> Result<()> {
}

let expected = vec![
r"\+--------------------\+--------------\+--------------------\+-------------------------------\+----------\+-----------\+----------------------\+------------\+",
r"\| database \| name \| engine \| created_on \| num_rows \| data_size \| data_compressed_size \| index_size \|",
r"\+--------------------\+--------------\+--------------------\+-------------------------------\+----------\+-----------\+----------------------\+------------\+",
r"\| INFORMATION_SCHEMA \| COLUMNS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| INFORMATION_SCHEMA \| KEYWORDS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| INFORMATION_SCHEMA \| SCHEMATA \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| INFORMATION_SCHEMA \| TABLES \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| INFORMATION_SCHEMA \| VIEWS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| clusters \| SystemClusters \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| columns \| SystemColumns \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| configs \| SystemConfigs \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| contributors \| SystemContributors \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| credits \| SystemCredits \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| databases \| SystemDatabases \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| engines \| SystemEngines \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| functions \| SystemFunctions \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| metrics \| SystemMetrics \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| one \| SystemOne \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| processes \| SystemProcesses \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| query_log \| SystemQueryLog \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| roles \| SystemRoles \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| settings \| SystemSettings \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| tables \| SystemTables \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| tracing \| SystemTracing \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| users \| SystemUsers \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| stages \| SystemStages \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\+--------------------\+--------------\+--------------------\+-------------------------------\+----------\+-----------\+----------------------\+------------\+",
r"\+--------------------\+--------------\+--------------------\+------------\+-------------------------------\+----------\+-----------\+----------------------\+------------\+",
r"\| database \| name \| engine \| cluster_by \| created_on \| num_rows \| data_size \| data_compressed_size \| index_size \|",
r"\+--------------------\+--------------\+--------------------\+------------\+-------------------------------\+----------\+-----------\+----------------------\+------------\+",
r"\| INFORMATION_SCHEMA \| COLUMNS \| VIEW \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| INFORMATION_SCHEMA \| KEYWORDS \| VIEW \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| INFORMATION_SCHEMA \| SCHEMATA \| VIEW \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| INFORMATION_SCHEMA \| TABLES \| VIEW \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| INFORMATION_SCHEMA \| VIEWS \| VIEW \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| clusters \| SystemClusters \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| columns \| SystemColumns \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| configs \| SystemConfigs \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| contributors \| SystemContributors \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| credits \| SystemCredits \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| databases \| SystemDatabases \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| engines \| SystemEngines \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| functions \| SystemFunctions \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| metrics \| SystemMetrics \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| one \| SystemOne \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| processes \| SystemProcesses \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| query_log \| SystemQueryLog \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| roles \| SystemRoles \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| settings \| SystemSettings \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| tables \| SystemTables \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| tracing \| SystemTracing \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| users \| SystemUsers \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\| system \| stages \| SystemStages \| \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \| NULL \| NULL \| NULL \| NULL \|",
r"\+--------------------\+--------------\+--------------------\+------------\+-------------------------------\+----------\+-----------\+----------------------\+------------\+",
];
common_datablocks::assert_blocks_sorted_eq_with_regex(expected, without_dropped.as_slice());

Expand Down
4 changes: 2 additions & 2 deletions tests/logictest/suites/gen/01_system/01_0001_system_tables
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
statement query TTTTIIII
statement query TTTTTTIIII
SELECT * from system.tables where name = 'tables';

----
system tables SystemTables 1970-01-01 00:00:00.000 +0000 NULL NULL NULL NULL
system tables SystemTables 1970-01-01 00:00:00.000 +0000 NULL NULL NULL NULL NULL

Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ statement ok
USE db1;

statement ok
CREATE TABLE IF NOT EXISTS t1(a int, b varchar) Engine = fuse;
CREATE TABLE IF NOT EXISTS t1(a int, b varchar) Engine = fuse cluster by(a);

statement query TTTTIIIII
statement query TTTTTTIIII
SELECT * FROM system.tables WHERE database='db1';

----
db1 t1 fuse 1970-01-01 00:00:00.000 +0000 NULL 0 0 0 NULL
db1 t1 fuse (a) 1970-01-01 00:00:00.000 +0000 NULL 0 0 0 NULL

statement ok
DROP TABLE t1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ select * from t09_0014 order by b, a;
1 3
4 4

statement query TIIFFT
select * from clustering_information('default','t09_0014');

----
(b, a) 3 1 0.6667 1.6667 {"00001":1,"00002":2}

statement ok
drop table t09_0014;

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ select * from t09_0015 order by b, a;
1 3
4 4

statement query TIIFFT
select * from clustering_information('db1','t09_0015');

----
(b, a) 3 1 0.6667 1.6667 {"00001":1,"00002":2}

statement ok
ALTER TABLE t09_0015 DROP CLUSTER KEY;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
system tables SystemTables yyyy-mm-dd HH:MM:SS.sss +0000 NULL NULL NULL NULL NULL
system tables SystemTables yyyy-mm-dd HH:MM:SS.sss +0000 NULL NULL NULL NULL NULL
Original file line number Diff line number Diff line change
@@ -1 +1 @@
db1 t1 fuse yyyy-mm-dd HH:MM:SS.sss +0000 NULL 0 0 0 NULL
db1 t1 fuse (a) yyyy-mm-dd HH:MM:SS.sss +0000 NULL 0 0 0 NULL
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DROP DATABASE IF EXISTS db1;
CREATE DATABASE db1;
USE db1;

CREATE TABLE IF NOT EXISTS t1(a int, b varchar) Engine = fuse;
CREATE TABLE IF NOT EXISTS t1(a int, b varchar) Engine = fuse cluster by(a);
SELECT * FROM system.tables WHERE database='db1';

DROP TABLE t1;
Expand Down

0 comments on commit 8b55b48

Please sign in to comment.