Skip to content

Commit 2bbc4bc

Browse files
authored
fix: correct signature of current_schemas function (#7233)
1 parent b1525e5 commit 2bbc4bc

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

src/common/function/src/system/pg_catalog.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ use datafusion::arrow::array::{ArrayRef, StringArray, as_boolean_array};
2323
use datafusion::catalog::TableFunction;
2424
use datafusion::common::ScalarValue;
2525
use datafusion::common::utils::SingleRowListArrayBuilder;
26-
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility};
26+
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, TypeSignature, Volatility};
2727
use datafusion_pg_catalog::pg_catalog::{self, PgCatalogStaticTables};
2828
use datatypes::arrow::datatypes::{DataType, Field};
29+
use derive_more::derive::Display;
2930
use version::PGVersionFunction;
3031

3132
use crate::function::{Function, find_function_context};
@@ -38,7 +39,6 @@ const SESSION_USER_FUNCTION_NAME: &str = "session_user";
3839
const CURRENT_DATABASE_FUNCTION_NAME: &str = "current_database";
3940

4041
define_nullary_udf!(CurrentSchemaFunction);
41-
define_nullary_udf!(CurrentSchemasFunction);
4242
define_nullary_udf!(SessionUserFunction);
4343
define_nullary_udf!(CurrentDatabaseFunction);
4444

@@ -118,16 +118,33 @@ impl Function for SessionUserFunction {
118118
}
119119
}
120120

121+
#[derive(Display, Debug)]
122+
#[display("{}", self.name())]
123+
pub(super) struct CurrentSchemasFunction {
124+
signature: Signature,
125+
}
126+
127+
impl CurrentSchemasFunction {
128+
pub fn new() -> Self {
129+
Self {
130+
signature: Signature::new(
131+
TypeSignature::Exact(vec![DataType::Boolean]),
132+
Volatility::Stable,
133+
),
134+
}
135+
}
136+
}
137+
121138
impl Function for CurrentSchemasFunction {
122139
fn name(&self) -> &str {
123140
CURRENT_SCHEMAS_FUNCTION_NAME
124141
}
125142

126143
fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
127144
Ok(DataType::List(Arc::new(Field::new(
128-
"x",
129-
DataType::Utf8View,
130-
false,
145+
"item",
146+
DataType::Utf8,
147+
true,
131148
))))
132149
}
133150

@@ -168,7 +185,7 @@ impl PGCatalogFunction {
168185

169186
registry.register_scalar(PGVersionFunction::default());
170187
registry.register_scalar(CurrentSchemaFunction::default());
171-
registry.register_scalar(CurrentSchemasFunction::default());
188+
registry.register_scalar(CurrentSchemasFunction::new());
172189
registry.register_scalar(SessionUserFunction::default());
173190
registry.register_scalar(CurrentDatabaseFunction::default());
174191
registry.register(pg_catalog::format_type::create_format_type_udf());

tests/cases/standalone/common/system/pg_catalog.result

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ SELECT session_user is not null;
1313
| t |
1414
+----------------------------+
1515

16-
-- session_user and current_schema
16+
-- current_schema
1717
-- SQLNESS PROTOCOL POSTGRES
18-
select current_schema();
18+
select current_schema(), current_schemas(true), current_schemas(false), version(), current_database();
1919

20-
+------------------+
21-
| current_schema() |
22-
+------------------+
23-
| public |
24-
+------------------+
20+
+------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+
21+
| current_schema() | current_schemas(Boolean(true)) | current_schemas(Boolean(false)) | version | current_database() |
22+
+------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+
23+
| public | {public,information_schema,pg_catalog,greptime_private} | {public} | 16.3-greptimedb-1.0.0-beta.1 | greptime |
24+
+------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+
2525

2626
-- search_path for pg using schema for now FIXME when support real search_path
2727
-- SQLNESS PROTOCOL POSTGRES

tests/cases/standalone/common/system/pg_catalog.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ create database pg_catalog;
55
-- SQLNESS PROTOCOL POSTGRES
66
SELECT session_user is not null;
77

8-
-- session_user and current_schema
8+
-- current_schema
99
-- SQLNESS PROTOCOL POSTGRES
10-
select current_schema();
10+
select current_schema(), current_schemas(true), current_schemas(false), version(), current_database();
1111

1212
-- search_path for pg using schema for now FIXME when support real search_path
1313
-- SQLNESS PROTOCOL POSTGRES

0 commit comments

Comments
 (0)