Skip to content

Commit 91e9d26

Browse files
committed
fix unit tests
1 parent 3fdef44 commit 91e9d26

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ public GeospatialTypes getGeospatialTypes() {
183183
* @return whether the statistics has valid value.
184184
*/
185185
public boolean isValid() {
186+
if (boundingBox == null && geospatialTypes == null) {
187+
return false;
188+
}
186189
return Objects.requireNonNull(this.boundingBox).isValid()
187190
&& Objects.requireNonNull(this.geospatialTypes).isValid();
188191
}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,44 @@
2525
import org.apache.parquet.schema.Types;
2626
import org.junit.Assert;
2727
import org.junit.Test;
28+
import org.locationtech.jts.io.ParseException;
29+
import org.locationtech.jts.io.WKBWriter;
30+
import org.locationtech.jts.io.WKTReader;
2831

2932
public class TestGeospatialStatistics {
3033

3134
@Test
32-
public void testAddGeospatialData() {
35+
public void testAddGeospatialData() throws ParseException {
3336
PrimitiveType type = Types.optional(PrimitiveType.PrimitiveTypeName.BINARY)
3437
.as(LogicalTypeAnnotation.geometryType())
3538
.named("a");
3639
GeospatialStatistics.Builder builder = GeospatialStatistics.newBuilder(type);
37-
builder.update(Binary.fromString("POINT (1 1)"));
38-
builder.update(Binary.fromString("POINT (2 2)"));
40+
WKTReader wktReader = new WKTReader();
41+
WKBWriter wkbWriter = new WKBWriter();
42+
// Convert Geometry to WKB and update the builder
43+
builder.update(Binary.fromConstantByteArray(wkbWriter.write(wktReader.read("POINT (1 1)"))));
44+
builder.update(Binary.fromConstantByteArray(wkbWriter.write(wktReader.read("POINT (2 2)"))));
3945
GeospatialStatistics statistics = builder.build();
4046
Assert.assertTrue(statistics.isValid());
4147
Assert.assertNotNull(statistics.getBoundingBox());
4248
Assert.assertNotNull(statistics.getGeospatialTypes());
4349
}
4450

4551
@Test
46-
public void testMergeGeospatialStatistics() {
52+
public void testMergeGeospatialStatistics() throws ParseException {
4753
PrimitiveType type = Types.optional(PrimitiveType.PrimitiveTypeName.BINARY)
4854
.as(LogicalTypeAnnotation.geometryType())
4955
.named("a");
56+
57+
WKTReader wktReader = new WKTReader();
58+
WKBWriter wkbWriter = new WKBWriter();
59+
5060
GeospatialStatistics.Builder builder1 = GeospatialStatistics.newBuilder(type);
51-
builder1.update(Binary.fromString("POINT (1 1)"));
61+
builder1.update(Binary.fromConstantByteArray(wkbWriter.write(wktReader.read("POINT (1 1)"))));
5262
GeospatialStatistics statistics1 = builder1.build();
5363

5464
GeospatialStatistics.Builder builder2 = GeospatialStatistics.newBuilder(type);
55-
builder2.update(Binary.fromString("POINT (2 2)"));
65+
builder2.update(Binary.fromConstantByteArray(wkbWriter.write(wktReader.read("POINT (2 2)"))));
5666
GeospatialStatistics statistics2 = builder2.build();
5767

5868
statistics1.merge(statistics2);

0 commit comments

Comments
 (0)