huaxingao commented on PR #34693:
URL: https://github.com/apache/spark/pull/34693#issuecomment-1111629591

   @cloud-fan 
   When JDBC resolves a relation, it needs to get the schema of the relation 
first. JDBC uses this query
   ```
   s"SELECT * FROM $table WHERE 1=0"
   ```
   to discover the schema of the relation. In the user's case, the table is 
`WITH t AS (SELECT x, y FROM tbl) SELECT * FROM t WHERE x > 10` so the query to 
get the schema is
   ```
   SELECT * FROM (WITH t AS (SELECT x, y FROM tbl) SELECT * FROM t WHERE x > 
10) WHERE 1=0
   ```
   but MSSQL server doesn't support this syntax `SELECT * FROM (WITH t AS (...) 
SELECT ... FROM t) WHERE 1=0`
   This PR offers a `withClause` option so the user can split the query 
manually. The query will be changed to the following after the split 
   ```
   WITH t AS (SELECT x, y FROM tbl) SELECT * FROM (SELECT * FROM t WHERE x > 
10) WHERE 1=0
   ```


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