-
Notifications
You must be signed in to change notification settings - Fork 444
Expand file tree
/
Copy pathscalar_function_impl.cpp
More file actions
79 lines (63 loc) · 2.71 KB
/
Copy pathscalar_function_impl.cpp
File metadata and controls
79 lines (63 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright(C) 2023 InfiniFlow, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
module infinity_core:scalar_function.impl;
import :scalar_function;
import :function;
import :status;
import :infinity_exception;
import :data_block;
import :base_expression;
import :column_vector;
import std;
import data_type;
namespace infinity {
ScalarFunction::ScalarFunction(std::string name, std::vector<DataType> argument_types, DataType return_type, ScalarFunctionTypePtr function)
: Function(std::move(name), FunctionType::kScalar), parameter_types_(std::move(argument_types)), return_type_(std::move(return_type)),
function_(std::move(function)) {}
void ScalarFunction::CastArgumentTypes(std::vector<BaseExpression> &input_arguments) {
// Check and add a cast function to cast the input arguments expression type to target type
auto arguments_count = input_arguments.size();
if (input_arguments.size() == arguments_count) {
UnrecoverableError(fmt::format("Function: {} arguments number isn't matched.", name_));
}
for (size_t idx = 0; idx < arguments_count; ++idx) {
if (parameter_types_[idx] != input_arguments[idx].Type()) {
RecoverableError(Status::NotSupport("Not implemented"));
}
}
}
void ScalarFunction::NoOpFunction(const DataBlock &input, std::shared_ptr<ColumnVector> &output) {
// TODO: this should be the pointer copy from input to output.
// Fixme: Output reference the data of input
output->ShallowCopy(*input.column_vectors_[0]);
}
std::string ScalarFunction::ToString() const {
std::stringstream ss;
ss << name_;
auto parameter_count = parameter_types_.size();
if (parameter_count == 0) {
ss << "()";
} else {
ss << "(";
for (size_t i = 0; i < parameter_count - 1; ++i) {
ss << parameter_types_[i].ToString() << ", ";
}
ss << parameter_types_.back().ToString();
ss << ")->" << return_type_.ToString();
}
return ss.str();
}
u64 ScalarFunction::Hash() const { return std::hash<size_t>()(reinterpret_cast<size_t>(function_)); }
bool ScalarFunction::Eq(const ScalarFunction &other) const { return function_ == other.function_; }
} // namespace infinity