sunchao commented on code in PR #6428: URL: https://github.com/apache/datafusion-comet/pull/6428#discussion_r4151952438
########## spark/src/test/resources/sql-tests/expressions/struct/create_named_struct_nullability.sql: ########## @@ -0,0 +1,61 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +-- Config: spark.comet.sparkToColumnar.enabled=true +-- Config: spark.comet.sparkToColumnar.supportedOperatorList=Range +-- Config: spark.sql.caseSensitive=false + +-- Catalyst proves BIGINT -> DOUBLE nonnullable; native cast inference is conservative. +-- The computed struct must have the same field flags as the typed NULL array element. +query +SELECT array(named_struct('score', CAST(id AS DOUBLE), + 'amount', CAST(id AS DECIMAL(18,2))), NULL) +FROM range(8) + +-- The field contract must also survive a nested constructor with an actually nullable child. +query +SELECT array(named_struct('nested', named_struct('score', CAST(id AS DOUBLE), + 'optional', CASE WHEN id % 2 = 0 THEN id END)), NULL) +FROM range(8) + +-- CASE unions nullability by ordinal, even when case-insensitive names swap places. +query +SELECT CASE WHEN id % 2 = 0 + THEN named_struct('x', CAST(id AS DOUBLE), 'X', CAST(NULL AS DOUBLE)) + ELSE named_struct('X', CAST(NULL AS DOUBLE), 'x', CAST(id AS DOUBLE)) +END FROM range(8) + +-- An untyped NULL branch must not restore name-based struct coercion. +query +SELECT CASE WHEN id % 3 = 0 + THEN named_struct('x', CAST(id AS DOUBLE), 'X', CAST(NULL AS DOUBLE)) + WHEN id % 3 = 1 THEN NULL + ELSE named_struct('X', CAST(NULL AS DOUBLE), 'x', CAST(id AS DOUBLE)) +END FROM range(8) + +-- Spark compares struct fields by position, irrespective of field names. +query +SELECT named_struct('x', CAST(id AS DOUBLE), 'y', CAST(NULL AS DOUBLE)) = Review Comment: [P2] Could this comparison move into a separate fixture with `-- MinSparkVersion: 4.0`? Spark 3.4 and 3.5 require corresponding struct field names to match, even with `spark.sql.caseSensitive=false`. This query therefore raises `DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES` instead of returning rows. Because the file has no version gate and uses ordinary `query` mode, it breaks `CometSqlFileTestSuite` under the supported 3.x profiles. Keep the other five queries available on those versions. Evidence: Executed all six queries from the exact-head fixture on the repository-supported Spark 3.5.9 with case sensitivity disabled. Queries 1–4 and 6 returned eight rows. Query 5 failed with `DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES`, identifying incompatible `STRUCT<x: DOUBLE, y: DOUBLE>` and `STRUCT<y: DOUBLE, x: DOUBLE>`. Spark 3.4.3 and 3.5.9 source uses name-sensitive structural type checks here; Spark 4.x adds `BinaryComparison.sameType` using `equalsStructurally(..., ignoreNullability = true)`. -- 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]
