clintropolis commented on code in PR #17894:
URL: https://github.com/apache/druid/pull/17894#discussion_r2043356799
##########
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java:
##########
@@ -283,6 +292,49 @@ public void close()
planner.close();
}
+ private SqlNode processStatementList(SqlNode root, String sql)
+ {
+ if (root instanceof SqlNodeList) {
+ final SqlNodeList nodeList = (SqlNodeList) root;
+ if (!allowSetStatementsToBuildContext && nodeList.size() > 1) {
+ throw InvalidSqlInput.exception("Multiple statements detected in SQL
string[%s], but only a single statement is supported",
+ sql
+ );
+ }
+ final Map<String, Object> contextMap = new LinkedHashMap<>();
+ boolean isMissingDruidStatementNode = true;
+ // convert 0 or more SET statements into a Map of stuff to add to the
query context
+ for (int i = 0; i < nodeList.size(); i++) {
+ SqlNode sqlNode = nodeList.get(i);
+ if (sqlNode instanceof SqlSetOption) {
+ final SqlSetOption sqlSetOption = (SqlSetOption) sqlNode;
+ if (!(sqlSetOption.getValue() instanceof SqlLiteral)) {
+ throw InvalidSqlInput.exception("Invalid sql SET statement[%s],
value must be a literal", sqlSetOption);
+ }
+ final SqlLiteral value = (SqlLiteral) sqlSetOption.getValue();
Review Comment:
this could probably be cooler in the future to also support constant
expressions (like `ARRAY[1,2,3]` or `TO_JSON_STRING(...)` or whatever), but it
is quite a bit more work and I'm not entirely sure the best way to tackle it. I
think we would need to convert it so we could eventually lean on
`DruidRexExecutor` to turn the constant expressions into literals to put in the
context map, but not entirely sure the best way to ago about that, since the
normal sql node -> validator -> rel node path isn't happy if you try to
validate `sqlSetOption` or `sqlSetOption.getValue()`, so need to do.. something
else, just not totally sure what.
--
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]