mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-22 22:20:02 +00:00
fix: return sqlalchemy compatible version string in version() (#7271)
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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<DataType> {
|
||||
Ok(DataType::Utf8View)
|
||||
}
|
||||
|
||||
fn signature(&self) -> &Signature {
|
||||
&self.signature
|
||||
}
|
||||
|
||||
fn invoke_with_args(&self, _: ScalarFunctionArgs) -> datafusion_common::Result<ColumnarValue> {
|
||||
Ok(ColumnarValue::Scalar(ScalarValue::Utf8View(Some(format!(
|
||||
"PostgreSQL 16.3 GreptimeDB {}",
|
||||
common_version::version()
|
||||
)))))
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user