Skip to content

Commit 7955496

Browse files
committed
address review comments
1 parent e9d2426 commit 7955496

4 files changed

Lines changed: 33 additions & 45 deletions

File tree

parquet-column/src/main/java/org/apache/parquet/column/statistics/geometry/GeospatialStatistics.java

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.parquet.column.statistics.geometry;
2020

21-
import org.apache.parquet.Preconditions;
2221
import org.apache.parquet.io.api.Binary;
2322
import org.apache.parquet.schema.LogicalTypeAnnotation;
2423
import org.apache.parquet.schema.PrimitiveType;
@@ -39,23 +38,6 @@ public class GeospatialStatistics {
3938
private BoundingBox boundingBox;
4039
private GeospatialTypes geospatialTypes;
4140

42-
/**
43-
* Merge the statistics from another GeospatialStatistics object.
44-
*
45-
* @param other the other GeospatialStatistics object
46-
*/
47-
public void mergeStatistics(GeospatialStatistics other) {
48-
if (other == null) {
49-
return;
50-
}
51-
if (this.boundingBox != null && other.boundingBox != null) {
52-
this.boundingBox.merge(other.boundingBox);
53-
}
54-
if (this.geospatialTypes != null && other.geospatialTypes != null) {
55-
this.geospatialTypes.merge(other.geospatialTypes);
56-
}
57-
}
58-
5941
/**
6042
* Builder to create a GeospatialStatistics.
6143
*/
@@ -170,28 +152,28 @@ public boolean isValid() {
170152
if (boundingBox == null || geospatialTypes == null) {
171153
return false;
172154
}
173-
return boundingBox.isValid() && geospatialTypes.isValid();
155+
return (boundingBox != null && boundingBox.isValid()) || (geospatialTypes != null && geospatialTypes.isValid());
174156
}
175157

176158
public void merge(GeospatialStatistics other) {
177-
Preconditions.checkArgument(other != null, "Cannot merge with null GeometryStatistics");
178-
179-
// If other bounding box is null or invalid, set this as null
180-
if (boundingBox == null || other.boundingBox == null) {
181-
boundingBox = null;
159+
if (other == this) {
160+
abort();
182161
}
183162

184163
if (boundingBox != null) {
185164
boundingBox.merge(other.boundingBox);
186165
}
187-
188-
// If other geosptialTypes is null or invalid, set this as null
189-
if (geospatialTypes == null || other.geospatialTypes == null) {
190-
geospatialTypes = null;
166+
if (geospatialTypes != null) {
167+
geospatialTypes.merge(other.geospatialTypes);
191168
}
169+
}
192170

171+
private void abort() {
172+
if (boundingBox != null) {
173+
boundingBox.abort();
174+
}
193175
if (geospatialTypes != null) {
194-
geospatialTypes.merge(other.geospatialTypes);
176+
geospatialTypes.abort();
195177
}
196178
}
197179

parquet-column/src/test/java/org/apache/parquet/column/statistics/geometry/TestGeospatialStatistics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void testCopyGeospatialStatistics() {
129129
builder.update(Binary.fromString("POINT (1 1)"));
130130
GeospatialStatistics statistics = builder.build();
131131
GeospatialStatistics copy = statistics.copy();
132-
Assert.assertFalse(copy.isValid());
132+
Assert.assertTrue(copy.isValid());
133133
Assert.assertNotNull(copy.getBoundingBox());
134134
Assert.assertNotNull(copy.getGeospatialTypes());
135135
}

parquet-hadoop/src/main/java/org/apache/parquet/format/converter/ParquetMetadataConverter.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -821,12 +821,12 @@ private static BoundingBox toParquetBoundingBox(org.apache.parquet.column.statis
821821
formatBbox.setYmin(bbox.getYMin());
822822
formatBbox.setYmax(bbox.getYMax());
823823

824-
if (bbox.isZValid()) {
824+
if (bbox.isZValid() && !bbox.isZEmpty()) {
825825
formatBbox.setZmin(bbox.getZMin());
826826
formatBbox.setZmax(bbox.getZMax());
827827
}
828828

829-
if (bbox.isMValid()) {
829+
if (bbox.isMValid() && !bbox.isMEmpty()) {
830830
formatBbox.setMmin(bbox.getMMin());
831831
formatBbox.setMmax(bbox.getMMax());
832832
}
@@ -946,22 +946,29 @@ GeospatialStatistics toParquetGeospatialStatistics(
946946
}
947947

948948
GeospatialStatistics formatStats = new GeospatialStatistics();
949+
boolean isBoundingBoxSet = false;
950+
boolean isGeometryTypes = false;
949951

950-
if (geospatialStatistics.getBoundingBox() != null) {
951-
if (!geospatialStatistics.getBoundingBox().isValid()) {
952-
return null;
953-
}
954-
if (geospatialStatistics.getBoundingBox().isXYEmpty()) {
955-
return null;
956-
}
952+
if (geospatialStatistics.getBoundingBox() != null
953+
&& geospatialStatistics.getBoundingBox().isValid()
954+
&& !geospatialStatistics.getBoundingBox().isXYEmpty()) {
957955
formatStats.setBbox(toParquetBoundingBox(geospatialStatistics.getBoundingBox()));
956+
isBoundingBoxSet = true;
958957
}
959958

960-
if (geospatialStatistics.getGeospatialTypes() != null) {
959+
if (geospatialStatistics.getGeospatialTypes() != null
960+
&& geospatialStatistics.getGeospatialTypes().isValid()) {
961961
List<Integer> geometryTypes =
962962
new ArrayList<>(geospatialStatistics.getGeospatialTypes().getTypes());
963-
Collections.sort(geometryTypes);
964-
formatStats.setGeospatial_types(geometryTypes);
963+
if (!geometryTypes.isEmpty()) {
964+
Collections.sort(geometryTypes);
965+
formatStats.setGeospatial_types(geometryTypes);
966+
isGeometryTypes = true;
967+
}
968+
}
969+
970+
if (!isBoundingBoxSet && !isGeometryTypes) {
971+
return null;
965972
}
966973

967974
return formatStats;
@@ -1277,7 +1284,7 @@ LogicalTypeAnnotation getLogicalTypeAnnotation(ConvertedType type, SchemaElement
12771284
return LogicalTypeAnnotation.bsonType();
12781285
default:
12791286
throw new RuntimeException(
1280-
"Can't convert converted type t o logical type, unknown converted type " + type);
1287+
"Can't convert converted type to logical type, unknown converted type " + type);
12811288
}
12821289
}
12831290

@@ -2512,7 +2519,6 @@ public static ColumnIndex toParquetColumnIndex(
25122519
if (defLevelHistogram != null && !defLevelHistogram.isEmpty()) {
25132520
parquetColumnIndex.setDefinition_level_histograms(defLevelHistogram);
25142521
}
2515-
25162522
return parquetColumnIndex;
25172523
}
25182524

parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ColumnChunkPageWriteStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private void mergeColumnStatistics(
393393
sizeStatistics = null;
394394
}
395395

396-
totalGeospatialStatistics.mergeStatistics(geospatialStatistics);
396+
totalGeospatialStatistics.merge(geospatialStatistics);
397397

398398
if (totalStatistics != null && totalStatistics.isEmpty()) {
399399
return;

0 commit comments

Comments
 (0)