Skip to content

Commit fb0ad25

Browse files
committed
Fix after review
1 parent 3829e1a commit fb0ad25

5 files changed

Lines changed: 53 additions & 11 deletions

File tree

src/Storages/IStorageCluster.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <Analyzer/QueryTreeBuilder.h>
2525
#include <Analyzer/QueryNode.h>
2626
#include <Analyzer/ColumnNode.h>
27+
#include <Analyzer/ConstantNode.h>
2728
#include <Analyzer/JoinNode.h>
2829
#include <Analyzer/InDepthQueryTreeVisitor.h>
2930
#include <Analyzer/Utils.h>
@@ -105,9 +106,9 @@ class SearcherVisitor : public InDepthQueryTreeVisitorWithContext<SearcherVisito
105106

106107
explicit SearcherVisitor(std::unordered_set<QueryTreeNodeType> types_, ContextPtr context) : Base(context), types(types_) {}
107108

108-
bool needChildVisit(QueryTreeNodePtr &, QueryTreeNodePtr & /*child*/)
109+
bool needChildVisit(QueryTreeNodePtr & /*parent*/, QueryTreeNodePtr & /*child*/)
109110
{
110-
return !passed_node;
111+
return getSubqueryDepth() <= 2 && !passed_node;
111112
}
112113

113114
void enterImpl(QueryTreeNodePtr & node)
@@ -245,12 +246,22 @@ void IStorageCluster::updateQueryWithJoinToSendIfNeeded(
245246
collector.visit(modified_query_tree);
246247
const auto & columns = collector.getColumns();
247248

248-
query_node.resolveProjectionColumns(columns);
249-
auto column_nodes_to_select = std::make_shared<ListNode>();
250-
column_nodes_to_select->getNodes().reserve(columns.size());
251-
for (auto & column : columns)
252-
column_nodes_to_select->getNodes().emplace_back(std::make_shared<ColumnNode>(column, table_function_node));
253-
query_node.getProjectionNode() = column_nodes_to_select;
249+
if (columns.empty())
250+
{
251+
auto column_nodes_to_select = std::make_shared<ListNode>();
252+
column_nodes_to_select->getNodes().reserve(1);
253+
column_nodes_to_select->getNodes().emplace_back(std::make_shared<ConstantNode>(1));
254+
query_node.getProjectionNode() = column_nodes_to_select;
255+
}
256+
else
257+
{
258+
query_node.resolveProjectionColumns(columns);
259+
auto column_nodes_to_select = std::make_shared<ListNode>();
260+
column_nodes_to_select->getNodes().reserve(columns.size());
261+
for (auto & column : columns)
262+
column_nodes_to_select->getNodes().emplace_back(std::make_shared<ColumnNode>(column, table_function_node));
263+
query_node.getProjectionNode() = column_nodes_to_select;
264+
}
254265

255266
if (info.has_local_columns_in_where)
256267
{

tests/integration/test_s3_cluster/test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,3 +829,34 @@ def test_joins(started_cluster):
829829
)
830830
res = list(map(str.split, result6.splitlines()))
831831
assert len(res) == 25
832+
833+
result7 = node.query(
834+
f"""
835+
SELECT count() FROM
836+
s3Cluster('cluster_simple',
837+
'http://minio1:9001/root/data/{{clickhouse,database}}/*', 'minio', '{minio_secret_key}', 'CSV',
838+
'name String, value UInt32, polygon Array(Array(Tuple(Float64, Float64)))') AS t1
839+
JOIN
840+
join_table AS t2
841+
ON 1
842+
GROUP BY ALL
843+
SETTINGS object_storage_cluster_join_mode='local';
844+
"""
845+
)
846+
assert result7.strip() == "625"
847+
848+
result8 = node.query(
849+
f"""
850+
SELECT count(), t2.id FROM
851+
s3Cluster('cluster_simple',
852+
'http://minio1:9001/root/data/{{clickhouse,database}}/*', 'minio', '{minio_secret_key}', 'CSV',
853+
'name String, value UInt32, polygon Array(Array(Tuple(Float64, Float64)))') AS t1
854+
JOIN
855+
join_table AS t2
856+
ON 1
857+
GROUP BY ALL
858+
SETTINGS object_storage_cluster_join_mode='local';
859+
"""
860+
)
861+
res = list(map(str.split, result8.splitlines()))
862+
assert len(res) == 25

tests/queries/0_stateless/02126_dist_desc.sql.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ select * from remote('{{host}}', {{args}}) format Null;
1010
{% endfor -%}
1111

1212
system flush logs query_log;
13-
select anyIf(query, is_initial_query), groupArrayIf(query, query_kind = 'Describe' and not is_initial_query) from system.query_log
13+
select anyIf(query, initial_query_id == query_id), groupArrayIf(query, query_kind = 'Describe' and initial_query_id != query_id) from system.query_log
1414
where
1515
type = 'QueryFinish' and
1616
-- current_database is not set for queries on shards

tests/queries/0_stateless/03620_analyzer_distributed_global_in.reference

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ CreatingSets (Create sets before main query execution)
6060
ReadFromSystemNumbers
6161
system flush logs query_log;
6262
-- SKIP: current_database = currentDatabase()
63-
select normalizeQuery(replace(query, currentDatabase(), 'default')) from system.query_log where event_date >= yesterday() and log_comment like '%' || currentDatabase() || '%' and not is_initial_query and type != 'QueryStart' and query_kind = 'Select' order by event_time_microseconds;
63+
select normalizeQuery(replace(query, currentDatabase(), 'default')) from system.query_log where event_date >= yesterday() and log_comment like '%' || currentDatabase() || '%' and initial_query_id != query_id and type != 'QueryStart' and query_kind = 'Select' order by event_time_microseconds;
6464
SELECT `__table1`.`x` AS `x`, `__table1`.`y` AS `y` FROM `default`.`tab0` AS `__table1` HAVING in(`x`, (SELECT `__table1`.`number` + ? AS `?` FROM numbers(?) AS `__table1`))
6565
SELECT `__table1`.`x` AS `x`, `__table1`.`y` AS `y` FROM `default`.`tab0` AS `__table1` HAVING globalIn(`x`, `?`)
6666
SELECT `__table1`.`x` AS `x`, `__table1`.`y` AS `y` FROM `default`.`tab0` AS `__table1` HAVING in(`x`, (SELECT `__table1`.`number` + ? AS `?` FROM numbers(?) AS `__table1`))

tests/queries/0_stateless/03620_analyzer_distributed_global_in.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ select * from (explain indexes=1, distributed=1
2424
);
2525
system flush logs query_log;
2626
-- SKIP: current_database = currentDatabase()
27-
select normalizeQuery(replace(query, currentDatabase(), 'default')) from system.query_log where event_date >= yesterday() and log_comment like '%' || currentDatabase() || '%' and not is_initial_query and type != 'QueryStart' and query_kind = 'Select' order by event_time_microseconds;
27+
select normalizeQuery(replace(query, currentDatabase(), 'default')) from system.query_log where event_date >= yesterday() and log_comment like '%' || currentDatabase() || '%' and initial_query_id != query_id and type != 'QueryStart' and query_kind = 'Select' order by event_time_microseconds;

0 commit comments

Comments
 (0)