Fix incorrect key condition of fixed strings.

This commit is contained in:
Amos Bird 2020-09-20 11:53:29 +08:00
parent 988b20a32c
commit fcee786320
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 21 additions and 0 deletions

View File

@ -191,7 +191,20 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
else if (which_type.isStringOrFixedString())
{
if (src.getType() == Field::Types::String)
{
if (which_type.isFixedString())
{
size_t n = assert_cast<const DataTypeFixedString &>(type).getN();
const auto & src_str = src.get<String>();
if (src_str.size() < n)
{
String src_str_extended = src_str;
src_str_extended.resize(n);
return src_str_extended;
}
}
return src;
}
}
else if (const DataTypeArray * type_array = typeid_cast<const DataTypeArray *>(&type))
{

View File

@ -0,0 +1,7 @@
DROP TABLE IF EXISTS test;
CREATE TABLE test(key FixedString(10)) ENGINE=MergeTree() PARTITION BY tuple() ORDER BY (key);
INSERT INTO test SELECT toString(intDiv(number, 8)) FROM numbers(100);
SELECT count() FROM test WHERE key = '1';
DROP TABLE IF EXISTS test;