zachjsh commented on code in PR #15908:
URL: https://github.com/apache/druid/pull/15908#discussion_r1492945328
##########
sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java:
##########
@@ -299,13 +291,42 @@ public InsertHandler(
SqlExplain explain
)
{
- super(
- handlerContext,
- sqlNode,
- convertQuery(sqlNode),
- explain
- );
- this.sqlNode = sqlNode;
+ super(handlerContext, explain);
+ this.sqlNode = convertQuery(sqlNode);
+ handlerContext.hook().captureInsert(sqlNode);
+ }
+
+ protected static DruidSqlInsert convertQuery(DruidSqlIngest sqlNode)
+ {
+ SqlNode query = sqlNode.getSource();
+
+ // Check if ORDER BY clause is not provided to the underlying query
+ if (query instanceof SqlOrderBy) {
+ SqlOrderBy sqlOrderBy = (SqlOrderBy) query;
+ SqlNodeList orderByList = sqlOrderBy.orderList;
+ if (!(orderByList == null || orderByList.equals(SqlNodeList.EMPTY))) {
+ throw InvalidSqlInput.exception(
+ "Cannot use an ORDER BY clause on a Query of type [%s], use
CLUSTERED BY instead",
+ sqlNode.getOperator().getName()
+ );
+ }
+ }
+ if (sqlNode.getClusteredBy() != null) {
+ query = DruidSqlParserUtils.convertClusterByToOrderBy(query,
sqlNode.getClusteredBy());
+ }
+
+ if (!query.isA(SqlKind.QUERY)) {
+ throw InvalidSqlInput.exception("Unexpected SQL statement type [%s],
expected it to be a QUERY", query.getKind());
+ }
+ return DruidSqlInsert.create(new SqlInsert(
Review Comment:
See comment here:
https://github.com/apache/druid/pull/15908#discussion_r1492944936
--
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]