Skip to content

Match NaN partition values with IsNaN in partition predicates - #4283

Closed
linzch3 wants to merge 1 commit into
apache:mainfrom
linzch3:fix-nan-partition-predicate
Closed

linzch3 wants to merge 1 commit into
apache:mainfrom
linzch3:fix-nan-partition-predicate

Conversation

@linzch3

@linzch3 linzch3 commented Nov 4, 2026

Copy link
Copy Markdown

Closes #4277

Rationale for this change

Transaction._build_partition_predicate emits IsNull for a None partition value and EqualTo for anything else. Expression literals reject NaN, so as soon as a delete or overwrite touches a NaN identity partition it fails with ValueError: Cannot create expression literal from NaN. This affects delete() (both dropping and rewriting the file), overwrite(), upsert and dynamic_partition_overwrite. Both callers (_build_delete_files_partition_predicate and dynamic_partition_overwrite) go through this helper.

This PR takes the narrow fix suggested in the issue: a float NaN partition value now becomes IsNaN(Reference(field)), next to the existing IsNull branch.

Are these changes tested?

Yes. test_delete_and_overwrite_nan_identity_partition in tests/catalog/test_catalog_behaviors.py runs against each catalog fixture and covers the cases from the issue on a double identity partition:

  • delete("id = 3"), which rewrites the NaN file
  • delete("value is nan"), which drops the NaN file
  • dynamic_partition_overwrite with NaN incoming data
  • a full overwrite

Without the fix it fails with the NaN literal error.

Ran locally:

  • pytest tests/ -m unit --ignore=tests/integration: 4475 passed. The only failures are 4 Kerberos tests in test_hive.py, which also fail on main here because a Kerberos module is missing in my environment.
  • prek (ruff, ruff-format, mypy, codespell) on the changed files

Are there any user-facing changes?

Yes, a bug fix: deletes and overwrites on tables with a NaN identity partition no longer raise.

This change was prepared with an AI coding assistant (Grok Bot) and tested locally as described above.

_build_partition_predicate used EqualTo for every non-null partition
value, and expression literals reject NaN, so delete, overwrite and
dynamic_partition_overwrite failed with "Cannot create expression
literal from NaN" whenever they touched a NaN identity partition. Use
IsNaN for a NaN value, next to the existing IsNull branch for None.

Closes apache#4277

Generated-by: Grok Bot (AI coding assistant)
@linzch3 linzch3 closed this Nov 4, 2026
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.

delete() and overwrite() raise Cannot create expression literal from NaN on a NaN identity partition

1 participant