Skip to content

Commit

Permalink
Improve naming in the schema package
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed May 30, 2024
1 parent a838fd0 commit dc0703c
Show file tree
Hide file tree
Showing 40 changed files with 350 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -235,7 +235,7 @@ public static class RowIterator implements Iterator<DataRow> {

private final HeaderMeta headerMeta;

private final DataRowType rowType;
private final DataSchema rowType;

private final SeekableByteChannel channel;

Expand All @@ -252,7 +252,7 @@ public static class RowIterator implements Iterator<DataRow> {
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,82 +21,82 @@
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;
}

/**
* {@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);
}
}

/**
* {@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);
}
}

/**
* {@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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<DataColumn>();
Expand All @@ -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());
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public long size() {
* {@inheritDoc}
*/
@Override
public DataRowType rowType() {
public DataSchema schema() {
return rowType;
}

Expand Down Expand Up @@ -230,7 +230,7 @@ public class GeopackageIterator implements Iterator<DataRow> {

private final FeatureResultSet featureResultSet;

private final DataRowType rowType;
private final DataSchema rowType;

private boolean hasNext;

Expand All @@ -240,7 +240,7 @@ public class GeopackageIterator implements Iterator<DataRow> {
* @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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}

Expand All @@ -54,36 +54,36 @@ public void close() throws Exception {
* {@inheritDoc}
*/
@Override
public List<String> list() throws DataTableException {
public List<String> list() throws DataStoreException {
return geoPackage.getFeatureTables();
}

/**
* {@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();
}

/**
* {@inheritDoc}
*/
@Override
public void remove(String name) throws DataTableException {
public void remove(String name) throws DataStoreException {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public void clear() {
}

@Override
public DataRowType rowType() {
public DataSchema schema() {
if (rowType == null) {
try {
Schema schema = reader().getGeoParquetSchema();
Expand Down
Loading

0 comments on commit dc0703c

Please sign in to comment.