Skip to content

Commit 50e2ecb

Browse files
committed
test: new InformationSchemaConfig::make_tables behavior
1 parent 413bbab commit 50e2ecb

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

datafusion/catalog/src/information_schema.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,3 +1361,6 @@ impl PartitionStream for InformationSchemaParameters {
13611361
))
13621362
}
13631363
}
1364+
1365+
#[cfg(test)]
1366+
mod tests;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
use std::sync::Arc;
2+
3+
use crate::CatalogProvider;
4+
5+
use super::*;
6+
7+
#[tokio::test]
8+
async fn make_tables_uses_table_type() {
9+
let config = InformationSchemaConfig {
10+
catalog_list: Arc::new(Fixture),
11+
};
12+
let mut builder = InformationSchemaTablesBuilder {
13+
catalog_names: StringBuilder::new(),
14+
schema_names: StringBuilder::new(),
15+
table_names: StringBuilder::new(),
16+
table_types: StringBuilder::new(),
17+
schema: Arc::new(Schema::empty()),
18+
};
19+
20+
assert!(config.make_tables(&mut builder).await.is_ok());
21+
22+
assert_eq!("BASE TABLE", builder.table_types.finish().value(0));
23+
}
24+
25+
#[derive(Debug)]
26+
struct Fixture;
27+
28+
#[async_trait]
29+
impl SchemaProvider for Fixture {
30+
// InformationSchemaConfig::make_tables should use this.
31+
async fn table_type(&self, _: &str) -> Result<Option<TableType>> {
32+
Ok(Some(TableType::Base))
33+
}
34+
35+
// InformationSchemaConfig::make_tables used this before `table_type`
36+
// existed but should not, as it may be expensive.
37+
async fn table(&self, _: &str) -> Result<Option<Arc<dyn TableProvider>>> {
38+
panic!("InformationSchemaConfig::make_tables called SchemaProvider::table instead of table_type")
39+
}
40+
41+
fn as_any(&self) -> &dyn Any {
42+
unimplemented!("not required for these tests")
43+
}
44+
45+
fn table_names(&self) -> Vec<String> {
46+
vec!["atable".to_string()]
47+
}
48+
49+
fn table_exist(&self, _: &str) -> bool {
50+
unimplemented!("not required for these tests")
51+
}
52+
}
53+
54+
impl CatalogProviderList for Fixture {
55+
fn as_any(&self) -> &dyn Any {
56+
unimplemented!("not required for these tests")
57+
}
58+
59+
fn register_catalog(
60+
&self,
61+
_: String,
62+
_: Arc<dyn CatalogProvider>,
63+
) -> Option<Arc<dyn CatalogProvider>> {
64+
unimplemented!("not required for these tests")
65+
}
66+
67+
fn catalog_names(&self) -> Vec<String> {
68+
vec!["acatalog".to_string()]
69+
}
70+
71+
fn catalog(&self, _: &str) -> Option<Arc<dyn CatalogProvider>> {
72+
Some(Arc::new(Self))
73+
}
74+
}
75+
76+
impl CatalogProvider for Fixture {
77+
fn as_any(&self) -> &dyn Any {
78+
unimplemented!("not required for these tests")
79+
}
80+
81+
fn schema_names(&self) -> Vec<String> {
82+
vec!["aschema".to_string()]
83+
}
84+
85+
fn schema(&self, _: &str) -> Option<Arc<dyn SchemaProvider>> {
86+
Some(Arc::new(Self))
87+
}
88+
}

0 commit comments

Comments
 (0)