From 29d23e0ba130c274c42bb055251281b8c59f8dbd Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Fri, 21 Nov 2025 11:30:11 +0800 Subject: [PATCH] fix: return sqlalchemy compatible version string in version() (#7271) --- src/common/function/src/system/pg_catalog.rs | 4 -- .../function/src/system/pg_catalog/version.rs | 61 ------------------- src/common/function/src/system/version.rs | 2 +- .../common/system/pg_catalog.result | 12 ++-- .../standalone/common/system/pg_catalog.sql | 2 +- 5 files changed, 8 insertions(+), 73 deletions(-) delete mode 100644 src/common/function/src/system/pg_catalog/version.rs diff --git a/src/common/function/src/system/pg_catalog.rs b/src/common/function/src/system/pg_catalog.rs index 0924b58175..8f20b5ea8e 100644 --- a/src/common/function/src/system/pg_catalog.rs +++ b/src/common/function/src/system/pg_catalog.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod version; - use std::sync::Arc; use common_catalog::consts::{ @@ -27,7 +25,6 @@ use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, TypeSignatur 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}; use crate::function_registry::FunctionRegistry; @@ -183,7 +180,6 @@ impl PGCatalogFunction { let static_tables = Arc::new(PgCatalogStaticTables::try_new().expect("load postgres static tables")); - registry.register_scalar(PGVersionFunction::default()); registry.register_scalar(CurrentSchemaFunction::default()); registry.register_scalar(CurrentSchemasFunction::new()); registry.register_scalar(SessionUserFunction::default()); diff --git a/src/common/function/src/system/pg_catalog/version.rs b/src/common/function/src/system/pg_catalog/version.rs deleted file mode 100644 index 9acdd39472..0000000000 --- a/src/common/function/src/system/pg_catalog/version.rs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2023 Greptime Team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::fmt; - -use datafusion::arrow::datatypes::DataType; -use datafusion_common::ScalarValue; -use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility}; - -use crate::function::Function; - -#[derive(Clone, Debug)] -pub(crate) struct PGVersionFunction { - signature: Signature, -} - -impl Default for PGVersionFunction { - fn default() -> Self { - Self { - signature: Signature::exact(vec![], Volatility::Immutable), - } - } -} - -impl fmt::Display for PGVersionFunction { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "pg_catalog.VERSION") - } -} - -impl Function for PGVersionFunction { - fn name(&self) -> &str { - "pg_catalog.version" - } - - fn return_type(&self, _: &[DataType]) -> datafusion_common::Result { - Ok(DataType::Utf8View) - } - - fn signature(&self) -> &Signature { - &self.signature - } - - fn invoke_with_args(&self, _: ScalarFunctionArgs) -> datafusion_common::Result { - Ok(ColumnarValue::Scalar(ScalarValue::Utf8View(Some(format!( - "PostgreSQL 16.3 GreptimeDB {}", - common_version::version() - ))))) - } -} diff --git a/src/common/function/src/system/version.rs b/src/common/function/src/system/version.rs index 369ad14080..1c148bd7ab 100644 --- a/src/common/function/src/system/version.rs +++ b/src/common/function/src/system/version.rs @@ -50,7 +50,7 @@ impl Function for VersionFunction { ) } Channel::Postgres => { - format!("16.3-greptimedb-{}", common_version::version()) + format!("PostgreSQL 16.3 GreptimeDB {}", common_version::version()) } _ => common_version::version().to_string(), }; diff --git a/tests/cases/standalone/common/system/pg_catalog.result b/tests/cases/standalone/common/system/pg_catalog.result index 173ac3a811..bb1ad87683 100644 --- a/tests/cases/standalone/common/system/pg_catalog.result +++ b/tests/cases/standalone/common/system/pg_catalog.result @@ -13,16 +13,16 @@ SELECT session_user is not null; | t | +----------------------------+ --- SQLNESS REPLACE (\d+(?:\.\d+)*)-greptimedb-(\d+(?:\.\d+)*(?:-[a-zA-Z0-9-.]+)?) PG_VERSION-greptimedb-VERSION +-- SQLNESS REPLACE PostgreSQL.* VERSION -- current_schema -- SQLNESS PROTOCOL POSTGRES select current_schema(), current_schemas(true), current_schemas(false), version(), current_database(); -+------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+ -| current_schema() | current_schemas(Boolean(true)) | current_schemas(Boolean(false)) | version | current_database() | -+------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+ -| public | {public,information_schema,pg_catalog,greptime_private} | {public} | PG_VERSION-greptimedb-VERSION | greptime | -+------------------+---------------------------------------------------------+---------------------------------+------------------------------+--------------------+ ++------------------+---------------------------------------------------------+---------------------------------+-----------------------------------------+--------------------+ +| current_schema() | current_schemas(Boolean(true)) | current_schemas(Boolean(false)) | version | current_database() | ++------------------+---------------------------------------------------------+---------------------------------+-----------------------------------------+--------------------+ +| public | {public,information_schema,pg_catalog,greptime_private} | {public} | VERSION ++------------------+---------------------------------------------------------+---------------------------------+-----------------------------------------+--------------------+ -- 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 5eb1dc1211..d0d0649eb4 100644 --- a/tests/cases/standalone/common/system/pg_catalog.sql +++ b/tests/cases/standalone/common/system/pg_catalog.sql @@ -5,7 +5,7 @@ create database pg_catalog; -- SQLNESS PROTOCOL POSTGRES SELECT session_user is not null; --- SQLNESS REPLACE (\d+(?:\.\d+)*)-greptimedb-(\d+(?:\.\d+)*(?:-[a-zA-Z0-9-.]+)?) PG_VERSION-greptimedb-VERSION +-- SQLNESS REPLACE PostgreSQL.* VERSION -- current_schema -- SQLNESS PROTOCOL POSTGRES select current_schema(), current_schemas(true), current_schemas(false), version(), current_database();