You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by bc...@apache.org on 2025/04/14 15:50:20 UTC
(incubator-baremaps) branch calcite-schema-ddl updated: Format code
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-schema-ddl
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
The following commit(s) were added to refs/heads/calcite-schema-ddl by this push:
new fa987084b Format code
fa987084b is described below
commit fa987084b7903adf524f00bf8726e132a47aae48
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Mon Apr 14 17:50:13 2025 +0200
Format code
---
.../baremaps/calcite/BaremapsTableFactory.java | 5 +-
.../apache/baremaps/calcite/data/DataSchema.java | 10 ++--
.../baremaps/calcite/data/DataTableSchema.java | 2 +-
.../calcite/openstreetmap/OpenStreetMapSchema.java | 45 ++++++++---------
.../calcite/postgres/PostgresModifiableTable.java | 6 ++-
.../apache/baremaps/calcite/rpsl/RpslSchema.java | 35 +++++++-------
.../calcite/shapefile/ShapefileSchema.java | 29 ++++++-----
.../baremaps/calcite/data/DataSchemaTest.java | 45 ++++++++---------
.../openstreetmap/OpenStreetMapSchemaTest.java | 56 +++++++++++-----------
.../baremaps/calcite/rpsl/RpslSchemaTest.java | 23 ++++-----
.../calcite/shapefile/ShapefileSchemaTest.java | 22 ++++-----
11 files changed, 135 insertions(+), 143 deletions(-)
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
index c2ddc3ad3..9ae8cefd8 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
@@ -108,7 +108,8 @@ public class BaremapsTableFactory implements TableFactory<Table> {
int length = header.getInt();
byte[] bytes = new byte[length];
header.get(bytes);
- DataTableSchema dataTableSchema = DataTableSchema.read(new ByteArrayInputStream(bytes), typeFactory);
+ DataTableSchema dataTableSchema =
+ DataTableSchema.read(new ByteArrayInputStream(bytes), typeFactory);
DataRowType dataRowType = new DataRowType(dataTableSchema);
DataCollection<DataRow> dataCollection = AppendOnlyLog.<DataRow>builder()
.dataType(dataRowType)
@@ -116,7 +117,7 @@ public class BaremapsTableFactory implements TableFactory<Table> {
.build();
return new DataModifiableTable(
name,
- dataTableSchema,
+ dataTableSchema,
dataCollection,
typeFactory);
} catch (IOException e) {
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/data/DataSchema.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/data/DataSchema.java
index 8f3bafe84..7fd631bec 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/data/DataSchema.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/data/DataSchema.java
@@ -35,8 +35,8 @@ import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.impl.AbstractSchema;
/**
- * A Calcite schema implementation for data stored in directories. This schema provides access to data
- * through the Apache Calcite framework for SQL querying.
+ * A Calcite schema implementation for data stored in directories. This schema provides access to
+ * data through the Apache Calcite framework for SQL querying.
*/
public class DataSchema extends AbstractSchema {
@@ -62,12 +62,12 @@ public class DataSchema extends AbstractSchema {
for (File subdirectory : subdirectories) {
String tableName = subdirectory.getName();
Path schemaPath = subdirectory.toPath().resolve("schema.json");
-
+
if (Files.exists(schemaPath)) {
// Read the schema from the schema.json file
try (FileInputStream fis = new FileInputStream(schemaPath.toFile())) {
DataTableSchema schema = DataTableSchema.read(fis, typeFactory);
-
+
// Create the data collection
DataRowType dataRowType = new DataRowType(schema);
Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(schemaPath.getParent());
@@ -75,7 +75,7 @@ public class DataSchema extends AbstractSchema {
.dataType(dataRowType)
.memory(memory)
.build();
-
+
// Create the table
tableMap.put(tableName, new DataModifiableTable(tableName, schema, rows, typeFactory));
}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/data/DataTableSchema.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/data/DataTableSchema.java
index 920f24252..5e643a30b 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/data/DataTableSchema.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/data/DataTableSchema.java
@@ -39,7 +39,7 @@ import org.apache.calcite.sql.type.SqlTypeName;
* A {@link DataTableSchema} defines the structure of a table.
*/
public record DataTableSchema(String name,
- List<DataColumn> columns) implements Serializable {
+ List<DataColumn> columns) implements Serializable {
/**
* Constructs a schema with validation.
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapSchema.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapSchema.java
index 322a50592..26ab95a64 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapSchema.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapSchema.java
@@ -18,9 +18,7 @@
package org.apache.baremaps.calcite.openstreetmap;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -33,8 +31,8 @@ import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.impl.AbstractSchema;
/**
- * A Calcite schema implementation for OpenStreetMap data. This schema provides access to OpenStreetMap
- * files through the Apache Calcite framework for SQL querying.
+ * A Calcite schema implementation for OpenStreetMap data. This schema provides access to
+ * OpenStreetMap files through the Apache Calcite framework for SQL querying.
*/
public class OpenStreetMapSchema extends AbstractSchema {
@@ -55,18 +53,17 @@ public class OpenStreetMapSchema extends AbstractSchema {
this.tableMap = new HashMap<>();
// Process files in the directory
- File[] files = directory.listFiles((dir, name) ->
- name.toLowerCase().endsWith(".pbf") ||
- name.toLowerCase().endsWith(".osm.pbf") ||
- name.toLowerCase().endsWith(".xml") ||
+ File[] files = directory.listFiles((dir, name) -> name.toLowerCase().endsWith(".pbf") ||
+ name.toLowerCase().endsWith(".osm.pbf") ||
+ name.toLowerCase().endsWith(".xml") ||
name.toLowerCase().endsWith(".osm"));
-
+
if (files != null) {
for (File file : files) {
// Extract the base name without extension (e.g., "sample" from "sample.osm.pbf")
String fileName = file.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "sample.osm.pbf" -> "sample")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -76,7 +73,7 @@ public class OpenStreetMapSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(file));
}
@@ -90,7 +87,8 @@ public class OpenStreetMapSchema extends AbstractSchema {
* @param typeFactory the type factory to use for creating tables
* @throws IOException if an I/O error occurs
*/
- public OpenStreetMapSchema(File file, RelDataTypeFactory typeFactory, boolean isDirectory) throws IOException {
+ public OpenStreetMapSchema(File file, RelDataTypeFactory typeFactory, boolean isDirectory)
+ throws IOException {
if (isDirectory) {
// If isDirectory is true, treat the file as a directory
this.directory = Objects.requireNonNull(file, "Directory cannot be null");
@@ -98,18 +96,17 @@ public class OpenStreetMapSchema extends AbstractSchema {
this.tableMap = new HashMap<>();
// Process files in the directory
- File[] files = file.listFiles((dir, name) ->
- name.toLowerCase().endsWith(".pbf") ||
- name.toLowerCase().endsWith(".osm.pbf") ||
- name.toLowerCase().endsWith(".xml") ||
+ File[] files = file.listFiles((dir, name) -> name.toLowerCase().endsWith(".pbf") ||
+ name.toLowerCase().endsWith(".osm.pbf") ||
+ name.toLowerCase().endsWith(".xml") ||
name.toLowerCase().endsWith(".osm"));
-
+
if (files != null) {
for (File osmFile : files) {
// Extract the base name without extension (e.g., "sample" from "sample.osm.pbf")
String fileName = osmFile.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "sample.osm.pbf" -> "sample")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -119,7 +116,7 @@ public class OpenStreetMapSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(osmFile));
}
@@ -133,7 +130,7 @@ public class OpenStreetMapSchema extends AbstractSchema {
// Extract the base name without extension (e.g., "sample" from "sample.osm.pbf")
String fileName = file.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "sample.osm.pbf" -> "sample")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -143,7 +140,7 @@ public class OpenStreetMapSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(file));
}
@@ -158,7 +155,7 @@ public class OpenStreetMapSchema extends AbstractSchema {
private Table createTable(File file) {
// Determine the appropriate entity reader based on file extension
OpenStreetMapFormat.EntityReader<Entity> entityReader;
- if (file.getName().toLowerCase().endsWith(".pbf") ||
+ if (file.getName().toLowerCase().endsWith(".pbf") ||
file.getName().toLowerCase().endsWith(".osm.pbf")) {
PbfEntityReader pbfReader = new PbfEntityReader();
pbfReader.setGeometries(true);
@@ -172,7 +169,7 @@ public class OpenStreetMapSchema extends AbstractSchema {
xmlReader.setReferenceMap(new HashMap<>());
entityReader = xmlReader;
}
-
+
// Create the table with the file reference
return new OpenStreetMapTable(file, entityReader);
}
@@ -181,4 +178,4 @@ public class OpenStreetMapSchema extends AbstractSchema {
protected Map<String, Table> getTableMap() {
return tableMap;
}
-}
\ No newline at end of file
+}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresModifiableTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresModifiableTable.java
index e2fb59cd0..3de53b3c1 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresModifiableTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresModifiableTable.java
@@ -517,7 +517,8 @@ public class PostgresModifiableTable extends AbstractTable
@Override
public Iterator<Object[]> iterator() {
return new Iterator<Object[]>() {
- private final PostgisEnumerator enumerator = new PostgisEnumerator(dataSource, dataTableSchema);
+ private final PostgisEnumerator enumerator =
+ new PostgisEnumerator(dataSource, dataTableSchema);
private boolean hasNext = enumerator.moveNext();
@Override
@@ -595,7 +596,8 @@ public class PostgresModifiableTable extends AbstractTable
Objects.requireNonNull(objects, "Values cannot be null");
if (objects.length != dataTableSchema.columns().size()) {
throw new IllegalArgumentException(
- "Expected " + dataTableSchema.columns().size() + " values, got " + objects.length);
+ "Expected " + dataTableSchema.columns().size() + " values, got "
+ + objects.length);
}
writer.startRow(dataTableSchema.columns().size());
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslSchema.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslSchema.java
index e5f98af3c..f4780ecad 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslSchema.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslSchema.java
@@ -4,7 +4,7 @@
* 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
- * License. You may obtain a copy of the License at
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -27,8 +27,8 @@ import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.impl.AbstractSchema;
/**
- * A Calcite schema implementation for RPSL data. This schema provides access to RPSL files
- * through the Apache Calcite framework for SQL querying.
+ * A Calcite schema implementation for RPSL data. This schema provides access to RPSL files through
+ * the Apache Calcite framework for SQL querying.
*/
public class RpslSchema extends AbstractSchema {
@@ -49,15 +49,15 @@ public class RpslSchema extends AbstractSchema {
this.tableMap = new HashMap<>();
// Process files in the directory
- File[] files = directory.listFiles((dir, name) ->
- name.toLowerCase().endsWith(".rpsl") || name.toLowerCase().endsWith(".txt"));
-
+ File[] files = directory.listFiles(
+ (dir, name) -> name.toLowerCase().endsWith(".rpsl") || name.toLowerCase().endsWith(".txt"));
+
if (files != null) {
for (File file : files) {
// Extract the base name without extension (e.g., "routing" from "routing.rpsl")
String fileName = file.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "routing.rpsl" -> "routing")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -67,7 +67,7 @@ public class RpslSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(file));
}
@@ -81,7 +81,8 @@ public class RpslSchema extends AbstractSchema {
* @param typeFactory the type factory to use for creating tables
* @throws IOException if an I/O error occurs
*/
- public RpslSchema(File file, RelDataTypeFactory typeFactory, boolean isDirectory) throws IOException {
+ public RpslSchema(File file, RelDataTypeFactory typeFactory, boolean isDirectory)
+ throws IOException {
if (isDirectory) {
// If isDirectory is true, treat the file as a directory
this.directory = Objects.requireNonNull(file, "Directory cannot be null");
@@ -89,15 +90,15 @@ public class RpslSchema extends AbstractSchema {
this.tableMap = new HashMap<>();
// Process files in the directory
- File[] files = file.listFiles((dir, name) ->
- name.toLowerCase().endsWith(".rpsl") || name.toLowerCase().endsWith(".txt"));
-
+ File[] files = file.listFiles((dir, name) -> name.toLowerCase().endsWith(".rpsl")
+ || name.toLowerCase().endsWith(".txt"));
+
if (files != null) {
for (File rpslFile : files) {
// Extract the base name without extension (e.g., "routing" from "routing.rpsl")
String fileName = rpslFile.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "routing.rpsl" -> "routing")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -107,7 +108,7 @@ public class RpslSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(rpslFile));
}
@@ -121,7 +122,7 @@ public class RpslSchema extends AbstractSchema {
// Extract the base name without extension (e.g., "routing" from "routing.rpsl")
String fileName = file.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "routing.rpsl" -> "routing")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -131,7 +132,7 @@ public class RpslSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(file));
}
@@ -152,4 +153,4 @@ public class RpslSchema extends AbstractSchema {
protected Map<String, Table> getTableMap() {
return tableMap;
}
-}
\ No newline at end of file
+}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileSchema.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileSchema.java
index e66887b74..38f615f0e 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileSchema.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileSchema.java
@@ -4,7 +4,7 @@
* 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
- * License. You may obtain a copy of the License at
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -49,15 +49,14 @@ public class ShapefileSchema extends AbstractSchema {
this.tableMap = new HashMap<>();
// Process files in the directory
- File[] files = directory.listFiles((dir, name) ->
- name.toLowerCase().endsWith(".shp"));
-
+ File[] files = directory.listFiles((dir, name) -> name.toLowerCase().endsWith(".shp"));
+
if (files != null) {
for (File file : files) {
// Extract the base name without extension (e.g., "countries" from "countries.shp")
String fileName = file.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "countries.shp" -> "countries")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -67,7 +66,7 @@ public class ShapefileSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(file));
}
@@ -81,7 +80,8 @@ public class ShapefileSchema extends AbstractSchema {
* @param typeFactory the type factory to use for creating tables
* @throws IOException if an I/O error occurs
*/
- public ShapefileSchema(File file, RelDataTypeFactory typeFactory, boolean isDirectory) throws IOException {
+ public ShapefileSchema(File file, RelDataTypeFactory typeFactory, boolean isDirectory)
+ throws IOException {
if (isDirectory) {
// If isDirectory is true, treat the file as a directory
this.directory = Objects.requireNonNull(file, "Directory cannot be null");
@@ -89,15 +89,14 @@ public class ShapefileSchema extends AbstractSchema {
this.tableMap = new HashMap<>();
// Process files in the directory
- File[] files = file.listFiles((dir, name) ->
- name.toLowerCase().endsWith(".shp"));
-
+ File[] files = file.listFiles((dir, name) -> name.toLowerCase().endsWith(".shp"));
+
if (files != null) {
for (File shapeFile : files) {
// Extract the base name without extension (e.g., "countries" from "countries.shp")
String fileName = shapeFile.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "countries.shp" -> "countries")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -107,7 +106,7 @@ public class ShapefileSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(shapeFile));
}
@@ -121,7 +120,7 @@ public class ShapefileSchema extends AbstractSchema {
// Extract the base name without extension (e.g., "countries" from "countries.shp")
String fileName = file.getName();
String tableName = fileName;
-
+
// Remove all extensions (e.g., "countries.shp" -> "countries")
while (tableName.contains(".")) {
int lastDotIndex = tableName.lastIndexOf('.');
@@ -131,7 +130,7 @@ public class ShapefileSchema extends AbstractSchema {
break;
}
}
-
+
// Create the table with the file reference
tableMap.put(tableName, createTable(file));
}
@@ -152,4 +151,4 @@ public class ShapefileSchema extends AbstractSchema {
protected Map<String, Table> getTableMap() {
return tableMap;
}
-}
\ No newline at end of file
+}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/data/DataSchemaTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/data/DataSchemaTest.java
index 89405d6dc..5115441cb 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/data/DataSchemaTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/data/DataSchemaTest.java
@@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -33,17 +32,13 @@ import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-import org.apache.baremaps.testing.TestFiles;
import org.apache.calcite.config.CalciteConnectionConfig;
import org.apache.calcite.config.CalciteConnectionConfigImpl;
import org.apache.calcite.config.CalciteConnectionProperty;
import org.apache.calcite.jdbc.CalciteConnection;
-import org.apache.calcite.jdbc.CalciteSchema;
import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.rel.type.RelDataTypeSystem;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
-import org.apache.calcite.sql.type.SqlTypeName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -52,7 +47,7 @@ class DataSchemaTest {
@TempDir
Path tempDir;
-
+
private File sampleDataDir;
private File citiesDir;
private File countriesDir;
@@ -64,96 +59,96 @@ class DataSchemaTest {
sampleDataDir = tempDir.resolve("data").toFile();
citiesDir = new File(sampleDataDir, "cities");
countriesDir = new File(sampleDataDir, "countries");
-
+
sampleDataDir.mkdirs();
citiesDir.mkdirs();
countriesDir.mkdirs();
-
+
// Create schema files
createCitiesSchema();
createCountriesSchema();
-
+
// Initialize the type factory
Properties props = new Properties();
props.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), "false");
CalciteConnectionConfig config = new CalciteConnectionConfigImpl(props);
-
+
// Create a connection to get the type factory
try (Connection connection = DriverManager.getConnection("jdbc:calcite:", props)) {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
typeFactory = calciteConnection.getTypeFactory();
}
}
-
+
private void createCitiesSchema() throws IOException {
// Create a schema for cities
Map<String, Object> schemaMap = new HashMap<>();
schemaMap.put("name", "cities");
-
+
// Define columns
Map<String, Object>[] columns = new Map[3];
-
+
// city column
Map<String, Object> cityColumn = new HashMap<>();
cityColumn.put("name", "city");
cityColumn.put("cardinality", "REQUIRED");
cityColumn.put("sqlTypeName", "VARCHAR");
columns[0] = cityColumn;
-
+
// country column
Map<String, Object> countryColumn = new HashMap<>();
countryColumn.put("name", "country");
countryColumn.put("cardinality", "REQUIRED");
countryColumn.put("sqlTypeName", "VARCHAR");
columns[1] = countryColumn;
-
+
// population column
Map<String, Object> populationColumn = new HashMap<>();
populationColumn.put("name", "population");
populationColumn.put("cardinality", "REQUIRED");
populationColumn.put("sqlTypeName", "INTEGER");
columns[2] = populationColumn;
-
+
schemaMap.put("columns", columns);
-
+
// Write schema to file
ObjectMapper mapper = new ObjectMapper();
try (FileOutputStream fos = new FileOutputStream(new File(citiesDir, "schema.json"))) {
mapper.writeValue(fos, schemaMap);
}
}
-
+
private void createCountriesSchema() throws IOException {
// Create a schema for countries
Map<String, Object> schemaMap = new HashMap<>();
schemaMap.put("name", "countries");
-
+
// Define columns
Map<String, Object>[] columns = new Map[3];
-
+
// country column
Map<String, Object> countryColumn = new HashMap<>();
countryColumn.put("name", "country");
countryColumn.put("cardinality", "REQUIRED");
countryColumn.put("sqlTypeName", "VARCHAR");
columns[0] = countryColumn;
-
+
// continent column
Map<String, Object> continentColumn = new HashMap<>();
continentColumn.put("name", "continent");
continentColumn.put("cardinality", "REQUIRED");
continentColumn.put("sqlTypeName", "VARCHAR");
columns[1] = continentColumn;
-
+
// population column
Map<String, Object> populationColumn = new HashMap<>();
populationColumn.put("name", "population");
populationColumn.put("cardinality", "REQUIRED");
populationColumn.put("sqlTypeName", "INTEGER");
columns[2] = populationColumn;
-
+
schemaMap.put("columns", columns);
-
+
// Write schema to file
ObjectMapper mapper = new ObjectMapper();
try (FileOutputStream fos = new FileOutputStream(new File(countriesDir, "schema.json"))) {
@@ -240,4 +235,4 @@ class DataSchemaTest {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapSchemaTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapSchemaTest.java
index 8cedb78ad..34a1eed06 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapSchemaTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapSchemaTest.java
@@ -43,7 +43,7 @@ public class OpenStreetMapSchemaTest {
@TempDir
Path tempDir;
-
+
private Path sampleDataDir;
private RelDataTypeFactory typeFactory;
@@ -52,15 +52,15 @@ public class OpenStreetMapSchemaTest {
// Create a temporary directory for test files
sampleDataDir = tempDir.resolve("osm-data");
Files.createDirectories(sampleDataDir);
-
+
// Get the absolute paths to the sample files
Path pbfSourcePath = TestFiles.SAMPLE_OSM_PBF.toAbsolutePath();
Path xmlSourcePath = TestFiles.SAMPLE_OSM_XML.toAbsolutePath();
-
+
// Copy sample OSM files to the test directory
Path pbfPath = sampleDataDir.resolve("sample.osm.pbf");
Path xmlPath = sampleDataDir.resolve("sample.osm.xml");
-
+
// Check if source files exist
if (!Files.exists(pbfSourcePath)) {
throw new IOException("Sample PBF file not found: " + pbfSourcePath);
@@ -68,14 +68,14 @@ public class OpenStreetMapSchemaTest {
if (!Files.exists(xmlSourcePath)) {
throw new IOException("Sample XML file not found: " + xmlSourcePath);
}
-
+
Files.copy(pbfSourcePath, pbfPath);
Files.copy(xmlSourcePath, xmlPath);
-
+
// Set up Calcite connection to get a RelDataTypeFactory
Properties info = new Properties();
info.setProperty("lex", "MYSQL");
-
+
try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
typeFactory = calciteConnection.getTypeFactory();
@@ -86,15 +86,15 @@ public class OpenStreetMapSchemaTest {
void testSchemaCreation() throws IOException {
// Create an OpenStreetMapSchema with the test directory
OpenStreetMapSchema schema = new OpenStreetMapSchema(sampleDataDir.toFile(), typeFactory);
-
+
// Verify that the schema contains the expected tables
// The table name is based on the filename without extension
assertTrue(schema.getTableMap().containsKey("sample"), "Schema should contain 'sample' table");
-
+
// Verify that the table has the expected structure
OpenStreetMapTable table = (OpenStreetMapTable) schema.getTableMap().get("sample");
assertNotNull(table, "Table should not be null");
-
+
// Verify the schema structure
int fieldCount = table.getRowType(typeFactory).getFieldCount();
assertEquals(9, fieldCount, "Schema should have 9 columns");
@@ -104,35 +104,36 @@ public class OpenStreetMapSchemaTest {
void testSqlQueryWithDirectory() throws Exception {
// Create an OpenStreetMapSchema with the test directory
OpenStreetMapSchema schema = new OpenStreetMapSchema(sampleDataDir.toFile(), typeFactory);
-
+
// Configure Calcite connection properties
Properties info = new Properties();
info.setProperty("lex", "MYSQL");
-
+
// Set up a connection and register our schema
try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
-
+
// Add the schema to the root schema
rootSchema.add("osm", schema);
-
+
// Test a simple query to select a limited number of entities
// The table name is based on the filename without extension
try (Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery("SELECT id, type FROM osm.sample LIMIT 10")) {
+ ResultSet resultSet =
+ statement.executeQuery("SELECT id, type FROM osm.sample LIMIT 10")) {
int rowCount = 0;
-
+
while (resultSet.next()) {
rowCount++;
long id = resultSet.getLong("id");
String type = resultSet.getString("type");
-
+
// Verify basic properties
assertTrue(id != 0, "Entity should have non-zero ID");
assertNotNull(type, "Entity should have a type");
}
-
+
// Verify that we got some rows
assertTrue(rowCount > 0, "Should have retrieved at least one entity");
}
@@ -150,38 +151,39 @@ public class OpenStreetMapSchemaTest {
// Create an OpenStreetMapSchema with a single file
File pbfFile = sampleDataDir.resolve("sample.osm.pbf").toFile();
OpenStreetMapSchema schema = new OpenStreetMapSchema(pbfFile, typeFactory, false);
-
+
// Configure Calcite connection properties
Properties info = new Properties();
info.setProperty("lex", "MYSQL");
-
+
// Set up a connection and register our schema
try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
-
+
// Add the schema to the root schema
rootSchema.add("osm", schema);
-
+
// Test a simple query to select a limited number of entities
// For a single file, the table name is "sample" (not "osm")
try (Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery("SELECT id, type FROM osm.sample LIMIT 10")) {
+ ResultSet resultSet =
+ statement.executeQuery("SELECT id, type FROM osm.sample LIMIT 10")) {
int rowCount = 0;
-
+
while (resultSet.next()) {
rowCount++;
long id = resultSet.getLong("id");
String type = resultSet.getString("type");
-
+
// Verify basic properties
assertTrue(id != 0, "Entity should have non-zero ID");
assertNotNull(type, "Entity should have a type");
}
-
+
// Verify that we got some rows
assertTrue(rowCount > 0, "Should have retrieved at least one entity");
}
}
}
-}
\ No newline at end of file
+}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/rpsl/RpslSchemaTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/rpsl/RpslSchemaTest.java
index 276880127..49c5424be 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/rpsl/RpslSchemaTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/rpsl/RpslSchemaTest.java
@@ -4,7 +4,7 @@
* 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
- * License. You may obtain a copy of the License at
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -17,7 +17,6 @@
package org.apache.baremaps.calcite.rpsl;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -32,11 +31,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.baremaps.testing.TestFiles;
-import org.apache.calcite.config.CalciteConnectionConfig;
-import org.apache.calcite.config.CalciteConnectionConfigImpl;
-import org.apache.calcite.config.CalciteConnectionProperty;
import org.apache.calcite.jdbc.CalciteConnection;
-import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.schema.SchemaPlus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -70,7 +65,8 @@ public class RpslSchemaTest {
SchemaPlus rootSchema = calciteConnection.getRootSchema();
// Create and register the RPSL schema
- RpslSchema schema = new RpslSchema(tempDir.resolve("rpsl-test").toFile(), calciteConnection.getTypeFactory());
+ RpslSchema schema =
+ new RpslSchema(tempDir.resolve("rpsl-test").toFile(), calciteConnection.getTypeFactory());
rootSchema.add("rpsl", schema);
// Verify that the schema contains the expected table
@@ -88,7 +84,8 @@ public class RpslSchemaTest {
SchemaPlus rootSchema = calciteConnection.getRootSchema();
// Create and register the RPSL schema
- RpslSchema schema = new RpslSchema(tempDir.resolve("rpsl-test").toFile(), calciteConnection.getTypeFactory());
+ RpslSchema schema =
+ new RpslSchema(tempDir.resolve("rpsl-test").toFile(), calciteConnection.getTypeFactory());
rootSchema.add("rpsl", schema);
// Execute a simple SQL query - use lowercase for schema and table names
@@ -98,11 +95,11 @@ public class RpslSchemaTest {
// Verify that we get results
assertTrue(resultSet.next());
-
+
// Verify that the result set has the expected columns
assertNotNull(resultSet.getMetaData());
assertTrue(resultSet.getMetaData().getColumnCount() > 0);
-
+
// Verify that we can access the data
String inetnum = resultSet.getString("inetnum");
assertNotNull(inetnum);
@@ -136,11 +133,11 @@ public class RpslSchemaTest {
// Verify that we get results
assertTrue(resultSet.next());
-
+
// Verify that the result set has the expected columns
assertNotNull(resultSet.getMetaData());
assertTrue(resultSet.getMetaData().getColumnCount() > 0);
-
+
// Verify that we can access the data
String inetnum = resultSet.getString("inetnum");
assertNotNull(inetnum);
@@ -148,4 +145,4 @@ public class RpslSchemaTest {
connection.close();
}
-}
\ No newline at end of file
+}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/shapefile/ShapefileSchemaTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/shapefile/ShapefileSchemaTest.java
index fb534dd0e..34ca432f3 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/shapefile/ShapefileSchemaTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/shapefile/ShapefileSchemaTest.java
@@ -4,7 +4,7 @@
* 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
- * License. You may obtain a copy of the License at
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -17,7 +17,6 @@
package org.apache.baremaps.calcite.shapefile;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -32,11 +31,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.baremaps.testing.TestFiles;
-import org.apache.calcite.config.CalciteConnectionConfig;
-import org.apache.calcite.config.CalciteConnectionConfigImpl;
-import org.apache.calcite.config.CalciteConnectionProperty;
import org.apache.calcite.jdbc.CalciteConnection;
-import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.schema.SchemaPlus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -80,7 +75,8 @@ public class ShapefileSchemaTest {
SchemaPlus rootSchema = calciteConnection.getRootSchema();
// Create and register the shapefile schema
- ShapefileSchema schema = new ShapefileSchema(tempDir.resolve("shapefile-test").toFile(), calciteConnection.getTypeFactory());
+ ShapefileSchema schema = new ShapefileSchema(tempDir.resolve("shapefile-test").toFile(),
+ calciteConnection.getTypeFactory());
rootSchema.add("shapefile", schema);
// Verify that the schema contains the expected table
@@ -98,7 +94,8 @@ public class ShapefileSchemaTest {
SchemaPlus rootSchema = calciteConnection.getRootSchema();
// Create and register the shapefile schema
- ShapefileSchema schema = new ShapefileSchema(tempDir.resolve("shapefile-test").toFile(), calciteConnection.getTypeFactory());
+ ShapefileSchema schema = new ShapefileSchema(tempDir.resolve("shapefile-test").toFile(),
+ calciteConnection.getTypeFactory());
rootSchema.add("shapefile", schema);
// Execute a simple SQL query - use lowercase for schema and table names
@@ -108,7 +105,7 @@ public class ShapefileSchemaTest {
// Verify that we get results
assertTrue(resultSet.next());
-
+
// Verify that the result set has the expected columns
// Note: The actual column names will depend on the sample shapefile
assertNotNull(resultSet.getMetaData());
@@ -129,7 +126,8 @@ public class ShapefileSchemaTest {
File sampleFile = tempDir.resolve("shapefile-test").resolve("point.shp").toFile();
// Create and register the shapefile schema with a single file
- ShapefileSchema schema = new ShapefileSchema(sampleFile, calciteConnection.getTypeFactory(), false);
+ ShapefileSchema schema =
+ new ShapefileSchema(sampleFile, calciteConnection.getTypeFactory(), false);
rootSchema.add("single", schema);
// Verify that the schema contains the expected table
@@ -143,7 +141,7 @@ public class ShapefileSchemaTest {
// Verify that we get results
assertTrue(resultSet.next());
-
+
// Verify that the result set has the expected columns
assertNotNull(resultSet.getMetaData());
assertTrue(resultSet.getMetaData().getColumnCount() > 0);
@@ -151,4 +149,4 @@ public class ShapefileSchemaTest {
connection.close();
}
-}
\ No newline at end of file
+}