Skip to content

doc: Add documentation explaining the behavior of null values ​​in struct comparisons#21226

Open
xiedeyantu wants to merge 3 commits intoapache:mainfrom
xiedeyantu:tuple
Open

doc: Add documentation explaining the behavior of null values ​​in struct comparisons#21226
xiedeyantu wants to merge 3 commits intoapache:mainfrom
xiedeyantu:tuple

Conversation

@xiedeyantu
Copy link
Copy Markdown
Member

Which issue does this PR close?

  • Closes #.

Rationale for this change

DataFusion already supports tuple-like and STRUCT comparisons, but the user-facing documentation did not clearly describe the current comparison semantics, especially around lexicographical ordering and NULL handling. The IN documentation also did not explain tuple-like values.

What changes are included in this PR?

  • Added a short STRUCT comparison note to struct_coercion.md, documenting that:
    • STRUCT values support standard comparison operators
    • comparisons are lexicographical by field order
    • NULL is ordered before non-NULL
  • Added minimal examples for STRUCT comparisons, including a NULL example
  • Added a short note to subqueries.md explaining that tuple-like IN uses DataFusion's struct equality semantics
  • Added a concrete example:
    • SELECT (7521, 30) IN ((7521, NULL));
    • result: false

Are these changes tested?

No new tests were added. This PR only updates documentation for existing behavior, and the documented behavior is already covered by existing tuple/struct comparison and IN tests.

Are there any user-facing changes?

Yes. This PR updates the SQL user documentation to clarify the current semantics of STRUCT comparisons and tuple-like IN expressions.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 29, 2026
@xiedeyantu
Copy link
Copy Markdown
Member Author

@alamb I have submitted a new PR related to #21054. I closed that PR and am continuing with this one. Please have a look. Thanks!

@xiedeyantu xiedeyantu changed the title doc: Add documentation explaining the behavior of null values ​​in … doc: Add documentation explaining the behavior of null values ​​in struct comparisons Mar 29, 2026
Copy link
Copy Markdown
Member

@asolimando asolimando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: only one minor comment but the extra doc is already very helpful

For tuple-like values, `IN` uses DataFusion's struct equality semantics:

```sql
SELECT (7521, 30) IN ((7521, NULL));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an example retuning true involving a comparison with NULL elements (like that of line 227 above), which is probably the most surprising result if one expects standard SQL semantics. WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be helpful to add this in. Please feel free to let me know if anything else needs to be added. This way, users can quickly understand the differences involved.

Copy link
Copy Markdown
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @xiedeyantu it would be great also to include a link to this section into a doc describing the struct builtin function

@xiedeyantu
Copy link
Copy Markdown
Member Author

xiedeyantu commented Mar 30, 2026

Thanks @xiedeyantu it would be great also to include a link to this section into a doc describing the struct builtin function

@comphead Thanks for your reply! I have added a link to struct function. Please review again if it looks well for you.

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

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants