Skip to content

Commit

Permalink
feat: Add information_schema (#115)
Browse files Browse the repository at this point in the history
* feat: Add information_schema

Fixes #98

Cloud will be making requests directly to the database to get info about the
contents of the database, including schemas, tables, and columns.
  • Loading branch information
scsmithr authored Sep 20, 2022
1 parent 7db692c commit 1c2c06f
Show file tree
Hide file tree
Showing 6 changed files with 548 additions and 3 deletions.
11 changes: 11 additions & 0 deletions crates/sqlexec/src/catalog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::errors::{internal, Result};
use crate::information_schema::{InformationSchemaProvider, INFORMATION_SCHEMA};
use datafusion::catalog::catalog::{CatalogList, CatalogProvider};
use datafusion::catalog::schema::SchemaProvider;
use datafusion::datasource::TableProvider;
Expand Down Expand Up @@ -30,6 +31,16 @@ impl DatabaseCatalog {
&self.name
}

/// Insert an information schema into this catalog.
///
/// Note that this takes an arc as the information schema view needs a
/// reference to the catalog since everything is built during query time.
pub fn insert_information_schema(self: Arc<Self>) -> Result<()> {
let schema = InformationSchemaProvider::new(self.clone());
self.insert_schema(INFORMATION_SCHEMA, Arc::new(schema))?;
Ok(())
}

/// Insert the default "public" schema.
pub fn insert_default_schema(&self) -> Result<()> {
let schema = Arc::new(SchemaCatalog::new());
Expand Down
5 changes: 4 additions & 1 deletion crates/sqlexec/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ impl Engine {
let catalog = DatabaseCatalog::new(db_name);
catalog.insert_default_schema()?;

let catalog = Arc::new(catalog);
DatabaseCatalog::insert_information_schema(catalog.clone())?;

Ok(Engine {
catalog: Arc::new(catalog),
catalog,
runtime: Arc::new(runtime),
})
}
Expand Down
Loading

0 comments on commit 1c2c06f

Please sign in to comment.