Merge pull request #42469 from amosbird/issue_42456

Fix misbehavior of key analysis
This commit is contained in:
Alexey Milovidov 2022-10-28 16:18:00 +02:00 committed by GitHub
commit f64e632707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View File

@ -236,10 +236,11 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
} }
if (which_type.isDateTime64() if (which_type.isDateTime64()
&& (which_from_type.isNativeInt() || which_from_type.isNativeUInt() || which_from_type.isDate() || which_from_type.isDate32() || which_from_type.isDateTime() || which_from_type.isDateTime64())) && (src.getType() == Field::Types::UInt64 || src.getType() == Field::Types::Int64 || src.getType() == Field::Types::Decimal64))
{ {
const auto scale = static_cast<const DataTypeDateTime64 &>(type).getScale(); const auto scale = static_cast<const DataTypeDateTime64 &>(type).getScale();
const auto decimal_value = DecimalUtils::decimalFromComponents<DateTime64>(applyVisitor(FieldVisitorConvertToNumber<Int64>(), src), 0, scale); const auto decimal_value
= DecimalUtils::decimalFromComponents<DateTime64>(applyVisitor(FieldVisitorConvertToNumber<Int64>(), src), 0, scale);
return Field(DecimalField<DateTime64>(decimal_value, scale)); return Field(DecimalField<DateTime64>(decimal_value, scale));
} }
} }

View File

@ -1197,7 +1197,8 @@ bool KeyCondition::transformConstantWithValidFunctions(
if (is_valid_chain) if (is_valid_chain)
{ {
auto const_type = cur_node->result_type; out_type = removeLowCardinality(out_type);
auto const_type = removeLowCardinality(cur_node->result_type);
auto const_column = out_type->createColumnConst(1, out_value); auto const_column = out_type->createColumnConst(1, out_value);
auto const_value = (*castColumnAccurateOrNull({const_column, out_type, ""}, const_type))[0]; auto const_value = (*castColumnAccurateOrNull({const_column, out_type, ""}, const_type))[0];

View File

@ -0,0 +1,9 @@
drop table if exists test;
create table test (Printer LowCardinality(String), IntervalStart DateTime) engine MergeTree partition by (hiveHash(Printer), toYear(IntervalStart)) order by (Printer, IntervalStart);
insert into test values ('printer1', '2006-02-07 06:28:15');
select Printer from test where Printer='printer1';
drop table test;