forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemptyArray.cpp
75 lines (62 loc) · 2.41 KB
/
emptyArray.cpp
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
#include <Functions/IFunction.h>
#include <Functions/FunctionFactory.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/DataTypeString.h>
#include <Columns/ColumnArray.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h>
namespace DB
{
namespace
{
template <typename DataType>
class FunctionEmptyArray : public IFunction
{
public:
static String getNameImpl() { return "emptyArray" + DataType().getName(); }
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionEmptyArray>(); }
private:
String getName() const override
{
return getNameImpl();
}
size_t getNumberOfArguments() const override { return 0; }
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
{
return std::make_shared<DataTypeArray>(std::make_shared<DataType>());
}
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
ColumnPtr executeImpl(const ColumnsWithTypeAndName &, const DataTypePtr &, size_t input_rows_count) const override
{
return ColumnArray::create(
DataType().createColumn(),
ColumnArray::ColumnOffsets::create(input_rows_count, 0));
}
};
template <typename F>
void registerFunction(FunctionFactory & factory)
{
factory.registerFunction<F>(F::getNameImpl());
}
}
REGISTER_FUNCTION(EmptyArray)
{
registerFunction<FunctionEmptyArray<DataTypeUInt8>>(factory);
registerFunction<FunctionEmptyArray<DataTypeUInt16>>(factory);
registerFunction<FunctionEmptyArray<DataTypeUInt32>>(factory);
registerFunction<FunctionEmptyArray<DataTypeUInt64>>(factory);
registerFunction<FunctionEmptyArray<DataTypeInt8>>(factory);
registerFunction<FunctionEmptyArray<DataTypeInt16>>(factory);
registerFunction<FunctionEmptyArray<DataTypeInt32>>(factory);
registerFunction<FunctionEmptyArray<DataTypeInt64>>(factory);
registerFunction<FunctionEmptyArray<DataTypeFloat32>>(factory);
registerFunction<FunctionEmptyArray<DataTypeFloat64>>(factory);
registerFunction<FunctionEmptyArray<DataTypeDate>>(factory);
registerFunction<FunctionEmptyArray<DataTypeDateTime>>(factory);
registerFunction<FunctionEmptyArray<DataTypeString>>(factory);
}
}