Skip to content

Commit c70b155

Browse files
authored
feat(cubestore): Introduce information_schema.columns (#6152)
1 parent c4f51f4 commit c70b155

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
use crate::metastore::table::TablePath;
2+
use crate::metastore::Column;
3+
use crate::queryplanner::{InfoSchemaTableDef, InfoSchemaTableDefContext};
4+
use crate::CubeError;
5+
use arrow::array::{ArrayRef, StringArray};
6+
use arrow::datatypes::{DataType, Field};
7+
use async_trait::async_trait;
8+
use std::sync::Arc;
9+
10+
pub struct ColumnsInfoSchemaTableDef;
11+
12+
#[async_trait]
13+
impl InfoSchemaTableDef for ColumnsInfoSchemaTableDef {
14+
type T = (Column, TablePath);
15+
16+
async fn rows(
17+
&self,
18+
ctx: InfoSchemaTableDefContext,
19+
) -> Result<Arc<Vec<(Column, TablePath)>>, CubeError> {
20+
let rows = ctx.meta_store.get_tables_with_path(false).await?;
21+
let mut res = Vec::new();
22+
23+
for row in rows.iter() {
24+
let columns = row.table.get_row().get_columns();
25+
for column in columns {
26+
res.push((column.clone(), row.clone()));
27+
}
28+
}
29+
30+
Ok(Arc::new(res))
31+
}
32+
33+
fn columns(
34+
&self,
35+
) -> Vec<(
36+
Field,
37+
Box<dyn Fn(Arc<Vec<(Column, TablePath)>>) -> ArrayRef>,
38+
)> {
39+
vec![
40+
(
41+
Field::new("table_schema", DataType::Utf8, false),
42+
Box::new(|tables| {
43+
Arc::new(StringArray::from(
44+
tables
45+
.iter()
46+
.map(|(_, row)| row.schema.get_row().get_name().as_str())
47+
.collect::<Vec<_>>(),
48+
))
49+
}),
50+
),
51+
(
52+
Field::new("table_name", DataType::Utf8, false),
53+
Box::new(|tables| {
54+
Arc::new(StringArray::from(
55+
tables
56+
.iter()
57+
.map(|(_, row)| row.table.get_row().get_table_name().as_str())
58+
.collect::<Vec<_>>(),
59+
))
60+
}),
61+
),
62+
(
63+
Field::new("column_name", DataType::Utf8, false),
64+
Box::new(|tables| {
65+
Arc::new(StringArray::from(
66+
tables
67+
.iter()
68+
.map(|(column, _)| column.get_name().as_str())
69+
.collect::<Vec<_>>(),
70+
))
71+
}),
72+
),
73+
(
74+
Field::new("data_type", DataType::Utf8, false),
75+
Box::new(|tables| {
76+
Arc::new(StringArray::from(
77+
tables
78+
.iter()
79+
.map(|(column, _)| column.get_column_type().to_string())
80+
.collect::<Vec<_>>(),
81+
))
82+
}),
83+
),
84+
]
85+
}
86+
}
87+
88+
crate::base_info_schema_table_def!(ColumnsInfoSchemaTableDef);

rust/cubestore/cubestore/src/queryplanner/info_schema/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod info_schema_columns;
12
mod info_schema_schemata;
23
mod info_schema_tables;
34
mod system_cache;
@@ -10,6 +11,7 @@ mod system_replay_handles;
1011
mod system_snapshots;
1112
mod system_tables;
1213

14+
pub use info_schema_columns::*;
1315
pub use info_schema_schemata::*;
1416
pub use info_schema_tables::*;
1517
pub use system_cache::*;

rust/cubestore/cubestore/src/queryplanner/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ use crate::metastore::table::{Table, TablePath};
2525
use crate::metastore::{IdRow, MetaStore};
2626
use crate::queryplanner::flatten_union::FlattenUnion;
2727
use crate::queryplanner::info_schema::{
28-
SchemataInfoSchemaTableDef, SystemCacheTableDef, SystemChunksTableDef, SystemIndexesTableDef,
29-
SystemJobsTableDef, SystemPartitionsTableDef, SystemQueueTableDef, SystemReplayHandlesTableDef,
30-
SystemSnapshotsTableDef, SystemTablesTableDef, TablesInfoSchemaTableDef,
28+
ColumnsInfoSchemaTableDef, SchemataInfoSchemaTableDef, SystemCacheTableDef,
29+
SystemChunksTableDef, SystemIndexesTableDef, SystemJobsTableDef, SystemPartitionsTableDef,
30+
SystemQueueTableDef, SystemReplayHandlesTableDef, SystemSnapshotsTableDef,
31+
SystemTablesTableDef, TablesInfoSchemaTableDef,
3132
};
3233
use crate::queryplanner::now::MaterializeNow;
3334
use crate::queryplanner::planning::{choose_index_ext, ClusterSendNode};
@@ -297,6 +298,11 @@ impl ContextProvider for MetaStoreSchemaProvider {
297298
})
298299
});
299300
res.or_else(|| match (schema, table) {
301+
("information_schema", "columns") => Some(Arc::new(InfoSchemaTableProvider::new(
302+
self.meta_store.clone(),
303+
self.cache_store.clone(),
304+
InfoSchemaTable::Columns,
305+
))),
300306
("information_schema", "tables") => Some(Arc::new(InfoSchemaTableProvider::new(
301307
self.meta_store.clone(),
302308
self.cache_store.clone(),
@@ -382,6 +388,7 @@ impl ContextProvider for MetaStoreSchemaProvider {
382388

383389
#[derive(Clone, Debug)]
384390
pub enum InfoSchemaTable {
391+
Columns,
385392
Tables,
386393
Schemata,
387394
SystemJobs,
@@ -450,6 +457,7 @@ macro_rules! base_info_schema_table_def {
450457
impl InfoSchemaTable {
451458
fn table_def(&self) -> Box<dyn BaseInfoSchemaTableDef + Send + Sync> {
452459
match self {
460+
InfoSchemaTable::Columns => Box::new(ColumnsInfoSchemaTableDef),
453461
InfoSchemaTable::Tables => Box::new(TablesInfoSchemaTableDef),
454462
InfoSchemaTable::Schemata => Box::new(SchemataInfoSchemaTableDef),
455463
InfoSchemaTable::SystemTables => Box::new(SystemTablesTableDef),

0 commit comments

Comments
 (0)