Zachgille commented on issue #26469:
URL: https://github.com/apache/datafusion/issues/26469#issuecomment-7406406854

   Hi @CuteChuanChuan and @Dodothereal — is either of you still planning to 
finish this? #26752 has been in draft since Nov 9 and now has merge conflicts 
with `main` in `expr_schema.rs` and `cast_extension_type_metadata.slt`.
   
   I ran into the same nullability split while looking at #27791. A couple 
extra notes:
   
   - Besides aggregates, it also breaks `CREATE TABLE ... AS SELECT` and 
`SELECT DISTINCT` / `UNION` over the cast:
     ```sql
     CREATE TABLE k_src (u UUID NOT NULL, b BYTEA NOT NULL);
     INSERT INTO k_src VALUES (X'00010203040506070809000102030506', 
X'00010203040506070809000102030506');
   
     CREATE TABLE k1 AS SELECT CAST(b AS UUID) AS id FROM k_src;
     -- Error during planning: Mismatch between schema and batches
   
     SELECT DISTINCT CAST(b AS UUID) AS id FROM k_src;
     -- Internal error: Physical input schema should be the same as the one 
converted from logical input schema.
     --   - field nullability at index 0 [id]: (physical) true vs (logical) 
false.
     ```
   - It blocks #27791: using a field-aware cast (`Cast::new_from_field`) in the 
CTAS projection hits this same error whenever the optimizer folds an expression 
to non-null (e.g. `CASE WHEN true THEN raw ELSE NULL END` over a `NOT NULL` 
column).
   - Applying #26752's logical rule locally resolves the CTAS, `DISTINCT`, 
`UNION`, and #27791 cases (with `CAST(not_null AS UUID)` reporting nullable in 
`DESCRIBE` and writing as `OPTIONAL` in Parquet `COPY`).
   
   If neither of you plans to continue, I'd be happy to pick up #26752 with 
credit—rebasing it, addressing the review comments, and adding these test 
cases. Otherwise I'll leave it with you!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to