Skip to content

Commit

Permalink
canMaterializeQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Oct 10, 2024
1 parent b36e9eb commit 27c80e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ private <T> DataSource inlineIfNecessary(
dryRun
);
}
} else if (canRunQueryUsingLocalWalker(subQuery) || canRunQueryUsingClusterWalker(subQuery)) {
} else if (canMaterializeQuery(subQuery)) {
// Subquery needs to be inlined. Assign it a subquery id and run it.

final Sequence<?> queryResults;
Expand Down Expand Up @@ -516,6 +516,26 @@ private <T> DataSource inlineIfNecessary(
}
}

private boolean canMaterializeQuery(final Query query)
{
final DataSource dataSourceFromQuery = query.getDataSource();
final DataSourceAnalysis analysis = dataSourceFromQuery.getAnalysis();
final QueryToolChest<T, Query<T>> toolChest = warehouse.getToolChest(query);

// 1) Must be based on a concrete datasource that is not a table.
// 2) Must be based on globally available data (so we have a copy here on the Broker).
// 3) If there is an outer query, it must be handleable by the query toolchest (the local walker does not handle
// subqueries on its own).
// 1) Must be based on a concrete table (the only shape the Druid cluster can handle).
// 2) If there is an outer query, it must be handleable by the query toolchest (the cluster walker does not handle
// subqueries on its own).
boolean toolchestCanPerform = !(dataSourceFromQuery instanceof QueryDataSource)
|| toolChest.canPerformSubquery(((QueryDataSource) dataSourceFromQuery).getQuery());
return toolchestCanPerform && analysis.isConcreteBased()
&& (dataSourceFromQuery.isGlobal() || analysis.isTableBased());

}

/**
* Decorate query runners created by {@link #clusterClient}, adding result caching, result merging, metric
* emission, etc. Not to be used on runners from {@link #localClient}, since we expect it to do this kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4369,7 +4369,6 @@ public void testUnionAllTwoQueriesLeftQueryIsJoin(Map<String, Object> queryConte
);
}

@NotYetSupported(Modes.UNION_WITH_COMPLEX_OPERAND)
@MethodSource("provideQueryContexts")
@ParameterizedTest(name = "{0}")
public void testUnionAllTwoQueriesRightQueryIsJoin(Map<String, Object> queryContext)
Expand Down

0 comments on commit 27c80e8

Please sign in to comment.