1 | #include "FunctionArrayMapped.h" |
2 | #include <Functions/FunctionFactory.h> |
3 | |
4 | |
5 | namespace DB |
6 | { |
7 | |
8 | /** arrayMap(x1,...,xn -> expression, array1,...,arrayn) - apply the expression to each element of the array (or set of parallel arrays). |
9 | */ |
10 | struct ArrayMapImpl |
11 | { |
12 | /// true if the expression (for an overload of f(expression, arrays)) or an array (for f(array)) should be boolean. |
13 | static bool needBoolean() { return false; } |
14 | /// true if the f(array) overload is unavailable. |
15 | static bool needExpression() { return true; } |
16 | /// true if the array must be exactly one. |
17 | static bool needOneArray() { return false; } |
18 | |
19 | static DataTypePtr getReturnType(const DataTypePtr & expression_return, const DataTypePtr & /*array_element*/) |
20 | { |
21 | return std::make_shared<DataTypeArray>(expression_return); |
22 | } |
23 | |
24 | static ColumnPtr execute(const ColumnArray & array, ColumnPtr mapped) |
25 | { |
26 | return ColumnArray::create(mapped->convertToFullColumnIfConst(), array.getOffsetsPtr()); |
27 | } |
28 | }; |
29 | |
30 | struct NameArrayMap { static constexpr auto name = "arrayMap" ; }; |
31 | using FunctionArrayMap = FunctionArrayMapped<ArrayMapImpl, NameArrayMap>; |
32 | |
33 | void registerFunctionArrayMap(FunctionFactory & factory) |
34 | { |
35 | factory.registerFunction<FunctionArrayMap>(); |
36 | } |
37 | |
38 | } |
39 | |
40 | |
41 | |