Better code

This commit is contained in:
Alexey Milovidov 2020-08-03 00:01:39 +03:00
parent 3c489ce159
commit 4ed0bf3af1

View File

@ -464,7 +464,7 @@ static Field applyFunctionForField(
}
/// The case when arguments may have types different than in the primary key.
static Field applyFunctionForField(
static std::pair<Field, DataTypePtr> applyFunctionForFieldOfUnknownType(
const FunctionOverloadResolverPtr & func,
const DataTypePtr & arg_type,
const Field & arg_value)
@ -473,14 +473,19 @@ static Field applyFunctionForField(
FunctionBasePtr func_base = func->build({argument});
DataTypePtr return_type = func_base->getReturnType();
Block block
{
std::move(argument),
{ nullptr, func_base->getReturnType(), "y" }
{ nullptr, return_type, "result" }
};
func_base->execute(block, {0}, 1, 1);
return (*block.safeGetByPosition(1).column)[0];
Field result = (*block.safeGetByPosition(1).column)[0];
return {std::move(result), std::move(return_type)};
}
@ -577,11 +582,10 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
return false;
/// Apply the next transformation step.
out_value = applyFunctionForField(
std::tie(out_value, out_type) = applyFunctionForFieldOfUnknownType(
action.function_builder,
out_type, out_value);
out_type = action.function_base->getReturnType();
expr_name = action.result_name;
/// Transformation results in a key expression, accept.