From be7c70da5ce0cb13d81b8c99adb31b949e1264d4 Mon Sep 17 00:00:00 2001 From: artpaul Date: Wed, 1 Mar 2017 19:48:21 +0500 Subject: [PATCH] fix IN with nested tuples [#CLICKHOUSE-1999] --- dbms/src/Interpreters/Set.cpp | 18 ++++++++++++------ .../queries/0_stateless/00132_sets.reference | 5 +++++ dbms/tests/queries/0_stateless/00132_sets.sql | 5 +++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/dbms/src/Interpreters/Set.cpp b/dbms/src/Interpreters/Set.cpp index 32adc3331f0..faa25e34846 100644 --- a/dbms/src/Interpreters/Set.cpp +++ b/dbms/src/Interpreters/Set.cpp @@ -100,12 +100,18 @@ bool Set::insertFromBlock(const Block & block, bool create_ordered_set) materialized_columns.emplace_back(converted); key_columns.back() = materialized_columns.back().get(); } + } - /** Flatten tuples. For case when written - * (a, b) IN (SELECT (a, b) FROM table) - * instead of more typical - * (a, b) IN (SELECT a, b FROM table) - */ + /** Flatten tuples. For case when written + * (a, b) IN (SELECT (a, b) FROM table) + * instead of more typical + * (a, b) IN (SELECT a, b FROM table) + * + * Avoid flatten in case then we have more than one column: + * Ex.: 1, (2, 3) become just 1, 2, 3 + */ + if (keys_size == 1) + { if (const ColumnTuple * tuple = typeid_cast(key_columns.back())) { key_columns.pop_back(); @@ -229,7 +235,7 @@ void Set::createFromAST(const DataTypes & types, ASTPtr node, const Context & co if (value.isNull()) break; - tuple_values[j] = value; /// TODO Сделать move семантику для Field. + tuple_values[j] = value; } if (j == tuple_size) diff --git a/dbms/tests/queries/0_stateless/00132_sets.reference b/dbms/tests/queries/0_stateless/00132_sets.reference index b3fab3315f4..709745a5a17 100644 --- a/dbms/tests/queries/0_stateless/00132_sets.reference +++ b/dbms/tests/queries/0_stateless/00132_sets.reference @@ -25,3 +25,8 @@ 1 0 1 +1 (2,3) +2 (2,3) +3 (2,3) +4 (2,3) +5 (2,3) diff --git a/dbms/tests/queries/0_stateless/00132_sets.sql b/dbms/tests/queries/0_stateless/00132_sets.sql index f6394a3c1c2..b38e6af545d 100644 --- a/dbms/tests/queries/0_stateless/00132_sets.sql +++ b/dbms/tests/queries/0_stateless/00132_sets.sql @@ -19,3 +19,8 @@ SELECT ['Hello', 'world'] IN ('world'); SELECT ['Hello', 'world'] NOT IN ('world'); SELECT ['Hello', 'world'] NOT IN ('Hello', 'world'); SELECT ['Hello', 'world'] NOT IN ('hello', 'world'); +SELECT number, tuple FROM (SELECT 1 AS number, (2, 3) AS tuple) WHERE (number, tuple) IN (((1, (2, 3)), (4, (5, 6)))); +SELECT number, tuple FROM (SELECT 2 AS number, (2, 3) AS tuple) WHERE (number, tuple) IN ((2, (2, 3))); +SELECT number, tuple FROM (SELECT 3 AS number, (2, 3) AS tuple) WHERE (number, tuple) IN (3, (2, 3)); +SELECT number, tuple FROM (SELECT 4 AS number, (2, 3) AS tuple) WHERE (number, tuple) IN (SELECT (4, (2, 3))); +SELECT number, tuple FROM (SELECT 5 AS number, (2, 3) AS tuple) WHERE (number, tuple) IN (SELECT 5, (2, 3));