Skip to content

fix: report invalid input string on 1-arg to_date parse failure - #27842

Open
rctruta wants to merge 2 commits into
apache:mainfrom
rctruta:fix/to-date-parse-error-message
Open

rctruta wants to merge 2 commits into
apache:mainfrom
rctruta:fix/to-date-parse-error-message

Conversation

@rctruta

@rctruta rctruta commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

When 1-argument to_date(str) receives an unparseable string (such as to_date('1995-02-30'), to_date('not-a-date'), or to_date('')), it currently returns:

Arrow error: Parser error: Unable to cast to Date32 for converting from i64 to i32 failed

This message is a leftover from the pre-#12227 i64 nanosecond-timestamp -> i32 epoch-day narrowing step; Date32Type::parse(s) parses directly to Option<i32>, so returning that message on None misleads users about why parsing failed and hides the offending value. Returning Error parsing '{s}' as Date32 reports the actual parse failure and input string (consistent with to_time's Error parsing '{s}' as time).

What changes are included in this PR?

  • Update the Date32Type::parse(s) => None arm in datafusion/functions/src/datetime/to_date.rs to return arrow_err!(ParseError(format!("Error parsing '{s}' as Date32"))).
  • Strengthen test_to_date_string_with_invalid_number in to_date.rs and the invalid-date cases in datafusion/sqllogictest/test_files/datetime/dates.slt to assert the full error message across '213111111'/'202412311', '1995-02-30', 'not-a-date', and ''.

What is the testing strategy for this PR?

  • Unit tests in datafusion/functions/src/datetime/to_date.rs (test_to_date_string_with_invalid_number) covering Utf8, LargeUtf8, and Utf8View scalars and arrays.
  • End-to-end sqllogictest cases in datafusion/sqllogictest/test_files/datetime/dates.slt.

Are there any user-facing changes?

Invalid string inputs to 1-argument to_date() now return Arrow error: Parser error: Error parsing '<input>' as Date32 instead of Arrow error: Parser error: Unable to cast to Date32 for converting from i64 to i32 failed.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Nov 29, 2026
@rctruta
rctruta force-pushed the fix/to-date-parse-error-message branch from 794f6c5 to 8d5f0a2 Compare December 3, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1-argument to_date(string) returns leftover "converting from i64 to i32 failed" error on unparseable strings

1 participant