-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data schema and table for geoparquet
- Loading branch information
Showing
16 changed files
with
451 additions
and
23 deletions.
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
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
70 changes: 70 additions & 0 deletions
70
baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataSchema.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,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.baremaps.storage.geoparquet; | ||
|
||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import org.apache.baremaps.data.schema.DataSchema; | ||
import org.apache.baremaps.data.schema.DataTable; | ||
import org.apache.baremaps.data.schema.DataTableException; | ||
|
||
/** | ||
* A schema corresponding to a GeoPackage database. | ||
*/ | ||
public class GeoParquetDataSchema implements DataSchema, AutoCloseable { | ||
|
||
private final URI uri; | ||
|
||
public GeoParquetDataSchema(URI uri) { | ||
this.uri = uri; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public List<String> list() throws DataTableException { | ||
return List.of(uri.toString()); | ||
} | ||
|
||
@Override | ||
public DataTable get(String name) throws DataTableException { | ||
if (!uri.toString().equals(name)) { | ||
throw new DataTableException("Table not found"); | ||
} | ||
return new GeoParquetTable(uri); | ||
} | ||
|
||
@Override | ||
public void add(DataTable table) throws DataTableException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void add(String name, DataTable table) throws DataTableException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void remove(String name) throws DataTableException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetTable.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,87 @@ | ||
/* | ||
* 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.baremaps.storage.geoparquet; | ||
|
||
import java.net.URI; | ||
import java.util.Iterator; | ||
import java.util.Spliterator; | ||
import java.util.stream.Stream; | ||
import org.apache.baremaps.data.schema.*; | ||
import org.apache.baremaps.geoparquet.GeoParquetReader; | ||
import org.apache.baremaps.geoparquet.data.GeoParquetGroup.Schema; | ||
|
||
public class GeoParquetTable implements DataTable { | ||
|
||
private final URI path; | ||
|
||
private DataRowType rowType; | ||
|
||
public GeoParquetTable(URI path) { | ||
this.path = path; | ||
} | ||
|
||
@Override | ||
public long size() { | ||
return Long.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public Iterator<DataRow> iterator() { | ||
return parallelStream().iterator(); | ||
} | ||
|
||
public Spliterator<DataRow> spliterator() { | ||
Check notice Code scanning / CodeQL Missing Override annotation Note
This method overrides
DataCollection.spliterator Error loading related location Loading |
||
return parallelStream().spliterator(); | ||
} | ||
|
||
@Override | ||
public Stream<DataRow> stream() { | ||
return parallelStream().sequential(); | ||
} | ||
|
||
@Override | ||
public Stream<DataRow> parallelStream() { | ||
try { | ||
return new GeoParquetReader(path).read().map(group -> new DataRowImpl( | ||
GeoParquetTypeConversion.asDataRowType(path.toString(), group.getSchema()), | ||
GeoParquetTypeConversion.asDataRow(group))); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
|
||
} | ||
|
||
@Override | ||
public DataRowType rowType() { | ||
if (rowType == null) { | ||
try { | ||
GeoParquetReader reader = new GeoParquetReader(path); | ||
Schema schema = reader.getGeoParquetSchema(); | ||
rowType = GeoParquetTypeConversion.asDataRowType(path.toString(), schema); | ||
return rowType; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
return rowType; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...s-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetTypeConversion.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,77 @@ | ||
/* | ||
* 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.baremaps.storage.geoparquet; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.apache.baremaps.data.schema.DataColumn; | ||
import org.apache.baremaps.data.schema.DataColumn.Type; | ||
import org.apache.baremaps.data.schema.DataColumnImpl; | ||
import org.apache.baremaps.data.schema.DataRowType; | ||
import org.apache.baremaps.data.schema.DataRowTypeImpl; | ||
import org.apache.baremaps.geoparquet.data.GeoParquetGroup; | ||
import org.apache.baremaps.geoparquet.data.GeoParquetGroup.Field; | ||
import org.apache.baremaps.geoparquet.data.GeoParquetGroup.Schema; | ||
|
||
public class GeoParquetTypeConversion { | ||
|
||
public static DataRowType asDataRowType(String table, Schema schema) { | ||
List<DataColumn> fields = schema.fields().stream() | ||
.map(field -> (DataColumn) new DataColumnImpl(field.name(), asDataRowType(field.type()))) | ||
.toList(); | ||
return new DataRowTypeImpl(table, fields); | ||
} | ||
|
||
public static Type asDataRowType(GeoParquetGroup.Type type) { | ||
return switch (type) { | ||
case BINARY -> Type.BYTE_ARRAY; | ||
case BOOLEAN -> Type.BOOLEAN; | ||
case INTEGER -> Type.INTEGER; | ||
case INT96 -> Type.LONG; | ||
case LONG -> Type.LONG; | ||
case FLOAT -> Type.FLOAT; | ||
case DOUBLE -> Type.DOUBLE; | ||
case STRING -> Type.STRING; | ||
case GEOMETRY -> Type.GEOMETRY; | ||
case GROUP -> null; | ||
}; | ||
} | ||
|
||
public static List<Object> asDataRow(GeoParquetGroup group) { | ||
List<Object> values = new ArrayList<>(); | ||
Schema schema = group.getSchema(); | ||
List<Field> fields = schema.fields(); | ||
for (int i = 0; i < fields.size(); i++) { | ||
Field field = fields.get(i); | ||
field.type(); | ||
switch (field.type()) { | ||
case BINARY -> values.add(group.getBinaryValue(i).getBytes()); | ||
case BOOLEAN -> values.add(group.getBooleanValue(i)); | ||
case INTEGER -> values.add(group.getIntegerValue(i)); | ||
case INT96 -> values.add(group.getLongValue(i)); | ||
case LONG -> values.add(group.getLongValue(i)); | ||
case FLOAT -> values.add(group.getFloatValue(i)); | ||
case DOUBLE -> values.add(group.getDoubleValue(i)); | ||
case STRING -> values.add(group.getStringValue(i)); | ||
case GEOMETRY -> values.add(group.getGeometryValue(i)); | ||
case GROUP -> values.add(null); // TODO: values.add(asDataRow(group.getGroupValue(i))); | ||
} | ||
} | ||
return values; | ||
} | ||
} |
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
Oops, something went wrong.