1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mod pg_namespace;
mod pg_type;

use std::sync::Arc;

use anyhow::Result;
use datafusion::catalog::schema::{MemorySchemaProvider, SchemaProvider};
use datafusion::execution::context::SessionContext;
use pg_namespace::PgNamespaceTable;
use pg_type::PgTypeTable;

pub fn with_pg_catalog(ctx: &SessionContext) -> Result<()> {
    let pg_catalog = MemorySchemaProvider::new();
    pg_catalog.register_table("pg_type".to_string(), Arc::new(PgTypeTable::new()))?;

    ctx.register_table("public.pg_namespace", Arc::new(PgNamespaceTable::new()))?;

    let default_catalog = ctx
        .catalog(&ctx.state().config_options().catalog.default_catalog)
        .unwrap();
    default_catalog.register_schema("pg_catalog", Arc::new(pg_catalog))?;
    Ok(())
}