This commit is contained in:
hexiaoting 2022-02-16 11:28:21 +08:00 committed by vdimir
parent 71aa411746
commit aeec4a62e7
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862
3 changed files with 12 additions and 6 deletions

View File

@ -70,7 +70,7 @@ public:
const DataTypeFunction * function_type = checkAndGetDataType<DataTypeFunction>(arguments[0].get());
if (!function_type || function_type->getArgumentTypes().size() != 2)
throw Exception("First argument for this overload of " + getName() + " must be a function with 2 arguments. Found "
+ arguments[0]->getName() + " instead.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
+ arguments[0]->getName() + " instead.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
arguments[0] = std::make_shared<DataTypeFunction>(nested_types);
}
@ -79,8 +79,8 @@ public:
{
if (arguments.size() != 2)
throw Exception("Function " + getName() + " needs at least 2 argument; passed "
+ toString(arguments.size()) + ".",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
+ toString(arguments.size()) + ".",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
const auto * data_type_function = checkAndGetDataType<DataTypeFunction>(arguments[0].type.get());

View File

@ -11,6 +11,7 @@ namespace DB
namespace ErrorCodes
{
extern const int ILLEGAL_COLUMN;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}
/** MapFilter(x -> predicate, array) - leave in the array only the elements for which the expression is true.
@ -87,10 +88,14 @@ struct MapApplyImpl
/// true if the expression (for an overload of f(expression, maps)) or a map (for f(map)) should be boolean.
static bool needBoolean() { return false; }
static DataTypePtr getReturnType(const DataTypePtr & expression_return, const DataTypes & )
static DataTypePtr getReturnType(const DataTypePtr & expression_return, const DataTypes & /*elems*/)
{
const auto * date_type_tuple = typeid_cast<const DataTypeTuple *>(&*expression_return);
return std::make_shared<DataTypeMap>(date_type_tuple->getElements());
const auto & tuple_types = typeid_cast<const DataTypeTuple *>(&*expression_return)->getElements();
if (tuple_types.size() != 2)
throw Exception("Expected 2 columns as map's key and value, but found "
+ toString(tuple_types.size()) + " columns", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
return std::make_shared<DataTypeMap>(tuple_types);
}
static ColumnPtr execute(const ColumnMap & map, ColumnPtr mapped)

View File

@ -9,4 +9,5 @@ SELECT mapApply((k,v)->(k,v+1), col) FROM table_map ORDER BY id;
SELECT mapApply((x, y) -> (x, x + 1), map(1, 0, 2, 0));
SELECT mapFilter((k,v)->0, col) from table_map;
SELECT mapUpdate(map(1, 3, 3, 2), map(1, 0, 2, 0));
SELECT mapApply((k, v) -> tuple(v + 9223372036854775806), col) FROM table_map; -- { serverError 42 }
DROP TABLE table_map;