Registry Mirror
Skip to content

Conversation

@TechWizard9999

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Explained in the issue.

What changes are included in this PR?

Add a working invoke with args that checks the field and calls date part. the error tests now match only the message so they also pass without simplify.

Are these changes tested?

Yes, added unit tests that call invoke with args directly.

Are there any user-facing changes?

No.

@TechWizard9999

Copy link
Copy Markdown
Contributor Author

@andygrove Please review.

@andygrove andygrove left a comment

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.

Thanks for this! Moving the field check into a shared check_field and giving invoke_with_args a real implementation looks good, and the unit tests are thorough. A few comments inline. The first three are the ones I'd like to see addressed before merging; the rest are minor.

Two things this PR didn't introduce, for a possible follow-up:

  • The field name is lower-cased with Rust's Unicode to_lowercase(), while Spark upper-cases with toUpperCase(Locale.ROOT), so some non-ASCII spellings Spark accepts (for example 'mınute' with a dotless ı) are rejected here.
  • The error names the Arrow type (Date32) and has no error class, whereas Spark 4.x reports [INVALID_EXTRACT_FIELD] Cannot extract `QUARTERS` from DATE '2000-01-01'. The new execution path now surfaces this message too.

@TechWizard9999

Copy link
Copy Markdown
Contributor Author

Thanks. I can take both follow-ups separately.

@andygrove andygrove left a comment

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.

Thanks for the quick turnaround. I checked out 0c51837 and went through the changes since 4d01aa8. cargo fmt --all --check, cargo clippy --all-targets --all-features -- -D warnings, cargo test -p datafusion-spark (381 passed) and cargo test -p datafusion-spark-sqllogictest (249 of 249 files) all pass locally.

All four points from the last round are addressed. simplify returns Original for NotConstant and only looks up the source type for Invalid. try_as_str accepts the dictionary-encoded constant: the new unit test covers it, and date_part(arrow_cast('year', 'Dictionary(Int32, Utf8)'), d) returns 2000 end to end. The planning-time error cases now pin the full simplify_expressions / Error during planning output. The two new unit tests do reach the execution-time branches (array field -> NotConstant, DAYOFYEAR on Timestamp(µs) -> Invalid). I also ran the file through the PySpark runner against Spark 4.2.0. The only differences are the known SECOND scale/fraction gap (#38) and the NULL-field return type (see 3).

A couple of things:

  1. The onlyif evaluate records (date_part.slt:59, :159, :274) never run. Nothing in this repo's runner, or in datafusion-sqllogictest, registers an evaluate label, so sqllogictest always skips them. I confirmed this by changing the expected text of the QUARTERS one to garbage, and the file still passed. The skipif evaluate records run as plain records, which is what we want. Since the execution-time path is already covered by invoke_rejects_an_invalid_field and invoke_rejects_an_invalid_field_for_a_timestamp, I'd drop the onlyif evaluate copies and the skipif evaluate lines. Then the three cases go back to plain query error records with the full expected output.

  2. My earlier suggestion was broader than it needed to be, sorry. Returning Original for every NotConstant also moves a column field from a planning error to an execution error. SELECT date_part(f, d) FROM t now fails at execution with "must be a constant string", and on an empty input (... WHERE false) it succeeds with zero rows. Spark rejects both at analysis time with [NON_FOLDABLE_ARGUMENT]. The case we actually needed to defer is a placeholder. Could simplify return Original only when part_expr is an Expr::Placeholder, and keep the planning error for other non-literal fields? A foldable expression such as concat('ye', 'ar') is already folded to a literal before simplify sees it (it returns 2000 today), so it isn't affected. An slt case for date_part(column, d) would be good to add at the same time. Not a blocker if you'd rather do it separately, but it's a small change.

  3. Minor, and it predates this PR: Spark types date_part(NULL, d) as DOUBLE (typeof returns double, and the PySpark runner flags date_part.slt:257 as "results match, column types differ"), while we return a NULL INT. The value is the same, so I'm fine leaving this for a follow-up issue.

For reference, the new PREPARE/EXECUTE test covers the case from the last review, since the PREPARE now plans. Note that EXECUTE substitutes the parameter and re-runs simplify, so it goes through the literal path rather than invoke_with_args. EXECUTE p('QUARTERS') gives the planning-time Cannot extract error and EXECUTE p(NULL) returns NULL, both as expected.

I also didn't find open issues for the two follow-ups from the last review (Unicode lower-casing vs toUpperCase(Locale.ROOT), and the INVALID_EXTRACT_FIELD error class). Could you open them when you get a chance, so they don't get lost?

With 1 fixed, this looks good to merge to me. 2 would be nice to have.

@TechWizard9999

Copy link
Copy Markdown
Contributor Author

@andygrove Fixed 1 and 2. Thanks.

@andygrove andygrove left a comment

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.

Thanks for the updates. I checked 3bee4f4 and both points from my last review are fixed. The onlyif evaluate copies are gone and the planning-time cases pin the full output again. simplify now only defers a bare placeholder, and the new slt cases cover a column field with and without rows. I also confirmed against Spark 4.2 that a column field is rejected with [NON_FOLDABLE_ARGUMENT] even on an empty input, so this matches.

Two small things before merge. Could you refresh the PR description, since it becomes the commit message? The line about the error tests matching only the message no longer applies. "Are there any user-facing changes?" should mention that a prepared statement parameter now works as the field (PREPARE p(VARCHAR) AS SELECT date_part($1, d)), and that a column field now fails at planning with "must be a constant string" instead of an internal error.

Could you also open the follow-up issues and link them here? They are the Unicode lower-casing vs toUpperCase(Locale.ROOT), the INVALID_EXTRACT_FIELD error class, and date_part(NULL, d) being typed DOUBLE in Spark.

@TechWizard9999

Copy link
Copy Markdown
Contributor Author

@andygrove Could you please merge this ?
Thanks!!

@andygrove
andygrove merged commit 5314d77 into apache:main Nov 18, 2026
8 checks passed
@TechWizard9999

Copy link
Copy Markdown
Contributor Author

@andygrove Opened #374 and #375. Thanks.

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.

[Bug] date_part errors when evaluated without simplify: invoke_with_args is not implemented

2 participants