Allow literals for GLOBAL IN

This commit is contained in:
Azat Khuzhin 2020-04-12 00:28:04 +03:00
parent a332d8b01e
commit 194dcc01fb
5 changed files with 30 additions and 23 deletions

View File

@ -2,6 +2,7 @@
#include <Parsers/IAST.h>
#include <Parsers/ASTSubquery.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTTablesInSelectQuery.h>
#include <Parsers/ASTSelectQuery.h>
@ -166,7 +167,19 @@ private:
{
if (func.name == "globalIn" || func.name == "globalNotIn")
{
data.addExternalStorage(func.arguments->children[1]);
ASTPtr & ast = func.arguments->children[1];
/// Literal can use regular IN
if (ast->as<ASTLiteral>())
{
if (func.name == "globalIn")
func.name = "in";
else
func.name = "notIn";
return;
}
data.addExternalStorage(ast);
data.has_global_subqueries = true;
}
}

View File

@ -0,0 +1,6 @@
GLOBAL IN
0
0
0
0
GLOBAL NOT IN

View File

@ -0,0 +1,10 @@
SELECT 'GLOBAL IN';
select * from remote('localhost', system.one) where dummy global in (0);
select * from remote('localhost', system.one) where toUInt64(dummy) global in numbers(1);
select * from remote('localhost', system.one) where dummy global in system.one;
select * from remote('localhost', system.one) where dummy global in (select 0);
SELECT 'GLOBAL NOT IN';
select * from remote('localhost', system.one) where dummy global not in (0);
select * from remote('localhost', system.one) where toUInt64(dummy) global not in numbers(1);
select * from remote('localhost', system.one) where dummy global not in system.one;
select * from remote('localhost', system.one) where dummy global not in (select 0);

View File

@ -1,4 +0,0 @@
GLOBAL IN distributed_group_by_no_merge
1
GLOBAL IN
1

View File

@ -1,18 +0,0 @@
create table if not exists data_01224 (key Int) Engine=Memory();
create table if not exists dist_layer_01224 as data_01224 Engine=Distributed(test_cluster_two_shards, currentDatabase(), data_01224);
create table if not exists dist_01224 as data_01224 Engine=Distributed(test_cluster_two_shards, currentDatabase(), dist_layer_01224);
select * from dist_01224;
insert into data_01224 select * from numbers(3);
-- "Table expression is undefined, Method: ExpressionAnalyzer::interpretSubquery"
select 'GLOBAL IN distributed_group_by_no_merge';
select distinct * from dist_01224 where key global in (1) settings distributed_group_by_no_merge=1;
-- requires #9923
select 'GLOBAL IN';
select distinct * from dist_01224 where key global in (1);
drop table dist_01224;
drop table dist_layer_01224;
drop table data_01224;