Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: psql tab completion #2464

Merged
merged 4 commits into from
Jan 22, 2024
Merged
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
11 changes: 10 additions & 1 deletion crates/datafusion_ext/src/planner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@ impl<'a, S: AsyncContextProvider> SqlQueryPlanner<'a, S> {
}
SQLDataType::Bytea => Ok(DataType::Binary),
SQLDataType::Interval => Ok(DataType::Interval(IntervalUnit::MonthDayNano)),
SQLDataType::Custom(obj, _) => {
let obj = obj.to_string();
match obj.as_str() {
// PSQL uses `pg_catalog.text` for `text` type in some cases
"pg_catalog.text" => Ok(DataType::Utf8),
_ => Err(DataFusionError::NotImplemented(format!(
"Unsupported SQL type {sql_type:?}"
))),
}
}
Comment on lines +272 to +281
Copy link
Member

Choose a reason for hiding this comment

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

// Explicitly list all other types so that if sqlparser
// adds/changes the `SQLDataType` the compiler will tell us on upgrade
// and avoid bugs like https://github.com/apache/arrow-datafusion/issues/3059
Expand All @@ -280,7 +290,6 @@ impl<'a, S: AsyncContextProvider> SqlQueryPlanner<'a, S> {
| SQLDataType::Blob(_)
| SQLDataType::Datetime(_)
| SQLDataType::Regclass
| SQLDataType::Custom(_, _)
| SQLDataType::Array(_)
| SQLDataType::Enum(_)
| SQLDataType::Set(_)
Expand Down
35 changes: 34 additions & 1 deletion testdata/sqllogictests/pg_catalog.slt
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,37 @@ pg_catalog_test pg_description


statement ok
select * from pg_catalog.pg_type;
select * from pg_catalog.pg_type;


# This is one of the queries postgres uses for tab completion
# see https://github.com/GlareDB/glaredb/issues/2393
statement ok
SELECT
c.relname,
NULL::pg_catalog.text
FROM pg_catalog.pg_class c
WHERE c.relkind IN ('r', 'S', 'v', 'm', 'f', 'p')
AND (c.relname) LIKE '%'
AND pg_catalog.pg_table_is_visible(c.oid)
AND c.relnamespace <> ( SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = 'pg_catalog') UNION ALL
SELECT NULL::pg_catalog.text, n.nspname
FROM pg_catalog.pg_namespace n
WHERE n.nspname LIKE '%'
AND n.nspname NOT LIKE E'pg\\_%'
LIMIT 1000;

# Another query postgres uses for tab completion
# see https://github.com/GlareDB/glaredb/issues/2393
statement ok
SELECT
c.relname,
n.nspname
FROM
pg_catalog.pg_class c,
pg_catalog.pg_namespace n
WHERE c.relnamespace = n.oid
AND c.relkind IN ('r', 'S', 'v', 'm', 'f', 'p')
AND (c.relname) LIKE '%'
AND n.nspname = 'pg_catalog'
LIMIT 1000;