shardulm94 commented on a change in pull request #1208:
URL: https://github.com/apache/iceberg/pull/1208#discussion_r467673301
##########
File path:
orc/src/test/java/org/apache/iceberg/orc/TestExpressionToSearchArgument.java
##########
@@ -262,4 +264,132 @@ public void testEvolvedSchema() {
actual = ExpressionToSearchArgument.convert(boundFilter, readSchema);
Assert.assertEquals(expected.toString(), actual.toString());
}
+
+ @Test
+ public void testOriginalSchemaNameMapping() {
+ Schema originalSchema = new Schema(
+ required(1, "int", Types.IntegerType.get()),
+ optional(2, "long", Types.LongType.get())
+ );
+
+ TypeDescription orcSchemaWithoutIds =
ORCSchemaUtil.removeIds(ORCSchemaUtil.convert(originalSchema));
+ NameMapping nameMapping = MappingUtil.create(originalSchema);
+
+ TypeDescription readSchema =
ORCSchemaUtil.buildOrcProjection(originalSchema,
+ ORCSchemaUtil.applyNameMapping(orcSchemaWithoutIds, nameMapping));
+
+ Expression expr = and(equal("int", 1), equal("long", 1));
+ Expression boundFilter = Binder.bind(originalSchema.asStruct(), expr,
true);
+ SearchArgument expected = SearchArgumentFactory.newBuilder()
+ .equals("`int`", Type.LONG, 1L)
+ .equals("`long`", Type.LONG, 1L)
+ .build();
+
+ SearchArgument actual = ExpressionToSearchArgument.convert(boundFilter,
readSchema);
+ Assert.assertEquals(expected.toString(), actual.toString());
+ }
+
+ @Test
+ public void testModifiedSimpleSchemaNameMapping() {
+ Schema originalSchema = new Schema(
+ required(1, "int", Types.IntegerType.get()),
+ optional(2, "long_to_be_dropped", Types.LongType.get())
+ );
+ Schema mappingSchema = new Schema(
+ required(1, "int", Types.IntegerType.get()),
+ optional(3, "new_float_field", Types.FloatType.get())
+ );
+ TypeDescription orcSchemaWithoutIds =
ORCSchemaUtil.removeIds(ORCSchemaUtil.convert(originalSchema));
+ NameMapping nameMapping = MappingUtil.create(mappingSchema);
+
+ TypeDescription readSchema =
ORCSchemaUtil.buildOrcProjection(mappingSchema,
+ ORCSchemaUtil.applyNameMapping(orcSchemaWithoutIds, nameMapping));
+
+ Expression expr = equal("int", 1);
+ Expression boundFilter = Binder.bind(mappingSchema.asStruct(), expr, true);
+ SearchArgument expected = SearchArgumentFactory.newBuilder()
+ .equals("`int`", Type.LONG, 1L)
+ .build();
+
+ SearchArgument actual = ExpressionToSearchArgument.convert(boundFilter,
readSchema);
+ Assert.assertEquals(expected.toString(), actual.toString());
+
+ // for columns not in the file, buildOrcProjection will append field names
with _r<ID>
+ // this will be passed down to ORC, but ORC will handle such cases and
return a TruthValue during evaluation
+ expr = equal("new_float_field", 1);
+ boundFilter = Binder.bind(mappingSchema.asStruct(), expr, true);
+ expected = SearchArgumentFactory.newBuilder()
+ .equals("`new_float_field_r3`", Type.FLOAT, 1.0)
+ .build();
+
+ actual = ExpressionToSearchArgument.convert(boundFilter, readSchema);
+ Assert.assertEquals(expected.toString(), actual.toString());
+ }
+
+ @Test
+ public void testModifiedComplexSchemaNameMapping() {
+ Schema originalSchema = new Schema(
+ optional(1, "struct", Types.StructType.of(
+ required(2, "long", Types.LongType.get())
+ )),
+ optional(3, "list", Types.ListType.ofRequired(4,
Types.LongType.get())),
+ optional(5, "map", Types.MapType.ofRequired(6, 7,
Types.LongType.get(), Types.LongType.get())),
+ optional(8, "listOfStruct", Types.ListType.ofRequired(9,
Types.StructType.of(
+ required(10, "long", Types.LongType.get())))),
+ optional(11, "listOfPeople", Types.ListType.ofRequired(12,
Types.StructType.of(
+ required(13, "name", Types.StringType.get()),
+ required(14, "birth_date", Types.DateType.get()))))
+ );
+ Schema mappingSchema = new Schema(
+ optional(1, "struct", Types.StructType.of(
+ required(2, "int", Types.LongType.get())
+ )),
+ optional(3, "list", Types.ListType.ofRequired(4,
Types.LongType.get())),
+ optional(5, "newMap", Types.MapType.ofRequired(6, 7,
Types.StringType.get(), Types.LongType.get())),
+ optional(8, "listOfStruct", Types.ListType.ofRequired(9,
Types.StructType.of(
+ required(10, "newLong", Types.LongType.get())))),
+ optional(11, "listOfPeople", Types.ListType.ofRequired(12,
Types.StructType.of(
+ required(13, "name", Types.StringType.get()),
+ required(14, "age", Types.IntegerType.get()))))
+ );
+ TypeDescription orcSchemaWithoutIds =
ORCSchemaUtil.removeIds(ORCSchemaUtil.convert(originalSchema));
+ NameMapping nameMapping = MappingUtil.create(mappingSchema);
+
+ TypeDescription readSchema =
ORCSchemaUtil.buildOrcProjection(mappingSchema,
+ ORCSchemaUtil.applyNameMapping(orcSchemaWithoutIds, nameMapping));
+
+ Expression expr = and(
+ and(
+ equal("struct.int", 1), and(
+ lessThanOrEqual("list.element", 5),
+ equal("newMap.key", "country")
+ ),
+ and(
+ equal("listOfStruct.newLong", 100L),
+ notEqual("listOfPeople.name", "Bob")
+ )
+
+ ),
+ lessThan("listOfPeople.age", 30)
+ );
+ Expression boundFilter = Binder.bind(mappingSchema.asStruct(), expr, true);
+ SearchArgument expected = SearchArgumentFactory.newBuilder()
+ .startAnd()
+ // Drops strict.long
Review comment:
Nit: Typo `struct.long`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]