fix: correct signature of current_schemas function (#7233)

This commit is contained in:
Ning Sun
2025-11-16 20:42:09 -05:00
committed by GitHub
parent b1525e566b
commit 2bbc4bc4bc
3 changed files with 32 additions and 15 deletions

View File

@@ -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<DataType> {
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());

View File

@@ -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

View File

@@ -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