Make result Bool only if arguments contain Bool

This commit is contained in:
avogar 2022-01-19 19:53:06 +03:00
parent ba54a5ff80
commit 2d975057d0
2 changed files with 28 additions and 24 deletions

View File

@ -484,10 +484,14 @@ DataTypePtr FunctionAnyArityLogical<Impl, Name>::getReturnTypeImpl(const DataTyp
ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION);
bool has_nullable_arguments = false;
bool has_bool_arguments = false;
for (size_t i = 0; i < arguments.size(); ++i)
{
const auto & arg_type = arguments[i];
if (isBool(arg_type))
has_bool_arguments = true;
if (!has_nullable_arguments)
{
has_nullable_arguments = arg_type->isNullable();
@ -504,7 +508,7 @@ DataTypePtr FunctionAnyArityLogical<Impl, Name>::getReturnTypeImpl(const DataTyp
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
auto result_type = DataTypeFactory::instance().get("Bool");
auto result_type = has_bool_arguments ? DataTypeFactory::instance().get("Bool") : std::make_shared<DataTypeUInt8>();
return has_nullable_arguments
? makeNullable(result_type)
: result_type;
@ -712,7 +716,7 @@ DataTypePtr FunctionUnaryLogical<Impl, Name>::getReturnTypeImpl(const DataTypes
+ ") of argument of function " + getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
return DataTypeFactory::instance().get("Bool");
return isBool(arguments[0]) ? DataTypeFactory::instance().get("Bool") : std::make_shared<DataTypeUInt8>();
}
template <template <typename> class Impl, typename T>

View File

@ -1,36 +1,36 @@
Bool
Bool
true
0
1
0
Bool
UInt8
UInt8
UInt8
false
1
0
true
Bool
UInt8
UInt8
Bool
true
0
1
false
Bool
Bool
Bool
Bool
false
true
false
true
Bool
Bool
Bool
UInt8
UInt8
Bool
true
false
true
false
Bool
Bool
Bool
Bool
true
true
true
1
1
true
Bool
Bool
Bool
UInt8
UInt8
Bool
true
false