1 | #include <Functions/IFunctionImpl.h> |
---|---|
2 | #include <Functions/FunctionHelpers.h> |
3 | #include <Functions/FunctionFactory.h> |
4 | #include <DataTypes/DataTypeNullable.h> |
5 | #include <Columns/ColumnNullable.h> |
6 | #include <Core/ColumnNumbers.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | |
12 | /// If value is not Nullable or NULL, wraps it to Nullable. |
13 | class FunctionToNullable : public IFunction |
14 | { |
15 | public: |
16 | static constexpr auto name = "toNullable"; |
17 | |
18 | static FunctionPtr create(const Context &) |
19 | { |
20 | return std::make_shared<FunctionToNullable>(); |
21 | } |
22 | |
23 | std::string getName() const override |
24 | { |
25 | return name; |
26 | } |
27 | |
28 | size_t getNumberOfArguments() const override { return 1; } |
29 | bool useDefaultImplementationForNulls() const override { return false; } |
30 | bool useDefaultImplementationForConstants() const override { return true; } |
31 | |
32 | DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override |
33 | { |
34 | return makeNullable(arguments[0]); |
35 | } |
36 | |
37 | void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t) override |
38 | { |
39 | block.getByPosition(result).column = makeNullable(block.getByPosition(arguments[0]).column); |
40 | } |
41 | }; |
42 | |
43 | |
44 | void registerFunctionToNullable(FunctionFactory & factory) |
45 | { |
46 | factory.registerFunction<FunctionToNullable>(); |
47 | } |
48 | |
49 | } |
50 |