Skip to content
Open
Show file tree
Hide file tree
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
1,301 changes: 882 additions & 419 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ arrow = "58"
arrow-schema = "58"
bytes = "1.11.1"
chrono = { version = "0.4", features = ["std"] }
datafusion = { version = "53" }
datafusion = { version = "54" }
futures = "0.3"
pgwire = { version = "0.40", default-features = false }
postgres-types = "0.2"
Expand Down
30 changes: 22 additions & 8 deletions datafusion-pg-catalog/src/pg_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ use crate::pg_catalog::catalog_info::CatalogInfo;
use crate::pg_catalog::context::PgCatalogContextProvider;
use crate::pg_catalog::empty_table::EmptyTable;

pub mod array_bounds_udf;
pub mod catalog_info;
pub mod context;
pub mod empty_table;
pub mod format_type;
pub mod has_privilege_udf;
pub mod oid_coercion_rule;
pub mod oid_field;
pub mod oid_type_planner;
pub mod pg_attribute;
pub mod pg_class;
pub mod pg_database;
Expand Down Expand Up @@ -208,10 +210,6 @@ pub struct PgCatalogSchemaProvider<C, P> {

#[async_trait]
impl<C: CatalogInfo, P: PgCatalogContextProvider> SchemaProvider for PgCatalogSchemaProvider<C, P> {
fn as_any(&self) -> &dyn std::any::Any {
self
}

fn table_names(&self) -> Vec<String> {
PG_CATALOG_TABLES.iter().map(ToString::to_string).collect()
}
Expand Down Expand Up @@ -1384,10 +1382,6 @@ pub fn create_pg_get_constraintdef() -> ScalarUDF {
}

impl ScalarUDFImpl for GetConstraintDefUDF {
fn as_any(&self) -> &dyn std::any::Any {
self
}

fn name(&self) -> &str {
"pg_get_constraintdef"
}
Expand Down Expand Up @@ -1499,6 +1493,11 @@ where
session_context.register_udf(create_pg_get_partition_ancestors_udf());
session_context.register_udf(quote_ident_udf::create_quote_ident_udf());
session_context.register_udf(quote_ident_udf::create_parse_ident_udf());
// Postgres array bounds. DataFusion ships array_length but not array_upper /
// array_lower; without these, client queries (psql/dbeaver/grafan) that use
// them were only "supported" via hardcoded blacklist token substitution.
session_context.register_udf(array_bounds_udf::create_array_upper_udf());
session_context.register_udf(array_bounds_udf::create_array_lower_udf());

// Make oid / oid-alias columns (relnamespace, atttypid, ...) compare
// against string literals the way Postgres does. Requires the schema
Expand All @@ -1507,6 +1506,21 @@ where
pg_catalog.clone() as Arc<dyn oid_coercion_rule::OidLookupProvider>,
)));

// Teach the SQL planner to accept Postgres oid-alias type names
// (`regclass`, `regproc`, ...) -- DataFusion rejects them as unsupported
// otherwise. Each maps to int4 carrying `pg.oid_alias` metadata, which the
// analyzer rule above then reads to resolve name strings -> oids. This
// replaces the former SQL-layer cast-stripping / cast-rewriting rules.
{
use datafusion::execution::session_state::SessionStateBuilder;
let state = session_context.state_ref();
let existing = state.read().clone();
let new_state = SessionStateBuilder::new_from_existing(existing)
.with_type_planner(Arc::new(oid_type_planner::PgOidTypePlanner))
.build();
*state.write() = new_state;
}

Ok(())
}

Expand Down
Loading
Loading