From 59fbd21024067263a34fd61e562d8cda52dcc7d7 Mon Sep 17 00:00:00 2001 From: Arthur Passos Date: Fri, 29 Jul 2022 12:03:09 -0300 Subject: [PATCH 1/6] Unwrap LC column in IExecutablefunction::executeWithoutSparseColumns --- src/Functions/IFunction.cpp | 2 ++ tests/integration/test_cte_lc/__init__.py | 0 tests/integration/test_cte_lc/test.py | 26 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 tests/integration/test_cte_lc/__init__.py create mode 100644 tests/integration/test_cte_lc/test.py diff --git a/src/Functions/IFunction.cpp b/src/Functions/IFunction.cpp index 5be2ea3c5e3..e079fc626f3 100644 --- a/src/Functions/IFunction.cpp +++ b/src/Functions/IFunction.cpp @@ -285,6 +285,8 @@ ColumnPtr IExecutableFunction::executeWithoutSparseColumns(const ColumnsWithType ? res->cloneResized(1)->convertToFullColumnIfConst() : res; + keys = keys->convertToFullColumnIfLowCardinality(); + auto res_mut_dictionary = DataTypeLowCardinality::createColumnUnique(*res_low_cardinality_type->getDictionaryType()); ColumnPtr res_indexes = res_mut_dictionary->uniqueInsertRangeFrom(*keys, 0, keys->size()); ColumnUniquePtr res_dictionary = std::move(res_mut_dictionary); diff --git a/tests/integration/test_cte_lc/__init__.py b/tests/integration/test_cte_lc/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/integration/test_cte_lc/test.py b/tests/integration/test_cte_lc/test.py new file mode 100644 index 00000000000..e7c607b3e02 --- /dev/null +++ b/tests/integration/test_cte_lc/test.py @@ -0,0 +1,26 @@ +import pytest +from helpers.cluster import ClickHouseCluster + +cluster = ClickHouseCluster(__file__) +node = cluster.add_instance("node") + + +@pytest.fixture(scope="module", autouse=True) +def start_cluster(): + try: + cluster.start() + yield cluster + finally: + cluster.shutdown() + + +def test_lc_of_string(start_cluster): + result = node.query("WITH ( SELECT toLowCardinality('a') ) AS bar SELECT bar") + + assert result == 'a\n' + + +def test_lc_of_int(start_cluster): + result = node.query("WITH ( SELECT toLowCardinality(1) ) AS bar SELECT bar") + + assert result == '1\n' From f0f19874dafd84666af75818eb0dd8f1cdbbfb48 Mon Sep 17 00:00:00 2001 From: Arthur Passos Date: Fri, 29 Jul 2022 13:56:01 -0300 Subject: [PATCH 2/6] fix style --- src/Functions/IFunction.cpp | 2 +- tests/integration/test_cte_lc/test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Functions/IFunction.cpp b/src/Functions/IFunction.cpp index e079fc626f3..4e73f7588c5 100644 --- a/src/Functions/IFunction.cpp +++ b/src/Functions/IFunction.cpp @@ -286,7 +286,7 @@ ColumnPtr IExecutableFunction::executeWithoutSparseColumns(const ColumnsWithType : res; keys = keys->convertToFullColumnIfLowCardinality(); - + auto res_mut_dictionary = DataTypeLowCardinality::createColumnUnique(*res_low_cardinality_type->getDictionaryType()); ColumnPtr res_indexes = res_mut_dictionary->uniqueInsertRangeFrom(*keys, 0, keys->size()); ColumnUniquePtr res_dictionary = std::move(res_mut_dictionary); diff --git a/tests/integration/test_cte_lc/test.py b/tests/integration/test_cte_lc/test.py index e7c607b3e02..12fd47ee842 100644 --- a/tests/integration/test_cte_lc/test.py +++ b/tests/integration/test_cte_lc/test.py @@ -17,10 +17,10 @@ def start_cluster(): def test_lc_of_string(start_cluster): result = node.query("WITH ( SELECT toLowCardinality('a') ) AS bar SELECT bar") - assert result == 'a\n' + assert result == "a\n"" def test_lc_of_int(start_cluster): result = node.query("WITH ( SELECT toLowCardinality(1) ) AS bar SELECT bar") - assert result == '1\n' + assert result == "1\n" From d1de8d0dfbd143d67ac0e7a731a6de55ab5a32a6 Mon Sep 17 00:00:00 2001 From: Arthur Passos Date: Fri, 29 Jul 2022 13:59:29 -0300 Subject: [PATCH 3/6] remove extra double quotes --- tests/integration/test_cte_lc/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_cte_lc/test.py b/tests/integration/test_cte_lc/test.py index 12fd47ee842..36244446fff 100644 --- a/tests/integration/test_cte_lc/test.py +++ b/tests/integration/test_cte_lc/test.py @@ -17,7 +17,7 @@ def start_cluster(): def test_lc_of_string(start_cluster): result = node.query("WITH ( SELECT toLowCardinality('a') ) AS bar SELECT bar") - assert result == "a\n"" + assert result == "a\n" def test_lc_of_int(start_cluster): From e9b124b4bcced6ebc5a7a77aa54aca2ddb48db15 Mon Sep 17 00:00:00 2001 From: Arthur Passos Date: Tue, 2 Aug 2022 09:17:53 -0300 Subject: [PATCH 4/6] Don't use default implementation for LC columns in Scalar functions --- src/Functions/IFunction.cpp | 2 -- src/Functions/getScalar.cpp | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Functions/IFunction.cpp b/src/Functions/IFunction.cpp index 4e73f7588c5..5be2ea3c5e3 100644 --- a/src/Functions/IFunction.cpp +++ b/src/Functions/IFunction.cpp @@ -285,8 +285,6 @@ ColumnPtr IExecutableFunction::executeWithoutSparseColumns(const ColumnsWithType ? res->cloneResized(1)->convertToFullColumnIfConst() : res; - keys = keys->convertToFullColumnIfLowCardinality(); - auto res_mut_dictionary = DataTypeLowCardinality::createColumnUnique(*res_low_cardinality_type->getDictionaryType()); ColumnPtr res_indexes = res_mut_dictionary->uniqueInsertRangeFrom(*keys, 0, keys->size()); ColumnUniquePtr res_dictionary = std::move(res_mut_dictionary); diff --git a/src/Functions/getScalar.cpp b/src/Functions/getScalar.cpp index c165ef26ffa..aeb68c3825e 100644 --- a/src/Functions/getScalar.cpp +++ b/src/Functions/getScalar.cpp @@ -42,6 +42,11 @@ public: return 1; } + bool useDefaultImplementationForLowCardinalityColumns() const override + { + return false; + } + bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; } DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override From 5f7848ffd48f40a34e72d22182571fe31bfa666d Mon Sep 17 00:00:00 2001 From: Arthur Passos Date: Tue, 2 Aug 2022 09:30:54 -0300 Subject: [PATCH 5/6] Replace LC CTE scalar integ tests by stateless tests --- tests/integration/test_cte_lc/__init__.py | 0 tests/integration/test_cte_lc/test.py | 26 ------------------- .../0_stateless/02375_scalar_lc_cte.reference | 1 + .../0_stateless/02375_scalar_lc_cte.sql | 1 + 4 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 tests/integration/test_cte_lc/__init__.py delete mode 100644 tests/integration/test_cte_lc/test.py create mode 100644 tests/queries/0_stateless/02375_scalar_lc_cte.reference create mode 100644 tests/queries/0_stateless/02375_scalar_lc_cte.sql diff --git a/tests/integration/test_cte_lc/__init__.py b/tests/integration/test_cte_lc/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/integration/test_cte_lc/test.py b/tests/integration/test_cte_lc/test.py deleted file mode 100644 index 36244446fff..00000000000 --- a/tests/integration/test_cte_lc/test.py +++ /dev/null @@ -1,26 +0,0 @@ -import pytest -from helpers.cluster import ClickHouseCluster - -cluster = ClickHouseCluster(__file__) -node = cluster.add_instance("node") - - -@pytest.fixture(scope="module", autouse=True) -def start_cluster(): - try: - cluster.start() - yield cluster - finally: - cluster.shutdown() - - -def test_lc_of_string(start_cluster): - result = node.query("WITH ( SELECT toLowCardinality('a') ) AS bar SELECT bar") - - assert result == "a\n" - - -def test_lc_of_int(start_cluster): - result = node.query("WITH ( SELECT toLowCardinality(1) ) AS bar SELECT bar") - - assert result == "1\n" diff --git a/tests/queries/0_stateless/02375_scalar_lc_cte.reference b/tests/queries/0_stateless/02375_scalar_lc_cte.reference new file mode 100644 index 00000000000..2e65efe2a14 --- /dev/null +++ b/tests/queries/0_stateless/02375_scalar_lc_cte.reference @@ -0,0 +1 @@ +a \ No newline at end of file diff --git a/tests/queries/0_stateless/02375_scalar_lc_cte.sql b/tests/queries/0_stateless/02375_scalar_lc_cte.sql new file mode 100644 index 00000000000..80018333829 --- /dev/null +++ b/tests/queries/0_stateless/02375_scalar_lc_cte.sql @@ -0,0 +1 @@ +WITH ( SELECT toLowCardinality('a') ) AS bar SELECT bar \ No newline at end of file From b386db02e14caf5cc4eb283c5d05b822dbb01e0e Mon Sep 17 00:00:00 2001 From: Kruglov Pavel <48961922+Avogar@users.noreply.github.com> Date: Tue, 2 Aug 2022 15:51:57 +0200 Subject: [PATCH 6/6] Fix test --- tests/queries/0_stateless/02375_scalar_lc_cte.reference | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/02375_scalar_lc_cte.reference b/tests/queries/0_stateless/02375_scalar_lc_cte.reference index 2e65efe2a14..78981922613 100644 --- a/tests/queries/0_stateless/02375_scalar_lc_cte.reference +++ b/tests/queries/0_stateless/02375_scalar_lc_cte.reference @@ -1 +1 @@ -a \ No newline at end of file +a