This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch 590-flatgeobuf
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
The following commit(s) were added to refs/heads/590-flatgeobuf by this push:
new 0d2a723f Fix minor issues
0d2a723f is described below
commit 0d2a723f672eab0881b7174a65167a09511b8128
Author: Bertil Chapuis <[email protected]>
AuthorDate: Mon Apr 3 15:56:18 2023 +0200
Fix minor issues
---
.../storage/flatgeobuf/FlatGeoBufTable.java | 22 +++++++++---------
.../org/apache/baremaps/storage/MockTable.java | 5 -----
.../storage/flatgeobuf/FlatGeoBufTableTest.java | 26 ++++++++++------------
.../storage/postgres/PostgresTableTest.java | 12 +++++++++-
4 files changed, 35 insertions(+), 30 deletions(-)
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTable.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTable.java
index b87452b7..5a13eeef 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTable.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTable.java
@@ -45,12 +45,13 @@ public class FlatGeoBufTable extends AbstractTable {
private Schema schema;
/**
- * Constructs a table from a flatgeobuf file.
+ * Constructs a table from a flatgeobuf file (used for reading).
*
* @param file the path to the flatgeobuf file
*/
public FlatGeoBufTable(Path file) {
this.file = file;
+ this.schema = readSchema(file);
}
/**
@@ -67,18 +68,22 @@ public class FlatGeoBufTable extends AbstractTable {
/**
* {@inheritDoc}
*/
+ @Override
public Schema schema() {
- if (schema != null) {
- return schema;
- }
+ return schema;
+ }
- // try to read the schema from the file
+ /**
+ * {@inheritDoc}
+ */
+ public static Schema readSchema(Path file) {
try (var channel = FileChannel.open(file, StandardOpenOption.READ)) {
+ // try to read the schema from the file
var buffer = ByteBuffer.allocate(1 << 20).order(ByteOrder.LITTLE_ENDIAN);
HeaderMeta headerMeta = readHeaderMeta(channel, buffer);
return TableConversions.asFeatureType(headerMeta);
} catch (IOException e) {
- throw new RuntimeException(e);
+ return null;
}
}
@@ -102,9 +107,6 @@ public class FlatGeoBufTable extends AbstractTable {
buffer.clear();
- // read the schema
- var schema = schema();
-
// create the feature stream
return new RowIterator(channel, headerMeta, schema, buffer);
} catch (IOException e) {
@@ -134,7 +136,7 @@ public class FlatGeoBufTable extends AbstractTable {
* @return the header meta
* @throws IOException if an error occurs while reading the header meta
*/
- private HeaderMeta readHeaderMeta(SeekableByteChannel channel, ByteBuffer
buffer)
+ private static HeaderMeta readHeaderMeta(SeekableByteChannel channel,
ByteBuffer buffer)
throws IOException {
channel.read(buffer);
buffer.flip();
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/MockTable.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/MockTable.java
index 1ff92e9c..7e459dfc 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/storage/MockTable.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/storage/MockTable.java
@@ -46,11 +46,6 @@ public class MockTable extends AbstractTable {
List.of("string", 5, 5.0, 5.0f, GEOMETRY_FACTORY.createPoint(new
Coordinate(5, 5)))));
}
- public MockTable(Schema schema, List<Row> rows) {
- this.schema = schema;
- this.rows = rows;
- }
-
@Override
public Iterator<Row> iterator() {
return rows.iterator();
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTableTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTableTest.java
index a2384ee2..7f19c72b 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTableTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTableTest.java
@@ -22,32 +22,30 @@ import org.junit.jupiter.api.Test;
class FlatGeoBufTableTest {
@Test
- void getType() throws IOException {
- var featureSet = new FlatGeoBufTable(TestFiles.resolve("countries.fgb"));
- var featureType = featureSet.schema();
- assertEquals(featureType.name(), null);
- assertEquals(featureType.columns().size(), 2);
+ void schema() throws IOException {
+ var table = new FlatGeoBufTable(TestFiles.resolve("countries.fgb"));
+ var schema = table.schema();
+ assertEquals(schema.name(), null);
+ assertEquals(schema.columns().size(), 2);
}
@Test
void read() throws IOException {
- var featureSet = new FlatGeoBufTable(TestFiles.resolve("countries.fgb"));
- assertEquals(179, featureSet.sizeAsLong());
- assertEquals(179, featureSet.stream().count());
+ var table = new FlatGeoBufTable(TestFiles.resolve("countries.fgb"));
+ assertEquals(179, table.sizeAsLong());
+ assertEquals(179, table.stream().count());
}
@Test
void write() throws IOException {
var file = Files.createTempFile("countries", ".fgb");
file.toFile().deleteOnExit();
- var featureSet1 = new FlatGeoBufTable(TestFiles.resolve("countries.fgb"));
- var featureList = featureSet1.stream().toList();
- var featureSet2 = new FlatGeoBufTable(file, featureSet1.schema());
- featureSet2.write(featureList);
+ var table1 = new FlatGeoBufTable(TestFiles.resolve("countries.fgb"));
+ var rows = table1.stream().toList();
+ var table2 = new FlatGeoBufTable(file, table1.schema());
+ table2.write(rows);
var featureSet = new FlatGeoBufTable(file);
assertEquals(179, featureSet.stream().count());
}
-
-
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresTableTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresTableTest.java
index bc028e9a..40fd05c8 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresTableTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresTableTest.java
@@ -72,5 +72,15 @@ class PostgresTableTest extends PostgresContainerTest {
@Test
@Tag("integration")
- void addAll() {}
+ void addAll() {
+ var table = store.get("mock");
+ var schema = table.schema();
+ var added = table.addAll(List.of(
+ new RowImpl(schema,
+ List.of("string", 6, 6.0, 6.0f, GEOMETRY_FACTORY.createPoint(new
Coordinate(6, 6)))),
+ new RowImpl(schema,
+ List.of("string", 7, 7.0, 7.0f, GEOMETRY_FACTORY.createPoint(new
Coordinate(7, 7))))));
+ assertTrue(added);
+ assertEquals(7, table.size());
+ }
}