Skip to content

Commit

Permalink
Merge branch 'main' into feature/from_to_protobuf_pojo
Browse files Browse the repository at this point in the history
  • Loading branch information
davisusanibar committed Nov 24, 2023
2 parents 75e4f48 + 133ab83 commit 1d23187
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release Notes
---

## [0.21.0](https://github.com/substrait-io/substrait-java/compare/v0.20.0...v0.21.0) (2023-11-19)


### Features

* add MergeJoinRel ([#201](https://github.com/substrait-io/substrait-java/issues/201)) ([237179f](https://github.com/substrait-io/substrait-java/commit/237179f9f170c30f34ed09a1810db19e3725a5bc))

## [0.20.0](https://github.com/substrait-io/substrait-java/compare/v0.19.0...v0.20.0) (2023-11-07)


Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/io/substrait/dsl/SubstraitBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ public Expression singleOrList(Expression condition, Expression... options) {
return SingleOrList.builder().condition(condition).addOptions(options).build();
}

public Expression.InPredicate inPredicate(Rel haystack, Expression... needles) {
return Expression.InPredicate.builder()
.addAllNeedles(Arrays.asList(needles))
.haystack(haystack)
.build();
}

public List<Expression.SortField> sortFields(Rel input, int... indexes) {
return Arrays.stream(indexes)
.mapToObj(
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ slf4j.version=1.7.25
jackson.version=2.12.4

#version that is going to be updated automatically by releases
version = 0.20.0
version = 0.21.0

#signing
SIGNING_KEY_ID = 193EAE47
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public SubstraitRelNodeConverter(
this.scalarFunctionConverter = scalarFunctionConverter;
this.aggregateFunctionConverter = aggregateFunctionConverter;
this.expressionRexConverter = expressionRexConverter;
this.expressionRexConverter.setRelNodeConverter(this);
}

public static RelNode convert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.substrait.expression.FunctionArg;
import io.substrait.expression.WindowBound;
import io.substrait.extension.SimpleExtension;
import io.substrait.isthmus.SubstraitRelNodeConverter;
import io.substrait.isthmus.TypeConverter;
import io.substrait.type.StringTypeVisitor;
import io.substrait.type.Type;
Expand All @@ -22,12 +23,14 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.apache.calcite.avatica.util.ByteString;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.rex.RexFieldCollation;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexSubQuery;
import org.apache.calcite.rex.RexWindowBound;
import org.apache.calcite.rex.RexWindowBounds;
import org.apache.calcite.sql.SqlAggFunction;
Expand All @@ -50,6 +53,7 @@ public class ExpressionRexConverter extends AbstractExpressionVisitor<RexNode, R
protected final RexBuilder rexBuilder;
protected final ScalarFunctionConverter scalarFunctionConverter;
protected final WindowFunctionConverter windowFunctionConverter;
protected SubstraitRelNodeConverter relNodeConverter;

private static final SqlIntervalQualifier YEAR_MONTH_INTERVAL =
new SqlIntervalQualifier(
Expand Down Expand Up @@ -79,6 +83,10 @@ public ExpressionRexConverter(
this.windowFunctionConverter = windowFunctionConverter;
}

public void setRelNodeConverter(final SubstraitRelNodeConverter substraitRelNodeConverter) {
this.relNodeConverter = substraitRelNodeConverter;
}

@Override
public RexNode visit(Expression.NullLiteral expr) throws RuntimeException {
return rexBuilder.makeLiteral(null, typeConverter.toCalcite(typeFactory, expr.getType()));
Expand Down Expand Up @@ -385,6 +393,14 @@ public RexNode visit(Expression.WindowFunctionInvocation expr) throws RuntimeExc
ignoreNulls);
}

@Override
public RexNode visit(Expression.InPredicate expr) throws RuntimeException {
List<RexNode> needles =
expr.needles().stream().map(e -> e.accept(this)).collect(Collectors.toList());
RelNode rel = expr.haystack().accept(relNodeConverter);
return RexSubQuery.in(rel, ImmutableList.copyOf(needles));
}

static class ToRexWindowBound
implements WindowBound.WindowBoundVisitor<RexWindowBound, RuntimeException> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public void mapLiteral() throws IOException, SqlParseException {
assertFullRoundTrip("select MAP[1, 'hello'] from ORDERS");
}

@Test
public void inPredicate() throws IOException, SqlParseException {
assertFullRoundTrip(
"select L_PARTKEY from LINEITEM where L_PARTKEY in "
+ "(SELECT L_SUPPKEY from LINEITEM where L_SUPPKEY < L_ORDERKEY)");
}

@Test
public void singleOrList() {
Expression singleOrList = b.singleOrList(b.fieldReference(commonTable, 0), b.i32(5), b.i32(10));
Expand Down

0 comments on commit 1d23187

Please sign in to comment.