Skip to content

Commit eb484a3

Browse files
authored
chore: update to substrait v0.57.0 (#300)
feat(POJO): handle SET_OP_MINUS_PRIMARY_ALL feat(POJO): handle SET_OP_INTERSECTION_MULTISET_ALL feat(Isthmus): add mappings for new SetOps BREAKING CHANGE: EXCEPT ALL and INTERSECT ALL now output different SetOps
1 parent 91ce863 commit eb484a3

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

core/src/main/java/io/substrait/relation/Set.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ public abstract class Set extends AbstractRel implements HasExtension {
1111
public static enum SetOp {
1212
UNKNOWN(SetRel.SetOp.SET_OP_UNSPECIFIED),
1313
MINUS_PRIMARY(SetRel.SetOp.SET_OP_MINUS_PRIMARY),
14+
MINUS_PRIMARY_ALL(SetRel.SetOp.SET_OP_MINUS_PRIMARY_ALL),
1415
MINUS_MULTISET(SetRel.SetOp.SET_OP_MINUS_MULTISET),
1516
INTERSECTION_PRIMARY(SetRel.SetOp.SET_OP_INTERSECTION_PRIMARY),
1617
INTERSECTION_MULTISET(SetRel.SetOp.SET_OP_INTERSECTION_MULTISET),
18+
INTERSECTION_MULTISET_ALL(SetRel.SetOp.SET_OP_INTERSECTION_MULTISET_ALL),
1719
UNION_DISTINCT(SetRel.SetOp.SET_OP_UNION_DISTINCT),
1820
UNION_ALL(SetRel.SetOp.SET_OP_UNION_ALL);
1921

isthmus/src/main/java/io/substrait/isthmus/SubstraitRelNodeConverter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,17 @@ public RelNode visit(Set set) throws RuntimeException {
211211
input -> {
212212
relBuilder.push(input.accept(this));
213213
});
214+
// TODO: MINUS_MULTISET and INTERSECTION_PRIMARY mappings are set to be removed as they do not
215+
// correspond to the Calcite relations they are associated with. They are retained for now
216+
// to enable users to migrate off of them.
217+
// See: https://github.com/substrait-io/substrait-java/issues/303
214218
var builder =
215219
switch (set.getSetOp()) {
216220
case MINUS_PRIMARY -> relBuilder.minus(false, numInputs);
217-
case MINUS_MULTISET -> relBuilder.minus(true, numInputs);
218-
case INTERSECTION_PRIMARY -> relBuilder.intersect(false, numInputs);
219-
case INTERSECTION_MULTISET -> relBuilder.intersect(true, numInputs);
221+
case MINUS_PRIMARY_ALL, MINUS_MULTISET -> relBuilder.minus(true, numInputs);
222+
case INTERSECTION_PRIMARY, INTERSECTION_MULTISET -> relBuilder.intersect(
223+
false, numInputs);
224+
case INTERSECTION_MULTISET_ALL -> relBuilder.intersect(true, numInputs);
220225
case UNION_DISTINCT -> relBuilder.union(false, numInputs);
221226
case UNION_ALL -> relBuilder.union(true, numInputs);
222227
case UNKNOWN -> throw new UnsupportedOperationException(

isthmus/src/main/java/io/substrait/isthmus/SubstraitRelVisitor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,15 @@ public Rel visit(org.apache.calcite.rel.core.Union union) {
217217
@Override
218218
public Rel visit(org.apache.calcite.rel.core.Intersect intersect) {
219219
var inputs = apply(intersect.getInputs());
220-
var setOp = intersect.all ? Set.SetOp.INTERSECTION_MULTISET : Set.SetOp.INTERSECTION_PRIMARY;
220+
var setOp =
221+
intersect.all ? Set.SetOp.INTERSECTION_MULTISET_ALL : Set.SetOp.INTERSECTION_MULTISET;
221222
return Set.builder().inputs(inputs).setOp(setOp).build();
222223
}
223224

224225
@Override
225226
public Rel visit(org.apache.calcite.rel.core.Minus minus) {
226227
var inputs = apply(minus.getInputs());
227-
var setOp = minus.all ? Set.SetOp.MINUS_MULTISET : Set.SetOp.MINUS_PRIMARY;
228+
var setOp = minus.all ? Set.SetOp.MINUS_PRIMARY_ALL : Set.SetOp.MINUS_PRIMARY;
228229
return Set.builder().inputs(inputs).setOp(setOp).build();
229230
}
230231

isthmus/src/test/java/io/substrait/isthmus/utils/SetUtils.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public static String getSetQuery(Set.SetOp op, boolean multi) {
2121
String opString =
2222
switch (op) {
2323
case MINUS_PRIMARY -> "EXCEPT";
24-
case MINUS_MULTISET -> "EXCEPT ALL";
25-
case INTERSECTION_PRIMARY -> "INTERSECT";
26-
case INTERSECTION_MULTISET -> "INTERSECT ALL";
24+
case MINUS_PRIMARY_ALL -> "EXCEPT ALL";
25+
case INTERSECTION_MULTISET -> "INTERSECT";
26+
case INTERSECTION_MULTISET_ALL -> "INTERSECT ALL";
2727
case UNION_DISTINCT -> "UNION";
2828
case UNION_ALL -> "UNION ALL";
29-
case UNKNOWN -> throw new UnsupportedOperationException(
29+
default -> throw new UnsupportedOperationException(
3030
"Unknown set operation is not supported");
3131
};
3232

@@ -49,10 +49,16 @@ public static String getSetQuery(Set.SetOp op, boolean multi) {
4949
}
5050
}
5151

52-
// Generate all combinations excluding the UNKNOWN operator
52+
// Generate all SetOp types excluding:
53+
// * MINUS_MULTISET, INTERSECTION_PRIMARY: do not map to Calcite relations
54+
// * UNKNOWN: invalid
5355
public static Stream<Arguments> setTestConfig() {
5456
return Arrays.stream(Set.SetOp.values())
55-
.filter(op -> op != Set.SetOp.UNKNOWN)
57+
.filter(
58+
op ->
59+
op != Set.SetOp.UNKNOWN
60+
&& op != Set.SetOp.MINUS_MULTISET
61+
&& op != Set.SetOp.INTERSECTION_PRIMARY)
5662
.flatMap(op -> Stream.of(arguments(op, false), arguments(op, true)));
5763
}
5864
}

0 commit comments

Comments
 (0)