Skip to content

Commit 39882f5

Browse files
committed
Iceberg cross join
1 parent 70805a8 commit 39882f5

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/Storages/IStorageCluster.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void IStorageCluster::updateQueryWithJoinToSendIfNeeded(
223223
{
224224
case ObjectStorageClusterJoinMode::LOCAL:
225225
{
226-
if (has_join || has_local_columns_in_where)
226+
if (has_join || has_cross_join || has_local_columns_in_where)
227227
{
228228
auto modified_query_tree = query_tree->clone();
229229

@@ -237,7 +237,7 @@ void IStorageCluster::updateQueryWithJoinToSendIfNeeded(
237237

238238
auto & query_node = modified_query_tree->as<QueryNode &>();
239239

240-
if (has_join)
240+
if (has_join || has_cross_join)
241241
{
242242
if (table_function_searcher.getType().value() == QueryTreeNodeType::TABLE_FUNCTION)
243243
{
@@ -246,11 +246,20 @@ void IStorageCluster::updateQueryWithJoinToSendIfNeeded(
246246
auto & table_function_ast = table_function->as<ASTFunction &>();
247247
query_tree_distributed->setAlias(table_function_ast.alias);
248248
}
249-
else
249+
else if (has_join)
250250
{
251251
auto join_node = query_node.getJoinTree();
252252
query_tree_distributed = join_node->as<JoinNode>()->getLeftTableExpression()->clone();
253253
}
254+
else
255+
{
256+
SearcherVisitor join_searcher({QueryTreeNodeType::CROSS_JOIN}, context);
257+
join_searcher.visit(modified_query_tree);
258+
auto cross_join_node = join_searcher.getNode();
259+
if (!cross_join_node)
260+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Can't find CROSS JOIN node");
261+
query_tree_distributed = cross_join_node->as<CrossJoinNode>()->getTableExpressions()[0]->clone();
262+
}
254263
}
255264

256265
// Find add used columns from table function to make proper projection list
@@ -528,10 +537,15 @@ QueryProcessingStage::Enum IStorageCluster::getQueryProcessingStage(
528537
throw Exception(ErrorCodes::NOT_IMPLEMENTED,
529538
"object_storage_cluster_join_mode!='allow' is not supported without allow_experimental_analyzer=true");
530539

531-
SearcherVisitor join_searcher({QueryTreeNodeType::JOIN}, context);
540+
SearcherVisitor join_searcher({QueryTreeNodeType::JOIN, QueryTreeNodeType::CROSS_JOIN}, context);
532541
join_searcher.visit(query_info.query_tree);
533542
if (join_searcher.getNode())
534-
has_join = true;
543+
{
544+
if (join_searcher.getType() == QueryTreeNodeType::JOIN)
545+
has_join = true;
546+
else
547+
has_cross_join = true;
548+
}
535549

536550
SearcherVisitor table_function_searcher({QueryTreeNodeType::TABLE, QueryTreeNodeType::TABLE_FUNCTION}, context);
537551
table_function_searcher.visit(query_info.query_tree);
@@ -554,7 +568,7 @@ QueryProcessingStage::Enum IStorageCluster::getQueryProcessingStage(
554568
has_local_columns_in_where = true;
555569
}
556570

557-
if (has_join || has_local_columns_in_where)
571+
if (has_join || has_cross_join || has_local_columns_in_where)
558572
return QueryProcessingStage::Enum::FetchColumns;
559573
}
560574

src/Storages/IStorageCluster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class IStorageCluster : public IStorage
104104
String cluster_name;
105105

106106
mutable bool has_join = false;
107+
mutable bool has_cross_join = false;
107108
mutable bool has_local_columns_in_where = false;
108109
};
109110

0 commit comments

Comments
 (0)