Merge pull request #541 from yandex/ch-1999

fix IN with nested tuples [#CLICKHOUSE-1999]
This commit is contained in:
alexey-milovidov 2017-03-02 02:16:45 +04:00 committed by GitHub
commit 60e3af6c8d
3 changed files with 22 additions and 6 deletions

View File

@ -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<const ColumnTuple *>(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)

View File

@ -25,3 +25,8 @@
1
0
1
1 (2,3)
2 (2,3)
3 (2,3)
4 (2,3)
5 (2,3)

View File

@ -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));