sahilkumarsingh opened a new pull request, #53390:
URL: https://github.com/apache/spark/pull/53390

   
   ### What changes were proposed in this pull request?
   
   This PR will address the issue 
[SPARK-54634](https://issues.apache.org/jira/browse/SPARK-54634).
   
   With this, I am adding a user-friendly error message when users write SQL 
queries with an empty IN clause, like: _SELECT * FROM table WHERE col IN ()_
   
   ### Why are the changes needed?
   
   When users write SQL with an empty IN clause, Spark currently produces a 
syntax error of subclass [PARSE_SYNTAX_ERROR], which leads the user to believe 
that their syntax is incorrect, whereas the actual issue is due to the absence 
of values for the IN clause. Hence, the current error message does not 
communicate the right intention to the user.
   
   This change provides a clear, actionable error message that explains the 
actual problem 
   and suggests alternatives.
   
   Example - Before:
   ```
   org.apache.spark.sql.catalyst.parser.ParseException:
   [PARSE_SYNTAX_ERROR] Syntax error at or near 'IN'. SQLSTATE: 42601 (line 1, 
pos 33)
   ```
   
   Example - After:
   ```
   org.apache.spark.sql.catalyst.parser.ParseException:
   [INVALID_SQL_SYNTAX.EMPTY_IN_PREDICATE] Invalid SQL syntax: IN predicate 
requires at least one value. Empty IN clauses like 'IN ()' are not allowed. 
Consider using 'WHERE FALSE' if you need an always-false condition, or provide 
at least one value in the IN list. SQLSTATE: 42000
   ```
   
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, users will now see a better error message.
   
   Code executed: `spark.sql("SELECT * FROM range(10) WHERE id IN ()").show()`
   
   Before output:
   <img width="1080" height="309" alt="image" 
src="https://github.com/user-attachments/assets/1c6503e5-9e9c-4380-a9c0-87c9122417e6";
 />
   
   After output:
   <img width="1080" height="342" alt="image" 
src="https://github.com/user-attachments/assets/36169839-1ff4-4743-8666-cf87cfa622b5";
 />
   
   
   
   ### How was this patch tested?
   
   - I have added unit tests in QueryParsingErrorsSuite.scala and SQL golden 
tests added in predicate-functions.sql
   - I have also tested the build locally by running the query in spark-shell
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude (Anthropic) - used for code assistance, test 
generation, and documentation.
   


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