common_function/system/
version.rs1use datafusion::arrow::datatypes::DataType;
16use datafusion_common::ScalarValue;
17use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility};
18use session::context::Channel;
19
20use crate::function::{Function, find_function_context};
21use crate::system::define_nullary_udf;
22
23define_nullary_udf!(VersionFunction);
24
25impl Function for VersionFunction {
26 fn name(&self) -> &str {
27 "version"
28 }
29
30 fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
31 Ok(DataType::Utf8View)
32 }
33
34 fn signature(&self) -> &Signature {
35 &self.signature
36 }
37
38 fn invoke_with_args(
39 &self,
40 args: ScalarFunctionArgs,
41 ) -> datafusion_common::Result<ColumnarValue> {
42 let func_ctx = find_function_context(&args)?;
43 let version = match func_ctx.query_ctx.channel() {
44 Channel::Mysql => {
45 format!(
46 "{}-greptimedb-{}",
47 std::env::var("GREPTIMEDB_MYSQL_SERVER_VERSION")
48 .unwrap_or_else(|_| "8.4.2".to_string()),
49 common_version::version()
50 )
51 }
52 Channel::Postgres => {
53 format!("16.3-greptimedb-{}", common_version::version())
54 }
55 _ => common_version::version().to_string(),
56 };
57 Ok(ColumnarValue::Scalar(ScalarValue::Utf8View(Some(version))))
58 }
59}