Skip to content

[Spark] Check for null arguments in CDC read - #4489

Merged
allisonport-db merged 3 commits into
delta-io:masterfrom
ZiyaZa:cdc-null-arg
May 7, 2025
Merged

allisonport-db merged 3 commits into
delta-io:masterfrom
ZiyaZa:cdc-null-arg

Conversation

@ZiyaZa

@ZiyaZa ZiyaZa commented May 1, 2025

Copy link
Copy Markdown
Contributor

Which Delta project/connector is this regarding?

  • Spark
  • Standalone
  • Flink
  • Kernel
  • Other (fill in here)

Description

CDC read query table_changes does not support null value as the start or end parameter. However, passing null argument via the SQL API results in NullPointerException. This PR adds a check for null argument and throws a DeltaIllegalArgumentException with the new error class DELTA_CDC_READ_NULL_RANGE_BOUNDARY for the SQL API.

Similarly, providing null version for Scala API resulted in NumberFormatException. Added a new error class DELTA_VERSION_INVALID for this purpose (similar to existing DELTA_TIMESTAMP_INVALID for null timestamps).

How was this patch tested?

New unit tests are added in DeltaCDCScalaSuite and DeltaCDCSQLSuite to test for cases when either the start or the end parameter is null. Tests expect a proper DeltaIllegalArgumentException (SQL) or DeltaAnalysisException (Scala) to be thrown, which was not the case before.

Other unit tests are added to DeltaErrorsSuite to test if the error messages are correctly reported for the new error classes.

Does this PR introduce any user-facing changes?

No

@andreaschat-db andreaschat-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@allisonport-db
allisonport-db merged commit 5ccb599 into delta-io:master May 7, 2025
OussamaSaoudi pushed a commit that referenced this pull request Sep 26, 2025
#### Which Delta project/connector is this regarding?

- [x] Spark
- [ ] Standalone
- [ ] Flink
- [ ] Kernel
- [ ] Other (fill in here)

## Description

The previous fix for `NullPointerException` in #4489 wasn't enough to
catch all cases: `table_changes('tableName', CAST(null AS INT))` would
still result in NPE. This PR fixes it by wrapping the code in try-catch,
and rethrowing correct error on NPE.

## How was this patch tested?

New unit test with casted null.

## Does this PR introduce _any_ user-facing changes?

No
huashi-st pushed a commit to huashi-st/delta that referenced this pull request Apr 24, 2026
#### Which Delta project/connector is this regarding?

- [x] Spark
- [ ] Standalone
- [ ] Flink
- [ ] Kernel
- [ ] Other (fill in here)

## Description

The previous fix for `NullPointerException` in delta-io#4489 wasn't enough to
catch all cases: `table_changes('tableName', CAST(null AS INT))` would
still result in NPE. This PR fixes it by wrapping the code in try-catch,
and rethrowing correct error on NPE.

## How was this patch tested?

New unit test with casted null.

## Does this PR introduce _any_ user-facing changes?

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

3 participants