Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge): handle information schema #245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

skyzh
Copy link
Member

@skyzh skyzh commented Nov 23, 2024

The information schema is not in datafusion's catalog. It is handled differently as in the upstream source code:

https://github.com/apache/datafusion/blob/c0ca4b4e449e07c3bcd6f3593fa31dd31ed5e0c5/datafusion/core/src/execution/session_state.rs#L301-L311

Therefore, we added this special case in the df-bridge.

Comment on lines +64 to +81
let (schema, table) = if let Some((schema, table)) = name.split_once('.') {
(schema, table)
} else {
("public", name)
};
let schema = if schema == "information_schema" {
// This is `INFORMATION_SCHEMA` but datafusion didn't expose this constant.
// Also, note that we didn't check `session_state.is_information_schema_enabled()` so this schema is always
// available.
Arc::new(InformationSchemaProvider::new(Arc::clone(&self.catalog)))
} else if let Some(schema) = catalog.schema(schema) {
schema
} else {
panic!("schema not found in datafusion catalog: {}", schema)
};
let Some(table) = futures_lite::future::block_on(schema.table(table.as_ref())) else {
panic!("table not found in datafusion catalog: {}", name);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel using datafusion's resolve method makes it cleaner:

let resolved = TableReference::from(name).resolve("datafusion", "public");
let catalog = self.catalog.catalog(&resolved.catalog).unwrap();
let schema = if resolved.schema == "information_schema" {
self.information_schema.clone()
} else {
catalog.schema(&resolved.schema).unwrap()
};
let table = futures_lite::future::block_on(schema.table(&resolved.table)).unwrap();

I had it while drafting #233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants