rich7420 commented on code in PR #6428:
URL: https://github.com/apache/datafusion-comet/pull/6428#discussion_r4709143417
##########
spark/src/main/scala/org/apache/comet/serde/structs.scala:
##########
@@ -56,6 +56,8 @@ object CometCreateNamedStruct extends
CometExpressionSerde[CreateNamedStruct] {
val structBuilder = ExprOuterClass.CreateNamedStruct.newBuilder()
structBuilder.addAllValues(valExprs.map(_.get).asJava)
structBuilder.addAllNames(expr.names.map(_.toString).asJava)
+ // Native expressions can conservatively report nullable even when
Catalyst proves otherwise.
+ structBuilder.addAllFieldNullable(expr.valExprs.map(v =>
Boolean.box(v.nullable)).asJava)
Review Comment:
I ran this. The example above passes on the merge base and fails at head
with `Union is not implemented`. A plainer one fails the same way:
```sql
SELECT array_union(
array(named_struct('x', CAST(coalesce(i, 0) AS BIGINT))),
array_repeat(named_struct('x', CAST(coalesce(i, 0) AS BIGINT)), 1))
FROM t -- t(i INT) USING parquet
```
##########
spark/src/test/resources/sql-tests/expressions/struct/create_named_struct_nullability.sql:
##########
@@ -0,0 +1,51 @@
+-- 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.exec.range.enabled=true
+-- Config: spark.sql.caseSensitive=false
+
+-- Catalyst proves both fields nonnullable, but native cast inference is
conservative.
+-- array_repeat preserves the struct type, so array_union needs the same field
flags on both
+-- sides. Unlike array(...), this path does not cast elements to a
deeply-nullable type.
+query expect_native(array_union)
+SELECT array_union(
+ array_repeat(named_struct('x', CAST(id AS INT)), 2),
+ array_repeat(named_struct('x', IF(id = 0, 0, 1)), 2))
+FROM range(3)
+
+-- Preserve the field flags recursively through another struct constructor.
+query expect_native(array_union)
+SELECT array_union(
+ array_repeat(named_struct('inner', named_struct('x', CAST(id AS INT))), 2),
+ array_repeat(named_struct('inner', named_struct('x', IF(id = 0, 0, 1))), 2))
+FROM range(3)
+
+-- Map construction preserves Catalyst's nested nullability. CASE must union
those flags by
+-- position, even when case-insensitive field names swap places, so neither
NULL field is lost.
+query
Review Comment:
Could both `CASE` queries use `expect_native(casewhen)`? Since `map` and
`named_struct` use codegen dispatch here, plain `query` doesn't check whether
`CASE` ran in Rust.
--
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]