mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Try fix more cases.
This commit is contained in:
parent
9d152a3c4d
commit
c07043fd97
@ -92,6 +92,11 @@ Block evaluateConstantGroupByKeysWithShardNumber(
|
|||||||
{
|
{
|
||||||
Block res;
|
Block res;
|
||||||
|
|
||||||
|
ColumnWithTypeAndName shard_num_col;
|
||||||
|
shard_num_col.type = std::make_shared<DataTypeUInt32>();
|
||||||
|
shard_num_col.column = shard_num_col.type->createColumnConst(0, shard_num);
|
||||||
|
shard_num_col.name = "_shard_num";
|
||||||
|
|
||||||
if (auto group_by = query_ast->as<ASTSelectQuery &>().groupBy())
|
if (auto group_by = query_ast->as<ASTSelectQuery &>().groupBy())
|
||||||
{
|
{
|
||||||
for (const auto & elem : group_by->children)
|
for (const auto & elem : group_by->children)
|
||||||
@ -108,19 +113,20 @@ Block evaluateConstantGroupByKeysWithShardNumber(
|
|||||||
if (required_columns.size() != 1 || required_columns.count("_shard_num") == 0)
|
if (required_columns.size() != 1 || required_columns.count("_shard_num") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto type = std::make_shared<DataTypeUInt32>();
|
Block block({shard_num_col});
|
||||||
auto col = type->createColumnConst(1, shard_num);
|
auto syntax_result = TreeRewriter(context).analyze(ast, {NameAndTypePair{shard_num_col.name, shard_num_col.type}});
|
||||||
std::string name = "_shard_num";
|
ExpressionAnalyzer(ast, syntax_result, context).getActions(true, false)->execute(block);
|
||||||
|
|
||||||
Block block({ColumnWithTypeAndName{col, type, name}});
|
|
||||||
auto syntax_result = TreeRewriter(context).analyze(ast, {NameAndTypePair{name, type}});
|
|
||||||
ExpressionAnalyzer(ast, syntax_result, context).getActions(true)->execute(block);
|
|
||||||
|
|
||||||
res.insert(block.getByName(key_name));
|
res.insert(block.getByName(key_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We always add _shard_num constant just in case.
|
||||||
|
/// For initial query it is considered as a column from table, and may be required by intermediate block.
|
||||||
|
if (!res.has(shard_num_col.name))
|
||||||
|
res.insert(std::move(shard_num_col));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,3 +14,5 @@
|
|||||||
2
|
2
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
|
1 1
|
||||||
|
2 1
|
||||||
|
@ -10,3 +10,7 @@ SELECT _shard_num + dummy s, count() FROM remote('127.0.0.{1,2}', system.one) GR
|
|||||||
|
|
||||||
SELECT _shard_num FROM remote('127.0.0.{1,2}', system.one) ORDER BY _shard_num;
|
SELECT _shard_num FROM remote('127.0.0.{1,2}', system.one) ORDER BY _shard_num;
|
||||||
SELECT _shard_num s FROM remote('127.0.0.{1,2}', system.one) ORDER BY _shard_num;
|
SELECT _shard_num s FROM remote('127.0.0.{1,2}', system.one) ORDER BY _shard_num;
|
||||||
|
|
||||||
|
SELECT _shard_num s, count() FROM remote('127.0.0.{1,2}', system.one) GROUP BY s order by s;
|
||||||
|
|
||||||
|
select materialize(_shard_num), * from remote('127.{1,2}', system.one) limit 1 by dummy format Null;
|
||||||
|
Loading…
Reference in New Issue
Block a user