diff --git a/src/DataTypes/Serializations/SerializationString.cpp b/src/DataTypes/Serializations/SerializationString.cpp index 5bcbf2d3fdf..59861ee18b9 100644 --- a/src/DataTypes/Serializations/SerializationString.cpp +++ b/src/DataTypes/Serializations/SerializationString.cpp @@ -84,11 +84,12 @@ void SerializationString::deserializeBinary(IColumn & column, ReadBuffer & istr) void SerializationString::serializeBinaryBulk(const IColumn & column, WriteBuffer & ostr, size_t offset, size_t limit) const { - const ColumnString & column_string = typeid_cast(column); + const auto & full_column = column.convertToFullColumnIfLowCardinality(); + const ColumnString & column_string = typeid_cast(*full_column); const ColumnString::Chars & data = column_string.getChars(); const ColumnString::Offsets & offsets = column_string.getOffsets(); - size_t size = column.size(); + size_t size = column_string.size(); if (!size) return; diff --git a/tests/queries/0_stateless/02475_bad_cast_low_cardinality_to_string_bug.reference b/tests/queries/0_stateless/02475_bad_cast_low_cardinality_to_string_bug.reference new file mode 100644 index 00000000000..4ffc8576e57 --- /dev/null +++ b/tests/queries/0_stateless/02475_bad_cast_low_cardinality_to_string_bug.reference @@ -0,0 +1,2 @@ +bbbbb +bbbbb diff --git a/tests/queries/0_stateless/02475_bad_cast_low_cardinality_to_string_bug.sql b/tests/queries/0_stateless/02475_bad_cast_low_cardinality_to_string_bug.sql new file mode 100644 index 00000000000..3b2abfb3c42 --- /dev/null +++ b/tests/queries/0_stateless/02475_bad_cast_low_cardinality_to_string_bug.sql @@ -0,0 +1 @@ +SELECT if(materialize(0), extract(materialize(CAST('aaaaaa', 'LowCardinality(String)')), '\\w'), extract(materialize(CAST('bbbbb', 'LowCardinality(String)')), '\\w*')) AS res FROM numbers(2);