Skip to main content

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