Skip to content
Closed
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
22 changes: 22 additions & 0 deletions datafusion-pg-catalog/src/sql/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ impl VisitorMut for RemoveUnsupportedTypesVisitor<'_> {
.unsupported_types
.contains(data_type.to_string().to_lowercase().as_str())
{
self.remove_nested_unsupported_casts(value);
*expr = *value.clone();
}
}
Expand All @@ -372,6 +373,25 @@ impl VisitorMut for RemoveUnsupportedTypesVisitor<'_> {
}
}

impl RemoveUnsupportedTypesVisitor<'_> {
fn remove_nested_unsupported_casts(&mut self, expr: &mut Expr) {
if let Expr::Cast {
data_type,
expr: value,
..
} = expr
{
if self
.unsupported_types
.contains(data_type.to_string().to_lowercase().as_str())
{
self.remove_nested_unsupported_casts(value);
*expr = *value.clone();
}
}
}
}

impl SqlStatementRewriteRule for RemoveUnsupportedTypes {
fn rewrite(&self, mut statement: Statement) -> Statement {
let mut visitor = RemoveUnsupportedTypesVisitor {
Expand Down Expand Up @@ -995,6 +1015,8 @@ mod tests {
WHERE c.oid = '16386'",
"SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, false AS relhasoids, c.relispartition, '', c.reltablespace, CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::TEXT END, c.relpersistence, c.relreplident, am.amname FROM pg_catalog.pg_class AS c LEFT JOIN pg_catalog.pg_class AS tc ON (c.reltoastrelid = tc.oid) LEFT JOIN pg_catalog.pg_am AS am ON (c.relam = am.oid) WHERE c.oid = '16386'"
);

assert_rewrite!(&rules, "SELECT $1::regclass::oid", "SELECT $1");
}

#[test]
Expand Down
24 changes: 24 additions & 0 deletions datafusion-postgres/tests/pgadbc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use pgwire::api::query::SimpleQueryHandler;

use datafusion_postgres::testing::*;

const PGADBC_QUERIES: &[&str] = &[
"SELECT attname, atttypid FROM pg_catalog.pg_class AS cls INNER JOIN pg_catalog.pg_attribute AS attr ON cls.oid = attr.attrelid INNER JOIN pg_catalog.pg_type AS typ ON attr.atttypid = typ.oid WHERE attr.attnum >= 0 AND cls.oid = 1602::regclass::oid ORDER BY attr.attnum",


];

#[tokio::test]
pub async fn test_pgadbc_metadata_sql() {
env_logger::init();
let service = setup_handlers();
let mut client = MockClient::new();

for query in PGADBC_QUERIES {
SimpleQueryHandler::do_query(&service, &mut client, query)
.await
.unwrap_or_else(|e| {
panic!("failed to run sql:\n--------------\n {query}\n--------------\n{e}")
});
}
}
Loading