common_function/
system.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
15mod build;
16mod database;
17mod pg_catalog;
18mod procedure_state;
19mod timezone;
20mod version;
21
22use build::BuildFunction;
23use database::{
24    ConnectionIdFunction, DatabaseFunction, PgBackendPidFunction, ReadPreferenceFunction,
25};
26use pg_catalog::PGCatalogFunction;
27use procedure_state::ProcedureStateFunction;
28use timezone::TimezoneFunction;
29use version::VersionFunction;
30
31use crate::function_registry::FunctionRegistry;
32
33pub(crate) struct SystemFunction;
34
35impl SystemFunction {
36    pub fn register(registry: &FunctionRegistry) {
37        registry.register_scalar(BuildFunction::default());
38        registry.register_scalar(VersionFunction::default());
39        registry.register_scalar(DatabaseFunction::default());
40        registry.register_scalar(ReadPreferenceFunction::default());
41        registry.register_scalar(PgBackendPidFunction::default());
42        registry.register_scalar(ConnectionIdFunction::default());
43        registry.register_scalar(TimezoneFunction::default());
44        registry.register(ProcedureStateFunction::factory());
45        PGCatalogFunction::register(registry);
46    }
47}
48
49macro_rules! define_nullary_udf {
50    ($(#[$attr:meta])* $name: ident) => {
51        $(#[$attr])*
52        #[derive(Clone, Debug, derive_more::Display)]
53        #[display("{}", self.name())]
54        pub(crate) struct $name {
55            signature: datafusion_expr::Signature,
56        }
57
58        impl Default for $name {
59            fn default() -> Self {
60                Self {
61                    signature: datafusion_expr::Signature::nullary(Volatility::Immutable),
62                }
63            }
64        }
65    };
66}
67
68pub(crate) use define_nullary_udf;