abhishekagarwal87 commented on PR #12708:
URL: https://github.com/apache/druid/pull/12708#issuecomment-1184112654

   > @abhishekagarwal87, good point:
   > 
   > > This PR also paves the way to support multiple SQL statements now that 
we have forked the PlannerImpl class. We could change the `CalcitePlanner` to 
call `parseStmtList()` instead of `parseStmt()`. The calcite parser supports 
multiple SQL statements but the planner doesn't expose it.
   > 
   > The trick is that planning more than one statement at a time creates a 
race condition. In a normal DB, the following would fail:
   > 
   > ```sql
   > CREATE TABLE foo ...;
   > SELECT * FROM foo
   > ```
   > 
   > If we plan both statements up front, the second will fail because table 
`foo` doesn't exist yet. Once we support `INSERT`, we have the same issue, 
since `INSERT` can create a table. Still, if we had `ALTER SESSION SET <option> 
= <value>` (in place of context variables), it would be handy to do:
   > 
   > ```sql
   > ALTER SESSION SET "priority" = 1;
   > SELECT ...
   > ```
   > 
   > One solution that some tools use is to first split the statements at the 
semi-colon delimiter, then plan and execute them one by one. That eliminates 
the race conditions. For the above, we could create a mini per-request 
"session" to track the options, seeded with query context values.
   
   Indeed.  statements like `ALTER SESSION` was infact the very reason why we 
were exploring supporting multiple statements. So users can write the SQL query 
like 
   ```
   SET CONTEXT timeout=30000;
   SET CONTEXT priority=1;
   SELECT COUNT(*) from the_awesome_table
   ```
   
   Takes us one step closer to just submitting SQL as a string to Druid. Right 
now, that SQL needs to be wrapped up inside a JSON. 


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