common_function/system/
version.rs1use std::sync::Arc;
16use std::{env, fmt};
17
18use common_query::error::Result;
19use common_query::prelude::{Signature, Volatility};
20use datatypes::data_type::ConcreteDataType;
21use datatypes::vectors::{StringVector, VectorRef};
22use session::context::Channel;
23
24use crate::function::{Function, FunctionContext};
25
26#[derive(Clone, Debug, Default)]
27pub(crate) struct VersionFunction;
28
29impl fmt::Display for VersionFunction {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 write!(f, "VERSION")
32 }
33}
34
35impl Function for VersionFunction {
36 fn name(&self) -> &str {
37 "version"
38 }
39
40 fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result<ConcreteDataType> {
41 Ok(ConcreteDataType::string_datatype())
42 }
43
44 fn signature(&self) -> Signature {
45 Signature::nullary(Volatility::Immutable)
46 }
47
48 fn eval(&self, func_ctx: &FunctionContext, _columns: &[VectorRef]) -> Result<VectorRef> {
49 let version = match func_ctx.query_ctx.channel() {
50 Channel::Mysql => {
51 format!(
52 "{}-greptimedb-{}",
53 std::env::var("GREPTIMEDB_MYSQL_SERVER_VERSION")
54 .unwrap_or_else(|_| "8.4.2".to_string()),
55 env!("CARGO_PKG_VERSION")
56 )
57 }
58 Channel::Postgres => {
59 format!("16.3-greptimedb-{}", env!("CARGO_PKG_VERSION"))
60 }
61 _ => env!("CARGO_PKG_VERSION").to_string(),
62 };
63 let result = StringVector::from(vec![version]);
64 Ok(Arc::new(result))
65 }
66}