mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-01 03:52:15 +00:00
Move validations to transformArguments
This commit is contained in:
parent
c85aa0a4d6
commit
715766d7ec
@ -24,22 +24,40 @@ public:
|
|||||||
|
|
||||||
const auto * map_type = checkAndGetDataType<DataTypeMap>(arguments[0].get());
|
const auto * map_type = checkAndGetDataType<DataTypeMap>(arguments[0].get());
|
||||||
if (map_type)
|
if (map_type)
|
||||||
|
{
|
||||||
|
if (arguments->size() > 1)
|
||||||
|
throw Exception(
|
||||||
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
|
||||||
|
getName() + " combinator takes only one map argument");
|
||||||
|
|
||||||
return DataTypes({map_type->getValueType()});
|
return DataTypes({map_type->getValueType()});
|
||||||
|
}
|
||||||
|
|
||||||
// we need this part just to pass to redirection for mapped arrays
|
// we need this part just to pass to redirection for mapped arrays
|
||||||
|
auto check_func = [](DataTypePtr t)
|
||||||
|
{
|
||||||
|
return t->getTypeId() == TypeIndex::Array;
|
||||||
|
};
|
||||||
|
|
||||||
const auto * tup_type = checkAndGetDataType<DataTypeTuple>(arguments[0].get());
|
const auto * tup_type = checkAndGetDataType<DataTypeTuple>(arguments[0].get());
|
||||||
if (tup_type)
|
if (tup_type)
|
||||||
{
|
{
|
||||||
const auto * val_array_type = checkAndGetDataType<DataTypeArray>(tup_type->getElements()[1].get());
|
const auto & types = tup_type->getElements();
|
||||||
if (val_array_type)
|
bool arrays_match = arguments.size() == 1 && types.size() >= 2 && std::all_of(types.begin(), types.end(), check_func);
|
||||||
return DataTypes({val_array_type->getNestedType()});
|
if (arrays_match)
|
||||||
|
{
|
||||||
|
const auto & val_array_type = assert_cast<const DataTypeArray &>(types[1]);
|
||||||
|
return DataTypes({val_array_type.getNestedType()});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (arguments.size() >= 2)
|
|
||||||
{
|
{
|
||||||
const auto * val_array_type = checkAndGetDataType<DataTypeArray>(arguments[1].get());
|
bool arrays_match = arguments.size() >= 2 && std::all_of(arguments.begin(), arguments.end(), check_func);
|
||||||
if (val_array_type)
|
if (arrays_match)
|
||||||
|
{
|
||||||
|
const auto & val_array_type = assert_cast<const DataTypeArray &>(arguments[1]);
|
||||||
return DataTypes({val_array_type->getNestedType()});
|
return DataTypes({val_array_type->getNestedType()});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Aggregate function " + getName() + " requires map as argument");
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Aggregate function " + getName() + " requires map as argument");
|
||||||
@ -87,37 +105,15 @@ public:
|
|||||||
throw Exception{"Illegal columns in arguments for combinator " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
|
throw Exception{"Illegal columns in arguments for combinator " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!arguments.empty())
|
else
|
||||||
{
|
{
|
||||||
// check if we got tuple of arrays or just arrays and if so, try to redirect to sum/min/max-MappedArrays to implement old behavior
|
// in case of tuple of arrays or just arrays (checked in transformArguments), try to redirect to sum/min/max-MappedArrays to implement old behavior
|
||||||
auto nested_func_name = nested_function->getName();
|
auto nested_func_name = nested_function->getName();
|
||||||
if (nested_func_name == "sum" || nested_func_name == "min" || nested_func_name == "max")
|
if (nested_func_name == "sum" || nested_func_name == "min" || nested_func_name == "max")
|
||||||
{
|
{
|
||||||
bool match;
|
AggregateFunctionProperties out_properties;
|
||||||
const auto * tup_type = checkAndGetDataType<DataTypeTuple>(arguments[0].get());
|
auto & aggr_func_factory = AggregateFunctionFactory::instance();
|
||||||
|
return aggr_func_factory.get(nested_func_name + "MappedArrays", arguments, params, out_properties);
|
||||||
auto check_func = [](DataTypePtr t)
|
|
||||||
{
|
|
||||||
return t->getTypeId() == TypeIndex::Array;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (tup_type)
|
|
||||||
{
|
|
||||||
const auto & types = tup_type->getElements();
|
|
||||||
match = arguments.size() == 1 && types.size() >= 2 && std::all_of(types.begin(), types.end(), check_func);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// sumMappedArrays and others support more than 2 mapped arrays
|
|
||||||
match = arguments.size() >= 2 && std::all_of(arguments.begin(), arguments.end(), check_func);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match)
|
|
||||||
{
|
|
||||||
AggregateFunctionProperties out_properties;
|
|
||||||
auto & aggr_func_factory = AggregateFunctionFactory::instance();
|
|
||||||
return aggr_func_factory.get(nested_func_name + "MappedArrays", arguments, params, out_properties);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user