From 402f974fb7eb5ea5196f329bb97ac8c98f415a9d Mon Sep 17 00:00:00 2001 From: artpaul Date: Tue, 10 Jan 2017 19:16:37 +0500 Subject: [PATCH] fix where in () expression; [#METR-24043] --- dbms/src/Storages/MergeTree/PKCondition.cpp | 6 ++++++ .../00411_merge_tree_where_const_in_set.reference | 1 + .../00411_merge_tree_where_const_in_set.sql | 12 ++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 dbms/tests/queries/0_stateless/00411_merge_tree_where_const_in_set.reference create mode 100644 dbms/tests/queries/0_stateless/00411_merge_tree_where_const_in_set.sql diff --git a/dbms/src/Storages/MergeTree/PKCondition.cpp b/dbms/src/Storages/MergeTree/PKCondition.cpp index 9a1bab3fb1e..a2dc97ed00c 100644 --- a/dbms/src/Storages/MergeTree/PKCondition.cpp +++ b/dbms/src/Storages/MergeTree/PKCondition.cpp @@ -249,6 +249,12 @@ static bool getConstant(const ASTPtr & expr, Block & block_with_constants, Field if (const ASTLiteral * lit = typeid_cast(expr.get())) { + /// By default block_with_constants has only one column named "_dummy". + /// If block contains only constants it's may not be preprocessed by + // ExpressionAnalyzer, so try to look up in the default column. + if (!block_with_constants.has(column_name)) + column_name = "_dummy"; + /// Simple literal out_value = lit->value; out_type = block_with_constants.getByName(column_name).type; diff --git a/dbms/tests/queries/0_stateless/00411_merge_tree_where_const_in_set.reference b/dbms/tests/queries/0_stateless/00411_merge_tree_where_const_in_set.reference new file mode 100644 index 00000000000..a5bce3fd256 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00411_merge_tree_where_const_in_set.reference @@ -0,0 +1 @@ +test1 diff --git a/dbms/tests/queries/0_stateless/00411_merge_tree_where_const_in_set.sql b/dbms/tests/queries/0_stateless/00411_merge_tree_where_const_in_set.sql new file mode 100644 index 00000000000..a88eafa0f49 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00411_merge_tree_where_const_in_set.sql @@ -0,0 +1,12 @@ +DROP TABLE IF EXISTS test.const_in_const; +CREATE TABLE test.const_in_const (id UInt64, date Date, uid UInt32, name String, Sign Int8) ENGINE = CollapsingMergeTree(date, intHash32(uid), (id, date, intHash32(uid)), 8192, Sign); +INSERT INTO test.const_in_const VALUES(1, now(), 1, 'test1', 1); +INSERT INTO test.const_in_const VALUES(2, now(), 1, 'test2', 1); +INSERT INTO test.const_in_const VALUES(3, now(), 1, 'test3', 1); +INSERT INTO test.const_in_const VALUES(4, now(), 2, 'test4', 1); +INSERT INTO test.const_in_const VALUES(5, now(), 3, 'test5', 1); + +SELECT 1 from test.const_in_const where 42 in (225); +SELECT name FROM test.const_in_const WHERE 1 IN (125, 1, 2) ORDER BY name LIMIT 1; + +DROP TABLE IF EXISTS test.const_in_const;