mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
Merge pull request #3357 from yandex/check-for-array-join-in-prewhere
Added check for invalid PREWHERE
This commit is contained in:
commit
12772c2cd5
@ -417,6 +417,22 @@ InterpreterSelectQuery::AnalysisResult InterpreterSelectQuery::analyzeExpression
|
||||
|
||||
res.subqueries_for_sets = query_analyzer->getSubqueriesForSets();
|
||||
|
||||
/// Check that PREWHERE doesn't contain unusual actions. Unusual actions are that can change number of rows.
|
||||
if (res.prewhere_info)
|
||||
{
|
||||
auto check_actions = [](const ExpressionActionsPtr & actions)
|
||||
{
|
||||
if (actions)
|
||||
for (const auto & action : actions->getActions())
|
||||
if (action.type == ExpressionAction::Type::JOIN || action.type == ExpressionAction::Type::ARRAY_JOIN)
|
||||
throw Exception("PREWHERE cannot contain ARRAY JOIN or JOIN action", ErrorCodes::ILLEGAL_PREWHERE);
|
||||
};
|
||||
|
||||
check_actions(res.prewhere_info->prewhere_actions);
|
||||
check_actions(res.prewhere_info->alias_actions);
|
||||
check_actions(res.prewhere_info->remove_columns_actions);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
background 1
|
||||
foreground 1
|
||||
heading 1
|
||||
image 1
|
||||
background 1
|
||||
foreground 1
|
||||
heading 1
|
||||
image 1
|
33
dbms/tests/queries/0_stateless/00729_prewhere_array_join.sql
Normal file
33
dbms/tests/queries/0_stateless/00729_prewhere_array_join.sql
Normal file
@ -0,0 +1,33 @@
|
||||
SET send_logs_level = 'none';
|
||||
USE test;
|
||||
|
||||
drop table if exists t1;
|
||||
create table t1 (id UInt64, val Array(String),nid UInt64, eDate Date)ENGINE = MergeTree(eDate, (id, eDate), 8192);
|
||||
|
||||
insert into t1 (id,val,nid,eDate) values (1,['background','foreground','heading','image'],1,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (1,['background','foreground','heading','image'],1,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (2,['background','foreground','heading','image'],1,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (2,[],2,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (3,[],4,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (3,[],5,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (3,[],6,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (3,[],7,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (3,[],8,'2018-09-27');
|
||||
|
||||
select arrayJoin(val) as nameGroup6 from t1 prewhere notEmpty(toString(nameGroup6)) group by nameGroup6 order by nameGroup6; -- { serverError 182 }
|
||||
select arrayJoin(val) as nameGroup6, countDistinct(nid) as rowids from t1 where notEmpty(toString(nameGroup6)) group by nameGroup6 order by nameGroup6;
|
||||
select arrayJoin(val) as nameGroup6, countDistinct(nid) as rowids from t1 prewhere notEmpty(toString(nameGroup6)) group by nameGroup6 order by nameGroup6; -- { serverError 182 }
|
||||
|
||||
drop table t1;
|
||||
create table t1 (id UInt64, val Array(String),nid UInt64, eDate Date) ENGINE = MergeTree(eDate, (id, eDate), 8192);
|
||||
|
||||
insert into t1 (id,val,nid,eDate) values (1,['background','foreground','heading','image'],1,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (1,['background','foreground','heading','image'],1,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (2,['background','foreground','heading','image'],1,'2018-09-27');
|
||||
insert into t1 (id,val,nid,eDate) values (2,[],2,'2018-09-27');
|
||||
|
||||
select arrayJoin(val) as nameGroup6 from t1 prewhere notEmpty(toString(nameGroup6)) group by nameGroup6 order by nameGroup6; -- { serverError 182 }
|
||||
select arrayJoin(val) as nameGroup6, countDistinct(nid) as rowids from t1 where notEmpty(toString(nameGroup6)) group by nameGroup6 order by nameGroup6;
|
||||
select arrayJoin(val) as nameGroup6, countDistinct(nid) as rowids from t1 prewhere notEmpty(toString(nameGroup6)) group by nameGroup6 order by nameGroup6; -- { serverError 182 }
|
||||
|
||||
drop table t1;
|
Loading…
Reference in New Issue
Block a user