Skip to content

[SPARK-56976][SQL] Support Two-Argument IF(condition, value) Returning NULL#56025

Open
Richard-Durkee wants to merge 1 commit into
apache:masterfrom
Richard-Durkee:two-arg-if
Open

[SPARK-56976][SQL] Support Two-Argument IF(condition, value) Returning NULL#56025
Richard-Durkee wants to merge 1 commit into
apache:masterfrom
Richard-Durkee:two-arg-if

Conversation

@Richard-Durkee
Copy link
Copy Markdown

@Richard-Durkee Richard-Durkee commented May 20, 2026

What changes were proposed in this pull request?

Add an auxiliary constructor to the If expression that accepts two arguments, defaulting falseValue to Literal(null). This allows IF(condition, value) to return NULL when the condition is false.

Why are the changes needed?

The two-argument IF expression is supported by Trino and Presto. Users migrating queries from these systems currently get an arity error.

Does this PR introduce any user-facing change?

Yes. IF(condition, value) now returns value when true and NULL when false, instead of throwing an error.

How was this patch tested?

New golden file SQL test (if-two-arg.sql). Existing conditional-functions.sql and ifCoercion.sql tests pass with no regressions.

Was this patch authored or co-authored using generative AI tooling?

No

@nnguyen168
Copy link
Copy Markdown

Hi @Richard-Durkee, thanks for adding this compatibility feature! The change is clean and well-tested.

I noticed this aligns with MySQL/Trino/BigQuery behavior. A couple of thoughts:

  1. The auxiliary constructor approach is elegant — keeps backward compatibility.
  2. Golden file tests are comprehensive.

Minor: Have you considered adding a note to the SQL function documentation about this two-argument form?

Let me know if I can help with anything!

@Richard-Durkee
Copy link
Copy Markdown
Author

Richard-Durkee commented May 24, 2026

Hi @Richard-Durkee, thanks for adding this compatibility feature! The change is clean and well-tested.

I noticed this aligns with MySQL/Trino/BigQuery behavior. A couple of thoughts:

  1. The auxiliary constructor approach is elegant — keeps backward compatibility.
  2. Golden file tests are comprehensive.

Minor: Have you considered adding a note to the SQL function documentation about this two-argument form?

Let me know if I can help with anything!

Thanks! The @ExpressionDescription annotation was updated with the two-argument form, my understanding is that this auto-generates the SQL function docs. If this feature would be useful to you, consider leaving a comment on the Jira issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants