Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b24d784
Experiments with calcite
bchapuis Jan 13, 2025
3981793
Add list
bchapuis Jan 14, 2025
a7c82af
Format code
bchapuis Jan 17, 2025
00b5307
Improve GeoPackage store
bchapuis Jan 18, 2025
d3383d1
Make data collection closeable
bchapuis Jan 18, 2025
ae41449
Refactor the sub modules
bchapuis Jan 21, 2025
b9ecee2
Add header to memory
bchapuis Jan 26, 2025
9196a7f
Fix issues in header
bchapuis Feb 3, 2025
3e32723
Merge the calcite and store packages
bchapuis Feb 3, 2025
f5d3112
Add the server ddl class and implement materialized views
bchapuis Feb 7, 2025
bed98b0
Some progress
bchapuis Feb 26, 2025
a535dbc
Fix build issues
bchapuis Apr 5, 2025
b1b5db4
Fix unit test
bchapuis Apr 5, 2025
d4a8241
New version
bchapuis Apr 5, 2025
8237230
Add calcite table
bchapuis Apr 5, 2025
cc4b67a
Add an openstreetmap table
bchapuis Apr 6, 2025
8056231
Add Calcite table for shapefile
bchapuis Apr 6, 2025
8e27d14
Add calcite rpsl table
bchapuis Apr 6, 2025
3ecf5f7
Fix unit tests
bchapuis Apr 6, 2025
9795569
Add flatgeobuf calcite table
bchapuis Apr 6, 2025
0f46587
Add Calcite table for geoparquet
bchapuis Apr 7, 2025
7176093
Add a calcite postgis table and schema
bchapuis Apr 7, 2025
2555b3f
Delete old implementation of calcite tables
bchapuis Apr 7, 2025
93960ee
Fix compilation issues in calcite module
bchapuis Apr 7, 2025
c64b95a
Format code
bchapuis Apr 7, 2025
7105e06
Make postgis table modifiable
bchapuis Apr 7, 2025
ff21fa8
Add a postgres ddl executor
bchapuis Apr 7, 2025
0e7bd88
Import shapefile with calcite
bchapuis Apr 8, 2025
fc56420
Test import in postgis
bchapuis Apr 8, 2025
e0c6575
Adapt the tasks to calcite
bchapuis Apr 9, 2025
06b4276
Refactor GeoPackage and GeoParquet handling; remove debug prints, enh…
bchapuis Apr 10, 2025
2636a91
Refactor GeoParquet type conversion to use Envelope class instead of …
bchapuis Apr 10, 2025
348dbbf
Update GeoParquet type conversion to return Geometry from Envelope; e…
bchapuis Apr 10, 2025
83cdca3
Fix conversions, enumerator and table
bchapuis Apr 10, 2025
c678597
Clean and fix code
bchapuis Apr 11, 2025
18c73fc
Add calcite csv schema
bchapuis Apr 11, 2025
be9f84f
Add a csv schema and revise the overall structure of the package
bchapuis Apr 11, 2025
13a4efe
Fix the test and rat checks
bchapuis Apr 11, 2025
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
86 changes: 86 additions & 0 deletions baremaps-calcite/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps</artifactId>
<version>0.8.3-SNAPSHOT</version>
</parent>

<artifactId>baremaps-calcite</artifactId>
<name>Apache Baremaps Calcite</name>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
</dependency>
<dependency>
<groupId>mil.nga.geopackage</groupId>
<artifactId>geopackage</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-data</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-flatgeobuf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-geoparquet</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-openstreetmap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-postgres</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-rpsl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-shapefile</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-server</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.16.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
<version>2.10.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* limitations under the License.
*/

package org.apache.baremaps.store;
package org.apache.baremaps.calcite;

import java.io.Serializable;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
Expand All @@ -29,7 +30,7 @@
/**
* A column in a table.
*/
public interface DataColumn {
public interface DataColumn extends Serializable {

/**
* Returns the name of the column.
Expand All @@ -38,7 +39,6 @@ public interface DataColumn {
*/
String name();


Cardinality cardinality();

enum Cardinality {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/

package org.apache.baremaps.store;
package org.apache.baremaps.calcite;


/**
* A column in a table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.baremaps.store;
package org.apache.baremaps.calcite;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
* limitations under the License.
*/

package org.apache.baremaps.store;

package org.apache.baremaps.calcite;

import java.util.List;

/**
* A row in a table.
* A row in a {@link DataTable}.
*/
public record DataRowImpl(DataSchema schema, List<Object> values) implements DataRow {
public record DataRow(DataSchema schema, List<Object> values) {

/**
* {@inheritDoc}
*/
@Override
public Object get(String column) {
var columns = schema.columns();
for (int i = 0; i < columns.size(); i++) {
Expand All @@ -42,15 +40,13 @@ public Object get(String column) {
/**
* {@inheritDoc}
*/
@Override
public Object get(int index) {
return values.get(index);
}

/**
* {@inheritDoc}
*/
@Override
public void set(String column, Object value) {
for (int i = 0; i < schema.columns().size(); i++) {
if (schema.columns().get(i).name().equals(column)) {
Expand All @@ -64,8 +60,31 @@ public void set(String column, Object value) {
/**
* {@inheritDoc}
*/
@Override
public void set(int index, Object value) {
values.set(index, value);
}

/**
* Sets the value of the specified column and returns the row.
*
* @param column the column
* @param value the value
* @return the row
*/
public DataRow with(String column, Object value) {
set(column, value);
return this;
}

/**
* Sets the value of the specified column and returns the row.
*
* @param index the index of the column
* @param value the value
* @return the row
*/
public DataRow with(int index, Object value) {
set(index, value);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
* limitations under the License.
*/

package org.apache.baremaps.data.type;
package org.apache.baremaps.calcite;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.EnumMap;
import org.apache.baremaps.store.DataColumn;
import org.apache.baremaps.store.DataColumn.Type;
import org.apache.baremaps.store.DataRow;
import org.apache.baremaps.store.DataRowImpl;
import org.apache.baremaps.store.DataSchema;
import org.apache.baremaps.calcite.DataColumn.Type;
import org.apache.baremaps.data.type.*;

/**
* A {@link DataType} for reading and writing {@link DataRow} objects in {@link ByteBuffer}s.
*/
public class RowDataType implements DataType<DataRow> {
public class DataRowType implements DataType<DataRow> {

/**
* Map of data types for each of the supported column types.
Expand Down Expand Up @@ -58,12 +55,7 @@ public class RowDataType implements DataType<DataRow> {

private final DataSchema rowType;

/**
* Constructs a {@link RowDataType} with a specified schema.
*
* @param rowType the data schema defining the row's structure
*/
public RowDataType(DataSchema rowType) {
public DataRowType(DataSchema rowType) {
this.rowType = rowType;
}

Expand Down Expand Up @@ -115,6 +107,6 @@ public DataRow read(final ByteBuffer buffer, final int position) {
values.add(dataType.read(buffer, p));
p += dataType.size(buffer, p);
}
return new DataRowImpl(rowType, values);
return new DataRow(rowType, values);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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.calcite;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.baremaps.calcite.DataColumn.Cardinality;
import org.apache.baremaps.calcite.DataColumn.Type;

/**
* A {@link DataSchema} defines the structure of a table.
*/
public record DataSchema(String name,
List<DataColumn> columns) implements Serializable {

public DataRow createRow() {
var values = new ArrayList<>(columns.size());
for (int i = 0; i < columns.size(); i++) {
values.add(null);
}
return new DataRow(this, values);
}

static class DataSchemaDeserializer extends JsonDeserializer<DataSchema> {

@Override
public DataSchema deserialize(JsonParser parser, DeserializationContext ctxt)
throws IOException {
ObjectNode node = parser.getCodec().readTree(parser);
String name = node.get("name").asText();
List<DataColumn> columns = new ArrayList<>();
node.get("columns").elements().forEachRemaining(column -> {
columns.add(deserialize(column));
});
return new DataSchema(name, columns);
}

DataColumn deserialize(JsonNode node) {
String columnName = node.get("name").asText();
Cardinality cardinality = Cardinality.valueOf(node.get("cardinality").asText());
Type type = Type.valueOf(node.get("type").asText());
if (type == Type.NESTED) {
List<DataColumn> columns = new ArrayList<>();
node.get("columns").elements().forEachRemaining(column -> {
columns.add(deserialize(column));
});
return new DataColumnNested(columnName, cardinality, columns);
} else {
return new DataColumnFixed(columnName, cardinality, type);
}
}
}

private static ObjectMapper configureObjectMapper() {
var mapper = new ObjectMapper();
mapper.registerSubtypes(
new NamedType(DataColumnFixed.class, "FIXED"),
new NamedType(DataColumnNested.class, "NESTED"));
var module = new SimpleModule();
module.addDeserializer(DataSchema.class, new DataSchemaDeserializer());
mapper.registerModule(module);
return mapper;
}

static DataSchema read(InputStream inputStream) throws IOException {
var mapper = configureObjectMapper();
return mapper.readValue(inputStream, DataSchema.class);
}

static void write(OutputStream outputStream, DataSchema schema) throws IOException {
var mapper = configureObjectMapper();
mapper.writeValue(outputStream, schema);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.baremaps.store;
package org.apache.baremaps.calcite;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.baremaps.store;
package org.apache.baremaps.calcite;

/** Signals that an exception occurred in a {@link DataStore}. */
public class DataStoreException extends RuntimeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.baremaps.store;
package org.apache.baremaps.calcite;

import java.util.Iterator;
import java.util.Spliterator;
Expand All @@ -26,7 +26,7 @@
/**
* A {@link DataTable} is a collection of rows respecting a {@link DataSchema} .
*/
public interface DataTable extends Iterable<DataRow> {
public interface DataTable extends Iterable<DataRow>, AutoCloseable {

/**
* Returns the schema of the row.
Expand Down
Loading
Loading