Skip to content

Commit 133b704

Browse files
committed
tweak: get isthmus compiling, throw exception on struct UDTs
1 parent 03e38da commit 133b704

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

isthmus/src/main/java/io/substrait/isthmus/expression/CallConverters.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,20 @@ public class CallConverters {
7070
Expression.FixedBinaryLiteral literal = (Expression.FixedBinaryLiteral) operand;
7171
Type.UserDefined t = (Type.UserDefined) type;
7272

73-
return Expression.UserDefinedLiteral.builder()
74-
.urn(t.urn())
75-
.name(t.name())
76-
.value(literal.value())
77-
.build();
73+
// The binary literal contains the serialized protobuf Any - just parse it directly
74+
try {
75+
com.google.protobuf.Any anyValue =
76+
com.google.protobuf.Any.parseFrom(literal.value().toByteArray());
77+
78+
return Expression.UserDefinedAny.builder()
79+
.urn(t.urn())
80+
.name(t.name())
81+
.addAllTypeParameters(t.typeParameters())
82+
.value(anyValue)
83+
.build();
84+
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
85+
throw new IllegalStateException("Failed to parse UserDefinedAny value", e);
86+
}
7887
}
7988
return null;
8089
};

isthmus/src/main/java/io/substrait/isthmus/expression/ExpressionRexConverter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,19 @@ public RexNode visit(Expression.NullLiteral expr, Context context) throws Runtim
109109
}
110110

111111
@Override
112-
public RexNode visit(Expression.UserDefinedLiteral expr, Context context)
113-
throws RuntimeException {
112+
public RexNode visit(Expression.UserDefinedAny expr, Context context) throws RuntimeException {
114113
RexLiteral binaryLiteral =
115-
rexBuilder.makeBinaryLiteral(new ByteString(expr.value().toByteArray()));
114+
rexBuilder.makeBinaryLiteral(new ByteString(expr.value().toByteString().toByteArray()));
116115
RelDataType type = typeConverter.toCalcite(typeFactory, expr.getType());
117116
return rexBuilder.makeReinterpretCast(type, binaryLiteral, rexBuilder.makeLiteral(false));
118117
}
119118

119+
@Override
120+
public RexNode visit(Expression.UserDefinedStruct expr, Context context) throws RuntimeException {
121+
throw new UnsupportedOperationException(
122+
"UserDefinedStruct representation is not yet supported in Isthmus");
123+
}
124+
120125
@Override
121126
public RexNode visit(Expression.BoolLiteral expr, Context context) throws RuntimeException {
122127
return rexBuilder.makeLiteral(expr.value());

isthmus/src/test/java/io/substrait/isthmus/CustomFunctionTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,9 @@ void customTypesInFunctionsRoundtrip() {
587587
void customTypesLiteralInFunctionsRoundtrip() {
588588
Builder bldr = Expression.Literal.newBuilder();
589589
Any anyValue = Any.pack(bldr.setI32(10).build());
590-
UserDefinedLiteral val = ExpressionCreator.userDefinedLiteral(false, URN, "a_type", anyValue);
590+
UserDefinedLiteral val =
591+
ExpressionCreator.userDefinedLiteralAny(
592+
false, URN, "a_type", java.util.Collections.emptyList(), anyValue);
591593

592594
Rel rel1 =
593595
b.project(

0 commit comments

Comments
 (0)