| 1 | #include <Functions/IFunctionImpl.h> |
|---|---|
| 2 | #include <Functions/FunctionHelpers.h> |
| 3 | #include <Functions/FunctionFactory.h> |
| 4 | #include <DataTypes/DataTypeArray.h> |
| 5 | |
| 6 | |
| 7 | namespace DB |
| 8 | { |
| 9 | |
| 10 | namespace ErrorCodes |
| 11 | { |
| 12 | extern const int FUNCTION_IS_SPECIAL; |
| 13 | extern const int ILLEGAL_TYPE_OF_ARGUMENT; |
| 14 | } |
| 15 | |
| 16 | /** arrayJoin(arr) - a special function - it can not be executed directly; |
| 17 | * is used only to get the result type of the corresponding expression. |
| 18 | */ |
| 19 | class FunctionArrayJoin : public IFunction |
| 20 | { |
| 21 | public: |
| 22 | static constexpr auto name = "arrayJoin"; |
| 23 | static FunctionPtr create(const Context &) |
| 24 | { |
| 25 | return std::make_shared<FunctionArrayJoin>(); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | /// Get the function name. |
| 30 | String getName() const override |
| 31 | { |
| 32 | return name; |
| 33 | } |
| 34 | |
| 35 | size_t getNumberOfArguments() const override |
| 36 | { |
| 37 | return 1; |
| 38 | } |
| 39 | |
| 40 | /** It could return many different values for single argument. */ |
| 41 | bool isDeterministic() const override { return false; } |
| 42 | |
| 43 | bool isDeterministicInScopeOfQuery() const override |
| 44 | { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override |
| 49 | { |
| 50 | const DataTypeArray * arr = checkAndGetDataType<DataTypeArray>(arguments[0].get()); |
| 51 | if (!arr) |
| 52 | throw Exception("Argument for function "+ getName() + " must be Array.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
| 53 | |
| 54 | return arr->getNestedType(); |
| 55 | } |
| 56 | |
| 57 | void executeImpl(Block &, const ColumnNumbers &, size_t, size_t /*input_rows_count*/) override |
| 58 | { |
| 59 | throw Exception("Function "+ getName() + " must not be executed directly.", ErrorCodes::FUNCTION_IS_SPECIAL); |
| 60 | } |
| 61 | |
| 62 | /// Because of function cannot be executed directly. |
| 63 | bool isSuitableForConstantFolding() const override |
| 64 | { |
| 65 | return false; |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | void registerFunctionArrayJoin(FunctionFactory & factory) |
| 71 | { |
| 72 | factory.registerFunction<FunctionArrayJoin>(); |
| 73 | } |
| 74 | |
| 75 | } |
| 76 |