dramaticlly commented on code in PR #18537:
URL: https://github.com/apache/iceberg/pull/18537#discussion_r4297601556
##########
data/src/test/java/org/apache/iceberg/data/ReadFormatModelTests.java:
##########
@@ -2414,7 +2452,21 @@ protected static void assumeSupports(FileFormat
fileFormat, String feature) {
private static boolean supportsGenerator(FileFormat fileFormat,
DataGenerator generator) {
boolean hasVariant =
TypeUtil.find(generator.schema(), type -> type.typeId() ==
Type.TypeID.VARIANT) != null;
- return !hasVariant || supportsFeature(fileFormat, FEATURE_VARIANT);
+ if (hasVariant && !supportsFeature(fileFormat, FEATURE_VARIANT)) {
+ return false;
+ }
+
+ boolean hasGeospatial =
+ TypeUtil.find(
+ generator.schema(),
+ type ->
+ type.typeId() == Type.TypeID.GEOMETRY || type.typeId() ==
Type.TypeID.GEOGRAPHY)
+ != null;
+ if (hasGeospatial && !supportsFeature(fileFormat, FEATURE_GEOSPATIAL)) {
+ return false;
+ }
Review Comment:
nit: can probably decouple and separate into helper methods. return true IFF
the given types is used in the schema and the file format support such schema
and the features?
```java
boolean supportsGenerator(fileFormat, generator) {
return supportsTypes(fileFormat, schema, FEATURE_VARIANT,
VARIANT_TYPE_IDS)
&& supportsTypes(fileFormat, schema, FEATURE_GEOSPATIAL,
GEOSPATIAL_TYPE_IDS);
}
boolean supportsTypes(fileFormat, schema, feature) {
return !usesAnyType(schema.asStruct(), gatedTypeIds) ||
supportsFeature(fileFormat, feature);
}
boolean usesAnyType(type, typeIds) {
return TypeUtil.find(type, nested -> typeIds.contains(nested.typeId()))
!= null;
}
````
##########
data/src/test/java/org/apache/iceberg/data/ReadFormatModelTests.java:
##########
@@ -1473,6 +1477,40 @@ void testDataWriterMetricsCollection(FileFormat
fileFormat) throws IOException {
assertColumnSize(fileFormat, dataFile);
}
+ @ParameterizedTest
+ @FieldSource("FILE_FORMATS")
+ void testDataWriterGeospatialBounds(FileFormat fileFormat) throws
IOException {
+ assumeSupports(fileFormat, FEATURE_GEOSPATIAL);
+ assumeSupports(fileFormat, FEATURE_COLUMN_LEVEL_METRICS);
+
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "geometry_col",
Types.GeometryType.crs84()),
+ Types.NestedField.optional(2, "geometry_opt_col",
Types.GeometryType.crs84()));
Review Comment:
can reuse existing instead of build your own?
```suggestion
Schema schema = new DataGenerators.Geometry().schema();
```
##########
data/src/test/java/org/apache/iceberg/data/ReadFormatModelTests.java:
##########
@@ -1473,6 +1477,40 @@ void testDataWriterMetricsCollection(FileFormat
fileFormat) throws IOException {
assertColumnSize(fileFormat, dataFile);
}
+ @ParameterizedTest
+ @FieldSource("FILE_FORMATS")
+ void testDataWriterGeospatialBounds(FileFormat fileFormat) throws
IOException {
+ assumeSupports(fileFormat, FEATURE_GEOSPATIAL);
+ assumeSupports(fileFormat, FEATURE_COLUMN_LEVEL_METRICS);
+
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "geometry_col",
Types.GeometryType.crs84()),
+ Types.NestedField.optional(2, "geometry_opt_col",
Types.GeometryType.crs84()));
+
+ // The spatial lower/upper bounds are the corners of the bounding box over
all values, so no
+ // single value needs to sit at a corner. Points are chosen so the
expected corners differ from
+ // every input point, and the optional column exercises a skipped null.
+ List<Record> records =
+ List.of(
+ GenericRecord.create(schema)
+ .copy("geometry_col", wkbPoint(1.0, 4.0), "geometry_opt_col",
wkbPoint(-3.0, 7.0)),
+ GenericRecord.create(schema)
+ .copy("geometry_col", wkbPoint(5.0, 2.0), "geometry_opt_col",
null),
+ GenericRecord.create(schema)
+ .copy("geometry_col", wkbPoint(3.0, 6.0), "geometry_opt_col",
wkbPoint(2.0, -1.0)));
+
+ DataFile dataFile = writeGenericRecords(fileFormat, schema, records);
+
+ // Required column box: min corner (1, 2), max corner (5, 6).
+ assertGeospatialBound(dataFile.lowerBounds().get(1), 1.0, 2.0);
+ assertGeospatialBound(dataFile.upperBounds().get(1), 5.0, 6.0);
Review Comment:
```suggestion
Type geometryType = schema.findType("geometry_col");
assertGeospatialBound(
geometryType, dataFile.lowerBounds().get(1),
GeospatialBound.createXY(1.0, 2.0));
assertGeospatialBound(
geometryType, dataFile.upperBounds().get(1),
GeospatialBound.createXY(5.0, 6.0));
```
##########
data/src/test/java/org/apache/iceberg/data/TestGenericFormatModel.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.data;
+
+import java.util.List;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.types.Type;
+
+/**
+ * File Format API TCK binding for the generic {@link Record} object model.
+ *
+ * <p>Unlike the Spark and Flink bindings, the generic engine represents every
Iceberg type
+ * directly, so it exercises the full generator matrix (including geospatial
types) against the
+ * Avro, ORC and Parquet object models. Format-level gaps (for example ORC's
lack of geospatial
+ * support) are handled by {@code MISSING_FEATURES}/{@code supportsGenerator}
in the base class.
+ */
+class TestGenericFormatModel extends BaseFormatModelTests<Record> {
+
+ @Override
+ protected Class<Record> engineType() {
+ return Record.class;
+ }
+
+ @Override
+ protected Object engineSchema(Schema schema) {
+ // The generic object model derives its schema from the Iceberg schema; no
engine-native
+ // schema is required.
+ return null;
+ }
+
+ @Override
+ protected Record convertToEngine(Record record, Schema schema) {
+ return record;
+ }
+
+ @Override
+ protected void assertEquals(Schema schema, List<Record> expected,
List<Record> actual) {
+ DataTestHelpers.assertEquals(schema.asStruct(), expected, actual);
+ }
+
+ @Override
+ protected Object convertConstantToEngine(Type type, Object value) {
+ // Metadata-column constants such as the _partition struct arrive as a
StructLike (for example
+ // PartitionData) rather than a Record. Materialize them as a Record up
front, mirroring how the
+ // Flink and Spark bindings convert constants into their engine
representation, so reads expose
+ // the same type the generic comparison in DataTestHelpers expects.
+ if (value instanceof StructLike struct) {
+ return structLikeToRecord(struct, type.asStructType());
+ }
+
+ return value;
Review Comment:
I think iceberg internal representation difference from generic one so it
need to go through `GenericDataUtil.internalToGeneric(type, value)` before
return like date or timestamp?
##########
data/src/test/java/org/apache/iceberg/data/ReadFormatModelTests.java:
##########
@@ -2576,6 +2628,17 @@ private static Object[] computeMinMax(List<StructLike>
records, int pos, Compara
return new Object[] {min, max};
}
+ private static ByteBuffer wkbPoint(double xCoord, double yCoord) {
+ return ByteBuffer.wrap(RandomUtil.wkbPoint(xCoord, yCoord));
+ }
+
+ private static void assertGeospatialBound(ByteBuffer bound, double
expectedX, double expectedY) {
+ assertThat(bound).as("geospatial bound should be present").isNotNull();
+ GeospatialBound point = GeospatialBound.fromByteBuffer(bound);
+ assertThat(point.x()).isEqualTo(expectedX);
+ assertThat(point.y()).isEqualTo(expectedY);
+ }
Review Comment:
I think we already have existing conversions based method and
GeospatialBound.fromByteBuffer will rejects big-endian buffers, which can come
from copyWithStats
```suggestion
private static void assertGeospatialBound(Type type, ByteBuffer bound,
GeospatialBound expected) {
assertThat((Object) Conversions.fromByteBuffer(type,
bound)).isEqualTo(expected);
}
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]