Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.calcite.rel.logical.LogicalProject;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexOver;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.tools.RelBuilderFactory;

import org.immutables.value.Value;
Expand Down Expand Up @@ -67,8 +68,8 @@ public ProjectSetOpTransposeRule(
final Project origProject = call.rel(0);
final SetOp setOp = call.rel(1);

// cannot push project past a distinct
if (!setOp.all) {
// only UNION ALL; other set ops compare rows on all fields

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the rule misnamed?

if (setOp.kind != SqlKind.UNION || !setOp.all) {
return;
}

Expand Down
30 changes: 30 additions & 0 deletions core/src/test/resources/sql/planner.iq
Original file line number Diff line number Diff line change
Expand Up @@ -728,4 +728,34 @@ EnumerableCalc(expr#0=[{inputs}], expr#1=[null:INTEGER], ID=[$t1], ID0=[$t0])
!plan
!set planner-rules original

# [CALCITE-7909] ProjectSetOpTransposeRule returns wrong results for EXCEPT ALL and INTERSECT ALL.
!set planner-rules "
+CoreRules.PROJECT_SET_OP_TRANSPOSE"

select y from (
select x + 1 as x, y from (values (1, 10)) as a(x, y)
except all
select x + 1 as x, y from (values (2, 10)) as b(x, y));
+----+
| Y |
+----+
| 10 |
+----+
(1 row)

!ok

select y from (
select x + 1 as x, y from (values (1, 10)) as a(x, y)
intersect all
select x + 1 as x, y from (values (2, 10)) as b(x, y));
+---+
| Y |
+---+
+---+
(0 rows)

!ok
!set planner-rules original

# End planner.iq
Loading