Skip to content

Commit 96d1c34

Browse files
authored
Add views to navigation tree (#838)
1 parent 93fbd8a commit 96d1c34

File tree

8 files changed

+59
-44
lines changed

8 files changed

+59
-44
lines changed

crates/api-ui/src/navigation_trees/handlers.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ pub async fn get_navigation_trees(
7272
.await
7373
.map_err(|e| NavigationTreesAPIError::Execution { source: e })?;
7474

75-
let mut catalogs_tree: BTreeMap<String, BTreeMap<String, Vec<String>>> = BTreeMap::new();
75+
let mut catalogs_tree: BTreeMap<String, BTreeMap<String, Vec<(String, String)>>> =
76+
BTreeMap::new();
7677

7778
for batch in tree_batches {
7879
let databases = downcast_string_column(&batch, "database")?;
7980
let schemas = downcast_string_column(&batch, "schema")?;
8081
let tables = downcast_string_column(&batch, "table")?;
82+
let table_types = downcast_string_column(&batch, "table_type")?;
8183

8284
for j in 0..batch.num_rows() {
8385
let database = databases.value(j).to_string();
8486
let schema = schemas.value(j).to_string();
8587
let table = tables.value(j).to_string();
88+
let table_type = table_types.value(j).to_string();
8689

8790
let db_entry = catalogs_tree.entry(database).or_default();
8891

@@ -91,7 +94,7 @@ pub async fn get_navigation_trees(
9194
}
9295
let schema_entry = db_entry.entry(schema).or_default();
9396
if !table.is_empty() {
94-
schema_entry.push(table);
97+
schema_entry.push((table, table_type));
9598
}
9699
}
97100
}
@@ -107,12 +110,22 @@ pub async fn get_navigation_trees(
107110
name: catalog_name,
108111
schemas: schemas_map
109112
.into_iter()
110-
.map(|(schema_name, table_names)| NavigationTreeSchema {
111-
name: schema_name,
112-
tables: table_names
113-
.into_iter()
114-
.map(|name| NavigationTreeTable { name })
115-
.collect(),
113+
.map(|(schema_name, table_names)| {
114+
let tables = table_names
115+
.iter()
116+
.filter(|(_, table_type)| table_type != "VIEW")
117+
.map(|(name, _)| NavigationTreeTable { name: name.clone() })
118+
.collect();
119+
let views = table_names
120+
.iter()
121+
.filter(|(_, table_type)| table_type == "VIEW")
122+
.map(|(name, _)| NavigationTreeTable { name: name.clone() })
123+
.collect();
124+
NavigationTreeSchema {
125+
name: schema_name,
126+
tables,
127+
views,
128+
}
116129
})
117130
.collect(),
118131
})

crates/api-ui/src/navigation_trees/models.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct NavigationTreeDatabase {
2121
pub struct NavigationTreeSchema {
2222
pub name: String,
2323
pub tables: Vec<NavigationTreeTable>,
24+
pub views: Vec<NavigationTreeTable>,
2425
}
2526

2627
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Validate, ToSchema)]

crates/api-ui/src/tests/navigation_trees.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,7 @@ async fn test_ui_databases_navigation() {
133133
let query_payload = QueryCreatePayload {
134134
worksheet_id: Some(worksheet.id),
135135
query: format!(
136-
"create or replace Iceberg TABLE {}.{}.{}
137-
external_volume = ''
138-
catalog = ''
139-
base_location = ''
140-
(
141-
APP_ID TEXT,
142-
PLATFORM TEXT,
143-
ETL_TSTAMP TEXT,
144-
COLLECTOR_TSTAMP TEXT NOT NULL,
145-
DVCE_CREATED_TSTAMP TEXT,
146-
EVENT TEXT,
147-
EVENT_ID TEXT);",
136+
"CREATE TABLE {}.{}.{} (APP_ID TEXT)",
148137
expected1.data.name.clone(),
149138
schema_name.clone(),
150139
"tested1"
@@ -179,7 +168,7 @@ async fn test_ui_databases_navigation() {
179168
.tables
180169
.len()
181170
);
182-
// Information schema tables
171+
// Information schema views
183172
assert_eq!(
184173
8,
185174
databases_navigation
@@ -189,7 +178,7 @@ async fn test_ui_databases_navigation() {
189178
.schemas
190179
.first()
191180
.unwrap()
192-
.tables
181+
.views
193182
.len()
194183
);
195184

crates/core-executor/src/tests/query.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use core_metastore::{
1111
Database as MetastoreDatabase, Schema as MetastoreSchema, SchemaIdent as MetastoreSchemaIdent,
1212
TableIdent as MetastoreTableIdent, Volume as MetastoreVolume,
1313
};
14-
use datafusion::arrow::compute::{SortColumn, SortOptions, take_record_batch};
1514
use datafusion::assert_batches_eq;
1615
use datafusion::sql::parser::{DFParser, Statement as DFStatement};
1716
use datafusion::sql::sqlparser::ast::Statement as SQLStatement;

crates/df-catalog/src/information_schema/config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ impl InformationSchemaConfig {
8181
"Catalog '{catalog_name}' not found in catalog list"
8282
))
8383
})?;
84-
builder.add_navigation_tree(&catalog_name, None, None);
84+
builder.add_navigation_tree(&catalog_name, None, None, None);
8585

8686
for schema_name in catalog.schema_names() {
87-
builder.add_navigation_tree(&catalog_name, Some(schema_name.clone()), None);
87+
builder.add_navigation_tree(&catalog_name, Some(schema_name.clone()), None, None);
8888

8989
if let Some(schema) = catalog.schema(&schema_name) {
9090
for table_name in schema.table_names() {
9191
builder.add_navigation_tree(
9292
&catalog_name,
9393
Some(schema_name.clone()),
9494
Some(table_name),
95+
Some(TableType::Base),
9596
);
9697
}
9798
}
@@ -103,6 +104,7 @@ impl InformationSchemaConfig {
103104
&catalog_name,
104105
Some(INFORMATION_SCHEMA.to_string()),
105106
Some(table.key().to_string()),
107+
Some(TableType::View),
106108
);
107109
}
108110
}

crates/df-catalog/src/information_schema/navigation_tree.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use datafusion::arrow::{
77
};
88
use datafusion::execution::TaskContext;
99
use datafusion_common::DataFusionError;
10+
use datafusion_expr::TableType;
1011
use datafusion_physical_plan::SendableRecordBatchStream;
1112
use datafusion_physical_plan::stream::RecordBatchStreamAdapter;
1213
use datafusion_physical_plan::streaming::PartitionStream;
@@ -25,6 +26,7 @@ impl InformationSchemaNavigationTree {
2526
Field::new("database", DataType::Utf8, false),
2627
Field::new("schema", DataType::Utf8, true),
2728
Field::new("table", DataType::Utf8, true),
29+
Field::new("table_type", DataType::Utf8, true),
2830
]))
2931
}
3032
pub(crate) fn new(config: InformationSchemaConfig) -> Self {
@@ -37,6 +39,7 @@ impl InformationSchemaNavigationTree {
3739
databases: StringBuilder::new(),
3840
schemas: StringBuilder::new(),
3941
tables: StringBuilder::new(),
42+
table_types: StringBuilder::new(),
4043
schema: Arc::clone(&self.schema),
4144
}
4245
}
@@ -70,6 +73,7 @@ pub struct InformationSchemaNavigationTreeBuilder {
7073
databases: StringBuilder,
7174
schemas: StringBuilder,
7275
tables: StringBuilder,
76+
table_types: StringBuilder,
7377
}
7478

7579
impl InformationSchemaNavigationTreeBuilder {
@@ -78,11 +82,18 @@ impl InformationSchemaNavigationTreeBuilder {
7882
database: impl AsRef<str>,
7983
schema: Option<String>,
8084
table: Option<String>,
85+
table_type: Option<TableType>,
8186
) {
8287
// Note: append_value is actually infallible.
8388
self.databases.append_value(database.as_ref());
8489
self.schemas.append_option(schema);
8590
self.tables.append_option(table);
91+
self.table_types
92+
.append_option(table_type.map(|ttype| match ttype {
93+
TableType::Base => "TABLE",
94+
TableType::View => "VIEW",
95+
TableType::Temporary => "TEMPORARY",
96+
}));
8697
}
8798

8899
fn finish(&mut self) -> Result<RecordBatch, ArrowError> {
@@ -92,6 +103,7 @@ impl InformationSchemaNavigationTreeBuilder {
92103
Arc::new(self.databases.finish()),
93104
Arc::new(self.schemas.finish()),
94105
Arc::new(self.tables.finish()),
106+
Arc::new(self.table_types.finish()),
95107
],
96108
)
97109
}

crates/df-catalog/src/tests/information_schema.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::information_schema::information_schema::{
44
};
55
use crate::test_utils::sort_record_batch_by_sortable_columns;
66
use core_metastore::SlateDBMetastore;
7-
use datafusion::arrow::compute::{SortColumn, SortOptions, take_record_batch};
87
use datafusion::execution::SessionStateBuilder;
98
use datafusion::execution::context::SessionContext;
109
use datafusion::prelude::SessionConfig;

crates/df-catalog/src/tests/snapshots/information_schema_navigation_tree.snap

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ source: crates/df-catalog/src/tests/information_schema.rs
33
description: "SELECT * FROM embucket.information_schema.navigation_tree ORDER BY database, schema, table"
44
snapshot_kind: text
55
---
6-
+----------+--------------------+-----------------+
7-
| database | schema | table |
8-
+----------+--------------------+-----------------+
9-
| embucket | | |
10-
| embucket | information_schema | |
11-
| embucket | information_schema | columns |
12-
| embucket | information_schema | databases |
13-
| embucket | information_schema | df_settings |
14-
| embucket | information_schema | navigation_tree |
15-
| embucket | information_schema | parameters |
16-
| embucket | information_schema | routines |
17-
| embucket | information_schema | schemata |
18-
| embucket | information_schema | tables |
19-
| embucket | information_schema | views |
20-
| embucket | public | |
21-
| embucket | public | first |
22-
| embucket | public | second |
23-
+----------+--------------------+-----------------+
6+
+----------+--------------------+-----------------+------------+
7+
| database | schema | table | table_type |
8+
+----------+--------------------+-----------------+------------+
9+
| embucket | | | |
10+
| embucket | information_schema | | |
11+
| embucket | information_schema | columns | VIEW |
12+
| embucket | information_schema | databases | VIEW |
13+
| embucket | information_schema | df_settings | VIEW |
14+
| embucket | information_schema | navigation_tree | TABLE |
15+
| embucket | information_schema | parameters | VIEW |
16+
| embucket | information_schema | routines | VIEW |
17+
| embucket | information_schema | schemata | VIEW |
18+
| embucket | information_schema | tables | VIEW |
19+
| embucket | information_schema | views | VIEW |
20+
| embucket | public | | |
21+
| embucket | public | first | TABLE |
22+
| embucket | public | second | TABLE |
23+
+----------+--------------------+-----------------+------------+

0 commit comments

Comments
 (0)