Skip to content

Commit

Permalink
fix: incorrect set preserve_partitioning in SortExec (apache#8485)
Browse files Browse the repository at this point in the history
* fix: incorrect set preserve_partitioning in SortExec

* add more comment
  • Loading branch information
haohuaijin authored Dec 12, 2023
1 parent 2102275 commit 7f312c8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ fn try_swapping_with_sort(

Ok(Some(Arc::new(
SortExec::new(updated_exprs, make_with_child(projection, sort.input())?)
.with_fetch(sort.fetch()),
.with_fetch(sort.fetch())
.with_preserve_partitioning(sort.preserve_partitioning()),
)))
}

Expand Down
37 changes: 37 additions & 0 deletions datafusion/sqllogictest/test_files/join.slt
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,40 @@ drop table IF EXISTS full_join_test;
# batch size
statement ok
set datafusion.execution.batch_size = 8192;

# 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);

# the current query results are incorrect, becuase the query was incorrectly rewritten as:
# SELECT t1.a, t1.b FROM t1 JOIN t2 ON t1.a = t2.a ORDER BY t1.a, t1.b;
# the difference is ORDER BY clause rewrite from t2.b to t1.b, it is incorrect.
# after https://github.com/apache/arrow-datafusion/issues/8374 fixed, the correct result should be:
# Alice 50
# Alice 100
# Alice 50
# Alice 100
query TI
SELECT t1.a, t1.b FROM t1 JOIN t2 ON t1.a = t2.a ORDER BY t1.a, t2.b;
----
Alice 50
Alice 50
Alice 100
Alice 100

query TITI
SELECT t1.a, t1.b, t2.a, t2.b FROM t1 JOIN t2 ON t1.a = t2.a ORDER BY t1.a, t2.b;
----
Alice 50 Alice 1
Alice 100 Alice 1
Alice 50 Alice 2
Alice 100 Alice 2

statement ok
DROP TABLE t1;

statement ok
DROP TABLE t2;

0 comments on commit 7f312c8

Please sign in to comment.