abhishekrb19 commented on code in PR #14441:
URL: https://github.com/apache/druid/pull/14441#discussion_r1241013393
##########
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java:
##########
@@ -302,6 +309,82 @@ public static SqlOrderBy convertClusterByToOrderBy(SqlNode
query, SqlNodeList cl
);
}
+ /**
+ * Return resolved clustered by columns specified to output columns.
+ * For example,
+ * EXPLAIN PLAN FOR
+ * INSERT INTO w000
+ * SELECT
+ * TIME_PARSE("timestamp") AS __time,
+ * page AS page_alias,
+ * FLOOR("cost"),
+ * country,
+ * citName
+ * FROM ...
+ * PARTITIONED BY DAY
+ * CLUSTERED BY 1, 2, 3, cityName
+ *
+ * The above SQL will return the following clusteredBy columns: ["__time",
"page_alias", "FLOOR(\"cost\")", cityName"]
+ * Any ordinal and expression specified in the CLUSTERED BY clause will
resolve to the final output column name.
+ * @param clusteredByNodes List of {@link SqlNode}s representing columns to
be clustered by.
+ * @param sourceNode The select or order by source node.
+ */
+ @Nullable
+ public static List<String>
resolveClusteredByColumnsToOutputColumns(SqlNodeList clusteredByNodes, SqlNode
sourceNode)
Review Comment:
Right, the function is only accounting for types that are allowed in a
`CLUSTERED BY` clause as the syntax tree can be recursive and exhaustive -
partly adopted from the
[grammar](https://github.com/apache/druid/blob/master/sql/src/main/codegen/includes/insert.ftl#L37C19-L37C31).
The logic here is taking a defensive approach, so if we expect any unexpected
type along the way, we'd throw an exception. I've added some inline comments in
the different branches in this code.
Also, please see the unit tests in `DruidSqlParserUtilsTest`,
`CalciteInsertDmlTest.java` and `CalciteReplaceDmlTest.java`.
--
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]