Analyzer: Remove constants from header in StorageDistributed

This commit is contained in:
vdimir 2023-09-05 12:24:44 +00:00
parent e8422414b0
commit 1aa18e0eb6
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862
2 changed files with 13 additions and 2 deletions

View File

@ -742,12 +742,16 @@ void StorageDistributed::read(
remote_storage_id,
remote_table_function_ptr);
header = InterpreterSelectQueryAnalyzer::getSampleBlock(query_tree_distributed, local_context, SelectQueryOptions(processed_stage).analyze());
/** For distributed tables we do not need constants in header, since we don't send them to remote servers.
* Moreover, constants can break some functions like `hostName` that are constants only for local queries.
*/
for (auto & column : header)
column.column = column.column->convertToFullColumnIfConst();
query_ast = queryNodeToSelectQuery(query_tree_distributed);
}
else
{
header =
InterpreterSelectQuery(query_info.query, local_context, SelectQueryOptions(processed_stage).analyze()).getSampleBlock();
header = InterpreterSelectQuery(query_info.query, local_context, SelectQueryOptions(processed_stage).analyze()).getSampleBlock();
query_ast = query_info.query;
}

View File

@ -25,6 +25,13 @@ def test_cluster(start_cluster):
)
== "node1\nnode2\n"
)
assert set(
node1.query(
"""SELECT hostName(), * FROM clusterAllReplicas("one_shard_two_nodes", system.one) ORDER BY dummy"""
).splitlines()
) == {"node1\t0", "node2\t0"}
assert (
node1.query("SELECT hostName() FROM cluster('one_shard_two_nodes', system.one)")
== "node1\n"