-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for nested types, geoparquet groups, and postgres jsonb i…
…n data table (#860) * Add support for nested types in the DataTable * Add a JsonbHandler that serializes Objects * Add an EnvelopeField to the GeoParquet parser * Save the EnvelopeField as geometry in Postgis * Add a writeEnvelope method to the CopyWriter * BBox use float values in GeoParquet * Create Envelope from Double and Float values * Use the default CRS when the crs field is null in Geoparquet (#861) --------- Co-authored-by: Antoine Drabble <[email protected]>
- Loading branch information
Showing
25 changed files
with
502 additions
and
131 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
49 changes: 49 additions & 0 deletions
49
baremaps-core/src/main/java/org/apache/baremaps/database/copy/EnvelopeValueHandler.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,49 @@ | ||
/* | ||
* 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.database.copy; | ||
|
||
import static org.locationtech.jts.io.WKBConstants.wkbNDR; | ||
|
||
import de.bytefish.pgbulkinsert.pgsql.handlers.BaseValueHandler; | ||
import java.io.DataOutputStream; | ||
import org.locationtech.jts.geom.Envelope; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jts.geom.GeometryFactory; | ||
import org.locationtech.jts.io.WKBWriter; | ||
|
||
public class EnvelopeValueHandler extends BaseValueHandler<Envelope> { | ||
|
||
private static final GeometryFactory geometryFactory = new GeometryFactory(); | ||
|
||
private static byte[] asWKB(Envelope value) { | ||
Geometry geometry = geometryFactory.toGeometry(value); | ||
return new WKBWriter(2, wkbNDR, true).write(geometry); | ||
} | ||
|
||
@Override | ||
protected void internalHandle(DataOutputStream buffer, Envelope value) throws Exception { | ||
byte[] wkb = asWKB(value); | ||
buffer.writeInt(wkb.length); | ||
buffer.write(wkb, 0, wkb.length); | ||
} | ||
|
||
@Override | ||
public int getLength(Envelope value) { | ||
return asWKB(value).length + 4; | ||
} | ||
} |
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
80 changes: 80 additions & 0 deletions
80
baremaps-core/src/main/java/org/apache/baremaps/database/copy/JsonbValueHandler.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,80 @@ | ||
/* | ||
* 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.database.copy; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import de.bytefish.pgbulkinsert.pgsql.handlers.BaseValueHandler; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
|
||
public class JsonbValueHandler extends BaseValueHandler<Object> { | ||
|
||
private static final ObjectMapper objectMapper; | ||
|
||
static { | ||
objectMapper = new ObjectMapper(); | ||
SimpleModule module = new SimpleModule(); | ||
module.addSerializer(String.class, new NoQuotesStringSerializer()); | ||
objectMapper.registerModule(module); | ||
} | ||
|
||
static class NoQuotesStringSerializer extends JsonSerializer<String> { | ||
@Override | ||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) | ||
throws IOException { | ||
gen.writeRawValue(value); | ||
} | ||
} | ||
|
||
private final int jsonbProtocolVersion; | ||
|
||
public JsonbValueHandler() { | ||
this(1); | ||
} | ||
|
||
public JsonbValueHandler(int jsonbProtocolVersion) { | ||
this.jsonbProtocolVersion = jsonbProtocolVersion; | ||
} | ||
|
||
private static byte[] asJson(Object object) { | ||
try { | ||
String value = objectMapper.writeValueAsString(object); | ||
return value.getBytes("UTF-8"); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
protected void internalHandle(DataOutputStream buffer, Object value) throws Exception { | ||
byte[] utf8Bytes = asJson(value); | ||
buffer.writeInt(utf8Bytes.length + 1); | ||
buffer.writeByte(jsonbProtocolVersion); | ||
buffer.write(utf8Bytes); | ||
} | ||
|
||
@Override | ||
public int getLength(Object value) { | ||
byte[] utf8Bytes = asJson(value); | ||
return utf8Bytes.length; | ||
} | ||
} |
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
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
Oops, something went wrong.