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/DataTypeFactory.h>
#include <Columns/ColumnArray.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h>
namespace DB
{
namespace
{
class FunctionEmptyArray : public IFunction
{
private:
String element_type;
public:
static String getNameImpl(const String & element_type) { return "emptyArray" + element_type; }
explicit FunctionEmptyArray(const String & element_type_) : element_type(element_type_) {}
private:
String getName() const override
{
return getNameImpl(element_type);
}
size_t getNumberOfArguments() const override { return 0; }
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
{
return std::make_shared<DataTypeArray>(DataTypeFactory::instance().get(element_type));
}
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(
DataTypeFactory::instance().get(element_type)->createColumn(),
ColumnArray::ColumnOffsets::create(input_rows_count, 0));
}
};
void registerFunction(FunctionFactory & factory, const String & element_type)
{
factory.registerFunction(FunctionEmptyArray::getNameImpl(element_type),
[element_type](ContextPtr){ return std::make_unique<FunctionToOverloadResolverAdaptor>(
std::make_shared<FunctionEmptyArray>(element_type)); });
}
}
REGISTER_FUNCTION(EmptyArray)
{
registerFunction(factory, "UInt8");
registerFunction(factory, "UInt16");
registerFunction(factory, "UInt32");
registerFunction(factory, "UInt64");
registerFunction(factory, "Int8");
registerFunction(factory, "Int16");
registerFunction(factory, "Int32");
registerFunction(factory, "Int64");
registerFunction(factory, "Float32");
registerFunction(factory, "Float64");
registerFunction(factory, "Date");
registerFunction(factory, "DateTime");
registerFunction(factory, "String");
}
}
|