sunchao commented on code in PR #7836: URL: https://github.com/apache/datafusion-comet/pull/7836#discussion_r4778520957
########## spark/src/test/resources/sql-tests/expressions/map/map_null_short_circuit_no_codegen.sql: ########## @@ -0,0 +1,49 @@ +-- 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. + +-- With spark.sql.codegen.factoryMode=NO_CODEGEN, Spark runs interpreted projections and +-- aggregates, which evaluate a subexpression they eliminate only when an expression asks for it. +-- A lookup on a NULL map never asks for its key, so the ANSI cast that both lookups share does not +-- raise there, unlike with generated code (see map_null_short_circuit_cse_off.sql). +-- https://github.com/apache/datafusion-comet/issues/7814 + +-- Config: spark.sql.ansi.enabled=true +-- Config: spark.sql.subexpressionElimination.enabled=true +-- Config: spark.sql.codegen.wholeStage=false +-- Config: spark.sql.codegen.factoryMode=NO_CODEGEN + +statement +CREATE TABLE map_null_short_circuit_no_codegen(m map<int, int>, m2 map<int, int>, s string) +USING parquet + +-- `s` is malformed only where the maps are NULL +statement +INSERT INTO map_null_short_circuit_no_codegen SELECT /*+ COALESCE(1) */ * FROM VALUES + (NULL, NULL, 'bad'), + (map(1, 10, 2, 20), map(2, 5), '2'), + (map(3, 30), map(4, 6), '4') + AS v(m, m2, s) + +query expect_native(getmapvalue) +SELECT m[CAST(s AS INT)], m2[CAST(s AS INT)] FROM map_null_short_circuit_no_codegen + +query expect_native(getmapvalue) +SELECT max(m[CAST(s AS INT)]), max(m2[CAST(s AS INT)]) FROM map_null_short_circuit_no_codegen + +-- Where the map is not NULL, the key is evaluated and raises as in Spark +query expect_error(CAST_INVALID_INPUT) Review Comment: Could we use `expect_error_class(CAST_INVALID_INPUT)` and add `WHERE m IS NOT NULL` to this last query? `s || 'x'` is malformed even on the NULL-map row, so an eager cast on that row would satisfy the current assertion. `expect_error` also accepts Spark fallback for this changed projection. The stronger version checks the error on a row that needs the key and verifies the Comet operators. I ran it successfully on Spark 4.1.3. -- 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]
