abhishekrb19 commented on code in PR #14441:
URL: https://github.com/apache/druid/pull/14441#discussion_r1242884696


##########
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java:
##########
@@ -302,6 +309,109 @@
     );
   }
 
+  /**
+   * Return resolved clustered by column output names.
+   * For example, consider the following SQL:
+   * <pre>
+   * 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
+   * </pre>
+   *
+   * <p>
+   * The function will return the following clusteredBy columns for the above 
SQL: ["__time", "page_alias", "FLOOR(\"cost\")", cityName"]
+   * Any ordinal and expression specified in the CLUSTERED BY clause will 
resolve to the final output column name.
+   * </p>
+   * @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)
+  {
+    // CLUSTERED BY is an optional clause
+    if (clusteredByNodes == null) {
+      return null;
+    }
+
+    Preconditions.checkArgument(
+        sourceNode instanceof SqlSelect || sourceNode instanceof SqlOrderBy,
+        "Source node must be either SqlSelect or SqlOrderBy, but found [%s]",
+        sourceNode == null ? null : sourceNode.getKind()
+    );
+
+    final SqlSelect selectNode = (sourceNode instanceof SqlSelect) ? 
(SqlSelect) sourceNode
+                                                                   : 
(SqlSelect) ((SqlOrderBy) sourceNode).query;

Review Comment:
   We can ignore this warning. The `checkArgument` above verifies that 
`sourceNode` cannot be null



-- 
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]

Reply via email to