Skip to content

Calcite schema ddl #957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.apache.baremaps.calcite.data.DataModifiableTable;
import org.apache.baremaps.calcite.data.DataRow;
import org.apache.baremaps.calcite.data.DataRowType;
import org.apache.baremaps.calcite.data.DataSchema;
import org.apache.baremaps.calcite.data.DataTableSchema;
import org.apache.baremaps.calcite.flatgeobuf.FlatGeoBufTable;
import org.apache.baremaps.calcite.geopackage.GeoPackageTable;
import org.apache.baremaps.calcite.geoparquet.GeoParquetTable;
Expand Down Expand Up @@ -108,15 +108,16 @@ private Table createDataTable(
int length = header.getInt();
byte[] bytes = new byte[length];
header.get(bytes);
DataSchema dataSchema = DataSchema.read(new ByteArrayInputStream(bytes), typeFactory);
DataRowType dataRowType = new DataRowType(dataSchema);
DataTableSchema dataTableSchema =
DataTableSchema.read(new ByteArrayInputStream(bytes), typeFactory);
DataRowType dataRowType = new DataRowType(dataTableSchema);
DataCollection<DataRow> dataCollection = AppendOnlyLog.<DataRow>builder()
.dataType(dataRowType)
.memory(memory)
.build();
return new DataModifiableTable(
name,
dataSchema,
dataTableSchema,
dataCollection,
typeFactory);
} catch (IOException e) {
Expand All @@ -143,9 +144,9 @@ private Table createOpenStreetMapTable(Map<String, Object> operand) {

// Create an entity reader based on the file extension
if (filePath.endsWith(".pbf") || filePath.endsWith(".osm.pbf")) {
return createTableFromPbf(inputStream);
return createTableFromPbf(Paths.get(filePath));
} else if (filePath.endsWith(".xml") || filePath.endsWith(".osm")) {
return createTableFromXml(inputStream);
return createTableFromXml(Paths.get(filePath));
} else {
throw new IllegalArgumentException(
"Unsupported file format. Supported formats are .pbf, .osm.pbf, .xml, and .osm");
Expand Down Expand Up @@ -249,16 +250,6 @@ private Table createFlatGeoBufTable(Map<String, Object> operand) {
}
}

/**
* Create a table from a PBF file.
*
* @param inputStream the input stream
* @return the table
*/
public static OpenStreetMapTable createTableFromPbf(InputStream inputStream) {
return new OpenStreetMapTable(new PbfEntityReader().setGeometries(true), inputStream);
}

/**
* Create a table from a PBF file.
*
Expand All @@ -267,17 +258,9 @@ public static OpenStreetMapTable createTableFromPbf(InputStream inputStream) {
* @throws IOException if an I/O error occurs
*/
public static OpenStreetMapTable createTableFromPbf(Path path) throws IOException {
return createTableFromPbf(new FileInputStream(path.toFile()));
}

/**
* Create a table from an XML file.
*
* @param inputStream the input stream
* @return the table
*/
public static OpenStreetMapTable createTableFromXml(InputStream inputStream) {
return new OpenStreetMapTable(new XmlEntityReader().setGeometries(true), inputStream);
PbfEntityReader reader = new PbfEntityReader();
reader.setGeometries(true);
return new OpenStreetMapTable(path.toFile(), reader);
}

/**
Expand All @@ -288,7 +271,9 @@ public static OpenStreetMapTable createTableFromXml(InputStream inputStream) {
* @throws IOException if an I/O error occurs
*/
public static OpenStreetMapTable createTableFromXml(Path path) throws IOException {
return createTableFromXml(new FileInputStream(path.toFile()));
XmlEntityReader reader = new XmlEntityReader();
reader.setGeometries(true);
return new OpenStreetMapTable(path.toFile(), reader);
}

private Table createGeoParquetTable(Map<String, Object> operand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class DataModifiableTable extends AbstractTable implements ModifiableTabl
private final String name;
private final RelProtoDataType protoRowType;
private final RelDataType rowType;
private final DataSchema schema;
private final DataTableSchema schema;
public final DataCollection<DataRow> rows;

/**
Expand All @@ -92,7 +92,7 @@ public DataModifiableTable(String name,
columns.add(new DataColumnFixed(columnName, columnCardinality, relDataType));
});

this.schema = new DataSchema(name, columns);
this.schema = new DataTableSchema(name, columns);

// Create the collection
DataRowType dataRowType = new DataRowType(schema);
Expand All @@ -109,7 +109,7 @@ public DataModifiableTable(String name,
* @param typeFactory the type factory
*/
public DataModifiableTable(String name,
DataSchema schema,
DataTableSchema schema,
DataCollection<DataRow> rows,
RelDataTypeFactory typeFactory) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* A row in a table with values corresponding to the schema columns.
*/
public record DataRow(DataSchema schema, List<Object> values) {
public record DataRow(DataTableSchema schema, List<Object> values) {

/**
* Constructs a row with validation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public static <T> DataType<T> getType(SqlTypeName sqlTypeName) {
return dataType;
}

private final DataSchema rowType;
private final DataTableSchema rowType;

/**
* Constructs a DataRowType with the given schema.
*
* @param rowType the row schema
*/
public DataRowType(DataSchema rowType) {
public DataRowType(DataTableSchema rowType) {
this.rowType = Objects.requireNonNull(rowType, "Row type cannot be null");
}

Expand Down
Loading
Loading