Skip to content

Commit f5b6341

Browse files
committed
test: improve UDT literal test by making opaque-ness explicit
1 parent f0e13ef commit f5b6341

File tree

1 file changed

+10
-77
lines changed

1 file changed

+10
-77
lines changed

core/src/test/java/io/substrait/type/proto/LiteralRoundtripTest.java

Lines changed: 10 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,8 @@ void decimal() {
7575
/** Verifies round-trip conversion of a simple user-defined type using Any representation. */
7676
@Test
7777
void userDefinedLiteralWithAnyRepresentation() {
78-
// Create a struct literal inline representing a point with latitude=42, longitude=100
79-
io.substrait.proto.Expression.Literal.Struct pointStruct =
80-
io.substrait.proto.Expression.Literal.Struct.newBuilder()
81-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(42))
82-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(100))
83-
.build();
84-
io.substrait.proto.Expression.Literal innerLiteral =
85-
io.substrait.proto.Expression.Literal.newBuilder().setStruct(pointStruct).build();
86-
Any anyValue = Any.pack(innerLiteral);
78+
Any anyValue =
79+
Any.pack(com.google.protobuf.StringValue.of("<Some User-Defined Representation>"));
8780

8881
Expression.UserDefinedLiteral val =
8982
ExpressionCreator.userDefinedLiteralAny(
@@ -166,51 +159,8 @@ void nestedUserDefinedLiteralWithStructRepresentation() {
166159
*/
167160
@Test
168161
void nestedUserDefinedLiteralWithAnyRepresentation() {
169-
170-
// Create three point UDTs using Any representation
171-
io.substrait.proto.Expression.Literal.Struct p1Struct =
172-
io.substrait.proto.Expression.Literal.Struct.newBuilder()
173-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(0))
174-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(0))
175-
.build();
176-
Any p1Any =
177-
Any.pack(io.substrait.proto.Expression.Literal.newBuilder().setStruct(p1Struct).build());
178-
Expression.UserDefinedAny p1 =
179-
ExpressionCreator.userDefinedLiteralAny(
180-
false, NESTED_TYPES_URN, "point", Collections.emptyList(), p1Any);
181-
182-
io.substrait.proto.Expression.Literal.Struct p2Struct =
183-
io.substrait.proto.Expression.Literal.Struct.newBuilder()
184-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(10))
185-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(0))
186-
.build();
187-
Any p2Any =
188-
Any.pack(io.substrait.proto.Expression.Literal.newBuilder().setStruct(p2Struct).build());
189-
Expression.UserDefinedAny p2 =
190-
ExpressionCreator.userDefinedLiteralAny(
191-
false, NESTED_TYPES_URN, "point", Collections.emptyList(), p2Any);
192-
193-
io.substrait.proto.Expression.Literal.Struct p3Struct =
194-
io.substrait.proto.Expression.Literal.Struct.newBuilder()
195-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(5))
196-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(10))
197-
.build();
198-
Any p3Any =
199-
Any.pack(io.substrait.proto.Expression.Literal.newBuilder().setStruct(p3Struct).build());
200-
Expression.UserDefinedAny p3 =
201-
ExpressionCreator.userDefinedLiteralAny(
202-
false, NESTED_TYPES_URN, "point", Collections.emptyList(), p3Any);
203-
204-
// Create a "triangle" struct containing three point UDTs
205-
io.substrait.proto.Expression.Literal.Struct triangleStruct =
206-
io.substrait.proto.Expression.Literal.Struct.newBuilder()
207-
.addFields(NESTED_TYPES_EXPRESSION_TO_PROTO.toProto(p1).getLiteral())
208-
.addFields(NESTED_TYPES_EXPRESSION_TO_PROTO.toProto(p2).getLiteral())
209-
.addFields(NESTED_TYPES_EXPRESSION_TO_PROTO.toProto(p3).getLiteral())
210-
.build();
211162
Any triangleAny =
212-
Any.pack(
213-
io.substrait.proto.Expression.Literal.newBuilder().setStruct(triangleStruct).build());
163+
Any.pack(com.google.protobuf.StringValue.of("<Some User-Defined Representation>"));
214164

215165
Expression.UserDefinedAny triangle =
216166
ExpressionCreator.userDefinedLiteralAny(
@@ -228,38 +178,21 @@ void nestedUserDefinedLiteralWithAnyRepresentation() {
228178
*/
229179
@Test
230180
void mixedRepresentationNestedUserDefinedLiteral() {
231-
io.substrait.proto.Expression.Literal.Struct p1Struct =
232-
io.substrait.proto.Expression.Literal.Struct.newBuilder()
233-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(0))
234-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(0))
235-
.build();
236-
Any p1Any =
237-
Any.pack(io.substrait.proto.Expression.Literal.newBuilder().setStruct(p1Struct).build());
181+
Any anyValue =
182+
Any.pack(com.google.protobuf.StringValue.of("<Some User-Defined Representation>"));
183+
184+
// Create point UDTs using Any representation
238185
Expression.UserDefinedAny p1 =
239186
ExpressionCreator.userDefinedLiteralAny(
240-
false, NESTED_TYPES_URN, "point", Collections.emptyList(), p1Any);
187+
false, NESTED_TYPES_URN, "point", Collections.emptyList(), anyValue);
241188

242-
io.substrait.proto.Expression.Literal.Struct p2Struct =
243-
io.substrait.proto.Expression.Literal.Struct.newBuilder()
244-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(10))
245-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(0))
246-
.build();
247-
Any p2Any =
248-
Any.pack(io.substrait.proto.Expression.Literal.newBuilder().setStruct(p2Struct).build());
249189
Expression.UserDefinedAny p2 =
250190
ExpressionCreator.userDefinedLiteralAny(
251-
false, NESTED_TYPES_URN, "point", Collections.emptyList(), p2Any);
191+
false, NESTED_TYPES_URN, "point", Collections.emptyList(), anyValue);
252192

253-
io.substrait.proto.Expression.Literal.Struct p3Struct =
254-
io.substrait.proto.Expression.Literal.Struct.newBuilder()
255-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(5))
256-
.addFields(io.substrait.proto.Expression.Literal.newBuilder().setI32(10))
257-
.build();
258-
Any p3Any =
259-
Any.pack(io.substrait.proto.Expression.Literal.newBuilder().setStruct(p3Struct).build());
260193
Expression.UserDefinedAny p3 =
261194
ExpressionCreator.userDefinedLiteralAny(
262-
false, NESTED_TYPES_URN, "point", Collections.emptyList(), p3Any);
195+
false, NESTED_TYPES_URN, "point", Collections.emptyList(), anyValue);
263196

264197
// Create a "triangle" UDT using Struct representation, but with Any-encoded point fields
265198
Expression.UserDefinedStruct triangle =

0 commit comments

Comments
 (0)