Merge pull request #314 from yandex/metr-24043

fix where <const> in (<const>) expression; [#METR-24043]
This commit is contained in:
alexey-milovidov 2017-01-10 19:30:07 +04:00 committed by GitHub
commit bc377a6d69
3 changed files with 19 additions and 0 deletions

View File

@ -249,6 +249,12 @@ static bool getConstant(const ASTPtr & expr, Block & block_with_constants, Field
if (const ASTLiteral * lit = typeid_cast<const ASTLiteral *>(expr.get())) if (const ASTLiteral * lit = typeid_cast<const ASTLiteral *>(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 /// Simple literal
out_value = lit->value; out_value = lit->value;
out_type = block_with_constants.getByName(column_name).type; out_type = block_with_constants.getByName(column_name).type;

View File

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