Skip to content

fix(spark): next_day should not trim whitespace from dayOfWeek#22734

Closed
koopatroopa787 wants to merge 1 commit into
apache:mainfrom
koopatroopa787:fix/22717-next-day-no-trim
Closed

fix(spark): next_day should not trim whitespace from dayOfWeek#22734
koopatroopa787 wants to merge 1 commit into
apache:mainfrom
koopatroopa787:fix/22717-next-day-no-trim

Conversation

@koopatroopa787
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #22717

Rationale for this change

Spark's next_day function performs exact (case-insensitive) matching on the dayOfWeek argument. Whitespace-padded values like ' MO ' are not valid day names in Spark and should return NULL. DataFusion was calling .trim() before matching, so ' MO ' was silently accepted and returned a date — diverging from Spark's behavior.

What changes are included in this PR?

  • datafusion/spark/src/function/datetime/next_day.rs: removed .trim() from the spark_next_day helper so whitespace-padded day names fall through to the None branch.
  • datafusion/sqllogictest/test_files/spark/datetime/next_day.slt: added three regression tests (' MO ', ' Monday ', ' sun ') that all now correctly return NULL.

Are there any user-facing changes?

Yes — next_day(date, ' MO ') now returns NULL instead of a date. This is a bug fix that aligns with Spark's actual behavior.

🤖 Generated with Claude Code

Spark's next_day function performs exact (case-insensitive) matching on
the dayOfWeek argument — whitespace-padded values like ' MO ' are not
valid day names and should return NULL, not be silently accepted.

Remove the .trim() call from spark_next_day so that ' MO ', ' Monday ',
and '  sun  ' all return NULL, matching Spark's actual behavior.

Adds three sqllogictest cases that previously returned a date but now
correctly return NULL.

Closes apache#22717
Copilot AI review requested due to automatic review settings June 3, 2026 15:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Aligns next_day Spark-compat behavior by treating padded (whitespace-surrounded) day name inputs as invalid, matching Spark’s strict parsing.

Changes:

  • Add Sqllogictest cases asserting padded day names return NULL
  • Update spark_next_day implementation to stop trimming day_of_week before matching

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
datafusion/sqllogictest/test_files/spark/datetime/next_day.slt Adds regression tests for padded day-name inputs returning NULL to match Spark behavior
datafusion/spark/src/function/datetime/next_day.rs Removes .trim() so whitespace is no longer ignored when parsing day names

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let date = Date32Type::to_naive_date_opt(days)?;

let day_of_week = day_of_week.trim().to_uppercase();
let day_of_week = day_of_week.to_uppercase();
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) spark labels Jun 3, 2026
@kumarUjjawal
Copy link
Copy Markdown
Contributor

@koopatroopa787 another PR has already been approved for this issue #22720

I would appreciate if you first check if there are open PRs for a particular issue before moving forward.

@koopatroopa787
Copy link
Copy Markdown
Contributor Author

Hey @kumarUjjawal, really sorry about this — I missed #22720 when I checked the issue. Closing this one out. Thanks for the heads up, I'll make sure to check for existing PRs before opening one next time.

@kumarUjjawal
Copy link
Copy Markdown
Contributor

Hey @kumarUjjawal, really sorry about this — I missed #22720 when I checked the issue. Closing this one out. Thanks for the heads up, I'll make sure to check for existing PRs before opening one next time.

Thank you! Appreciate it.

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

Labels

spark sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[datafusion-spark] next_day trims whitespace from dayOfWeek; Spark does not

3 participants