drasi_core/evaluation/functions/
cypher_scalar.rs

1// Copyright 2024 The Drasi Authors.
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 char_length;
16mod coalesce;
17mod head;
18mod last;
19mod size;
20mod timestamp;
21mod to_boolean;
22mod to_float;
23mod to_integer;
24
25#[cfg(test)]
26mod tests;
27
28use std::sync::Arc;
29
30use char_length::CharLength;
31use coalesce::Coalesce;
32
33use super::{Function, FunctionRegistry};
34use head::Head;
35use last::Last;
36use size::Size;
37use timestamp::Timestamp;
38use to_boolean::{ToBoolean, ToBooleanOrNull};
39use to_float::{ToFloat, ToFloatOrNull};
40use to_integer::{ToInteger, ToIntegerOrNull};
41
42pub trait RegisterCypherScalarFunctions {
43    fn register_scalar_functions(&self);
44}
45
46impl RegisterCypherScalarFunctions for FunctionRegistry {
47    fn register_scalar_functions(&self) {
48        self.register_function("char_length", Function::Scalar(Arc::new(CharLength {})));
49        self.register_function(
50            "character_length",
51            Function::Scalar(Arc::new(CharLength {})),
52        );
53        self.register_function("size", Function::Scalar(Arc::new(Size {})));
54        self.register_function("toInteger", Function::Scalar(Arc::new(ToInteger {})));
55        self.register_function(
56            "toIntegerOrNull",
57            Function::Scalar(Arc::new(ToIntegerOrNull {})),
58        );
59        self.register_function("toFloat", Function::Scalar(Arc::new(ToFloat {})));
60        self.register_function(
61            "toFloatOrNull",
62            Function::Scalar(Arc::new(ToFloatOrNull {})),
63        );
64        self.register_function("toBoolean", Function::Scalar(Arc::new(ToBoolean {})));
65        self.register_function(
66            "toBooleanOrNull",
67            Function::Scalar(Arc::new(ToBooleanOrNull {})),
68        );
69        self.register_function("coalesce", Function::Scalar(Arc::new(Coalesce {})));
70        self.register_function("head", Function::Scalar(Arc::new(Head {})));
71        self.register_function("last", Function::Scalar(Arc::new(Last {})));
72        self.register_function("timestamp", Function::Scalar(Arc::new(Timestamp {})));
73    }
74}