Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

fix(bridge): handle information schema #245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions optd-datafusion-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::sync::{Arc, Mutex};

use async_trait::async_trait;
use datafusion::arrow::datatypes::DataType;
use datafusion::catalog::information_schema::InformationSchemaProvider;
use datafusion::catalog::CatalogList;
use datafusion::error::Result;
use datafusion::execution::context::{QueryPlanner, SessionState};
Expand Down Expand Up @@ -60,8 +61,24 @@ impl DatafusionCatalog {
impl Catalog for DatafusionCatalog {
fn get(&self, name: &str) -> optd_datafusion_repr::properties::schema::Schema {
let catalog = self.catalog.catalog("datafusion").unwrap();
let schema = catalog.schema("public").unwrap();
let table = futures_lite::future::block_on(schema.table(name.as_ref())).unwrap();
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);
};
Comment on lines +64 to +81
Copy link
Member

Choose a reason for hiding this comment

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

let schema = table.schema();
let fields = schema.fields();
let mut optd_fields = Vec::with_capacity(fields.len());
Expand Down
Loading