Skip to content

Commit 83cdca3

Browse files
committed
Fix conversions, enumerator and table
1 parent 348dbbf commit 83cdca3

File tree

5 files changed

+39
-33
lines changed

5 files changed

+39
-33
lines changed

baremaps-calcite/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to you under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
218
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
319
<modelVersion>4.0.0</modelVersion>
420
<parent>

baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetTable.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,18 @@ private static class GeoParquetEnumerator implements Enumerator<Object[]> {
101101
private GeoParquetGroup currentRow;
102102
private boolean hasNext;
103103
private final Path path;
104+
private java.util.Iterator<GeoParquetGroup> iterator;
104105

105106
public GeoParquetEnumerator(GeoParquetReader reader, GeoParquetSchema schema) {
106107
this.reader = reader;
107108
this.schema = schema;
108109
this.path = new Path(reader.getGeoParquetSchema().name());
110+
try {
111+
// Initialize the iterator once from the stream
112+
this.iterator = reader.read().iterator();
113+
} catch (Exception e) {
114+
throw new RuntimeException("Failed to initialize GeoParquet reader", e);
115+
}
109116
this.hasNext = true;
110117
moveNext();
111118
}
@@ -124,12 +131,14 @@ public boolean moveNext() {
124131
if (!hasNext) {
125132
return false;
126133
}
127-
try {
128-
currentRow = reader.read().findFirst().orElse(null);
129-
hasNext = currentRow != null;
130-
return hasNext;
131-
} catch (Exception e) {
132-
throw new RuntimeException("Failed to read GeoParquet row", e);
134+
135+
if (iterator.hasNext()) {
136+
currentRow = iterator.next();
137+
return true;
138+
} else {
139+
currentRow = null;
140+
hasNext = false;
141+
return false;
133142
}
134143
}
135144

@@ -138,6 +147,7 @@ public void reset() {
138147
try {
139148
reader.close();
140149
GeoParquetReader newReader = new GeoParquetReader(this.path);
150+
this.iterator = newReader.read().iterator();
141151
currentRow = null;
142152
hasNext = true;
143153
moveNext();

baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetTypeConversion.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -244,35 +244,13 @@ public static List<Object> asPostgresRowValues(GeoParquetGroup group) {
244244

245245
for (int i = 0; i < schema.fields().size(); i++) {
246246
Field field = schema.fields().get(i);
247+
// Use convertValue to get values converted to Calcite types
247248
Object value = convertValue(field, group, i);
248249

249-
// Convert record types to JSON strings
250-
if (field.type() == Type.GROUP || field.type() == Type.ENVELOPE) {
250+
// Only handle GROUP types for PostgreSQL - other types pass through Calcite
251+
if (field.type() == Type.GROUP) {
251252
try {
252-
if (field.type() == Type.GROUP) {
253-
value = MAPPER.writeValueAsString(value);
254-
} else if (field.type() == Type.ENVELOPE) {
255-
// Convert envelope to a map with minx, miny, maxx, maxy
256-
Map<String, Object> envelopeMap = new HashMap<>();
257-
if (value instanceof org.locationtech.jts.geom.Envelope) {
258-
org.locationtech.jts.geom.Envelope envelope =
259-
(org.locationtech.jts.geom.Envelope) value;
260-
envelopeMap.put("minx", envelope.getMinX());
261-
envelopeMap.put("miny", envelope.getMinY());
262-
envelopeMap.put("maxx", envelope.getMaxX());
263-
envelopeMap.put("maxy", envelope.getMaxY());
264-
} else if (value instanceof Object[]) {
265-
Object[] envelope = (Object[]) value;
266-
envelopeMap.put("minx", envelope[0]);
267-
envelopeMap.put("miny", envelope[1]);
268-
envelopeMap.put("maxx", envelope[2]);
269-
envelopeMap.put("maxy", envelope[3]);
270-
} else {
271-
throw new IllegalArgumentException(
272-
"Unexpected envelope type: " + value.getClass().getName());
273-
}
274-
value = MAPPER.writeValueAsString(envelopeMap);
275-
}
253+
value = MAPPER.writeValueAsString(value);
276254
} catch (Exception e) {
277255
throw new RuntimeException("Error converting record type to JSON", e);
278256
}

baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected Memory(int headerSize, int segmentSize) {
5757
}
5858

5959
/**
60-
* <<<<<<< HEAD Returns the size of each segment. ======= Returns the size of the header.
60+
* Returns the size of the header.
6161
*
6262
* @return the size of the header
6363
*/

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ limitations under the License.
743743
<exclude>**/ways.wkt</exclude>
744744
<exclude>**/relations.wkt</exclude>
745745
<exclude>**/labels.wkt</exclude>
746+
<exclude>**/point.prj</exclude>
747+
<exclude>**/point.cpg</exclude>
746748
<exclude>**/result</exclude>
747749
<exclude>**/*.txt</exclude>
748750
<exclude>**/*.md</exclude>

0 commit comments

Comments
 (0)