Skip to content

[SPARK-56541][SQL][TESTS] Add test coverage for try_to_date() in DateFunctionSuite#55418

Closed
pratham76 wants to merge 1 commit intoapache:masterfrom
pratham76:add-test-try-to-date
Closed

[SPARK-56541][SQL][TESTS] Add test coverage for try_to_date() in DateFunctionSuite#55418
pratham76 wants to merge 1 commit intoapache:masterfrom
pratham76:add-test-try-to-date

Conversation

@pratham76
Copy link
Copy Markdown
Contributor

@pratham76 pratham76 commented Apr 19, 2026

What changes were proposed in this pull request?

Added comprehensive test coverage for the try_to_date function in DateFunctionsSuite.

Why are the changes needed?

The try_to_date function was added as part of SPARK-52866, but comprehensive test coverage in DateFunctionsSuite seems to have been missed at that time.

Does this PR introduce any user-facing change?

No

How was this patch tested?

UT framework

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

No

@pratham76
Copy link
Copy Markdown
Contributor Author

@MaxGekk @cloud-fan Could you please have a look.

FYI @mihailomilosevic2001. Just following up on your initial PR #51555, which added support for try_to_date(), please have a look as well. Thanks!

@pratham76 pratham76 force-pushed the add-test-try-to-date branch from 9d45d2e to 3ccaa47 Compare April 20, 2026 05:49
@pratham76
Copy link
Copy Markdown
Contributor Author

CI has passed. @HyukjinKwon @MaxGekk Could we check this in?

df2.select(try_to_date(col("s"), "yyyy-dd-MM")),
Seq(Row(null), Row(Date.valueOf("2014-12-31"))))

// invalid dates - returns NULL
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.

nit: These are not only invalid dates, but invalid string inputs in general.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Noted. Have updated the comment as invalid format

Seq(Row(Date.valueOf("2015-07-22")), Row(null)))
checkAnswer(
df2.select(try_to_date(col("s"), "yyyy-dd-MM")),
Seq(Row(null), Row(Date.valueOf("2014-12-31"))))
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.

We need a test coverage for selectExpr too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Updated the test case to have selectExpr as well

@pratham76 pratham76 force-pushed the add-test-try-to-date branch from 3ccaa47 to e12bd27 Compare April 21, 2026 05:01
@MaxGekk
Copy link
Copy Markdown
Member

MaxGekk commented Apr 21, 2026

+1, LGTM. Merging to master.
Thank you, @pratham76 and @HyukjinKwon @mihailomilosevic2001 @dongjoon-hyun for review.

@MaxGekk MaxGekk closed this in 22623e5 Apr 21, 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.

5 participants