Conversation
|
@andygrove Please review. |
andygrove
left a comment
There was a problem hiding this comment.
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 withtoUpperCase(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.
|
Thanks. I can take both follow-ups separately. |
andygrove
left a comment
There was a problem hiding this comment.
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:
-
The
onlyif evaluaterecords (date_part.slt:59, :159, :274) never run. Nothing in this repo's runner, or indatafusion-sqllogictest, registers anevaluatelabel, so sqllogictest always skips them. I confirmed this by changing the expected text of theQUARTERSone to garbage, and the file still passed. Theskipif evaluaterecords run as plain records, which is what we want. Since the execution-time path is already covered byinvoke_rejects_an_invalid_fieldandinvoke_rejects_an_invalid_field_for_a_timestamp, I'd drop theonlyif evaluatecopies and theskipif evaluatelines. Then the three cases go back to plainquery errorrecords with the full expected output. -
My earlier suggestion was broader than it needed to be, sorry. Returning
Originalfor everyNotConstantalso moves a column field from a planning error to an execution error.SELECT date_part(f, d) FROM tnow 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. CouldsimplifyreturnOriginalonly whenpart_expris anExpr::Placeholder, and keep the planning error for other non-literal fields? A foldable expression such asconcat('ye', 'ar')is already folded to a literal beforesimplifysees it (it returns 2000 today), so it isn't affected. An slt case fordate_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. -
Minor, and it predates this PR: Spark types
date_part(NULL, d)as DOUBLE (typeofreturnsdouble, 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.
|
@andygrove Fixed 1 and 2. Thanks. |
andygrove
left a comment
There was a problem hiding this comment.
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.
|
@andygrove Could you please merge this ? |
|
@andygrove Opened #374 and #375. Thanks. |
Which issue does this PR close?
date_parterrors when evaluated withoutsimplify:invoke_with_argsis not implemented #308.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.