Skip to content

Commit

Permalink
chore(query): add column: system.tables.total_columns (#16447)
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason authored Sep 13, 2024
1 parent 8cff049 commit 007a076
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async fn test_simple_sql() -> Result<()> {
assert_eq!(result.state, ExecuteStateKind::Succeeded, "{:?}", result);
assert_eq!(result.next_uri, Some(final_uri.clone()), "{:?}", result);
assert_eq!(result.data.len(), 10, "{:?}", result);
assert_eq!(result.schema.len(), 21, "{:?}", result);
assert_eq!(result.schema.len(), 22, "{:?}", result);

// get state
let uri = result.stats_uri.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'task_type' | 'system' | 'background_jobs' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'tenant_id' | 'system' | 'query_log' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
| 'time' | 'system' | 'processes' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
| 'total_columns' | 'system' | 'tables' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
| 'total_columns' | 'system' | 'tables_with_history' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
| 'total_partitions' | 'system' | 'query_log' | 'UInt64' | 'BIGINT UNSIGNED' | '' | '' | 'NO' | '' |
| 'trigger' | 'system' | 'background_tasks' | 'Nullable(String)' | 'VARCHAR' | '' | '' | 'YES' | '' |
| 'type' | 'system' | 'background_tasks' | 'String' | 'VARCHAR' | '' | '' | 'NO' | '' |
Expand Down
9 changes: 9 additions & 0 deletions src/query/storages/system/src/tables_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ where TablesTable<WITH_HISTORY, WITHOUT_VIEW>: HistoryAware
TableField::new("database", TableDataType::String),
TableField::new("name", TableDataType::String),
TableField::new("table_id", TableDataType::Number(NumberDataType::UInt64)),
TableField::new(
"total_columns",
TableDataType::Number(NumberDataType::UInt64),
),
TableField::new("engine", TableDataType::String),
TableField::new("engine_full", TableDataType::String),
TableField::new("cluster_by", TableDataType::String),
Expand Down Expand Up @@ -587,6 +591,10 @@ where TablesTable<WITH_HISTORY, WITHOUT_VIEW>: HistoryAware
.iter()
.map(|v| v.get_table_info().ident.table_id)
.collect();
let total_columns: Vec<u64> = database_tables
.iter()
.map(|v| v.get_table_info().schema().fields().len() as u64)
.collect();
let engines: Vec<String> = database_tables
.iter()
.map(|v| v.engine().to_string())
Expand Down Expand Up @@ -678,6 +686,7 @@ where TablesTable<WITH_HISTORY, WITHOUT_VIEW>: HistoryAware
StringType::from_data(databases),
StringType::from_data(names),
UInt64Type::from_data(table_id),
UInt64Type::from_data(total_columns),
StringType::from_data(engines),
StringType::from_data(engines_full),
StringType::from_data(cluster_bys),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ number_of_segments BIGINT UNSIGNED YES NULL NULL
owner VARCHAR YES NULL NULL
table_id BIGINT UNSIGNED NO NULL NULL
table_type VARCHAR NO NULL NULL
total_columns BIGINT UNSIGNED NO NULL NULL
updated_on TIMESTAMP NO NULL NULL
Error: APIError: ResponseError with 1063: Permission denied: User 'a'@'%' does not have the required privileges for database 'nogrant'
1
Expand Down

0 comments on commit 007a076

Please sign in to comment.