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

commit c6221ab15c3a52190e7bc4fe021dcb78008d9178
Author: Bertil Chapuis <[email protected]>
AuthorDate: Mon Apr 3 15:56:18 2023 +0200

    Fix minor issues
---
 .../storage/flatgeobuf/FlatGeoBufTable.java        | 22 +++++++++---------
 .../baremaps/storage/postgres/PostgresStore.java   |  3 ++-
 .../baremaps/storage/postgres/PostgresTable.java   |  4 ++--
 .../org/apache/baremaps/storage/MockTable.java     |  6 -----
 .../storage/flatgeobuf/FlatGeoBufTableTest.java    | 26 ++++++++++------------
 .../storage/postgres/PostgresTableTest.java        | 12 +++++++++-
 .../src/main/resources/assets/server.html          |  1 +
 .../src/main/resources/assets/viewer.html          |  1 +
 basemap/README.md                                  |  2 +-
 9 files changed, 42 insertions(+), 35 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/main/java/org/apache/baremaps/storage/postgres/PostgresStore.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresStore.java
index 3079bcb1..a07e60f9 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresStore.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresStore.java
@@ -215,7 +215,8 @@ public class PostgresStore implements Store {
   protected Schema adaptDataType(Schema schema) {
     var name = schema.name().replaceAll("[^a-zA-Z0-9]", "_");
     var properties = schema.columns().stream()
-        .filter(columnType -> typeToName.containsKey(columnType.type()))
+        .filter(column -> typeToName.containsKey(column.type()))
+        .map(column -> (Column) new ColumnImpl(column.name(), column.type()))
         .toList();
     return new SchemaImpl(name, properties);
   }
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTable.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTable.java
index 41b32034..6ae2a7aa 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTable.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTable.java
@@ -145,7 +145,7 @@ public class PostgresTable extends AbstractTable {
     var columns = schema.columns().stream()
         .map(column -> {
           if (column.type().isAssignableFrom(Geometry.class)) {
-            return String.format("st_asbinary(\"%s\") AS %s", column.name(), 
column.name());
+            return String.format("st_asbinary(\"%s\") AS \"%s\"", 
column.name(), column.name());
           } else {
             return String.format("\"%s\"", column.name());
           }
@@ -179,7 +179,7 @@ public class PostgresTable extends AbstractTable {
    * @return the query
    */
   protected String count(Schema schema) {
-    return String.format("SELECT COUNT(*) FROM %s", schema.name());
+    return String.format("SELECT COUNT(*) FROM \"%s\"", schema.name());
   }
 
   /**
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..39e36fc8 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
@@ -21,7 +21,6 @@ import org.locationtech.jts.geom.Geometry;
 
 public class MockTable extends AbstractTable {
 
-
   private final Schema schema;
 
   private final List<Row> rows;
@@ -46,11 +45,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());
+  }
 }
diff --git a/baremaps-server/src/main/resources/assets/server.html 
b/baremaps-server/src/main/resources/assets/server.html
index f7279cf9..168653f3 100644
--- a/baremaps-server/src/main/resources/assets/server.html
+++ b/baremaps-server/src/main/resources/assets/server.html
@@ -25,6 +25,7 @@
     }
 
     #map {
+      position: fixed;
       width: 100%;
       height: 100%;
     }
diff --git a/baremaps-server/src/main/resources/assets/viewer.html 
b/baremaps-server/src/main/resources/assets/viewer.html
index 352b117a..fe3633fb 100644
--- a/baremaps-server/src/main/resources/assets/viewer.html
+++ b/baremaps-server/src/main/resources/assets/viewer.html
@@ -25,6 +25,7 @@
     }
 
     #map {
+      position: fixed;
       width: 100%;
       height: 100%;
     }
diff --git a/basemap/README.md b/basemap/README.md
index 60e5b171..6ee082a0 100644
--- a/basemap/README.md
+++ b/basemap/README.md
@@ -43,7 +43,7 @@ The development server can be started with the following 
command.
 baremaps map dev --log-level DEBUG \
   --database 
'jdbc:postgresql://localhost:5432/baremaps?user=baremaps&password=baremaps' \
   --tileset 'tileset.js' \
-  --style 'line.js'
+  --style 'style.js'
 ```
 
 ## Editing the tileset

Reply via email to