common_function/system/pg_catalog/
version.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::fmt;
16
17use datafusion::arrow::datatypes::DataType;
18use datafusion_common::ScalarValue;
19use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, Signature, Volatility};
20
21use crate::function::Function;
22
23#[derive(Clone, Debug)]
24pub(crate) struct PGVersionFunction {
25    signature: Signature,
26}
27
28impl Default for PGVersionFunction {
29    fn default() -> Self {
30        Self {
31            signature: Signature::exact(vec![], Volatility::Immutable),
32        }
33    }
34}
35
36impl fmt::Display for PGVersionFunction {
37    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38        write!(f, "pg_catalog.VERSION")
39    }
40}
41
42impl Function for PGVersionFunction {
43    fn name(&self) -> &str {
44        "pg_catalog.version"
45    }
46
47    fn return_type(&self, _: &[DataType]) -> datafusion_common::Result<DataType> {
48        Ok(DataType::Utf8View)
49    }
50
51    fn signature(&self) -> &Signature {
52        &self.signature
53    }
54
55    fn invoke_with_args(&self, _: ScalarFunctionArgs) -> datafusion_common::Result<ColumnarValue> {
56        Ok(ColumnarValue::Scalar(ScalarValue::Utf8View(Some(format!(
57            "PostgreSQL 16.3 GreptimeDB {}",
58            common_version::version()
59        )))))
60    }
61}