diff --git a/src/common/function/src/system/pg_catalog.rs b/src/common/function/src/system/pg_catalog.rs index 07e7d2abaf..0924b58175 100644 --- a/src/common/function/src/system/pg_catalog.rs +++ b/src/common/function/src/system/pg_catalog.rs @@ -23,9 +23,10 @@ use datafusion::arrow::array::{ArrayRef, StringArray, as_boolean_array}; use datafusion::catalog::TableFunction; use datafusion::common::ScalarValue; use datafusion::common::utils::SingleRowListArrayBuilder; -use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility}; +use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, TypeSignature, Volatility}; use datafusion_pg_catalog::pg_catalog::{self, PgCatalogStaticTables}; use datatypes::arrow::datatypes::{DataType, Field}; +use derive_more::derive::Display; use version::PGVersionFunction; use crate::function::{Function, find_function_context}; @@ -38,7 +39,6 @@ const SESSION_USER_FUNCTION_NAME: &str = "session_user"; const CURRENT_DATABASE_FUNCTION_NAME: &str = "current_database"; define_nullary_udf!(CurrentSchemaFunction); -define_nullary_udf!(CurrentSchemasFunction); define_nullary_udf!(SessionUserFunction); define_nullary_udf!(CurrentDatabaseFunction); @@ -118,6 +118,23 @@ impl Function for SessionUserFunction { } } +#[derive(Display, Debug)] +#[display("{}", self.name())] +pub(super) struct CurrentSchemasFunction { + signature: Signature, +} + +impl CurrentSchemasFunction { + pub fn new() -> Self { + Self { + signature: Signature::new( + TypeSignature::Exact(vec![DataType::Boolean]), + Volatility::Stable, + ), + } + } +} + impl Function for CurrentSchemasFunction { fn name(&self) -> &str { CURRENT_SCHEMAS_FUNCTION_NAME @@ -125,9 +142,9 @@ impl Function for CurrentSchemasFunction { fn return_type(&self, _: &[DataType]) -> datafusion_common::Result { Ok(DataType::List(Arc::new(Field::new( - "x", - DataType::Utf8View, - false, + "item", + DataType::Utf8, + true, )))) } @@ -168,7 +185,7 @@ impl PGCatalogFunction { registry.register_scalar(PGVersionFunction::default()); registry.register_scalar(CurrentSchemaFunction::default()); - registry.register_scalar(CurrentSchemasFunction::default()); + registry.register_scalar(CurrentSchemasFunction::new()); registry.register_scalar(SessionUserFunction::default()); registry.register_scalar(CurrentDatabaseFunction::default()); registry.register(pg_catalog::format_type::create_format_type_udf()); diff --git a/tests/cases/standalone/common/system/pg_catalog.result b/tests/cases/standalone/common/system/pg_catalog.result index 0aa7f1cc7e..704caa860a 100644 --- a/tests/cases/standalone/common/system/pg_catalog.result +++ b/tests/cases/standalone/common/system/pg_catalog.result @@ -13,15 +13,15 @@ SELECT session_user is not null; | t | +----------------------------+ --- session_user and current_schema +-- current_schema -- SQLNESS PROTOCOL POSTGRES -select current_schema(); +select current_schema(), current_schemas(true), current_schemas(false), version(), current_database(); -+------------------+ -| current_schema() | -+------------------+ -| public | -+------------------+ ++------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+ +| current_schema() | current_schemas(Boolean(true)) | current_schemas(Boolean(false)) | version | current_database() | ++------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+ +| public | {public,information_schema,pg_catalog,greptime_private} | {public} | 16.3-greptimedb-1.0.0-beta.1 | greptime | ++------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+ -- search_path for pg using schema for now FIXME when support real search_path -- SQLNESS PROTOCOL POSTGRES diff --git a/tests/cases/standalone/common/system/pg_catalog.sql b/tests/cases/standalone/common/system/pg_catalog.sql index 960f3cb1ff..ac45192311 100644 --- a/tests/cases/standalone/common/system/pg_catalog.sql +++ b/tests/cases/standalone/common/system/pg_catalog.sql @@ -5,9 +5,9 @@ create database pg_catalog; -- SQLNESS PROTOCOL POSTGRES SELECT session_user is not null; --- session_user and current_schema +-- current_schema -- SQLNESS PROTOCOL POSTGRES -select current_schema(); +select current_schema(), current_schemas(true), current_schemas(false), version(), current_database(); -- search_path for pg using schema for now FIXME when support real search_path -- SQLNESS PROTOCOL POSTGRES