| 1 | #include <Functions/IFunctionImpl.h> |
|---|---|
| 2 | #include <Functions/FunctionFactory.h> |
| 3 | #include <DataTypes/DataTypeArray.h> |
| 4 | #include <DataTypes/DataTypesNumber.h> |
| 5 | #include <DataTypes/DataTypeDate.h> |
| 6 | #include <DataTypes/DataTypeDateTime.h> |
| 7 | #include <DataTypes/DataTypeDateTime64.h> |
| 8 | #include <DataTypes/DataTypeString.h> |
| 9 | #include <Columns/ColumnArray.h> |
| 10 | #include <Columns/ColumnString.h> |
| 11 | #include <Columns/ColumnsNumber.h> |
| 12 | |
| 13 | |
| 14 | namespace DB |
| 15 | { |
| 16 | |
| 17 | /// TODO Make it simple. |
| 18 | |
| 19 | template <typename Type> struct TypeToColumnType { using ColumnType = ColumnVector<Type>; }; |
| 20 | template <> struct TypeToColumnType<String> { using ColumnType = ColumnString; }; |
| 21 | |
| 22 | template <typename DataType> struct DataTypeToName : TypeName<typename DataType::FieldType> { }; |
| 23 | template <> struct DataTypeToName<DataTypeDate> { static std::string get() { return "Date"; } }; |
| 24 | template <> struct DataTypeToName<DataTypeDateTime> { static std::string get() { return "DateTime"; } }; |
| 25 | |
| 26 | |
| 27 | template <typename DataType> |
| 28 | struct FunctionEmptyArray : public IFunction |
| 29 | { |
| 30 | static constexpr auto base_name = "emptyArray"; |
| 31 | static const String name; |
| 32 | static FunctionPtr create(const Context &) { return std::make_shared<FunctionEmptyArray>(); } |
| 33 | |
| 34 | private: |
| 35 | String getName() const override |
| 36 | { |
| 37 | return name; |
| 38 | } |
| 39 | |
| 40 | size_t getNumberOfArguments() const override { return 0; } |
| 41 | |
| 42 | DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override |
| 43 | { |
| 44 | return std::make_shared<DataTypeArray>(std::make_shared<DataType>()); |
| 45 | } |
| 46 | |
| 47 | void executeImpl(Block & block, const ColumnNumbers &, size_t result, size_t input_rows_count) override |
| 48 | { |
| 49 | using UnderlyingColumnType = typename TypeToColumnType<typename DataType::FieldType>::ColumnType; |
| 50 | |
| 51 | block.getByPosition(result).column = ColumnArray::create( |
| 52 | UnderlyingColumnType::create(), |
| 53 | ColumnArray::ColumnOffsets::create(input_rows_count, 0)); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | |
| 58 | template <typename DataType> |
| 59 | const String FunctionEmptyArray<DataType>::name = FunctionEmptyArray::base_name + String(DataTypeToName<DataType>::get()); |
| 60 | |
| 61 | using FunctionEmptyArrayUInt8 = FunctionEmptyArray<DataTypeUInt8>; |
| 62 | using FunctionEmptyArrayUInt16 = FunctionEmptyArray<DataTypeUInt16>; |
| 63 | using FunctionEmptyArrayUInt32 = FunctionEmptyArray<DataTypeUInt32>; |
| 64 | using FunctionEmptyArrayUInt64 = FunctionEmptyArray<DataTypeUInt64>; |
| 65 | using FunctionEmptyArrayInt8 = FunctionEmptyArray<DataTypeInt8>; |
| 66 | using FunctionEmptyArrayInt16 = FunctionEmptyArray<DataTypeInt16>; |
| 67 | using FunctionEmptyArrayInt32 = FunctionEmptyArray<DataTypeInt32>; |
| 68 | using FunctionEmptyArrayInt64 = FunctionEmptyArray<DataTypeInt64>; |
| 69 | using FunctionEmptyArrayFloat32 = FunctionEmptyArray<DataTypeFloat32>; |
| 70 | using FunctionEmptyArrayFloat64 = FunctionEmptyArray<DataTypeFloat64>; |
| 71 | using FunctionEmptyArrayDate = FunctionEmptyArray<DataTypeDate>; |
| 72 | using FunctionEmptyArrayDateTime = FunctionEmptyArray<DataTypeDateTime>; |
| 73 | using FunctionEmptyArrayString = FunctionEmptyArray<DataTypeString>; |
| 74 | |
| 75 | |
| 76 | void registerFunctionsEmptyArray(FunctionFactory & factory) |
| 77 | { |
| 78 | factory.registerFunction<FunctionEmptyArrayUInt8>(); |
| 79 | factory.registerFunction<FunctionEmptyArrayUInt16>(); |
| 80 | factory.registerFunction<FunctionEmptyArrayUInt32>(); |
| 81 | factory.registerFunction<FunctionEmptyArrayUInt64>(); |
| 82 | factory.registerFunction<FunctionEmptyArrayInt8>(); |
| 83 | factory.registerFunction<FunctionEmptyArrayInt16>(); |
| 84 | factory.registerFunction<FunctionEmptyArrayInt32>(); |
| 85 | factory.registerFunction<FunctionEmptyArrayInt64>(); |
| 86 | factory.registerFunction<FunctionEmptyArrayFloat32>(); |
| 87 | factory.registerFunction<FunctionEmptyArrayFloat64>(); |
| 88 | factory.registerFunction<FunctionEmptyArrayDate>(); |
| 89 | factory.registerFunction<FunctionEmptyArrayDateTime>(); |
| 90 | factory.registerFunction<FunctionEmptyArrayString>(); |
| 91 | } |
| 92 | |
| 93 | } |
| 94 |