From c22a398f59028c08310963cf9ddd2639e602c060 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Sun, 8 Sep 2024 20:36:54 -0700 Subject: [PATCH] fix: return version string based on request protocol (#4680) * fix: return version string based on request protocol * fix: resolve lint issue --- src/common/function/src/system/version.rs | 22 ++++++++++++++----- src/servers/src/postgres.rs | 2 +- .../standalone/common/function/system.result | 12 +++++----- .../standalone/common/function/system.sql | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/common/function/src/system/version.rs b/src/common/function/src/system/version.rs index 1817583590f..0843ec23635 100644 --- a/src/common/function/src/system/version.rs +++ b/src/common/function/src/system/version.rs @@ -19,6 +19,7 @@ use common_query::error::Result; use common_query::prelude::{Signature, Volatility}; use datatypes::data_type::ConcreteDataType; use datatypes::vectors::{StringVector, VectorRef}; +use session::context::Channel; use crate::function::{Function, FunctionContext}; @@ -44,11 +45,22 @@ impl Function for VersionFunction { Signature::exact(vec![], Volatility::Immutable) } - fn eval(&self, _func_ctx: FunctionContext, _columns: &[VectorRef]) -> Result { - let result = StringVector::from(vec![format!( - "5.7.20-greptimedb-{}", - env!("CARGO_PKG_VERSION") - )]); + fn eval(&self, func_ctx: FunctionContext, _columns: &[VectorRef]) -> Result { + let version = match func_ctx.query_ctx.channel() { + Channel::Mysql => { + format!( + "{}-greptimedb-{}", + std::env::var("GREPTIMEDB_MYSQL_SERVER_VERSION") + .unwrap_or_else(|_| "8.4.2".to_string()), + env!("CARGO_PKG_VERSION") + ) + } + Channel::Postgres => { + format!("16.3-greptimedb-{}", env!("CARGO_PKG_VERSION")) + } + _ => env!("CARGO_PKG_VERSION").to_string(), + }; + let result = StringVector::from(vec![version]); Ok(Arc::new(result)) } } diff --git a/src/servers/src/postgres.rs b/src/servers/src/postgres.rs index 42683ff680f..36f6730b43d 100644 --- a/src/servers/src/postgres.rs +++ b/src/servers/src/postgres.rs @@ -48,7 +48,7 @@ pub(crate) struct GreptimeDBStartupParameters { impl GreptimeDBStartupParameters { fn new() -> GreptimeDBStartupParameters { GreptimeDBStartupParameters { - version: format!("16.3-greptime-{}", env!("CARGO_PKG_VERSION")), + version: format!("16.3-greptimedb-{}", env!("CARGO_PKG_VERSION")), } } } diff --git a/tests/cases/standalone/common/function/system.result b/tests/cases/standalone/common/function/system.result index ba03e47f138..8abcb1e9157 100644 --- a/tests/cases/standalone/common/function/system.result +++ b/tests/cases/standalone/common/function/system.result @@ -8,12 +8,12 @@ SELECT build(); ++|build()|++|branch:BRANCH|commit:COMMIT|commit_short:COMMIT_SHORT|clean:CLEAN|version:VERSION++ --- SQLNESS REPLACE greptimedb-[\d\.]+ greptimedb-VERSION +-- SQLNESS REPLACE [\d\.]+ VERSION SELECT version(); -+-------------------------+ -| version() | -+-------------------------+ -| 5.7.20-greptimedb-VERSION | -+-------------------------+ ++-----------+ +| version() | ++-----------+ +| VERSION | ++-----------+ diff --git a/tests/cases/standalone/common/function/system.sql b/tests/cases/standalone/common/function/system.sql index d945c8baf80..368dcdc5c5e 100644 --- a/tests/cases/standalone/common/function/system.sql +++ b/tests/cases/standalone/common/function/system.sql @@ -6,5 +6,5 @@ -- SQLNESS REPLACE [\s\-]+ SELECT build(); --- SQLNESS REPLACE greptimedb-[\d\.]+ greptimedb-VERSION +-- SQLNESS REPLACE [\d\.]+ VERSION SELECT version();