mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #27788 from Avogar/nullable-decimal
Set function divide as suitable for short-circuit in case of Nullable(Decimal)
This commit is contained in:
commit
cd07cabada
@ -958,7 +958,7 @@ public:
|
||||
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & arguments) const override
|
||||
{
|
||||
return ((IsOperation<Op>::div_int || IsOperation<Op>::modulo) && !arguments[1].is_const)
|
||||
|| (IsOperation<Op>::div_floating && (isDecimal(arguments[0].type) || isDecimal(arguments[1].type)));
|
||||
|| (IsOperation<Op>::div_floating && (isDecimalOrNullableDecimal(arguments[0].type) || isDecimalOrNullableDecimal(arguments[1].type)));
|
||||
}
|
||||
|
||||
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
||||
|
@ -303,4 +303,14 @@ NullPresence getNullPresense(const ColumnsWithTypeAndName & args)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool isDecimalOrNullableDecimal(const DataTypePtr & type)
|
||||
{
|
||||
WhichDataType which(type);
|
||||
if (which.isDecimal())
|
||||
return true;
|
||||
if (!which.isNullable())
|
||||
return false;
|
||||
return isDecimal(assert_cast<const DataTypeNullable *>(type.get())->getNestedType());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <Common/assert_cast.h>
|
||||
#include <DataTypes/IDataType.h>
|
||||
#include <DataTypes/DataTypeNullable.h>
|
||||
#include <Columns/IColumn.h>
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
@ -171,4 +172,5 @@ struct NullPresence
|
||||
|
||||
NullPresence getNullPresense(const ColumnsWithTypeAndName & args);
|
||||
|
||||
bool isDecimalOrNullableDecimal(const DataTypePtr & type);
|
||||
}
|
||||
|
@ -1395,3 +1395,11 @@ Decimal32
|
||||
21
|
||||
14
|
||||
10.5
|
||||
0
|
||||
42
|
||||
21
|
||||
14
|
||||
10.5
|
||||
\N
|
||||
\N
|
||||
\N
|
||||
|
@ -123,3 +123,8 @@ select if(number > 0, intDiv(42, number), 1) from numbers(5);
|
||||
select if(number > 0, intDiv(42, number), 1) from numbers(5);
|
||||
|
||||
select if(number > 0, 42 / toDecimal32(number, 2), 0) from numbers(5);
|
||||
select if(number = 0, 0, toDecimal32(42, 2) / number) from numbers(5);
|
||||
select if(isNull(x), Null, 42 / x) from (select CAST(materialize(Null), 'Nullable(Decimal32(2))') as x);
|
||||
select if(isNull(x), Null, x / 0) from (select CAST(materialize(Null), 'Nullable(Decimal32(2))') as x);
|
||||
|
||||
select if(isNull(x), Null, intDiv(42, x)) from (select CAST(materialize(Null), 'Nullable(Int64)') as x);
|
||||
|
Loading…
Reference in New Issue
Block a user