Skip to content

Commit

Permalink
test: verify conversion of user-defined type literal between proto an…
Browse files Browse the repository at this point in the history
…d pojo
  • Loading branch information
vbarua committed Feb 17, 2024
1 parent d3a816c commit 0995f0d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions isthmus/src/test/java/io/substrait/isthmus/CustomFunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import com.google.protobuf.Any;
import io.substrait.dsl.SubstraitBuilder;
import io.substrait.expression.ExpressionCreator;
import io.substrait.extension.ExtensionCollector;
import io.substrait.extension.SimpleExtension;
import io.substrait.isthmus.expression.AggregateFunctionConverter;
import io.substrait.isthmus.expression.FunctionMappings;
import io.substrait.isthmus.expression.ScalarFunctionConverter;
import io.substrait.isthmus.expression.WindowFunctionConverter;
import io.substrait.isthmus.utils.UserTypeFactory;
import io.substrait.proto.Expression;
import io.substrait.relation.ProtoRelConverter;
import io.substrait.relation.Rel;
import io.substrait.relation.RelProtoConverter;
import io.substrait.type.Type;
import io.substrait.type.TypeCreator;
import java.io.IOException;
Expand Down Expand Up @@ -238,12 +241,11 @@ void customTypesInFunctionsRoundtrip() {

@Test
void customTypesLiteralInFunctionsRoundtrip() {

var bldr = Expression.Literal.newBuilder();
var anyValue = Any.pack(bldr.setI32(10).build());
var val = ExpressionCreator.userDefinedLiteral(false, NAMESPACE, "a_type", anyValue);

Rel rel =
Rel rel1 =
b.project(
input ->
List.of(
Expand All @@ -253,8 +255,13 @@ void customTypesLiteralInFunctionsRoundtrip() {
b.namedScan(
List.of("example"), List.of("a"), List.of(N.userDefined(NAMESPACE, "a_type"))));

RelNode calciteRel = substraitToCalcite.convert(rel);
var relReturned = calciteToSubstrait.apply(calciteRel);
assertEquals(rel, relReturned);
RelNode calciteRel = substraitToCalcite.convert(rel1);
Rel rel2 = calciteToSubstrait.apply(calciteRel);
assertEquals(rel1, rel2);

var extensionCollector = new ExtensionCollector();
io.substrait.proto.Rel protoRel = new RelProtoConverter(extensionCollector).toProto(rel1);
Rel rel3 = new ProtoRelConverter(extensionCollector, extensionCollection).from(protoRel);
assertEquals(rel1, rel3);
}
}

0 comments on commit 0995f0d

Please sign in to comment.