-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# 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. | ||
|
||
########## | ||
## Sort Merge Join Tests | ||
########## | ||
|
||
statement ok | ||
set datafusion.optimizer.prefer_hash_join = false; | ||
|
||
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); | ||
|
||
# equijoin and join filter (sort merge join) | ||
|
||
query TT | ||
EXPLAIN SELECT t1.a, t1.b, t2.a, t2.b FROM t1 JOIN t2 ON t1.a = t2.a AND t2.b * 50 <= t1.b | ||
---- | ||
logical_plan | ||
Inner Join: t1.a = t2.a Filter: CAST(t2.b AS Int64) * Int64(50) <= 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) * 50 <= 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 rowsort | ||
SELECT t1.a, t1.b, t2.a, t2.b FROM t1 JOIN t2 ON t1.a = t2.a AND t2.b * 50 <= t1.b | ||
---- | ||
Alice 100 Alice 1 | ||
Alice 100 Alice 2 | ||
Alice 50 Alice 1 | ||
|
||
query TITI rowsort | ||
SELECT t1.a, t1.b, t2.a, t2.b FROM t1 JOIN t2 ON t1.a = t2.a AND t2.b < t1.b | ||
---- | ||
Alice 100 Alice 1 | ||
Alice 100 Alice 2 | ||
Alice 50 Alice 1 | ||
Alice 50 Alice 2 | ||
|
||
query TITI rowsort | ||
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; |