Skip to content

[common] Fix NullPointerExceptions on null transform inputs - #9214

Open
plusplusjiajia wants to merge 1 commit into
apache:masterfrom
plusplusjiajia:common-transform-null-fixes
Open

[common] Fix NullPointerExceptions on null transform inputs#9214
plusplusjiajia wants to merge 1 commit into
apache:masterfrom
plusplusjiajia:common-transform-null-fixes

Conversation

@plusplusjiajia

@plusplusjiajia plusplusjiajia commented Aug 13, 2026

Copy link
Copy Markdown
Member

Purpose

Three NullPointerExceptions on null transform inputs, all reachable today:

  • TrimTransform reads charsToTrim with toString() before checking it for null, so a null second input throws — even though StringUtils.ltrim/rtrim, which it delegates to, already define a null charsToTrim as a null result.
  • SubstringTransform reads a begin or length field with InternalRow.getInt without an isNullAt check. On a GenericRow that throws; on a columnar row it returns an undefined value, so the rule masks at an arbitrary offset without failing.
  • StringTransform.toString maps inputs with Object::toString and throws on a null input, which ConcatTransform and ConcatWsTransform accept.

All three change behaviour only for inputs that previously threw, so no query that previously succeeded changes its result, and nothing about the persisted JSON format changes.

@plusplusjiajia
plusplusjiajia marked this pull request as ready for review August 13, 2026 16:56
@plusplusjiajia
plusplusjiajia force-pushed the common-transform-null-fixes branch from ab5f184 to d2fce1c Compare August 13, 2026 17:51
@plusplusjiajia plusplusjiajia changed the title [common] Fix two NullPointerExceptions on null transform inputs [common] Fix NullPointerExceptions on null transform inputs Aug 13, 2026
@JingsongLi

Copy link
Copy Markdown
Contributor

SUBSTRING('123', null) still throws an NPE at toString() and does not follow SQL null propagation; consistently reproducible locally.

@plusplusjiajia
plusplusjiajia force-pushed the common-transform-null-fixes branch from d2fce1c to 484835d Compare August 18, 2026 06:42
@plusplusjiajia
plusplusjiajia force-pushed the common-transform-null-fixes branch from 484835d to af0fac4 Compare August 18, 2026 08:17
@plusplusjiajia

Copy link
Copy Markdown
Member Author

SUBSTRING('123', null) still throws an NPE at toString() and does not follow SQL null propagation; consistently reproducible locally.

@JingsongLi Thanks, fixed.

The old code only checked for null when the position was a FieldRef. A literal null went straight to Integer.parseInt(...) and threw. Now any null input gives null, wherever it comes from:

SUBSTRING('123', null) -> null
SUBSTRING('123', 1, null) -> null

One change worth noting: the null check now runs before the "begin past the end" check, so SUBSTRING('123', 99, null) returns null where it used to return ''. That keeps one simple rule — null always wins — and matches Spark, whose Substring is NullIntolerant.

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