From b67405915e6c41de92a3098a87086744455b2137 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Tue, 12 Jul 2022 02:01:41 +0000 Subject: [PATCH 1/4] keep LowCardinality type in tuple() function --- src/Functions/tuple.cpp | 1 + .../0_stateless/02354_tuple_lowcardinality.reference | 4 ++++ tests/queries/0_stateless/02354_tuple_lowcardinality.sql | 6 ++++++ 3 files changed, 11 insertions(+) create mode 100644 tests/queries/0_stateless/02354_tuple_lowcardinality.reference create mode 100644 tests/queries/0_stateless/02354_tuple_lowcardinality.sql diff --git a/src/Functions/tuple.cpp b/src/Functions/tuple.cpp index 4238b12157a..5e85984bee0 100644 --- a/src/Functions/tuple.cpp +++ b/src/Functions/tuple.cpp @@ -55,6 +55,7 @@ public: /// tuple(..., Nothing, ...) -> Tuple(..., Nothing, ...) bool useDefaultImplementationForNothing() const override { return false; } bool useDefaultImplementationForConstants() const override { return true; } + bool useDefaultImplementationForLowCardinalityColumns() const override { return false; } DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { diff --git a/tests/queries/0_stateless/02354_tuple_lowcardinality.reference b/tests/queries/0_stateless/02354_tuple_lowcardinality.reference new file mode 100644 index 00000000000..435417d7f2b --- /dev/null +++ b/tests/queries/0_stateless/02354_tuple_lowcardinality.reference @@ -0,0 +1,4 @@ +Tuple(LowCardinality(String), LowCardinality(UInt8)) +Tuple(LowCardinality(String), LowCardinality(UInt8)) +Tuple(LowCardinality(String), LowCardinality(UInt8)) +Tuple(LowCardinality(String), LowCardinality(UInt8)) diff --git a/tests/queries/0_stateless/02354_tuple_lowcardinality.sql b/tests/queries/0_stateless/02354_tuple_lowcardinality.sql new file mode 100644 index 00000000000..44b64aab327 --- /dev/null +++ b/tests/queries/0_stateless/02354_tuple_lowcardinality.sql @@ -0,0 +1,6 @@ +SET allow_suspicious_low_cardinality_types = 1; + +SELECT toTypeName(tuple(toLowCardinality('1'), toLowCardinality(1))); +SELECT toTypeName(tuple(materialize(toLowCardinality('1')), toLowCardinality(1))); +SELECT toTypeName(tuple(toLowCardinality('1'), materialize(toLowCardinality(1)))); +SELECT toTypeName(tuple(materialize(toLowCardinality('1')), materialize(toLowCardinality(1)))); From 72fe4ce680379e8ac908065713ae4492a7b26268 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Tue, 12 Jul 2022 03:12:42 +0000 Subject: [PATCH 2/4] fix function toColumnTypeName with LowCardinality --- src/Functions/toColumnTypeName.cpp | 2 ++ tests/queries/0_stateless/02355_column_type_name_lc.reference | 1 + tests/queries/0_stateless/02355_column_type_name_lc.sql | 1 + 3 files changed, 4 insertions(+) create mode 100644 tests/queries/0_stateless/02355_column_type_name_lc.reference create mode 100644 tests/queries/0_stateless/02355_column_type_name_lc.sql diff --git a/src/Functions/toColumnTypeName.cpp b/src/Functions/toColumnTypeName.cpp index 466a8ba17c5..d8013f13340 100644 --- a/src/Functions/toColumnTypeName.cpp +++ b/src/Functions/toColumnTypeName.cpp @@ -28,6 +28,8 @@ public: bool useDefaultImplementationForNothing() const override { return false; } + bool useDefaultImplementationForLowCardinalityColumns() const override { return false; } + bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; } size_t getNumberOfArguments() const override diff --git a/tests/queries/0_stateless/02355_column_type_name_lc.reference b/tests/queries/0_stateless/02355_column_type_name_lc.reference new file mode 100644 index 00000000000..234a072299f --- /dev/null +++ b/tests/queries/0_stateless/02355_column_type_name_lc.reference @@ -0,0 +1 @@ +ColumnLowCardinality diff --git a/tests/queries/0_stateless/02355_column_type_name_lc.sql b/tests/queries/0_stateless/02355_column_type_name_lc.sql new file mode 100644 index 00000000000..13a6393aaf2 --- /dev/null +++ b/tests/queries/0_stateless/02355_column_type_name_lc.sql @@ -0,0 +1 @@ +SELECT toColumnTypeName(toLowCardinality(materialize('foo'))); From 81da0bb9f558b55f6d7b3d08d0990b30eef5af08 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Tue, 12 Jul 2022 13:28:10 +0000 Subject: [PATCH 3/4] keep LowCardinality type in array() and map() functions --- src/Functions/array/array.cpp | 1 + src/Functions/map.cpp | 1 + .../02354_array_lowcardinality.reference | 12 ++++++++++++ .../0_stateless/02354_array_lowcardinality.sql | 14 ++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 tests/queries/0_stateless/02354_array_lowcardinality.reference create mode 100644 tests/queries/0_stateless/02354_array_lowcardinality.sql diff --git a/src/Functions/array/array.cpp b/src/Functions/array/array.cpp index b0a7daac522..f220117407c 100644 --- a/src/Functions/array/array.cpp +++ b/src/Functions/array/array.cpp @@ -23,6 +23,7 @@ public: /// array(..., Nothing, ...) -> Array(..., Nothing, ...) bool useDefaultImplementationForNothing() const override { return false; } bool useDefaultImplementationForConstants() const override { return true; } + bool useDefaultImplementationForLowCardinalityColumns() const override { return false; } bool isVariadic() const override { return true; } bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; } diff --git a/src/Functions/map.cpp b/src/Functions/map.cpp index 8c891fdec81..866d3ae3866 100644 --- a/src/Functions/map.cpp +++ b/src/Functions/map.cpp @@ -68,6 +68,7 @@ public: /// map(..., Nothing) -> Map(..., Nothing) bool useDefaultImplementationForNothing() const override { return false; } bool useDefaultImplementationForConstants() const override { return true; } + bool useDefaultImplementationForLowCardinalityColumns() const override { return false; } DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { diff --git a/tests/queries/0_stateless/02354_array_lowcardinality.reference b/tests/queries/0_stateless/02354_array_lowcardinality.reference new file mode 100644 index 00000000000..d364bbdb5f4 --- /dev/null +++ b/tests/queries/0_stateless/02354_array_lowcardinality.reference @@ -0,0 +1,12 @@ +Array(LowCardinality(String)) +Array(LowCardinality(String)) +Array(LowCardinality(String)) +Array(LowCardinality(String)) +Array(String) +Array(String) +Array(String) +Array(String) +Map(LowCardinality(String), LowCardinality(String)) +Map(LowCardinality(String), LowCardinality(String)) +Map(LowCardinality(String), LowCardinality(String)) +Map(LowCardinality(String), LowCardinality(String)) diff --git a/tests/queries/0_stateless/02354_array_lowcardinality.sql b/tests/queries/0_stateless/02354_array_lowcardinality.sql new file mode 100644 index 00000000000..1aa26b29050 --- /dev/null +++ b/tests/queries/0_stateless/02354_array_lowcardinality.sql @@ -0,0 +1,14 @@ +SELECT toTypeName([toLowCardinality('1'), toLowCardinality('2')]); +SELECT toTypeName([materialize(toLowCardinality('1')), toLowCardinality('2')]); +SELECT toTypeName([toLowCardinality('1'), materialize(toLowCardinality('2'))]); +SELECT toTypeName([materialize(toLowCardinality('1')), materialize(toLowCardinality('2'))]); + +SELECT toTypeName([toLowCardinality('1'), '2']); +SELECT toTypeName([materialize(toLowCardinality('1')), '2']); +SELECT toTypeName([toLowCardinality('1'), materialize('2')]); +SELECT toTypeName([materialize(toLowCardinality('1')), materialize('2')]); + +SELECT toTypeName(map(toLowCardinality('1'), toLowCardinality('2'))); +SELECT toTypeName(map(materialize(toLowCardinality('1')), toLowCardinality('2'))); +SELECT toTypeName(map(toLowCardinality('1'), materialize(toLowCardinality('2')))); +SELECT toTypeName(map(materialize(toLowCardinality('1')), materialize(toLowCardinality('2')))); From 04f9e15012c7b2d668cbb60d9d4a059afffcceda Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Tue, 12 Jul 2022 13:46:49 +0000 Subject: [PATCH 4/4] fix test --- .../02210_toColumnTypeName_toLowCardinality_const.reference | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/02210_toColumnTypeName_toLowCardinality_const.reference b/tests/queries/0_stateless/02210_toColumnTypeName_toLowCardinality_const.reference index 2ac2f690f1b..1e3d3a50562 100644 --- a/tests/queries/0_stateless/02210_toColumnTypeName_toLowCardinality_const.reference +++ b/tests/queries/0_stateless/02210_toColumnTypeName_toLowCardinality_const.reference @@ -1 +1 @@ -Const(UInt8) +Const(ColumnLowCardinality)