Aaaaaaron commented on a change in pull request #2125:
URL: https://github.com/apache/calcite/pull/2125#discussion_r481684776
##########
File path: core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
##########
@@ -885,14 +886,22 @@ public TrimResult trimFields(
/**
* Variant of {@link #trimFields(RelNode, ImmutableBitSet, Set)} for
- * {@link org.apache.calcite.rel.core.SetOp} (including UNION and UNION ALL).
+ * {@link org.apache.calcite.rel.core.SetOp} (Only UNION ALL is supported).
*/
public TrimResult trimFields(
SetOp setOp,
ImmutableBitSet fieldsUsed,
Set<RelDataTypeField> extraFields) {
final RelDataType rowType = setOp.getRowType();
final int fieldCount = rowType.getFieldCount();
+
+ // Trim fields only for UNION ALL.
+ // Operator UNION/INTERSECT/INTERSECT ALL/EXCEPT/EXCEPT ALL
+ // will check duplication. We can not trim fields on them.
+ if (!(setOp.kind == SqlKind.UNION && setOp.all)) {
+ return result(setOp, Mappings.createIdentity(fieldCount));
Review comment:
> Does `INTERSECT ALL` and `EXCEPT ALL` check the duplicates ?
INTERSECT returns the same element in two sets.
```
emp0:
name, deptno
"A", 0
"B", 1
emp1:
name, deptno
"A", 0
"A", 1
select name from
(select name, deptno from emp0
intersect all
select name, deptno from emp1)
```
intersect all (name, deptno) returns (("A", 0), ("A", 0))
intersect all (name) returns (("A"),("A"),("A"))
They are different, all subtraction operation will be affected, tell me if
I'm wrong.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]