This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
The following commit(s) were added to refs/heads/main by this push:
new ee7aed76 Refactor and clean the storage package (#857)
ee7aed76 is described below
commit ee7aed7641a9f8e4e6a5099765c2a6d5bb2274d2
Author: Bertil Chapuis <[email protected]>
AuthorDate: Sat Jun 1 11:15:57 2024 +0200
Refactor and clean the storage package (#857)
- The DataFrame class becomes the DataTable class
- The data.schema package becomes the data.storage package
- The method and variable names in the unit tests have been improved
- The overall architecture is documented in the README.md of the module
---
...BufDataSchema.java => FlatGeoBufDataStore.java} | 38 ++++-----
.../storage/flatgeobuf/FlatGeoBufDataTable.java | 66 ++++++++--------
.../flatgeobuf/FlatGeoBufTypeConversion.java | 10 +--
...ageDataSchema.java => GeoPackageDataStore.java} | 26 +++----
.../storage/geopackage/GeoPackageDataTable.java | 32 ++++----
...uetDataSchema.java => GeoParquetDataStore.java} | 24 +++---
.../storage/geoparquet/GeoParquetDataTable.java | 22 +++---
.../geoparquet/GeoParquetTypeConversion.java | 22 +++---
...tgresDataSchema.java => PostgresDataStore.java} | 91 +++++++++++-----------
.../storage/postgres/PostgresDataTable.java | 66 ++++++++--------
.../storage/postgres/PostgresTypeConversion.java | 2 +-
...fileDataSchema.java => ShapefileDataStore.java} | 14 ++--
.../storage/shapefile/ShapefileDataTable.java | 14 ++--
.../shapefile/internal/DbaseByteReader.java | 2 +-
.../shapefile/internal/ShapefileByteReader.java | 24 +++---
.../shapefile/internal/ShapefileInputStream.java | 18 ++---
.../shapefile/internal/ShapefileReader.java | 14 ++--
.../baremaps/workflow/tasks/ImportGeoPackage.java | 14 ++--
.../baremaps/workflow/tasks/ImportShapefile.java | 10 +--
.../org/apache/baremaps/calcite/CalciteTest.java | 16 ++--
.../org/apache/baremaps/storage/MockDataTable.java | 10 +--
.../flatgeobuf/FlatGeoBufDataTableTest.java | 31 ++++----
...chemaTest.java => GeoPackageDataStoreTest.java} | 14 ++--
.../geopackage/GeoPackageToPostgresTest.java | 14 ++--
...chemaTest.java => GeoParquetDataStoreTest.java} | 10 +--
.../geoparquet/GeoParquetToPostgresTest.java | 12 +--
...aSchemaTest.java => PostgresDataStoreTest.java} | 10 +--
.../storage/postgres/PostgresDataTableTest.java | 12 +--
baremaps-data/README.md | 66 ++++++++++++++++
.../apache/baremaps/data/calcite/SqlDataTable.java | 6 +-
.../baremaps/data/calcite/SqlTypeConversion.java | 2 +-
.../apache/baremaps/data/schema/DataSchema.java | 65 ----------------
.../data/{schema => storage}/DataColumn.java | 2 +-
.../data/{schema => storage}/DataColumnImpl.java | 2 +-
.../baremaps/data/{schema => storage}/DataRow.java | 10 +--
.../data/{schema => storage}/DataRowImpl.java | 10 +--
.../DataRowType.java => storage/DataSchema.java} | 18 ++---
.../DataSchemaImpl.java} | 14 ++--
.../apache/baremaps/data/storage/DataStore.java | 65 ++++++++++++++++
.../DataStoreException.java} | 22 +++---
.../data/{schema => storage}/DataTable.java | 10 +--
.../DataTableGeometryMapper.java} | 23 +++---
.../data/{schema => storage}/DataTableImpl.java | 24 +++---
.../data/{schema => storage}/DataTableMapper.java | 14 ++--
.../org/apache/baremaps/data/type/RowDataType.java | 14 ++--
.../baremaps/data/type/DataTypeProvider.java | 10 +--
46 files changed, 539 insertions(+), 476 deletions(-)
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataSchema.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataStore.java
similarity index 67%
rename from
baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataSchema.java
rename to
baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataStore.java
index 6b2d4ba8..8dd15779 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataSchema.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataStore.java
@@ -21,18 +21,18 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
-import org.apache.baremaps.data.schema.DataSchema;
-import org.apache.baremaps.data.schema.DataTable;
-import org.apache.baremaps.data.schema.DataTableException;
+import org.apache.baremaps.data.storage.DataStore;
+import org.apache.baremaps.data.storage.DataStoreException;
+import org.apache.baremaps.data.storage.DataTable;
/**
- * A schema corresponding to the flatgeobuf files of a directory.
+ * A {@link DataStore} corresponding to the flatgeobuf files of a directory.
*/
-public class FlatGeoBufDataSchema implements DataSchema {
+public class FlatGeoBufDataStore implements DataStore {
private final Path directory;
- public FlatGeoBufDataSchema(Path directory) {
+ public FlatGeoBufDataStore(Path directory) {
this.directory = directory;
}
@@ -40,14 +40,14 @@ public class FlatGeoBufDataSchema implements DataSchema {
* {@inheritDoc}
*/
@Override
- public List<String> list() throws DataTableException {
+ public List<String> list() throws DataStoreException {
try (var files = Files.list(directory)) {
return files
.filter(file -> file.toString().toLowerCase().endsWith(".fgb"))
.map(file -> file.getFileName().toString())
.toList();
} catch (IOException e) {
- throw new DataTableException(e);
+ throw new DataStoreException(e);
}
}
@@ -55,7 +55,7 @@ public class FlatGeoBufDataSchema implements DataSchema {
* {@inheritDoc}
*/
@Override
- public DataTable get(String name) throws DataTableException {
+ public DataTable get(String name) throws DataStoreException {
var path = directory.resolve(name);
return new FlatGeoBufDataTable(path);
}
@@ -64,22 +64,22 @@ public class FlatGeoBufDataSchema implements DataSchema {
* {@inheritDoc}
*/
@Override
- public void add(DataTable table) throws DataTableException {
- var filename = table.rowType().name();
- filename = filename.endsWith(".fgb") ? filename : filename + ".fgb";
- add(filename, table);
+ public void add(DataTable table) throws DataStoreException {
+ var fileName = table.schema().name();
+ fileName = fileName.endsWith(".fgb") ? fileName : fileName + ".fgb";
+ add(fileName, table);
}
@Override
- public void add(String name, DataTable table) throws DataTableException {
+ public void add(String name, DataTable table) throws DataStoreException {
var path = directory.resolve(name);
try {
Files.deleteIfExists(path);
Files.createFile(path);
- var flatGeoBufTable = new FlatGeoBufDataTable(path, table.rowType());
+ var flatGeoBufTable = new FlatGeoBufDataTable(path, table.schema());
flatGeoBufTable.write(table);
} catch (IOException e) {
- throw new DataTableException(e);
+ throw new DataStoreException(e);
}
}
@@ -87,16 +87,16 @@ public class FlatGeoBufDataSchema implements DataSchema {
* {@inheritDoc}
*/
@Override
- public void remove(String name) throws DataTableException {
+ public void remove(String name) throws DataStoreException {
var path = directory.resolve(name);
if (name.equals(path.getFileName().toString())) {
try {
Files.delete(path);
} catch (IOException e) {
- throw new DataTableException(e);
+ throw new DataStoreException(e);
}
} else {
- throw new DataTableException("Table not found");
+ throw new DataStoreException("Table not found");
}
}
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTable.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTable.java
index d84b345a..a7c9c93c 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTable.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTable.java
@@ -27,9 +27,9 @@ import java.nio.file.StandardOpenOption;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.baremaps.data.collection.DataCollection;
-import org.apache.baremaps.data.schema.DataRow;
-import org.apache.baremaps.data.schema.DataRowType;
-import org.apache.baremaps.data.schema.DataTable;
+import org.apache.baremaps.data.storage.DataRow;
+import org.apache.baremaps.data.storage.DataSchema;
+import org.apache.baremaps.data.storage.DataTable;
import org.locationtech.jts.geom.*;
import org.wololo.flatgeobuf.Constants;
import org.wololo.flatgeobuf.GeometryConversions;
@@ -39,13 +39,13 @@ import org.wololo.flatgeobuf.generated.Feature;
import org.wololo.flatgeobuf.generated.GeometryType;
/**
- * A table that stores rows in a flatgeobuf file.
+ * A {@link DataTable} that stores rows in a flatgeobuf file.
*/
public class FlatGeoBufDataTable implements DataTable {
private final Path file;
- private DataRowType rowType;
+ private DataSchema schema;
/**
* Constructs a table from a flatgeobuf file (used for reading).
@@ -54,40 +54,38 @@ public class FlatGeoBufDataTable implements DataTable {
*/
public FlatGeoBufDataTable(Path file) {
this.file = file;
- this.rowType = readRowType(file);
+ this.schema = readSchema(file);
+ }
+
+
+ private static DataSchema 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 FlatGeoBufTypeConversion.asSchema(headerMeta);
+ } catch (IOException e) {
+ return null;
+ }
}
/**
- * Constructs a table from a flatgeobuf file and a row type (used for
writing).
+ * Constructs a table from a flatgeobuf file and a schema (used for writing).
*
* @param file the path to the flatgeobuf file
- * @param rowType the row type of the table
+ * @param schema the schema of the table
*/
- public FlatGeoBufDataTable(Path file, DataRowType rowType) {
+ public FlatGeoBufDataTable(Path file, DataSchema schema) {
this.file = file;
- this.rowType = rowType;
+ this.schema = schema;
}
/**
* {@inheritDoc}
*/
@Override
- public DataRowType rowType() {
- return rowType;
- }
-
- /**
- * {@inheritDoc}
- */
- public static DataRowType readRowType(Path file) {
- try (var channel = FileChannel.open(file, StandardOpenOption.READ)) {
- // try to read the row type from the file
- var buffer = ByteBuffer.allocate(1 << 20).order(ByteOrder.LITTLE_ENDIAN);
- HeaderMeta headerMeta = readHeaderMeta(channel, buffer);
- return FlatGeoBufTypeConversion.asRowType(headerMeta);
- } catch (IOException e) {
- return null;
- }
+ public DataSchema schema() {
+ return schema;
}
/**
@@ -111,7 +109,7 @@ public class FlatGeoBufDataTable implements DataTable {
buffer.clear();
// create the feature stream
- return new RowIterator(channel, headerMeta, rowType, buffer);
+ return new RowIterator(channel, headerMeta, schema, buffer);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -173,8 +171,8 @@ public class FlatGeoBufDataTable implements DataTable {
headerMeta.indexNodeSize = 16;
headerMeta.srid = 3857;
headerMeta.featuresCount = features.size();
- headerMeta.name = rowType.name();
- headerMeta.columns =
FlatGeoBufTypeConversion.asColumns(rowType.columns());
+ headerMeta.name = schema.name();
+ headerMeta.columns =
FlatGeoBufTypeConversion.asColumns(schema.columns());
HeaderMeta.write(headerMeta, outputStream, bufferBuilder);
var indexSize =
@@ -235,7 +233,7 @@ public class FlatGeoBufDataTable implements DataTable {
private final HeaderMeta headerMeta;
- private final DataRowType rowType;
+ private final DataSchema schema;
private final SeekableByteChannel channel;
@@ -248,14 +246,14 @@ public class FlatGeoBufDataTable implements DataTable {
*
* @param channel the channel to read from
* @param headerMeta the header meta
- * @param rowType the row type of the table
+ * @param schema the schema of the table
* @param buffer the buffer to use
*/
public RowIterator(SeekableByteChannel channel, HeaderMeta headerMeta,
- DataRowType rowType, ByteBuffer buffer) {
+ DataSchema schema, ByteBuffer buffer) {
this.channel = channel;
this.headerMeta = headerMeta;
- this.rowType = rowType;
+ this.schema = schema;
this.buffer = buffer;
}
@@ -278,7 +276,7 @@ public class FlatGeoBufDataTable implements DataTable {
var featureSize = buffer.getInt();
var row =
- FlatGeoBufTypeConversion.asRow(headerMeta, rowType,
Feature.getRootAsFeature(buffer));
+ FlatGeoBufTypeConversion.asRow(headerMeta, schema,
Feature.getRootAsFeature(buffer));
buffer.position(Integer.BYTES + featureSize);
buffer.compact();
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java
index 68208da0..58c1074c 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java
@@ -25,8 +25,8 @@ import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
-import org.apache.baremaps.data.schema.*;
-import org.apache.baremaps.data.schema.DataColumn.Type;
+import org.apache.baremaps.data.storage.*;
+import org.apache.baremaps.data.storage.DataColumn.Type;
import org.wololo.flatgeobuf.ColumnMeta;
import org.wololo.flatgeobuf.GeometryConversions;
import org.wololo.flatgeobuf.HeaderMeta;
@@ -50,16 +50,16 @@ public class FlatGeoBufTypeConversion {
types.put(Type.STRING, ColumnType.String);
}
- public static DataRowType asRowType(HeaderMeta headerMeta) {
+ public static DataSchema asSchema(HeaderMeta headerMeta) {
var name = headerMeta.name;
var columns = headerMeta.columns.stream()
.map(column -> new DataColumnImpl(column.name,
Type.fromBinding(column.getBinding())))
.map(DataColumn.class::cast)
.toList();
- return new DataRowTypeImpl(name, columns);
+ return new DataSchemaImpl(name, columns);
}
- public static DataRow asRow(HeaderMeta headerMeta, DataRowType dataType,
Feature feature) {
+ public static DataRow asRow(HeaderMeta headerMeta, DataSchema dataType,
Feature feature) {
var values = new ArrayList();
var geometryBuffer = feature.geometry();
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataSchema.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStore.java
similarity index 69%
rename from
baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataSchema.java
rename to
baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStore.java
index 7a8f42ec..abf75b05 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataSchema.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStore.java
@@ -22,23 +22,23 @@ import java.nio.file.Path;
import java.util.List;
import mil.nga.geopackage.GeoPackage;
import mil.nga.geopackage.GeoPackageManager;
-import org.apache.baremaps.data.schema.DataSchema;
-import org.apache.baremaps.data.schema.DataTable;
-import org.apache.baremaps.data.schema.DataTableException;
+import org.apache.baremaps.data.storage.DataStore;
+import org.apache.baremaps.data.storage.DataStoreException;
+import org.apache.baremaps.data.storage.DataTable;
/**
- * A schema corresponding to a GeoPackage database.
+ * A {@link DataStore} corresponding to a GeoPackage file.
*/
-public class GeoPackageDataSchema implements DataSchema, AutoCloseable {
+public class GeoPackageDataStore implements DataStore, AutoCloseable {
private final GeoPackage geoPackage;
/**
- * Constructs a schema from a GeoPackage database.
+ * Constructs a {@link GeoPackageDataStore} from a GeoPackage file.
*
- * @param file the path to the GeoPackage database
+ * @param file the path to the GeoPackage file
*/
- public GeoPackageDataSchema(Path file) {
+ public GeoPackageDataStore(Path file) {
this.geoPackage = GeoPackageManager.open(file.toFile());
}
@@ -54,7 +54,7 @@ public class GeoPackageDataSchema implements DataSchema,
AutoCloseable {
* {@inheritDoc}
*/
@Override
- public List<String> list() throws DataTableException {
+ public List<String> list() throws DataStoreException {
return geoPackage.getFeatureTables();
}
@@ -62,7 +62,7 @@ public class GeoPackageDataSchema implements DataSchema,
AutoCloseable {
* {@inheritDoc}
*/
@Override
- public DataTable get(String name) throws DataTableException {
+ public DataTable get(String name) throws DataStoreException {
return new GeoPackageDataTable(geoPackage.getFeatureDao(name));
}
@@ -70,12 +70,12 @@ public class GeoPackageDataSchema implements DataSchema,
AutoCloseable {
* {@inheritDoc}
*/
@Override
- public void add(DataTable table) throws DataTableException {
+ public void add(DataTable table) throws DataStoreException {
throw new UnsupportedOperationException();
}
@Override
- public void add(String name, DataTable table) throws DataTableException {
+ public void add(String name, DataTable table) throws DataStoreException {
throw new UnsupportedOperationException();
}
@@ -83,7 +83,7 @@ public class GeoPackageDataSchema implements DataSchema,
AutoCloseable {
* {@inheritDoc}
*/
@Override
- public void remove(String name) throws DataTableException {
+ public void remove(String name) throws DataStoreException {
throw new UnsupportedOperationException();
}
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataTable.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataTable.java
index 57b7f8a5..ed6bc89c 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataTable.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataTable.java
@@ -23,23 +23,23 @@ import mil.nga.geopackage.features.user.FeatureColumn;
import mil.nga.geopackage.features.user.FeatureDao;
import mil.nga.geopackage.features.user.FeatureResultSet;
import mil.nga.geopackage.geom.GeoPackageGeometryData;
-import org.apache.baremaps.data.schema.*;
-import org.apache.baremaps.data.schema.DataColumn.Type;
+import org.apache.baremaps.data.storage.*;
+import org.apache.baremaps.data.storage.DataColumn.Type;
import org.locationtech.jts.geom.*;
/**
- * A table that stores rows in a GeoPackage table.
+ * A {@link DataTable} that stores rows in a GeoPackage file.
*/
public class GeoPackageDataTable implements DataTable {
private final FeatureDao featureDao;
- private final DataRowType rowType;
+ private final DataSchema schema;
private final GeometryFactory geometryFactory;
/**
- * Constructs a table from a feature DAO.
+ * Constructs a {@link DataTable} from a feature DAO.
*
* @param featureDao the feature DAO
*/
@@ -52,11 +52,11 @@ public class GeoPackageDataTable implements DataTable {
var propertyType = classType(column);
columns.add(new DataColumnImpl(propertyName, propertyType));
}
- rowType = new DataRowTypeImpl(name, columns);
+ schema = new DataSchemaImpl(name, columns);
geometryFactory = new GeometryFactory(new PrecisionModel(), (int)
featureDao.getSrs().getId());
}
- protected Type classType(FeatureColumn column) {
+ private Type classType(FeatureColumn column) {
if (column.isGeometry()) {
return Type.fromBinding(Geometry.class);
} else {
@@ -69,7 +69,7 @@ public class GeoPackageDataTable implements DataTable {
*/
@Override
public Iterator<DataRow> iterator() {
- return new GeopackageIterator(featureDao.queryForAll(), rowType);
+ return new GeopackageIterator(featureDao.queryForAll(), schema);
}
/**
@@ -92,8 +92,8 @@ public class GeoPackageDataTable implements DataTable {
* {@inheritDoc}
*/
@Override
- public DataRowType rowType() {
- return rowType;
+ public DataSchema schema() {
+ return schema;
}
/**
@@ -224,13 +224,13 @@ public class GeoPackageDataTable implements DataTable {
}
/**
- * An iterator over the rows of a GeoPackage table.
+ * An iterator over the rows of a GeoPackage data table.
*/
public class GeopackageIterator implements Iterator<DataRow> {
private final FeatureResultSet featureResultSet;
- private final DataRowType rowType;
+ private final DataSchema schema;
private boolean hasNext;
@@ -238,11 +238,11 @@ public class GeoPackageDataTable implements DataTable {
* Constructs an iterator from a feature result set.
*
* @param featureResultSet the feature result set
- * @param rowType the row type of the table
+ * @param schema the schema of the data table
*/
- public GeopackageIterator(FeatureResultSet featureResultSet, DataRowType
rowType) {
+ public GeopackageIterator(FeatureResultSet featureResultSet, DataSchema
schema) {
this.featureResultSet = featureResultSet;
- this.rowType = rowType;
+ this.schema = schema;
this.hasNext = featureResultSet.moveToFirst();
}
@@ -262,7 +262,7 @@ public class GeoPackageDataTable implements DataTable {
if (!hasNext) {
throw new NoSuchElementException();
}
- DataRow row = rowType.createRow();
+ DataRow row = schema.createRow();
for (FeatureColumn featureColumn :
featureResultSet.getColumns().getColumns()) {
var value = featureResultSet.getValue(featureColumn);
if (value != null) {
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataSchema.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataStore.java
similarity index 65%
rename from
baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataSchema.java
rename to
baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataStore.java
index 2fbecbea..05874cf9 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataSchema.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataStore.java
@@ -20,46 +20,46 @@ package org.apache.baremaps.storage.geoparquet;
import java.net.URI;
import java.util.List;
-import org.apache.baremaps.data.schema.DataSchema;
-import org.apache.baremaps.data.schema.DataTable;
-import org.apache.baremaps.data.schema.DataTableException;
+import org.apache.baremaps.data.storage.DataStore;
+import org.apache.baremaps.data.storage.DataStoreException;
+import org.apache.baremaps.data.storage.DataTable;
/**
- * A schema corresponding to a GeoParquet database.
+ * A {@link DataStore} corresponding to a GeoParquet file.
*/
-public class GeoParquetDataSchema implements DataSchema {
+public class GeoParquetDataStore implements DataStore {
private final URI uri;
- public GeoParquetDataSchema(URI uri) {
+ public GeoParquetDataStore(URI uri) {
this.uri = uri;
}
@Override
- public List<String> list() throws DataTableException {
+ public List<String> list() throws DataStoreException {
return List.of(uri.toString());
}
@Override
- public DataTable get(String name) throws DataTableException {
+ public DataTable get(String name) throws DataStoreException {
if (!uri.toString().equals(name)) {
- throw new DataTableException("Table not found");
+ throw new DataStoreException("Table not found");
}
return new GeoParquetDataTable(uri);
}
@Override
- public void add(DataTable table) throws DataTableException {
+ public void add(DataTable table) throws DataStoreException {
throw new UnsupportedOperationException();
}
@Override
- public void add(String name, DataTable table) throws DataTableException {
+ public void add(String name, DataTable table) throws DataStoreException {
throw new UnsupportedOperationException();
}
@Override
- public void remove(String name) throws DataTableException {
+ public void remove(String name) throws DataStoreException {
throw new UnsupportedOperationException();
}
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java
index 5fbd4b9d..0d05f680 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java
@@ -23,7 +23,7 @@ import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.stream.Stream;
-import org.apache.baremaps.data.schema.*;
+import org.apache.baremaps.data.storage.*;
import org.apache.baremaps.geoparquet.GeoParquetException;
import org.apache.baremaps.geoparquet.GeoParquetReader;
import org.apache.baremaps.geoparquet.data.GeoParquetGroup.Schema;
@@ -32,7 +32,7 @@ public class GeoParquetDataTable implements DataTable {
private final URI path;
- private DataRowType rowType;
+ private DataSchema schema;
private GeoParquetReader reader;
@@ -75,8 +75,8 @@ public class GeoParquetDataTable implements DataTable {
public Stream<DataRow> parallelStream() {
try {
return reader().read().map(group -> new DataRowImpl(
- GeoParquetTypeConversion.asDataRowType(path.toString(),
group.getSchema()),
- GeoParquetTypeConversion.asDataRow(group)));
+ GeoParquetTypeConversion.asSchema(path.toString(),
group.getSchema()),
+ GeoParquetTypeConversion.asRowValues(group)));
} catch (IOException | URISyntaxException e) {
throw new GeoParquetException("Fail to read() the reader", e);
}
@@ -88,22 +88,22 @@ public class GeoParquetDataTable implements DataTable {
reader = null;
}
- if (rowType != null) {
- rowType = null;
+ if (schema != null) {
+ schema = null;
}
}
@Override
- public DataRowType rowType() {
- if (rowType == null) {
+ public DataSchema schema() {
+ if (schema == null) {
try {
Schema schema = reader().getGeoParquetSchema();
- rowType = GeoParquetTypeConversion.asDataRowType(path.toString(),
schema);
- return rowType;
+ this.schema = GeoParquetTypeConversion.asSchema(path.toString(),
schema);
+ return this.schema;
} catch (URISyntaxException e) {
throw new GeoParquetException("Fail toe get the schema.", e);
}
}
- return rowType;
+ return schema;
}
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetTypeConversion.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetTypeConversion.java
index d0f2f2b9..19c09e41 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetTypeConversion.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetTypeConversion.java
@@ -19,11 +19,11 @@ package org.apache.baremaps.storage.geoparquet;
import java.util.ArrayList;
import java.util.List;
-import org.apache.baremaps.data.schema.DataColumn;
-import org.apache.baremaps.data.schema.DataColumn.Type;
-import org.apache.baremaps.data.schema.DataColumnImpl;
-import org.apache.baremaps.data.schema.DataRowType;
-import org.apache.baremaps.data.schema.DataRowTypeImpl;
+import org.apache.baremaps.data.storage.DataColumn;
+import org.apache.baremaps.data.storage.DataColumn.Type;
+import org.apache.baremaps.data.storage.DataColumnImpl;
+import org.apache.baremaps.data.storage.DataSchema;
+import org.apache.baremaps.data.storage.DataSchemaImpl;
import org.apache.baremaps.geoparquet.data.GeoParquetGroup;
import org.apache.baremaps.geoparquet.data.GeoParquetGroup.Field;
import org.apache.baremaps.geoparquet.data.GeoParquetGroup.Schema;
@@ -32,14 +32,14 @@ public class GeoParquetTypeConversion {
private GeoParquetTypeConversion() {}
- public static DataRowType asDataRowType(String table, Schema schema) {
- List<DataColumn> fields = schema.fields().stream()
- .map(field -> (DataColumn) new DataColumnImpl(field.name(),
asDataRowType(field.type())))
+ public static DataSchema asSchema(String table, Schema schema) {
+ List<DataColumn> columns = schema.fields().stream()
+ .map(field -> (DataColumn) new DataColumnImpl(field.name(),
asSchema(field.type())))
.toList();
- return new DataRowTypeImpl(table, fields);
+ return new DataSchemaImpl(table, columns);
}
- public static Type asDataRowType(GeoParquetGroup.Type type) {
+ public static Type asSchema(GeoParquetGroup.Type type) {
return switch (type) {
case BINARY -> Type.BYTE_ARRAY;
case BOOLEAN -> Type.BOOLEAN;
@@ -53,7 +53,7 @@ public class GeoParquetTypeConversion {
};
}
- public static List<Object> asDataRow(GeoParquetGroup group) {
+ public static List<Object> asRowValues(GeoParquetGroup group) {
List<Object> values = new ArrayList<>();
Schema schema = group.getSchema();
List<Field> fields = schema.fields();
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataSchema.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataStore.java
similarity index 77%
rename from
baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataSchema.java
rename to
baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataStore.java
index 99e3f179..eabd5c59 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataSchema.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataStore.java
@@ -25,8 +25,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import javax.sql.DataSource;
-import org.apache.baremaps.data.schema.*;
-import org.apache.baremaps.data.schema.DataColumn.Type;
+import org.apache.baremaps.data.storage.*;
+import org.apache.baremaps.data.storage.DataColumn.Type;
import org.apache.baremaps.database.copy.CopyWriter;
import org.apache.baremaps.database.copy.GeometryValueHandler;
import org.apache.baremaps.database.metadata.DatabaseMetadata;
@@ -37,23 +37,24 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * A schema that stores tables in a Postgres database.
+ * A {@link DataStore} that stores {@link DataTable}s in the tables of a
Postgres database.
*/
-public class PostgresDataSchema implements DataSchema {
+public class PostgresDataStore implements DataStore {
public static final String REGEX = "[^a-zA-Z0-9]";
- private static final Logger logger =
LoggerFactory.getLogger(PostgresDataSchema.class);
+
+ private static final Logger logger =
LoggerFactory.getLogger(PostgresDataStore.class);
private static final String[] TYPES = new String[] {"TABLE", "VIEW"};
private final DataSource dataSource;
/**
- * Creates a postgres schema.
+ * Creates a postgres data store with the given data source.
*
* @param dataSource the data source
*/
- public PostgresDataSchema(DataSource dataSource) {
+ public PostgresDataStore(DataSource dataSource) {
this.dataSource = dataSource;
}
@@ -61,7 +62,7 @@ public class PostgresDataSchema implements DataSchema {
* {@inheritDoc}
*/
@Override
- public List<String> list() throws DataTableException {
+ public List<String> list() throws DataStoreException {
DatabaseMetadata metadata = new DatabaseMetadata(dataSource);
return metadata.getTableMetaData(null, "public", null, TYPES).stream()
.map(table -> table.table().tableName())
@@ -72,16 +73,16 @@ public class PostgresDataSchema implements DataSchema {
* {@inheritDoc}
*/
@Override
- public DataTable get(String name) throws DataTableException {
+ public DataTable get(String name) throws DataStoreException {
var databaseMetadata = new DatabaseMetadata(dataSource);
var postgresName = name.replaceAll(REGEX, "_").toLowerCase();
var tableMetadata = databaseMetadata.getTableMetaData(null, null,
postgresName, TYPES)
.stream().findFirst();
if (tableMetadata.isEmpty()) {
- throw new DataTableException("Table " + name + " does not exist.");
+ throw new DataStoreException("Table " + name + " does not exist.");
}
- var rowType = createRowType(tableMetadata.get());
- return new PostgresDataTable(dataSource, rowType);
+ var schema = createSchema(tableMetadata.get());
+ return new PostgresDataTable(dataSource, schema);
}
/**
@@ -89,7 +90,7 @@ public class PostgresDataSchema implements DataSchema {
*/
@Override
public void add(DataTable table) {
- var name = table.rowType().name().replaceAll(REGEX, "_").toLowerCase();
+ var name = table.schema().name().replaceAll(REGEX, "_").toLowerCase();
add(name, table);
}
@@ -101,7 +102,7 @@ public class PostgresDataSchema implements DataSchema {
try (var connection = dataSource.getConnection()) {
var mapping = new HashMap<String, String>();
var properties = new ArrayList<DataColumn>();
- for (DataColumn column : table.rowType().columns()) {
+ for (DataColumn column : table.schema().columns()) {
if (PostgresTypeConversion.typeToName.containsKey(column.type())) {
var columnName = column.name().replaceAll(REGEX, "_").toLowerCase();
mapping.put(columnName, column.name());
@@ -109,17 +110,17 @@ public class PostgresDataSchema implements DataSchema {
}
}
- var rowType = new DataRowTypeImpl(name, properties);
+ var schema = new DataSchemaImpl(name, properties);
// Drop the table if it exists
- var dropQuery = dropTable(rowType);
+ var dropQuery = dropTable(schema);
logger.debug(dropQuery);
try (var dropStatement = connection.prepareStatement(dropQuery)) {
dropStatement.execute();
}
// Create the table
- var createQuery = createTable(rowType);
+ var createQuery = createTable(schema);
logger.debug(createQuery);
try (var createStatement = connection.prepareStatement(createQuery)) {
createStatement.execute();
@@ -127,12 +128,12 @@ public class PostgresDataSchema implements DataSchema {
// Copy the data
var pgConnection = connection.unwrap(PGConnection.class);
- var copyQuery = copy(rowType);
+ var copyQuery = copy(schema);
logger.debug(copyQuery);
try (var writer = new CopyWriter(new PGCopyOutputStream(pgConnection,
copyQuery))) {
writer.writeHeader();
- var columns = getColumns(rowType);
- var handlers = getHandlers(rowType);
+ var columns = getColumns(schema);
+ var handlers = getHandlers(schema);
for (DataRow row : table) {
writer.startRow(columns.size());
for (int i = 0; i < columns.size(); i++) {
@@ -158,9 +159,9 @@ public class PostgresDataSchema implements DataSchema {
*/
@Override
public void remove(String name) {
- var rowType = get(name).rowType();
+ var schema = get(name).schema();
try (var connection = dataSource.getConnection();
- var statement = connection.prepareStatement(dropTable(rowType))) {
+ var statement = connection.prepareStatement(dropTable(schema))) {
statement.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
@@ -168,43 +169,43 @@ public class PostgresDataSchema implements DataSchema {
}
/**
- * Creates a row type from the metadata of a postgres table.
+ * Creates a schema from the metadata of a postgres table.
*
* @param tableMetadata the table metadata
- * @return the rowType
+ * @return the schema
*/
- protected static DataRowType createRowType(TableMetadata tableMetadata) {
+ protected static DataSchema createSchema(TableMetadata tableMetadata) {
var name = tableMetadata.table().tableName();
var columns = tableMetadata.columns().stream()
.map(column -> new DataColumnImpl(column.columnName(),
PostgresTypeConversion.nameToType.get(column.typeName())))
.map(DataColumn.class::cast)
.toList();
- return new DataRowTypeImpl(name, columns);
+ return new DataSchemaImpl(name, columns);
}
/**
* Generate a drop table query.
*
- * @param rowType the table name
+ * @param schema the schema
* @return the query
*/
- protected String dropTable(DataRowType rowType) {
- return String.format("DROP TABLE IF EXISTS \"%s\" CASCADE",
rowType.name());
+ protected String dropTable(DataSchema schema) {
+ return String.format("DROP TABLE IF EXISTS \"%s\" CASCADE", schema.name());
}
/**
* Generate a create table query.
*
- * @param rowType the row type
+ * @param schema the schema
* @return the query
*/
- protected String createTable(DataRowType rowType) {
+ protected String createTable(DataSchema schema) {
StringBuilder builder = new StringBuilder();
builder.append("CREATE TABLE \"");
- builder.append(rowType.name());
+ builder.append(schema.name());
builder.append("\" (");
- builder.append(rowType.columns().stream()
+ builder.append(schema.columns().stream()
.map(column -> "\"" + column.name()
+ "\" " + PostgresTypeConversion.typeToName.get(column.type()))
.collect(Collectors.joining(", ")));
@@ -215,15 +216,15 @@ public class PostgresDataSchema implements DataSchema {
/**
* Generate a copy query.
*
- * @param rowType the row type
+ * @param schema the schema
* @return the query
*/
- protected String copy(DataRowType rowType) {
+ protected String copy(DataSchema schema) {
var builder = new StringBuilder();
builder.append("COPY \"");
- builder.append(rowType.name());
+ builder.append(schema.name());
builder.append("\" (");
- builder.append(rowType.columns().stream()
+ builder.append(schema.columns().stream()
.map(column -> "\"" + column.name() + "\"")
.collect(Collectors.joining(", ")));
builder.append(") FROM STDIN BINARY");
@@ -231,25 +232,25 @@ public class PostgresDataSchema implements DataSchema {
}
/**
- * Get the columns of the row type.
+ * Get the columns of the schema.
*
- * @param rowType the row type
+ * @param schema the schema
* @return the columns
*/
- protected List<DataColumn> getColumns(DataRowType rowType) {
- return rowType.columns().stream()
+ protected List<DataColumn> getColumns(DataSchema schema) {
+ return schema.columns().stream()
.filter(this::isSupported)
.collect(Collectors.toList());
}
/**
- * Get the handlers for the columns of the row type.
+ * Get the handlers for the columns of the schema.
*
- * @param rowType the row type
+ * @param schema the schema
* @return the handlers
*/
- protected List<BaseValueHandler> getHandlers(DataRowType rowType) {
- return getColumns(rowType).stream()
+ protected List<BaseValueHandler> getHandlers(DataSchema schema) {
+ return getColumns(schema).stream()
.map(column -> getHandler(column.type()))
.collect(Collectors.toList());
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataTable.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataTable.java
index def24547..6e6315a2 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataTable.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataTable.java
@@ -23,31 +23,31 @@ import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.sql.DataSource;
-import org.apache.baremaps.data.schema.DataRow;
-import org.apache.baremaps.data.schema.DataRowImpl;
-import org.apache.baremaps.data.schema.DataRowType;
-import org.apache.baremaps.data.schema.DataTable;
+import org.apache.baremaps.data.storage.DataRow;
+import org.apache.baremaps.data.storage.DataRowImpl;
+import org.apache.baremaps.data.storage.DataSchema;
+import org.apache.baremaps.data.storage.DataTable;
import org.apache.baremaps.openstreetmap.utils.GeometryUtils;
import org.locationtech.jts.geom.*;
/**
- * A table that stores rows in a Postgres table.
+ * A {@link DataTable} that stores rows in a Postgres table.
*/
public class PostgresDataTable implements DataTable {
private final DataSource dataSource;
- private final DataRowType rowType;
+ private final DataSchema schema;
/**
- * Constructs a table with a given name and a given row type.
+ * Constructs a table with a given name and a given schema.
*
* @param dataSource the data source
- * @param rowType the rowType of the table
+ * @param schema the schema of the table
*/
- public PostgresDataTable(DataSource dataSource, DataRowType rowType) {
+ public PostgresDataTable(DataSource dataSource, DataSchema schema) {
this.dataSource = dataSource;
- this.rowType = rowType;
+ this.schema = schema;
}
/**
@@ -74,7 +74,7 @@ public class PostgresDataTable implements DataTable {
*/
@Override
public long size() {
- var countQuery = count(rowType);
+ var countQuery = count(schema);
try (var connection = dataSource.getConnection();
var statement = connection.prepareStatement(countQuery);
var resultSet = statement.executeQuery()) {
@@ -89,8 +89,8 @@ public class PostgresDataTable implements DataTable {
* {@inheritDoc}
*/
@Override
- public DataRowType rowType() {
- return rowType;
+ public DataSchema schema() {
+ return schema;
}
/**
@@ -98,7 +98,7 @@ public class PostgresDataTable implements DataTable {
*/
@Override
public boolean add(DataRow row) {
- var query = insert(rowType);
+ var query = insert(schema);
try (var connection = dataSource.getConnection();
var statement = connection.prepareStatement(query)) {
setParameters(statement, row);
@@ -114,7 +114,7 @@ public class PostgresDataTable implements DataTable {
@Override
public boolean addAll(Iterable<? extends DataRow> rows) {
try (var connection = dataSource.getConnection();
- var statement = connection.prepareStatement(insert(rowType))) {
+ var statement = connection.prepareStatement(insert(schema))) {
for (var row : rows) {
setParameters(statement, row);
statement.addBatch();
@@ -142,8 +142,8 @@ public class PostgresDataTable implements DataTable {
* @throws SQLException if an SQL error occurs
*/
private void setParameters(PreparedStatement statement, DataRow row) throws
SQLException {
- for (int i = 1; i <= rowType.columns().size(); i++) {
- var value = row.get(rowType.columns().get(i - 1).name());
+ for (int i = 1; i <= schema.columns().size(); i++) {
+ var value = row.get(schema.columns().get(i - 1).name());
if (value instanceof Geometry geometry) {
statement.setBytes(i, GeometryUtils.serialize(geometry));
} else {
@@ -155,11 +155,11 @@ public class PostgresDataTable implements DataTable {
/**
* Generates a query that selects all the rows of a table.
*
- * @param rowType the row type of the table
+ * @param schema the schema of the table
* @return the query
*/
- protected static String select(DataRowType rowType) {
- var columns = rowType.columns().stream()
+ protected static String select(DataSchema schema) {
+ var columns = schema.columns().stream()
.map(column -> {
if (column.type().binding().isAssignableFrom(Geometry.class)) {
return String.format("st_asewkb(\"%s\") AS \"%s\"", column.name(),
column.name());
@@ -168,35 +168,35 @@ public class PostgresDataTable implements DataTable {
}
})
.toList();
- return "SELECT " + String.join(", ", columns) + " FROM \"" +
rowType.name() + "\"";
+ return "SELECT " + String.join(", ", columns) + " FROM \"" + schema.name()
+ "\"";
}
/**
* Generates a query that counts the number of rows of a table.
*
- * @param rowType the row type of the table
+ * @param schema the schema of the table
* @return the query
*/
- protected static String insert(DataRowType rowType) {
- var columns = rowType.columns().stream()
+ protected static String insert(DataSchema schema) {
+ var columns = schema.columns().stream()
.map(column -> String.format("\"%s\"", column.name()))
.toList();
- var values = rowType.columns().stream()
+ var values = schema.columns().stream()
.map(column -> "?")
.toList();
return "INSERT INTO \""
- + rowType.name() + "\" (" + String.join(", ", columns) + ") "
+ + schema.name() + "\" (" + String.join(", ", columns) + ") "
+ "VALUES (" + String.join(", ", values) + ")";
}
/**
* Generates a query that counts the number of rows of a table.
*
- * @param rowType the row type of the table
+ * @param schema the schema of the table
* @return the query
*/
- protected String count(DataRowType rowType) {
- return String.format("SELECT COUNT(*) FROM \"%s\"", rowType.name());
+ protected String count(DataSchema schema) {
+ return String.format("SELECT COUNT(*) FROM \"%s\"", schema.name());
}
/**
@@ -216,7 +216,7 @@ public class PostgresDataTable implements DataTable {
try {
connection = dataSource.getConnection();
statement = connection.createStatement();
- resultSet = statement.executeQuery(select(rowType));
+ resultSet = statement.executeQuery(select(schema));
hasNext = resultSet.next();
} catch (SQLException e) {
close();
@@ -245,8 +245,8 @@ public class PostgresDataTable implements DataTable {
}
try {
List<Object> values = new ArrayList<>();
- for (int i = 0; i < rowType.columns().size(); i++) {
- var column = rowType.columns().get(i);
+ for (int i = 0; i < schema.columns().size(); i++) {
+ var column = schema.columns().get(i);
if (column.type().binding().isAssignableFrom(Geometry.class)) {
values.add(GeometryUtils.deserialize(resultSet.getBytes(i + 1)));
} else {
@@ -254,7 +254,7 @@ public class PostgresDataTable implements DataTable {
}
}
hasNext = resultSet.next();
- return new DataRowImpl(rowType, values);
+ return new DataRowImpl(schema, values);
} catch (SQLException e) {
close();
throw new RuntimeException("Error while fetching the next result", e);
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTypeConversion.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTypeConversion.java
index e11432fd..4188ade5 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTypeConversion.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTypeConversion.java
@@ -19,7 +19,7 @@ package org.apache.baremaps.storage.postgres;
import java.util.EnumMap;
import java.util.Map;
-import org.apache.baremaps.data.schema.DataColumn.Type;
+import org.apache.baremaps.data.storage.DataColumn.Type;
public class PostgresTypeConversion {
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataSchema.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataStore.java
similarity index 84%
rename from
baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataSchema.java
rename to
baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataStore.java
index 77a8102f..315cbf50 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataSchema.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataStore.java
@@ -23,14 +23,14 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
-import org.apache.baremaps.data.schema.DataSchema;
-import org.apache.baremaps.data.schema.DataTable;
-import org.apache.baremaps.data.schema.DataTableException;
+import org.apache.baremaps.data.storage.DataStore;
+import org.apache.baremaps.data.storage.DataStoreException;
+import org.apache.baremaps.data.storage.DataTable;
/**
* A schema corresponding to the shapefiles of a directory.
*/
-public class ShapefileDataSchema implements DataSchema {
+public class ShapefileDataStore implements DataStore {
private final Path directory;
@@ -39,7 +39,7 @@ public class ShapefileDataSchema implements DataSchema {
*
* @param directory the directory
*/
- public ShapefileDataSchema(Path directory) {
+ public ShapefileDataStore(Path directory) {
this.directory = directory;
}
@@ -54,7 +54,7 @@ public class ShapefileDataSchema implements DataSchema {
.map(file -> file.getFileName().toString())
.toList();
} catch (IOException e) {
- throw new DataTableException(e);
+ throw new DataStoreException(e);
}
}
@@ -75,7 +75,7 @@ public class ShapefileDataSchema implements DataSchema {
}
@Override
- public void add(String name, DataTable table) throws DataTableException {
+ public void add(String name, DataTable table) throws DataStoreException {
throw new UnsupportedOperationException();
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java
index 7d89d007..dae52548 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java
@@ -22,10 +22,10 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.apache.baremaps.data.schema.DataRow;
-import org.apache.baremaps.data.schema.DataRowType;
-import org.apache.baremaps.data.schema.DataTable;
-import org.apache.baremaps.data.schema.DataTableException;
+import org.apache.baremaps.data.storage.DataRow;
+import org.apache.baremaps.data.storage.DataSchema;
+import org.apache.baremaps.data.storage.DataStoreException;
+import org.apache.baremaps.data.storage.DataTable;
import org.apache.baremaps.storage.shapefile.internal.ShapefileInputStream;
import org.apache.baremaps.storage.shapefile.internal.ShapefileReader;
import org.slf4j.Logger;
@@ -53,11 +53,11 @@ public class ShapefileDataTable implements DataTable {
* {@inheritDoc}
*/
@Override
- public DataRowType rowType() throws DataTableException {
+ public DataSchema schema() throws DataStoreException {
try (var input = shapeFile.read()) {
- return input.rowType();
+ return input.schema();
} catch (IOException e) {
- throw new DataTableException(e);
+ throw new DataStoreException(e);
}
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/DbaseByteReader.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/DbaseByteReader.java
index a14b32fc..60975998 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/DbaseByteReader.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/DbaseByteReader.java
@@ -27,7 +27,7 @@ import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.text.MessageFormat;
import java.util.*;
-import org.apache.baremaps.data.schema.DataRow;
+import org.apache.baremaps.data.storage.DataRow;
/**
* Reader of a Database Binary content.
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java
index c71a5d74..d733067b 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java
@@ -24,8 +24,8 @@ import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.*;
-import org.apache.baremaps.data.schema.*;
-import org.apache.baremaps.data.schema.DataColumn.Type;
+import org.apache.baremaps.data.storage.*;
+import org.apache.baremaps.data.storage.DataColumn.Type;
import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateList;
@@ -51,7 +51,7 @@ public class ShapefileByteReader extends CommonByteReader {
private List<DBaseFieldDescriptor> databaseFieldsDescriptors;
/** Schema of the rows contained in this shapefile. */
- private DataRowType rowType;
+ private DataSchema schema;
/** Shapefile index. */
private File shapeFileIndex;
@@ -86,7 +86,7 @@ public class ShapefileByteReader extends CommonByteReader {
loadShapefileIndexes();
}
- this.rowType = getSchema(shapefile.getName());
+ this.schema = getSchema(shapefile.getName());
}
/**
@@ -108,21 +108,21 @@ public class ShapefileByteReader extends CommonByteReader
{
}
/**
- * Returns the row type of the data contained in this shapefile.
+ * Returns the schema of the data contained in this shapefile.
*
- * @return the row type
+ * @return the schema
*/
- public DataRowType getRowType() {
- return this.rowType;
+ public DataSchema getSchema() {
+ return this.schema;
}
/**
* Create a row descriptor.
*
* @param name Name of the field.
- * @return The row type.
+ * @return The schema.
*/
- private DataRowType getSchema(final String name) {
+ private DataSchema getSchema(final String name) {
Objects.requireNonNull(name, "The row name cannot be null.");
var columns = new ArrayList<DataColumn>();
@@ -154,7 +154,7 @@ public class ShapefileByteReader extends CommonByteReader {
// Add geometry column.
columns.add(new DataColumnImpl(GEOMETRY_NAME, Type.GEOMETRY));
- return new DataRowTypeImpl(name, columns);
+ return new DataSchemaImpl(name, columns);
}
/** Load shapefile descriptor. */
@@ -273,7 +273,7 @@ public class ShapefileByteReader extends CommonByteReader {
if (shapefileGeometryType == null) {
throw new ShapefileException(
- "The shapefile row type doesn''t match to any known row type.");
+ "The shapefile schema doesn''t match to any known schema.");
}
switch (shapefileGeometryType) {
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileInputStream.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileInputStream.java
index 655a2ce6..bd7a1e9a 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileInputStream.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileInputStream.java
@@ -23,8 +23,8 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import org.apache.baremaps.data.schema.DataRow;
-import org.apache.baremaps.data.schema.DataRowType;
+import org.apache.baremaps.data.storage.DataRow;
+import org.apache.baremaps.data.storage.DataSchema;
/**
* Input Stream of features.
@@ -52,7 +52,7 @@ public class ShapefileInputStream extends InputStream {
private boolean hasShapefileIndex;
/** Row type of the features contained in this shapefile. */
- private DataRowType rowType;
+ private DataSchema schema;
/** Shapefile reader. */
private ShapefileByteReader shapefileReader;
@@ -79,7 +79,7 @@ public class ShapefileInputStream extends InputStream {
this.shapefileReader =
new ShapefileByteReader(this.shapefile, this.databaseFile,
this.shapefileIndex);
- this.rowType = this.shapefileReader.getRowType();
+ this.schema = this.shapefileReader.getSchema();
}
/**
@@ -122,7 +122,7 @@ public class ShapefileInputStream extends InputStream {
if (!this.dbaseReader.nextRowAvailable()) {
return null;
}
- DataRow row = this.rowType.createRow();
+ DataRow row = this.schema.createRow();
this.dbaseReader.loadRow(row);
this.shapefileReader.setRowNum(this.dbaseReader.getRowNum());
this.shapefileReader.completeRow(row);
@@ -130,12 +130,12 @@ public class ShapefileInputStream extends InputStream {
}
/**
- * Returns the row type.
+ * Returns the schema.
*
- * @return the row type.
+ * @return the schema.
*/
- public DataRowType rowType() {
- return rowType;
+ public DataSchema schema() {
+ return schema;
}
/**
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileReader.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileReader.java
index 63e98dde..6d41aa7b 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileReader.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileReader.java
@@ -23,7 +23,7 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
-import org.apache.baremaps.data.schema.DataRowType;
+import org.apache.baremaps.data.storage.DataSchema;
/**
* Provides a ShapeFile Reader.
@@ -49,7 +49,7 @@ public class ShapefileReader {
private File shapeFileIndex;
/** Type of the features contained in this shapefile. */
- private DataRowType rowType;
+ private DataSchema schema;
/** Shapefile descriptor. */
private ShapefileDescriptor shapefileDescriptor;
@@ -118,12 +118,12 @@ public class ShapefileReader {
}
/**
- * Return the row type.
+ * Return the schema.
*
- * @return the row type.
+ * @return the schema.
*/
- public DataRowType rowType() {
- return this.rowType;
+ public DataSchema schema() {
+ return this.schema;
}
/**
@@ -179,7 +179,7 @@ public class ShapefileReader {
public ShapefileInputStream read() throws IOException {
ShapefileInputStream is =
new ShapefileInputStream(this.shapefile, this.databaseFile,
this.shapeFileIndex);
- this.rowType = is.rowType();
+ this.schema = is.schema();
this.shapefileDescriptor = is.getShapefileDescriptor();
this.databaseFieldsDescriptors = is.getDatabaseFieldsDescriptors();
return is;
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportGeoPackage.java
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportGeoPackage.java
index e0b80d98..88801a53 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportGeoPackage.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportGeoPackage.java
@@ -19,11 +19,11 @@ package org.apache.baremaps.workflow.tasks;
import java.nio.file.Path;
import java.util.StringJoiner;
-import org.apache.baremaps.data.schema.DataTableGeometryTransformer;
-import org.apache.baremaps.data.schema.DataTableMapper;
+import org.apache.baremaps.data.storage.DataTableGeometryMapper;
+import org.apache.baremaps.data.storage.DataTableMapper;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
-import org.apache.baremaps.storage.geopackage.GeoPackageDataSchema;
-import org.apache.baremaps.storage.postgres.PostgresDataSchema;
+import org.apache.baremaps.storage.geopackage.GeoPackageDataStore;
+import org.apache.baremaps.storage.postgres.PostgresDataStore;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
import org.apache.baremaps.workflow.WorkflowException;
@@ -70,14 +70,14 @@ public class ImportGeoPackage implements Task {
@Override
public void execute(WorkflowContext context) throws Exception {
var path = file.toAbsolutePath();
- try (var geoPackageDataStore = new GeoPackageDataSchema(path)) {
+ try (var geoPackageDataStore = new GeoPackageDataStore(path)) {
var dataSource = context.getDataSource(database);
- var postgresDataStore = new PostgresDataSchema(dataSource);
+ var postgresDataStore = new PostgresDataStore(dataSource);
for (var name : geoPackageDataStore.list()) {
var geoPackageTable = geoPackageDataStore.get(name);
var projectionTransformer = new ProjectionTransformer(fileSrid,
databaseSrid);
var rowTransformer =
- new DataTableGeometryTransformer(geoPackageTable,
projectionTransformer);
+ new DataTableGeometryMapper(geoPackageTable,
projectionTransformer);
var transformedDataTable =
new DataTableMapper(geoPackageDataStore.get(name), rowTransformer);
postgresDataStore.add(transformedDataTable);
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportShapefile.java
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportShapefile.java
index e671d3dc..6cb3b789 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportShapefile.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportShapefile.java
@@ -19,10 +19,10 @@ package org.apache.baremaps.workflow.tasks;
import java.nio.file.Path;
import java.util.StringJoiner;
-import org.apache.baremaps.data.schema.DataTableGeometryTransformer;
-import org.apache.baremaps.data.schema.DataTableMapper;
+import org.apache.baremaps.data.storage.DataTableGeometryMapper;
+import org.apache.baremaps.data.storage.DataTableMapper;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
-import org.apache.baremaps.storage.postgres.PostgresDataSchema;
+import org.apache.baremaps.storage.postgres.PostgresDataStore;
import org.apache.baremaps.storage.shapefile.ShapefileDataTable;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
@@ -73,8 +73,8 @@ public class ImportShapefile implements Task {
try {
var shapefileDataTable = new ShapefileDataTable(path);
var dataSource = context.getDataSource(database);
- var postgresDataStore = new PostgresDataSchema(dataSource);
- var rowTransformer = new DataTableGeometryTransformer(shapefileDataTable,
+ var postgresDataStore = new PostgresDataStore(dataSource);
+ var rowTransformer = new DataTableGeometryMapper(shapefileDataTable,
new ProjectionTransformer(fileSrid, databaseSrid));
var transformedDataTable = new DataTableMapper(shapefileDataTable,
rowTransformer);
postgresDataStore.add(transformedDataTable);
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index 74f298a6..d59123ae 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
@@ -25,8 +25,8 @@ import java.util.Properties;
import org.apache.baremaps.data.calcite.SqlDataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
-import org.apache.baremaps.data.schema.*;
-import org.apache.baremaps.data.schema.DataColumn.Type;
+import org.apache.baremaps.data.storage.*;
+import org.apache.baremaps.data.storage.DataColumn.Type;
import org.apache.baremaps.data.type.RowDataType;
import org.apache.baremaps.maplibre.vectortile.VectorTileFunctions;
import org.apache.calcite.jdbc.CalciteConnection;
@@ -73,31 +73,31 @@ public class CalciteTest {
VectorTileFunctions.class.getName(), "asVectorTile", true);
// Create the city table
- DataRowType cityRowType = new DataRowTypeImpl("city", List.of(
+ DataSchema cityRowType = new DataSchemaImpl("city", List.of(
new DataColumnImpl("id", Type.INTEGER),
new DataColumnImpl("name", Type.STRING),
new DataColumnImpl("geometry", Type.GEOMETRY)));
DataTable cityDataTable = new DataTableImpl(
cityRowType,
new IndexedDataList<>(new AppendOnlyLog<>(new
RowDataType(cityRowType))));
- cityDataTable.add(new DataRowImpl(cityDataTable.rowType(),
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
List.of(1, "Paris", geometryFactory.createPoint(new
Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRowImpl(cityDataTable.rowType(),
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
List.of(2, "New York", geometryFactory.createPoint(new
Coordinate(-74.0060, 40.7128)))));
SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
rootSchema.add("city", citySqlDataTable);
// Create the population table
- DataRowType populationRowType = new DataRowTypeImpl("population",
List.of(
+ DataSchema populationRowType = new DataSchemaImpl("population", List.of(
new DataColumnImpl("city_id", Type.INTEGER),
new DataColumnImpl("population", Type.INTEGER)));
DataTable populationDataTable = new DataTableImpl(
populationRowType,
new IndexedDataList<>(new AppendOnlyLog<>(new
RowDataType(populationRowType))));
populationDataTable
- .add(new DataRowImpl(populationDataTable.rowType(), List.of(1,
2_161_000)));
+ .add(new DataRowImpl(populationDataTable.schema(), List.of(1,
2_161_000)));
populationDataTable
- .add(new DataRowImpl(populationDataTable.rowType(), List.of(2,
8_336_000)));
+ .add(new DataRowImpl(populationDataTable.schema(), List.of(2,
8_336_000)));
SqlDataTable populationSqlDataTable = new
SqlDataTable(populationDataTable);
rootSchema.add("population", populationSqlDataTable);
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataTable.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataTable.java
index 77d11c40..f21bdd7f 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataTable.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataTable.java
@@ -21,18 +21,18 @@ import static
org.apache.baremaps.database.repository.Constants.GEOMETRY_FACTORY
import java.util.Iterator;
import java.util.List;
-import org.apache.baremaps.data.schema.*;
-import org.apache.baremaps.data.schema.DataColumn.Type;
+import org.apache.baremaps.data.storage.*;
+import org.apache.baremaps.data.storage.DataColumn.Type;
import org.locationtech.jts.geom.Coordinate;
public class MockDataTable implements DataTable {
- private final DataRowType rowType;
+ private final DataSchema rowType;
private final List<DataRow> rows;
public MockDataTable() {
- this.rowType = new DataRowTypeImpl("mock", List.of(
+ this.rowType = new DataSchemaImpl("mock", List.of(
new DataColumnImpl("string", Type.STRING),
new DataColumnImpl("integer", Type.INTEGER),
new DataColumnImpl("double", Type.DOUBLE),
@@ -67,7 +67,7 @@ public class MockDataTable implements DataTable {
}
@Override
- public DataRowType rowType() {
+ public DataSchema schema() {
return rowType;
}
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java
index c48abdb5..bcf450f1 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java
@@ -27,32 +27,31 @@ import org.junit.jupiter.api.Test;
class FlatGeoBufDataTableTest {
@Test
- void rowType() throws IOException {
- var table =
- new
FlatGeoBufDataTable(TestFiles.resolve("baremaps-testing/data/samples/countries.fgb"));
- var rowType = table.rowType();
+ void schema() {
+ var file =
TestFiles.resolve("baremaps-testing/data/samples/countries.fgb");
+ var table = new FlatGeoBufDataTable(file);
+ var rowType = table.schema();
assertEquals(rowType.name(), null);
assertEquals(rowType.columns().size(), 2);
}
@Test
- void read() throws IOException {
- var table =
- new
FlatGeoBufDataTable(TestFiles.resolve("baremaps-testing/data/samples/countries.fgb"));
+ void read() {
+ var file =
TestFiles.resolve("baremaps-testing/data/samples/countries.fgb");
+ var table = new FlatGeoBufDataTable(file);
assertEquals(179, table.size());
assertEquals(179, table.stream().count());
}
@Test
- void write() throws IOException {
- var file = Files.createTempFile("countries", ".fgb");
- file.toFile().deleteOnExit();
- var table1 =
- new
FlatGeoBufDataTable(TestFiles.resolve("baremaps-testing/data/samples/countries.fgb"));
- var table2 = new FlatGeoBufDataTable(file, table1.rowType());
- table2.write(table1);
-
- var featureSet = new FlatGeoBufDataTable(file);
+ void readAndWrite() throws IOException {
+ var file =
TestFiles.resolve("baremaps-testing/data/samples/countries.fgb");
+ var tempFile = Files.createTempFile("countries", ".fgb");
+ tempFile.toFile().deleteOnExit();
+ var table = new FlatGeoBufDataTable(file);
+ var tempTable = new FlatGeoBufDataTable(tempFile, table.schema());
+ tempTable.write(table);
+ var featureSet = new FlatGeoBufDataTable(tempFile);
assertEquals(179, featureSet.stream().count());
}
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataSchemaTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStoreTest.java
similarity index 78%
rename from
baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataSchemaTest.java
rename to
baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStoreTest.java
index 8abcfe64..12785b83 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataSchemaTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStoreTest.java
@@ -22,22 +22,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.baremaps.testing.TestFiles;
import org.junit.jupiter.api.Test;
-class GeoPackageDataSchemaTest {
+class GeoPackageDataStoreTest {
@Test
- void rowType() {
- var geoPackageStore =
- new
GeoPackageDataSchema(TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg"));
+ void schema() {
+ var file =
TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg");
+ var geoPackageStore = new GeoPackageDataStore(file);
var table = geoPackageStore.get("countries");
- var rowType = table.rowType();
+ var rowType = table.schema();
assertEquals(rowType.name(), "countries");
assertEquals(rowType.columns().size(), 4);
}
@Test
void read() {
- var geoPackageStore =
- new
GeoPackageDataSchema(TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg"));
+ var file =
TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg");
+ var geoPackageStore = new GeoPackageDataStore(file);
var table = geoPackageStore.get("countries");
assertEquals(179, table.size());
assertEquals(179, table.stream().count());
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageToPostgresTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageToPostgresTest.java
index 2ba4f86d..3296be4d 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageToPostgresTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageToPostgresTest.java
@@ -20,7 +20,7 @@ package org.apache.baremaps.storage.geopackage;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.baremaps.database.PostgresContainerTest;
-import org.apache.baremaps.storage.postgres.PostgresDataSchema;
+import org.apache.baremaps.storage.postgres.PostgresDataStore;
import org.apache.baremaps.testing.TestFiles;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -29,20 +29,20 @@ public class GeoPackageToPostgresTest extends
PostgresContainerTest {
@Test
@Tag("integration")
- void schema() {
+ void copyGeoPackageToPostgres() {
// Open the GeoPackage
- var geoPackageSchema =
- new
GeoPackageDataSchema(TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg"));
+ var file =
TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg");
+ var geoPackageSchema = new GeoPackageDataStore(file);
var geoPackageTable = geoPackageSchema.get("countries");
// Copy the table to Postgres
- var postgresStore = new PostgresDataSchema(dataSource());
+ var postgresStore = new PostgresDataStore(dataSource());
postgresStore.add(geoPackageTable);
// Check the table in Postgres
var postgresTable = postgresStore.get("countries");
- assertEquals("countries", postgresTable.rowType().name());
- assertEquals(4, postgresTable.rowType().columns().size());
+ assertEquals("countries", postgresTable.schema().name());
+ assertEquals(4, postgresTable.schema().columns().size());
assertEquals(179l, postgresTable.size());
assertEquals(179l, postgresTable.stream().count());
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataSchemaTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataStoreTest.java
similarity index 87%
rename from
baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataSchemaTest.java
rename to
baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataStoreTest.java
index a364aeca..c599561b 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataSchemaTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataStoreTest.java
@@ -22,14 +22,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.baremaps.testing.TestFiles;
import org.junit.jupiter.api.Test;
-class GeoParquetDataSchemaTest {
+class GeoParquetDataStoreTest {
@Test
- void rowType() {
+ void schema() {
var uri =
TestFiles.resolve("baremaps-testing/data/samples/example.parquet").toUri();
- var geoParquetDataSchema = new GeoParquetDataSchema(uri);
+ var geoParquetDataSchema = new GeoParquetDataStore(uri);
var table = geoParquetDataSchema.get(uri.toString());
- var rowType = table.rowType();
+ var rowType = table.schema();
assertEquals(uri.toString(), rowType.name());
assertEquals(7, rowType.columns().size());
}
@@ -37,7 +37,7 @@ class GeoParquetDataSchemaTest {
@Test
void read() {
var uri =
TestFiles.resolve("baremaps-testing/data/samples/example.parquet").toUri();
- var geoParquetDataSchema = new GeoParquetDataSchema(uri);
+ var geoParquetDataSchema = new GeoParquetDataStore(uri);
var table = geoParquetDataSchema.get(uri.toString());
assertEquals(5, table.size());
assertEquals(5, table.stream().count());
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetToPostgresTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetToPostgresTest.java
index 6eeac236..198a63d2 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetToPostgresTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geoparquet/GeoParquetToPostgresTest.java
@@ -20,7 +20,7 @@ package org.apache.baremaps.storage.geoparquet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.baremaps.database.PostgresContainerTest;
-import org.apache.baremaps.storage.postgres.PostgresDataSchema;
+import org.apache.baremaps.storage.postgres.PostgresDataStore;
import org.apache.baremaps.testing.TestFiles;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -29,21 +29,21 @@ class GeoParquetToPostgresTest extends
PostgresContainerTest {
@Test
@Tag("integration")
- void schema() {
+ void copyGeoParquetToPostgres() {
// Open the GeoParquet
var uri =
TestFiles.resolve("baremaps-testing/data/samples/example.parquet").toUri();
- var geoParquetSchema = new GeoParquetDataSchema(uri);
+ var geoParquetSchema = new GeoParquetDataStore(uri);
var tables = geoParquetSchema.list();
var geoParquetTable = geoParquetSchema.get(tables.get(0));
// Copy the table to Postgres
- var postgresStore = new PostgresDataSchema(dataSource());
+ var postgresStore = new PostgresDataStore(dataSource());
postgresStore.add("geoparquet", geoParquetTable);
// Check the table in Postgres
var postgresTable = postgresStore.get("geoparquet");
- assertEquals("geoparquet", postgresTable.rowType().name());
- assertEquals(3, postgresTable.rowType().columns().size());
+ assertEquals("geoparquet", postgresTable.schema().name());
+ assertEquals(3, postgresTable.schema().columns().size());
assertEquals(5L, postgresTable.size());
assertEquals(5L, postgresTable.stream().count());
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataSchemaTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataStoreTest.java
similarity index 84%
rename from
baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataSchemaTest.java
rename to
baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataStoreTest.java
index 82b14ad3..d352332e 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataSchemaTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataStoreTest.java
@@ -19,20 +19,20 @@ package org.apache.baremaps.storage.postgres;
import static org.junit.jupiter.api.Assertions.*;
-import org.apache.baremaps.data.schema.DataTableException;
+import org.apache.baremaps.data.storage.DataStoreException;
import org.apache.baremaps.database.PostgresContainerTest;
import org.apache.baremaps.storage.MockDataTable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-class PostgresDataSchemaTest extends PostgresContainerTest {
+class PostgresDataStoreTest extends PostgresContainerTest {
- private PostgresDataSchema schema;
+ private PostgresDataStore schema;
@BeforeEach
void init() {
- schema = new PostgresDataSchema(dataSource());
+ schema = new PostgresDataStore(dataSource());
schema.add(new MockDataTable());
}
@@ -54,6 +54,6 @@ class PostgresDataSchemaTest extends PostgresContainerTest {
@Tag("integration")
void remove() {
schema.remove("mock");
- assertThrows(DataTableException.class, () -> schema.get("mock"));
+ assertThrows(DataStoreException.class, () -> schema.get("mock"));
}
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataTableTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataTableTest.java
index b58eaacf..c1a7a7be 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataTableTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataTableTest.java
@@ -21,7 +21,7 @@ import static
org.apache.baremaps.database.repository.Constants.GEOMETRY_FACTORY
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
-import org.apache.baremaps.data.schema.DataRowImpl;
+import org.apache.baremaps.data.storage.DataRowImpl;
import org.apache.baremaps.database.PostgresContainerTest;
import org.apache.baremaps.storage.MockDataTable;
import org.junit.jupiter.api.BeforeEach;
@@ -31,11 +31,11 @@ import org.locationtech.jts.geom.Coordinate;
class PostgresDataTableTest extends PostgresContainerTest {
- private PostgresDataSchema schema;
+ private PostgresDataStore schema;
@BeforeEach
void init() {
- schema = new PostgresDataSchema(dataSource());
+ schema = new PostgresDataStore(dataSource());
schema.add(new MockDataTable());
}
@@ -58,7 +58,7 @@ class PostgresDataTableTest extends PostgresContainerTest {
@Tag("integration")
void schema() {
var table = schema.get("mock");
- var rowType = table.rowType();
+ var rowType = table.schema();
assertNotNull(rowType);
assertEquals("mock", rowType.name());
assertEquals(5, rowType.columns().size());
@@ -68,7 +68,7 @@ class PostgresDataTableTest extends PostgresContainerTest {
@Tag("integration")
void add() {
var table = schema.get("mock");
- var rowType = table.rowType();
+ var rowType = table.schema();
var added = table.add(new DataRowImpl(rowType,
List.of("string", 6, 6.0, 6.0f, GEOMETRY_FACTORY.createPoint(new
Coordinate(6, 6)))));
assertTrue(added);
@@ -79,7 +79,7 @@ class PostgresDataTableTest extends PostgresContainerTest {
@Tag("integration")
void addAll() {
var table = schema.get("mock");
- var rowType = table.rowType();
+ var rowType = table.schema();
var added = table.addAll(List.of(
new DataRowImpl(rowType,
List.of("string", 6, 6.0, 6.0f, GEOMETRY_FACTORY.createPoint(new
Coordinate(6, 6)))),
diff --git a/baremaps-data/README.md b/baremaps-data/README.md
new file mode 100644
index 00000000..031375c2
--- /dev/null
+++ b/baremaps-data/README.md
@@ -0,0 +1,66 @@
+# Data Module
+
+The data module contains classes and functions to load and process large data
sets.
+
+## On-heap, off-heap, and memory-mapped data
+
+The following packages are used to deal with large data sets:
+- `org.apache.baremaps.data.memory` contains utilities to deal with on-heap,
off-heap, and memory-mapped memories that excapes the garbage collector.
+- `org.apache.baremaps.data.type` contains classes to serialize and
deserialize data types in memories.
+- `org.apache.baremaps.data.collection` defines large collections backed by
memories that can hold more than `Integer.MAX_VALUE` elements.
+- `org.apache.baremaps.data.algorithm` contains algorithms to process large
collections.
+
+## Data Storage
+
+A common issue is to deal with large data sets whose structure is discovered
at runtime.
+The `org.apache.baremaps.data.storage` package contains classes to deal with
this kind of data.
+The following diagram describes the main interfaces and classes of this
package.
+
+```mermaid
+classDiagram
+ class DataColumn {
+ +String name()
+ +Type type()
+ }
+ class DataSchema {
+ +String name()
+ +List<DataColumn> columns()
+ +DataRow createRow()
+ }
+ class DataRow {
+ +DataSchema schema()
+ +List<?> values()
+ +Object get(String column)
+ +Object get(int index)
+ +void set(String column, Object value)
+ +void set(int index, Object value)
+ +DataRow with(String column, Object value)
+ +DataRow with(int index, Object value)
+ }
+ class DataTable {
+ +DataSchema schema()
+ +boolean add(DataRow row)
+ +void clear()
+ +long size()
+ +Iterator<DataRow> iterator()
+ }
+ class DataStore {
+ +List<String> list()
+ +DataTable get(String name)
+ +void add(DataTable table)
+ +void add(String name, DataTable table)
+ +void remove(String name)
+ }
+ DataStore --> DataTable : has
+ DataTable --> DataRow : has
+ DataTable --> DataSchema : follows
+ DataRow --> DataSchema : follows
+ DataSchema --> DataColumn : has
+```
+
+## Executing SQL queries in the JVM
+
+The `org.apache.baremaps.data.calcite` package contains classes to execute SQL
queries in the JVM.
+This is a work in progress that demonstrates how to use the spatial extension
of Apache Calcite in Apache Baremaps.
+The long term goal is to perform very fast data processing without the need of
a database.
+
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
index caafd45c..b2db254a 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
@@ -19,8 +19,8 @@ package org.apache.baremaps.data.calcite;
import org.apache.baremaps.data.collection.DataCollection;
import org.apache.baremaps.data.collection.DataCollectionMapper;
-import org.apache.baremaps.data.schema.DataColumn;
-import org.apache.baremaps.data.schema.DataTable;
+import org.apache.baremaps.data.storage.DataColumn;
+import org.apache.baremaps.data.storage.DataTable;
import org.apache.calcite.DataContext;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Linq4j;
@@ -59,7 +59,7 @@ public class SqlDataTable extends AbstractTable implements
ScannableTable {
private RelDataType createRowType(RelDataTypeFactory typeFactory) {
var rowType = new RelDataTypeFactory.Builder(typeFactory);
- for (DataColumn column : table.rowType().columns()) {
+ for (DataColumn column : table.schema().columns()) {
rowType.add(column.name(), SqlTypeConversion.types.get(column.type()));
}
return rowType.build();
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
index 755721b8..e0116e59 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
@@ -18,7 +18,7 @@
package org.apache.baremaps.data.calcite;
import java.util.EnumMap;
-import org.apache.baremaps.data.schema.DataColumn.Type;
+import org.apache.baremaps.data.storage.DataColumn.Type;
import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.sql.type.SqlTypeName;
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataSchema.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataSchema.java
deleted file mode 100644
index 4d9bf6dc..00000000
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataSchema.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.data.schema;
-
-import java.util.List;
-
-/**
- * A schema is a collection of tables.
- */
-public interface DataSchema {
-
- /**
- * Lists the names of the tables.
- *
- * @return the names of the tables
- */
- List<String> list() throws DataTableException;
-
- /**
- * Gets a table by its name.
- *
- * @param name the name of the table
- * @return the table
- */
- DataTable get(String name) throws DataTableException;
-
- /**
- * Adds a table to the schema.
- *
- * @param table the table
- */
- void add(DataTable table) throws DataTableException;
-
- /**
- * Adds a table to the schema.
- *
- * @param name the name of the table
- * @param table the table
- * @throws DataTableException if the table already exists
- */
- void add(String name, DataTable table) throws DataTableException;
-
- /**
- * Removes a table from the schema.
- *
- * @param name the name of the table
- */
- void remove(String name) throws DataTableException;
-
-}
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataColumn.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataColumn.java
similarity index 98%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataColumn.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataColumn.java
index aa157347..9c70bd34 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataColumn.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataColumn.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import java.net.Inet4Address;
import java.net.Inet6Address;
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataColumnImpl.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataColumnImpl.java
similarity index 95%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataColumnImpl.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataColumnImpl.java
index 13cccff1..400e6033 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataColumnImpl.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataColumnImpl.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
/**
* A column in a table.
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRow.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataRow.java
similarity index 92%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRow.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataRow.java
index 0cce0e41..25476c20 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRow.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataRow.java
@@ -15,21 +15,21 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import java.util.List;
/**
- * A row in a table.
+ * A row in a {@link DataTable}.
*/
public interface DataRow {
/**
- * Returns the type of the row.
+ * Returns the schema of the row.
*
- * @return the type of the row
+ * @return the schema of the row
*/
- DataRowType rowType();
+ DataSchema schema();
/**
* Returns the values of the columns in the row.
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowImpl.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataRowImpl.java
similarity index 85%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowImpl.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataRowImpl.java
index c45531a4..26b27f44 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowImpl.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataRowImpl.java
@@ -15,21 +15,21 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import java.util.List;
/**
* A row in a table.
*/
-public record DataRowImpl(DataRowType rowType, List values) implements DataRow
{
+public record DataRowImpl(DataSchema schema, List values) implements DataRow {
/**
* {@inheritDoc}
*/
@Override
public Object get(String column) {
- var columns = rowType.columns();
+ var columns = schema.columns();
for (int i = 0; i < columns.size(); i++) {
if (columns.get(i).name().equals(column)) {
return values.get(i);
@@ -51,8 +51,8 @@ public record DataRowImpl(DataRowType rowType, List values)
implements DataRow {
*/
@Override
public void set(String column, Object value) {
- for (int i = 0; i < rowType.columns().size(); i++) {
- if (rowType.columns().get(i).name().equals(column)) {
+ for (int i = 0; i < schema.columns().size(); i++) {
+ if (schema.columns().get(i).name().equals(column)) {
values.set(i, value);
return;
}
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowType.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchema.java
similarity index 71%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowType.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchema.java
index aa9ce058..0b915f88 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowType.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchema.java
@@ -15,33 +15,33 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import java.util.List;
/**
- * A row type defines the structure of a table.
+ * A {@link DataSchema} is a description of the structure of a row in a {@link
DataTable}.
*/
-public interface DataRowType {
+public interface DataSchema {
/**
- * Returns the name of the row type.
+ * Returns the name of the schema.
*
- * @return the name of the row type
+ * @return the name of the schema
*/
String name();
/**
- * Returns the columns of the row type.
+ * Returns the columns of the schema.
*
- * @return the columns of the row type
+ * @return the columns of the schema
*/
List<DataColumn> columns();
/**
- * Creates a new row of the row type.
+ * Creates a new row of the schema.
*
- * @return a new row of the row type
+ * @return a new row of the schema
*/
DataRow createRow();
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowTypeImpl.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchemaImpl.java
similarity index 79%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowTypeImpl.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchemaImpl.java
index 6ebfda5b..c9b20c7a 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowTypeImpl.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchemaImpl.java
@@ -15,27 +15,27 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import java.util.ArrayList;
import java.util.List;
/**
- * A row type defines the structure of a table.
+ * A {@link DataSchema} defines the structure of a table.
*/
-public class DataRowTypeImpl implements DataRowType {
+public class DataSchemaImpl implements DataSchema {
private final String name;
private final List<DataColumn> columns;
/**
- * Constructs a row type.
+ * Constructs a schema with the specified name and columns.
*
- * @param name the name of the row type
- * @param columns the columns of the row type
+ * @param name the name of the schema
+ * @param columns the columns of the schema
*/
- public DataRowTypeImpl(String name, List<DataColumn> columns) {
+ public DataSchemaImpl(String name, List<DataColumn> columns) {
this.name = name;
this.columns = columns;
}
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataStore.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataStore.java
new file mode 100644
index 00000000..9b8d4a7d
--- /dev/null
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataStore.java
@@ -0,0 +1,65 @@
+/*
+ * 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.data.storage;
+
+import java.util.List;
+
+/**
+ * A {@link DataStore} is a collection of {@link DataTable}s.
+ */
+public interface DataStore {
+
+ /**
+ * Lists the names of the data tables.
+ *
+ * @return the names of the data tables
+ */
+ List<String> list() throws DataStoreException;
+
+ /**
+ * Gets a data table by name.
+ *
+ * @param name the name of the data table
+ * @return the data table
+ */
+ DataTable get(String name) throws DataStoreException;
+
+ /**
+ * Adds a data table to the data store.
+ *
+ * @param table the data table
+ */
+ void add(DataTable table) throws DataStoreException;
+
+ /**
+ * Adds a data table to the data store.
+ *
+ * @param name the name of the data table
+ * @param table the data table
+ * @throws DataStoreException if the data table cannot be added
+ */
+ void add(String name, DataTable table) throws DataStoreException;
+
+ /**
+ * Removes a data table from the data store.
+ *
+ * @param name the name of the data table
+ */
+ void remove(String name) throws DataStoreException;
+
+}
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableException.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataStoreException.java
similarity index 62%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableException.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataStoreException.java
index cbd19009..62bc79df 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableException.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataStoreException.java
@@ -15,39 +15,39 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
-/** Signals that an exception occurred in a table. */
-public class DataTableException extends RuntimeException {
+/** Signals that an exception occurred in a {@link DataStore}. */
+public class DataStoreException extends RuntimeException {
- /** Constructs a {@link DataTableException} with {@code null} as its error
detail message. */
- public DataTableException() {}
+ /** Constructs a {@link DataStoreException} with {@code null} as its error
detail message. */
+ public DataStoreException() {}
/**
- * Constructs an {@code TableException} with the specified detail message.
+ * Constructs an {@link DataStoreException} with the specified detail
message.
*
* @param message the message
*/
- public DataTableException(String message) {
+ public DataStoreException(String message) {
super(message);
}
/**
- * Constructs a {@code TableException} with the specified cause.
+ * Constructs a {@link DataStoreException} with the specified cause.
*
* @param cause the cause
*/
- public DataTableException(Throwable cause) {
+ public DataStoreException(Throwable cause) {
super(cause);
}
/**
- * Constructs a {@code TableException} with the specified detail message and
cause.
+ * Constructs a {@link DataStoreException} with the specified detail message
and cause.
*
* @param message the message
* @param cause the cause
*/
- public DataTableException(String message, Throwable cause) {
+ public DataStoreException(String message, Throwable cause) {
super(message, cause);
}
}
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTable.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTable.java
similarity index 81%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTable.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTable.java
index e8789420..3a7760c4 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTable.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTable.java
@@ -15,20 +15,20 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import org.apache.baremaps.data.collection.DataCollection;
/**
- * A table is a collection of rows respecting a row type.
+ * A {@link DataTable} is a collection of rows respecting a {@link DataSchema}
.
*/
public interface DataTable extends DataCollection<DataRow> {
/**
- * Returns the type of the row.
+ * Returns the schema of the row.
*
- * @return the type of the row
+ * @return the schema of the row
*/
- DataRowType rowType();
+ DataSchema schema();
}
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableGeometryTransformer.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableGeometryMapper.java
similarity index 67%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableGeometryTransformer.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableGeometryMapper.java
index 0f2db39f..09110fcf 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableGeometryTransformer.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableGeometryMapper.java
@@ -15,31 +15,30 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import java.util.function.Function;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.util.GeometryTransformer;
/**
- * A transformer that applies a {@code GeometryTransformer} to the geometries
of a
- * {@code DataTable}.
+ * A decorator for a {@link DataTable} that applies a geometry transformation
to each row.
*/
-public class DataTableGeometryTransformer implements Function<DataRow,
DataRow> {
+public class DataTableGeometryMapper implements Function<DataRow, DataRow> {
private final DataTable table;
- private final GeometryTransformer geometryTransformer;
+ private final GeometryTransformer mapper;
/**
- * Constructs a new table transformer.
+ * Constructs a new data table transformer with the specified data table and
geometry transformer.
*
- * @param table the table to transform
- * @param geometryTransformer the geometry transformer
+ * @param table the data table to transform
+ * @param mapper the geometry mapper
*/
- public DataTableGeometryTransformer(DataTable table, GeometryTransformer
geometryTransformer) {
+ public DataTableGeometryMapper(DataTable table, GeometryTransformer mapper) {
this.table = table;
- this.geometryTransformer = geometryTransformer;
+ this.mapper = mapper;
}
/**
@@ -47,7 +46,7 @@ public class DataTableGeometryTransformer implements
Function<DataRow, DataRow>
*/
@Override
public DataRow apply(DataRow row) {
- var columns = table.rowType()
+ var columns = table.schema()
.columns().stream()
.filter(column ->
column.type().binding().isAssignableFrom(Geometry.class))
.toList();
@@ -55,7 +54,7 @@ public class DataTableGeometryTransformer implements
Function<DataRow, DataRow>
var name = column.name();
var geometry = (Geometry) row.get(name);
if (geometry != null) {
- row.set(name, geometryTransformer.transform(geometry));
+ row.set(name, mapper.transform(geometry));
}
}
return row;
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableImpl.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableImpl.java
similarity index 73%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableImpl.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableImpl.java
index 72fc83fb..6bc9d815 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableImpl.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableImpl.java
@@ -15,28 +15,28 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import java.util.Iterator;
import org.apache.baremaps.data.collection.DataCollection;
/**
- * A table is a collection of rows respecting a row type.
+ * A {@link DataTable} is a collection of rows respecting a {@link DataSchema}.
*/
public class DataTableImpl implements DataTable {
- private final DataRowType rowType;
+ private final DataSchema schema;
private final DataCollection<DataRow> rows;
/**
- * Constructs a table with the specified row type.
+ * Constructs a {@link DataTable} with the specified row {@link DataSchema}.
*
- * @param rowType the row type of the table
- * @param rows the collection of rows
+ * @param schema the schema of the rows
+ * @param rows the rows
*/
- public DataTableImpl(DataRowType rowType, DataCollection<DataRow> rows) {
- this.rowType = rowType;
+ public DataTableImpl(DataSchema schema, DataCollection<DataRow> rows) {
+ this.schema = schema;
this.rows = rows;
}
@@ -44,16 +44,16 @@ public class DataTableImpl implements DataTable {
* {@inheritDoc}
*/
@Override
- public DataRowType rowType() {
- return rowType;
+ public DataSchema schema() {
+ return schema;
}
/**
* {@inheritDoc}
*/
@Override
- public boolean add(DataRow e) {
- return rows.add(e);
+ public boolean add(DataRow row) {
+ return rows.add(row);
}
/**
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableMapper.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableMapper.java
similarity index 81%
rename from
baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableMapper.java
rename to
baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableMapper.java
index 9f7b746c..e496060b 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableMapper.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataTableMapper.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.schema;
+package org.apache.baremaps.data.storage;
import java.util.Iterator;
import java.util.function.Function;
/**
- * A decorator for a table that transforms the geometries of the rows.
+ * A decorator for a {@link DataTable} that applies a transformation to each
row.
*/
public class DataTableMapper implements DataTable {
@@ -31,10 +31,10 @@ public class DataTableMapper implements DataTable {
private final Function<DataRow, DataRow> transformer;
/**
- * Constructs a new table decorator.
+ * Constructs a new {@link DataTableMapper} with the specified table and row
transformer.
*
- * @param table the table to decorate
- * @param mapper the row transformer
+ * @param table the table
+ * @param mapper the mapper
*/
public DataTableMapper(DataTable table, Function<DataRow, DataRow> mapper) {
this.table = table;
@@ -45,8 +45,8 @@ public class DataTableMapper implements DataTable {
* {@inheritDoc}
*/
@Override
- public DataRowType rowType() {
- return table.rowType();
+ public DataSchema schema() {
+ return table.schema();
}
@Override
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/type/RowDataType.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/type/RowDataType.java
index 0474432f..1236e530 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/type/RowDataType.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/type/RowDataType.java
@@ -20,11 +20,11 @@ package org.apache.baremaps.data.type;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.EnumMap;
-import org.apache.baremaps.data.schema.DataColumn;
-import org.apache.baremaps.data.schema.DataColumn.Type;
-import org.apache.baremaps.data.schema.DataRow;
-import org.apache.baremaps.data.schema.DataRowImpl;
-import org.apache.baremaps.data.schema.DataRowType;
+import org.apache.baremaps.data.storage.DataColumn;
+import org.apache.baremaps.data.storage.DataColumn.Type;
+import org.apache.baremaps.data.storage.DataRow;
+import org.apache.baremaps.data.storage.DataRowImpl;
+import org.apache.baremaps.data.storage.DataSchema;
/**
* A data type for rows.
@@ -53,9 +53,9 @@ public class RowDataType implements DataType<DataRow> {
types.put(Type.COORDINATE, new CoordinateDataType());
}
- private final DataRowType rowType;
+ private final DataSchema rowType;
- public RowDataType(DataRowType rowType) {
+ public RowDataType(DataSchema rowType) {
this.rowType = rowType;
}
diff --git
a/baremaps-data/src/test/java/org/apache/baremaps/data/type/DataTypeProvider.java
b/baremaps-data/src/test/java/org/apache/baremaps/data/type/DataTypeProvider.java
index 0f202f1e..0b2f98cf 100644
---
a/baremaps-data/src/test/java/org/apache/baremaps/data/type/DataTypeProvider.java
+++
b/baremaps-data/src/test/java/org/apache/baremaps/data/type/DataTypeProvider.java
@@ -21,10 +21,10 @@ package org.apache.baremaps.data.type;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
-import org.apache.baremaps.data.schema.*;
-import org.apache.baremaps.data.schema.DataColumn.Type;
-import org.apache.baremaps.data.schema.DataRowType;
-import org.apache.baremaps.data.schema.DataRowTypeImpl;
+import org.apache.baremaps.data.storage.*;
+import org.apache.baremaps.data.storage.DataColumn.Type;
+import org.apache.baremaps.data.storage.DataSchema;
+import org.apache.baremaps.data.storage.DataSchemaImpl;
import org.junit.jupiter.params.provider.Arguments;
import org.locationtech.jts.geom.*;
@@ -32,7 +32,7 @@ public class DataTypeProvider {
private static final GeometryFactory geometryFactory = new GeometryFactory();
- private static final DataRowType DATA_SCHEMA = new DataRowTypeImpl("row",
List.of(
+ private static final DataSchema DATA_SCHEMA = new DataSchemaImpl("row",
List.of(
new DataColumnImpl("byte", Type.BYTE),
new DataColumnImpl("boolean", Type.BOOLEAN),
new DataColumnImpl("short", Type.SHORT),