-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PARQUET-2471: Add support for geometry logical type
- Loading branch information
Showing
15 changed files
with
1,047 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
parquet-column/src/main/java/org/apache/parquet/column/statistics/GeometryStatistics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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.parquet.column.statistics; | ||
|
||
import org.apache.parquet.Preconditions; | ||
import org.apache.parquet.column.statistics.geometry.BoundingBox; | ||
import org.apache.parquet.column.statistics.geometry.Covering; | ||
import org.apache.parquet.column.statistics.geometry.EnvelopeCovering; | ||
import org.apache.parquet.column.statistics.geometry.GeometryTypes; | ||
import org.apache.parquet.io.api.Binary; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jts.io.ParseException; | ||
import org.locationtech.jts.io.WKBReader; | ||
|
||
public class GeometryStatistics { | ||
|
||
private final BoundingBox boundingBox; | ||
private final Covering covering; | ||
private final GeometryTypes geometryTypes; | ||
private final WKBReader reader = new WKBReader(); | ||
|
||
public GeometryStatistics(BoundingBox boundingBox, Covering covering, GeometryTypes geometryTypes) { | ||
this.boundingBox = boundingBox; | ||
this.covering = covering; | ||
this.geometryTypes = geometryTypes; | ||
} | ||
|
||
public GeometryStatistics() { | ||
this(new BoundingBox(), new EnvelopeCovering(), new GeometryTypes()); | ||
} | ||
|
||
public BoundingBox getBoundingBox() { | ||
return boundingBox; | ||
} | ||
|
||
public Covering getCovering() { | ||
return covering; | ||
} | ||
|
||
public GeometryTypes getGeometryTypes() { | ||
return geometryTypes; | ||
} | ||
|
||
public void update(Binary value) { | ||
if (value == null) { | ||
return; | ||
} | ||
try { | ||
Geometry geom = reader.read(value.getBytes()); | ||
update(geom); | ||
} catch (ParseException e) { | ||
abort(); | ||
} | ||
} | ||
|
||
public void update(Geometry geom) { | ||
boundingBox.update(geom); | ||
covering.update(geom); | ||
geometryTypes.update(geom); | ||
} | ||
|
||
public void merge(GeometryStatistics other) { | ||
Preconditions.checkArgument(other != null, "Cannot merge with null GeometryStatistics"); | ||
boundingBox.merge(other.boundingBox); | ||
covering.merge(other.covering); | ||
geometryTypes.merge(other.geometryTypes); | ||
} | ||
|
||
public void reset() { | ||
boundingBox.reset(); | ||
covering.reset(); | ||
geometryTypes.reset(); | ||
} | ||
|
||
public void abort() { | ||
boundingBox.abort(); | ||
covering.abort(); | ||
geometryTypes.abort(); | ||
} | ||
|
||
public GeometryStatistics copy() { | ||
return new GeometryStatistics(boundingBox.copy(), covering.copy(), geometryTypes.copy()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GeometryStatistics{" + "boundingBox=" | ||
+ boundingBox + ", covering=" | ||
+ covering + ", geometryTypes=" | ||
+ geometryTypes + '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
parquet-column/src/main/java/org/apache/parquet/column/statistics/geometry/BoundingBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* 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.parquet.column.statistics.geometry; | ||
|
||
import org.apache.parquet.Preconditions; | ||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.Geometry; | ||
|
||
public class BoundingBox { | ||
|
||
private double xMin = Double.MAX_VALUE; | ||
private double xMax = Double.MIN_VALUE; | ||
private double yMin = Double.MAX_VALUE; | ||
private double yMax = Double.MIN_VALUE; | ||
private double zMin = Double.MAX_VALUE; | ||
private double zMax = Double.MIN_VALUE; | ||
private double mMin = Double.MAX_VALUE; | ||
private double mMax = Double.MIN_VALUE; | ||
|
||
public BoundingBox( | ||
double xMin, double xMax, double yMin, double yMax, double zMin, double zMax, double mMin, double mMax) { | ||
this.xMin = xMin; | ||
this.xMax = xMax; | ||
this.yMin = yMin; | ||
this.yMax = yMax; | ||
this.zMin = zMin; | ||
this.zMax = zMax; | ||
this.mMin = mMin; | ||
this.mMax = mMax; | ||
} | ||
|
||
public BoundingBox() {} | ||
|
||
public double getXMin() { | ||
return xMin; | ||
} | ||
|
||
public double getXMax() { | ||
return xMax; | ||
} | ||
|
||
public double getYMin() { | ||
return yMin; | ||
} | ||
|
||
public double getYMax() { | ||
return yMax; | ||
} | ||
|
||
public double getZMin() { | ||
return zMin; | ||
} | ||
|
||
public double getZMax() { | ||
return zMax; | ||
} | ||
|
||
public double getMMin() { | ||
return mMin; | ||
} | ||
|
||
public double getMMax() { | ||
return mMax; | ||
} | ||
|
||
public void update(Geometry geom) { | ||
if (geom == null || geom.isEmpty()) { | ||
return; | ||
} | ||
Coordinate[] coordinates = geom.getCoordinates(); | ||
for (Coordinate coordinate : coordinates) { | ||
update(coordinate.getX(), coordinate.getY(), coordinate.getZ(), coordinate.getM()); | ||
} | ||
} | ||
|
||
public void update(double x, double y, double z, double m) { | ||
xMin = Math.min(xMin, x); | ||
xMax = Math.max(xMax, x); | ||
yMin = Math.min(yMin, y); | ||
yMax = Math.max(yMax, y); | ||
zMin = Math.min(zMin, z); | ||
zMax = Math.max(zMax, z); | ||
mMin = Math.min(mMin, m); | ||
mMax = Math.max(mMax, m); | ||
} | ||
|
||
public void merge(BoundingBox other) { | ||
Preconditions.checkArgument(other != null, "Cannot merge with null bounding box"); | ||
xMin = Math.min(xMin, other.xMin); | ||
xMax = Math.max(xMax, other.xMax); | ||
yMin = Math.min(yMin, other.yMin); | ||
yMax = Math.max(yMax, other.yMax); | ||
zMin = Math.min(zMin, other.zMin); | ||
zMax = Math.max(zMax, other.zMax); | ||
mMin = Math.min(mMin, other.mMin); | ||
mMax = Math.max(mMax, other.mMax); | ||
} | ||
|
||
public void reset() { | ||
xMin = Double.MAX_VALUE; | ||
xMax = Double.MIN_VALUE; | ||
yMin = Double.MAX_VALUE; | ||
yMax = Double.MIN_VALUE; | ||
zMin = Double.MAX_VALUE; | ||
zMax = Double.MIN_VALUE; | ||
mMin = Double.MAX_VALUE; | ||
mMax = Double.MIN_VALUE; | ||
} | ||
|
||
public void abort() { | ||
xMin = Double.NaN; | ||
xMax = Double.NaN; | ||
yMin = Double.NaN; | ||
yMax = Double.NaN; | ||
zMin = Double.NaN; | ||
zMax = Double.NaN; | ||
mMin = Double.NaN; | ||
mMax = Double.NaN; | ||
} | ||
|
||
public BoundingBox copy() { | ||
return new BoundingBox(xMin, xMax, yMin, yMax, zMin, zMax, mMin, mMax); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BoundingBox{" + "xMin=" | ||
+ xMin + ", xMax=" | ||
+ xMax + ", yMin=" | ||
+ yMin + ", yMax=" | ||
+ yMax + ", zMin=" | ||
+ zMin + ", zMax=" | ||
+ zMax + ", mMin=" | ||
+ mMin + ", mMax=" | ||
+ mMax + '}'; | ||
} | ||
} |
Oops, something went wrong.