mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-12 01:12:12 +00:00
Handle Nullable conversions in LowCardinality
For `k::LowCardinality(UInt8)`, the resolution of `k IN (1, NULL)` results in type LowCardinality(UInt8). This commit converts the return type to LowCardinality(Nullable(UInt8)).
This commit is contained in:
parent
04b5a5587e
commit
844001779d
@ -551,14 +551,25 @@ private:
|
|||||||
|
|
||||||
in_function->getArguments().getNodes() = std::move(in_arguments);
|
in_function->getArguments().getNodes() = std::move(in_arguments);
|
||||||
in_function->resolveAsFunction(in_function_resolver);
|
in_function->resolveAsFunction(in_function_resolver);
|
||||||
|
|
||||||
|
DataTypePtr result_type = in_function->getResultType();
|
||||||
|
const auto * type_low_cardinality = typeid_cast<const DataTypeLowCardinality *>(result_type.get());
|
||||||
|
if (type_low_cardinality)
|
||||||
|
result_type = type_low_cardinality->getDictionaryType();
|
||||||
/** For `k :: UInt8`, expression `k = 1 OR k = NULL` with result type Nullable(UInt8)
|
/** For `k :: UInt8`, expression `k = 1 OR k = NULL` with result type Nullable(UInt8)
|
||||||
* is replaced with `k IN (1, NULL)` with result type UInt8.
|
* is replaced with `k IN (1, NULL)` with result type UInt8.
|
||||||
* Convert it back to Nullable(UInt8).
|
* Convert it back to Nullable(UInt8).
|
||||||
|
* And for `k :: LowCardinality(UInt8)`, the transformation of `k IN (1, NULL)` results in type LowCardinality(UInt8).
|
||||||
|
* Convert it to LowCardinality(Nullable(UInt8)).
|
||||||
*/
|
*/
|
||||||
if (is_any_nullable && !in_function->getResultType()->isNullable())
|
if (is_any_nullable && !result_type->isNullable())
|
||||||
{
|
{
|
||||||
auto nullable_result_type = std::make_shared<DataTypeNullable>(in_function->getResultType());
|
DataTypePtr new_result_type = std::make_shared<DataTypeNullable>(result_type);
|
||||||
auto in_function_nullable = createCastFunction(std::move(in_function), std::move(nullable_result_type), getContext());
|
if (type_low_cardinality)
|
||||||
|
{
|
||||||
|
new_result_type = std::make_shared<DataTypeLowCardinality>(new_result_type);
|
||||||
|
}
|
||||||
|
auto in_function_nullable = createCastFunction(std::move(in_function), std::move(new_result_type), getContext());
|
||||||
or_operands.push_back(std::move(in_function_nullable));
|
or_operands.push_back(std::move(in_function_nullable));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user