Skip to content

Commit 33d3b77

Browse files
committed
split xy into x and y for valid and empty check
1 parent dbc8798 commit 33d3b77

4 files changed

Lines changed: 41 additions & 78 deletions

File tree

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,27 @@ public boolean isValid() {
111111
* @return true if the X and Y dimensions are valid, false otherwise.
112112
*/
113113
public boolean isXYValid() {
114-
return !(Double.isNaN(xMin) || Double.isNaN(xMax) || Double.isNaN(yMin) || Double.isNaN(yMax));
114+
return isXValid() && isYValid();
115+
}
116+
117+
/**
118+
* Checks if the X dimension of the bounding box is valid.
119+
* The X dimension is considered valid if neither bound contains NaN.
120+
*
121+
* @return true if the X dimension is valid, false otherwise.
122+
*/
123+
public boolean isXValid() {
124+
return !(Double.isNaN(xMin) || Double.isNaN(xMax));
125+
}
126+
127+
/**
128+
* Checks if the Y dimension of the bounding box is valid.
129+
* The Y dimension is considered valid if neither bound contains NaN.
130+
*
131+
* @return true if the Y dimension is valid, false otherwise.
132+
*/
133+
public boolean isYValid() {
134+
return !(Double.isNaN(yMin) || Double.isNaN(yMax));
115135
}
116136

117137
/**
@@ -140,8 +160,25 @@ public boolean isMValid() {
140160
* @return true if the bounding box is empty, false otherwise.
141161
*/
142162
public boolean isXYEmpty() {
143-
return (Double.isInfinite(xMin) && Double.isInfinite(xMax))
144-
|| (Double.isInfinite(yMin) && Double.isInfinite(yMax));
163+
return isXEmpty() || isYEmpty();
164+
}
165+
166+
/**
167+
* Checks if the bounding box is empty in the X dimension.
168+
*
169+
* @return true if the X dimension is empty, false otherwise.
170+
*/
171+
public boolean isXEmpty() {
172+
return Double.isInfinite(xMin) && Double.isInfinite(xMax);
173+
}
174+
175+
/**
176+
* Checks if the bounding box is empty in the Y dimension.
177+
*
178+
* @return true if the Y dimension is empty, false otherwise.
179+
*/
180+
public boolean isYEmpty() {
181+
return Double.isInfinite(yMin) && Double.isInfinite(yMax);
145182
}
146183

147184
/**

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

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class GeospatialTypes {
3232

3333
public GeospatialTypes(Set<Integer> types) {
3434
this.types = types;
35-
this.valid = validateTypeValues();
35+
this.valid = true;
3636
}
3737

3838
public GeospatialTypes(Set<Integer> types, boolean valid) {
@@ -95,50 +95,6 @@ public GeospatialTypes copy() {
9595
return new GeospatialTypes(new HashSet<>(types), valid);
9696
}
9797

98-
/**
99-
* Validates the geometry type codes in this GeospatialTypes instance.
100-
* This method ensures that all type codes represent valid geometry types and dimensions.
101-
*
102-
* @return true if all type codes are valid, false otherwise.
103-
*/
104-
public boolean validateTypeValues() {
105-
if (!isValid()) {
106-
return false;
107-
}
108-
109-
// No types is considered valid
110-
if (types.isEmpty()) {
111-
return true;
112-
}
113-
114-
for (Integer typeId : types) {
115-
// Null type code is invalid
116-
if (typeId == null) {
117-
return false;
118-
}
119-
120-
// Negative type codes (except UNKNOWN_TYPE_ID) are invalid
121-
if (typeId < 0 && typeId != UNKNOWN_TYPE_ID) {
122-
return false;
123-
}
124-
125-
// Check for valid geometry type base codes (1-7)
126-
// After removing dimension prefix: 1=Point, 2=LineString, 3=Polygon, etc.
127-
int baseTypeCode = getBaseTypeCode(typeId);
128-
if (baseTypeCode < 1 || baseTypeCode > 7) {
129-
return false;
130-
}
131-
132-
// Check for valid dimension prefix (0=XY, 1000=XYZ, 2000=XYM, 3000=XYZM)
133-
int dimension = getDimensionPrefix(typeId);
134-
if (dimension != 0 && dimension != 1000 && dimension != 2000 && dimension != 3000) {
135-
return false;
136-
}
137-
}
138-
139-
return true;
140-
}
141-
14298
/**
14399
* Extracts the base geometry type code from a full type code.
144100
* For example: 1001 (XYZ Point) -> 1 (Point)

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -530,34 +530,6 @@ public void testGeometryTypeCodeAssignment() {
530530
Assert.assertTrue(geospatialTypes.getTypes().contains(7));
531531
}
532532

533-
@Test
534-
public void testUnsupportedGeometryType() {
535-
// Instead of creating a mock geometry, we'll use reflection to test
536-
// the GeospatialTypes with invalid geometry type codes
537-
GeospatialTypes types = new GeospatialTypes();
538-
539-
// Add an invalid type code directly to test validation
540-
Set<Integer> invalidTypes = new HashSet<>();
541-
invalidTypes.add(8); // 8 is not a valid base geometry type (valid ones are 1-7)
542-
543-
GeospatialTypes invalidTypeInstance = new GeospatialTypes(invalidTypes);
544-
Assert.assertFalse(invalidTypeInstance.isValid());
545-
546-
// Test with out of range dimension prefix
547-
Set<Integer> invalidDimensionTypes = new HashSet<>();
548-
invalidDimensionTypes.add(4000 + 1); // 4000 is not a valid dimension prefix
549-
550-
GeospatialTypes invalidDimensionInstance = new GeospatialTypes(invalidDimensionTypes);
551-
Assert.assertFalse(invalidDimensionInstance.isValid());
552-
553-
// Test with negative type code
554-
Set<Integer> negativeTypes = new HashSet<>();
555-
negativeTypes.add(-5); // Negative type that's not UNKNOWN_TYPE_ID
556-
557-
GeospatialTypes negativeTypeInstance = new GeospatialTypes(negativeTypes);
558-
Assert.assertFalse(negativeTypeInstance.isValid());
559-
}
560-
561533
@Test
562534
public void testGeometryTypeDimensionCodes() {
563535
GeometryFactory gf = new GeometryFactory();

parquet-hadoop/src/test/java/org/apache/parquet/statistics/TestGeometryTypeRoundTrip.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,6 @@ public void testInvalidGeometryPresented() throws Exception {
221221
Assert.assertNotNull("Bounding box should not be null", geospatialStatistics.getBoundingBox());
222222
Assert.assertNotNull("Geospatial types should not be null", geospatialStatistics.getGeospatialTypes());
223223
Assert.assertTrue("Geospatial types should be valid", geospatialStatistics.getGeospatialTypes().isValid());
224-
Assert.assertTrue("Geospatial types should contain valid geometry type values",
225-
geospatialStatistics.getGeospatialTypes().validateTypeValues());
226224
}
227225
}
228226
}

0 commit comments

Comments
 (0)