LakshSingla commented on a change in pull request #11908:
URL: https://github.com/apache/druid/pull/11908#discussion_r747506946
##########
File path:
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
##########
@@ -384,6 +399,72 @@ private PlannerResult planExplanation(
return new PlannerResult(resultsSupplier,
getExplainStructType(rel.getCluster().getTypeFactory()));
}
+ /**
+ * Construct a {@link PlannerResult} for an 'explain' query from a {@link
RelNode}
+ */
+ private PlannerResult planDruidExplanation(
+ final DruidRel<?> rel
+ )
+ {
+ String resources = null;
+ String explanation = null;
+ try {
+ explanation = dumpDruidPlan(rel);
+ resources = jsonMapper.writeValueAsString(plannerContext.getResources());
+ }
+ catch (JsonProcessingException jpe) {
+ // this should never happen, we create the Resources here, not a user
+ log.error(jpe, "Encountered exception while serializing Resources for
explain output");
+ }
+ final Supplier<Sequence<Object[]>> resultsSupplier = Suppliers.ofInstance(
+ Sequences.simple(ImmutableList.of(new Object[]{explanation,
resources})));
+ return new PlannerResult(resultsSupplier,
getExplainStructType(rel.getCluster().getTypeFactory()));
+ }
+
+ /**
+ * This method doesn't utilize the Calcite's internal {@link
RelOptUtil#dumpPlan} since that tends to be verbose
+ * and not indicative of the native Druid Queries which will get executed
+ * This method assumes that the Planner has converted the RelNodes to
DruidRels, and thereby we can implictly cast it
+ *
+ * @param rel Instance of the root {@link DruidRel} which is formed by
running the planner transformations on it
+ * @return A string representing an array of native queries that correspond
to the given SQL query, in JSON format
+ * @throws JsonProcessingException
+ */
+ public static String dumpDruidPlan(DruidRel<?> rel) throws
JsonProcessingException
+ {
+ List<Map<String, Object>> nativeQueries;
+
+ // Only if rel is an instance of DruidUnionRel, do we run multiple native
queries corresponding to single SQL query
Review comment:
Yes, AFAIK only the outermost union query is run as multiple native
queries (and the results are simply appended), and rest all are implemented as
a single native query. Reference:
https://github.com/apache/druid/blob/223c5692a8292a210a770dc0702f75b4484ae347/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidUnionRel.java#L44
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]