coderfender commented on code in PR #4587: URL: https://github.com/apache/datafusion-comet/pull/4587#discussion_r4156453301
########## spark/src/test/resources/sql-tests/join/existence_join.sql: ########## @@ -0,0 +1,234 @@ +-- 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. + +-- Tests for ExistenceJoin: produced when EXISTS / NOT EXISTS is combined +-- with another predicate via OR, preventing rewrite to LeftSemi / LeftAnti. +-- +-- Strategy hints are placed INSIDE the EXISTS subquery (on the subquery's own +-- relation alias), because an outer hint referencing the subquery table cannot +-- resolve it and silently falls back to a broadcast hash join. Subquery-local +-- hints (verified on Spark 4.1.3 with AQE off) select ShuffledHashJoin / +-- SortMergeJoin. +-- +-- Native existence support is currently hash-only: BROADCAST and SHUFFLE_HASH +-- cases exercise CometBroadcastHashJoinExec / CometHashJoinExec, while MERGE +-- cases fall back to Spark's SortMergeJoin (existence SMJ is not yet native) and +-- verify result parity under the Comet-enabled config. + +-- Native ExistenceJoin support is experimental and disabled by default. +-- Config: spark.comet.exec.existenceJoin.enabled=true + +-- ============================================================ +-- Setup: NULLs (both sides), duplicates, empty build, all-NULL build +-- ============================================================ + +statement +CREATE TABLE ex_left(id int, k int, region string) USING parquet + +statement +INSERT INTO ex_left VALUES + (1, 1, 'US'), + (2, 2, 'EU'), + (3, NULL, 'US'), + (4, 4, 'EU'), + (5, 5, 'EU'), + (6, NULL, 'EU') + +statement +CREATE TABLE ex_right(id int, k int) USING parquet + +statement +INSERT INTO ex_right VALUES (10, 1), (11, 2), (12, 2), (13, NULL) + +statement +CREATE TABLE ex_right_no_nulls(id int, k int) USING parquet + +statement +INSERT INTO ex_right_no_nulls VALUES (10, 1), (11, 5) + +statement +CREATE TABLE ex_right_empty(id int, k int) USING parquet + +statement +CREATE TABLE ex_right_dups(id int, k int) USING parquet + +statement +INSERT INTO ex_right_dups VALUES (10, 1), (11, 1), (12, 1), (13, 2) + +statement +CREATE TABLE ex_right_all_null(id int, k int) USING parquet + +statement +INSERT INTO ex_right_all_null VALUES (10, NULL), (11, NULL) + +statement +CREATE TABLE ex_left_empty(id int, k int, region string) USING parquet + +-- ============================================================ +-- EXISTS with OR across all three strategies (hint in subquery) +-- ============================================================ + +query +SELECT * FROM ex_left l +WHERE l.region = 'US' + OR EXISTS (SELECT /*+ BROADCAST(r) */ 1 FROM ex_right r WHERE r.k = l.k) Review Comment: Added all three: a direct marker projection (`SELECT l.id, EXISTS (…) FROM ex_left l`), the `l.k IN (SELECT …)` form combined with `OR`, and a string join key for both BHJ and SHJ. -- 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]
