Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Jan 30, 2024
1 parent 5227091 commit c126258
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions datafusion/sqllogictest/test_files/sort_merge_join.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# related to: https://github.com/apache/arrow-datafusion/issues/8374
statement ok
CREATE TABLE t1(a text, b int) AS VALUES ('Alice', 50), ('Alice', 100);

statement ok
CREATE TABLE t2(a text, b int) AS VALUES ('Alice', 2), ('Alice', 1);

# Reset the configs to old values
statement ok
set datafusion.execution.target_partitions = 4;

statement ok
set datafusion.optimizer.repartition_joins = true;

# equijoin_and_other_condition (sort merge join)
statement ok
set datafusion.optimizer.prefer_hash_join = false;

query TT
EXPLAIN SELECT t1.a, t1.b, t2.a, t2.b FROM t1 JOIN t2 ON t1.a = t2.a AND t2.b + 1 > t1.b
----
logical_plan
Inner Join: t1.a = t2.a Filter: CAST(t2.b AS Int64) + Int64(1) > CAST(t1.b AS Int64)
--TableScan: t1 projection=[a, b]
--TableScan: t2 projection=[a, b]
physical_plan
SortMergeJoin: join_type=Inner, on=[(a@0, a@0)], filter=CAST(b@1 AS Int64) + 1 > CAST(b@0 AS Int64)
--SortExec: expr=[a@0 ASC]
----CoalesceBatchesExec: target_batch_size=8192
------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=1
--------MemoryExec: partitions=1, partition_sizes=[1]
--SortExec: expr=[a@0 ASC]
----CoalesceBatchesExec: target_batch_size=8192
------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=1
--------MemoryExec: partitions=1, partition_sizes=[1]

query TITI
SELECT t1.a, t1.b, t2.a, t2.b FROM t1 JOIN t2 ON t1.a = t2.a AND t2.b > t1.b
----

statement ok
set datafusion.optimizer.prefer_hash_join = true;

statement ok
DROP TABLE t1;

statement ok
DROP TABLE t2;

0 comments on commit c126258

Please sign in to comment.