1 | #include <Functions/IFunctionImpl.h> |
---|---|
2 | #include <Functions/FunctionFactory.h> |
3 | #include <DataTypes/DataTypesNumber.h> |
4 | #include <Columns/ColumnsNumber.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | /** ignoreExceptNull(...) is a function that takes any arguments, and always returns 0 except Null. |
11 | */ |
12 | class FunctionIgnoreExceptNull : public IFunction |
13 | { |
14 | public: |
15 | static constexpr auto name = "ignoreExceptNull"; |
16 | static FunctionPtr create(const Context &) |
17 | { |
18 | return std::make_shared<FunctionIgnoreExceptNull>(); |
19 | } |
20 | |
21 | bool isVariadic() const override |
22 | { |
23 | return true; |
24 | } |
25 | size_t getNumberOfArguments() const override |
26 | { |
27 | return 0; |
28 | } |
29 | |
30 | String getName() const override |
31 | { |
32 | return name; |
33 | } |
34 | |
35 | DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override |
36 | { |
37 | return std::make_shared<DataTypeUInt8>(); |
38 | } |
39 | |
40 | void executeImpl(Block & block, const ColumnNumbers &, size_t result, size_t input_rows_count) override |
41 | { |
42 | /// This function is mainly used in query analysis instead of "in" functions |
43 | /// in the case when only header is needed and set for in is not calculated. |
44 | /// Because of that function must return the same column type as "in" function, which is ColumnUInt8. |
45 | auto res = ColumnUInt8::create(input_rows_count, 0); |
46 | block.getByPosition(result).column = std::move(res); |
47 | } |
48 | }; |
49 | |
50 | |
51 | void registerFunctionIgnoreExceptNull(FunctionFactory & factory) |
52 | { |
53 | factory.registerFunction<FunctionIgnoreExceptNull>(); |
54 | } |
55 | |
56 | } |
57 |