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/FlatGeoBufDataFrame.java similarity index 94% rename from baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTable.java rename to baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataFrame.java index d84b345aa..c8e9157ec 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/FlatGeoBufDataFrame.java @@ -27,9 +27,9 @@ import java.util.Iterator; import java.util.NoSuchElementException; import org.apache.baremaps.data.collection.DataCollection; +import org.apache.baremaps.data.schema.DataFrame; 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.DataSchema; import org.locationtech.jts.geom.*; import org.wololo.flatgeobuf.Constants; import org.wololo.flatgeobuf.GeometryConversions; @@ -41,18 +41,18 @@ /** * A table that stores rows in a flatgeobuf file. */ -public class FlatGeoBufDataTable implements DataTable { +public class FlatGeoBufDataFrame implements DataFrame { private final Path file; - private DataRowType rowType; + private DataSchema rowType; /** * Constructs a table from a flatgeobuf file (used for reading). * * @param file the path to the flatgeobuf file */ - public FlatGeoBufDataTable(Path file) { + public FlatGeoBufDataFrame(Path file) { this.file = file; this.rowType = readRowType(file); } @@ -63,7 +63,7 @@ public FlatGeoBufDataTable(Path file) { * @param file the path to the flatgeobuf file * @param rowType the row type of the table */ - public FlatGeoBufDataTable(Path file, DataRowType rowType) { + public FlatGeoBufDataFrame(Path file, DataSchema rowType) { this.file = file; this.rowType = rowType; } @@ -72,14 +72,14 @@ public FlatGeoBufDataTable(Path file, DataRowType rowType) { * {@inheritDoc} */ @Override - public DataRowType rowType() { + public DataSchema schema() { return rowType; } /** * {@inheritDoc} */ - public static DataRowType readRowType(Path file) { + public static DataSchema 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); @@ -235,7 +235,7 @@ public static class RowIterator implements Iterator { private final HeaderMeta headerMeta; - private final DataRowType rowType; + private final DataSchema rowType; private final SeekableByteChannel channel; @@ -252,7 +252,7 @@ public static class RowIterator implements Iterator { * @param buffer the buffer to use */ public RowIterator(SeekableByteChannel channel, HeaderMeta headerMeta, - DataRowType rowType, ByteBuffer buffer) { + DataSchema rowType, ByteBuffer buffer) { this.channel = channel; this.headerMeta = headerMeta; this.rowType = rowType; 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 6b2d4ba86..40aacd4e7 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.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.schema.DataFrame; +import org.apache.baremaps.data.schema.DataStore; +import org.apache.baremaps.data.schema.DataStoreException; /** * A schema 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 FlatGeoBufDataSchema(Path directory) { * {@inheritDoc} */ @Override - public List list() throws DataTableException { + public List 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,31 +55,31 @@ public List list() throws DataTableException { * {@inheritDoc} */ @Override - public DataTable get(String name) throws DataTableException { + public DataFrame get(String name) throws DataStoreException { var path = directory.resolve(name); - return new FlatGeoBufDataTable(path); + return new FlatGeoBufDataFrame(path); } /** * {@inheritDoc} */ @Override - public void add(DataTable table) throws DataTableException { - var filename = table.rowType().name(); + public void add(DataFrame frame) throws DataStoreException { + var filename = frame.schema().name(); filename = filename.endsWith(".fgb") ? filename : filename + ".fgb"; - add(filename, table); + add(filename, frame); } @Override - public void add(String name, DataTable table) throws DataTableException { + public void add(String name, DataFrame frame) throws DataStoreException { var path = directory.resolve(name); try { Files.deleteIfExists(path); Files.createFile(path); - var flatGeoBufTable = new FlatGeoBufDataTable(path, table.rowType()); - flatGeoBufTable.write(table); + var flatGeoBufTable = new FlatGeoBufDataFrame(path, frame.schema()); + flatGeoBufTable.write(frame); } catch (IOException e) { - throw new DataTableException(e); + throw new DataStoreException(e); } } @@ -87,16 +87,16 @@ public void add(String name, DataTable table) throws DataTableException { * {@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/FlatGeoBufTypeConversion.java b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java index 68208da0a..aa5a8e474 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 @@ -50,16 +50,16 @@ public class FlatGeoBufTypeConversion { types.put(Type.STRING, ColumnType.String); } - public static DataRowType asRowType(HeaderMeta headerMeta) { + public static DataSchema asRowType(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/GeoPackageDataTable.java b/baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataFrame.java similarity index 96% rename from baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataTable.java rename to baremaps-core/src/main/java/org/apache/baremaps/storage/geopackage/GeoPackageDataFrame.java index 57b7f8a58..dcb5b6318 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/GeoPackageDataFrame.java @@ -30,11 +30,11 @@ /** * A table that stores rows in a GeoPackage table. */ -public class GeoPackageDataTable implements DataTable { +public class GeoPackageDataFrame implements DataFrame { private final FeatureDao featureDao; - private final DataRowType rowType; + private final DataSchema rowType; private final GeometryFactory geometryFactory; @@ -43,7 +43,7 @@ public class GeoPackageDataTable implements DataTable { * * @param featureDao the feature DAO */ - public GeoPackageDataTable(FeatureDao featureDao) { + public GeoPackageDataFrame(FeatureDao featureDao) { this.featureDao = featureDao; var name = featureDao.getTableName(); var columns = new ArrayList(); @@ -52,7 +52,7 @@ public GeoPackageDataTable(FeatureDao featureDao) { var propertyType = classType(column); columns.add(new DataColumnImpl(propertyName, propertyType)); } - rowType = new DataRowTypeImpl(name, columns); + rowType = new DataSchemaImpl(name, columns); geometryFactory = new GeometryFactory(new PrecisionModel(), (int) featureDao.getSrs().getId()); } @@ -92,7 +92,7 @@ public long size() { * {@inheritDoc} */ @Override - public DataRowType rowType() { + public DataSchema schema() { return rowType; } @@ -230,7 +230,7 @@ public class GeopackageIterator implements Iterator { private final FeatureResultSet featureResultSet; - private final DataRowType rowType; + private final DataSchema rowType; private boolean hasNext; @@ -240,7 +240,7 @@ public class GeopackageIterator implements Iterator { * @param featureResultSet the feature result set * @param rowType the row type of the table */ - public GeopackageIterator(FeatureResultSet featureResultSet, DataRowType rowType) { + public GeopackageIterator(FeatureResultSet featureResultSet, DataSchema rowType) { this.featureResultSet = featureResultSet; this.rowType = rowType; this.hasNext = featureResultSet.moveToFirst(); 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 73% 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 7a8f42ec4..7425f96e9 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,14 +22,14 @@ 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.schema.DataFrame; +import org.apache.baremaps.data.schema.DataStore; +import org.apache.baremaps.data.schema.DataStoreException; /** * A schema corresponding to a GeoPackage database. */ -public class GeoPackageDataSchema implements DataSchema, AutoCloseable { +public class GeoPackageDataStore implements DataStore, AutoCloseable { private final GeoPackage geoPackage; @@ -38,7 +38,7 @@ public class GeoPackageDataSchema implements DataSchema, AutoCloseable { * * @param file the path to the GeoPackage database */ - public GeoPackageDataSchema(Path file) { + public GeoPackageDataStore(Path file) { this.geoPackage = GeoPackageManager.open(file.toFile()); } @@ -54,7 +54,7 @@ public void close() throws Exception { * {@inheritDoc} */ @Override - public List list() throws DataTableException { + public List list() throws DataStoreException { return geoPackage.getFeatureTables(); } @@ -62,20 +62,20 @@ public List list() throws DataTableException { * {@inheritDoc} */ @Override - public DataTable get(String name) throws DataTableException { - return new GeoPackageDataTable(geoPackage.getFeatureDao(name)); + public DataFrame get(String name) throws DataStoreException { + return new GeoPackageDataFrame(geoPackage.getFeatureDao(name)); } /** * {@inheritDoc} */ @Override - public void add(DataTable table) throws DataTableException { + public void add(DataFrame frame) throws DataStoreException { throw new UnsupportedOperationException(); } @Override - public void add(String name, DataTable table) throws DataTableException { + public void add(String name, DataFrame frame) throws DataStoreException { throw new UnsupportedOperationException(); } @@ -83,7 +83,7 @@ public void add(String name, DataTable table) throws DataTableException { * {@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/geoparquet/GeoParquetDataTable.java b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataFrame.java similarity index 94% rename from baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java rename to baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataFrame.java index 5fbd4b9dc..411d05bc9 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/GeoParquetDataFrame.java @@ -28,15 +28,15 @@ import org.apache.baremaps.geoparquet.GeoParquetReader; import org.apache.baremaps.geoparquet.data.GeoParquetGroup.Schema; -public class GeoParquetDataTable implements DataTable { +public class GeoParquetDataFrame implements DataFrame { private final URI path; - private DataRowType rowType; + private DataSchema rowType; private GeoParquetReader reader; - public GeoParquetDataTable(URI path) { + public GeoParquetDataFrame(URI path) { this.path = path; } @@ -94,7 +94,7 @@ public void clear() { } @Override - public DataRowType rowType() { + public DataSchema schema() { if (rowType == null) { try { Schema schema = reader().getGeoParquetSchema(); 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 66% 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 2fbecbea6..6fb7b1c7f 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 @@ 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.schema.DataFrame; +import org.apache.baremaps.data.schema.DataStore; +import org.apache.baremaps.data.schema.DataStoreException; /** * A schema corresponding to a GeoParquet database. */ -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 list() throws DataTableException { + public List list() throws DataStoreException { return List.of(uri.toString()); } @Override - public DataTable get(String name) throws DataTableException { + public DataFrame 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); + return new GeoParquetDataFrame(uri); } @Override - public void add(DataTable table) throws DataTableException { + public void add(DataFrame frame) throws DataStoreException { throw new UnsupportedOperationException(); } @Override - public void add(String name, DataTable table) throws DataTableException { + public void add(String name, DataFrame frame) 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/GeoParquetTypeConversion.java b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetTypeConversion.java index d0f2f2b90..f77cf09f3 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 @@ -22,8 +22,8 @@ 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.schema.DataSchema; +import org.apache.baremaps.data.schema.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,11 +32,11 @@ public class GeoParquetTypeConversion { private GeoParquetTypeConversion() {} - public static DataRowType asDataRowType(String table, Schema schema) { + public static DataSchema asDataRowType(String table, Schema schema) { List fields = schema.fields().stream() .map(field -> (DataColumn) new DataColumnImpl(field.name(), asDataRowType(field.type()))) .toList(); - return new DataRowTypeImpl(table, fields); + return new DataSchemaImpl(table, fields); } public static Type asDataRowType(GeoParquetGroup.Type type) { 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/PostgresDataFrame.java similarity index 94% rename from baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataTable.java rename to baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataFrame.java index def245479..9cffced77 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/PostgresDataFrame.java @@ -23,21 +23,21 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; import javax.sql.DataSource; +import org.apache.baremaps.data.schema.DataFrame; 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.schema.DataSchema; import org.apache.baremaps.openstreetmap.utils.GeometryUtils; import org.locationtech.jts.geom.*; /** * A table that stores rows in a Postgres table. */ -public class PostgresDataTable implements DataTable { +public class PostgresDataFrame implements DataFrame { private final DataSource dataSource; - private final DataRowType rowType; + private final DataSchema rowType; /** * Constructs a table with a given name and a given row type. @@ -45,7 +45,7 @@ public class PostgresDataTable implements DataTable { * @param dataSource the data source * @param rowType the rowType of the table */ - public PostgresDataTable(DataSource dataSource, DataRowType rowType) { + public PostgresDataFrame(DataSource dataSource, DataSchema rowType) { this.dataSource = dataSource; this.rowType = rowType; } @@ -89,7 +89,7 @@ public long size() { * {@inheritDoc} */ @Override - public DataRowType rowType() { + public DataSchema schema() { return rowType; } @@ -158,7 +158,7 @@ private void setParameters(PreparedStatement statement, DataRow row) throws SQLE * @param rowType the row type of the table * @return the query */ - protected static String select(DataRowType rowType) { + protected static String select(DataSchema rowType) { var columns = rowType.columns().stream() .map(column -> { if (column.type().binding().isAssignableFrom(Geometry.class)) { @@ -177,7 +177,7 @@ protected static String select(DataRowType rowType) { * @param rowType the row type of the table * @return the query */ - protected static String insert(DataRowType rowType) { + protected static String insert(DataSchema rowType) { var columns = rowType.columns().stream() .map(column -> String.format("\"%s\"", column.name())) .toList(); @@ -195,7 +195,7 @@ protected static String insert(DataRowType rowType) { * @param rowType the row type of the table * @return the query */ - protected String count(DataRowType rowType) { + protected String count(DataSchema rowType) { return String.format("SELECT COUNT(*) FROM \"%s\"", rowType.name()); } 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 87% 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 99e3f179d..34fa4cc49 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 @@ -39,10 +39,10 @@ /** * A schema that stores tables in 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"}; @@ -53,7 +53,7 @@ public class PostgresDataSchema implements DataSchema { * * @param dataSource the data source */ - public PostgresDataSchema(DataSource dataSource) { + public PostgresDataStore(DataSource dataSource) { this.dataSource = dataSource; } @@ -61,7 +61,7 @@ public PostgresDataSchema(DataSource dataSource) { * {@inheritDoc} */ @Override - public List list() throws DataTableException { + public List list() throws DataStoreException { DatabaseMetadata metadata = new DatabaseMetadata(dataSource); return metadata.getTableMetaData(null, "public", null, TYPES).stream() .map(table -> table.table().tableName()) @@ -72,36 +72,36 @@ public List list() throws DataTableException { * {@inheritDoc} */ @Override - public DataTable get(String name) throws DataTableException { + public DataFrame 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); + return new PostgresDataFrame(dataSource, rowType); } /** * {@inheritDoc} */ @Override - public void add(DataTable table) { - var name = table.rowType().name().replaceAll(REGEX, "_").toLowerCase(); - add(name, table); + public void add(DataFrame frame) { + var name = frame.schema().name().replaceAll(REGEX, "_").toLowerCase(); + add(name, frame); } /** * {@inheritDoc} */ @Override - public void add(String name, DataTable table) { + public void add(String name, DataFrame frame) { try (var connection = dataSource.getConnection()) { var mapping = new HashMap(); var properties = new ArrayList(); - for (DataColumn column : table.rowType().columns()) { + for (DataColumn column : frame.schema().columns()) { if (PostgresTypeConversion.typeToName.containsKey(column.type())) { var columnName = column.name().replaceAll(REGEX, "_").toLowerCase(); mapping.put(columnName, column.name()); @@ -109,7 +109,7 @@ public void add(String name, DataTable table) { } } - var rowType = new DataRowTypeImpl(name, properties); + var rowType = new DataSchemaImpl(name, properties); // Drop the table if it exists var dropQuery = dropTable(rowType); @@ -133,7 +133,7 @@ public void add(String name, DataTable table) { writer.writeHeader(); var columns = getColumns(rowType); var handlers = getHandlers(rowType); - for (DataRow row : table) { + for (DataRow row : frame) { writer.startRow(columns.size()); for (int i = 0; i < columns.size(); i++) { var targetColumn = columns.get(i).name(); @@ -158,7 +158,7 @@ public void add(String name, DataTable table) { */ @Override public void remove(String name) { - var rowType = get(name).rowType(); + var rowType = get(name).schema(); try (var connection = dataSource.getConnection(); var statement = connection.prepareStatement(dropTable(rowType))) { statement.execute(); @@ -173,14 +173,14 @@ public void remove(String name) { * @param tableMetadata the table metadata * @return the rowType */ - protected static DataRowType createRowType(TableMetadata tableMetadata) { + protected static DataSchema createRowType(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); } /** @@ -189,7 +189,7 @@ protected static DataRowType createRowType(TableMetadata tableMetadata) { * @param rowType the table name * @return the query */ - protected String dropTable(DataRowType rowType) { + protected String dropTable(DataSchema rowType) { return String.format("DROP TABLE IF EXISTS \"%s\" CASCADE", rowType.name()); } @@ -199,7 +199,7 @@ protected String dropTable(DataRowType rowType) { * @param rowType the row type * @return the query */ - protected String createTable(DataRowType rowType) { + protected String createTable(DataSchema rowType) { StringBuilder builder = new StringBuilder(); builder.append("CREATE TABLE \""); builder.append(rowType.name()); @@ -218,7 +218,7 @@ protected String createTable(DataRowType rowType) { * @param rowType the row type * @return the query */ - protected String copy(DataRowType rowType) { + protected String copy(DataSchema rowType) { var builder = new StringBuilder(); builder.append("COPY \""); builder.append(rowType.name()); @@ -236,7 +236,7 @@ protected String copy(DataRowType rowType) { * @param rowType the row type * @return the columns */ - protected List getColumns(DataRowType rowType) { + protected List getColumns(DataSchema rowType) { return rowType.columns().stream() .filter(this::isSupported) .collect(Collectors.toList()); @@ -248,7 +248,7 @@ protected List getColumns(DataRowType rowType) { * @param rowType the row type * @return the handlers */ - protected List getHandlers(DataRowType rowType) { + protected List getHandlers(DataSchema rowType) { return getColumns(rowType).stream() .map(column -> getHandler(column.type())) .collect(Collectors.toList()); 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/ShapefileDataFrame.java similarity index 89% rename from baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java rename to baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataFrame.java index 7d89d0074..dc51917fd 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/ShapefileDataFrame.java @@ -22,10 +22,10 @@ import java.nio.file.Path; import java.util.Iterator; import java.util.NoSuchElementException; +import org.apache.baremaps.data.schema.DataFrame; 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.schema.DataSchema; +import org.apache.baremaps.data.schema.DataStoreException; import org.apache.baremaps.storage.shapefile.internal.ShapefileInputStream; import org.apache.baremaps.storage.shapefile.internal.ShapefileReader; import org.slf4j.Logger; @@ -34,9 +34,9 @@ /** * A table that stores rows in a shapefile. */ -public class ShapefileDataTable implements DataTable { +public class ShapefileDataFrame implements DataFrame { - private static final Logger logger = LoggerFactory.getLogger(ShapefileDataTable.class); + private static final Logger logger = LoggerFactory.getLogger(ShapefileDataFrame.class); private final ShapefileReader shapeFile; @@ -45,7 +45,7 @@ public class ShapefileDataTable implements DataTable { * * @param file the path to the shapefile */ - public ShapefileDataTable(Path file) { + public ShapefileDataFrame(Path file) { this.shapeFile = new ShapefileReader(file.toString()); } @@ -53,11 +53,11 @@ public ShapefileDataTable(Path file) { * {@inheritDoc} */ @Override - public DataRowType rowType() throws DataTableException { + public DataSchema schema() throws DataStoreException { try (var input = shapeFile.read()) { return input.rowType(); } catch (IOException e) { - throw new DataTableException(e); + throw new DataStoreException(e); } } 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 78% 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 77a8102f5..e4d2d8afa 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.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.schema.DataFrame; +import org.apache.baremaps.data.schema.DataStore; +import org.apache.baremaps.data.schema.DataStoreException; /** * 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 List list() { .map(file -> file.getFileName().toString()) .toList(); } catch (IOException e) { - throw new DataTableException(e); + throw new DataStoreException(e); } } @@ -62,20 +62,20 @@ public List list() { * {@inheritDoc} */ @Override - public DataTable get(String name) { - return new ShapefileDataTable(directory.resolve(name)); + public DataFrame get(String name) { + return new ShapefileDataFrame(directory.resolve(name)); } /** * {@inheritDoc} */ @Override - public void add(DataTable table) { + public void add(DataFrame frame) { throw new UnsupportedOperationException(); } @Override - public void add(String name, DataTable table) throws DataTableException { + public void add(String name, DataFrame frame) throws DataStoreException { throw new UnsupportedOperationException(); } 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 c71a5d74b..88deae2e2 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 @@ -51,7 +51,7 @@ public class ShapefileByteReader extends CommonByteReader { private List databaseFieldsDescriptors; /** Schema of the rows contained in this shapefile. */ - private DataRowType rowType; + private DataSchema rowType; /** Shapefile index. */ private File shapeFileIndex; @@ -112,7 +112,7 @@ public ShapefileDescriptor getShapefileDescriptor() { * * @return the row type */ - public DataRowType getRowType() { + public DataSchema getRowType() { return this.rowType; } @@ -122,7 +122,7 @@ public DataRowType getRowType() { * @param name Name of the field. * @return The row type. */ - 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(); @@ -154,7 +154,7 @@ private DataRowType getSchema(final String name) { // Add geometry column. columns.add(new DataColumnImpl(GEOMETRY_NAME, Type.GEOMETRY)); - return new DataRowTypeImpl(name, columns); + return new DataSchemaImpl(name, columns); } /** Load shapefile descriptor. */ 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 655a2ce67..6aecb5a74 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 @@ -24,7 +24,7 @@ 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.schema.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 rowType; /** Shapefile reader. */ private ShapefileByteReader shapefileReader; @@ -134,7 +134,7 @@ public DataRow readRow() throws ShapefileException { * * @return the row type. */ - public DataRowType rowType() { + public DataSchema rowType() { return rowType; } 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 63e98ddeb..b95debf36 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.IOException; import java.util.List; import java.util.Objects; -import org.apache.baremaps.data.schema.DataRowType; +import org.apache.baremaps.data.schema.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 rowType; /** Shapefile descriptor. */ private ShapefileDescriptor shapefileDescriptor; @@ -122,7 +122,7 @@ public ShapefileReader(String shpfile, String dbasefile, String shpfileIndex) { * * @return the row type. */ - public DataRowType rowType() { + public DataSchema rowType() { return this.rowType; } 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 e0b80d98f..476adb4dc 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 @@ 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.schema.DataFrameGeometryMapper; +import org.apache.baremaps.data.schema.DataFrameMapper; 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,16 +70,16 @@ public ImportGeoPackage(Path file, Integer fileSrid, Object database, Integer da @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 DataFrameGeometryMapper(geoPackageTable, projectionTransformer); var transformedDataTable = - new DataTableMapper(geoPackageDataStore.get(name), rowTransformer); + new DataFrameMapper(geoPackageDataStore.get(name), rowTransformer); postgresDataStore.add(transformedDataTable); } } catch (Exception e) { 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 e671d3dca..38e58fcb5 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,11 +19,11 @@ 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.schema.DataFrameGeometryMapper; +import org.apache.baremaps.data.schema.DataFrameMapper; import org.apache.baremaps.openstreetmap.function.ProjectionTransformer; -import org.apache.baremaps.storage.postgres.PostgresDataSchema; -import org.apache.baremaps.storage.shapefile.ShapefileDataTable; +import org.apache.baremaps.storage.postgres.PostgresDataStore; +import org.apache.baremaps.storage.shapefile.ShapefileDataFrame; import org.apache.baremaps.workflow.Task; import org.apache.baremaps.workflow.WorkflowContext; import org.apache.baremaps.workflow.WorkflowException; @@ -71,12 +71,12 @@ public ImportShapefile(Path file, Integer fileSrid, Object database, Integer dat public void execute(WorkflowContext context) throws Exception { var path = file.toAbsolutePath(); try { - var shapefileDataTable = new ShapefileDataTable(path); + var shapefileDataTable = new ShapefileDataFrame(path); var dataSource = context.getDataSource(database); - var postgresDataStore = new PostgresDataSchema(dataSource); - var rowTransformer = new DataTableGeometryTransformer(shapefileDataTable, + var postgresDataStore = new PostgresDataStore(dataSource); + var rowTransformer = new DataFrameGeometryMapper(shapefileDataTable, new ProjectionTransformer(fileSrid, databaseSrid)); - var transformedDataTable = new DataTableMapper(shapefileDataTable, rowTransformer); + var transformedDataTable = new DataFrameMapper(shapefileDataTable, rowTransformer); postgresDataStore.add(transformedDataTable); } catch (Exception e) { throw new WorkflowException(e); 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 74f298a65..5a8123983 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 @@ -73,32 +73,32 @@ public void test() throws SQLException { 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( + DataFrame cityDataFrame = new DataFrameImpl( cityRowType, new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType)))); - cityDataTable.add(new DataRowImpl(cityDataTable.rowType(), + cityDataFrame.add(new DataRowImpl(cityDataFrame.schema(), List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566))))); - cityDataTable.add(new DataRowImpl(cityDataTable.rowType(), + cityDataFrame.add(new DataRowImpl(cityDataFrame.schema(), List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128))))); - SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable); + SqlDataTable citySqlDataTable = new SqlDataTable(cityDataFrame); 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( + DataFrame populationDataFrame = new DataFrameImpl( populationRowType, new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(populationRowType)))); - populationDataTable - .add(new DataRowImpl(populationDataTable.rowType(), List.of(1, 2_161_000))); - populationDataTable - .add(new DataRowImpl(populationDataTable.rowType(), List.of(2, 8_336_000))); - SqlDataTable populationSqlDataTable = new SqlDataTable(populationDataTable); + populationDataFrame + .add(new DataRowImpl(populationDataFrame.schema(), List.of(1, 2_161_000))); + populationDataFrame + .add(new DataRowImpl(populationDataFrame.schema(), List.of(2, 8_336_000))); + SqlDataTable populationSqlDataTable = new SqlDataTable(populationDataFrame); rootSchema.add("population", populationSqlDataTable); // Query the database diff --git a/baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataTable.java b/baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataFrame.java similarity index 92% rename from baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataTable.java rename to baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataFrame.java index 77d11c40a..02c49cc55 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataTable.java +++ b/baremaps-core/src/test/java/org/apache/baremaps/storage/MockDataFrame.java @@ -25,14 +25,14 @@ import org.apache.baremaps.data.schema.DataColumn.Type; import org.locationtech.jts.geom.Coordinate; -public class MockDataTable implements DataTable { +public class MockDataFrame implements DataFrame { - private final DataRowType rowType; + private final DataSchema rowType; private final List rows; - public MockDataTable() { - this.rowType = new DataRowTypeImpl("mock", List.of( + public MockDataFrame() { + 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 void clear() { } @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/FlatGeoBufDataFrameTest.java similarity index 81% rename from baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java rename to baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataFrameTest.java index c48abdb56..d0a83cc2f 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/FlatGeoBufDataFrameTest.java @@ -24,13 +24,13 @@ import org.apache.baremaps.testing.TestFiles; import org.junit.jupiter.api.Test; -class FlatGeoBufDataTableTest { +class FlatGeoBufDataFrameTest { @Test void rowType() throws IOException { var table = - new FlatGeoBufDataTable(TestFiles.resolve("baremaps-testing/data/samples/countries.fgb")); - var rowType = table.rowType(); + new FlatGeoBufDataFrame(TestFiles.resolve("baremaps-testing/data/samples/countries.fgb")); + var rowType = table.schema(); assertEquals(rowType.name(), null); assertEquals(rowType.columns().size(), 2); } @@ -38,7 +38,7 @@ void rowType() throws IOException { @Test void read() throws IOException { var table = - new FlatGeoBufDataTable(TestFiles.resolve("baremaps-testing/data/samples/countries.fgb")); + new FlatGeoBufDataFrame(TestFiles.resolve("baremaps-testing/data/samples/countries.fgb")); assertEquals(179, table.size()); assertEquals(179, table.stream().count()); } @@ -48,11 +48,11 @@ 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()); + new FlatGeoBufDataFrame(TestFiles.resolve("baremaps-testing/data/samples/countries.fgb")); + var table2 = new FlatGeoBufDataFrame(file, table1.schema()); table2.write(table1); - var featureSet = new FlatGeoBufDataTable(file); + var featureSet = new FlatGeoBufDataFrame(file); 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 83% 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 8abcfe646..e7e5d5c5d 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,14 +22,14 @@ 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")); + new GeoPackageDataStore(TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg")); var table = geoPackageStore.get("countries"); - var rowType = table.rowType(); + var rowType = table.schema(); assertEquals(rowType.name(), "countries"); assertEquals(rowType.columns().size(), 4); } @@ -37,7 +37,7 @@ void rowType() { @Test void read() { var geoPackageStore = - new GeoPackageDataSchema(TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg")); + new GeoPackageDataStore(TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg")); 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 2ba4f86d9..6e7ba2569 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 @@ 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; @@ -32,17 +32,17 @@ public class GeoPackageToPostgresTest extends PostgresContainerTest { void schema() { // Open the GeoPackage var geoPackageSchema = - new GeoPackageDataSchema(TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg")); + new GeoPackageDataStore(TestFiles.resolve("baremaps-testing/data/samples/countries.gpkg")); 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 88% 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 a364aeca4..60f7bb587 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 org.apache.baremaps.testing.TestFiles; import org.junit.jupiter.api.Test; -class GeoParquetDataSchemaTest { +class GeoParquetDataStoreTest { @Test void rowType() { 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 @@ void rowType() { @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 6eeac236c..76bf98e4a 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 @@ 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; @@ -32,18 +32,18 @@ class GeoParquetToPostgresTest extends PostgresContainerTest { void schema() { // 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/PostgresDataTableTest.java b/baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataFrameTest.java similarity index 88% rename from baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataTableTest.java rename to baremaps-core/src/test/java/org/apache/baremaps/storage/postgres/PostgresDataFrameTest.java index b58eaacfc..a6753d48b 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/PostgresDataFrameTest.java @@ -23,20 +23,20 @@ import java.util.List; import org.apache.baremaps.data.schema.DataRowImpl; import org.apache.baremaps.database.PostgresContainerTest; -import org.apache.baremaps.storage.MockDataTable; +import org.apache.baremaps.storage.MockDataFrame; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.locationtech.jts.geom.Coordinate; -class PostgresDataTableTest extends PostgresContainerTest { +class PostgresDataFrameTest extends PostgresContainerTest { - private PostgresDataSchema schema; + private PostgresDataStore schema; @BeforeEach void init() { - schema = new PostgresDataSchema(dataSource()); - schema.add(new MockDataTable()); + schema = new PostgresDataStore(dataSource()); + schema.add(new MockDataFrame()); } @Test @@ -58,7 +58,7 @@ void sizeAsLong() { @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 @@ void schema() { @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 @@ void add() { @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-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 79% 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 82b14ad3a..9414da2ff 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,21 +19,21 @@ import static org.junit.jupiter.api.Assertions.*; -import org.apache.baremaps.data.schema.DataTableException; +import org.apache.baremaps.data.schema.DataStoreException; import org.apache.baremaps.database.PostgresContainerTest; -import org.apache.baremaps.storage.MockDataTable; +import org.apache.baremaps.storage.MockDataFrame; 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.add(new MockDataTable()); + schema = new PostgresDataStore(dataSource()); + schema.add(new MockDataFrame()); } @Test @@ -54,6 +54,6 @@ void addAndGet() { @Tag("integration") void remove() { schema.remove("mock"); - assertThrows(DataTableException.class, () -> schema.get("mock")); + assertThrows(DataStoreException.class, () -> schema.get("mock")); } } 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 caafd45c4..984d99888 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 @@ -20,7 +20,7 @@ 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.schema.DataFrame; import org.apache.calcite.DataContext; import org.apache.calcite.linq4j.Enumerable; import org.apache.calcite.linq4j.Linq4j; @@ -34,11 +34,11 @@ */ public class SqlDataTable extends AbstractTable implements ScannableTable { - private final DataTable table; + private final DataFrame table; private RelDataType rowType; - public SqlDataTable(DataTable table) { + public SqlDataTable(DataFrame table) { this.table = table; } @@ -59,7 +59,7 @@ public RelDataType getRowType(final RelDataTypeFactory typeFactory) { 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/schema/DataTable.java b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataFrame.java similarity index 79% 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/schema/DataFrame.java index e8789420a..f7b3fad56 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTable.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataFrame.java @@ -20,15 +20,15 @@ import org.apache.baremaps.data.collection.DataCollection; /** - * A table is a collection of rows respecting a row type. + * A {@link DataFrame} is a collection of rows respecting a {@link DataSchema} . */ -public interface DataTable extends DataCollection { +public interface DataFrame extends DataCollection { /** - * 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/schema/DataFrameGeometryMapper.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/schema/DataFrameGeometryMapper.java index 0f2db39f5..203017edb 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableGeometryTransformer.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataFrameGeometryMapper.java @@ -22,24 +22,23 @@ 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 DataFrame} that applies a geometry transformation to each row. */ -public class DataTableGeometryTransformer implements Function { +public class DataFrameGeometryMapper implements Function { - private final DataTable table; + private final DataFrame frame; - private final GeometryTransformer geometryTransformer; + private final GeometryTransformer mapper; /** - * Constructs a new table transformer. + * Constructs a new data frame transformer with the specified data frame and geometry transformer. * - * @param table the table to transform - * @param geometryTransformer the geometry transformer + * @param frame the data frame to transform + * @param mapper the geometry mapper */ - public DataTableGeometryTransformer(DataTable table, GeometryTransformer geometryTransformer) { - this.table = table; - this.geometryTransformer = geometryTransformer; + public DataFrameGeometryMapper(DataFrame frame, GeometryTransformer mapper) { + this.frame = frame; + this.mapper = mapper; } /** @@ -47,7 +46,7 @@ public DataTableGeometryTransformer(DataTable table, GeometryTransformer geometr */ @Override public DataRow apply(DataRow row) { - var columns = table.rowType() + var columns = frame.schema() .columns().stream() .filter(column -> column.type().binding().isAssignableFrom(Geometry.class)) .toList(); @@ -55,7 +54,7 @@ public DataRow apply(DataRow row) { 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/schema/DataFrameImpl.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/schema/DataFrameImpl.java index 72fc83fb7..78fbcbd09 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableImpl.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataFrameImpl.java @@ -21,22 +21,22 @@ import org.apache.baremaps.data.collection.DataCollection; /** - * A table is a collection of rows respecting a row type. + * A {@link DataFrame} is a collection of rows respecting a {@link DataSchema}. */ -public class DataTableImpl implements DataTable { +public class DataFrameImpl implements DataFrame { - private final DataRowType rowType; + private final DataSchema schema; private final DataCollection rows; /** - * Constructs a table with the specified row type. + * Constructs a {@link DataFrame} 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 rows) { - this.rowType = rowType; + public DataFrameImpl(DataSchema schema, DataCollection rows) { + this.schema = schema; this.rows = rows; } @@ -44,16 +44,16 @@ public DataTableImpl(DataRowType rowType, DataCollection rows) { * {@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/schema/DataFrameMapper.java similarity index 74% 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/schema/DataFrameMapper.java index 9f7b746cd..0c44cacfc 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableMapper.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataFrameMapper.java @@ -22,22 +22,22 @@ import java.util.function.Function; /** - * A decorator for a table that transforms the geometries of the rows. + * A decorator for a {@link DataFrame} that applies a transformation to each row. */ -public class DataTableMapper implements DataTable { +public class DataFrameMapper implements DataFrame { - private final DataTable table; + private final DataFrame table; private final Function transformer; /** - * Constructs a new table decorator. + * Constructs a new {@code DataFrameMapper} with the specified table and row transformer. * - * @param table the table to decorate - * @param mapper the row transformer + * @param frame the frame + * @param mapper the mapper */ - public DataTableMapper(DataTable table, Function mapper) { - this.table = table; + public DataFrameMapper(DataFrame frame, Function mapper) { + this.table = frame; this.transformer = mapper; } @@ -45,8 +45,8 @@ public DataTableMapper(DataTable table, Function mapper) { * {@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/schema/DataRow.java b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRow.java index 0cce0e41e..5f2e7a6d1 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRow.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRow.java @@ -20,16 +20,16 @@ import java.util.List; /** - * A row in a table. + * A row in a {@link DataFrame}. */ 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/schema/DataRowImpl.java index c45531a45..10ba67ebf 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowImpl.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowImpl.java @@ -22,14 +22,14 @@ /** * 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 Object get(int index) { */ @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/schema/DataRowType.java deleted file mode 100644 index aa9ce058b..000000000 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowType.java +++ /dev/null @@ -1,48 +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 row type defines the structure of a table. - */ -public interface DataRowType { - - /** - * Returns the name of the row type. - * - * @return the name of the row type - */ - String name(); - - /** - * Returns the columns of the row type. - * - * @return the columns of the row type - */ - List columns(); - - /** - * Creates a new row of the row type. - * - * @return a new row of the row type - */ - DataRow createRow(); - -} 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 index 4d9bf6dc8..b69d41f5a 100644 --- 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 @@ -20,46 +20,29 @@ import java.util.List; /** - * A schema is a collection of tables. + * A {@link DataSchema} is a description of the structure of a row in a {@link DataFrame}. */ public interface DataSchema { /** - * Lists the names of the tables. + * Returns the name of the schema. * - * @return the names of the tables + * @return the name of the schema */ - List list() throws DataTableException; + String name(); /** - * Gets a table by its name. + * Returns the columns of the schema. * - * @param name the name of the table - * @return the table + * @return the columns of the schema */ - DataTable get(String name) throws DataTableException; + List columns(); /** - * Adds a table to the schema. + * Creates a new row of the schema. * - * @param table the table + * @return a new row of the schema */ - 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; + 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/schema/DataSchemaImpl.java similarity index 82% 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/schema/DataSchemaImpl.java index 6ebfda5bf..51c1c409e 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataRowTypeImpl.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataSchemaImpl.java @@ -21,21 +21,21 @@ 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 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 columns) { + public DataSchemaImpl(String name, List columns) { this.name = name; this.columns = columns; } diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataStore.java b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataStore.java new file mode 100644 index 000000000..e2f8a94b7 --- /dev/null +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/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.schema; + +import java.util.List; + +/** + * A {@link DataSchema} is a collection of {@link DataFrame}s. + */ +public interface DataStore { + + /** + * Lists the names of the data frames. + * + * @return the names of the data frames + */ + List list() throws DataStoreException; + + /** + * Gets a data frame by name. + * + * @param name the name of the data frame + * @return the data frame + */ + DataFrame get(String name) throws DataStoreException; + + /** + * Adds a data frame to the data store. + * + * @param frame the data frame + */ + void add(DataFrame frame) throws DataStoreException; + + /** + * Adds a data frame to the data store. + * + * @param name the name of the data frame + * @param frame the data frame + * @throws DataStoreException if the data frame cannot be added + */ + void add(String name, DataFrame frame) throws DataStoreException; + + /** + * Removes a data frame from the data store. + * + * @param name the name of the data frame + */ + 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/schema/DataStoreException.java similarity index 64% 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/schema/DataStoreException.java index cbd190097..948ed7d4f 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataTableException.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/schema/DataStoreException.java @@ -17,37 +17,37 @@ package org.apache.baremaps.data.schema; -/** 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/type/RowDataType.java b/baremaps-data/src/main/java/org/apache/baremaps/data/type/RowDataType.java index 0474432f1..36db55f66 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 @@ -24,7 +24,7 @@ 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.schema.DataSchema; /** * A data type for rows. @@ -53,9 +53,9 @@ public class RowDataType implements DataType { 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 0f202f1ee..3ad13fb06 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 @@ -23,8 +23,8 @@ 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.schema.DataSchema; +import org.apache.baremaps.data.schema.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),