Skip to content

Conversation

@sahilkumarsingh
Copy link

What changes were proposed in this pull request?

This PR will address the issue 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:
image

After output:
image

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.

@github-actions github-actions bot added the SQL label Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant