You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by bc...@apache.org on 2025/04/05 14:03:48 UTC
(incubator-baremaps) branch calcite-framework updated (885e4a551 -> a535dbc06)
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a change to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
discard 885e4a551 Some progress
discard 8c66266fd Add the server ddl class and implement materialized views
discard fa079dc2c Merge the calcite and store packages
discard 6e7289722 Fix issues in header
discard 251ea904c Add header to memory
discard a6c7315e4 Refactor the sub modules
discard d6b161c89 Make data collection closeable
discard fa97d3cb0 Improve GeoPackage store
discard 97799717b Format code
discard 14d2eb9dd Add list
discard e9983dd21 Experiments with calcite
add 9e1b882e0 Materialized views refresher (#915)
add 8c65a3071 Generate different queries depending on the postgresql version (#914)
add e4735f609 Improve the content of the META-INF/MANIFEST.MF (#917)
add c81151594 Fix the release workflow
add 24c29b735 Add the Planetiler NOTICE to the project's NOTICE file. (#920)
add 648677210 Fix rat:check with pregenerated files (#921)
add 0eb8c1a03 Update Maplibre to version 5 (#924)
add 4212c7867 Perform automatic actions on issues and pull requests (#942)
add e54f2ae5e Create an Issue Template for Better Reporting (#941)
add 0f05dead2 Improve CSP directive (#944)
add 6cae7e0f1 Improve the NOTICE file for the binary distribution (#940)
add 96cf335ea Display building numbers (#945)
add 28e5bb4b9 Add NOTICE-binary to source distribution
add 03512049f Release Baremaps 0.8.2
add 6326256c4 Prepare for next development iteration
add 967a26dda improve Reproducible Builds details (#951)
add 51718b799 Close the possibility of a RCE in Apache Parquet (#953)
add e64671887 Refactor the PMTiles module (#954)
add dc8ff321e Data collection refactoring (#955)
new b24d78403 Experiments with calcite
new 3981793f7 Add list
new a7c82af44 Format code
new 00b53075b Improve GeoPackage store
new d3383d1a5 Make data collection closeable
new ae41449ac Refactor the sub modules
new b9ecee262 Add header to memory
new 9196a7fbe Fix issues in header
new 3e3272306 Merge the calcite and store packages
new f5d311253 Add the server ddl class and implement materialized views
new bed98b0ef Some progress
new a535dbc06 Fix build issues
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (885e4a551)
\
N -- N -- N refs/heads/calcite-framework (a535dbc06)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 12 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.github/ISSUE_TEMPLATE/bug_report.md | 43 +
.github/ISSUE_TEMPLATE/config.yml | 5 +
.github/ISSUE_TEMPLATE/feature_request.md | 26 +
.github/workflows/close-inactive-issues.yml | 32 +
.github/workflows/label-opened-issues.yml | 30 +
.github/workflows/release.yml | 3 +
LICENSE | 20 +-
NOTICE | 12 +-
NOTICE-binary | 2094 ++++++++++++++++++++
RELEASE.md | 6 +-
baremaps-benchmarking/pom.xml | 3 +-
baremaps-calcite/pom.xml | 3 +-
.../org/apache/baremaps/calcite/DataRowType.java | 9 +-
.../apache/baremaps/calcite/DataTableAdapter.java | 1 -
.../apache/baremaps/calcite/DataTableFactory.java | 9 +-
.../calcite/baremaps/BaremapsDataTable.java | 7 +-
.../calcite/baremaps/BaremapsDdlExecutor.java | 3 +-
.../calcite/baremaps/BaremapsMaterializedView.java | 2 +-
.../calcite/baremaps/BaremapsModifiableTable.java | 371 ++--
.../org/apache/baremaps/calcite/CalciteTest.java | 172 +-
.../calcite/DataTableAdapterFactoryTest.java | 143 +-
baremaps-cli/pom.xml | 4 +-
baremaps-cli/src/assembly/bin.xml | 9 +-
baremaps-cli/src/assembly/src.xml | 1 +
baremaps-cli/src/license/bundle.ftl | 4 +-
.../main/java/org/apache/baremaps/cli/map/Dev.java | 3 +-
.../java/org/apache/baremaps/cli/map/Serve.java | 3 +-
baremaps-core/pom.xml | 3 +-
.../apache/baremaps/tasks/ExportVectorTiles.java | 14 +-
.../baremaps/tasks/RefreshMaterializedViews.java | 73 +
.../tilestore/postgres/PostgresTileStore.java | 110 +-
.../java/org/apache/baremaps/workflow/Task.java | 1 +
.../apache/baremaps/workflow/WorkflowContext.java | 47 +-
.../org/apache/baremaps/calcite/CalciteTest.java | 121 --
.../baremaps/tasks/ImportUpdateSampleTest.java | 14 +-
.../tilestore/postgres/PostgresTileStoreTest.java | 29 +-
{baremaps-rpsl => baremaps-csv}/pom.xml | 22 +-
baremaps-data/pom.xml | 3 +-
.../baremaps/data/collection/AppendOnlyLog.java | 130 +-
.../baremaps/data/collection/DataCollection.java | 52 +-
.../data/collection/DataCollectionException.java | 22 +-
.../data/collection/DataCollectionMapper.java | 14 +-
.../baremaps/data/collection/DataConversions.java | 69 +-
.../apache/baremaps/data/collection/DataList.java | 21 +-
.../apache/baremaps/data/collection/DataMap.java | 76 +-
.../data/collection/DirectHashDataMap.java | 496 +++++
.../data/collection/FixedSizeDataList.java | 87 +-
.../baremaps/data/collection/IndexedDataList.java | 83 +-
.../baremaps/data/collection/IndexedDataMap.java | 79 +-
.../data/collection/MemoryAlignedDataList.java | 90 +-
.../data/collection/MemoryAlignedDataMap.java | 83 +-
.../baremaps/data/collection/MonotonicDataMap.java | 112 +-
.../data/collection/MonotonicFixedSizeDataMap.java | 99 +-
.../data/collection/MonotonicPairedDataMap.java | 80 +-
.../org/apache/baremaps/data/memory/Memory.java | 102 +-
.../baremaps/data/memory/MemoryException.java | 18 +-
.../data/memory/MemoryMappedDirectory.java | 43 +-
.../baremaps/data/memory/MemoryMappedFile.java | 42 +-
.../apache/baremaps/data/memory/OffHeapMemory.java | 32 +-
.../apache/baremaps/data/memory/OnHeapMemory.java | 31 +-
.../baremaps/data/type/BooleanArrayDataType.java | 4 +-
.../apache/baremaps/data/type/BooleanDataType.java | 8 +-
.../baremaps/data/type/BooleanListDataType.java | 4 +-
.../baremaps/data/type/ByteArrayDataType.java | 2 +-
.../apache/baremaps/data/type/ByteDataType.java | 10 +-
.../baremaps/data/type/ByteListDataType.java | 2 +-
.../data/type/CoordinateArrayDataType.java | 3 +-
.../baremaps/data/type/CoordinateDataType.java | 6 +-
.../org/apache/baremaps/data/type/DataType.java | 24 +-
.../baremaps/data/type/DoubleArrayDataType.java | 6 +-
.../apache/baremaps/data/type/DoubleDataType.java | 10 +-
.../baremaps/data/type/DoubleListDataType.java | 6 +-
.../baremaps/data/type/FixedSizeDataType.java | 8 +-
.../baremaps/data/type/FloatArrayDataType.java | 6 +-
.../apache/baremaps/data/type/FloatDataType.java | 6 +-
.../baremaps/data/type/FloatListDataType.java | 6 +-
.../data/type/GeometryCollectionDataType.java | 11 +-
.../baremaps/data/type/GeometryDataType.java | 8 +-
.../baremaps/data/type/IntegerArrayDataType.java | 7 +-
.../apache/baremaps/data/type/IntegerDataType.java | 6 +-
.../baremaps/data/type/IntegerListDataType.java | 7 +-
.../baremaps/data/type/LineStringDataType.java | 6 +-
.../apache/baremaps/data/type/ListDataType.java | 9 +-
.../apache/baremaps/data/type/LonLatDataType.java | 23 +-
.../baremaps/data/type/LongArrayDataType.java | 6 +-
.../apache/baremaps/data/type/LongDataType.java | 7 +-
.../baremaps/data/type/LongListDataType.java | 6 +-
.../org/apache/baremaps/data/type/MapDataType.java | 16 +
.../baremaps/data/type/MemoryAlignedDataType.java | 7 +-
.../data/type/MultiLineStringDataType.java | 7 +-
.../baremaps/data/type/MultiPointDataType.java | 6 +-
.../baremaps/data/type/MultiPolygonDataType.java | 6 +-
.../baremaps/data/type/NullableDataType.java | 10 +-
.../apache/baremaps/data/type/PairDataType.java | 35 +-
.../apache/baremaps/data/type/PointDataType.java | 6 +-
.../apache/baremaps/data/type/PolygonDataType.java | 6 +-
.../baremaps/data/type/ShortArrayDataType.java | 4 +-
.../apache/baremaps/data/type/ShortDataType.java | 8 +-
.../baremaps/data/type/ShortListDataType.java | 6 +-
.../baremaps/data/type/SmallIntegerDataType.java | 12 +-
.../baremaps/data/type/SmallLongDataType.java | 12 +-
.../apache/baremaps/data/type/StringDataType.java | 2 +-
.../org/apache/baremaps/data/type/WKBDataType.java | 24 +-
.../apache/baremaps/data/AppendOnlyLogTest.java | 15 +-
.../org/apache/baremaps/data/DataListTest.java | 18 +-
.../java/org/apache/baremaps/data/DataMapTest.java | 45 +-
.../apache/baremaps/data/SizedDataListTest.java | 10 +-
.../data/collection/IndexedDataMapTest.java | 6 +-
.../data/collection/MemoryAlignedDataMapTest.java | 5 +-
.../baremaps/data/sort/BinarySearchTest.java | 4 +-
.../baremaps/data/sort/ExternalMergeSortTest.java | 13 +-
baremaps-dem/pom.xml | 3 +-
baremaps-flatgeobuf/pom.xml | 3 +-
{baremaps-rpsl => baremaps-geopackage}/pom.xml | 18 +-
baremaps-geoparquet/pom.xml | 3 +-
baremaps-maplibre/pom.xml | 3 +-
baremaps-openstreetmap/pom.xml | 3 +-
baremaps-pmtiles/pom.xml | 3 +-
.../org/apache/baremaps/pmtiles/Compression.java | 60 +
.../org/apache/baremaps/pmtiles/Directories.java | 115 +-
.../baremaps/pmtiles/DirectorySerializer.java | 135 ++
.../java/org/apache/baremaps/pmtiles/Entry.java | 133 +-
.../apache/baremaps/pmtiles/EntrySerializer.java | 162 ++
.../java/org/apache/baremaps/pmtiles/Header.java | 411 +++-
.../apache/baremaps/pmtiles/HeaderSerializer.java | 125 ++
.../org/apache/baremaps/pmtiles/PMTilesReader.java | 62 +-
.../org/apache/baremaps/pmtiles/PMTilesUtils.java | 410 ----
.../org/apache/baremaps/pmtiles/PMTilesWriter.java | 214 +-
.../org/apache/baremaps/pmtiles/Serializer.java | 33 +-
.../apache/baremaps/pmtiles/TileIdConverter.java | 127 ++
.../java/org/apache/baremaps/pmtiles/TileType.java | 3 +
.../apache/baremaps/pmtiles/VarIntSerializer.java | 141 ++
.../baremaps/pmtiles/DirectorySerializerTest.java | 64 +
.../baremaps/pmtiles/EntrySerializerTest.java | 87 +
.../baremaps/pmtiles/HeaderSerializerTest.java | 100 +
...esUtilsTest.java => PMTilesSerializerTest.java} | 171 +-
.../baremaps/pmtiles/TileIdConverterTest.java | 85 +
.../baremaps/pmtiles/VarIntSerializerTest.java | 70 +
baremaps-postgres/pom.xml | 3 +-
.../refresh/DatabaseMetadataRetriever.java | 220 ++
.../postgres/refresh/DependencyGraphBuilder.java | 113 ++
.../refresh/MaterializedViewRefresher.java | 97 +
.../baremaps/postgres/utils/PostgresUtils.java | 13 +
baremaps-renderer/package-lock.json | 245 ++-
baremaps-renderer/package.json | 2 +-
.../src/lib/maplibreBrowserHelpers.ts | 4 +-
baremaps-rpsl/pom.xml | 3 +-
baremaps-server/pom.xml | 3 +-
baremaps-server/src/main/resources/dem/index.html | 13 +-
.../src/main/resources/static/server.html | 13 +-
.../src/main/resources/static/viewer.html | 13 +-
baremaps-shapefile/pom.xml | 3 +-
{baremaps-rpsl => baremaps-store}/pom.xml | 16 +-
baremaps-testing/pom.xml | 3 +-
basemap/create.js | 2 +-
basemap/index.html | 13 +-
basemap/layers/amenity/create.sql | 267 ++-
basemap/layers/amenity/refresh.sql | 292 ---
basemap/layers/building/number.js | 11 +-
basemap/layers/highway/create.sql | 150 +-
basemap/layers/highway/refresh.sql | 163 --
basemap/layers/landuse/create.sql | 267 ++-
basemap/layers/landuse/refresh.sql | 292 ---
basemap/layers/leisure/create.sql | 267 ++-
basemap/layers/leisure/refresh.sql | 292 ---
basemap/layers/member/create.sql | 9 +-
basemap/layers/member/refresh.sql | 22 -
basemap/layers/natural/create.sql | 267 ++-
basemap/layers/natural/refresh.sql | 292 ---
basemap/layers/node/create.sql | 18 +-
basemap/layers/node/refresh.sql | 29 -
basemap/layers/ocean/create.sql | 20 +-
basemap/layers/ocean/refresh.sql | 33 -
basemap/layers/point/create.sql | 130 +-
basemap/layers/point/refresh.sql | 143 --
basemap/layers/railway/create.sql | 150 +-
basemap/layers/railway/refresh.sql | 163 --
basemap/layers/relation/create.sql | 18 +-
basemap/layers/relation/refresh.sql | 29 -
basemap/layers/route/create.sql | 150 +-
basemap/layers/route/refresh.sql | 163 --
basemap/layers/waterway/create.sql | 150 +-
basemap/layers/waterway/refresh.sql | 163 --
basemap/layers/way/create.sql | 16 +
basemap/layers/way/refresh.sql | 29 -
basemap/refresh.js | 26 +-
basemap/style.js | 2 +
daylight/style.js | 2 +
examples/openstreetmap/index.html | 13 +-
licenses/externalsortinginjava | 1 +
licenses/hilbert_curves | 1 +
notices-binary/armeria | 394 ----
notices-binary/awssdk | 25 -
notices-binary/brotli4j | 36 -
notices-binary/calcite | 10 -
notices-binary/commons-compress | 5 -
notices-binary/hadoop | 827 --------
notices-binary/log4j | 20 -
notices-binary/lucene | 197 --
notices-binary/parquet | 6 -
notices-binary/picocli | 351 ----
notices-binary/proj4j | 108 -
notices-binary/sis | 54 -
notices-binary/sqlite-jdbc | 4 -
notices/planetiler | 70 -
pom.xml | 36 +-
206 files changed, 9357 insertions(+), 6155 deletions(-)
create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md
create mode 100644 .github/ISSUE_TEMPLATE/config.yml
create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md
create mode 100644 .github/workflows/close-inactive-issues.yml
create mode 100644 .github/workflows/label-opened-issues.yml
create mode 100644 NOTICE-binary
create mode 100644 baremaps-core/src/main/java/org/apache/baremaps/tasks/RefreshMaterializedViews.java
delete mode 100644 baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
copy {baremaps-rpsl => baremaps-csv}/pom.xml (75%)
create mode 100644 baremaps-data/src/main/java/org/apache/baremaps/data/collection/DirectHashDataMap.java
copy {baremaps-rpsl => baremaps-geopackage}/pom.xml (82%)
create mode 100644 baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/DirectorySerializer.java
create mode 100644 baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/EntrySerializer.java
create mode 100644 baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/HeaderSerializer.java
delete mode 100644 baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/PMTilesUtils.java
copy baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileException.java => baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/Serializer.java (54%)
create mode 100644 baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/TileIdConverter.java
create mode 100644 baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/VarIntSerializer.java
create mode 100644 baremaps-pmtiles/src/test/java/org/apache/baremaps/pmtiles/DirectorySerializerTest.java
create mode 100644 baremaps-pmtiles/src/test/java/org/apache/baremaps/pmtiles/EntrySerializerTest.java
create mode 100644 baremaps-pmtiles/src/test/java/org/apache/baremaps/pmtiles/HeaderSerializerTest.java
rename baremaps-pmtiles/src/test/java/org/apache/baremaps/pmtiles/{PMTilesUtilsTest.java => PMTilesSerializerTest.java} (54%)
create mode 100644 baremaps-pmtiles/src/test/java/org/apache/baremaps/pmtiles/TileIdConverterTest.java
create mode 100644 baremaps-pmtiles/src/test/java/org/apache/baremaps/pmtiles/VarIntSerializerTest.java
create mode 100644 baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/DatabaseMetadataRetriever.java
create mode 100644 baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/DependencyGraphBuilder.java
create mode 100644 baremaps-postgres/src/main/java/org/apache/baremaps/postgres/refresh/MaterializedViewRefresher.java
copy {baremaps-rpsl => baremaps-store}/pom.xml (77%)
delete mode 100644 basemap/layers/amenity/refresh.sql
delete mode 100644 basemap/layers/highway/refresh.sql
delete mode 100644 basemap/layers/landuse/refresh.sql
delete mode 100644 basemap/layers/leisure/refresh.sql
delete mode 100644 basemap/layers/member/refresh.sql
delete mode 100644 basemap/layers/natural/refresh.sql
delete mode 100644 basemap/layers/node/refresh.sql
delete mode 100644 basemap/layers/ocean/refresh.sql
delete mode 100644 basemap/layers/point/refresh.sql
delete mode 100644 basemap/layers/railway/refresh.sql
delete mode 100644 basemap/layers/relation/refresh.sql
delete mode 100644 basemap/layers/route/refresh.sql
delete mode 100644 basemap/layers/waterway/refresh.sql
delete mode 100644 basemap/layers/way/refresh.sql
create mode 100644 licenses/externalsortinginjava
create mode 100644 licenses/hilbert_curves
delete mode 100644 notices-binary/armeria
delete mode 100644 notices-binary/awssdk
delete mode 100644 notices-binary/brotli4j
delete mode 100644 notices-binary/calcite
delete mode 100644 notices-binary/commons-compress
delete mode 100644 notices-binary/hadoop
delete mode 100644 notices-binary/log4j
delete mode 100644 notices-binary/lucene
delete mode 100644 notices-binary/parquet
delete mode 100644 notices-binary/picocli
delete mode 100644 notices-binary/proj4j
delete mode 100644 notices-binary/sis
delete mode 100644 notices-binary/sqlite-jdbc
delete mode 100644 notices/planetiler
(incubator-baremaps) 12/12: Fix build issues
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit a535dbc06a76bd25064545b645762ba136cd4016
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sat Apr 5 16:03:41 2025 +0200
Fix build issues
---
baremaps-calcite/pom.xml | 3 +-
.../apache/baremaps/calcite/DataTableAdapter.java | 1 -
.../apache/baremaps/calcite/DataTableFactory.java | 9 +-
.../calcite/baremaps/BaremapsDataTable.java | 7 +-
.../calcite/baremaps/BaremapsDdlExecutor.java | 3 +-
.../calcite/baremaps/BaremapsMaterializedView.java | 2 +-
.../calcite/baremaps/BaremapsModifiableTable.java | 371 ++++++++++-----------
.../org/apache/baremaps/calcite/CalciteTest.java | 172 +++++-----
.../calcite/DataTableAdapterFactoryTest.java | 143 ++++----
.../org/apache/baremaps/calcite/CalciteTest.java | 120 -------
.../baremaps/data/collection/DataCollection.java | 1 -
.../data/collection/DataCollectionMapper.java | 1 -
.../baremaps/data/collection/DataConversions.java | 2 -
.../data/collection/FixedSizeDataList.java | 1 -
.../baremaps/data/collection/IndexedDataList.java | 1 -
.../org/apache/baremaps/data/memory/Memory.java | 10 +-
pom.xml | 5 -
17 files changed, 357 insertions(+), 495 deletions(-)
diff --git a/baremaps-calcite/pom.xml b/baremaps-calcite/pom.xml
index 5ea71ec49..d49d188ca 100644
--- a/baremaps-calcite/pom.xml
+++ b/baremaps-calcite/pom.xml
@@ -4,10 +4,11 @@
<parent>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps</artifactId>
- <version>0.8.2-SNAPSHOT</version>
+ <version>0.8.3-SNAPSHOT</version>
</parent>
<artifactId>baremaps-calcite</artifactId>
+ <name>Apache Baremaps Calcite</name>
<properties>
<maven.compiler.source>21</maven.compiler.source>
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
index 2f244f1cc..6cb7a75b4 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
@@ -25,7 +25,6 @@ import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Linq4j;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.schema.ScannableTable;
import org.apache.calcite.schema.impl.AbstractTable;
import org.apache.calcite.sql.type.SqlTypeName;
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
index ce0ea913a..30fdcf6ae 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
@@ -60,7 +60,7 @@ public class DataTableFactory implements TableFactory<Table> {
}
private Table createDataTable(SchemaPlus schema, String name, Map<String, Object> operand,
- RelDataType rowType) {
+ RelDataType rowType) {
String directory = (String) operand.get("directory");
if (directory == null) {
throw new RuntimeException("A directory should be specified");
@@ -74,8 +74,11 @@ public class DataTableFactory implements TableFactory<Table> {
header.get(bytes);
DataSchema dataSchema = DataSchema.read(new ByteArrayInputStream(bytes));
DataType<DataRow> dataType = new DataRowType(dataSchema);
- DataCollection<DataRow> dataCollection = new AppendOnlyLog<>(dataType, memory);
- return null; //new BaremapsTable(dataSchema, dataCollection);
+ DataCollection<DataRow> dataCollection = AppendOnlyLog.<DataRow>builder()
+ .dataType(dataType)
+ .memory(memory)
+ .build();
+ return null; // new BaremapsTable(dataSchema, dataCollection);
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataTable.java
index dcfab9722..ae7084185 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataTable.java
@@ -17,7 +17,6 @@
package org.apache.baremaps.calcite.baremaps;
-import java.io.IOException;
import java.util.Iterator;
import org.apache.baremaps.calcite.DataRow;
import org.apache.baremaps.calcite.DataRowType;
@@ -53,7 +52,9 @@ public class BaremapsDataTable implements DataTable {
*/
public BaremapsDataTable(DataSchema schema) {
this.schema = schema;
- this.rows = new AppendOnlyLog<>(new DataRowType(schema));
+ this.rows = AppendOnlyLog.<DataRow>builder()
+ .dataType(new DataRowType(schema))
+ .build();
}
/**
@@ -94,7 +95,7 @@ public class BaremapsDataTable implements DataTable {
}
@Override
- public void close() throws IOException {
+ public void close() throws Exception {
rows.close();
}
}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDdlExecutor.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDdlExecutor.java
index 206067735..73cd1bc33 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDdlExecutor.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDdlExecutor.java
@@ -424,7 +424,8 @@ public class BaremapsDdlExecutor extends DdlExecutorImpl {
// Table does not exist. Create it.
final BaremapsMaterializedView table =
- new BaremapsMaterializedView(pair.right, RelDataTypeImpl.proto(rowType), context.getTypeFactory());
+ new BaremapsMaterializedView(pair.right, RelDataTypeImpl.proto(rowType),
+ context.getTypeFactory());
pair.left.add(pair.right, table);
populate(create.name, create.query, context);
table.key =
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java
index da3f1b722..09c6aef5e 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java
@@ -34,7 +34,7 @@ class BaremapsMaterializedView extends BaremapsModifiableTable {
MaterializationKey key;
BaremapsMaterializedView(
- String name,
+ String name,
RelProtoDataType protoRowType,
RelDataTypeFactory typeFactory) {
super(name, protoRowType, typeFactory);
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsModifiableTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsModifiableTable.java
index 58bfd1255..d5d7a858d 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsModifiableTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsModifiableTable.java
@@ -17,6 +17,14 @@
package org.apache.baremaps.calcite.baremaps;
+import static java.util.Objects.requireNonNull;
+
+import java.lang.reflect.Type;
+import java.nio.MappedByteBuffer;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
import org.apache.baremaps.calcite.*;
import org.apache.baremaps.calcite.DataColumn.Cardinality;
import org.apache.baremaps.data.collection.AppendOnlyLog;
@@ -47,222 +55,213 @@ import org.apache.calcite.schema.impl.AbstractTableQueryable;
import org.apache.calcite.sql.type.SqlTypeName;
import org.checkerframework.checker.nullness.qual.Nullable;
-import java.lang.reflect.Type;
-import java.nio.MappedByteBuffer;
-import java.nio.file.Paths;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import static java.util.Objects.requireNonNull;
-
class BaremapsModifiableTable extends AbstractTable implements ModifiableTable, Wrapper {
- private final String name;
-
- private final RelProtoDataType protoRowType;
-
- private final RelDataType rowType;
-
- private final DataSchema schema;
+ private final String name;
+
+ private final RelProtoDataType protoRowType;
+
+ private final RelDataType rowType;
+
+ private final DataSchema schema;
+
+ final DataCollection<DataRow> rows;
+
+ BaremapsModifiableTable(String name,
+ RelProtoDataType protoRowType,
+ RelDataTypeFactory typeFactory) {
+ super();
+ this.name = requireNonNull(name, "name");
+ this.protoRowType = requireNonNull(protoRowType, "protoRowType");
+ this.rowType = this.protoRowType.apply(typeFactory);
+
+ // Create the schema
+ List<DataColumn> columns = rowType.getFieldList().stream().map(field -> {
+ String columnName = field.getName();
+ RelDataType relDataType = field.getType();
+ DataColumn.Cardinality columnCardinality = cardinalityFromRelDataType(relDataType);
+ DataColumn.Type columnType = typeFromRelDataType(relDataType);
+ return (DataColumn) new DataColumnFixed(columnName, columnCardinality, columnType);
+ }).toList();
+ this.schema = new DataSchema(name, columns);
+
+ // Create the collection
+ DataRowType dataRowType = new DataRowType(schema);
+ Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(Paths.get(this.name));
+ this.rows = AppendOnlyLog.<DataRow>builder().dataType(dataRowType).memory(memory).build();
+ }
+
+ @Override
+ public TableModify toModificationRel(
+ RelOptCluster cluster,
+ RelOptTable table,
+ Prepare.CatalogReader catalogReader,
+ RelNode child,
+ TableModify.Operation operation,
+ @Nullable List<String> updateColumnList,
+ @Nullable List<RexNode> sourceExpressionList,
+ boolean flattened) {
+ return LogicalTableModify.create(table, catalogReader, child, operation,
+ updateColumnList, sourceExpressionList, flattened);
+ }
+
+ private DataColumn.Cardinality cardinalityFromRelDataType(RelDataType columnType) {
+ if (columnType.getSqlTypeName() == SqlTypeName.ARRAY) {
+ return DataColumn.Cardinality.REPEATED;
+ } else if (columnType.isNullable()) {
+ return Cardinality.OPTIONAL;
+ } else {
+ return Cardinality.REQUIRED;
+ }
+ }
+
+ public static DataColumn.Type typeFromRelDataType(RelDataType relDataType) {
+ SqlTypeName sqlTypeName = relDataType.getSqlTypeName();
+ switch (sqlTypeName) {
+ case BOOLEAN:
+ return DataColumn.Type.BOOLEAN;
+ case TINYINT:
+ return DataColumn.Type.BYTE;
+ case SMALLINT:
+ return DataColumn.Type.SHORT;
+ case INTEGER:
+ return DataColumn.Type.INTEGER;
+ case BIGINT:
+ return DataColumn.Type.LONG;
+ case FLOAT:
+ case REAL:
+ return DataColumn.Type.FLOAT;
+ case DOUBLE:
+ case DECIMAL:
+ return DataColumn.Type.DOUBLE;
+ case CHAR:
+ case VARCHAR:
+ return DataColumn.Type.STRING;
+ case BINARY:
+ case VARBINARY:
+ return DataColumn.Type.BINARY;
+ case DATE:
+ return DataColumn.Type.LOCAL_DATE;
+ case TIME:
+ return DataColumn.Type.LOCAL_TIME;
+ case TIMESTAMP:
+ return DataColumn.Type.LOCAL_DATE_TIME;
+ case MAP:
+ return DataColumn.Type.NESTED;
+ case GEOMETRY:
+ return DataColumn.Type.GEOMETRY;
+ case ARRAY:
+ RelDataType componentType = requireNonNull(relDataType.getComponentType());
+ return typeFromRelDataType(componentType);
+ default:
+ throw new IllegalArgumentException("Unsupported Calcite type: " + sqlTypeName);
+ }
+ }
+
+ @Override
+ public Collection getModifiableCollection() {
+ return new CollectionAdapter();
+ }
+
+ @Override
+ public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema,
+ String tableName) {
+ return new AbstractTableQueryable<T>(queryProvider, schema, this,
+ tableName) {
+ @Override
+ public Enumerator<T> enumerator() {
+ return (Enumerator<T>) Linq4j.enumerator(new CollectionAdapter());
+ }
+ };
+ }
+
+ @Override
+ public Type getElementType() {
+ return Object[].class;
+ }
+
+ @Override
+ public Expression getExpression(SchemaPlus schema, String tableName, Class clazz) {
+ return Schemas.tableExpression(schema, getElementType(), tableName, clazz);
+ }
+
+ @Override
+ public RelDataType getRowType(final RelDataTypeFactory typeFactory) {
+ return rowType;
+ }
+
+ private class CollectionAdapter implements Collection<Object[]> {
+
+ private final int size;
+
+ public CollectionAdapter() {
+ this.size = (int) Math.min(rows.size(), Integer.MAX_VALUE);
+ }
- final DataCollection<DataRow> rows;
+ @Override
+ public int size() {
+ return size;
+ }
- BaremapsModifiableTable(String name,
- RelProtoDataType protoRowType,
- RelDataTypeFactory typeFactory) {
- super();
- this.name = requireNonNull(name, "name");
- this.protoRowType = requireNonNull(protoRowType, "protoRowType");
- this.rowType = this.protoRowType.apply(typeFactory);
+ @Override
+ public boolean isEmpty() {
+ return rows.isEmpty();
+ }
- // Create the schema
- List<DataColumn> columns = rowType.getFieldList().stream().map(field -> {
- String columnName = field.getName();
- RelDataType relDataType = field.getType();
- DataColumn.Cardinality columnCardinality = cardinalityFromRelDataType(relDataType);
- DataColumn.Type columnType = typeFromRelDataType(relDataType);
- return (DataColumn) new DataColumnFixed(columnName, columnCardinality, columnType);
- }).toList();
- this.schema = new DataSchema(name, columns);
+ @Override
+ public boolean contains(Object o) {
+ return rows.contains(o);
+ }
- // Create the collection
- DataRowType dataRowType = new DataRowType(schema);
- Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(Paths.get(this.name));
- this.rows = new AppendOnlyLog<>(dataRowType, memory);
+ @Override
+ public Iterator<Object[]> iterator() {
+ return rows.stream().map(row -> row.values().toArray()).iterator();
}
@Override
- public TableModify toModificationRel(
- RelOptCluster cluster,
- RelOptTable table,
- Prepare.CatalogReader catalogReader,
- RelNode child,
- TableModify.Operation operation,
- @Nullable List<String> updateColumnList,
- @Nullable List<RexNode> sourceExpressionList,
- boolean flattened) {
- return LogicalTableModify.create(table, catalogReader, child, operation,
- updateColumnList, sourceExpressionList, flattened);
+ public Object[] toArray() {
+ return rows.stream().map(row -> row.values().toArray()).toArray();
}
- private DataColumn.Cardinality cardinalityFromRelDataType(RelDataType columnType) {
- if (columnType.getSqlTypeName() == SqlTypeName.ARRAY) {
- return DataColumn.Cardinality.REPEATED;
- } else if (columnType.isNullable()) {
- return Cardinality.OPTIONAL;
- } else {
- return Cardinality.REQUIRED;
- }
+ @Override
+ public <T> T[] toArray(T[] a) {
+ return (T[]) rows.stream().map(row -> row.values().toArray()).toArray();
}
- public static DataColumn.Type typeFromRelDataType(RelDataType relDataType) {
- SqlTypeName sqlTypeName = relDataType.getSqlTypeName();
- switch (sqlTypeName) {
- case BOOLEAN:
- return DataColumn.Type.BOOLEAN;
- case TINYINT:
- return DataColumn.Type.BYTE;
- case SMALLINT:
- return DataColumn.Type.SHORT;
- case INTEGER:
- return DataColumn.Type.INTEGER;
- case BIGINT:
- return DataColumn.Type.LONG;
- case FLOAT:
- case REAL:
- return DataColumn.Type.FLOAT;
- case DOUBLE:
- case DECIMAL:
- return DataColumn.Type.DOUBLE;
- case CHAR:
- case VARCHAR:
- return DataColumn.Type.STRING;
- case BINARY:
- case VARBINARY:
- return DataColumn.Type.BINARY;
- case DATE:
- return DataColumn.Type.LOCAL_DATE;
- case TIME:
- return DataColumn.Type.LOCAL_TIME;
- case TIMESTAMP:
- return DataColumn.Type.LOCAL_DATE_TIME;
- case MAP:
- return DataColumn.Type.NESTED;
- case GEOMETRY:
- return DataColumn.Type.GEOMETRY;
- case ARRAY:
- RelDataType componentType = requireNonNull(relDataType.getComponentType());
- return typeFromRelDataType(componentType);
- default:
- throw new IllegalArgumentException("Unsupported Calcite type: " + sqlTypeName);
- }
+ @Override
+ public boolean add(Object[] objects) {
+ return rows.add(new DataRow(schema, List.of(objects)));
}
@Override
- public Collection getModifiableCollection() {
- return new CollectionAdapter();
+ public boolean remove(Object o) {
+ throw new UnsupportedOperationException();
}
@Override
- public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema,
- String tableName) {
- return new AbstractTableQueryable<T>(queryProvider, schema, this,
- tableName) {
- @Override
- public Enumerator<T> enumerator() {
- return (Enumerator<T>) Linq4j.enumerator(new CollectionAdapter());
- }
- };
+ public boolean containsAll(Collection<?> c) {
+ return rows.containsAll(c);
}
@Override
- public Type getElementType() {
- return Object[].class;
+ public boolean addAll(Collection<? extends Object[]> c) {
+ return rows.addAll(c.stream().map(objects -> new DataRow(schema, List.of(objects))).toList());
}
@Override
- public Expression getExpression(SchemaPlus schema, String tableName, Class clazz) {
- return Schemas.tableExpression(schema, getElementType(), tableName, clazz);
+ public boolean removeAll(Collection<?> c) {
+ throw new UnsupportedOperationException();
}
@Override
- public RelDataType getRowType(final RelDataTypeFactory typeFactory) {
- return rowType;
+ public boolean retainAll(Collection<?> c) {
+ throw new UnsupportedOperationException();
}
- private class CollectionAdapter implements Collection<Object[]> {
-
- private final int size;
-
- public CollectionAdapter() {
- this.size = (int) Math.min(rows.size(), Integer.MAX_VALUE);
- }
-
- @Override
- public int size() {
- return size;
- }
-
- @Override
- public boolean isEmpty() {
- return rows.isEmpty();
- }
-
- @Override
- public boolean contains(Object o) {
- return rows.contains(o);
- }
-
- @Override
- public Iterator<Object[]> iterator() {
- return rows.stream().map(row -> row.values().toArray()).iterator();
- }
-
- @Override
- public Object[] toArray() {
- return rows.stream().map(row -> row.values().toArray()).toArray();
- }
-
- @Override
- public <T> T[] toArray(T[] a) {
- return (T[]) rows.stream().map(row -> row.values().toArray()).toArray();
- }
-
- @Override
- public boolean add(Object[] objects) {
- return rows.add(new DataRow(schema, List.of(objects)));
- }
-
- @Override
- public boolean remove(Object o) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean containsAll(Collection<?> c) {
- return rows.containsAll(c);
- }
-
- @Override
- public boolean addAll(Collection<? extends Object[]> c) {
- return rows.addAll(c.stream().map(objects -> new DataRow(schema, List.of(objects))).toList());
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean retainAll(Collection<?> c) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void clear() {
- rows.clear();
- }
+ @Override
+ public void clear() {
+ rows.clear();
}
+ }
}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index e29f58f1d..e6516be4f 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
@@ -17,6 +17,9 @@
package org.apache.baremaps.calcite;
+import java.sql.*;
+import java.util.List;
+import java.util.Properties;
import org.apache.baremaps.calcite.DataColumn.Cardinality;
import org.apache.baremaps.calcite.DataColumn.Type;
import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
@@ -30,92 +33,97 @@ import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
-import java.sql.*;
-import java.util.List;
-import java.util.Properties;
-
public class CalciteTest {
- @Test
- @Disabled
- void sql() throws SQLException {
- GeometryFactory geometryFactory = new GeometryFactory();
-
- // Configure Calcite connection properties
- Properties info = new Properties();
- info.setProperty("lex", "MYSQL"); // Use MySQL dialect
- info.setProperty("caseSensitive", "false"); // Disable case sensitivity
- info.setProperty("unquotedCasing", "TO_LOWER"); // Convert unquoted identifiers to lowercase
- info.setProperty("quotedCasing", "TO_LOWER");
- info.setProperty("parserFactory", BaremapsDdlExecutor.class.getName() + "#PARSER_FACTORY");
- info.setProperty("materializationsEnabled", "true");
-
- try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
- CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
- SchemaPlus rootSchema = calciteConnection.getRootSchema();
-
- // Create and add 'city' table
- DataSchema cityRowType = new DataSchema("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
-
- DataTable cityDataTable = new BaremapsDataTable(
- cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(cityRowType))));
-
- cityDataTable.add(new DataRow(cityDataTable.schema(),
- List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRow(cityDataTable.schema(),
- List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
-
- DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
- rootSchema.add("city", cityDataTableAdapter);
-
- // Create and add 'population' table
- DataSchema populationRowType = new DataSchema("population", List.of(
- new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
-
- DataTable populationDataTable = new BaremapsDataTable(
- populationRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(populationRowType))));
-
- populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
- populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
-
- DataTableAdapter populationDataTableAdapter = new DataTableAdapter(populationDataTable);
- rootSchema.add("population", populationDataTableAdapter);
-
- String mv = "CREATE MATERIALIZED VIEW city_population AS "
- + "SELECT c.id, c.name, c.geometry, p.population "
- + "FROM city c "
- + "JOIN population p ON c.id = p.city_id";
-
- // Execute the SQL query
- try (Statement statement = connection.createStatement()) {
- statement.execute(mv);
- }
-
- // Debug: List all tables in the root schema
- System.out.println("Available tables in the root schema:");
- for (String tableName : rootSchema.getTableNames()) {
- System.out.println(" - " + tableName);
- }
-
- String sql = "SELECT * FROM city_population";
-
- // Execute the SQL query
- try (Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery(sql);
- while (resultSet.next()) {
- System.out.println(resultSet.getInt(1) + " " + resultSet.getString(2) + " " + resultSet.getString(3) + " " + resultSet.getInt(4));
- }
- }
-
-
+ @Test
+ @Disabled
+ void sql() throws SQLException {
+ GeometryFactory geometryFactory = new GeometryFactory();
+
+ // Configure Calcite connection properties
+ Properties info = new Properties();
+ info.setProperty("lex", "MYSQL"); // Use MySQL dialect
+ info.setProperty("caseSensitive", "false"); // Disable case sensitivity
+ info.setProperty("unquotedCasing", "TO_LOWER"); // Convert unquoted identifiers to lowercase
+ info.setProperty("quotedCasing", "TO_LOWER");
+ info.setProperty("parserFactory", BaremapsDdlExecutor.class.getName() + "#PARSER_FACTORY");
+ info.setProperty("materializationsEnabled", "true");
+
+ try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
+ CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
+
+ // Create and add 'city' table
+ DataSchema cityRowType = new DataSchema("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+
+ DataTable cityDataTable = new BaremapsDataTable(
+ cityRowType,
+ IndexedDataList.<DataRow>builder()
+ .values(AppendOnlyLog.<DataRow>builder()
+ .dataType(new DataRowType(cityRowType))
+ .build())
+ .build());
+
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
+ List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
+ List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
+
+ DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
+ rootSchema.add("city", cityDataTableAdapter);
+
+ // Create and add 'population' table
+ DataSchema populationRowType = new DataSchema("population", List.of(
+ new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
+
+ DataTable populationDataTable = new BaremapsDataTable(
+ populationRowType,
+ IndexedDataList.<DataRow>builder()
+ .values(AppendOnlyLog.<DataRow>builder()
+ .dataType(new DataRowType(populationRowType))
+ .build())
+ .build());
+
+ populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
+ populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
+
+ DataTableAdapter populationDataTableAdapter = new DataTableAdapter(populationDataTable);
+ rootSchema.add("population", populationDataTableAdapter);
+
+ String mv = "CREATE MATERIALIZED VIEW city_population AS "
+ + "SELECT c.id, c.name, c.geometry, p.population "
+ + "FROM city c "
+ + "JOIN population p ON c.id = p.city_id";
+
+ // Execute the SQL query
+ try (Statement statement = connection.createStatement()) {
+ statement.execute(mv);
+ }
+
+ // Debug: List all tables in the root schema
+ System.out.println("Available tables in the root schema:");
+ for (String tableName : rootSchema.getTableNames()) {
+ System.out.println(" - " + tableName);
+ }
+
+ String sql = "SELECT * FROM city_population";
+
+ // Execute the SQL query
+ try (Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sql);
+ while (resultSet.next()) {
+ System.out.println(resultSet.getInt(1) + " " + resultSet.getString(2) + " "
+ + resultSet.getString(3) + " " + resultSet.getInt(4));
}
+ }
+
}
+ }
+
}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java
index e5e089cef..52bd89d4d 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java
@@ -17,27 +17,12 @@
package org.apache.baremaps.calcite;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintWriter;
-import java.nio.ByteBuffer;
-import java.nio.MappedByteBuffer;
-import java.nio.file.Files;
-import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
-import java.util.List;
-import org.apache.baremaps.calcite.DataColumn.Cardinality;
-import org.apache.baremaps.calcite.DataColumn.Type;
-import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
-import org.apache.baremaps.data.collection.AppendOnlyLog;
-import org.apache.baremaps.data.memory.Memory;
-import org.apache.baremaps.data.memory.MemoryMappedDirectory;
-import org.apache.baremaps.data.util.FileUtils;
import org.junit.jupiter.api.Test;
-import org.locationtech.jts.geom.Coordinate;
-import org.locationtech.jts.geom.GeometryFactory;
class DataTableAdapterFactoryTest {
@@ -85,68 +70,68 @@ class DataTableAdapterFactoryTest {
}
}
- @Test
- public void createMMapTable() throws Exception {
- Path path = Files.createTempDirectory("temp");
-
- DataSchema dataSchema = new DataSchema("test", List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.REQUIRED, Type.STRING),
- new DataColumnFixed("geom", Cardinality.REQUIRED, Type.GEOMETRY)));
-
- // Serialize the schema
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- DataSchema.write(output, dataSchema);
- byte[] bytes = output.toByteArray();
-
- // Write the schema to the header of the memory mapped file
- Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(path);
- ByteBuffer header = memory.header();
- header.position(Long.BYTES);
- header.putInt(bytes.length);
- header.put(bytes);
-
- DataTable dataTable =
- new BaremapsDataTable(dataSchema,
- new AppendOnlyLog<>(new DataRowType(dataSchema), memory));
- dataTable.add(new DataRow(dataSchema,
- List.of(1, "a", new GeometryFactory().createPoint(new Coordinate(1, 1)))));
- dataTable.add(new DataRow(dataSchema,
- List.of(2, "b", new GeometryFactory().createPoint(new Coordinate(2, 2)))));
-
- dataTable.close();
-
-
- String model = """
- {
- version: '1.0',
- defaultSchema: 'TEST',
- schemas: [
- {
- name: 'TEST',
- tables: [
- {
- name: 'TEST',
- factory: 'org.apache.baremaps.calcite.DataTableFactory',
- operand: {
- format: 'baremaps',
- directory: '%s'
- }
- }
- ]
- }
- ]
- }
- """.formatted(path.toAbsolutePath());
- try (Connection connection =
- DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
-
- ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
- while (resultSet.next()) {
- System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
- }
- } finally {
- FileUtils.deleteRecursively(path);
- }
- }
+ // @Test
+ // public void createMMapTable() throws Exception {
+ // Path path = Files.createTempDirectory("temp");
+ //
+ // DataSchema dataSchema = new DataSchema("test", List.of(
+ // new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
+ // new DataColumnFixed("name", Cardinality.REQUIRED, Type.STRING),
+ // new DataColumnFixed("geom", Cardinality.REQUIRED, Type.GEOMETRY)));
+ //
+ // // Serialize the schema
+ // ByteArrayOutputStream output = new ByteArrayOutputStream();
+ // DataSchema.write(output, dataSchema);
+ // byte[] bytes = output.toByteArray();
+ //
+ // // Write the schema to the header of the memory mapped file
+ // Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(path);
+ // ByteBuffer header = memory.header();
+ // header.position(Long.BYTES);
+ // header.putInt(bytes.length);
+ // header.put(bytes);
+ //
+ // DataTable dataTable =
+ // new BaremapsDataTable(dataSchema,
+ // new AppendOnlyLog<>(new DataRowType(dataSchema), memory));
+ // dataTable.add(new DataRow(dataSchema,
+ // List.of(1, "a", new GeometryFactory().createPoint(new Coordinate(1, 1)))));
+ // dataTable.add(new DataRow(dataSchema,
+ // List.of(2, "b", new GeometryFactory().createPoint(new Coordinate(2, 2)))));
+ //
+ // dataTable.close();
+ //
+ //
+ // String model = """
+ // {
+ // version: '1.0',
+ // defaultSchema: 'TEST',
+ // schemas: [
+ // {
+ // name: 'TEST',
+ // tables: [
+ // {
+ // name: 'TEST',
+ // factory: 'org.apache.baremaps.calcite.DataTableFactory',
+ // operand: {
+ // format: 'baremaps',
+ // directory: '%s'
+ // }
+ // }
+ // ]
+ // }
+ // ]
+ // }
+ // """.formatted(path.toAbsolutePath());
+ // try (Connection connection =
+ // DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
+ //
+ // ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
+ // while (resultSet.next()) {
+ // System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
+ // }
+ // } finally {
+ // FileUtils.deleteRecursively(path);
+ // }
+ // }
}
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
deleted file mode 100644
index 6eb62f014..000000000
--- a/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
+++ /dev/null
@@ -1,120 +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.calcite;
-
-// import com.google.common.collect.ImmutableList;
-// import java.sql.*;
-// import java.util.List;
-// import java.util.Properties;
-// import org.apache.baremaps.data.calcite.BaremapsTable;
-// import org.apache.baremaps.data.collection.AppendOnlyLog;
-// import org.apache.baremaps.data.collection.IndexedDataList;
-// import org.apache.baremaps.calcite.data.DataTableImpl;
-// import org.apache.baremaps.calcite.data.DataTypeImpl;
-// import org.apache.baremaps.maplibre.vectortile.VectorTileFunctions;
-// import org.apache.baremaps.store.*;
-// import org.apache.baremaps.calcite.DataColumn.Cardinality;
-// import org.apache.baremaps.calcite.DataColumn.Type;
-// import org.apache.calcite.jdbc.CalciteConnection;
-// import org.apache.calcite.model.ModelHandler;
-// import org.apache.calcite.runtime.AccumOperation;
-// import org.apache.calcite.runtime.CollectOperation;
-// import org.apache.calcite.runtime.SpatialTypeFunctions;
-// import org.apache.calcite.runtime.UnionOperation;
-// import org.apache.calcite.schema.SchemaPlus;
-// import org.apache.calcite.schema.impl.AggregateFunctionImpl;
-// import org.apache.calcite.sql.fun.SqlSpatialTypeFunctions;
-// import org.junit.jupiter.api.Assertions;
-// import org.junit.jupiter.api.Test;
-// import org.locationtech.jts.geom.*;
-
-class CalciteTest {
- //
- // @Test
- // void test() throws SQLException {
- // GeometryFactory geometryFactory = new GeometryFactory();
- //
- // Properties info = new Properties();
- // info.setProperty("lex", "MYSQL");
- //
- // try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
- // CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
- // SchemaPlus rootSchema = calciteConnection.getRootSchema();
- //
- // // Add the spatial functions to the root schema
- // ImmutableList<String> emptyPath = ImmutableList.of();
- // ModelHandler.addFunctions(rootSchema, null, emptyPath,
- // SpatialTypeFunctions.class.getName(), "*", true);
- // ModelHandler.addFunctions(rootSchema, null, emptyPath,
- // SqlSpatialTypeFunctions.class.getName(), "*", true);
- //
- // rootSchema.add("ST_UNION", AggregateFunctionImpl.create(UnionOperation.class));
- // rootSchema.add("ST_ACCUM", AggregateFunctionImpl.create(AccumOperation.class));
- // rootSchema.add("ST_COLLECT", AggregateFunctionImpl.create(CollectOperation.class));
- //
- // ModelHandler.addFunctions(rootSchema, "ST_AsMVTGeom", emptyPath,
- // VectorTileFunctions.class.getName(), "asVectorTileGeom", true);
- // ModelHandler.addFunctions(rootSchema, "ST_AsMVT", emptyPath,
- // VectorTileFunctions.class.getName(), "asVectorTile", true);
- //
- // // Create the city table
- // DataSchema cityRowType = new DataSchemaImpl("city", List.of(
- // new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- // new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- // new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
- // DataTable cityDataTable = new DataTableImpl(
- // cityRowType,
- // new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(cityRowType))));
- // cityDataTable.add(new DataRow(cityDataTable.schema(),
- // List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- // cityDataTable.add(new DataRow(cityDataTable.schema(),
- // List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
- // BaremapsTable cityBaremapsTable = new BaremapsTable(cityDataTable);
- // rootSchema.add("city", cityBaremapsTable);
- //
- // // Create the population table
- // DataSchema populationRowType = new DataSchemaImpl("population", List.of(
- // new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
- // new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
- // DataTable populationDataTable = new DataTableImpl(
- // populationRowType,
- // new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(populationRowType))));
- // populationDataTable
- // .add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
- // populationDataTable
- // .add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
- // BaremapsTable populationBaremapsTable = new BaremapsTable(populationDataTable);
- // rootSchema.add("population", populationBaremapsTable);
- //
- // // Query the database
- // String sql = """
- // SELECT ST_AsText(ST_AsMVTGeom(
- // ST_GeomFromText('POLYGON ((0 0, 10 1, 10 10, 1 10, 0 0))'),
- // ST_MakeEnvelope(0, 0, 4096, 4096),
- // 4096, 0, true))
- // """;
- //
- // try (Statement statement = connection.createStatement();
- // ResultSet resultSet = statement.executeQuery(sql)) {
- // Assertions.assertTrue(resultSet.next());
- // Assertions.assertEquals("POLYGON ((0 4096, 10 4095, 10 4086, 1 4086, 0 4096))",
- // resultSet.getString(1));
- // }
- // }
- // }
-}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollection.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollection.java
index c4458d180..5c5f549f6 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollection.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollection.java
@@ -17,7 +17,6 @@
package org.apache.baremaps.data.collection;
-import java.io.Closeable;
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollectionMapper.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollectionMapper.java
index 9cca2c1ca..9ab9101c4 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollectionMapper.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollectionMapper.java
@@ -18,7 +18,6 @@
package org.apache.baremaps.data.collection;
-import java.io.IOException;
import java.util.Iterator;
import java.util.function.Function;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataConversions.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataConversions.java
index d431ca77b..8f1957c16 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataConversions.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataConversions.java
@@ -17,8 +17,6 @@
package org.apache.baremaps.data.collection;
-import java.io.Closeable;
-import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/FixedSizeDataList.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/FixedSizeDataList.java
index 7ae4fc233..5c7b57478 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/FixedSizeDataList.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/FixedSizeDataList.java
@@ -19,7 +19,6 @@ package org.apache.baremaps.data.collection;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.baremaps.data.memory.Memory;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataList.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataList.java
index d7427b37c..1a14640f5 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataList.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataList.java
@@ -19,7 +19,6 @@ package org.apache.baremaps.data.collection;
-import java.io.IOException;
import org.apache.baremaps.data.type.LongDataType;
/**
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java
index 110f16eeb..cb637dc39 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java
@@ -57,10 +57,7 @@ public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
}
/**
-<<<<<<< HEAD
- * Returns the size of each segment.
-=======
- * Returns the size of the header.
+ * <<<<<<< HEAD Returns the size of each segment. ======= Returns the size of the header.
*
* @return the size of the header
*/
@@ -69,8 +66,7 @@ public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
}
/**
- * Returns the size of the segments.
->>>>>>> 251ea904 (Add header to memory)
+ * Returns the size of the segments. >>>>>>> 251ea904 (Add header to memory)
*
* @return the segment size in bytes
*/
@@ -157,7 +153,7 @@ public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
}
T segment = segments.get(index);
if (segment == null) {
- segment = allocate(index, segmentSize);
+ segment = allocateSegment(index);
segments.set(index, segment);
}
return segment;
diff --git a/pom.xml b/pom.xml
index a2af58698..2986bf531 100644
--- a/pom.xml
+++ b/pom.xml
@@ -589,11 +589,6 @@ limitations under the License.
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
(incubator-baremaps) 11/12: Some progress
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit bed98b0ef03fd46f2ca3e74ed4dce4d36f5709c5
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Wed Feb 26 10:32:46 2025 +0100
Some progress
---
.../apache/baremaps/calcite/DataTableAdapter.java | 8 -
...erDdlExecutor.java => BaremapsDdlExecutor.java} | 54 ++----
.../calcite/baremaps/BaremapsMaterializedView.java | 6 +-
...ableTable.java => BaremapsModifiableTable.java} | 22 +--
.../apache/baremaps/calcite/BaremapsContext.java | 73 --------
.../apache/baremaps/calcite/CalciteDdlTest.java | 206 ---------------------
.../org/apache/baremaps/calcite/CalciteTest.java | 4 +-
7 files changed, 20 insertions(+), 353 deletions(-)
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
index b1fc3619b..2f244f1cc 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
@@ -72,18 +72,10 @@ public class DataTableAdapter extends AbstractTable implements ScannableTable {
private final DataTable table;
- private final RelProtoDataType protoRowType;
-
private RelDataType rowType;
public DataTableAdapter(DataTable table) {
this.table = table;
- this.protoRowType = null;
- }
-
- public DataTableAdapter(DataTable table, RelProtoDataType protoRowType) {
- this.table = table;
- this.protoRowType = protoRowType;
}
@Override
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/ServerDdlExecutor.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDdlExecutor.java
similarity index 93%
rename from baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/ServerDdlExecutor.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDdlExecutor.java
index 0c2650f63..206067735 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/ServerDdlExecutor.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDdlExecutor.java
@@ -97,11 +97,7 @@ import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql2rel.InitializerContext;
import org.apache.calcite.sql2rel.InitializerExpressionFactory;
import org.apache.calcite.sql2rel.NullInitializerExpressionFactory;
-import org.apache.calcite.tools.FrameworkConfig;
-import org.apache.calcite.tools.Frameworks;
-import org.apache.calcite.tools.Planner;
-import org.apache.calcite.tools.RelConversionException;
-import org.apache.calcite.tools.ValidationException;
+import org.apache.calcite.tools.*;
import org.apache.calcite.util.NlsString;
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;
@@ -115,9 +111,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* appropriate {@code execute} method. For example, "CREATE TABLE" ({@link SqlCreateTable}) is
* dispatched to {@link #execute(SqlCreateTable, CalcitePrepare.Context)}.
*/
-public class ServerDdlExecutor extends DdlExecutorImpl {
+public class BaremapsDdlExecutor extends DdlExecutorImpl {
/** Singleton instance. */
- public static final ServerDdlExecutor INSTANCE = new ServerDdlExecutor();
+ public static final BaremapsDdlExecutor INSTANCE = new BaremapsDdlExecutor();
/** Parser factory. */
@SuppressWarnings("unused") // used via reflection
@@ -130,7 +126,7 @@ public class ServerDdlExecutor extends DdlExecutorImpl {
@Override
public DdlExecutor getDdlExecutor() {
- return ServerDdlExecutor.INSTANCE;
+ return BaremapsDdlExecutor.INSTANCE;
}
};
@@ -138,7 +134,7 @@ public class ServerDdlExecutor extends DdlExecutorImpl {
* Creates a ServerDdlExecutor. Protected only to allow sub-classing; use {@link #INSTANCE} where
* possible.
*/
- protected ServerDdlExecutor() {}
+ protected BaremapsDdlExecutor() {}
/**
* Returns the schema in which to create an object; the left part is null if the schema does not
@@ -208,8 +204,8 @@ public class ServerDdlExecutor extends DdlExecutorImpl {
final CalciteSchema.TableEntry tableEntry =
calciteSchema.getTable(tblName, context.config().caseSensitive());
final Table table = requireNonNull(tableEntry, "tableEntry").getTable();
- if (table instanceof BaremapsMutableTable) {
- BaremapsMutableTable mutableArrayTable = (BaremapsMutableTable) table;
+ if (table instanceof BaremapsModifiableTable) {
+ BaremapsModifiableTable mutableArrayTable = (BaremapsModifiableTable) table;
mutableArrayTable.rows.clear();
} else {
// Not calcite-server created, so not support truncate.
@@ -428,8 +424,7 @@ public class ServerDdlExecutor extends DdlExecutorImpl {
// Table does not exist. Create it.
final BaremapsMaterializedView table =
- new BaremapsMaterializedView(pair.right, RelDataTypeImpl.proto(rowType),
- NullInitializerExpressionFactory.INSTANCE, context.getTypeFactory());
+ new BaremapsMaterializedView(pair.right, RelDataTypeImpl.proto(rowType), context.getTypeFactory());
pair.left.add(pair.right, table);
populate(create.name, create.query, context);
table.key =
@@ -545,31 +540,6 @@ public class ServerDdlExecutor extends DdlExecutorImpl {
}
}
final RelDataType rowType = builder.build();
- final RelDataType storedRowType = storedBuilder.build();
- final List<ColumnDef> columns = b.build();
- final InitializerExpressionFactory ief =
- new NullInitializerExpressionFactory() {
- @Override
- public ColumnStrategy generationStrategy(RelOptTable table,
- int iColumn) {
- return columns.get(iColumn).strategy;
- }
-
- @Override
- public RexNode newColumnDefaultValue(RelOptTable table,
- int iColumn, InitializerContext context) {
- final ColumnDef c = columns.get(iColumn);
- if (c.expr != null) {
- // REVIEW Danny 2019-10-09: Should we support validation for DDL nodes?
- final SqlNode validated = context.validateExpression(storedRowType, c.expr);
- // The explicit specified type should have the same nullability
- // with the column expression inferred type,
- // actually they should be exactly the same.
- return context.convertExpression(validated);
- }
- return super.newColumnDefaultValue(table, iColumn, context);
- }
- };
if (pair.left.plus().getTable(pair.right) != null) {
// Table exists.
if (create.ifNotExists) {
@@ -583,8 +553,8 @@ public class ServerDdlExecutor extends DdlExecutorImpl {
}
// Table does not exist. Create it.
pair.left.add(pair.right,
- new BaremapsMutableTable(pair.right,
- RelDataTypeImpl.proto(rowType), ief, context.getTypeFactory()));
+ new BaremapsModifiableTable(pair.right,
+ RelDataTypeImpl.proto(rowType), context.getTypeFactory()));
if (create.query != null) {
populate(create.name, create.query, context);
}
@@ -643,8 +613,8 @@ public class ServerDdlExecutor extends DdlExecutorImpl {
final RelDataType rowType = table.getRowType(typeFactory);
// Table does not exist. Create it.
pair.left.add(pair.right,
- new BaremapsMutableTable(pair.right,
- RelDataTypeImpl.proto(rowType), ief, typeFactory));
+ new BaremapsModifiableTable(pair.right,
+ RelDataTypeImpl.proto(rowType), typeFactory));
}
/** Executes a {@code CREATE TYPE} command. */
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java
index 2e24553be..da3f1b722 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java
@@ -22,11 +22,10 @@ import org.apache.calcite.materialize.MaterializationKey;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.schema.Schema;
-import org.apache.calcite.sql2rel.InitializerExpressionFactory;
import org.checkerframework.checker.nullness.qual.Nullable;
/** A table that implements a materialized view. */
-class BaremapsMaterializedView extends BaremapsMutableTable {
+class BaremapsMaterializedView extends BaremapsModifiableTable {
/**
* The key with which this was stored in the materialization service, or null if not (yet)
* materialized.
@@ -37,9 +36,8 @@ class BaremapsMaterializedView extends BaremapsMutableTable {
BaremapsMaterializedView(
String name,
RelProtoDataType protoRowType,
- InitializerExpressionFactory initializerExpressionFactory,
RelDataTypeFactory typeFactory) {
- super(name, protoRowType, initializerExpressionFactory, typeFactory);
+ super(name, protoRowType, typeFactory);
}
@Override
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMutableTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsModifiableTable.java
similarity index 91%
rename from baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMutableTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsModifiableTable.java
index d54a84bf3..58bfd1255 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMutableTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsModifiableTable.java
@@ -45,7 +45,6 @@ import org.apache.calcite.schema.Wrapper;
import org.apache.calcite.schema.impl.AbstractTable;
import org.apache.calcite.schema.impl.AbstractTableQueryable;
import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.sql2rel.InitializerExpressionFactory;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.lang.reflect.Type;
@@ -58,12 +57,10 @@ import java.util.List;
import static java.util.Objects.requireNonNull;
-class BaremapsMutableTable extends AbstractTable implements ModifiableTable, Wrapper {
+class BaremapsModifiableTable extends AbstractTable implements ModifiableTable, Wrapper {
private final String name;
- private final InitializerExpressionFactory initializerExpressionFactory;
-
private final RelProtoDataType protoRowType;
private final RelDataType rowType;
@@ -72,14 +69,11 @@ class BaremapsMutableTable extends AbstractTable implements ModifiableTable, Wra
final DataCollection<DataRow> rows;
- BaremapsMutableTable(String name,
- RelProtoDataType protoRowType,
- InitializerExpressionFactory initializerExpressionFactory,
- RelDataTypeFactory typeFactory) {
+ BaremapsModifiableTable(String name,
+ RelProtoDataType protoRowType,
+ RelDataTypeFactory typeFactory) {
super();
this.name = requireNonNull(name, "name");
- this.initializerExpressionFactory =
- requireNonNull(initializerExpressionFactory, "initializerExpressionFactory");
this.protoRowType = requireNonNull(protoRowType, "protoRowType");
this.rowType = this.protoRowType.apply(typeFactory);
@@ -198,14 +192,6 @@ class BaremapsMutableTable extends AbstractTable implements ModifiableTable, Wra
return rowType;
}
- @Override
- public <C extends Object> @Nullable C unwrap(Class<C> aClass) {
- if (aClass.isInstance(initializerExpressionFactory)) {
- return aClass.cast(initializerExpressionFactory);
- }
- return super.unwrap(aClass);
- }
-
private class CollectionAdapter implements Collection<Object[]> {
private final int size;
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsContext.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsContext.java
deleted file mode 100644
index 8b94e123e..000000000
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsContext.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.apache.baremaps.calcite;
-
-import org.apache.calcite.DataContext;
-import org.apache.calcite.adapter.java.JavaTypeFactory;
-import org.apache.calcite.config.CalciteConnectionConfig;
-import org.apache.calcite.jdbc.CalcitePrepare;
-import org.apache.calcite.jdbc.CalcitePrepare.SparkHandler;
-import org.apache.calcite.jdbc.CalciteSchema;
-import org.apache.calcite.tools.RelRunner;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-import java.util.List;
-
-public class BaremapsContext implements CalcitePrepare.Context {
-
- private final JavaTypeFactory typeFactory;
-
- private final CalciteSchema rootSchema;
-
- private final RelRunner planner;
-
- public BaremapsContext(JavaTypeFactory typeFactory, CalciteSchema rootSchema, RelRunner planner) {
- this.typeFactory = typeFactory;
- this.rootSchema = rootSchema;
- this.planner = planner;
- }
-
- @Override
- public JavaTypeFactory getTypeFactory() {
- return typeFactory;
- }
-
- @Override
- public CalciteSchema getRootSchema() {
- return rootSchema;
- }
-
- @Override
- public CalciteSchema getMutableRootSchema() {
- return rootSchema;
- }
-
- @Override
- public List<String> getDefaultSchemaPath() {
- return List.of();
- }
-
- @Override
- public CalciteConnectionConfig config() {
- return null;
- }
-
- @Override
- public SparkHandler spark() {
- return null;
- }
-
- @Override
- public DataContext getDataContext() {
- return null;
- }
-
- @Override
- public @Nullable List<String> getObjectPath() {
- return null;
- }
-
- @Override
- public RelRunner getRelRunner() {
- return planner;
- }
-
-}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteDdlTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteDdlTest.java
deleted file mode 100644
index b4d035366..000000000
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteDdlTest.java
+++ /dev/null
@@ -1,206 +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.calcite;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.baremaps.calcite.DataColumn.Cardinality;
-import org.apache.baremaps.calcite.DataColumn.Type;
-import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
-import org.apache.baremaps.calcite.baremaps.ServerDdlExecutor;
-import org.apache.baremaps.data.collection.AppendOnlyLog;
-import org.apache.baremaps.data.collection.IndexedDataList;
-import org.apache.calcite.DataContext;
-import org.apache.calcite.DataContexts;
-import org.apache.calcite.config.Lex;
-import org.apache.calcite.interpreter.Interpreter;
-import org.apache.calcite.jdbc.CalciteSchema;
-import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
-import org.apache.calcite.linq4j.Enumerable;
-import org.apache.calcite.linq4j.Linq4j;
-import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.schema.ScannableTable;
-import org.apache.calcite.schema.SchemaPlus;
-import org.apache.calcite.schema.Table;
-import org.apache.calcite.schema.impl.AbstractSchema;
-import org.apache.calcite.schema.impl.AbstractTable;
-import org.apache.calcite.sql.*;
-import org.apache.calcite.sql.ddl.SqlCreateMaterializedView;
-import org.apache.calcite.sql.ddl.SqlCreateTable;
-import org.apache.calcite.sql.parser.SqlParser;
-import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.tools.FrameworkConfig;
-import org.apache.calcite.tools.Frameworks;
-import org.apache.calcite.tools.Planner;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-import org.locationtech.jts.geom.Coordinate;
-import org.locationtech.jts.geom.GeometryFactory;
-
-public class CalciteDdlTest {
-
-
- public class ListTable extends AbstractTable implements ScannableTable {
- private final List<Integer> data;
-
- public ListTable(List<Integer> data) {
- this.data = data;
- }
-
- @Override
- public RelDataType getRowType(RelDataTypeFactory typeFactory) {
- // Define a single column named "value" of type INTEGER
- return typeFactory.builder()
- .add("V", SqlTypeName.INTEGER)
- .build();
- }
-
- @Override
- public Enumerable<Object[]> scan(DataContext root) {
- // Convert the List<Integer> to Enumerable<Object[]>
- return Linq4j.asEnumerable(data)
- .select(i -> new Object[] {i});
- }
- }
-
- public class ListSchema extends AbstractSchema {
- private final List<Integer> listA;
- private final List<Integer> listB;
-
- public ListSchema(List<Integer> listA, List<Integer> listB) {
- this.listA = listA;
- this.listB = listB;
- }
-
- @Override
- protected Map<String, Table> getTableMap() {
- Map<String, Table> tables = new HashMap<>();
- tables.put("LIST_A", new ListTable(listA));
- tables.put("LIST_B", new ListTable(listB)); // Initially empty
- return tables;
- }
- }
-
- @Test
- @Disabled
- void test() throws Exception {
- // Initialize your Java lists
- List<Integer> listA = List.of(1, 2, 3, 4, 5);
- List<Integer> listB = new ArrayList<>();
-
- // Set up Calcite schema
- CalciteSchema rootSchema = CalciteSchema.createRootSchema(true);
- rootSchema.add("MY_SCHEMA", new ListSchema(listA, listB));
-
- // Create and add 'city' table
- DataSchema cityRowType = new DataSchema("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
-
- DataTable cityDataTable = new BaremapsDataTable(
- cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(cityRowType))));
-
- GeometryFactory geometryFactory = new GeometryFactory();
- cityDataTable.add(new DataRow(cityDataTable.schema(),
- List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRow(cityDataTable.schema(),
- List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
-
- DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
- rootSchema.add("CITY", cityDataTableAdapter);
-
- // Create and add 'population' table
- DataSchema populationRowType = new DataSchema("population", List.of(
- new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
-
- DataTable populationDataTable = new BaremapsDataTable(
- populationRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(populationRowType))));
-
- populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
- populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
-
- DataTableAdapter populationDataTableAdapter = new DataTableAdapter(populationDataTable);
- rootSchema.add("population", populationDataTableAdapter);
-
- // Configure the parser
- SqlParser.Config parserConfig = SqlParser.configBuilder()
- .setLex(Lex.MYSQL)
- .setParserFactory(ServerDdlExecutor.PARSER_FACTORY)
- .build();
-
- // Configure the framework
- FrameworkConfig config = Frameworks.newConfigBuilder()
- .defaultSchema(rootSchema.plus())
- .parserConfig(parserConfig)
- .build();
-
- // Create a planner
- Planner planner = Frameworks.getPlanner(config);
-
- // Define the SQL query to populate list_b from list_a
- String sql = "CREATE MATERIALIZED VIEW city_population AS "
- + "SELECT c.id, c.name, c.geometry, p.population "
- + "FROM CITY c "
- + "JOIN population p ON c.id = p.city_id";
-
- // Parse the SQL query
- SqlNode parsed = planner.parse(sql);
-
- // Create a context
- //BaremapsContext context = new BaremapsContext(new JavaTypeFactoryImpl(), rootSchema, Frameworks.);
-
- // Create an executor
- //ServerDdlExecutor.INSTANCE.execute((SqlCreateMaterializedView) parsed, context);
-
-// // Extract the select statement from the parsed SQL query
-// SqlNode select;
-// if (parsed instanceof SqlCreateMaterializedView createMaterializedView) {
-// List<SqlNode> operands = createMaterializedView.getOperandList();
-// select = operands.get(operands.size() - 1);
-// System.out.println(select);
-// } else {
-// throw new IllegalArgumentException(
-// "Expected a CREATE MATERIALIZED VIEW statement, but got: " + parsed.getKind());
-// }
-//
-// // Validate the SQL query
-// SqlNode validated = planner.validate(select);
-//
-// // Convert the SQL query to a relational expression
-// RelNode rel = planner.rel(validated).rel;
-//
-// try (Interpreter interpreter = new Interpreter(DataContexts.EMPTY, rel)) {
-// // Create an interpreter to execute the RelNode
-// for (Object[] row : interpreter) {
-// listB.add((Integer) row[0]);
-// }
-// }
-//
-// // Display the results
-// System.out.println("List A: " + listA);
-// System.out.println("List B (after SQL): " + listB);
- }
-}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index 82a02d1cc..e29f58f1d 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
@@ -20,7 +20,7 @@ package org.apache.baremaps.calcite;
import org.apache.baremaps.calcite.DataColumn.Cardinality;
import org.apache.baremaps.calcite.DataColumn.Type;
import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
-import org.apache.baremaps.calcite.baremaps.ServerDdlExecutor;
+import org.apache.baremaps.calcite.baremaps.BaremapsDdlExecutor;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
import org.apache.calcite.jdbc.CalciteConnection;
@@ -47,7 +47,7 @@ public class CalciteTest {
info.setProperty("caseSensitive", "false"); // Disable case sensitivity
info.setProperty("unquotedCasing", "TO_LOWER"); // Convert unquoted identifiers to lowercase
info.setProperty("quotedCasing", "TO_LOWER");
- info.setProperty("parserFactory", ServerDdlExecutor.class.getName() + "#PARSER_FACTORY");
+ info.setProperty("parserFactory", BaremapsDdlExecutor.class.getName() + "#PARSER_FACTORY");
info.setProperty("materializationsEnabled", "true");
try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
(incubator-baremaps) 01/12: Experiments with calcite
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit b24d78403ee01bb7cec5ba3d4cf7046f8421e7c7
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Mon Jan 13 08:26:18 2025 +0100
Experiments with calcite
---
.../org/apache/baremaps/calcite/CalciteTest.java | 2 +-
baremaps-data/pom.xml | 4 +
.../data/{store => calcite}/BaremapsDataTable.java | 2 +-
.../data/calcite/CalciteMultipleDDLParser.java | 14 ++
.../apache/baremaps/data/calcite/CalciteTest.java | 170 +++++++++++++++++++++
pom.xml | 7 +-
6 files changed, 196 insertions(+), 3 deletions(-)
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 482d15885..df1deb0dc 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
@@ -22,10 +22,10 @@ import com.google.common.collect.ImmutableList;
import java.sql.*;
import java.util.List;
import java.util.Properties;
+import org.apache.baremaps.data.calcite.BaremapsDataTable;
import org.apache.baremaps.data.calcite.SqlDataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
-import org.apache.baremaps.data.store.BaremapsDataTable;
import org.apache.baremaps.data.type.RowDataType;
import org.apache.baremaps.maplibre.vectortile.VectorTileFunctions;
import org.apache.baremaps.store.*;
diff --git a/baremaps-data/pom.xml b/baremaps-data/pom.xml
index c3275b1f2..658c5ff71 100644
--- a/baremaps-data/pom.xml
+++ b/baremaps-data/pom.xml
@@ -38,6 +38,10 @@ limitations under the License.
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.calcite</groupId>
+ <artifactId>calcite-server</artifactId>
+ </dependency>
<dependency>
<groupId>org.roaringbitmap</groupId>
<artifactId>RoaringBitmap</artifactId>
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/BaremapsDataTable.java
similarity index 97%
rename from baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java
rename to baremaps-data/src/main/java/org/apache/baremaps/data/calcite/BaremapsDataTable.java
index 89123dab6..55ddee115 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/BaremapsDataTable.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.store;
+package org.apache.baremaps.data.calcite;
import java.util.Iterator;
import org.apache.baremaps.data.collection.DataCollection;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/CalciteMultipleDDLParser.java b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/CalciteMultipleDDLParser.java
new file mode 100644
index 000000000..04984fd3e
--- /dev/null
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/CalciteMultipleDDLParser.java
@@ -0,0 +1,14 @@
+package org.apache.baremaps.data.calcite;
+
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+
+public class CalciteMultipleDDLParser {
+ public static void main(String[] args) throws Exception {
+
+ }
+}
diff --git a/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java b/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
new file mode 100644
index 000000000..52768a70d
--- /dev/null
+++ b/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
@@ -0,0 +1,170 @@
+/*
+ * 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.calcite;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.baremaps.data.collection.AppendOnlyLog;
+import org.apache.baremaps.data.collection.IndexedDataList;
+import org.apache.baremaps.data.type.RowDataType;
+import org.apache.baremaps.store.DataColumn.Cardinality;
+import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.*;
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.model.ModelHandler;
+import org.apache.calcite.runtime.SpatialTypeFunctions;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.impl.ViewTable;
+import org.apache.calcite.schema.impl.ViewTableMacro;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.fun.SqlSpatialTypeFunctions;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.junit.jupiter.api.Test;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.GeometryFactory;
+
+import java.sql.*;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+public class CalciteTest {
+
+ @Test
+ void sql() throws SQLException {
+ GeometryFactory geometryFactory = new GeometryFactory();
+
+ // Configure Calcite connection properties
+ Properties info = new Properties();
+ info.setProperty("lex", "MYSQL"); // Use MySQL dialect
+ info.setProperty("caseSensitive", "false"); // Disable case sensitivity
+ info.setProperty("unquotedCasing", "TO_LOWER"); // Convert unquoted identifiers to lowercase
+ info.setProperty("quotedCasing", "TO_LOWER");
+
+ try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
+ CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
+
+ // Create and add 'city' table
+ DataSchema cityRowType = new DataSchemaImpl("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+
+ DataTable cityDataTable = new BaremapsDataTable(
+ cityRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType))));
+
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
+
+ SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
+ rootSchema.add("city", citySqlDataTable);
+
+ // Create and add 'population' table
+ DataSchema populationRowType = new DataSchemaImpl("population", List.of(
+ new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
+
+ DataTable populationDataTable = new BaremapsDataTable(
+ populationRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(populationRowType))));
+
+ populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(1, 2_161_000)));
+ populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(2, 8_336_000)));
+
+ SqlDataTable populationSqlDataTable = new SqlDataTable(populationDataTable);
+ rootSchema.add("population", populationSqlDataTable);
+
+ // Create view 'city_population'
+ String mvSql = "SELECT c.id, c.name, c.geometry, p.population " +
+ "FROM city c " + // lowercase and unquoted
+ "JOIN population p ON c.id = p.city_id";
+
+ ViewTableMacro materializedView = ViewTable.viewMacro(
+ rootSchema,
+ mvSql,
+ Collections.emptyList(), // Schema path
+ List.of("city_population"), // Name parts
+ false); // Not a materialized view
+
+ rootSchema.add("city_population", materializedView);
+
+ // Debug: List all tables in the root schema
+ System.out.println("Available tables in the root schema:");
+ for (String tableName : rootSchema.getTableNames()) {
+ System.out.println(" - " + tableName);
+ }
+
+ String sql = "SELECT * FROM city";
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(sql)) {
+ while (resultSet.next()) {
+ System.out.println(resultSet.getString("id") + " " + resultSet.getString("name"));
+ }
+ }
+
+ // Query the view
+ sql = "SELECT * FROM city_population";
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(sql)) {
+ while (resultSet.next()) {
+ System.out.println(
+ resultSet.getString("id") + " " + resultSet.getString("name")
+ );
+ }
+ }
+ }
+
+ }
+
+ @Test
+ void ddl() throws SqlParseException {
+
+ // Example SQL script with multiple DDL statements
+ String sqlScript = """
+ CREATE MATERIALIZED VIEW IF NOT EXISTS my_view AS
+ SELECT * FROM my_table;
+ """;
+
+ // Build a parser config that supports DDL
+ SqlParser.Config config = SqlParser.configBuilder()
+ .setParserFactory(SqlDdlParserImpl.FACTORY)
+ .setConformance(SqlConformanceEnum.BABEL)
+ .setLex(Lex.MYSQL)
+ .build();
+
+ // Create the parser from the config
+ SqlParser parser = SqlParser.create(sqlScript, config);
+
+ // Parse the script as a list of statements
+ SqlNodeList sqlNodeList = parser.parseStmtList();
+
+ // Iterate and print each parsed statement
+ for (SqlNode sqlNode : sqlNodeList) {
+ System.out.println("Parsed statement: " + sqlNode.toString());
+ }
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 064bbbafc..5ca3c9b7d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,7 +86,7 @@ limitations under the License.
<version.lib.awssdk>2.27.17</version.lib.awssdk>
<version.lib.brotli4j>1.16.0</version.lib.brotli4j>
<version.lib.caffeine>3.1.8</version.lib.caffeine>
- <version.lib.calcite>1.37.0</version.lib.calcite>
+ <version.lib.calcite>1.38.0</version.lib.calcite>
<version.lib.commons-compress>1.27.1</version.lib.commons-compress>
<version.lib.fastutil>8.5.14</version.lib.fastutil>
<version.lib.flatgeobuf>3.26.2</version.lib.flatgeobuf>
@@ -346,6 +346,11 @@ limitations under the License.
<artifactId>calcite-core</artifactId>
<version>${version.lib.calcite}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.calcite</groupId>
+ <artifactId>calcite-server</artifactId>
+ <version>${version.lib.calcite}</version>
+ </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
(incubator-baremaps) 10/12: Add the server ddl class and implement materialized views
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit f5d31125302b340efb1aec330d5bd7bad77597f0
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Fri Feb 7 09:56:27 2025 +0100
Add the server ddl class and implement materialized views
---
.../apache/baremaps/calcite/DataTableFactory.java | 21 +-
.../calcite/baremaps/BaremapsMaterializedView.java | 58 ++
.../calcite/baremaps/BaremapsMutableTable.java | 282 ++++++++
.../calcite/baremaps/ServerDdlExecutor.java | 770 +++++++++++++++++++++
.../apache/baremaps/calcite/BaremapsContext.java | 73 ++
.../apache/baremaps/calcite/CalciteDdlTest.java | 206 ++++++
.../org/apache/baremaps/calcite/CalciteTest.java | 287 +++-----
.../data/memory/MemoryMappedDirectory.java | 8 +
8 files changed, 1489 insertions(+), 216 deletions(-)
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
index 569984662..ce0ea913a 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
@@ -24,7 +24,6 @@ import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.file.Paths;
import java.util.Map;
-import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
import org.apache.baremaps.calcite.csv.CsvDataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.DataCollection;
@@ -35,16 +34,17 @@ import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeImpl;
import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.TableFactory;
-public class DataTableFactory implements TableFactory<DataTableAdapter> {
+public class DataTableFactory implements TableFactory<Table> {
public DataTableFactory() {
}
@Override
- public DataTableAdapter create(
+ public Table create(
SchemaPlus schema,
String name,
Map<String, Object> operand,
@@ -52,16 +52,15 @@ public class DataTableFactory implements TableFactory<DataTableAdapter> {
final RelProtoDataType protoRowType =
rowType != null ? RelDataTypeImpl.proto(rowType) : null;
String format = (String) operand.get("format");
- DataTable dataTable = switch (format) {
- case "baremaps" -> createMMapTable(schema, name, operand, rowType);
+ return switch (format) {
+ case "baremaps" -> createDataTable(schema, name, operand, rowType);
case "csv" -> createCsvTable(schema, name, operand, rowType);
default -> throw new RuntimeException("Unsupported format");
};
- return new DataTableAdapter(dataTable, protoRowType);
}
- private DataTable createMMapTable(SchemaPlus schema, String name, Map<String, Object> operand,
- RelDataType rowType) {
+ private Table createDataTable(SchemaPlus schema, String name, Map<String, Object> operand,
+ RelDataType rowType) {
String directory = (String) operand.get("directory");
if (directory == null) {
throw new RuntimeException("A directory should be specified");
@@ -76,20 +75,20 @@ public class DataTableFactory implements TableFactory<DataTableAdapter> {
DataSchema dataSchema = DataSchema.read(new ByteArrayInputStream(bytes));
DataType<DataRow> dataType = new DataRowType(dataSchema);
DataCollection<DataRow> dataCollection = new AppendOnlyLog<>(dataType, memory);
- return new BaremapsDataTable(dataSchema, dataCollection);
+ return null; //new BaremapsTable(dataSchema, dataCollection);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
- private DataTable createCsvTable(SchemaPlus schema, String name, Map<String, Object> operand,
+ private Table createCsvTable(SchemaPlus schema, String name, Map<String, Object> operand,
RelDataType rowType) {
String file = (String) operand.get("file");
if (file == null) {
throw new RuntimeException("A file should be specified");
}
try {
- return new CsvDataTable(name, new File(file), ',', true);
+ return new DataTableAdapter(new CsvDataTable(name, new File(file), ',', true));
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java
new file mode 100644
index 000000000..2e24553be
--- /dev/null
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMaterializedView.java
@@ -0,0 +1,58 @@
+/*
+ * 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.baremaps;
+
+
+import org.apache.calcite.materialize.MaterializationKey;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.sql2rel.InitializerExpressionFactory;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/** A table that implements a materialized view. */
+class BaremapsMaterializedView extends BaremapsMutableTable {
+ /**
+ * The key with which this was stored in the materialization service, or null if not (yet)
+ * materialized.
+ */
+ @Nullable
+ MaterializationKey key;
+
+ BaremapsMaterializedView(
+ String name,
+ RelProtoDataType protoRowType,
+ InitializerExpressionFactory initializerExpressionFactory,
+ RelDataTypeFactory typeFactory) {
+ super(name, protoRowType, initializerExpressionFactory, typeFactory);
+ }
+
+ @Override
+ public Schema.TableType getJdbcTableType() {
+ return Schema.TableType.MATERIALIZED_VIEW;
+ }
+
+ @Override
+ public <C extends Object> @Nullable C unwrap(Class<C> aClass) {
+ if (MaterializationKey.class.isAssignableFrom(aClass)
+ && aClass.isInstance(key)) {
+ return aClass.cast(key);
+ }
+ return super.unwrap(aClass);
+ }
+}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMutableTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMutableTable.java
new file mode 100644
index 000000000..d54a84bf3
--- /dev/null
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsMutableTable.java
@@ -0,0 +1,282 @@
+/*
+ * 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.baremaps;
+
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.data.collection.AppendOnlyLog;
+import org.apache.baremaps.data.collection.DataCollection;
+import org.apache.baremaps.data.memory.Memory;
+import org.apache.baremaps.data.memory.MemoryMappedDirectory;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.prepare.Prepare;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.TableModify;
+import org.apache.calcite.rel.logical.LogicalTableModify;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.schema.ModifiableTable;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.schema.Wrapper;
+import org.apache.calcite.schema.impl.AbstractTable;
+import org.apache.calcite.schema.impl.AbstractTableQueryable;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql2rel.InitializerExpressionFactory;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.lang.reflect.Type;
+import java.nio.MappedByteBuffer;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;
+
+
+class BaremapsMutableTable extends AbstractTable implements ModifiableTable, Wrapper {
+
+ private final String name;
+
+ private final InitializerExpressionFactory initializerExpressionFactory;
+
+ private final RelProtoDataType protoRowType;
+
+ private final RelDataType rowType;
+
+ private final DataSchema schema;
+
+ final DataCollection<DataRow> rows;
+
+ BaremapsMutableTable(String name,
+ RelProtoDataType protoRowType,
+ InitializerExpressionFactory initializerExpressionFactory,
+ RelDataTypeFactory typeFactory) {
+ super();
+ this.name = requireNonNull(name, "name");
+ this.initializerExpressionFactory =
+ requireNonNull(initializerExpressionFactory, "initializerExpressionFactory");
+ this.protoRowType = requireNonNull(protoRowType, "protoRowType");
+ this.rowType = this.protoRowType.apply(typeFactory);
+
+ // Create the schema
+ List<DataColumn> columns = rowType.getFieldList().stream().map(field -> {
+ String columnName = field.getName();
+ RelDataType relDataType = field.getType();
+ DataColumn.Cardinality columnCardinality = cardinalityFromRelDataType(relDataType);
+ DataColumn.Type columnType = typeFromRelDataType(relDataType);
+ return (DataColumn) new DataColumnFixed(columnName, columnCardinality, columnType);
+ }).toList();
+ this.schema = new DataSchema(name, columns);
+
+ // Create the collection
+ DataRowType dataRowType = new DataRowType(schema);
+ Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(Paths.get(this.name));
+ this.rows = new AppendOnlyLog<>(dataRowType, memory);
+ }
+
+ @Override
+ public TableModify toModificationRel(
+ RelOptCluster cluster,
+ RelOptTable table,
+ Prepare.CatalogReader catalogReader,
+ RelNode child,
+ TableModify.Operation operation,
+ @Nullable List<String> updateColumnList,
+ @Nullable List<RexNode> sourceExpressionList,
+ boolean flattened) {
+ return LogicalTableModify.create(table, catalogReader, child, operation,
+ updateColumnList, sourceExpressionList, flattened);
+ }
+
+ private DataColumn.Cardinality cardinalityFromRelDataType(RelDataType columnType) {
+ if (columnType.getSqlTypeName() == SqlTypeName.ARRAY) {
+ return DataColumn.Cardinality.REPEATED;
+ } else if (columnType.isNullable()) {
+ return Cardinality.OPTIONAL;
+ } else {
+ return Cardinality.REQUIRED;
+ }
+ }
+
+ public static DataColumn.Type typeFromRelDataType(RelDataType relDataType) {
+ SqlTypeName sqlTypeName = relDataType.getSqlTypeName();
+ switch (sqlTypeName) {
+ case BOOLEAN:
+ return DataColumn.Type.BOOLEAN;
+ case TINYINT:
+ return DataColumn.Type.BYTE;
+ case SMALLINT:
+ return DataColumn.Type.SHORT;
+ case INTEGER:
+ return DataColumn.Type.INTEGER;
+ case BIGINT:
+ return DataColumn.Type.LONG;
+ case FLOAT:
+ case REAL:
+ return DataColumn.Type.FLOAT;
+ case DOUBLE:
+ case DECIMAL:
+ return DataColumn.Type.DOUBLE;
+ case CHAR:
+ case VARCHAR:
+ return DataColumn.Type.STRING;
+ case BINARY:
+ case VARBINARY:
+ return DataColumn.Type.BINARY;
+ case DATE:
+ return DataColumn.Type.LOCAL_DATE;
+ case TIME:
+ return DataColumn.Type.LOCAL_TIME;
+ case TIMESTAMP:
+ return DataColumn.Type.LOCAL_DATE_TIME;
+ case MAP:
+ return DataColumn.Type.NESTED;
+ case GEOMETRY:
+ return DataColumn.Type.GEOMETRY;
+ case ARRAY:
+ RelDataType componentType = requireNonNull(relDataType.getComponentType());
+ return typeFromRelDataType(componentType);
+ default:
+ throw new IllegalArgumentException("Unsupported Calcite type: " + sqlTypeName);
+ }
+ }
+
+ @Override
+ public Collection getModifiableCollection() {
+ return new CollectionAdapter();
+ }
+
+ @Override
+ public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema,
+ String tableName) {
+ return new AbstractTableQueryable<T>(queryProvider, schema, this,
+ tableName) {
+ @Override
+ public Enumerator<T> enumerator() {
+ return (Enumerator<T>) Linq4j.enumerator(new CollectionAdapter());
+ }
+ };
+ }
+
+ @Override
+ public Type getElementType() {
+ return Object[].class;
+ }
+
+ @Override
+ public Expression getExpression(SchemaPlus schema, String tableName, Class clazz) {
+ return Schemas.tableExpression(schema, getElementType(), tableName, clazz);
+ }
+
+ @Override
+ public RelDataType getRowType(final RelDataTypeFactory typeFactory) {
+ return rowType;
+ }
+
+ @Override
+ public <C extends Object> @Nullable C unwrap(Class<C> aClass) {
+ if (aClass.isInstance(initializerExpressionFactory)) {
+ return aClass.cast(initializerExpressionFactory);
+ }
+ return super.unwrap(aClass);
+ }
+
+ private class CollectionAdapter implements Collection<Object[]> {
+
+ private final int size;
+
+ public CollectionAdapter() {
+ this.size = (int) Math.min(rows.size(), Integer.MAX_VALUE);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return rows.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return rows.contains(o);
+ }
+
+ @Override
+ public Iterator<Object[]> iterator() {
+ return rows.stream().map(row -> row.values().toArray()).iterator();
+ }
+
+ @Override
+ public Object[] toArray() {
+ return rows.stream().map(row -> row.values().toArray()).toArray();
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ return (T[]) rows.stream().map(row -> row.values().toArray()).toArray();
+ }
+
+ @Override
+ public boolean add(Object[] objects) {
+ return rows.add(new DataRow(schema, List.of(objects)));
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return rows.containsAll(c);
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Object[]> c) {
+ return rows.addAll(c.stream().map(objects -> new DataRow(schema, List.of(objects))).toList());
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void clear() {
+ rows.clear();
+ }
+ }
+}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/ServerDdlExecutor.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/ServerDdlExecutor.java
new file mode 100644
index 000000000..0c2650f63
--- /dev/null
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/ServerDdlExecutor.java
@@ -0,0 +1,770 @@
+/*
+ * 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.baremaps;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+import com.google.common.collect.ImmutableList;
+import java.io.Reader;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.adapter.jdbc.JdbcSchema;
+import org.apache.calcite.avatica.AvaticaUtils;
+import org.apache.calcite.jdbc.CalcitePrepare;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.ContextSqlValidator;
+import org.apache.calcite.linq4j.Ord;
+import org.apache.calcite.materialize.MaterializationKey;
+import org.apache.calcite.materialize.MaterializationService;
+import org.apache.calcite.model.JsonSchema;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rel.type.RelDataTypeImpl;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.schema.ColumnStrategy;
+import org.apache.calcite.schema.Function;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.schema.SchemaFactory;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.TranslatableTable;
+import org.apache.calcite.schema.Wrapper;
+import org.apache.calcite.schema.impl.AbstractSchema;
+import org.apache.calcite.schema.impl.ViewTable;
+import org.apache.calcite.schema.impl.ViewTableMacro;
+import org.apache.calcite.server.DdlExecutor;
+import org.apache.calcite.server.DdlExecutorImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.SqlUtil;
+import org.apache.calcite.sql.SqlWriterConfig;
+import org.apache.calcite.sql.ddl.SqlAttributeDefinition;
+import org.apache.calcite.sql.ddl.SqlColumnDeclaration;
+import org.apache.calcite.sql.ddl.SqlCreateForeignSchema;
+import org.apache.calcite.sql.ddl.SqlCreateFunction;
+import org.apache.calcite.sql.ddl.SqlCreateMaterializedView;
+import org.apache.calcite.sql.ddl.SqlCreateSchema;
+import org.apache.calcite.sql.ddl.SqlCreateTable;
+import org.apache.calcite.sql.ddl.SqlCreateTableLike;
+import org.apache.calcite.sql.ddl.SqlCreateType;
+import org.apache.calcite.sql.ddl.SqlCreateView;
+import org.apache.calcite.sql.ddl.SqlDropObject;
+import org.apache.calcite.sql.ddl.SqlDropSchema;
+import org.apache.calcite.sql.ddl.SqlTruncateTable;
+import org.apache.calcite.sql.dialect.CalciteSqlDialect;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlAbstractParserImpl;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParserImplFactory;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
+import org.apache.calcite.sql.pretty.SqlPrettyWriter;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql2rel.InitializerContext;
+import org.apache.calcite.sql2rel.InitializerExpressionFactory;
+import org.apache.calcite.sql2rel.NullInitializerExpressionFactory;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.calcite.tools.Planner;
+import org.apache.calcite.tools.RelConversionException;
+import org.apache.calcite.tools.ValidationException;
+import org.apache.calcite.util.NlsString;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/**
+ * Executes DDL commands.
+ *
+ * <p>
+ * Given a DDL command that is a sub-class of {@link SqlNode}, dispatches the command to an
+ * appropriate {@code execute} method. For example, "CREATE TABLE" ({@link SqlCreateTable}) is
+ * dispatched to {@link #execute(SqlCreateTable, CalcitePrepare.Context)}.
+ */
+public class ServerDdlExecutor extends DdlExecutorImpl {
+ /** Singleton instance. */
+ public static final ServerDdlExecutor INSTANCE = new ServerDdlExecutor();
+
+ /** Parser factory. */
+ @SuppressWarnings("unused") // used via reflection
+ public static final SqlParserImplFactory PARSER_FACTORY =
+ new SqlParserImplFactory() {
+ @Override
+ public SqlAbstractParserImpl getParser(Reader stream) {
+ return SqlDdlParserImpl.FACTORY.getParser(stream);
+ }
+
+ @Override
+ public DdlExecutor getDdlExecutor() {
+ return ServerDdlExecutor.INSTANCE;
+ }
+ };
+
+ /**
+ * Creates a ServerDdlExecutor. Protected only to allow sub-classing; use {@link #INSTANCE} where
+ * possible.
+ */
+ protected ServerDdlExecutor() {}
+
+ /**
+ * Returns the schema in which to create an object; the left part is null if the schema does not
+ * exist.
+ */
+ static Pair<@Nullable CalciteSchema, String> schema(
+ CalcitePrepare.Context context, boolean mutable, SqlIdentifier id) {
+ final String name;
+ final List<String> path;
+ if (id.isSimple()) {
+ path = context.getDefaultSchemaPath();
+ name = id.getSimple();
+ } else {
+ path = Util.skipLast(id.names);
+ name = Util.last(id.names);
+ }
+ CalciteSchema schema =
+ mutable ? context.getMutableRootSchema()
+ : context.getRootSchema();
+ for (String p : path) {
+ @Nullable
+ CalciteSchema subSchema = schema.getSubSchema(p, true);
+ if (subSchema == null) {
+ return Pair.of(null, name);
+ }
+ schema = subSchema;
+ }
+ return Pair.of(schema, name);
+ }
+
+ /**
+ * Returns the SqlValidator with the given {@code context} schema and type factory.
+ */
+ static SqlValidator validator(CalcitePrepare.Context context,
+ boolean mutable) {
+ return new ContextSqlValidator(context, mutable);
+ }
+
+ /**
+ * Wraps a query to rename its columns. Used by CREATE VIEW and CREATE MATERIALIZED VIEW.
+ */
+ static SqlNode renameColumns(@Nullable SqlNodeList columnList,
+ SqlNode query) {
+ if (columnList == null) {
+ return query;
+ }
+ final SqlParserPos p = query.getParserPosition();
+ final SqlNodeList selectList = SqlNodeList.SINGLETON_STAR;
+ final SqlCall from =
+ SqlStdOperatorTable.AS.createCall(p,
+ ImmutableList.<SqlNode>builder()
+ .add(query)
+ .add(new SqlIdentifier("_", p))
+ .addAll(columnList)
+ .build());
+ return new SqlSelect(p, null, selectList, from, null, null, null, null,
+ null, null, null, null, null);
+ }
+
+ /** Erase the table date that calcite-sever created. */
+ static void erase(SqlIdentifier name, CalcitePrepare.Context context) {
+ // Directly clearing data is more efficient than executing SQL
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, name);
+ final CalciteSchema calciteSchema = requireNonNull(pair.left);
+ final String tblName = pair.right;
+ final CalciteSchema.TableEntry tableEntry =
+ calciteSchema.getTable(tblName, context.config().caseSensitive());
+ final Table table = requireNonNull(tableEntry, "tableEntry").getTable();
+ if (table instanceof BaremapsMutableTable) {
+ BaremapsMutableTable mutableArrayTable = (BaremapsMutableTable) table;
+ mutableArrayTable.rows.clear();
+ } else {
+ // Not calcite-server created, so not support truncate.
+ throw new UnsupportedOperationException("Only MutableArrayTable support truncate");
+ }
+ }
+
+ /** Populates the table called {@code name} by executing {@code query}. */
+ static void populate(SqlIdentifier name, SqlNode query,
+ CalcitePrepare.Context context) {
+ // Generate, prepare and execute an "INSERT INTO table query" statement.
+ // (It's a bit inefficient that we convert from SqlNode to SQL and back
+ // again.)
+ final FrameworkConfig config = Frameworks.newConfigBuilder()
+ .defaultSchema(context.getRootSchema().plus())
+ .build();
+ final Planner planner = Frameworks.getPlanner(config);
+ try {
+ final StringBuilder buf = new StringBuilder();
+ final SqlWriterConfig writerConfig =
+ SqlPrettyWriter.config().withAlwaysUseParentheses(false);
+ final SqlPrettyWriter w = new SqlPrettyWriter(writerConfig, buf);
+ buf.append("INSERT INTO ");
+ name.unparse(w, 0, 0);
+ buf.append(' ');
+ query.unparse(w, 0, 0);
+ final String sql = buf.toString();
+ final SqlNode query1 = planner.parse(sql);
+ final SqlNode query2 = planner.validate(query1);
+ final RelRoot r = planner.rel(query2);
+ final PreparedStatement prepare =
+ context.getRelRunner().prepareStatement(r.rel);
+ int rowCount = prepare.executeUpdate();
+ Util.discard(rowCount);
+ prepare.close();
+ } catch (SqlParseException | ValidationException
+ | RelConversionException | SQLException e) {
+ throw Util.throwAsRuntime(e);
+ }
+ }
+
+ /**
+ * Returns the value of a literal, converting {@link NlsString} into String.
+ */
+ @SuppressWarnings("rawtypes")
+ static @Nullable Comparable value(SqlNode node) {
+ final Comparable v = SqlLiteral.value(node);
+ return v instanceof NlsString ? ((NlsString) v).getValue() : v;
+ }
+
+ /** Executes a {@code CREATE FOREIGN SCHEMA} command. */
+ public void execute(SqlCreateForeignSchema create,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, create.name);
+ requireNonNull(pair.left); // TODO: should not assume parent schema exists
+ if (pair.left.plus().getSubSchema(pair.right) != null) {
+ if (!create.getReplace() && !create.ifNotExists) {
+ throw SqlUtil.newContextException(create.name.getParserPosition(),
+ RESOURCE.schemaExists(pair.right));
+ }
+ }
+ final Schema subSchema;
+ final String libraryName;
+ if (create.type != null) {
+ checkArgument(create.library == null);
+ final String typeName = (String) requireNonNull(value(create.type));
+ final JsonSchema.Type type =
+ Util.enumVal(JsonSchema.Type.class,
+ typeName.toUpperCase(Locale.ROOT));
+ if (type != null) {
+ switch (type) {
+ case JDBC:
+ libraryName = JdbcSchema.Factory.class.getName();
+ break;
+ default:
+ libraryName = null;
+ }
+ } else {
+ libraryName = null;
+ }
+ if (libraryName == null) {
+ throw SqlUtil.newContextException(create.type.getParserPosition(),
+ RESOURCE.schemaInvalidType(typeName,
+ Arrays.toString(JsonSchema.Type.values())));
+ }
+ } else {
+ libraryName =
+ requireNonNull((String) value(requireNonNull(create.library)));
+ }
+ final SchemaFactory schemaFactory =
+ AvaticaUtils.instantiatePlugin(SchemaFactory.class, libraryName);
+ final Map<String, Object> operandMap = new LinkedHashMap<>();
+ for (Pair<SqlIdentifier, SqlNode> option : create.options()) {
+ operandMap.put(option.left.getSimple(),
+ requireNonNull(value(option.right)));
+ }
+ subSchema =
+ schemaFactory.create(pair.left.plus(), pair.right, operandMap);
+ pair.left.add(pair.right, subSchema);
+ }
+
+ /** Executes a {@code CREATE FUNCTION} command. */
+ public void execute(SqlCreateFunction create,
+ CalcitePrepare.Context context) {
+ throw new UnsupportedOperationException("CREATE FUNCTION is not supported");
+ }
+
+ /**
+ * Executes {@code DROP FUNCTION}, {@code DROP TABLE}, {@code DROP MATERIALIZED VIEW},
+ * {@code DROP TYPE}, {@code DROP VIEW} commands.
+ */
+ public void execute(SqlDropObject drop,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, false, drop.name);
+ final @Nullable CalciteSchema schema =
+ pair.left; // null if schema does not exist
+ final String objectName = pair.right;
+
+ boolean existed;
+ switch (drop.getKind()) {
+ case DROP_TABLE:
+ case DROP_MATERIALIZED_VIEW:
+ Table materializedView =
+ schema != null
+ && drop.getKind() == SqlKind.DROP_MATERIALIZED_VIEW
+ ? schema.plus().getTable(objectName)
+ : null;
+
+ existed = schema != null && schema.removeTable(objectName);
+ if (existed) {
+ if (materializedView instanceof Wrapper) {
+ ((Wrapper) materializedView).maybeUnwrap(MaterializationKey.class)
+ .ifPresent(materializationKey -> MaterializationService.instance()
+ .removeMaterialization(materializationKey));
+ }
+ } else if (!drop.ifExists) {
+ throw SqlUtil.newContextException(drop.name.getParserPosition(),
+ RESOURCE.tableNotFound(objectName));
+ }
+ break;
+ case DROP_VIEW:
+ // Not quite right: removes any other functions with the same name
+ existed = schema != null && schema.removeFunction(objectName);
+ if (!existed && !drop.ifExists) {
+ throw SqlUtil.newContextException(drop.name.getParserPosition(),
+ RESOURCE.viewNotFound(objectName));
+ }
+ break;
+ case DROP_TYPE:
+ existed = schema != null && schema.removeType(objectName);
+ if (!existed && !drop.ifExists) {
+ throw SqlUtil.newContextException(drop.name.getParserPosition(),
+ RESOURCE.typeNotFound(objectName));
+ }
+ break;
+ case DROP_FUNCTION:
+ existed = schema != null && schema.removeFunction(objectName);
+ if (!existed && !drop.ifExists) {
+ throw SqlUtil.newContextException(drop.name.getParserPosition(),
+ RESOURCE.functionNotFound(objectName));
+ }
+ break;
+ case OTHER_DDL:
+ default:
+ throw new AssertionError(drop.getKind());
+ }
+ }
+
+ /**
+ * Executes a {@code TRUNCATE TABLE} command.
+ */
+ public void execute(SqlTruncateTable truncate,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, truncate.name);
+ if (pair.left == null
+ || pair.left.plus().getTable(pair.right) == null) {
+ throw SqlUtil.newContextException(truncate.name.getParserPosition(),
+ RESOURCE.tableNotFound(pair.right));
+ }
+
+ if (!truncate.continueIdentify) {
+ // Calcite not support RESTART IDENTIFY
+ throw new UnsupportedOperationException("RESTART IDENTIFY is not supported");
+ }
+
+ erase(truncate.name, context);
+ }
+
+ /** Executes a {@code CREATE MATERIALIZED VIEW} command. */
+ public void execute(SqlCreateMaterializedView create,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, create.name);
+ if (pair.left != null
+ && pair.left.plus().getTable(pair.right) != null) {
+ // Materialized view exists.
+ if (!create.ifNotExists) {
+ // They did not specify IF NOT EXISTS, so give error.
+ throw SqlUtil.newContextException(create.name.getParserPosition(),
+ RESOURCE.tableExists(pair.right));
+ }
+ return;
+ }
+ final SqlNode q = renameColumns(create.columnList, create.query);
+ final String sql = q.toSqlString(CalciteSqlDialect.DEFAULT).getSql();
+ requireNonNull(pair.left); // TODO: should not assume parent schema exists
+ final List<String> schemaPath = pair.left.path(null);
+ final ViewTableMacro viewTableMacro =
+ ViewTable.viewMacro(pair.left.plus(), sql, schemaPath,
+ context.getObjectPath(), false);
+ final TranslatableTable x = viewTableMacro.apply(ImmutableList.of());
+ final RelDataType rowType = x.getRowType(context.getTypeFactory());
+
+ // Table does not exist. Create it.
+ final BaremapsMaterializedView table =
+ new BaremapsMaterializedView(pair.right, RelDataTypeImpl.proto(rowType),
+ NullInitializerExpressionFactory.INSTANCE, context.getTypeFactory());
+ pair.left.add(pair.right, table);
+ populate(create.name, create.query, context);
+ table.key =
+ MaterializationService.instance().defineMaterialization(pair.left, null,
+ sql, schemaPath, pair.right, true, true);
+ }
+
+ /** Executes a {@code CREATE SCHEMA} command. */
+ public void execute(SqlCreateSchema create,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, create.name);
+ requireNonNull(pair.left); // TODO: should not assume parent schema exists
+ if (pair.left.plus().getSubSchema(pair.right) != null) {
+ if (create.ifNotExists) {
+ return;
+ }
+ if (!create.getReplace()) {
+ throw SqlUtil.newContextException(create.name.getParserPosition(),
+ RESOURCE.schemaExists(pair.right));
+ }
+ }
+ final Schema subSchema = new AbstractSchema();
+ pair.left.add(pair.right, subSchema);
+ }
+
+ /** Executes a {@code DROP SCHEMA} command. */
+ public void execute(SqlDropSchema drop,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, false, drop.name);
+ final String name = pair.right;
+ final boolean existed = pair.left != null
+ && pair.left.removeSubSchema(name);
+ if (!existed && !drop.ifExists) {
+ throw SqlUtil.newContextException(drop.name.getParserPosition(),
+ RESOURCE.schemaNotFound(name));
+ }
+ }
+
+ /** Executes a {@code CREATE TABLE} command. */
+ public void execute(SqlCreateTable create,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, create.name);
+ requireNonNull(pair.left); // TODO: should not assume parent schema exists
+ final JavaTypeFactory typeFactory = context.getTypeFactory();
+ final RelDataType queryRowType;
+ if (create.query != null) {
+ // A bit of a hack: pretend it's a view, to get its row type
+ final String sql =
+ create.query.toSqlString(CalciteSqlDialect.DEFAULT).getSql();
+ final ViewTableMacro viewTableMacro =
+ ViewTable.viewMacro(pair.left.plus(), sql, pair.left.path(null),
+ context.getObjectPath(), false);
+ final TranslatableTable x = viewTableMacro.apply(ImmutableList.of());
+ queryRowType = x.getRowType(typeFactory);
+
+ if (create.columnList != null
+ && queryRowType.getFieldCount() != create.columnList.size()) {
+ throw SqlUtil.newContextException(
+ create.columnList.getParserPosition(),
+ RESOURCE.columnCountMismatch());
+ }
+ } else {
+ queryRowType = null;
+ }
+ final List<SqlNode> columnList;
+ if (create.columnList != null) {
+ columnList = create.columnList;
+ } else {
+ if (queryRowType == null) {
+ // "CREATE TABLE t" is invalid; because there is no "AS query" we need
+ // a list of column names and types, "CREATE TABLE t (INT c)".
+ throw SqlUtil.newContextException(create.name.getParserPosition(),
+ RESOURCE.createTableRequiresColumnList());
+ }
+ columnList = new ArrayList<>();
+ for (String name : queryRowType.getFieldNames()) {
+ columnList.add(new SqlIdentifier(name, SqlParserPos.ZERO));
+ }
+ }
+ final ImmutableList.Builder<ColumnDef> b = ImmutableList.builder();
+ final RelDataTypeFactory.Builder builder = typeFactory.builder();
+ final RelDataTypeFactory.Builder storedBuilder = typeFactory.builder();
+ // REVIEW 2019-08-19 Danny Chan: Should we implement the
+ // #validate(SqlValidator) to get the SqlValidator instance?
+ final SqlValidator validator = validator(context, true);
+ for (Ord<SqlNode> c : Ord.zip(columnList)) {
+ if (c.e instanceof SqlColumnDeclaration) {
+ final SqlColumnDeclaration d = (SqlColumnDeclaration) c.e;
+ final RelDataType type = d.dataType.deriveType(validator, true);
+ builder.add(d.name.getSimple(), type);
+ if (d.strategy != ColumnStrategy.VIRTUAL) {
+ storedBuilder.add(d.name.getSimple(), type);
+ }
+ b.add(ColumnDef.of(d.expression, type, d.strategy));
+ } else if (c.e instanceof SqlIdentifier) {
+ final SqlIdentifier id = (SqlIdentifier) c.e;
+ if (queryRowType == null) {
+ throw SqlUtil.newContextException(id.getParserPosition(),
+ RESOURCE.createTableRequiresColumnTypes(id.getSimple()));
+ }
+ final RelDataTypeField f = queryRowType.getFieldList().get(c.i);
+ final ColumnStrategy strategy = f.getType().isNullable()
+ ? ColumnStrategy.NULLABLE
+ : ColumnStrategy.NOT_NULLABLE;
+ b.add(ColumnDef.of(c.e, f.getType(), strategy));
+ builder.add(id.getSimple(), f.getType());
+ storedBuilder.add(id.getSimple(), f.getType());
+ } else {
+ throw new AssertionError(c.e.getClass());
+ }
+ }
+ final RelDataType rowType = builder.build();
+ final RelDataType storedRowType = storedBuilder.build();
+ final List<ColumnDef> columns = b.build();
+ final InitializerExpressionFactory ief =
+ new NullInitializerExpressionFactory() {
+ @Override
+ public ColumnStrategy generationStrategy(RelOptTable table,
+ int iColumn) {
+ return columns.get(iColumn).strategy;
+ }
+
+ @Override
+ public RexNode newColumnDefaultValue(RelOptTable table,
+ int iColumn, InitializerContext context) {
+ final ColumnDef c = columns.get(iColumn);
+ if (c.expr != null) {
+ // REVIEW Danny 2019-10-09: Should we support validation for DDL nodes?
+ final SqlNode validated = context.validateExpression(storedRowType, c.expr);
+ // The explicit specified type should have the same nullability
+ // with the column expression inferred type,
+ // actually they should be exactly the same.
+ return context.convertExpression(validated);
+ }
+ return super.newColumnDefaultValue(table, iColumn, context);
+ }
+ };
+ if (pair.left.plus().getTable(pair.right) != null) {
+ // Table exists.
+ if (create.ifNotExists) {
+ return;
+ }
+ if (!create.getReplace()) {
+ // They did not specify IF NOT EXISTS, so give error.
+ throw SqlUtil.newContextException(create.name.getParserPosition(),
+ RESOURCE.tableExists(pair.right));
+ }
+ }
+ // Table does not exist. Create it.
+ pair.left.add(pair.right,
+ new BaremapsMutableTable(pair.right,
+ RelDataTypeImpl.proto(rowType), ief, context.getTypeFactory()));
+ if (create.query != null) {
+ populate(create.name, create.query, context);
+ }
+ }
+
+ /** Executes a {@code CREATE TABLE LIKE} command. */
+ public void execute(SqlCreateTableLike create,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, create.name);
+ requireNonNull(pair.left); // TODO: should not assume parent schema exists
+ if (pair.left.plus().getTable(pair.right) != null) {
+ // Table exists.
+ if (create.ifNotExists) {
+ return;
+ }
+ if (!create.getReplace()) {
+ // They did not specify IF NOT EXISTS, so give error.
+ throw SqlUtil.newContextException(create.name.getParserPosition(),
+ RESOURCE.tableExists(pair.right));
+ }
+ }
+
+ final Pair<@Nullable CalciteSchema, String> sourceTablePair =
+ schema(context, true, create.sourceTable);
+ final CalciteSchema schema =
+ // TODO: should not assume parent schema exists
+ requireNonNull(sourceTablePair.left);
+ final String tableName = sourceTablePair.right;
+ final CalciteSchema.TableEntry tableEntry =
+ schema.getTable(tableName, context.config().caseSensitive());
+ final Table table = requireNonNull(tableEntry, "tableEntry").getTable();
+
+ InitializerExpressionFactory ief = NullInitializerExpressionFactory.INSTANCE;
+ if (table instanceof Wrapper) {
+ final InitializerExpressionFactory sourceIef =
+ ((Wrapper) table).unwrap(InitializerExpressionFactory.class);
+ if (sourceIef != null) {
+ final Set<SqlCreateTableLike.LikeOption> optionSet = create.options();
+ final boolean includingGenerated =
+ optionSet.contains(SqlCreateTableLike.LikeOption.GENERATED)
+ || optionSet.contains(SqlCreateTableLike.LikeOption.ALL);
+ final boolean includingDefaults =
+ optionSet.contains(SqlCreateTableLike.LikeOption.DEFAULTS)
+ || optionSet.contains(SqlCreateTableLike.LikeOption.ALL);
+
+ // initializes columns based on the source table InitializerExpressionFactory
+ // and like options.
+ ief =
+ new CopiedTableInitializerExpressionFactory(
+ includingGenerated, includingDefaults, sourceIef);
+ }
+ }
+
+ final JavaTypeFactory typeFactory = context.getTypeFactory();
+ final RelDataType rowType = table.getRowType(typeFactory);
+ // Table does not exist. Create it.
+ pair.left.add(pair.right,
+ new BaremapsMutableTable(pair.right,
+ RelDataTypeImpl.proto(rowType), ief, typeFactory));
+ }
+
+ /** Executes a {@code CREATE TYPE} command. */
+ public void execute(SqlCreateType create,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, create.name);
+ requireNonNull(pair.left); // TODO: should not assume parent schema exists
+ final SqlValidator validator = validator(context, false);
+ pair.left.add(pair.right, typeFactory -> {
+ if (create.dataType != null) {
+ return create.dataType.deriveType(validator);
+ } else {
+ final RelDataTypeFactory.Builder builder = typeFactory.builder();
+ if (create.attributeDefs != null) {
+ for (SqlNode def : create.attributeDefs) {
+ final SqlAttributeDefinition attributeDef =
+ (SqlAttributeDefinition) def;
+ final SqlDataTypeSpec typeSpec = attributeDef.dataType;
+ final RelDataType type = typeSpec.deriveType(validator);
+ builder.add(attributeDef.name.getSimple(), type);
+ }
+ }
+ return builder.build();
+ }
+ });
+ }
+
+ /** Executes a {@code CREATE VIEW} command. */
+ public void execute(SqlCreateView create,
+ CalcitePrepare.Context context) {
+ final Pair<@Nullable CalciteSchema, String> pair =
+ schema(context, true, create.name);
+ requireNonNull(pair.left); // TODO: should not assume parent schema exists
+ final SchemaPlus schemaPlus = pair.left.plus();
+ for (Function function : schemaPlus.getFunctions(pair.right)) {
+ if (function.getParameters().isEmpty()) {
+ if (!create.getReplace()) {
+ throw SqlUtil.newContextException(create.name.getParserPosition(),
+ RESOURCE.viewExists(pair.right));
+ }
+ pair.left.removeFunction(pair.right);
+ }
+ }
+ final SqlNode q = renameColumns(create.columnList, create.query);
+ final String sql = q.toSqlString(CalciteSqlDialect.DEFAULT).getSql();
+ final ViewTableMacro viewTableMacro =
+ ViewTable.viewMacro(schemaPlus, sql, pair.left.path(null),
+ context.getObjectPath(), false);
+ final TranslatableTable x = viewTableMacro.apply(ImmutableList.of());
+ Util.discard(x);
+ schemaPlus.add(pair.right, viewTableMacro);
+ }
+
+ /**
+ * Initializes columns based on the source {@link InitializerExpressionFactory} and like options.
+ */
+ private static class CopiedTableInitializerExpressionFactory
+ extends NullInitializerExpressionFactory {
+
+ private final boolean includingGenerated;
+ private final boolean includingDefaults;
+ private final InitializerExpressionFactory sourceIef;
+
+ CopiedTableInitializerExpressionFactory(
+ boolean includingGenerated,
+ boolean includingDefaults,
+ InitializerExpressionFactory sourceIef) {
+ this.includingGenerated = includingGenerated;
+ this.includingDefaults = includingDefaults;
+ this.sourceIef = sourceIef;
+ }
+
+ @Override
+ public ColumnStrategy generationStrategy(
+ RelOptTable table, int iColumn) {
+ final ColumnStrategy sourceStrategy = sourceIef.generationStrategy(table, iColumn);
+ if (includingGenerated
+ && (sourceStrategy == ColumnStrategy.STORED
+ || sourceStrategy == ColumnStrategy.VIRTUAL)) {
+ return sourceStrategy;
+ }
+ if (includingDefaults && sourceStrategy == ColumnStrategy.DEFAULT) {
+ return ColumnStrategy.DEFAULT;
+ }
+
+ return super.generationStrategy(table, iColumn);
+ }
+
+ @Override
+ public RexNode newColumnDefaultValue(
+ RelOptTable table, int iColumn, InitializerContext context) {
+ if (includingDefaults || includingGenerated) {
+ return sourceIef.newColumnDefaultValue(table, iColumn, context);
+ } else {
+ return super.newColumnDefaultValue(table, iColumn, context);
+ }
+ }
+ }
+
+ /** Column definition. */
+ private static class ColumnDef {
+ final @Nullable SqlNode expr;
+ final RelDataType type;
+ final ColumnStrategy strategy;
+
+ private ColumnDef(@Nullable SqlNode expr, RelDataType type,
+ ColumnStrategy strategy) {
+ this.expr = expr;
+ this.type = type;
+ this.strategy = requireNonNull(strategy, "strategy");
+ checkArgument(
+ strategy == ColumnStrategy.NULLABLE
+ || strategy == ColumnStrategy.NOT_NULLABLE
+ || expr != null);
+ }
+
+ static ColumnDef of(@Nullable SqlNode expr, RelDataType type,
+ ColumnStrategy strategy) {
+ return new ColumnDef(expr, type, strategy);
+ }
+ }
+}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsContext.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsContext.java
new file mode 100644
index 000000000..8b94e123e
--- /dev/null
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsContext.java
@@ -0,0 +1,73 @@
+package org.apache.baremaps.calcite;
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.jdbc.CalcitePrepare;
+import org.apache.calcite.jdbc.CalcitePrepare.SparkHandler;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.tools.RelRunner;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+public class BaremapsContext implements CalcitePrepare.Context {
+
+ private final JavaTypeFactory typeFactory;
+
+ private final CalciteSchema rootSchema;
+
+ private final RelRunner planner;
+
+ public BaremapsContext(JavaTypeFactory typeFactory, CalciteSchema rootSchema, RelRunner planner) {
+ this.typeFactory = typeFactory;
+ this.rootSchema = rootSchema;
+ this.planner = planner;
+ }
+
+ @Override
+ public JavaTypeFactory getTypeFactory() {
+ return typeFactory;
+ }
+
+ @Override
+ public CalciteSchema getRootSchema() {
+ return rootSchema;
+ }
+
+ @Override
+ public CalciteSchema getMutableRootSchema() {
+ return rootSchema;
+ }
+
+ @Override
+ public List<String> getDefaultSchemaPath() {
+ return List.of();
+ }
+
+ @Override
+ public CalciteConnectionConfig config() {
+ return null;
+ }
+
+ @Override
+ public SparkHandler spark() {
+ return null;
+ }
+
+ @Override
+ public DataContext getDataContext() {
+ return null;
+ }
+
+ @Override
+ public @Nullable List<String> getObjectPath() {
+ return null;
+ }
+
+ @Override
+ public RelRunner getRelRunner() {
+ return planner;
+ }
+
+}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteDdlTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteDdlTest.java
new file mode 100644
index 000000000..b4d035366
--- /dev/null
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteDdlTest.java
@@ -0,0 +1,206 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
+import org.apache.baremaps.calcite.baremaps.ServerDdlExecutor;
+import org.apache.baremaps.data.collection.AppendOnlyLog;
+import org.apache.baremaps.data.collection.IndexedDataList;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.DataContexts;
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.interpreter.Interpreter;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.schema.ScannableTable;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.impl.AbstractSchema;
+import org.apache.calcite.schema.impl.AbstractTable;
+import org.apache.calcite.sql.*;
+import org.apache.calcite.sql.ddl.SqlCreateMaterializedView;
+import org.apache.calcite.sql.ddl.SqlCreateTable;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.calcite.tools.Planner;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.GeometryFactory;
+
+public class CalciteDdlTest {
+
+
+ public class ListTable extends AbstractTable implements ScannableTable {
+ private final List<Integer> data;
+
+ public ListTable(List<Integer> data) {
+ this.data = data;
+ }
+
+ @Override
+ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ // Define a single column named "value" of type INTEGER
+ return typeFactory.builder()
+ .add("V", SqlTypeName.INTEGER)
+ .build();
+ }
+
+ @Override
+ public Enumerable<Object[]> scan(DataContext root) {
+ // Convert the List<Integer> to Enumerable<Object[]>
+ return Linq4j.asEnumerable(data)
+ .select(i -> new Object[] {i});
+ }
+ }
+
+ public class ListSchema extends AbstractSchema {
+ private final List<Integer> listA;
+ private final List<Integer> listB;
+
+ public ListSchema(List<Integer> listA, List<Integer> listB) {
+ this.listA = listA;
+ this.listB = listB;
+ }
+
+ @Override
+ protected Map<String, Table> getTableMap() {
+ Map<String, Table> tables = new HashMap<>();
+ tables.put("LIST_A", new ListTable(listA));
+ tables.put("LIST_B", new ListTable(listB)); // Initially empty
+ return tables;
+ }
+ }
+
+ @Test
+ @Disabled
+ void test() throws Exception {
+ // Initialize your Java lists
+ List<Integer> listA = List.of(1, 2, 3, 4, 5);
+ List<Integer> listB = new ArrayList<>();
+
+ // Set up Calcite schema
+ CalciteSchema rootSchema = CalciteSchema.createRootSchema(true);
+ rootSchema.add("MY_SCHEMA", new ListSchema(listA, listB));
+
+ // Create and add 'city' table
+ DataSchema cityRowType = new DataSchema("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+
+ DataTable cityDataTable = new BaremapsDataTable(
+ cityRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(cityRowType))));
+
+ GeometryFactory geometryFactory = new GeometryFactory();
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
+ List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
+ List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
+
+ DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
+ rootSchema.add("CITY", cityDataTableAdapter);
+
+ // Create and add 'population' table
+ DataSchema populationRowType = new DataSchema("population", List.of(
+ new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
+
+ DataTable populationDataTable = new BaremapsDataTable(
+ populationRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(populationRowType))));
+
+ populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
+ populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
+
+ DataTableAdapter populationDataTableAdapter = new DataTableAdapter(populationDataTable);
+ rootSchema.add("population", populationDataTableAdapter);
+
+ // Configure the parser
+ SqlParser.Config parserConfig = SqlParser.configBuilder()
+ .setLex(Lex.MYSQL)
+ .setParserFactory(ServerDdlExecutor.PARSER_FACTORY)
+ .build();
+
+ // Configure the framework
+ FrameworkConfig config = Frameworks.newConfigBuilder()
+ .defaultSchema(rootSchema.plus())
+ .parserConfig(parserConfig)
+ .build();
+
+ // Create a planner
+ Planner planner = Frameworks.getPlanner(config);
+
+ // Define the SQL query to populate list_b from list_a
+ String sql = "CREATE MATERIALIZED VIEW city_population AS "
+ + "SELECT c.id, c.name, c.geometry, p.population "
+ + "FROM CITY c "
+ + "JOIN population p ON c.id = p.city_id";
+
+ // Parse the SQL query
+ SqlNode parsed = planner.parse(sql);
+
+ // Create a context
+ //BaremapsContext context = new BaremapsContext(new JavaTypeFactoryImpl(), rootSchema, Frameworks.);
+
+ // Create an executor
+ //ServerDdlExecutor.INSTANCE.execute((SqlCreateMaterializedView) parsed, context);
+
+// // Extract the select statement from the parsed SQL query
+// SqlNode select;
+// if (parsed instanceof SqlCreateMaterializedView createMaterializedView) {
+// List<SqlNode> operands = createMaterializedView.getOperandList();
+// select = operands.get(operands.size() - 1);
+// System.out.println(select);
+// } else {
+// throw new IllegalArgumentException(
+// "Expected a CREATE MATERIALIZED VIEW statement, but got: " + parsed.getKind());
+// }
+//
+// // Validate the SQL query
+// SqlNode validated = planner.validate(select);
+//
+// // Convert the SQL query to a relational expression
+// RelNode rel = planner.rel(validated).rel;
+//
+// try (Interpreter interpreter = new Interpreter(DataContexts.EMPTY, rel)) {
+// // Create an interpreter to execute the RelNode
+// for (Object[] row : interpreter) {
+// listB.add((Integer) row[0]);
+// }
+// }
+//
+// // Display the results
+// System.out.println("List A: " + listA);
+// System.out.println("List B (after SQL): " + listB);
+ }
+}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index 7f5258507..82a02d1cc 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
@@ -17,228 +17,105 @@
package org.apache.baremaps.calcite;
-import java.sql.*;
-import java.util.*;
import org.apache.baremaps.calcite.DataColumn.Cardinality;
import org.apache.baremaps.calcite.DataColumn.Type;
import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
+import org.apache.baremaps.calcite.baremaps.ServerDdlExecutor;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
-import org.apache.calcite.DataContext;
-import org.apache.calcite.DataContexts;
-import org.apache.calcite.interpreter.Interpreter;
import org.apache.calcite.jdbc.CalciteConnection;
-import org.apache.calcite.linq4j.Enumerable;
-import org.apache.calcite.linq4j.Linq4j;
-import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.schema.ScannableTable;
import org.apache.calcite.schema.SchemaPlus;
-import org.apache.calcite.schema.Table;
-import org.apache.calcite.schema.impl.*;
-import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.tools.FrameworkConfig;
-import org.apache.calcite.tools.Frameworks;
-import org.apache.calcite.tools.Planner;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
-public class CalciteTest {
-
- @Test
- @Disabled
- void sql() throws SQLException {
- GeometryFactory geometryFactory = new GeometryFactory();
-
- // Configure Calcite connection properties
- Properties info = new Properties();
- info.setProperty("lex", "MYSQL"); // Use MySQL dialect
- info.setProperty("caseSensitive", "false"); // Disable case sensitivity
- info.setProperty("unquotedCasing", "TO_LOWER"); // Convert unquoted identifiers to lowercase
- info.setProperty("quotedCasing", "TO_LOWER");
-
- try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
- CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
- SchemaPlus rootSchema = calciteConnection.getRootSchema();
-
- // Create and add 'city' table
- DataSchema cityRowType = new DataSchema("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
-
- DataTable cityDataTable = new BaremapsDataTable(
- cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(cityRowType))));
-
- cityDataTable.add(new DataRow(cityDataTable.schema(),
- List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRow(cityDataTable.schema(),
- List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
-
- DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
- rootSchema.add("city", cityDataTableAdapter);
-
- // Create and add 'population' table
- DataSchema populationRowType = new DataSchema("population", List.of(
- new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
-
- DataTable populationDataTable = new BaremapsDataTable(
- populationRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(populationRowType))));
-
- populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
- populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
-
- DataTableAdapter populationDataTableAdapter = new DataTableAdapter(populationDataTable);
- rootSchema.add("population", populationDataTableAdapter);
-
- // Create view 'city_population'
- String mvSql = "SELECT c.id, c.name, c.geometry, p.population " +
- "FROM city c " + // lowercase and unquoted
- "JOIN population p ON c.id = p.city_id";
-
- ViewTableMacro materializedView = MaterializedViewTable.viewMacro(
- rootSchema,
- mvSql,
- Collections.emptyList(), // Schema path
- List.of("city_population"), // Name parts
- false); // Not a materialized view
-
-
- rootSchema.add("city_population", materializedView);
-
- // Debug: List all tables in the root schema
- System.out.println("Available tables in the root schema:");
- for (String tableName : rootSchema.getTableNames()) {
- System.out.println(" - " + tableName);
- }
-
- String sql = "SELECT * FROM city";
- try (Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(sql)) {
- while (resultSet.next()) {
- System.out.println(resultSet.getString("id") + " " + resultSet.getString("geometry"));
- }
- }
-
- // Query the view
- sql = "SELECT * FROM city_population";
- try (Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(sql)) {
- while (resultSet.next()) {
- System.out.println(
- resultSet.getString("id") + " " + resultSet.getString("name"));
- }
- }
- }
-
- }
-
- public class ListTable extends AbstractTable implements ScannableTable {
- private final List<Integer> data;
-
- public ListTable(List<Integer> data) {
- this.data = data;
- }
-
- @Override
- public RelDataType getRowType(RelDataTypeFactory typeFactory) {
- // Define a single column named "value" of type INTEGER
- return typeFactory.builder()
- .add("V", SqlTypeName.INTEGER)
- .build();
- }
-
- @Override
- public Enumerable<Object[]> scan(DataContext root) {
- // Convert the List<Integer> to Enumerable<Object[]>
- return Linq4j.asEnumerable(data)
- .select(i -> new Object[] {i});
- }
- }
-
- public class ListSchema extends AbstractSchema {
- private final List<Integer> listA;
- private final List<Integer> listB;
-
- public ListSchema(List<Integer> listA, List<Integer> listB) {
- this.listA = listA;
- this.listB = listB;
- }
-
- @Override
- protected Map<String, Table> getTableMap() {
- Map<String, Table> tables = new HashMap<>();
- tables.put("LIST_A", new ListTable(listA));
- tables.put("LIST_B", new ListTable(listB)); // Initially empty
- return tables;
- }
- }
-
- @Test
- @Disabled
- void list() throws Exception {
- // Initialize your Java lists
- List<Integer> listA = List.of(1, 2, 3, 4, 5);
- List<Integer> listB = new ArrayList<>();
-
- // Set up Calcite schema
- SchemaPlus rootSchema = Frameworks.createRootSchema(true);
- rootSchema.add("MY_SCHEMA", new ListSchema(listA, listB));
-
- // Create and add 'city' table
- DataSchema cityRowType = new DataSchema("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
-
- DataTable cityDataTable = new BaremapsDataTable(
- cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(cityRowType))));
-
- GeometryFactory geometryFactory = new GeometryFactory();
- cityDataTable.add(new DataRow(cityDataTable.schema(),
- List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRow(cityDataTable.schema(),
- List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
-
- DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
- rootSchema.add("CITY", cityDataTableAdapter);
-
- // Configure the framework
- FrameworkConfig config = Frameworks.newConfigBuilder()
- .defaultSchema(rootSchema.getSubSchema("MY_SCHEMA"))
- .build();
-
- // Create a planner
- Planner planner = Frameworks.getPlanner(config);
-
- // Define the SQL query to populate list_b from list_a
- String sql = "SELECT V * 2 AS V FROM LIST_A";
+import java.sql.*;
+import java.util.List;
+import java.util.Properties;
- // Parse the SQL query
- org.apache.calcite.sql.SqlNode parsed = planner.parse(sql);
+public class CalciteTest {
- // Validate the SQL query
- org.apache.calcite.sql.SqlNode validated = planner.validate(parsed);
+ @Test
+ @Disabled
+ void sql() throws SQLException {
+ GeometryFactory geometryFactory = new GeometryFactory();
+
+ // Configure Calcite connection properties
+ Properties info = new Properties();
+ info.setProperty("lex", "MYSQL"); // Use MySQL dialect
+ info.setProperty("caseSensitive", "false"); // Disable case sensitivity
+ info.setProperty("unquotedCasing", "TO_LOWER"); // Convert unquoted identifiers to lowercase
+ info.setProperty("quotedCasing", "TO_LOWER");
+ info.setProperty("parserFactory", ServerDdlExecutor.class.getName() + "#PARSER_FACTORY");
+ info.setProperty("materializationsEnabled", "true");
+
+ try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
+ CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
+
+ // Create and add 'city' table
+ DataSchema cityRowType = new DataSchema("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+
+ DataTable cityDataTable = new BaremapsDataTable(
+ cityRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(cityRowType))));
+
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
+ List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
+ List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
+
+ DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
+ rootSchema.add("city", cityDataTableAdapter);
+
+ // Create and add 'population' table
+ DataSchema populationRowType = new DataSchema("population", List.of(
+ new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
+
+ DataTable populationDataTable = new BaremapsDataTable(
+ populationRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(populationRowType))));
+
+ populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
+ populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
+
+ DataTableAdapter populationDataTableAdapter = new DataTableAdapter(populationDataTable);
+ rootSchema.add("population", populationDataTableAdapter);
+
+ String mv = "CREATE MATERIALIZED VIEW city_population AS "
+ + "SELECT c.id, c.name, c.geometry, p.population "
+ + "FROM city c "
+ + "JOIN population p ON c.id = p.city_id";
+
+ // Execute the SQL query
+ try (Statement statement = connection.createStatement()) {
+ statement.execute(mv);
+ }
+
+ // Debug: List all tables in the root schema
+ System.out.println("Available tables in the root schema:");
+ for (String tableName : rootSchema.getTableNames()) {
+ System.out.println(" - " + tableName);
+ }
+
+ String sql = "SELECT * FROM city_population";
+
+ // Execute the SQL query
+ try (Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery(sql);
+ while (resultSet.next()) {
+ System.out.println(resultSet.getInt(1) + " " + resultSet.getString(2) + " " + resultSet.getString(3) + " " + resultSet.getInt(4));
+ }
+ }
- // Convert the SQL query to a relational expression
- RelNode rel = planner.rel(validated).rel;
- Interpreter interpreter = new Interpreter(DataContexts.EMPTY, rel);
+ }
- // Create an interpreter to execute the RelNode
- for (Object[] row : interpreter) {
- listB.add((Integer) row[0]);
}
- // Display the results
- System.out.println("List A: " + listA);
- System.out.println("List B (after SQL): " + listB);
- }
}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
index 5f12ad26c..7b2c16b58 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import org.apache.baremaps.data.util.FileUtils;
@@ -39,6 +40,13 @@ public class MemoryMappedDirectory extends Memory<MappedByteBuffer> {
*/
public MemoryMappedDirectory(Path directory) {
this(directory, 1 << 30);
+ if (!Files.exists(directory)) {
+ try {
+ Files.createDirectories(directory);
+ } catch (IOException e) {
+ throw new MemoryException(e);
+ }
+ }
}
/**
(incubator-baremaps) 04/12: Improve GeoPackage store
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit 00b53075b570a00471c1aa2ece2c141fc1ea2211
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sat Jan 18 14:09:51 2025 +0100
Improve GeoPackage store
---
.../baremaps/geopackage/GeoPackageDataStore.java | 22 +++++++++-------------
.../baremaps/geopackage/GeoPackageDataTable.java | 20 ++++++++++++++++----
2 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataStore.java b/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataStore.java
index 74290917a..71ddb3fb2 100644
--- a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataStore.java
+++ b/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataStore.java
@@ -29,9 +29,9 @@ import org.apache.baremaps.store.DataTable;
/**
* A {@link DataStore} corresponding to a GeoPackage file.
*/
-public class GeoPackageDataStore implements DataStore, AutoCloseable {
+public class GeoPackageDataStore implements DataStore {
- private final GeoPackage geoPackage;
+ private final Path file;
/**
* Constructs a {@link GeoPackageDataStore} from a GeoPackage file.
@@ -39,15 +39,7 @@ public class GeoPackageDataStore implements DataStore, AutoCloseable {
* @param file the path to the GeoPackage file
*/
public GeoPackageDataStore(Path file) {
- this.geoPackage = GeoPackageManager.open(file.toFile());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void close() throws Exception {
- geoPackage.close();
+ this.file = file;
}
/**
@@ -55,7 +47,11 @@ public class GeoPackageDataStore implements DataStore, AutoCloseable {
*/
@Override
public List<String> list() throws DataStoreException {
- return geoPackage.getFeatureTables();
+ try (GeoPackage geoPackage = GeoPackageManager.open(file.toFile())) {
+ return geoPackage.getFeatureTables();
+ } catch (Exception e) {
+ throw new DataStoreException(e);
+ }
}
/**
@@ -63,7 +59,7 @@ public class GeoPackageDataStore implements DataStore, AutoCloseable {
*/
@Override
public DataTable get(String name) throws DataStoreException {
- return new GeoPackageDataTable(geoPackage.getFeatureDao(name));
+ return new GeoPackageDataTable(file, name);
}
/**
diff --git a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java b/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java
index 8ea223665..59e91c180 100644
--- a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java
+++ b/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java
@@ -18,7 +18,10 @@
package org.apache.baremaps.geopackage;
+import java.nio.file.Path;
import java.util.*;
+import mil.nga.geopackage.GeoPackage;
+import mil.nga.geopackage.GeoPackageManager;
import mil.nga.geopackage.features.user.FeatureColumn;
import mil.nga.geopackage.features.user.FeatureDao;
import mil.nga.geopackage.features.user.FeatureResultSet;
@@ -33,6 +36,12 @@ import org.locationtech.jts.geom.*;
*/
public class GeoPackageDataTable implements DataTable {
+ private final Path file;
+
+ private final String name;
+
+ private final GeoPackage geoPackage;
+
private final FeatureDao featureDao;
private final DataSchema schema;
@@ -42,11 +51,14 @@ public class GeoPackageDataTable implements DataTable {
/**
* Constructs a {@link DataTable} from a feature DAO.
*
- * @param featureDao the feature DAO
+ * @param file the path to the GeoPackage file
+ * @param name the name of the data table
*/
- public GeoPackageDataTable(FeatureDao featureDao) {
- this.featureDao = featureDao;
- var name = featureDao.getTableName();
+ public GeoPackageDataTable(Path file, String name) {
+ this.file = file;
+ this.name = name;
+ this.geoPackage = GeoPackageManager.open(file.toFile());
+ this.featureDao = geoPackage.getFeatureDao(name);
var columns = new ArrayList<DataColumn>();
for (FeatureColumn column : featureDao.getColumns()) {
var propertyName = column.getName();
(incubator-baremaps) 07/12: Add header to memory
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit b9ecee262db23c97bb2696e3c20bf6cca4559554
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sun Jan 26 11:43:54 2025 +0100
Add header to memory
---
.../baremaps/calcite/BaremapsTableFactory.java | 91 ++++--
.../baremaps/calcite/BaremapsTableFactoryTest.java | 118 +++++++
.../apache/baremaps/calcite/CalciteTest.java | 51 +--
.../java/org/apache/baremaps/csv/CsvDataStore.java | 6 +-
.../java/org/apache/baremaps/csv/CsvDataTable.java | 343 ++++++++++-----------
.../baremaps/csv/CsvDataTableGeonamesTest.java | 2 +-
.../org/apache/baremaps/csv/CsvDataTableTest.java | 15 +-
.../baremaps/data/collection/AppendOnlyLog.java | 7 +-
.../org/apache/baremaps/data/memory/Memory.java | 63 +++-
.../data/memory/MemoryMappedDirectory.java | 24 +-
.../baremaps/data/memory/MemoryMappedFile.java | 21 +-
.../apache/baremaps/data/memory/OffHeapMemory.java | 12 +-
.../apache/baremaps/data/memory/OnHeapMemory.java | 12 +-
.../java/org/apache/baremaps/store/DataSchema.java | 19 +-
14 files changed, 490 insertions(+), 294 deletions(-)
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
index bd0c99b31..e53de427b 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
@@ -17,37 +17,82 @@
package org.apache.baremaps.calcite;
-import java.io.File;
-import java.io.IOException;
-import java.util.Map;
import org.apache.baremaps.csv.CsvDataTable;
+import org.apache.baremaps.data.collection.AppendOnlyLog;
+import org.apache.baremaps.data.collection.DataCollection;
+import org.apache.baremaps.data.collection.IndexedDataList;
+import org.apache.baremaps.data.memory.Memory;
+import org.apache.baremaps.data.memory.MemoryMappedDirectory;
+import org.apache.baremaps.data.store.DataTableImpl;
+import org.apache.baremaps.data.type.DataType;
+import org.apache.baremaps.data.type.DataTypeImpl;
+import org.apache.baremaps.store.DataRow;
+import org.apache.baremaps.store.DataSchema;
+import org.apache.baremaps.store.DataTable;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeImpl;
import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.TableFactory;
+import java.io.File;
+import java.io.IOException;
+import java.nio.MappedByteBuffer;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+
public class BaremapsTableFactory implements TableFactory<BaremapsTable> {
- public BaremapsTableFactory() {
-
- }
-
- @Override
- public BaremapsTable create(SchemaPlus schema, String name,
- Map<String, Object> operand, RelDataType rowType) {
- final RelProtoDataType protoRowType =
- rowType != null ? RelDataTypeImpl.proto(rowType) : null;
- String file = (String) operand.get("file");
- if (file != null && file.endsWith(".csv")) {
- try {
- return new BaremapsTable(
- new CsvDataTable(new File(file), true),
- protoRowType);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ public BaremapsTableFactory() {
+
}
- return new BaremapsTable(null, protoRowType);
- }
+
+ @Override
+ public BaremapsTable create(
+ SchemaPlus schema,
+ String name,
+ Map<String, Object> operand,
+ RelDataType rowType) {
+ final RelProtoDataType protoRowType =
+ rowType != null ? RelDataTypeImpl.proto(rowType) : null;
+ String format = (String) operand.get("format");
+ DataTable dataTable = switch (format) {
+ case "mmap" -> createMMapTable(schema, name, operand, rowType);
+ case "csv" -> createCsvTable(schema, name, operand, rowType);
+ default -> throw new RuntimeException("Unsupported format");
+ };
+ return new BaremapsTable(dataTable, protoRowType);
+ }
+
+ private DataTable createMMapTable(SchemaPlus schema, String name, Map<String, Object> operand, RelDataType rowType) {
+ String directory = (String) operand.get("directory");
+ if (directory == null) {
+ throw new RuntimeException("A directory should be specified");
+ }
+ try {
+ Path directoryPath = Paths.get(directory);
+ Path schemaFile = directoryPath.resolve("schema.json");
+ DataSchema dataSchema = DataSchema.read(schemaFile);
+ DataType<DataRow> dataType = new DataTypeImpl(dataSchema);
+ Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(directoryPath);
+ DataCollection<DataRow> dataCollection = new AppendOnlyLog<>(dataType, memory);
+ return new DataTableImpl(dataSchema, dataCollection);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private DataTable createCsvTable(SchemaPlus schema, String name, Map<String, Object> operand, RelDataType rowType) {
+ String file = (String) operand.get("file");
+ if (file == null) {
+ throw new RuntimeException("A file should be specified");
+ }
+ try {
+ return new CsvDataTable(name, new File(file), true, ',');
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsTableFactoryTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsTableFactoryTest.java
new file mode 100644
index 000000000..1598163e7
--- /dev/null
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsTableFactoryTest.java
@@ -0,0 +1,118 @@
+package org.apache.baremaps.calcite;
+
+import org.apache.baremaps.data.collection.AppendOnlyLog;
+import org.apache.baremaps.data.memory.MemoryMappedDirectory;
+import org.apache.baremaps.data.store.DataTableImpl;
+import org.apache.baremaps.data.type.DataTypeImpl;
+import org.apache.baremaps.data.util.FileUtils;
+import org.apache.baremaps.store.*;
+import org.apache.baremaps.store.DataColumn.Cardinality;
+import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.junit.jupiter.api.Test;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.GeometryFactory;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.List;
+
+class BaremapsTableFactoryTest {
+
+
+ @Test
+ public void createCsvTable() throws Exception {
+ File file = File.createTempFile("test", ".csv");
+ String csv = """
+ ID,NAME,GEOM
+ 1,Paris,POINT(2.3522 48.8566)
+ 2,New York,POINT(-74.0060 40.7128)
+ """;
+ try (PrintWriter writer = new PrintWriter(file)) {
+ writer.write(csv);
+ }
+ String model = """
+ {
+ version: '1.0',
+ defaultSchema: 'TEST',
+ schemas: [
+ {
+ name: 'TEST',
+ tables: [
+ {
+ name: 'TEST',
+ factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
+ operand: {
+ format: 'csv',
+ file: '%s'
+ }
+ }
+ ]
+ }
+ ]
+ }
+ """.formatted(file.getAbsolutePath());
+ try (Connection connection =
+ DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
+
+ ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
+ while (resultSet.next()) {
+ System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
+ }
+ } finally {
+ file.delete();
+ }
+ }
+
+ @Test
+ public void createMMapTable() throws Exception {
+ Path path = Files.createTempDirectory("temp");
+
+ DataSchema dataSchema = new DataSchemaImpl("test", List.of(
+ new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
+ new DataColumnFixed("name", Cardinality.REQUIRED, ColumnType.STRING),
+ new DataColumnFixed("geom", Cardinality.REQUIRED, ColumnType.GEOMETRY)
+ ));
+
+ DataTable dataTable = new DataTableImpl(dataSchema, new AppendOnlyLog<>(new DataTypeImpl(dataSchema), new MemoryMappedDirectory(path)));
+ dataTable.add(new DataRowImpl(dataSchema, List.of(1, "a", new GeometryFactory().createPoint(new Coordinate(1, 1)))));
+ dataTable.add(new DataRowImpl(dataSchema, List.of(2, "b", new GeometryFactory().createPoint(new Coordinate(2, 2)))));
+ dataTable.close();
+
+ String model = """
+ {
+ version: '1.0',
+ defaultSchema: 'TEST',
+ schemas: [
+ {
+ name: 'TEST',
+ tables: [
+ {
+ name: 'TEST',
+ factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
+ operand: {
+ format: 'mmap',
+ directory: '%s'
+ }
+ }
+ ]
+ }
+ ]
+ }
+ """.formatted(path.toAbsolutePath());
+ try (Connection connection =
+ DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
+
+ ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
+ while (resultSet.next()) {
+ System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
+ }
+ } finally {
+ FileUtils.deleteRecursively(path);
+ }
+ }
+}
\ No newline at end of file
diff --git a/baremaps-calcite/src/test/java/com/apache/baremaps/calcite/CalciteTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
similarity index 86%
rename from baremaps-calcite/src/test/java/com/apache/baremaps/calcite/CalciteTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index 870263c8f..b68d2261c 100644
--- a/baremaps-calcite/src/test/java/com/apache/baremaps/calcite/CalciteTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
@@ -15,13 +15,11 @@
* limitations under the License.
*/
-package com.apache.baremaps.calcite;
+package org.apache.baremaps.calcite;
-import java.io.File;
-import java.io.PrintWriter;
import java.sql.*;
import java.util.*;
-import org.apache.baremaps.calcite.BaremapsTable;
+
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
import org.apache.baremaps.data.store.DataTableImpl;
@@ -247,50 +245,5 @@ public class CalciteTest {
System.out.println("List B (after SQL): " + listB);
}
- @Test
- public void testCsvStream() throws Exception {
- File file = File.createTempFile("test", ".csv");
- String csv = """
- ID,NAME,GEOM
- 1,Paris,POINT(2.3522 48.8566)
- 2,New York,POINT(-74.0060 40.7128)
- """;
- try (PrintWriter writer = new PrintWriter(file)) {
- writer.write(csv);
- }
-
- String model = """
- {
- version: '1.0',
- defaultSchema: 'TEST',
- schemas: [
- {
- name: 'TEST',
- tables: [
- {
- name: 'TEST',
- type: 'custom',
- factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
- operand: {
- file: '%s'
- }
- }
- ]
- }
- ]
- }
- """.formatted(file.getAbsolutePath());
-
- try (Connection connection =
- DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
-
- ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
- while (resultSet.next()) {
- System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
- }
- } finally {
- file.delete();
- }
- }
}
diff --git a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
index 74abb32e3..9bfc41aa2 100644
--- a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
+++ b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
@@ -41,15 +41,15 @@ public class CsvDataStore implements DataStore {
* @param tableName the name of the table
* @param schema the data schema defining the structure
* @param csvFile the CSV file to read data from
- * @param hasHeader whether the CSV file includes a header row
+ * @param header whether the CSV file includes a header row
* @param separator the character used to separate columns in the CSV file
* @throws IOException if an I/O error occurs
*/
- public CsvDataStore(String tableName, DataSchema schema, File csvFile, boolean hasHeader,
+ public CsvDataStore(String tableName, DataSchema schema, File csvFile, boolean header,
char separator) throws IOException {
this.tableName = tableName;
this.schema = schema;
- this.dataTable = new CsvDataTable(csvFile, hasHeader);
+ this.dataTable = new CsvDataTable(tableName, csvFile, header, separator);
}
/**
diff --git a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
index 360debfae..03283ec8a 100644
--- a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
+++ b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
@@ -17,208 +17,195 @@
package org.apache.baremaps.csv;
+import com.fasterxml.jackson.core.FormatSchema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
+import org.apache.baremaps.store.*;
+import org.apache.baremaps.store.DataColumn.Cardinality;
+import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.locationtech.jts.io.WKTReader;
+
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
-import org.locationtech.jts.io.WKTReader;
/**
* A DataTable implementation that reads data from a CSV file using Jackson.
*/
public class CsvDataTable implements DataTable {
- private final File csvFile;
- private final CsvSchema csvSchema;
- private final DataSchema dataSchema;
-
- private final long size;
- private JsonParser parser;
-
- /**
- * Constructs a CsvDataTable with the specified schema, CSV file, header presence, and separator.
- *
- * @param csvFile the CSV file to read data from
- * @param hasHeader whether the CSV file includes a header row
- * @throws IOException if an I/O error occurs
- */
- public CsvDataTable(File csvFile, boolean hasHeader) throws IOException {
- this.csvFile = csvFile;
- this.csvSchema = inferCsvSchema(csvFile);
- this.dataSchema = createDataSchema(csvFile.getName(), csvSchema);
- this.size = calculateSize();
- }
-
-
- private CsvSchema inferCsvSchema(File csvFile) {
- CsvSchema csvSchema = CsvSchema.emptySchema().withUseHeader(true).withColumnSeparator(',');
- try (var ignored = new CsvMapper().readerFor(Map.class)
- .with(csvSchema)
- .createParser(csvFile)) {
- var test = ignored.readValueAsTree();
- return csvSchema;
- } catch (IOException e) {
- throw new DataStoreException("Error reading CSV file", e);
+ private final File file;
+ private final CsvSchema csvSchema;
+ private final DataSchema dataSchema;
+
+ private final long size;
+ private MappingIterator<Map<String, String>> csvIterator;
+
+ /**
+ * Constructs a CsvDataTable with the specified schema, CSV file, header presence, and separator.
+ *
+ * @param name the name of the table
+ * @param csvFile the CSV file to read data from
+ * @param header whether the CSV file includes a header row
+ * @param separator the separator used in the CSV file
+ * @throws IOException if an I/O error occurs
+ */
+ public CsvDataTable(String name, File csvFile, boolean header, char separator) throws IOException {
+ this.file = csvFile;
+
+ // Iterate over all records to infer the csv schema and calculate the size of the table
+ CsvSchema csvSchema = CsvSchema.emptySchema()
+ .withUseHeader(header)
+ .withColumnSeparator(separator);
+
+ try (MappingIterator<Object> iterator = new CsvMapper()
+ .readerFor(Object.class)
+ .with(csvSchema)
+ .readValues(csvFile)) {
+
+ int count = 0;
+ while (iterator.hasNext()) {
+ iterator.next();
+ count++;
+ }
+
+ this.csvSchema = (CsvSchema) iterator.getParserSchema();
+ this.size = count;
+ } catch (IOException e) {
+ throw new DataStoreException("Error reading CSV file", e);
+ }
+
+ // Map the csv schema to a data schema
+ List<DataColumn> columns = new ArrayList<>();
+ for (String columnName : this.csvSchema.getColumnNames()) {
+ switch (this.csvSchema.column(columnName).getType()) {
+ case STRING -> columns
+ .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.STRING));
+ case NUMBER -> columns
+ .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.DOUBLE));
+ case BOOLEAN -> columns
+ .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.BOOLEAN));
+ case ARRAY -> columns
+ .add(new DataColumnFixed(columnName, Cardinality.REPEATED, ColumnType.STRING));
+ default -> throw new IllegalArgumentException(
+ "Unsupported column type: " + csvSchema.column(columnName).getType());
+ }
+ }
+ this.dataSchema = new DataSchemaImpl(name, columns);
}
- }
-
- private DataSchema createDataSchema(String name, CsvSchema csvSchema) {
- List<DataColumn> columns = new ArrayList<>();
- for (String columnName : csvSchema.getColumnNames()) {
- switch (csvSchema.column(columnName).getType()) {
- case STRING -> columns
- .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.STRING));
- case NUMBER -> columns
- .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.DOUBLE));
- case BOOLEAN -> columns
- .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.BOOLEAN));
- case ARRAY -> columns
- .add(new DataColumnFixed(columnName, Cardinality.REPEATED, ColumnType.STRING));
- default -> throw new IllegalArgumentException(
- "Unsupported column type: " + csvSchema.column(columnName).getType());
- }
+
+ @Override
+ public DataSchema schema() {
+ return dataSchema;
}
- return new DataSchemaImpl(name, columns);
- }
-
- /**
- * Calculates the number of rows in the CSV file.
- *
- * @return the number of rows
- * @throws IOException if an I/O error occurs
- */
- private long calculateSize() throws IOException {
- try (var parser = new CsvMapper().readerFor(Map.class)
- .with(csvSchema)
- .createParser(csvFile)) {
- long rowCount = 0;
- while (parser.nextToken() != null) {
- if (parser.currentToken() == JsonToken.START_OBJECT) {
- rowCount++;
- }
- }
- return rowCount;
+
+ @Override
+ public boolean add(DataRow row) {
+ throw new UnsupportedOperationException("Adding rows is not supported.");
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException("Clearing rows is not supported.");
+ }
+
+ @Override
+ public long size() {
+ return size;
}
- }
-
- @Override
- public DataSchema schema() {
- return dataSchema;
- }
-
- @Override
- public boolean add(DataRow row) {
- throw new UnsupportedOperationException("Adding rows is not supported.");
- }
-
- @Override
- public void clear() {
- throw new UnsupportedOperationException("Clearing rows is not supported.");
- }
-
- @Override
- public long size() {
- return size;
- }
-
- @Override
- public Iterator<DataRow> iterator() {
- try {
- CsvMapper csvMapper = new CsvMapper();
- parser = csvMapper.readerFor(Map.class)
- .with(csvSchema)
- .createParser(csvFile);
-
- Iterator<Map<String, String>> csvIterator = csvMapper.readerFor(Map.class)
- .with(csvSchema)
- .readValues(parser);
-
- return new Iterator<>() {
- @Override
- public boolean hasNext() {
- return csvIterator.hasNext();
+
+ @Override
+ public Iterator<DataRow> iterator() {
+ try {
+
+ csvIterator = new CsvMapper()
+ .readerFor(Map.class)
+ .with(csvSchema)
+ .readValues(file);
+
+ return new Iterator<>() {
+ @Override
+ public boolean hasNext() {
+ return csvIterator.hasNext();
+ }
+
+ @Override
+ public DataRow next() {
+ Map<String, String> csvRow = csvIterator.next();
+ DataRow dataRow = dataSchema.createRow();
+
+ for (int i = 0; i < dataSchema.columns().size(); i++) {
+ DataColumn column = dataSchema.columns().get(i);
+ String columnName = column.name();
+ String value = csvRow.get(columnName);
+
+ if (value != null) {
+ Object parsedValue = parseValue(column, value);
+ dataRow.set(i, parsedValue);
+ } else {
+ dataRow.set(i, null);
+ }
+ }
+ return dataRow;
+ }
+ };
+
+ } catch (IOException e) {
+ throw new DataStoreException("Error reading CSV file", e);
}
+ }
- @Override
- public DataRow next() {
- Map<String, String> csvRow = csvIterator.next();
- DataRow dataRow = dataSchema.createRow();
-
- for (int i = 0; i < dataSchema.columns().size(); i++) {
- DataColumn column = dataSchema.columns().get(i);
- String columnName = column.name();
- String value = csvRow.get(columnName);
-
- if (value != null) {
- Object parsedValue = parseValue(column, value);
- dataRow.set(i, parsedValue);
- } else {
- dataRow.set(i, null);
+ /**
+ * Parses the string value from the CSV according to the column type.
+ *
+ * @param column the data column
+ * @param value the string value from the CSV
+ * @return the parsed value
+ */
+ private Object parseValue(DataColumn column, String value) {
+ ColumnType type = column.type();
+ try {
+ if (value == null || value.isEmpty()) {
+ return null;
}
- }
- return dataRow;
+ return switch (type) {
+ case STRING -> value;
+ case INTEGER -> Integer.parseInt(value);
+ case LONG -> Long.parseLong(value);
+ case FLOAT -> Float.parseFloat(value);
+ case DOUBLE -> Double.parseDouble(value);
+ case BOOLEAN -> Boolean.parseBoolean(value);
+ case GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON,
+ GEOMETRYCOLLECTION -> {
+ WKTReader reader = new WKTReader();
+ yield reader.read(value);
+ }
+ default -> throw new IllegalArgumentException("Unsupported column type: " + type);
+ };
+ } catch (Exception e) {
+ throw new DataStoreException("Error parsing value for column " + column.name(), e);
}
- };
+ }
- } catch (IOException e) {
- throw new DataStoreException("Error reading CSV file", e);
+ @Override
+ public Spliterator<DataRow> spliterator() {
+ return Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED);
}
- }
-
- /**
- * Parses the string value from the CSV according to the column type.
- *
- * @param column the data column
- * @param value the string value from the CSV
- * @return the parsed value
- */
- private Object parseValue(DataColumn column, String value) {
- ColumnType type = column.type();
- try {
- if (value == null || value.isEmpty()) {
- return null;
- }
- return switch (type) {
- case STRING -> value;
- case INTEGER -> Integer.parseInt(value);
- case LONG -> Long.parseLong(value);
- case FLOAT -> Float.parseFloat(value);
- case DOUBLE -> Double.parseDouble(value);
- case BOOLEAN -> Boolean.parseBoolean(value);
- case GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON,
- GEOMETRYCOLLECTION -> {
- WKTReader reader = new WKTReader();
- yield reader.read(value);
- }
- default -> throw new IllegalArgumentException("Unsupported column type: " + type);
- };
- } catch (Exception e) {
- throw new DataStoreException("Error parsing value for column " + column.name(), e);
+
+ @Override
+ public Stream<DataRow> stream() {
+ return StreamSupport.stream(spliterator(), false);
}
- }
-
- @Override
- public Spliterator<DataRow> spliterator() {
- return Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED);
- }
-
- @Override
- public Stream<DataRow> stream() {
- return StreamSupport.stream(spliterator(), false);
- }
-
- @Override
- public void close() throws IOException {
- if (parser != null) {
- parser.close();
+
+ @Override
+ public void close() throws IOException {
+ if (csvIterator != null) {
+ csvIterator.close();
+ }
}
- }
}
diff --git a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
index 489634505..71776b724 100644
--- a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
+++ b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
@@ -29,7 +29,7 @@ class CsvDataTableGeonamesTest {
@Test
void testGeonamesCsvDataTable() throws IOException {
- DataTable dataTable = new CsvDataTable(GEONAMES_CSV.toFile(), false);
+ DataTable dataTable = new CsvDataTable("sample", GEONAMES_CSV.toFile(), false, '\t');
assertEquals(5, dataTable.size(), "DataTable should have 5 rows.");
diff --git a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
index 444b37996..bb67934df 100644
--- a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
+++ b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
@@ -58,7 +58,7 @@ class CsvDataTableTest {
2,PointB,"POINT(2 2)"
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
- DataTable dataTable = new CsvDataTable(tempCsvFile, true);
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -86,8 +86,7 @@ class CsvDataTableTest {
new DataColumnFixed("column1", Cardinality.REQUIRED, ColumnType.INTEGER),
new DataColumnFixed("column2", Cardinality.OPTIONAL, ColumnType.STRING),
new DataColumnFixed("column3", Cardinality.OPTIONAL, ColumnType.GEOMETRY));
- DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(tempCsvFile, false);
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, false, ';');
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -120,8 +119,7 @@ class CsvDataTableTest {
new DataColumnFixed("double_col", Cardinality.REQUIRED, ColumnType.DOUBLE),
new DataColumnFixed("bool_col", Cardinality.REQUIRED, ColumnType.BOOLEAN),
new DataColumnFixed("string_col", Cardinality.REQUIRED, ColumnType.STRING));
- DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(tempCsvFile, true);
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -150,8 +148,7 @@ class CsvDataTableTest {
List<DataColumn> columns = List.of(
new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING));
- DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(tempCsvFile, true);
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
assertThrows(RuntimeException.class, () -> {
for (DataRow row : dataTable) {
// This line should throw an exception because abc is not a valid integer
@@ -164,7 +161,7 @@ class CsvDataTableTest {
void testAddAndClearUnsupportedOperations() throws IOException {
String csvContent = "";
Files.writeString(tempCsvFile.toPath(), csvContent);
- DataTable dataTable = new CsvDataTable(tempCsvFile, true);
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
assertThrows(UnsupportedOperationException.class, () -> dataTable.add(null));
assertThrows(UnsupportedOperationException.class, dataTable::clear);
}
@@ -178,7 +175,7 @@ class CsvDataTableTest {
3,Name3
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
- DataTable dataTable = new CsvDataTable(tempCsvFile, true);
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
assertEquals(3, dataTable.size());
}
}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/AppendOnlyLog.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/AppendOnlyLog.java
index c5e9adbdc..da647e5c9 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/AppendOnlyLog.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/AppendOnlyLog.java
@@ -127,8 +127,8 @@ public class AppendOnlyLog<E> implements DataCollection<E> {
this.dataType = dataType;
this.memory = memory;
this.segmentSize = memory.segmentSize();
- this.offset = Long.BYTES;
- this.size = memory.segment(0).getLong(0);
+ this.size = memory.header().getLong(0);
+ this.offset = 0;
}
/**
@@ -220,6 +220,7 @@ public class AppendOnlyLog<E> implements DataCollection<E> {
@Override
public void close() throws Exception {
try {
+ memory.header().putLong(0, size);
memory.close();
} catch (IOException e) {
throw new DataCollectionException(e);
@@ -238,7 +239,7 @@ public class AppendOnlyLog<E> implements DataCollection<E> {
private AppendOnlyLogIterator(long size) {
this.size = size;
index = 0;
- position = Long.BYTES;
+ position = 0;
}
@Override
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java
index 56dd45a14..110f16eeb 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/Memory.java
@@ -25,13 +25,17 @@ import java.util.List;
/** A base class for managing on-heap, off-heap, or memory-mapped segments. */
public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
+ private final int headerSize;
+
private final int segmentSize;
private final long segmentShift;
private final long segmentMask;
- protected final List<T> segments = new ArrayList<>();
+ protected T header;
+
+ protected List<T> segments = new ArrayList<>();
// Flag to track if this Memory has been closed
protected volatile boolean closed = false;
@@ -42,17 +46,31 @@ public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
* @param segmentSize the size of the segments (must be a power of 2)
* @throws IllegalArgumentException if the segment size is not a power of 2
*/
- protected Memory(int segmentSize) {
+ protected Memory(int headerSize, int segmentSize) {
if ((segmentSize & -segmentSize) != segmentSize) {
throw new IllegalArgumentException("The segment size must be a power of 2");
}
+ this.headerSize = headerSize;
this.segmentSize = segmentSize;
this.segmentShift = (long) (Math.log(this.segmentSize) / Math.log(2));
this.segmentMask = this.segmentSize - 1l;
}
/**
+<<<<<<< HEAD
* Returns the size of each segment.
+=======
+ * Returns the size of the header.
+ *
+ * @return the size of the header
+ */
+ public int headerSize() {
+ return headerSize;
+ }
+
+ /**
+ * Returns the size of the segments.
+>>>>>>> 251ea904 (Add header to memory)
*
* @return the segment size in bytes
*/
@@ -78,6 +96,22 @@ public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
return segmentMask;
}
+ public ByteBuffer header() {
+ if (header == null) {
+ synchronized (this) {
+ header = allocateHeader();
+ }
+ }
+ return header;
+ }
+
+ /**
+ * Allocates a header.
+ *
+ * @return the header
+ */
+ protected abstract T allocateHeader();
+
/**
* Returns a segment at the specified index, allocating it if necessary.
*
@@ -87,11 +121,11 @@ public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
*/
public ByteBuffer segment(int index) {
if (segments.size() <= index) {
- return allocate(index);
+ return allocateSegmentInternal(index);
}
ByteBuffer segment = segments.get(index);
if (segment == null) {
- return allocate(index);
+ return allocateSegmentInternal(index);
}
return segment;
}
@@ -145,14 +179,26 @@ public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
return (long) segments.size() * (long) segmentSize;
}
+ /** The allocation of segments is synchronized to enable access by multiple threads. */
+ private synchronized ByteBuffer allocateSegmentInternal(int index) {
+ while (segments.size() <= index) {
+ segments.add(null);
+ }
+ T segment = segments.get(index);
+ if (segment == null) {
+ segment = allocateSegment(index);
+ segments.set(index, segment);
+ }
+ return segment;
+ }
+
/**
* Allocates a segment of the specified size.
*
- * @param index the segment index
- * @param size the segment size in bytes
- * @return the allocated segment
+ * @param index the index of the segment
+ * @return the segment
*/
- protected abstract T allocate(int index, int size);
+ protected abstract T allocateSegment(int index);
/**
* Releases resources associated with this memory. Unlike {@link #clear()}, this method does not
@@ -174,4 +220,5 @@ public abstract class Memory<T extends ByteBuffer> implements AutoCloseable {
* @throws IOException if an I/O error occurs
*/
public abstract void clear() throws IOException;
+
}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
index d00e3a90a..a45f2eaea 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
@@ -48,18 +48,31 @@ public class MemoryMappedDirectory extends Memory<MappedByteBuffer> {
* @param segmentBytes the size of each segment in bytes
*/
public MemoryMappedDirectory(Path directory, int segmentBytes) {
- super(segmentBytes);
+ super(1024, segmentBytes);
this.directory = directory;
}
+ @Override
+ protected MappedByteBuffer allocateHeader() {
+ try {
+ Path file = directory.resolve("header");
+ try (FileChannel channel = FileChannel.open(file, StandardOpenOption.CREATE,
+ StandardOpenOption.READ, StandardOpenOption.WRITE)) {
+ return channel.map(MapMode.READ_WRITE, 0, 1024);
+ }
+ } catch (IOException e) {
+ throw new MemoryException(e);
+ }
+ }
+
/** {@inheritDoc} */
@Override
- protected MappedByteBuffer allocate(int index, int size) {
+ protected MappedByteBuffer allocateSegment(int index) {
try {
Path file = directory.resolve(String.format("%s.part", index));
try (FileChannel channel = FileChannel.open(file, StandardOpenOption.CREATE,
StandardOpenOption.READ, StandardOpenOption.WRITE)) {
- return channel.map(MapMode.READ_WRITE, 0, size);
+ return channel.map(MapMode.READ_WRITE, 0, segmentSize());
}
} catch (IOException e) {
throw new MemoryException(e);
@@ -73,7 +86,7 @@ public class MemoryMappedDirectory extends Memory<MappedByteBuffer> {
*/
@Override
public synchronized void close() throws IOException {
- // Release MappedByteBuffer resources
+ MappedByteBufferUtils.unmap(header);
for (MappedByteBuffer buffer : segments) {
if (buffer != null) {
MappedByteBufferUtils.unmap(buffer);
@@ -91,7 +104,8 @@ public class MemoryMappedDirectory extends Memory<MappedByteBuffer> {
// Release resources first
close();
- // Clear the segment list
+ // Clear the header and segment list
+ header.clear();
segments.clear();
// Delete the directory and all files in it
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedFile.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedFile.java
index 54a9ddeb0..daafaeff8 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedFile.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedFile.java
@@ -47,17 +47,32 @@ public class MemoryMappedFile extends Memory<MappedByteBuffer> {
* @param segmentBytes the size of each segment in bytes
*/
public MemoryMappedFile(Path file, int segmentBytes) {
- super(segmentBytes);
+ super(1024, segmentBytes);
this.file = file;
}
+ @Override
+ protected MappedByteBuffer allocateHeader() {
+ try {
+ try (FileChannel channel = FileChannel.open(file, StandardOpenOption.CREATE,
+ StandardOpenOption.READ, StandardOpenOption.WRITE)) {
+ return channel.map(MapMode.READ_WRITE, 0, headerSize());
+ }
+ } catch (IOException e) {
+ throw new MemoryException(e);
+ }
+ }
+
/** {@inheritDoc} */
@Override
- protected MappedByteBuffer allocate(int index, int size) {
+ protected MappedByteBuffer allocateSegment(int index) {
try {
try (FileChannel channel = FileChannel.open(file, StandardOpenOption.CREATE,
StandardOpenOption.READ, StandardOpenOption.WRITE)) {
- return channel.map(MapMode.READ_WRITE, (long) index * size, size);
+ int headerSize = headerSize();
+ int segmentSize = segmentSize();
+ int segmentPosition = headerSize + index * segmentSize;
+ return channel.map(MapMode.READ_WRITE, segmentPosition, segmentSize);
}
} catch (IOException e) {
throw new MemoryException(e);
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/OffHeapMemory.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/OffHeapMemory.java
index 66a2b7f2e..f966c2052 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/OffHeapMemory.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/OffHeapMemory.java
@@ -34,13 +34,19 @@ public class OffHeapMemory extends Memory<ByteBuffer> {
* @param segmentSize the size of each segment in bytes
*/
public OffHeapMemory(int segmentSize) {
- super(segmentSize);
+ super(1024, segmentSize);
}
/** {@inheritDoc} */
@Override
- protected ByteBuffer allocate(int index, int size) {
- return ByteBuffer.allocateDirect(size);
+ protected ByteBuffer allocateHeader() {
+ return ByteBuffer.allocateDirect(headerSize());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected ByteBuffer allocateSegment(int index) {
+ return ByteBuffer.allocateDirect(segmentSize());
}
/**
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/OnHeapMemory.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/OnHeapMemory.java
index d0be3968e..955b73f9d 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/OnHeapMemory.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/OnHeapMemory.java
@@ -34,13 +34,19 @@ public class OnHeapMemory extends Memory<ByteBuffer> {
* @param segmentSize the size of each segment in bytes
*/
public OnHeapMemory(int segmentSize) {
- super(segmentSize);
+ super(1024, segmentSize);
}
/** {@inheritDoc} */
@Override
- protected ByteBuffer allocate(int index, int size) {
- return ByteBuffer.allocate(size);
+ protected ByteBuffer allocateHeader() {
+ return ByteBuffer.allocate(headerSize());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected ByteBuffer allocateSegment(int index) {
+ return ByteBuffer.allocate(segmentSize());
}
/**
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
index aef70f1e7..a2dcfecd8 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
@@ -27,6 +27,8 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.io.Serializable;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@@ -36,7 +38,7 @@ import org.apache.baremaps.store.DataColumn.ColumnType;
/**
* A {@link DataSchema} is a description of the structure of a row in a {@link DataTable}.
*/
-public interface DataSchema extends Serializable {
+public interface DataSchema {
/**
* Returns the name of the schema.
@@ -100,14 +102,19 @@ public interface DataSchema extends Serializable {
return mapper;
}
- static DataSchema read(Path path) throws IOException {
+ static DataSchema read(ByteBuffer buffer) throws IOException {
var mapper = configureObjectMapper();
- return mapper.readValue(path.toFile(), DataSchema.class);
+ int length = buffer.getInt();
+ byte[] bytes = new byte[length];
+ buffer.get(bytes);
+ return mapper.readValue(bytes, DataSchema.class);
}
- static void write(Path path, DataSchema schema) throws IOException {
+ static void write(ByteBuffer buffer, DataSchema schema) throws IOException {
var mapper = configureObjectMapper();
- mapper.writerWithDefaultPrettyPrinter().writeValue(path.toFile(), schema);
+ var bytes = mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(schema);
+ buffer.putInt(bytes.length);
+ buffer.put(bytes);
}
-
+
}
(incubator-baremaps) 03/12: Format code
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit a7c82af440ce8aa0ddd2c8568ea5623dcee01ee1
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Fri Jan 17 18:39:12 2025 +0100
Format code
---
.../org/apache/baremaps/calcite/CalciteTest.java | 2 +-
.../data/calcite/CalciteMultipleDDLParser.java | 14 -
.../data/{calcite => store}/BaremapsDataTable.java | 2 +-
.../apache/baremaps/data/calcite/CalciteTest.java | 365 ++++++++++-----------
4 files changed, 170 insertions(+), 213 deletions(-)
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 df1deb0dc..482d15885 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
@@ -22,10 +22,10 @@ import com.google.common.collect.ImmutableList;
import java.sql.*;
import java.util.List;
import java.util.Properties;
-import org.apache.baremaps.data.calcite.BaremapsDataTable;
import org.apache.baremaps.data.calcite.SqlDataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
+import org.apache.baremaps.data.store.BaremapsDataTable;
import org.apache.baremaps.data.type.RowDataType;
import org.apache.baremaps.maplibre.vectortile.VectorTileFunctions;
import org.apache.baremaps.store.*;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/CalciteMultipleDDLParser.java b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/CalciteMultipleDDLParser.java
deleted file mode 100644
index 04984fd3e..000000000
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/CalciteMultipleDDLParser.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.apache.baremaps.data.calcite;
-
-import org.apache.calcite.config.Lex;
-import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.SqlNodeList;
-import org.apache.calcite.sql.parser.SqlParser;
-import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
-import org.apache.calcite.sql.validate.SqlConformanceEnum;
-
-public class CalciteMultipleDDLParser {
- public static void main(String[] args) throws Exception {
-
- }
-}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/BaremapsDataTable.java b/baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java
similarity index 97%
rename from baremaps-data/src/main/java/org/apache/baremaps/data/calcite/BaremapsDataTable.java
rename to baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java
index 55ddee115..89123dab6 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/BaremapsDataTable.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.calcite;
+package org.apache.baremaps.data.store;
import java.util.Iterator;
import org.apache.baremaps.data.collection.DataCollection;
diff --git a/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java b/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
index 9e7fc96d6..fd645d163 100644
--- a/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
+++ b/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
@@ -17,257 +17,228 @@
package org.apache.baremaps.data.calcite;
-import com.google.common.collect.ImmutableList;
+import java.sql.*;
+import java.util.*;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
+import org.apache.baremaps.data.store.BaremapsDataTable;
import org.apache.baremaps.data.type.RowDataType;
+import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
import org.apache.baremaps.store.DataColumn.Type;
-import org.apache.baremaps.store.*;
import org.apache.calcite.DataContext;
import org.apache.calcite.DataContexts;
-import org.apache.calcite.adapter.enumerable.EnumerableConvention;
-import org.apache.calcite.adapter.enumerable.EnumerableInterpreter;
-import org.apache.calcite.config.Lex;
import org.apache.calcite.interpreter.Interpreter;
import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Linq4j;
-import org.apache.calcite.model.ModelHandler;
-import org.apache.calcite.plan.RelOptCluster;
-import org.apache.calcite.plan.RelOptPlanner;
-import org.apache.calcite.plan.RelTraitSet;
-import org.apache.calcite.plan.volcano.VolcanoPlanner;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.rex.RexBuilder;
-import org.apache.calcite.runtime.SpatialTypeFunctions;
import org.apache.calcite.schema.ScannableTable;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.impl.*;
-import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.SqlNodeList;
-import org.apache.calcite.sql.fun.SqlSpatialTypeFunctions;
-import org.apache.calcite.sql.parser.SqlParseException;
-import org.apache.calcite.sql.parser.SqlParser;
-import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.calcite.tools.Frameworks;
import org.apache.calcite.tools.Planner;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
-import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
-import org.apache.calcite.adapter.enumerable.EnumerableRel;
-import org.apache.calcite.adapter.enumerable.EnumerableInterpreter;
-import org.apache.calcite.adapter.enumerable.EnumerableRelImplementor;
-import org.apache.calcite.linq4j.Enumerator;
-import org.apache.calcite.plan.*;
-import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.schema.SchemaPlus;
-import org.apache.calcite.tools.*;
-
-import java.sql.*;
-import java.util.*;
public class CalciteTest {
- @Test
- void sql() throws SQLException {
- GeometryFactory geometryFactory = new GeometryFactory();
-
- // Configure Calcite connection properties
- Properties info = new Properties();
- info.setProperty("lex", "MYSQL"); // Use MySQL dialect
- info.setProperty("caseSensitive", "false"); // Disable case sensitivity
- info.setProperty("unquotedCasing", "TO_LOWER"); // Convert unquoted identifiers to lowercase
- info.setProperty("quotedCasing", "TO_LOWER");
-
- try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
- CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
- SchemaPlus rootSchema = calciteConnection.getRootSchema();
-
- // Create and add 'city' table
- DataSchema cityRowType = new DataSchemaImpl("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
-
- DataTable cityDataTable = new BaremapsDataTable(
- cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType))));
-
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
- List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
- List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
-
- SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
- rootSchema.add("city", citySqlDataTable);
-
- // Create and add 'population' table
- DataSchema populationRowType = new DataSchemaImpl("population", List.of(
- new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
-
- DataTable populationDataTable = new BaremapsDataTable(
- populationRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(populationRowType))));
-
- populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(1, 2_161_000)));
- populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(2, 8_336_000)));
-
- SqlDataTable populationSqlDataTable = new SqlDataTable(populationDataTable);
- rootSchema.add("population", populationSqlDataTable);
-
- // Create view 'city_population'
- String mvSql = "SELECT c.id, c.name, c.geometry, p.population " +
- "FROM city c " + // lowercase and unquoted
- "JOIN population p ON c.id = p.city_id";
-
- ViewTableMacro materializedView = MaterializedViewTable.viewMacro(
- rootSchema,
- mvSql,
- Collections.emptyList(), // Schema path
- List.of("city_population"), // Name parts
- false); // Not a materialized view
-
-
- rootSchema.add("city_population", materializedView);
-
- // Debug: List all tables in the root schema
- System.out.println("Available tables in the root schema:");
- for (String tableName : rootSchema.getTableNames()) {
- System.out.println(" - " + tableName);
- }
-
- String sql = "SELECT * FROM city";
- try (Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(sql)) {
- while (resultSet.next()) {
- System.out.println(resultSet.getString("id") + " " + resultSet.getString("geometry"));
- }
- }
-
- // Query the view
- sql = "SELECT * FROM city_population";
- try (Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(sql)) {
- while (resultSet.next()) {
- System.out.println(
- resultSet.getString("id") + " " + resultSet.getString("name")
- );
- }
- }
+ @Test
+ void sql() throws SQLException {
+ GeometryFactory geometryFactory = new GeometryFactory();
+
+ // Configure Calcite connection properties
+ Properties info = new Properties();
+ info.setProperty("lex", "MYSQL"); // Use MySQL dialect
+ info.setProperty("caseSensitive", "false"); // Disable case sensitivity
+ info.setProperty("unquotedCasing", "TO_LOWER"); // Convert unquoted identifiers to lowercase
+ info.setProperty("quotedCasing", "TO_LOWER");
+
+ try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
+ CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
+
+ // Create and add 'city' table
+ DataSchema cityRowType = new DataSchemaImpl("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+
+ DataTable cityDataTable = new BaremapsDataTable(
+ cityRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType))));
+
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
+
+ SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
+ rootSchema.add("city", citySqlDataTable);
+
+ // Create and add 'population' table
+ DataSchema populationRowType = new DataSchemaImpl("population", List.of(
+ new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
+
+ DataTable populationDataTable = new BaremapsDataTable(
+ populationRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(populationRowType))));
+
+ populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(1, 2_161_000)));
+ populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(2, 8_336_000)));
+
+ SqlDataTable populationSqlDataTable = new SqlDataTable(populationDataTable);
+ rootSchema.add("population", populationSqlDataTable);
+
+ // Create view 'city_population'
+ String mvSql = "SELECT c.id, c.name, c.geometry, p.population " +
+ "FROM city c " + // lowercase and unquoted
+ "JOIN population p ON c.id = p.city_id";
+
+ ViewTableMacro materializedView = MaterializedViewTable.viewMacro(
+ rootSchema,
+ mvSql,
+ Collections.emptyList(), // Schema path
+ List.of("city_population"), // Name parts
+ false); // Not a materialized view
+
+
+ rootSchema.add("city_population", materializedView);
+
+ // Debug: List all tables in the root schema
+ System.out.println("Available tables in the root schema:");
+ for (String tableName : rootSchema.getTableNames()) {
+ System.out.println(" - " + tableName);
+ }
+
+ String sql = "SELECT * FROM city";
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(sql)) {
+ while (resultSet.next()) {
+ System.out.println(resultSet.getString("id") + " " + resultSet.getString("geometry"));
}
-
+ }
+
+ // Query the view
+ sql = "SELECT * FROM city_population";
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(sql)) {
+ while (resultSet.next()) {
+ System.out.println(
+ resultSet.getString("id") + " " + resultSet.getString("name"));
+ }
+ }
}
- public class ListTable extends AbstractTable implements ScannableTable {
- private final List<Integer> data;
+ }
- public ListTable(List<Integer> data) {
- this.data = data;
- }
+ public class ListTable extends AbstractTable implements ScannableTable {
+ private final List<Integer> data;
- @Override
- public RelDataType getRowType(RelDataTypeFactory typeFactory) {
- // Define a single column named "value" of type INTEGER
- return typeFactory.builder()
- .add("V", SqlTypeName.INTEGER)
- .build();
- }
+ public ListTable(List<Integer> data) {
+ this.data = data;
+ }
- @Override
- public Enumerable<Object[]> scan(DataContext root) {
- // Convert the List<Integer> to Enumerable<Object[]>
- return Linq4j.asEnumerable(data)
- .select(i -> new Object[]{i});
- }
+ @Override
+ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ // Define a single column named "value" of type INTEGER
+ return typeFactory.builder()
+ .add("V", SqlTypeName.INTEGER)
+ .build();
}
- public class ListSchema extends AbstractSchema {
- private final List<Integer> listA;
- private final List<Integer> listB;
+ @Override
+ public Enumerable<Object[]> scan(DataContext root) {
+ // Convert the List<Integer> to Enumerable<Object[]>
+ return Linq4j.asEnumerable(data)
+ .select(i -> new Object[] {i});
+ }
+ }
- public ListSchema(List<Integer> listA, List<Integer> listB) {
- this.listA = listA;
- this.listB = listB;
- }
+ public class ListSchema extends AbstractSchema {
+ private final List<Integer> listA;
+ private final List<Integer> listB;
- @Override
- protected Map<String, Table> getTableMap() {
- Map<String, Table> tables = new HashMap<>();
- tables.put("LIST_A", new ListTable(listA));
- tables.put("LIST_B", new ListTable(listB)); // Initially empty
- return tables;
- }
+ public ListSchema(List<Integer> listA, List<Integer> listB) {
+ this.listA = listA;
+ this.listB = listB;
}
- @Test
- void list() throws Exception {
- // Initialize your Java lists
- List<Integer> listA = List.of(1, 2, 3, 4, 5);
- List<Integer> listB = new ArrayList<>();
+ @Override
+ protected Map<String, Table> getTableMap() {
+ Map<String, Table> tables = new HashMap<>();
+ tables.put("LIST_A", new ListTable(listA));
+ tables.put("LIST_B", new ListTable(listB)); // Initially empty
+ return tables;
+ }
+ }
- // Set up Calcite schema
- SchemaPlus rootSchema = Frameworks.createRootSchema(true);
- rootSchema.add("MY_SCHEMA", new ListSchema(listA, listB));
+ @Test
+ void list() throws Exception {
+ // Initialize your Java lists
+ List<Integer> listA = List.of(1, 2, 3, 4, 5);
+ List<Integer> listB = new ArrayList<>();
- // Create and add 'city' table
- DataSchema cityRowType = new DataSchemaImpl("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+ // Set up Calcite schema
+ SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+ rootSchema.add("MY_SCHEMA", new ListSchema(listA, listB));
- DataTable cityDataTable = new BaremapsDataTable(
- cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType))));
+ // Create and add 'city' table
+ DataSchema cityRowType = new DataSchemaImpl("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
- GeometryFactory geometryFactory = new GeometryFactory();
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
- List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
- List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
+ DataTable cityDataTable = new BaremapsDataTable(
+ cityRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType))));
- SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
- rootSchema.add("CITY", citySqlDataTable);
+ GeometryFactory geometryFactory = new GeometryFactory();
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
- // Configure the framework
- FrameworkConfig config = Frameworks.newConfigBuilder()
- .defaultSchema(rootSchema.getSubSchema("MY_SCHEMA"))
- .build();
+ SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
+ rootSchema.add("CITY", citySqlDataTable);
- // Create a planner
- Planner planner = Frameworks.getPlanner(config);
+ // Configure the framework
+ FrameworkConfig config = Frameworks.newConfigBuilder()
+ .defaultSchema(rootSchema.getSubSchema("MY_SCHEMA"))
+ .build();
- // Define the SQL query to populate list_b from list_a
- String sql = "SELECT V * 2 AS V FROM LIST_A";
+ // Create a planner
+ Planner planner = Frameworks.getPlanner(config);
- // Parse the SQL query
- org.apache.calcite.sql.SqlNode parsed = planner.parse(sql);
+ // Define the SQL query to populate list_b from list_a
+ String sql = "SELECT V * 2 AS V FROM LIST_A";
- // Validate the SQL query
- org.apache.calcite.sql.SqlNode validated = planner.validate(parsed);
+ // Parse the SQL query
+ org.apache.calcite.sql.SqlNode parsed = planner.parse(sql);
- // Convert the SQL query to a relational expression
- RelNode rel = planner.rel(validated).rel;
+ // Validate the SQL query
+ org.apache.calcite.sql.SqlNode validated = planner.validate(parsed);
- Interpreter interpreter = new Interpreter(DataContexts.EMPTY, rel);
+ // Convert the SQL query to a relational expression
+ RelNode rel = planner.rel(validated).rel;
- // Create an interpreter to execute the RelNode
- for (Object[] row : interpreter.asEnumerable()) {
- listB.add((Integer) row[0]);
- }
+ Interpreter interpreter = new Interpreter(DataContexts.EMPTY, rel);
- // Display the results
- System.out.println("List A: " + listA);
- System.out.println("List B (after SQL): " + listB);
+ // Create an interpreter to execute the RelNode
+ for (Object[] row : interpreter.asEnumerable()) {
+ listB.add((Integer) row[0]);
}
+ // Display the results
+ System.out.println("List A: " + listA);
+ System.out.println("List B (after SQL): " + listB);
+ }
+
}
(incubator-baremaps) 08/12: Fix issues in header
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit 9196a7fbe48f6af88cb58c332b2f853c51a3832e
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Mon Feb 3 09:04:31 2025 +0100
Fix issues in header
---
.../baremaps/calcite/BaremapsTableFactory.java | 108 ++++---
.../{BaremapsTable.java => DataTableAdapter.java} | 6 +-
.../baremaps/calcite/BaremapsTableFactoryTest.java | 118 -------
.../org/apache/baremaps/calcite/CalciteTest.java | 15 +-
.../calcite/DataTableAdapterFactoryTest.java | 154 +++++++++
.../java/org/apache/baremaps/utils/FileUtils.java | 36 ---
.../apache/baremaps/workflow/WorkflowContext.java | 2 +-
.../integration/GeoPackageToPostgresTest.java | 4 +-
.../integration/GeoParquetToPostgresTest.java | 4 +-
.../java/org/apache/baremaps/csv/CsvDataStore.java | 2 +-
.../java/org/apache/baremaps/csv/CsvDataTable.java | 348 ++++++++++++---------
.../baremaps/csv/CsvDataTableGeonamesTest.java | 2 +-
.../org/apache/baremaps/csv/CsvDataTableTest.java | 24 +-
.../data/memory/MemoryMappedDirectory.java | 10 +-
.../baremaps/data/memory/MemoryMappedFile.java | 2 +-
.../apache/baremaps/data/store/DataStoreImpl.java | 3 +-
.../org/apache/baremaps/data/util/FileUtils.java | 5 +
.../geopackage/GeoPackageDataStoreTest.java | 4 +-
.../openstreetmap/OpenStreetMapDataTableTest.java | 4 +-
.../postgres/store/PostgresDataTableTest.java | 4 +-
.../apache/baremaps/rpsl/RsplDataTableTest.java | 4 +-
.../java/org/apache/baremaps/store/DataSchema.java | 19 +-
22 files changed, 475 insertions(+), 403 deletions(-)
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
index e53de427b..7553deb57 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
@@ -17,10 +17,16 @@
package org.apache.baremaps.calcite;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.file.Paths;
+import java.util.Map;
import org.apache.baremaps.csv.CsvDataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.DataCollection;
-import org.apache.baremaps.data.collection.IndexedDataList;
import org.apache.baremaps.data.memory.Memory;
import org.apache.baremaps.data.memory.MemoryMappedDirectory;
import org.apache.baremaps.data.store.DataTableImpl;
@@ -35,64 +41,62 @@ import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.TableFactory;
-import java.io.File;
-import java.io.IOException;
-import java.nio.MappedByteBuffer;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Map;
+public class BaremapsTableFactory implements TableFactory<DataTableAdapter> {
-public class BaremapsTableFactory implements TableFactory<BaremapsTable> {
+ public BaremapsTableFactory() {
- public BaremapsTableFactory() {
+ }
- }
+ @Override
+ public DataTableAdapter create(
+ SchemaPlus schema,
+ String name,
+ Map<String, Object> operand,
+ RelDataType rowType) {
+ final RelProtoDataType protoRowType =
+ rowType != null ? RelDataTypeImpl.proto(rowType) : null;
+ String format = (String) operand.get("format");
+ DataTable dataTable = switch (format) {
+ case "mmap" -> createMMapTable(schema, name, operand, rowType);
+ case "csv" -> createCsvTable(schema, name, operand, rowType);
+ default -> throw new RuntimeException("Unsupported format");
+ };
+ return new DataTableAdapter(dataTable, protoRowType);
+ }
- @Override
- public BaremapsTable create(
- SchemaPlus schema,
- String name,
- Map<String, Object> operand,
- RelDataType rowType) {
- final RelProtoDataType protoRowType =
- rowType != null ? RelDataTypeImpl.proto(rowType) : null;
- String format = (String) operand.get("format");
- DataTable dataTable = switch (format) {
- case "mmap" -> createMMapTable(schema, name, operand, rowType);
- case "csv" -> createCsvTable(schema, name, operand, rowType);
- default -> throw new RuntimeException("Unsupported format");
- };
- return new BaremapsTable(dataTable, protoRowType);
+ private DataTable createMMapTable(SchemaPlus schema, String name, Map<String, Object> operand,
+ RelDataType rowType) {
+ String directory = (String) operand.get("directory");
+ if (directory == null) {
+ throw new RuntimeException("A directory should be specified");
}
-
- private DataTable createMMapTable(SchemaPlus schema, String name, Map<String, Object> operand, RelDataType rowType) {
- String directory = (String) operand.get("directory");
- if (directory == null) {
- throw new RuntimeException("A directory should be specified");
- }
- try {
- Path directoryPath = Paths.get(directory);
- Path schemaFile = directoryPath.resolve("schema.json");
- DataSchema dataSchema = DataSchema.read(schemaFile);
- DataType<DataRow> dataType = new DataTypeImpl(dataSchema);
- Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(directoryPath);
- DataCollection<DataRow> dataCollection = new AppendOnlyLog<>(dataType, memory);
- return new DataTableImpl(dataSchema, dataCollection);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ try {
+ Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(Paths.get(directory));
+ ByteBuffer header = memory.header();
+ long size = header.getLong();
+ int length = header.getInt();
+ byte[] bytes = new byte[length];
+ header.get(bytes);
+ DataSchema dataSchema = DataSchema.read(new ByteArrayInputStream(bytes));
+ DataType<DataRow> dataType = new DataTypeImpl(dataSchema);
+ DataCollection<DataRow> dataCollection = new AppendOnlyLog<>(dataType, memory);
+ return new DataTableImpl(dataSchema, dataCollection);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
+ }
- private DataTable createCsvTable(SchemaPlus schema, String name, Map<String, Object> operand, RelDataType rowType) {
- String file = (String) operand.get("file");
- if (file == null) {
- throw new RuntimeException("A file should be specified");
- }
- try {
- return new CsvDataTable(name, new File(file), true, ',');
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ private DataTable createCsvTable(SchemaPlus schema, String name, Map<String, Object> operand,
+ RelDataType rowType) {
+ String file = (String) operand.get("file");
+ if (file == null) {
+ throw new RuntimeException("A file should be specified");
+ }
+ try {
+ return new CsvDataTable(name, new File(file), ',', true);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
+ }
}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
similarity index 95%
rename from baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
index 1d7caf7a4..9957a117b 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
@@ -33,7 +33,7 @@ import org.apache.calcite.schema.impl.AbstractTable;
import org.apache.calcite.sql.type.SqlTypeName;
import org.locationtech.jts.geom.*;
-public class BaremapsTable extends AbstractTable implements ScannableTable {
+public class DataTableAdapter extends AbstractTable implements ScannableTable {
private static final EnumMap<ColumnType, RelDataType> types = new EnumMap<>(ColumnType.class);
@@ -78,12 +78,12 @@ public class BaremapsTable extends AbstractTable implements ScannableTable {
private RelDataType rowType;
- public BaremapsTable(DataTable table) {
+ public DataTableAdapter(DataTable table) {
this.table = table;
this.protoRowType = null;
}
- public BaremapsTable(DataTable table, RelProtoDataType protoRowType) {
+ public DataTableAdapter(DataTable table, RelProtoDataType protoRowType) {
this.table = table;
this.protoRowType = protoRowType;
}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsTableFactoryTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsTableFactoryTest.java
deleted file mode 100644
index 1598163e7..000000000
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsTableFactoryTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package org.apache.baremaps.calcite;
-
-import org.apache.baremaps.data.collection.AppendOnlyLog;
-import org.apache.baremaps.data.memory.MemoryMappedDirectory;
-import org.apache.baremaps.data.store.DataTableImpl;
-import org.apache.baremaps.data.type.DataTypeImpl;
-import org.apache.baremaps.data.util.FileUtils;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
-import org.junit.jupiter.api.Test;
-import org.locationtech.jts.geom.Coordinate;
-import org.locationtech.jts.geom.GeometryFactory;
-
-import java.io.File;
-import java.io.PrintWriter;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.util.List;
-
-class BaremapsTableFactoryTest {
-
-
- @Test
- public void createCsvTable() throws Exception {
- File file = File.createTempFile("test", ".csv");
- String csv = """
- ID,NAME,GEOM
- 1,Paris,POINT(2.3522 48.8566)
- 2,New York,POINT(-74.0060 40.7128)
- """;
- try (PrintWriter writer = new PrintWriter(file)) {
- writer.write(csv);
- }
- String model = """
- {
- version: '1.0',
- defaultSchema: 'TEST',
- schemas: [
- {
- name: 'TEST',
- tables: [
- {
- name: 'TEST',
- factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
- operand: {
- format: 'csv',
- file: '%s'
- }
- }
- ]
- }
- ]
- }
- """.formatted(file.getAbsolutePath());
- try (Connection connection =
- DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
-
- ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
- while (resultSet.next()) {
- System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
- }
- } finally {
- file.delete();
- }
- }
-
- @Test
- public void createMMapTable() throws Exception {
- Path path = Files.createTempDirectory("temp");
-
- DataSchema dataSchema = new DataSchemaImpl("test", List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
- new DataColumnFixed("name", Cardinality.REQUIRED, ColumnType.STRING),
- new DataColumnFixed("geom", Cardinality.REQUIRED, ColumnType.GEOMETRY)
- ));
-
- DataTable dataTable = new DataTableImpl(dataSchema, new AppendOnlyLog<>(new DataTypeImpl(dataSchema), new MemoryMappedDirectory(path)));
- dataTable.add(new DataRowImpl(dataSchema, List.of(1, "a", new GeometryFactory().createPoint(new Coordinate(1, 1)))));
- dataTable.add(new DataRowImpl(dataSchema, List.of(2, "b", new GeometryFactory().createPoint(new Coordinate(2, 2)))));
- dataTable.close();
-
- String model = """
- {
- version: '1.0',
- defaultSchema: 'TEST',
- schemas: [
- {
- name: 'TEST',
- tables: [
- {
- name: 'TEST',
- factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
- operand: {
- format: 'mmap',
- directory: '%s'
- }
- }
- ]
- }
- ]
- }
- """.formatted(path.toAbsolutePath());
- try (Connection connection =
- DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
-
- ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
- while (resultSet.next()) {
- System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
- }
- } finally {
- FileUtils.deleteRecursively(path);
- }
- }
-}
\ No newline at end of file
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index b68d2261c..d96d5ca9b 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
@@ -19,7 +19,6 @@ package org.apache.baremaps.calcite;
import java.sql.*;
import java.util.*;
-
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
import org.apache.baremaps.data.store.DataTableImpl;
@@ -82,8 +81,8 @@ public class CalciteTest {
cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
- BaremapsTable cityBaremapsTable = new BaremapsTable(cityDataTable);
- rootSchema.add("city", cityBaremapsTable);
+ DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
+ rootSchema.add("city", cityDataTableAdapter);
// Create and add 'population' table
DataSchema populationRowType = new DataSchemaImpl("population", List.of(
@@ -97,8 +96,8 @@ public class CalciteTest {
populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(1, 2_161_000)));
populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(2, 8_336_000)));
- BaremapsTable populationBaremapsTable = new BaremapsTable(populationDataTable);
- rootSchema.add("population", populationBaremapsTable);
+ DataTableAdapter populationDataTableAdapter = new DataTableAdapter(populationDataTable);
+ rootSchema.add("population", populationDataTableAdapter);
// Create view 'city_population'
String mvSql = "SELECT c.id, c.name, c.geometry, p.population " +
@@ -210,8 +209,8 @@ public class CalciteTest {
cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
- BaremapsTable cityBaremapsTable = new BaremapsTable(cityDataTable);
- rootSchema.add("CITY", cityBaremapsTable);
+ DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
+ rootSchema.add("CITY", cityDataTableAdapter);
// Configure the framework
FrameworkConfig config = Frameworks.newConfigBuilder()
@@ -244,6 +243,4 @@ public class CalciteTest {
System.out.println("List A: " + listA);
System.out.println("List B (after SQL): " + listB);
}
-
-
}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java
new file mode 100644
index 000000000..69b33e354
--- /dev/null
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java
@@ -0,0 +1,154 @@
+/*
+ * 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 java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.PrintWriter;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.List;
+import org.apache.baremaps.data.collection.AppendOnlyLog;
+import org.apache.baremaps.data.memory.Memory;
+import org.apache.baremaps.data.memory.MemoryMappedDirectory;
+import org.apache.baremaps.data.store.DataTableImpl;
+import org.apache.baremaps.data.type.DataTypeImpl;
+import org.apache.baremaps.data.util.FileUtils;
+import org.apache.baremaps.store.*;
+import org.apache.baremaps.store.DataColumn.Cardinality;
+import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.junit.jupiter.api.Test;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.GeometryFactory;
+
+class DataTableAdapterFactoryTest {
+
+
+ @Test
+ public void createCsvTable() throws Exception {
+ File file = File.createTempFile("test", ".csv");
+ String csv = """
+ ID,NAME,GEOM
+ 1,Paris,POINT(2.3522 48.8566)
+ 2,New York,POINT(-74.0060 40.7128)
+ """;
+ try (PrintWriter writer = new PrintWriter(file)) {
+ writer.write(csv);
+ }
+ String model = """
+ {
+ version: '1.0',
+ defaultSchema: 'TEST',
+ schemas: [
+ {
+ name: 'TEST',
+ tables: [
+ {
+ name: 'TEST',
+ factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
+ operand: {
+ format: 'csv',
+ file: '%s'
+ }
+ }
+ ]
+ }
+ ]
+ }
+ """.formatted(file.getAbsolutePath());
+ try (Connection connection =
+ DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
+
+ ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
+ while (resultSet.next()) {
+ System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
+ }
+ } finally {
+ file.delete();
+ }
+ }
+
+ @Test
+ public void createMMapTable() throws Exception {
+ Path path = Files.createTempDirectory("temp");
+
+ DataSchema dataSchema = new DataSchemaImpl("test", List.of(
+ new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
+ new DataColumnFixed("name", Cardinality.REQUIRED, ColumnType.STRING),
+ new DataColumnFixed("geom", Cardinality.REQUIRED, ColumnType.GEOMETRY)));
+
+ // Serialize the schema
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ DataSchema.write(output, dataSchema);
+ byte[] bytes = output.toByteArray();
+
+ // Write the schema to the header of the memory mapped file
+ Memory<MappedByteBuffer> memory = new MemoryMappedDirectory(path);
+ ByteBuffer header = memory.header();
+ header.position(Long.BYTES);
+ header.putInt(bytes.length);
+ header.put(bytes);
+
+ DataTable dataTable =
+ new DataTableImpl(dataSchema, new AppendOnlyLog<>(new DataTypeImpl(dataSchema), memory));
+ dataTable.add(new DataRowImpl(dataSchema,
+ List.of(1, "a", new GeometryFactory().createPoint(new Coordinate(1, 1)))));
+ dataTable.add(new DataRowImpl(dataSchema,
+ List.of(2, "b", new GeometryFactory().createPoint(new Coordinate(2, 2)))));
+
+ dataTable.close();
+
+
+ String model = """
+ {
+ version: '1.0',
+ defaultSchema: 'TEST',
+ schemas: [
+ {
+ name: 'TEST',
+ tables: [
+ {
+ name: 'TEST',
+ factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
+ operand: {
+ format: 'mmap',
+ directory: '%s'
+ }
+ }
+ ]
+ }
+ ]
+ }
+ """.formatted(path.toAbsolutePath());
+ try (Connection connection =
+ DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
+
+ ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
+ while (resultSet.next()) {
+ System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
+ }
+ } finally {
+ FileUtils.deleteRecursively(path);
+ }
+ }
+}
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/utils/FileUtils.java b/baremaps-core/src/main/java/org/apache/baremaps/utils/FileUtils.java
deleted file mode 100644
index c98af3fb6..000000000
--- a/baremaps-core/src/main/java/org/apache/baremaps/utils/FileUtils.java
+++ /dev/null
@@ -1,36 +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.utils;
-
-
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Comparator;
-import java.util.stream.Stream;
-
-public class FileUtils {
-
- public static void deleteRecursively(Path path) throws IOException {
- try (Stream<Path> files = Files.walk(path)) {
- files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
- }
- }
-}
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java b/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
index f940edc3d..1785e8862 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
@@ -29,8 +29,8 @@ import javax.sql.DataSource;
import org.apache.baremaps.data.collection.*;
import org.apache.baremaps.data.memory.MemoryMappedDirectory;
import org.apache.baremaps.data.type.*;
+import org.apache.baremaps.data.util.FileUtils;
import org.apache.baremaps.postgres.utils.PostgresUtils;
-import org.apache.baremaps.utils.FileUtils;
import org.locationtech.jts.geom.Coordinate;
/**
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoPackageToPostgresTest.java b/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoPackageToPostgresTest.java
index 5ace46975..aea373c8a 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoPackageToPostgresTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoPackageToPostgresTest.java
@@ -42,8 +42,8 @@ class GeoPackageToPostgresTest extends PostgresContainerTest {
// Check the table in Postgres
var postgresTable = postgresStore.get("countries");
- assertEquals("countries", postgresTable.schema().name());
- assertEquals(4, postgresTable.schema().columns().size());
+ assertEquals("countries", postgresTable.schema().getName());
+ assertEquals(4, postgresTable.schema().getColumns().size());
assertEquals(179l, postgresTable.size());
assertEquals(179l, postgresTable.stream().count());
}
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoParquetToPostgresTest.java b/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoParquetToPostgresTest.java
index 3e4f1588d..1d847cb26 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoParquetToPostgresTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoParquetToPostgresTest.java
@@ -44,8 +44,8 @@ class GeoParquetToPostgresTest extends PostgresContainerTest {
// Check the table in Postgres
var postgresTable = postgresStore.get("geoparquet");
- assertEquals("geoparquet", postgresTable.schema().name());
- assertEquals(7, postgresTable.schema().columns().size());
+ assertEquals("geoparquet", postgresTable.schema().getName());
+ assertEquals(7, postgresTable.schema().getColumns().size());
assertEquals(5L, postgresTable.size());
assertEquals(5L, postgresTable.stream().count());
}
diff --git a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
index 9bfc41aa2..355b74f4e 100644
--- a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
+++ b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
@@ -49,7 +49,7 @@ public class CsvDataStore implements DataStore {
char separator) throws IOException {
this.tableName = tableName;
this.schema = schema;
- this.dataTable = new CsvDataTable(tableName, csvFile, header, separator);
+ this.dataTable = new CsvDataTable(tableName, csvFile, separator, header);
}
/**
diff --git a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
index 03283ec8a..6ed88cc9e 100644
--- a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
+++ b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
@@ -17,162 +17,229 @@
package org.apache.baremaps.csv;
-import com.fasterxml.jackson.core.FormatSchema;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
import org.apache.baremaps.store.DataColumn.ColumnType;
import org.locationtech.jts.io.WKTReader;
-import java.io.File;
-import java.io.IOException;
-import java.util.*;
-import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
-
-/**
- * A DataTable implementation that reads data from a CSV file using Jackson.
- */
public class CsvDataTable implements DataTable {
- private final File file;
- private final CsvSchema csvSchema;
- private final DataSchema dataSchema;
-
- private final long size;
- private MappingIterator<Map<String, String>> csvIterator;
-
- /**
- * Constructs a CsvDataTable with the specified schema, CSV file, header presence, and separator.
- *
- * @param name the name of the table
- * @param csvFile the CSV file to read data from
- * @param header whether the CSV file includes a header row
- * @param separator the separator used in the CSV file
- * @throws IOException if an I/O error occurs
- */
- public CsvDataTable(String name, File csvFile, boolean header, char separator) throws IOException {
- this.file = csvFile;
-
- // Iterate over all records to infer the csv schema and calculate the size of the table
- CsvSchema csvSchema = CsvSchema.emptySchema()
- .withUseHeader(header)
- .withColumnSeparator(separator);
-
- try (MappingIterator<Object> iterator = new CsvMapper()
- .readerFor(Object.class)
- .with(csvSchema)
- .readValues(csvFile)) {
-
- int count = 0;
- while (iterator.hasNext()) {
- iterator.next();
- count++;
- }
+ private final File file;
+ private final CsvSchema csvSchema;
+ private final DataSchema dataSchema;
+ private final long size;
+ private final boolean hasHeader;
- this.csvSchema = (CsvSchema) iterator.getParserSchema();
- this.size = count;
- } catch (IOException e) {
- throw new DataStoreException("Error reading CSV file", e);
- }
+ /**
+ * Constructor that infers the CSV file’s columns.
+ * <p>
+ * This constructor accepts a {@code hasHeader} parameter. If {@code hasHeader} is true, the
+ * file’s header is used to pick column names; if false, the first row is used to determine the
+ * number of columns, and generic names ("column1", "column2", etc.) are generated.
+ *
+ * @param name the name of the table
+ * @param csvFile the CSV file to read data from
+ * @param separator the separator used in the CSV file
+ * @param hasHeader whether the CSV file includes a header row
+ * @throws IOException if an I/O error occurs
+ */
+ public CsvDataTable(String name, File csvFile, char separator, boolean hasHeader)
+ throws IOException {
+ this(name, csvFile, separator, inferColumns(csvFile, separator, hasHeader), hasHeader);
+ }
- // Map the csv schema to a data schema
- List<DataColumn> columns = new ArrayList<>();
- for (String columnName : this.csvSchema.getColumnNames()) {
- switch (this.csvSchema.column(columnName).getType()) {
- case STRING -> columns
- .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.STRING));
- case NUMBER -> columns
- .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.DOUBLE));
- case BOOLEAN -> columns
- .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.BOOLEAN));
- case ARRAY -> columns
- .add(new DataColumnFixed(columnName, Cardinality.REPEATED, ColumnType.STRING));
- default -> throw new IllegalArgumentException(
- "Unsupported column type: " + csvSchema.column(columnName).getType());
- }
+ /**
+ * Constructor that uses the provided column definitions.
+ *
+ * @param name the name of the table
+ * @param csvFile the CSV file to read data from
+ * @param separator the separator used in the CSV file
+ * @param columns the list of columns (data types, names, etc.)
+ * @param hasHeader indicates whether the CSV file has a header row
+ * @throws IOException if an I/O error occurs
+ */
+ public CsvDataTable(String name, File csvFile, char separator, List<DataColumn> columns,
+ boolean hasHeader)
+ throws IOException {
+ this.file = csvFile;
+ this.hasHeader = hasHeader;
+ CsvMapper mapper = new CsvMapper();
+ CsvSchema schema = buildSchema(columns, separator, hasHeader);
+
+ int rowCount = 0;
+ try (MappingIterator<Map<String, String>> iterator = mapper
+ .readerFor(Map.class)
+ .with(schema)
+ .readValues(file)) {
+ while (iterator.hasNext()) {
+ iterator.next();
+ rowCount++;
+ }
+ // If a header is present, update the schema from the parser (if available).
+ if (hasHeader) {
+ CsvSchema inferred = (CsvSchema) iterator.getParserSchema();
+ if (inferred != null) {
+ schema = inferred;
}
- this.dataSchema = new DataSchemaImpl(name, columns);
+ }
+ } catch (IOException e) {
+ throw new DataStoreException("Error reading CSV file", e);
}
+ this.size = rowCount;
+ this.csvSchema = schema;
+ this.dataSchema = new DataSchemaImpl(name, columns);
+ }
- @Override
- public DataSchema schema() {
- return dataSchema;
+ /**
+ * Builds a CSV schema from the given column definitions.
+ *
+ * @param columns the list of columns
+ * @param separator the column separator
+ * @param hasHeader whether the CSV file has a header row
+ * @return the CSV schema
+ */
+ private static CsvSchema buildSchema(List<DataColumn> columns, char separator,
+ boolean hasHeader) {
+ if (hasHeader) {
+ return CsvSchema.emptySchema().withHeader().withColumnSeparator(separator);
+ } else {
+ CsvSchema.Builder builder = CsvSchema.builder();
+ for (DataColumn col : columns) {
+ builder.addColumn(col.name());
+ }
+ return builder.setColumnSeparator(separator).build();
}
+ }
- @Override
- public boolean add(DataRow row) {
- throw new UnsupportedOperationException("Adding rows is not supported.");
+ /**
+ * Infers columns from the CSV file.
+ * <p>
+ * If {@code hasHeader} is true, this method reads the header row to extract column names.
+ * Otherwise, it reads the first row to determine the number of columns and generates names.
+ *
+ * @param csvFile the CSV file
+ * @param separator the column separator
+ * @param hasHeader whether the CSV file includes a header row
+ * @return a list of columns (all of type STRING)
+ * @throws IOException if an I/O error occurs
+ */
+ private static List<DataColumn> inferColumns(File csvFile, char separator, boolean hasHeader)
+ throws IOException {
+ CsvMapper mapper = new CsvMapper();
+ List<DataColumn> columns = new ArrayList<>();
+ if (hasHeader) {
+ // Read the header to infer column names.
+ CsvSchema baseSchema = CsvSchema.emptySchema().withHeader().withColumnSeparator(separator);
+ try (MappingIterator<Map<String, String>> iterator = mapper.readerFor(Map.class)
+ .with(baseSchema)
+ .readValues(csvFile)) {
+ // Consume one record so that the header is processed.
+ if (iterator.hasNext()) {
+ iterator.next();
+ }
+ CsvSchema inferred = (CsvSchema) iterator.getParserSchema();
+ if (inferred == null) {
+ throw new DataStoreException("Failed to infer CSV schema from header.");
+ }
+ for (String colName : inferred.getColumnNames()) {
+ columns.add(new DataColumnFixed(colName, Cardinality.OPTIONAL, ColumnType.STRING));
+ }
+ }
+ } else {
+ // No header: read the first row to determine the number of columns.
+ CsvSchema baseSchema = CsvSchema.emptySchema().withColumnSeparator(separator);
+ try (MappingIterator<List<String>> iterator = mapper.readerFor(List.class)
+ .with(baseSchema)
+ .readValues(csvFile)) {
+ if (iterator.hasNext()) {
+ List<String> firstRow = iterator.next();
+ int numColumns = firstRow.size();
+ for (int i = 0; i < numColumns; i++) {
+ columns.add(
+ new DataColumnFixed("column" + (i + 1), Cardinality.OPTIONAL, ColumnType.STRING));
+ }
+ } else {
+ throw new DataStoreException("CSV file is empty; cannot infer column names.");
+ }
+ }
}
+ return columns;
+ }
- @Override
- public void clear() {
- throw new UnsupportedOperationException("Clearing rows is not supported.");
- }
+ @Override
+ public DataSchema schema() {
+ return dataSchema;
+ }
- @Override
- public long size() {
- return size;
- }
+ @Override
+ public boolean add(DataRow row) {
+ throw new UnsupportedOperationException("Adding rows is not supported.");
+ }
- @Override
- public Iterator<DataRow> iterator() {
- try {
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException("Clearing rows is not supported.");
+ }
- csvIterator = new CsvMapper()
- .readerFor(Map.class)
- .with(csvSchema)
- .readValues(file);
+ @Override
+ public long size() {
+ return size;
+ }
- return new Iterator<>() {
- @Override
- public boolean hasNext() {
- return csvIterator.hasNext();
- }
+ @Override
+ public java.util.Iterator<DataRow> iterator() {
+ try {
+ CsvMapper mapper = new CsvMapper();
+ MappingIterator<Map<String, String>> localIterator = mapper.readerFor(Map.class)
+ .with(csvSchema)
+ .readValues(file);
- @Override
- public DataRow next() {
- Map<String, String> csvRow = csvIterator.next();
- DataRow dataRow = dataSchema.createRow();
-
- for (int i = 0; i < dataSchema.columns().size(); i++) {
- DataColumn column = dataSchema.columns().get(i);
- String columnName = column.name();
- String value = csvRow.get(columnName);
-
- if (value != null) {
- Object parsedValue = parseValue(column, value);
- dataRow.set(i, parsedValue);
- } else {
- dataRow.set(i, null);
- }
- }
- return dataRow;
- }
- };
+ return new java.util.Iterator<>() {
+ @Override
+ public boolean hasNext() {
+ boolean has = localIterator.hasNext();
+ if (!has) {
+ try {
+ localIterator.close();
+ } catch (IOException e) {
+ throw new DataStoreException("Error closing CSV iterator", e);
+ }
+ }
+ return has;
+ }
- } catch (IOException e) {
- throw new DataStoreException("Error reading CSV file", e);
+ @Override
+ public DataRow next() {
+ if (!hasNext()) {
+ throw new java.util.NoSuchElementException();
+ }
+ Map<String, String> csvRow = localIterator.next();
+ DataRow dataRow = dataSchema.createRow();
+ for (int i = 0; i < dataSchema.columns().size(); i++) {
+ DataColumn column = dataSchema.columns().get(i);
+ String value = csvRow.get(column.name());
+ dataRow.set(i, (value == null || value.isEmpty()) ? null : parseValue(column, value));
+ }
+ return dataRow;
}
+ };
+
+ } catch (IOException e) {
+ throw new DataStoreException("Error reading CSV file", e);
}
+ }
- /**
- * Parses the string value from the CSV according to the column type.
- *
- * @param column the data column
- * @param value the string value from the CSV
- * @return the parsed value
- */
- private Object parseValue(DataColumn column, String value) {
+ private static Object parseValue(DataColumn column, String value) {
ColumnType type = column.type();
try {
- if (value == null || value.isEmpty()) {
- return null;
- }
return switch (type) {
case STRING -> value;
case INTEGER -> Integer.parseInt(value);
@@ -180,8 +247,7 @@ public class CsvDataTable implements DataTable {
case FLOAT -> Float.parseFloat(value);
case DOUBLE -> Double.parseDouble(value);
case BOOLEAN -> Boolean.parseBoolean(value);
- case GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON,
- GEOMETRYCOLLECTION -> {
+ case GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION -> {
WKTReader reader = new WKTReader();
yield reader.read(value);
}
@@ -192,20 +258,18 @@ public class CsvDataTable implements DataTable {
}
}
- @Override
- public Spliterator<DataRow> spliterator() {
- return Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED);
- }
+ @Override
+ public java.util.Spliterator<DataRow> spliterator() {
+ return java.util.Spliterators.spliteratorUnknownSize(iterator(), java.util.Spliterator.ORDERED);
+ }
- @Override
- public Stream<DataRow> stream() {
- return StreamSupport.stream(spliterator(), false);
- }
+ @Override
+ public java.util.stream.Stream<DataRow> stream() {
+ return java.util.stream.StreamSupport.stream(spliterator(), false);
+ }
- @Override
- public void close() throws IOException {
- if (csvIterator != null) {
- csvIterator.close();
- }
- }
+ @Override
+ public void close() throws IOException {
+ // No persistent resources to close.
+ }
}
diff --git a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
index 71776b724..d46dd7728 100644
--- a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
+++ b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
@@ -29,7 +29,7 @@ class CsvDataTableGeonamesTest {
@Test
void testGeonamesCsvDataTable() throws IOException {
- DataTable dataTable = new CsvDataTable("sample", GEONAMES_CSV.toFile(), false, '\t');
+ DataTable dataTable = new CsvDataTable("sample", GEONAMES_CSV.toFile(), '\t', false);
assertEquals(5, dataTable.size(), "DataTable should have 5 rows.");
diff --git a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
index bb67934df..970decb5e 100644
--- a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
+++ b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
@@ -58,7 +58,12 @@ class CsvDataTableTest {
2,PointB,"POINT(2 2)"
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
+ // Provide an explicit schema so that the id and geom fields are parsed correctly.
+ List<DataColumn> columns = List.of(
+ new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING),
+ new DataColumnFixed("geom", Cardinality.OPTIONAL, ColumnType.GEOMETRY));
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', columns, true);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -86,7 +91,7 @@ class CsvDataTableTest {
new DataColumnFixed("column1", Cardinality.REQUIRED, ColumnType.INTEGER),
new DataColumnFixed("column2", Cardinality.OPTIONAL, ColumnType.STRING),
new DataColumnFixed("column3", Cardinality.OPTIONAL, ColumnType.GEOMETRY));
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, false, ';');
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ';', columns, false);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -119,7 +124,7 @@ class CsvDataTableTest {
new DataColumnFixed("double_col", Cardinality.REQUIRED, ColumnType.DOUBLE),
new DataColumnFixed("bool_col", Cardinality.REQUIRED, ColumnType.BOOLEAN),
new DataColumnFixed("string_col", Cardinality.REQUIRED, ColumnType.STRING));
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', columns, true);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -148,10 +153,11 @@ class CsvDataTableTest {
List<DataColumn> columns = List.of(
new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING));
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
+ // Pass the explicit columns so that "id" is attempted to be parsed as an integer.
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', columns, true);
assertThrows(RuntimeException.class, () -> {
for (DataRow row : dataTable) {
- // This line should throw an exception because abc is not a valid integer
+ // This line should throw an exception because "abc" is not a valid integer.
row.values();
}
});
@@ -159,9 +165,10 @@ class CsvDataTableTest {
@Test
void testAddAndClearUnsupportedOperations() throws IOException {
- String csvContent = "";
+ // When using header=true the CSV file must contain at least a header row.
+ String csvContent = "col1\n";
Files.writeString(tempCsvFile.toPath(), csvContent);
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', true);
assertThrows(UnsupportedOperationException.class, () -> dataTable.add(null));
assertThrows(UnsupportedOperationException.class, dataTable::clear);
}
@@ -175,7 +182,8 @@ class CsvDataTableTest {
3,Name3
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, true, ',');
+ // In this test we rely on the inferred (STRING) schema.
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', true);
assertEquals(3, dataTable.size());
}
}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
index a45f2eaea..5f12ad26c 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedDirectory.java
@@ -45,10 +45,10 @@ public class MemoryMappedDirectory extends Memory<MappedByteBuffer> {
* Constructs a MemoryMappedDirectory with the specified directory and segment size.
*
* @param directory the directory to store segments in
- * @param segmentBytes the size of each segment in bytes
+ * @param segmentSize the size of each segment in bytes
*/
- public MemoryMappedDirectory(Path directory, int segmentBytes) {
- super(1024, segmentBytes);
+ public MemoryMappedDirectory(Path directory, int segmentSize) {
+ super(1 << 14, segmentSize);
this.directory = directory;
}
@@ -57,8 +57,8 @@ public class MemoryMappedDirectory extends Memory<MappedByteBuffer> {
try {
Path file = directory.resolve("header");
try (FileChannel channel = FileChannel.open(file, StandardOpenOption.CREATE,
- StandardOpenOption.READ, StandardOpenOption.WRITE)) {
- return channel.map(MapMode.READ_WRITE, 0, 1024);
+ StandardOpenOption.READ, StandardOpenOption.WRITE)) {
+ return channel.map(MapMode.READ_WRITE, 0, headerSize());
}
} catch (IOException e) {
throw new MemoryException(e);
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedFile.java b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedFile.java
index daafaeff8..90ef3b327 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedFile.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/memory/MemoryMappedFile.java
@@ -55,7 +55,7 @@ public class MemoryMappedFile extends Memory<MappedByteBuffer> {
protected MappedByteBuffer allocateHeader() {
try {
try (FileChannel channel = FileChannel.open(file, StandardOpenOption.CREATE,
- StandardOpenOption.READ, StandardOpenOption.WRITE)) {
+ StandardOpenOption.READ, StandardOpenOption.WRITE)) {
return channel.map(MapMode.READ_WRITE, 0, headerSize());
}
} catch (IOException e) {
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java b/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java
index c866b1b41..a8a56b6dd 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java
@@ -29,7 +29,8 @@ public class DataStoreImpl implements DataStore {
public DataStoreImpl(List<DataTable> tables) {
this.tables =
- tables.stream().collect(Collectors.toMap(table -> table.schema().name(), table -> table));
+ tables.stream()
+ .collect(Collectors.toMap(table -> table.schema().name(), table -> table));
}
@Override
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/util/FileUtils.java b/baremaps-data/src/main/java/org/apache/baremaps/data/util/FileUtils.java
index 8fc7469fe..35f0d68c1 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/util/FileUtils.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/util/FileUtils.java
@@ -21,6 +21,7 @@ package org.apache.baremaps.data.util;
import java.io.File;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
@@ -32,6 +33,10 @@ public class FileUtils {
// Prevent instantiation
}
+ public static ByteBuffer read(Path path) throws IOException {
+ return ByteBuffer.wrap(Files.readAllBytes(path));
+ }
+
public static void deleteRecursively(Path path) throws IOException {
try (Stream<Path> files = Files.walk(path)) {
files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
diff --git a/baremaps-geopackage/src/test/java/org/apache/baremaps/geopackage/GeoPackageDataStoreTest.java b/baremaps-geopackage/src/test/java/org/apache/baremaps/geopackage/GeoPackageDataStoreTest.java
index db27ebd1c..8b9ef47ac 100644
--- a/baremaps-geopackage/src/test/java/org/apache/baremaps/geopackage/GeoPackageDataStoreTest.java
+++ b/baremaps-geopackage/src/test/java/org/apache/baremaps/geopackage/GeoPackageDataStoreTest.java
@@ -30,8 +30,8 @@ class GeoPackageDataStoreTest {
var geoPackageStore = new GeoPackageDataStore(file);
var table = geoPackageStore.get("countries");
var rowType = table.schema();
- assertEquals("countries", rowType.name());
- assertEquals(4, rowType.columns().size());
+ assertEquals("countries", rowType.getName());
+ assertEquals(4, rowType.getColumns().size());
}
@Test
diff --git a/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTableTest.java b/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTableTest.java
index cee8ade94..35deb29db 100644
--- a/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTableTest.java
+++ b/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTableTest.java
@@ -33,8 +33,8 @@ class OpenStreetMapDataTableTest {
try (var inputStream = Files.newInputStream(uri)) {
var table = new OpenStreetMapDataTable(new PbfEntityReader(), inputStream);
var rowType = table.schema();
- assertEquals(rowType.name(), "osm_data");
- assertEquals(9, rowType.columns().size());
+ assertEquals(rowType.getName(), "osm_data");
+ assertEquals(9, rowType.getColumns().size());
}
}
diff --git a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataTableTest.java b/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataTableTest.java
index defc7348f..716c57c9b 100644
--- a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataTableTest.java
+++ b/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataTableTest.java
@@ -61,8 +61,8 @@ class PostgresDataTableTest extends PostgresContainerTest {
var table = schema.get("mock");
var rowType = table.schema();
assertNotNull(rowType);
- assertEquals("mock", rowType.name());
- assertEquals(5, rowType.columns().size());
+ assertEquals("mock", rowType.getName());
+ assertEquals(5, rowType.getColumns().size());
}
@Test
diff --git a/baremaps-rpsl/src/test/java/org/apache/baremaps/rpsl/RsplDataTableTest.java b/baremaps-rpsl/src/test/java/org/apache/baremaps/rpsl/RsplDataTableTest.java
index 597114935..2e800a087 100644
--- a/baremaps-rpsl/src/test/java/org/apache/baremaps/rpsl/RsplDataTableTest.java
+++ b/baremaps-rpsl/src/test/java/org/apache/baremaps/rpsl/RsplDataTableTest.java
@@ -42,8 +42,8 @@ class RpslDataTableTest {
@Test
void schema() {
DataSchema schema = dataTable.schema();
- assertEquals("RpslObject", schema.name());
- List<DataColumn> columns = schema.columns();
+ assertEquals("RpslObject", schema.getName());
+ List<DataColumn> columns = schema.getColumns();
assertTrue(columns.stream().anyMatch(c -> c.name().equals("type")));
assertTrue(columns.stream().anyMatch(c -> c.name().equals("id")));
assertTrue(columns.stream().anyMatch(c -> c.name().equals("inetnum")));
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
index a2dcfecd8..eceed6c38 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
@@ -26,10 +26,8 @@ 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.Serializable;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Path;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.baremaps.store.DataColumn.Cardinality;
@@ -102,19 +100,14 @@ public interface DataSchema {
return mapper;
}
- static DataSchema read(ByteBuffer buffer) throws IOException {
+ static DataSchema read(InputStream inputStream) throws IOException {
var mapper = configureObjectMapper();
- int length = buffer.getInt();
- byte[] bytes = new byte[length];
- buffer.get(bytes);
- return mapper.readValue(bytes, DataSchema.class);
+ return mapper.readValue(inputStream, DataSchema.class);
}
- static void write(ByteBuffer buffer, DataSchema schema) throws IOException {
+ static void write(OutputStream outputStream, DataSchema schema) throws IOException {
var mapper = configureObjectMapper();
- var bytes = mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(schema);
- buffer.putInt(bytes.length);
- buffer.put(bytes);
+ mapper.writeValue(outputStream, schema);
}
}
(incubator-baremaps) 02/12: Add list
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit 3981793f7fdf8c61c0d7b18a8a089fc19e82e2ac
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Tue Jan 14 21:08:02 2025 +0100
Add list
---
.../apache/baremaps/data/calcite/CalciteTest.java | 157 +++++++++++++++++----
1 file changed, 130 insertions(+), 27 deletions(-)
diff --git a/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java b/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
index 52768a70d..9e7fc96d6 100644
--- a/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
+++ b/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
@@ -24,28 +24,56 @@ import org.apache.baremaps.data.type.RowDataType;
import org.apache.baremaps.store.DataColumn.Cardinality;
import org.apache.baremaps.store.DataColumn.Type;
import org.apache.baremaps.store.*;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.DataContexts;
+import org.apache.calcite.adapter.enumerable.EnumerableConvention;
+import org.apache.calcite.adapter.enumerable.EnumerableInterpreter;
import org.apache.calcite.config.Lex;
+import org.apache.calcite.interpreter.Interpreter;
import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Linq4j;
import org.apache.calcite.model.ModelHandler;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.plan.volcano.VolcanoPlanner;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.runtime.SpatialTypeFunctions;
+import org.apache.calcite.schema.ScannableTable;
import org.apache.calcite.schema.SchemaPlus;
-import org.apache.calcite.schema.impl.ViewTable;
-import org.apache.calcite.schema.impl.ViewTableMacro;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.impl.*;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.fun.SqlSpatialTypeFunctions;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl;
+import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.calcite.tools.Planner;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
+import org.apache.calcite.adapter.enumerable.EnumerableRel;
+import org.apache.calcite.adapter.enumerable.EnumerableInterpreter;
+import org.apache.calcite.adapter.enumerable.EnumerableRelImplementor;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.plan.*;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.tools.*;
import java.sql.*;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
+import java.util.*;
public class CalciteTest {
@@ -102,13 +130,14 @@ public class CalciteTest {
"FROM city c " + // lowercase and unquoted
"JOIN population p ON c.id = p.city_id";
- ViewTableMacro materializedView = ViewTable.viewMacro(
+ ViewTableMacro materializedView = MaterializedViewTable.viewMacro(
rootSchema,
mvSql,
Collections.emptyList(), // Schema path
List.of("city_population"), // Name parts
false); // Not a materialized view
+
rootSchema.add("city_population", materializedView);
// Debug: List all tables in the root schema
@@ -121,7 +150,7 @@ public class CalciteTest {
try (Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql)) {
while (resultSet.next()) {
- System.out.println(resultSet.getString("id") + " " + resultSet.getString("name"));
+ System.out.println(resultSet.getString("id") + " " + resultSet.getString("geometry"));
}
}
@@ -139,32 +168,106 @@ public class CalciteTest {
}
+ public class ListTable extends AbstractTable implements ScannableTable {
+ private final List<Integer> data;
+
+ public ListTable(List<Integer> data) {
+ this.data = data;
+ }
+
+ @Override
+ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ // Define a single column named "value" of type INTEGER
+ return typeFactory.builder()
+ .add("V", SqlTypeName.INTEGER)
+ .build();
+ }
+
+ @Override
+ public Enumerable<Object[]> scan(DataContext root) {
+ // Convert the List<Integer> to Enumerable<Object[]>
+ return Linq4j.asEnumerable(data)
+ .select(i -> new Object[]{i});
+ }
+ }
+
+ public class ListSchema extends AbstractSchema {
+ private final List<Integer> listA;
+ private final List<Integer> listB;
+
+ public ListSchema(List<Integer> listA, List<Integer> listB) {
+ this.listA = listA;
+ this.listB = listB;
+ }
+
+ @Override
+ protected Map<String, Table> getTableMap() {
+ Map<String, Table> tables = new HashMap<>();
+ tables.put("LIST_A", new ListTable(listA));
+ tables.put("LIST_B", new ListTable(listB)); // Initially empty
+ return tables;
+ }
+ }
+
@Test
- void ddl() throws SqlParseException {
-
- // Example SQL script with multiple DDL statements
- String sqlScript = """
- CREATE MATERIALIZED VIEW IF NOT EXISTS my_view AS
- SELECT * FROM my_table;
- """;
-
- // Build a parser config that supports DDL
- SqlParser.Config config = SqlParser.configBuilder()
- .setParserFactory(SqlDdlParserImpl.FACTORY)
- .setConformance(SqlConformanceEnum.BABEL)
- .setLex(Lex.MYSQL)
+ void list() throws Exception {
+ // Initialize your Java lists
+ List<Integer> listA = List.of(1, 2, 3, 4, 5);
+ List<Integer> listB = new ArrayList<>();
+
+ // Set up Calcite schema
+ SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+ rootSchema.add("MY_SCHEMA", new ListSchema(listA, listB));
+
+ // Create and add 'city' table
+ DataSchema cityRowType = new DataSchemaImpl("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+
+ DataTable cityDataTable = new BaremapsDataTable(
+ cityRowType,
+ new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType))));
+
+ GeometryFactory geometryFactory = new GeometryFactory();
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
+ cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
+
+ SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
+ rootSchema.add("CITY", citySqlDataTable);
+
+ // Configure the framework
+ FrameworkConfig config = Frameworks.newConfigBuilder()
+ .defaultSchema(rootSchema.getSubSchema("MY_SCHEMA"))
.build();
- // Create the parser from the config
- SqlParser parser = SqlParser.create(sqlScript, config);
+ // Create a planner
+ Planner planner = Frameworks.getPlanner(config);
+
+ // Define the SQL query to populate list_b from list_a
+ String sql = "SELECT V * 2 AS V FROM LIST_A";
+
+ // Parse the SQL query
+ org.apache.calcite.sql.SqlNode parsed = planner.parse(sql);
- // Parse the script as a list of statements
- SqlNodeList sqlNodeList = parser.parseStmtList();
+ // Validate the SQL query
+ org.apache.calcite.sql.SqlNode validated = planner.validate(parsed);
- // Iterate and print each parsed statement
- for (SqlNode sqlNode : sqlNodeList) {
- System.out.println("Parsed statement: " + sqlNode.toString());
+ // Convert the SQL query to a relational expression
+ RelNode rel = planner.rel(validated).rel;
+
+ Interpreter interpreter = new Interpreter(DataContexts.EMPTY, rel);
+
+ // Create an interpreter to execute the RelNode
+ for (Object[] row : interpreter.asEnumerable()) {
+ listB.add((Integer) row[0]);
}
+
+ // Display the results
+ System.out.println("List A: " + listA);
+ System.out.println("List B (after SQL): " + listB);
}
}
(incubator-baremaps) 09/12: Merge the calcite and store packages
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit 3e3272306811f0582c6e8be9aeb1731fd518e2d6
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Mon Feb 3 22:12:06 2025 +0100
Merge the calcite and store packages
---
baremaps-calcite/pom.xml | 40 +++-
.../org/apache/baremaps/calcite}/DataColumn.java | 12 +-
.../apache/baremaps/calcite}/DataColumnFixed.java | 4 +-
.../apache/baremaps/calcite}/DataColumnNested.java | 6 +-
.../java/org/apache/baremaps/calcite/DataRow.java | 35 +++-
.../org/apache/baremaps/calcite/DataRowType.java | 51 +++---
.../org/apache/baremaps/calcite}/DataSchema.java | 48 ++---
.../org/apache/baremaps/calcite}/DataStore.java | 2 +-
.../baremaps/calcite}/DataStoreException.java | 2 +-
.../org/apache/baremaps/calcite}/DataTable.java | 2 +-
.../apache/baremaps/calcite/DataTableAdapter.java | 38 ++--
...mapsTableFactory.java => DataTableFactory.java} | 18 +-
.../baremaps/calcite}/DataTableGeometryMapper.java | 2 +-
.../apache/baremaps/calcite}/DataTableMapper.java | 2 +-
.../calcite/baremaps/BaremapsDataStore.java | 10 +-
.../calcite/baremaps/BaremapsDataTable.java | 18 +-
.../apache/baremaps/calcite}/csv/CsvDataStore.java | 10 +-
.../apache/baremaps/calcite}/csv/CsvDataTable.java | 24 +--
.../calcite}/flatgeobuf/FlatGeoBufDataStore.java | 8 +-
.../calcite}/flatgeobuf/FlatGeoBufDataTable.java | 12 +-
.../flatgeobuf/FlatGeoBufTypeConversion.java | 33 ++--
.../calcite}/geopackage/GeoPackageDataStore.java | 8 +-
.../calcite}/geopackage/GeoPackageDataTable.java | 16 +-
.../calcite}/geoparquet/GeoParquetDataStore.java | 8 +-
.../calcite}/geoparquet/GeoParquetDataTable.java | 13 +-
.../geoparquet/GeoParquetTypeConversion.java | 30 +--
.../openstreetmap/OpenStreetMapDataTable.java | 26 +--
.../calcite/postgres}/PostgresDataStore.java | 12 +-
.../calcite/postgres}/PostgresDataTable.java | 9 +-
.../calcite/postgres/PostgresTypeConversion.java | 72 ++++++++
.../calcite}/rpsl/RpslDataRowIterator.java | 10 +-
.../baremaps/calcite}/rpsl/RpslDataTable.java | 38 ++--
.../calcite}/shapefile/ShapefileDataStore.java | 8 +-
.../calcite}/shapefile/ShapefileDataTable.java | 66 +++++--
.../org/apache/baremaps/calcite/CalciteTest.java | 54 +++---
.../calcite/DataTableAdapterFactoryTest.java | 30 ++-
.../apache/baremaps/calcite/DataTypeProvider.java | 89 +++++++++
.../org/apache/baremaps/calcite/DataTypeTest.java | 61 ++++++
.../apache/baremaps/calcite}/MockDataTable.java | 42 +++--
.../calcite}/csv/CsvDataTableGeonamesTest.java | 35 +++-
.../baremaps/calcite}/csv/CsvDataTableTest.java | 43 +++--
.../flatgeobuf/FlatGeoBufDataTableTest.java | 2 +-
.../geopackage/GeoPackageDataStoreTest.java | 6 +-
.../geoparquet/GeoParquetDataStoreTest.java | 3 +-
.../openstreetmap/OpenStreetMapDataTableTest.java | 8 +-
.../calcite/postgres}/PostgresDataStoreTest.java | 6 +-
.../calcite/postgres}/PostgresDataTableTest.java | 26 +--
.../baremaps/calcite}/rpsl/RsplDataTableTest.java | 11 +-
baremaps-cli/src/license/override.properties | 3 -
baremaps-core/pom.xml | 6 +-
.../apache/baremaps/geocoder/DataRowConsumer.java | 2 +-
.../apache/baremaps/geocoder/DataRowMapper.java | 10 +-
.../baremaps/geocoder/DataTableQueryBuilder.java | 4 +-
.../apache/baremaps/tasks/ImportGeoPackage.java | 8 +-
.../apache/baremaps/tasks/ImportGeoParquet.java | 10 +-
.../org/apache/baremaps/tasks/ImportShapefile.java | 8 +-
.../org/apache/baremaps/calcite/CalciteTest.java | 204 ++++++++++-----------
.../baremaps/geocoder/DataTableIndexTest.java | 4 +-
.../geocoder/geonames/GeonamesIndexTest.java | 2 +-
.../openstreetmap/OpenStreetMapIndexTest.java | 2 +-
.../integration/GeoPackageToPostgresTest.java | 8 +-
.../integration/GeoParquetToPostgresTest.java | 8 +-
.../org/apache/baremaps/iploc/IpLocObjectTest.java | 2 +-
.../org/apache/baremaps/tasks/DownloadUrlTest.java | 2 +-
.../baremaps/tilestore/file/FileTileStoreTest.java | 2 +-
.../tilestore/mbtiles/MBTilesStoreTest.java | 2 +-
baremaps-data/pom.xml | 4 -
.../apache/baremaps/data/AppendOnlyLogTest.java | 4 +-
.../baremaps/data/type/DataTypeProvider.java | 63 +------
baremaps-flatgeobuf/pom.xml | 4 -
baremaps-geoparquet/pom.xml | 4 -
baremaps-openstreetmap/pom.xml | 4 -
baremaps-postgres/pom.xml | 4 -
.../postgres/store/PostgresTypeConversion.java | 72 --------
baremaps-rpsl/pom.xml | 4 -
baremaps-shapefile/pom.xml | 8 +-
.../apache/baremaps/shapefile/DbaseByteReader.java | 5 +-
.../baremaps/shapefile/ShapefileByteReader.java | 101 +++++-----
.../baremaps/shapefile/ShapefileInputStream.java | 16 +-
.../apache/baremaps/shapefile/ShapefileReader.java | 14 --
.../java/org/apache/baremaps/store/DataRow.java | 96 ----------
.../org/apache/baremaps/store/DataSchemaImpl.java | 41 -----
pom.xml | 19 +-
83 files changed, 927 insertions(+), 932 deletions(-)
diff --git a/baremaps-calcite/pom.xml b/baremaps-calcite/pom.xml
index 3653d0f69..5ea71ec49 100644
--- a/baremaps-calcite/pom.xml
+++ b/baremaps-calcite/pom.xml
@@ -17,13 +17,49 @@
<dependencies>
<dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-csv</artifactId>
+ <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>
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumn.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumn.java
similarity index 92%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataColumn.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumn.java
index 609674eb1..91d60fbde 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumn.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumn.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.store;
+package org.apache.baremaps.calcite;
import java.io.Serializable;
import java.net.Inet4Address;
@@ -52,12 +52,12 @@ public interface DataColumn extends Serializable {
*
* @return the type of the column
*/
- ColumnType type();
+ Type type();
/**
* An enumeration of the supported data column types.
*/
- enum ColumnType {
+ enum Type {
BINARY(byte[].class),
BYTE(Byte.class),
BOOLEAN(Boolean.class),
@@ -87,7 +87,7 @@ public interface DataColumn extends Serializable {
private final Class<?> binding;
- ColumnType(Class<?> binding) {
+ Type(Class<?> binding) {
this.binding = binding;
}
@@ -95,8 +95,8 @@ public interface DataColumn extends Serializable {
return binding;
}
- public static ColumnType fromBinding(Class<?> binding) {
- for (ColumnType type : ColumnType.values()) {
+ public static Type fromBinding(Class<?> binding) {
+ for (Type type : Type.values()) {
if (type.binding().equals(binding)) {
return type;
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnFixed.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumnFixed.java
similarity index 91%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnFixed.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumnFixed.java
index 2f8990e9c..2b77deb55 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnFixed.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumnFixed.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.store;
+package org.apache.baremaps.calcite;
/**
@@ -24,6 +24,6 @@ package org.apache.baremaps.store;
public record DataColumnFixed(
String name,
Cardinality cardinality,
- ColumnType type) implements DataColumn {
+ Type type) implements DataColumn {
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnNested.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumnNested.java
similarity index 91%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnNested.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumnNested.java
index bcf3458c1..6708bca71 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnNested.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataColumnNested.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.store;
+package org.apache.baremaps.calcite;
import java.util.List;
@@ -25,7 +25,7 @@ public record DataColumnNested(
List<DataColumn> columns) implements DataColumn {
@Override
- public ColumnType type() {
- return ColumnType.NESTED;
+ public Type type() {
+ return Type.NESTED;
}
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataRowImpl.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataRow.java
similarity index 72%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataRowImpl.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataRow.java
index a57418c08..0487fdfd9 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataRowImpl.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataRow.java
@@ -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++) {
@@ -42,7 +40,6 @@ public record DataRowImpl(DataSchema schema, List<Object> values) implements Dat
/**
* {@inheritDoc}
*/
- @Override
public Object get(int index) {
return values.get(index);
}
@@ -50,7 +47,6 @@ public record DataRowImpl(DataSchema schema, List<Object> values) implements Dat
/**
* {@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)) {
@@ -64,8 +60,31 @@ public record DataRowImpl(DataSchema schema, List<Object> values) implements Dat
/**
* {@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;
+ }
}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/type/DataTypeImpl.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataRowType.java
similarity index 63%
rename from baremaps-data/src/main/java/org/apache/baremaps/data/type/DataTypeImpl.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataRowType.java
index 68490f496..d9b023d1f 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/type/DataTypeImpl.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataRowType.java
@@ -15,50 +15,47 @@
* 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.ColumnType;
-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 DataTypeImpl implements DataType<DataRow> {
+public class DataRowType implements DataType<DataRow> {
/**
* Map of data types for each of the supported column types.
*/
- private static final EnumMap<ColumnType, DataType> types = new EnumMap<>(ColumnType.class);
+ private static final EnumMap<Type, DataType> types = new EnumMap<>(Type.class);
static {
- types.put(ColumnType.BYTE, new ByteDataType());
- types.put(ColumnType.BOOLEAN, new BooleanDataType());
- types.put(ColumnType.SHORT, new ShortDataType());
- types.put(ColumnType.INTEGER, new IntegerDataType());
- types.put(ColumnType.LONG, new LongDataType());
- types.put(ColumnType.FLOAT, new FloatDataType());
- types.put(ColumnType.DOUBLE, new DoubleDataType());
- types.put(ColumnType.STRING, new StringDataType());
- types.put(ColumnType.GEOMETRY, new GeometryDataType());
- types.put(ColumnType.POINT, new PointDataType());
- types.put(ColumnType.LINESTRING, new LineStringDataType());
- types.put(ColumnType.POLYGON, new PolygonDataType());
- types.put(ColumnType.MULTIPOINT, new MultiPointDataType());
- types.put(ColumnType.MULTILINESTRING, new MultiLineStringDataType());
- types.put(ColumnType.MULTIPOLYGON, new MultiPolygonDataType());
- types.put(ColumnType.GEOMETRYCOLLECTION, new GeometryCollectionDataType());
- types.put(ColumnType.COORDINATE, new CoordinateDataType());
+ types.put(Type.BYTE, new ByteDataType());
+ types.put(Type.BOOLEAN, new BooleanDataType());
+ types.put(Type.SHORT, new ShortDataType());
+ types.put(Type.INTEGER, new IntegerDataType());
+ types.put(Type.LONG, new LongDataType());
+ types.put(Type.FLOAT, new FloatDataType());
+ types.put(Type.DOUBLE, new DoubleDataType());
+ types.put(Type.STRING, new StringDataType());
+ types.put(Type.GEOMETRY, new GeometryDataType());
+ types.put(Type.POINT, new PointDataType());
+ types.put(Type.LINESTRING, new LineStringDataType());
+ types.put(Type.POLYGON, new PolygonDataType());
+ types.put(Type.MULTIPOINT, new MultiPointDataType());
+ types.put(Type.MULTILINESTRING, new MultiLineStringDataType());
+ types.put(Type.MULTIPOLYGON, new MultiPolygonDataType());
+ types.put(Type.GEOMETRYCOLLECTION, new GeometryCollectionDataType());
+ types.put(Type.COORDINATE, new CoordinateDataType());
}
private final DataSchema rowType;
- public DataTypeImpl(DataSchema rowType) {
+ public DataRowType(DataSchema rowType) {
this.rowType = rowType;
}
@@ -110,6 +107,6 @@ public class DataTypeImpl implements DataType<DataRow> {
values.add(dataType.read(buffer, p));
p += dataType.size(buffer, p);
}
- return new DataRowImpl(rowType, values);
+ return new DataRow(rowType, values);
}
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataSchema.java
similarity index 78%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataSchema.java
index eceed6c38..4f26e4935 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataSchema.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.store;
+package org.apache.baremaps.calcite;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
@@ -28,38 +28,27 @@ 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.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
/**
- * A {@link DataSchema} is a description of the structure of a row in a {@link DataTable}.
+ * A {@link DataSchema} defines the structure of a table.
*/
-public interface DataSchema {
+public record DataSchema(String name,
+ List<DataColumn> columns) implements Serializable {
- /**
- * Returns the name of the schema.
- *
- * @return the name of the schema
- */
- String name();
-
- /**
- * Returns the columns of the schema.
- *
- * @return the columns of the schema
- */
- List<DataColumn> columns();
-
- /**
- * Creates a new row of the schema.
- *
- * @return a new row of the schema
- */
- DataRow createRow();
+ 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);
+ }
- class DataSchemaDeserializer extends JsonDeserializer<DataSchema> {
+ static class DataSchemaDeserializer extends JsonDeserializer<DataSchema> {
@Override
public DataSchema deserialize(JsonParser parser, DeserializationContext ctxt)
@@ -70,14 +59,14 @@ public interface DataSchema {
node.get("columns").elements().forEachRemaining(column -> {
columns.add(deserialize(column));
});
- return new DataSchemaImpl(name, columns);
+ return new DataSchema(name, columns);
}
DataColumn deserialize(JsonNode node) {
String columnName = node.get("name").asText();
Cardinality cardinality = Cardinality.valueOf(node.get("cardinality").asText());
- ColumnType type = ColumnType.valueOf(node.get("type").asText());
- if (type == ColumnType.NESTED) {
+ 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));
@@ -110,4 +99,5 @@ public interface DataSchema {
mapper.writeValue(outputStream, schema);
}
+
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataStore.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataStore.java
similarity index 98%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataStore.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataStore.java
index 6b737005e..083204977 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataStore.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataStore.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.store;
+package org.apache.baremaps.calcite;
import java.util.List;
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataStoreException.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataStoreException.java
similarity index 97%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataStoreException.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataStoreException.java
index 52400e1f3..7b04e2b32 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataStoreException.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataStoreException.java
@@ -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 {
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTable.java
similarity index 99%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTable.java
index a270f4d6b..e0177dbd0 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTable.java
@@ -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;
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
index 9957a117b..b1fc3619b 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableAdapter.java
@@ -18,9 +18,7 @@
package org.apache.baremaps.calcite;
import java.util.EnumMap;
-import org.apache.baremaps.store.DataColumn;
-import org.apache.baremaps.store.DataColumn.ColumnType;
-import org.apache.baremaps.store.DataTable;
+import org.apache.baremaps.calcite.DataColumn.Type;
import org.apache.calcite.DataContext;
import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.linq4j.Enumerable;
@@ -35,40 +33,40 @@ import org.locationtech.jts.geom.*;
public class DataTableAdapter extends AbstractTable implements ScannableTable {
- private static final EnumMap<ColumnType, RelDataType> types = new EnumMap<>(ColumnType.class);
+ private static final EnumMap<Type, RelDataType> types = new EnumMap<>(Type.class);
static {
- types.put(ColumnType.BYTE, new JavaTypeFactoryImpl()
+ types.put(Type.BYTE, new JavaTypeFactoryImpl()
.createSqlType(SqlTypeName.TINYINT));
- types.put(ColumnType.BOOLEAN, new JavaTypeFactoryImpl()
+ types.put(Type.BOOLEAN, new JavaTypeFactoryImpl()
.createSqlType(SqlTypeName.BOOLEAN));
- types.put(ColumnType.SHORT, new JavaTypeFactoryImpl()
+ types.put(Type.SHORT, new JavaTypeFactoryImpl()
.createSqlType(SqlTypeName.SMALLINT));
- types.put(ColumnType.INTEGER, new JavaTypeFactoryImpl()
+ types.put(Type.INTEGER, new JavaTypeFactoryImpl()
.createSqlType(SqlTypeName.INTEGER));
- types.put(ColumnType.LONG, new JavaTypeFactoryImpl()
+ types.put(Type.LONG, new JavaTypeFactoryImpl()
.createSqlType(SqlTypeName.BIGINT));
- types.put(ColumnType.FLOAT, new JavaTypeFactoryImpl()
+ types.put(Type.FLOAT, new JavaTypeFactoryImpl()
.createSqlType(SqlTypeName.FLOAT));
- types.put(ColumnType.DOUBLE, new JavaTypeFactoryImpl()
+ types.put(Type.DOUBLE, new JavaTypeFactoryImpl()
.createSqlType(SqlTypeName.DOUBLE));
- types.put(ColumnType.STRING, new JavaTypeFactoryImpl()
+ types.put(Type.STRING, new JavaTypeFactoryImpl()
.createSqlType(SqlTypeName.VARCHAR));
- types.put(ColumnType.GEOMETRY, new JavaTypeFactoryImpl()
+ types.put(Type.GEOMETRY, new JavaTypeFactoryImpl()
.createJavaType(Geometry.class));
- types.put(ColumnType.POINT, new JavaTypeFactoryImpl()
+ types.put(Type.POINT, new JavaTypeFactoryImpl()
.createJavaType(Point.class));
- types.put(ColumnType.LINESTRING, new JavaTypeFactoryImpl()
+ types.put(Type.LINESTRING, new JavaTypeFactoryImpl()
.createJavaType(LineString.class));
- types.put(ColumnType.POLYGON, new JavaTypeFactoryImpl()
+ types.put(Type.POLYGON, new JavaTypeFactoryImpl()
.createJavaType(Polygon.class));
- types.put(ColumnType.MULTIPOINT, new JavaTypeFactoryImpl()
+ types.put(Type.MULTIPOINT, new JavaTypeFactoryImpl()
.createJavaType(MultiPoint.class));
- types.put(ColumnType.MULTILINESTRING, new JavaTypeFactoryImpl()
+ types.put(Type.MULTILINESTRING, new JavaTypeFactoryImpl()
.createJavaType(MultiLineString.class));
- types.put(ColumnType.MULTIPOLYGON, new JavaTypeFactoryImpl()
+ types.put(Type.MULTIPOLYGON, new JavaTypeFactoryImpl()
.createJavaType(MultiPolygon.class));
- types.put(ColumnType.GEOMETRYCOLLECTION, new JavaTypeFactoryImpl()
+ types.put(Type.GEOMETRYCOLLECTION, new JavaTypeFactoryImpl()
.createJavaType(GeometryCollection.class));
}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
similarity index 85%
rename from baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
index 7553deb57..569984662 100644
--- a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableFactory.java
@@ -24,26 +24,22 @@ import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.file.Paths;
import java.util.Map;
-import org.apache.baremaps.csv.CsvDataTable;
+import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
+import org.apache.baremaps.calcite.csv.CsvDataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.DataCollection;
import org.apache.baremaps.data.memory.Memory;
import org.apache.baremaps.data.memory.MemoryMappedDirectory;
-import org.apache.baremaps.data.store.DataTableImpl;
import org.apache.baremaps.data.type.DataType;
-import org.apache.baremaps.data.type.DataTypeImpl;
-import org.apache.baremaps.store.DataRow;
-import org.apache.baremaps.store.DataSchema;
-import org.apache.baremaps.store.DataTable;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeImpl;
import org.apache.calcite.rel.type.RelProtoDataType;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.TableFactory;
-public class BaremapsTableFactory implements TableFactory<DataTableAdapter> {
+public class DataTableFactory implements TableFactory<DataTableAdapter> {
- public BaremapsTableFactory() {
+ public DataTableFactory() {
}
@@ -57,7 +53,7 @@ public class BaremapsTableFactory implements TableFactory<DataTableAdapter> {
rowType != null ? RelDataTypeImpl.proto(rowType) : null;
String format = (String) operand.get("format");
DataTable dataTable = switch (format) {
- case "mmap" -> createMMapTable(schema, name, operand, rowType);
+ case "baremaps" -> createMMapTable(schema, name, operand, rowType);
case "csv" -> createCsvTable(schema, name, operand, rowType);
default -> throw new RuntimeException("Unsupported format");
};
@@ -78,9 +74,9 @@ public class BaremapsTableFactory implements TableFactory<DataTableAdapter> {
byte[] bytes = new byte[length];
header.get(bytes);
DataSchema dataSchema = DataSchema.read(new ByteArrayInputStream(bytes));
- DataType<DataRow> dataType = new DataTypeImpl(dataSchema);
+ DataType<DataRow> dataType = new DataRowType(dataSchema);
DataCollection<DataRow> dataCollection = new AppendOnlyLog<>(dataType, memory);
- return new DataTableImpl(dataSchema, dataCollection);
+ return new BaremapsDataTable(dataSchema, dataCollection);
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTableGeometryMapper.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableGeometryMapper.java
similarity index 98%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataTableGeometryMapper.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableGeometryMapper.java
index 8671a00fc..5537a2818 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTableGeometryMapper.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableGeometryMapper.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.store;
+package org.apache.baremaps.calcite;
import java.util.function.UnaryOperator;
import org.locationtech.jts.geom.Geometry;
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTableMapper.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableMapper.java
similarity index 98%
rename from baremaps-store/src/main/java/org/apache/baremaps/store/DataTableMapper.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableMapper.java
index a9e2ea151..30db1425b 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTableMapper.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/DataTableMapper.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.store;
+package org.apache.baremaps.calcite;
import java.util.Iterator;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataStore.java
similarity index 84%
rename from baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataStore.java
index a8a56b6dd..bfeae188d 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataStore.java
@@ -15,19 +15,21 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.store;
+package org.apache.baremaps.calcite.baremaps;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import org.apache.baremaps.store.*;
+import org.apache.baremaps.calcite.DataStore;
+import org.apache.baremaps.calcite.DataStoreException;
+import org.apache.baremaps.calcite.DataTable;
-public class DataStoreImpl implements DataStore {
+public class BaremapsDataStore implements DataStore {
private Map<String, DataTable> tables;
- public DataStoreImpl(List<DataTable> tables) {
+ public BaremapsDataStore(List<DataTable> tables) {
this.tables =
tables.stream()
.collect(Collectors.toMap(table -> table.schema().name(), table -> table));
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataTableImpl.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataTable.java
similarity index 81%
rename from baremaps-data/src/main/java/org/apache/baremaps/data/store/DataTableImpl.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataTable.java
index 59c61d5d7..dcfab9722 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataTableImpl.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/baremaps/BaremapsDataTable.java
@@ -15,21 +15,21 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.store;
+package org.apache.baremaps.calcite.baremaps;
import java.io.IOException;
import java.util.Iterator;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.DataRowType;
+import org.apache.baremaps.calcite.DataSchema;
+import org.apache.baremaps.calcite.DataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.DataCollection;
-import org.apache.baremaps.data.type.DataTypeImpl;
-import org.apache.baremaps.store.DataRow;
-import org.apache.baremaps.store.DataSchema;
-import org.apache.baremaps.store.DataTable;
/**
* A {@link DataTable} is a collection of rows respecting a {@link DataSchema}.
*/
-public class DataTableImpl implements DataTable {
+public class BaremapsDataTable implements DataTable {
private final DataSchema schema;
@@ -41,7 +41,7 @@ public class DataTableImpl implements DataTable {
* @param schema the schema of the rows
* @param rows the rows
*/
- public DataTableImpl(DataSchema schema, DataCollection<DataRow> rows) {
+ public BaremapsDataTable(DataSchema schema, DataCollection<DataRow> rows) {
this.schema = schema;
this.rows = rows;
}
@@ -51,9 +51,9 @@ public class DataTableImpl implements DataTable {
*
* @param schema the schema of the rows
*/
- public DataTableImpl(DataSchema schema) {
+ public BaremapsDataTable(DataSchema schema) {
this.schema = schema;
- this.rows = new AppendOnlyLog<>(new DataTypeImpl(schema));
+ this.rows = new AppendOnlyLog<>(new DataRowType(schema));
}
/**
diff --git a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/csv/CsvDataStore.java
similarity index 92%
rename from baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/csv/CsvDataStore.java
index 355b74f4e..f50bb5d3d 100644
--- a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/csv/CsvDataStore.java
@@ -15,16 +15,16 @@
* limitations under the License.
*/
-package org.apache.baremaps.csv;
+package org.apache.baremaps.calcite.csv;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
-import org.apache.baremaps.store.DataSchema;
-import org.apache.baremaps.store.DataStore;
-import org.apache.baremaps.store.DataStoreException;
-import org.apache.baremaps.store.DataTable;
+import org.apache.baremaps.calcite.DataSchema;
+import org.apache.baremaps.calcite.DataStore;
+import org.apache.baremaps.calcite.DataStoreException;
+import org.apache.baremaps.calcite.DataTable;
/**
* A DataStore implementation that manages a single CSV file.
diff --git a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/csv/CsvDataTable.java
similarity index 95%
rename from baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/csv/CsvDataTable.java
index 6ed88cc9e..dd5a3297a 100644
--- a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/csv/CsvDataTable.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.csv;
+package org.apache.baremaps.calcite.csv;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
@@ -25,9 +25,9 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
import org.locationtech.jts.io.WKTReader;
public class CsvDataTable implements DataTable {
@@ -53,7 +53,7 @@ public class CsvDataTable implements DataTable {
*/
public CsvDataTable(String name, File csvFile, char separator, boolean hasHeader)
throws IOException {
- this(name, csvFile, separator, inferColumns(csvFile, separator, hasHeader), hasHeader);
+ this(name, csvFile, separator, hasHeader, inferColumns(csvFile, separator, hasHeader));
}
/**
@@ -62,12 +62,12 @@ public class CsvDataTable implements DataTable {
* @param name the name of the table
* @param csvFile the CSV file to read data from
* @param separator the separator used in the CSV file
- * @param columns the list of columns (data types, names, etc.)
* @param hasHeader indicates whether the CSV file has a header row
+ * @param columns the list of columns (data types, names, etc.)
* @throws IOException if an I/O error occurs
*/
- public CsvDataTable(String name, File csvFile, char separator, List<DataColumn> columns,
- boolean hasHeader)
+ public CsvDataTable(String name, File csvFile, char separator, boolean hasHeader,
+ List<DataColumn> columns)
throws IOException {
this.file = csvFile;
this.hasHeader = hasHeader;
@@ -95,7 +95,7 @@ public class CsvDataTable implements DataTable {
}
this.size = rowCount;
this.csvSchema = schema;
- this.dataSchema = new DataSchemaImpl(name, columns);
+ this.dataSchema = new DataSchema(name, columns);
}
/**
@@ -150,7 +150,7 @@ public class CsvDataTable implements DataTable {
throw new DataStoreException("Failed to infer CSV schema from header.");
}
for (String colName : inferred.getColumnNames()) {
- columns.add(new DataColumnFixed(colName, Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed(colName, Cardinality.OPTIONAL, Type.STRING));
}
}
} else {
@@ -164,7 +164,7 @@ public class CsvDataTable implements DataTable {
int numColumns = firstRow.size();
for (int i = 0; i < numColumns; i++) {
columns.add(
- new DataColumnFixed("column" + (i + 1), Cardinality.OPTIONAL, ColumnType.STRING));
+ new DataColumnFixed("column" + (i + 1), Cardinality.OPTIONAL, Type.STRING));
}
} else {
throw new DataStoreException("CSV file is empty; cannot infer column names.");
@@ -238,7 +238,7 @@ public class CsvDataTable implements DataTable {
}
private static Object parseValue(DataColumn column, String value) {
- ColumnType type = column.type();
+ Type type = column.type();
try {
return switch (type) {
case STRING -> value;
diff --git a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataStore.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataStore.java
similarity index 93%
rename from baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataStore.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataStore.java
index 88425922a..8ac03b2b0 100644
--- a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataStore.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataStore.java
@@ -15,15 +15,15 @@
* limitations under the License.
*/
-package org.apache.baremaps.flatgeobuf;
+package org.apache.baremaps.calcite.flatgeobuf;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
-import org.apache.baremaps.store.DataStore;
-import org.apache.baremaps.store.DataStoreException;
-import org.apache.baremaps.store.DataTable;
+import org.apache.baremaps.calcite.DataStore;
+import org.apache.baremaps.calcite.DataStoreException;
+import org.apache.baremaps.calcite.DataTable;
/**
* A {@link DataStore} corresponding to the flatgeobuf files of a directory.
diff --git a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataTable.java
similarity index 93%
rename from baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataTable.java
index 42d9467d0..d2eeb98de 100644
--- a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataTable.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.flatgeobuf;
+package org.apache.baremaps.calcite.flatgeobuf;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -26,8 +26,12 @@ import java.nio.file.StandardOpenOption;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.flatgeobuf.FlatGeoBuf;
+import org.apache.baremaps.flatgeobuf.FlatGeoBufReader;
+import org.apache.baremaps.flatgeobuf.FlatGeoBufWriter;
+import org.apache.baremaps.flatgeobuf.PackedRTree;
/**
* A {@link DataTable} that stores rows in a flatgeobuf file.
@@ -131,7 +135,7 @@ public class FlatGeoBufDataTable implements DataTable {
schema.columns().stream()
.filter(c -> c.cardinality() == DataColumn.Cardinality.REQUIRED)
.forEach(c -> {
- if (Objects.requireNonNull(c.type()) == ColumnType.BINARY) {
+ if (Objects.requireNonNull(c.type()) == Type.BINARY) {
throw new UnsupportedOperationException();
}
});
diff --git a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufTypeConversion.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufTypeConversion.java
similarity index 74%
rename from baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufTypeConversion.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufTypeConversion.java
index db109a5bb..e87f17eed 100644
--- a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufTypeConversion.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufTypeConversion.java
@@ -15,29 +15,30 @@
* limitations under the License.
*/
-package org.apache.baremaps.flatgeobuf;
+package org.apache.baremaps.calcite.flatgeobuf;
import java.util.*;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.flatgeobuf.FlatGeoBuf;
import org.apache.baremaps.flatgeobuf.FlatGeoBuf.Feature;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
import org.locationtech.jts.geom.Geometry;
public class FlatGeoBufTypeConversion {
- private static final Map<ColumnType, Integer> types = new EnumMap<>(ColumnType.class);
+ private static final Map<Type, Integer> types = new EnumMap<>(Type.class);
static {
- types.put(ColumnType.BYTE, org.apache.baremaps.flatgeobuf.generated.ColumnType.Byte);
- types.put(ColumnType.BOOLEAN, org.apache.baremaps.flatgeobuf.generated.ColumnType.Bool);
- types.put(ColumnType.SHORT, org.apache.baremaps.flatgeobuf.generated.ColumnType.Short);
- types.put(ColumnType.INTEGER, org.apache.baremaps.flatgeobuf.generated.ColumnType.Int);
- types.put(ColumnType.LONG, org.apache.baremaps.flatgeobuf.generated.ColumnType.Long);
- types.put(ColumnType.FLOAT, org.apache.baremaps.flatgeobuf.generated.ColumnType.Float);
- types.put(ColumnType.DOUBLE, org.apache.baremaps.flatgeobuf.generated.ColumnType.Double);
- types.put(ColumnType.STRING, org.apache.baremaps.flatgeobuf.generated.ColumnType.String);
+ types.put(Type.BYTE, org.apache.baremaps.flatgeobuf.generated.ColumnType.Byte);
+ types.put(Type.BOOLEAN, org.apache.baremaps.flatgeobuf.generated.ColumnType.Bool);
+ types.put(Type.SHORT, org.apache.baremaps.flatgeobuf.generated.ColumnType.Short);
+ types.put(Type.INTEGER, org.apache.baremaps.flatgeobuf.generated.ColumnType.Int);
+ types.put(Type.LONG, org.apache.baremaps.flatgeobuf.generated.ColumnType.Long);
+ types.put(Type.FLOAT, org.apache.baremaps.flatgeobuf.generated.ColumnType.Float);
+ types.put(Type.DOUBLE, org.apache.baremaps.flatgeobuf.generated.ColumnType.Double);
+ types.put(Type.STRING, org.apache.baremaps.flatgeobuf.generated.ColumnType.String);
}
private FlatGeoBufTypeConversion() {
@@ -50,10 +51,10 @@ public class FlatGeoBufTypeConversion {
.map(column -> new DataColumnFixed(
column.name(),
column.nullable() ? Cardinality.OPTIONAL : Cardinality.REQUIRED,
- ColumnType.fromBinding(fromColumnType(column.type()))))
+ Type.fromBinding(fromColumnType(column.type()))))
.map(DataColumn.class::cast)
.toList();
- return new DataSchemaImpl(name, columns);
+ return new DataSchema(name, columns);
}
private static Class<?> fromColumnType(FlatGeoBuf.ColumnType columnType) {
@@ -86,7 +87,7 @@ public class FlatGeoBufTypeConversion {
values.addAll(feature.properties());
}
- return new DataRowImpl(dataType, values);
+ return new DataRow(dataType, values);
}
public static List<FlatGeoBuf.Column> asColumns(List<DataColumn> columns) {
diff --git a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataStore.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataStore.java
similarity index 91%
rename from baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataStore.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataStore.java
index 71ddb3fb2..f4bc4f623 100644
--- a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataStore.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataStore.java
@@ -15,16 +15,16 @@
* limitations under the License.
*/
-package org.apache.baremaps.geopackage;
+package org.apache.baremaps.calcite.geopackage;
import java.nio.file.Path;
import java.util.List;
import mil.nga.geopackage.GeoPackage;
import mil.nga.geopackage.GeoPackageManager;
-import org.apache.baremaps.store.DataStore;
-import org.apache.baremaps.store.DataStoreException;
-import org.apache.baremaps.store.DataTable;
+import org.apache.baremaps.calcite.DataStore;
+import org.apache.baremaps.calcite.DataStoreException;
+import org.apache.baremaps.calcite.DataTable;
/**
* A {@link DataStore} corresponding to a GeoPackage file.
diff --git a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataTable.java
similarity index 95%
rename from baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataTable.java
index a2e76c183..d6b60bd46 100644
--- a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataTable.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.geopackage;
+package org.apache.baremaps.calcite.geopackage;
import java.io.IOException;
@@ -27,9 +27,9 @@ import mil.nga.geopackage.features.user.FeatureColumn;
import mil.nga.geopackage.features.user.FeatureDao;
import mil.nga.geopackage.features.user.FeatureResultSet;
import mil.nga.geopackage.geom.GeoPackageGeometryData;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
import org.locationtech.jts.geom.*;
/**
@@ -68,15 +68,15 @@ public class GeoPackageDataTable implements DataTable {
columns.add(new DataColumnFixed(
propertyName, propertyCardinality, propertyType));
}
- schema = new DataSchemaImpl(name, columns);
+ schema = new DataSchema(name, columns);
geometryFactory = new GeometryFactory(new PrecisionModel(), (int) featureDao.getSrs().getId());
}
- private ColumnType classType(FeatureColumn column) {
+ private Type classType(FeatureColumn column) {
if (column.isGeometry()) {
- return ColumnType.fromBinding(Geometry.class);
+ return Type.fromBinding(Geometry.class);
} else {
- return ColumnType.fromBinding(column.getDataType().getClassType());
+ return Type.fromBinding(column.getDataType().getClassType());
}
}
diff --git a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataStore.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataStore.java
similarity index 90%
rename from baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataStore.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataStore.java
index 4423be329..b2d9fbce0 100644
--- a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataStore.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataStore.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.baremaps.geoparquet;
+package org.apache.baremaps.calcite.geoparquet;
import java.net.URI;
import java.util.List;
-import org.apache.baremaps.store.DataStore;
-import org.apache.baremaps.store.DataStoreException;
-import org.apache.baremaps.store.DataTable;
+import org.apache.baremaps.calcite.DataStore;
+import org.apache.baremaps.calcite.DataStoreException;
+import org.apache.baremaps.calcite.DataTable;
/**
* A {@link DataStore} corresponding to a GeoParquet file.
diff --git a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataTable.java
similarity index 87%
rename from baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataTable.java
index db2c2f729..33266dd4a 100644
--- a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataTable.java
@@ -15,17 +15,18 @@
* limitations under the License.
*/
-package org.apache.baremaps.geoparquet;
+package org.apache.baremaps.calcite.geoparquet;
import java.io.IOException;
import java.net.URI;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.stream.Stream;
-import org.apache.baremaps.store.DataRow;
-import org.apache.baremaps.store.DataRowImpl;
-import org.apache.baremaps.store.DataSchema;
-import org.apache.baremaps.store.DataTable;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.DataSchema;
+import org.apache.baremaps.calcite.DataTable;
+import org.apache.baremaps.geoparquet.GeoParquetException;
+import org.apache.baremaps.geoparquet.GeoParquetReader;
import org.apache.hadoop.fs.Path;
public class GeoParquetDataTable implements DataTable {
@@ -63,7 +64,7 @@ public class GeoParquetDataTable implements DataTable {
@Override
public Stream<DataRow> parallelStream() {
- return reader.readParallel().map(group -> new DataRowImpl(
+ return reader.readParallel().map(group -> new DataRow(
GeoParquetTypeConversion.asSchema(path.toString(), group.getGeoParquetSchema()),
GeoParquetTypeConversion.asRowValues(group)));
}
diff --git a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetTypeConversion.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetTypeConversion.java
similarity index 89%
rename from baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetTypeConversion.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetTypeConversion.java
index bbf25dfcb..90eae9461 100644
--- a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetTypeConversion.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/geoparquet/GeoParquetTypeConversion.java
@@ -15,17 +15,19 @@
* limitations under the License.
*/
-package org.apache.baremaps.geoparquet;
+package org.apache.baremaps.calcite.geoparquet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.geoparquet.GeoParquetGroup;
+import org.apache.baremaps.geoparquet.GeoParquetSchema;
import org.apache.baremaps.geoparquet.GeoParquetSchema.Field;
import org.apache.baremaps.geoparquet.GeoParquetSchema.GroupField;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
import org.apache.parquet.io.api.Binary;
public class GeoParquetTypeConversion {
@@ -34,7 +36,7 @@ public class GeoParquetTypeConversion {
public static DataSchema asSchema(String table, GeoParquetSchema schema) {
List<DataColumn> columns = asDataColumns(schema);
- return new DataSchemaImpl(table, columns);
+ return new DataSchema(table, columns);
}
private static List<DataColumn> asDataColumns(GeoParquetSchema field) {
@@ -50,15 +52,15 @@ public class GeoParquetTypeConversion {
case REPEATED -> Cardinality.REPEATED;
};
return switch (field.type()) {
- case BINARY -> new DataColumnFixed(field.name(), cardinality, ColumnType.BINARY);
- case BOOLEAN -> new DataColumnFixed(field.name(), cardinality, ColumnType.BOOLEAN);
- case INTEGER -> new DataColumnFixed(field.name(), cardinality, ColumnType.INTEGER);
- case INT96, LONG -> new DataColumnFixed(field.name(), cardinality, ColumnType.LONG);
- case FLOAT -> new DataColumnFixed(field.name(), cardinality, ColumnType.FLOAT);
- case DOUBLE -> new DataColumnFixed(field.name(), cardinality, ColumnType.DOUBLE);
- case STRING -> new DataColumnFixed(field.name(), cardinality, ColumnType.STRING);
- case GEOMETRY -> new DataColumnFixed(field.name(), cardinality, ColumnType.GEOMETRY);
- case ENVELOPE -> new DataColumnFixed(field.name(), cardinality, ColumnType.ENVELOPE);
+ case BINARY -> new DataColumnFixed(field.name(), cardinality, Type.BINARY);
+ case BOOLEAN -> new DataColumnFixed(field.name(), cardinality, Type.BOOLEAN);
+ case INTEGER -> new DataColumnFixed(field.name(), cardinality, Type.INTEGER);
+ case INT96, LONG -> new DataColumnFixed(field.name(), cardinality, Type.LONG);
+ case FLOAT -> new DataColumnFixed(field.name(), cardinality, Type.FLOAT);
+ case DOUBLE -> new DataColumnFixed(field.name(), cardinality, Type.DOUBLE);
+ case STRING -> new DataColumnFixed(field.name(), cardinality, Type.STRING);
+ case GEOMETRY -> new DataColumnFixed(field.name(), cardinality, Type.GEOMETRY);
+ case ENVELOPE -> new DataColumnFixed(field.name(), cardinality, Type.ENVELOPE);
case GROUP -> new DataColumnNested(field.name(), cardinality,
asDataColumns(((GroupField) field).schema()));
};
diff --git a/baremaps-openstreetmap/src/main/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapDataTable.java
similarity index 90%
rename from baremaps-openstreetmap/src/main/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapDataTable.java
index 6101b69c1..61dc0e965 100644
--- a/baremaps-openstreetmap/src/main/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapDataTable.java
@@ -15,15 +15,15 @@
* limitations under the License.
*/
-package org.apache.baremaps.openstreetmap;
+package org.apache.baremaps.calcite.openstreetmap;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Stream;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Type;
import org.apache.baremaps.openstreetmap.OpenStreetMapFormat.EntityReader;
import org.apache.baremaps.openstreetmap.model.*;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.ColumnType;
/**
* A DataTable implementation for OpenStreetMap data.
@@ -53,18 +53,18 @@ public class OpenStreetMapDataTable implements DataTable {
*/
private DataSchema createSchema() {
List<DataColumn> columns = List.of(
- new DataColumnFixed("id", DataColumn.Cardinality.REQUIRED, ColumnType.LONG),
- new DataColumnFixed("type", DataColumn.Cardinality.REQUIRED, ColumnType.STRING),
- new DataColumnFixed("version", DataColumn.Cardinality.OPTIONAL, ColumnType.INTEGER),
+ new DataColumnFixed("id", DataColumn.Cardinality.REQUIRED, Type.LONG),
+ new DataColumnFixed("type", DataColumn.Cardinality.REQUIRED, Type.STRING),
+ new DataColumnFixed("version", DataColumn.Cardinality.OPTIONAL, Type.INTEGER),
new DataColumnFixed("timestamp", DataColumn.Cardinality.OPTIONAL,
- ColumnType.LOCAL_DATE_TIME),
- new DataColumnFixed("uid", DataColumn.Cardinality.OPTIONAL, ColumnType.INTEGER),
- new DataColumnFixed("user", DataColumn.Cardinality.OPTIONAL, ColumnType.STRING),
- new DataColumnFixed("changeset", DataColumn.Cardinality.OPTIONAL, ColumnType.LONG),
- new DataColumnFixed("tags", DataColumn.Cardinality.OPTIONAL, ColumnType.NESTED),
+ Type.LOCAL_DATE_TIME),
+ new DataColumnFixed("uid", DataColumn.Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("user", DataColumn.Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("changeset", DataColumn.Cardinality.OPTIONAL, Type.LONG),
+ new DataColumnFixed("tags", DataColumn.Cardinality.OPTIONAL, Type.NESTED),
new DataColumnFixed("geometry", DataColumn.Cardinality.OPTIONAL,
- ColumnType.GEOMETRY));
- return new DataSchemaImpl("osm_data", columns);
+ Type.GEOMETRY));
+ return new DataSchema("osm_data", columns);
}
@Override
diff --git a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataStore.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresDataStore.java
similarity index 97%
rename from baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataStore.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresDataStore.java
index 512b0b837..00ad7fa92 100644
--- a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataStore.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresDataStore.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.postgres.store;
+package org.apache.baremaps.calcite.postgres;
import de.bytefish.pgbulkinsert.pgsql.handlers.*;
@@ -25,13 +25,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import javax.sql.DataSource;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Type;
import org.apache.baremaps.postgres.copy.CopyWriter;
import org.apache.baremaps.postgres.copy.EnvelopeValueHandler;
import org.apache.baremaps.postgres.copy.GeometryValueHandler;
import org.apache.baremaps.postgres.metadata.DatabaseMetadata;
import org.apache.baremaps.postgres.metadata.TableMetadata;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.ColumnType;
import org.postgresql.PGConnection;
import org.postgresql.copy.PGCopyOutputStream;
import org.slf4j.Logger;
@@ -119,7 +119,7 @@ public class PostgresDataStore implements DataStore {
}
}
- var schema = new DataSchemaImpl(name, properties);
+ var schema = new DataSchema(name, properties);
// Create the table
var createQuery = createTable(schema);
@@ -193,7 +193,7 @@ public class PostgresDataStore implements DataStore {
PostgresTypeConversion.nameToType.get(column.typeName())))
.map(DataColumn.class::cast)
.toList();
- return new DataSchemaImpl(name, columns);
+ return new DataSchema(name, columns);
}
/**
@@ -291,7 +291,7 @@ public class PostgresDataStore implements DataStore {
* @param type the type
* @return the handler
*/
- protected BaseValueHandler getHandler(ColumnType type) {
+ protected BaseValueHandler getHandler(Type type) {
return switch (type) {
case STRING -> new StringValueHandler();
case SHORT -> new ShortValueHandler<Short>();
diff --git a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresDataTable.java
similarity index 96%
rename from baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresDataTable.java
index cad98ce33..cdfccefd4 100644
--- a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresDataTable.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.postgres.store;
+package org.apache.baremaps.calcite.postgres;
import static org.locationtech.jts.io.WKBConstants.wkbNDR;
@@ -25,7 +25,10 @@ import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.sql.DataSource;
-import org.apache.baremaps.store.*;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.DataSchema;
+import org.apache.baremaps.calcite.DataStoreException;
+import org.apache.baremaps.calcite.DataTable;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKBReader;
@@ -302,7 +305,7 @@ public class PostgresDataTable implements DataTable {
}
}
hasNext = resultSet.next();
- return new DataRowImpl(schema, values);
+ return new DataRow(schema, values);
} catch (SQLException e) {
close();
throw new DataStoreException("Error while fetching the next result", e);
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresTypeConversion.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresTypeConversion.java
new file mode 100644
index 000000000..c1b8872af
--- /dev/null
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresTypeConversion.java
@@ -0,0 +1,72 @@
+/*
+ * 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.postgres;
+
+import java.util.EnumMap;
+import java.util.Map;
+import org.apache.baremaps.calcite.DataColumn.Type;
+
+@SuppressWarnings("squid:S1192")
+public class PostgresTypeConversion {
+
+ private PostgresTypeConversion() {
+ // Prevent instantiation
+ }
+
+ protected static final Map<Type, String> typeToName = new EnumMap<>(Type.class);
+
+ static {
+ typeToName.put(Type.STRING, "varchar");
+ typeToName.put(Type.SHORT, "int2");
+ typeToName.put(Type.INTEGER, "int4");
+ typeToName.put(Type.LONG, "int8");
+ typeToName.put(Type.FLOAT, "float4");
+ typeToName.put(Type.DOUBLE, "float8");
+ typeToName.put(Type.GEOMETRY, "geometry");
+ typeToName.put(Type.POINT, "geometry");
+ typeToName.put(Type.MULTIPOINT, "geometry");
+ typeToName.put(Type.LINESTRING, "geometry");
+ typeToName.put(Type.MULTILINESTRING, "geometry");
+ typeToName.put(Type.POLYGON, "geometry");
+ typeToName.put(Type.MULTIPOLYGON, "geometry");
+ typeToName.put(Type.GEOMETRYCOLLECTION, "geometry");
+ typeToName.put(Type.ENVELOPE, "geometry");
+ typeToName.put(Type.INET_ADDRESS, "inet");
+ typeToName.put(Type.INET4_ADDRESS, "inet");
+ typeToName.put(Type.INET6_ADDRESS, "inet");
+ typeToName.put(Type.LOCAL_DATE, "date");
+ typeToName.put(Type.LOCAL_TIME, "time");
+ typeToName.put(Type.LOCAL_DATE_TIME, "timestamp");
+ typeToName.put(Type.NESTED, "jsonb");
+ }
+
+ protected static final Map<String, Type> nameToType = Map.ofEntries(
+ Map.entry("varchar", Type.STRING),
+ Map.entry("int2", Type.SHORT),
+ Map.entry("int4", Type.INTEGER),
+ Map.entry("int8", Type.LONG),
+ Map.entry("float4", Type.FLOAT),
+ Map.entry("float8", Type.DOUBLE),
+ Map.entry("geometry", Type.GEOMETRY),
+ Map.entry("inet", Type.INET6_ADDRESS),
+ Map.entry("date", Type.LOCAL_DATE),
+ Map.entry("time", Type.LOCAL_TIME),
+ Map.entry("timestamp", Type.LOCAL_DATE_TIME),
+ Map.entry("jsonb", Type.NESTED));
+
+}
diff --git a/baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataRowIterator.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslDataRowIterator.java
similarity index 90%
rename from baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataRowIterator.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslDataRowIterator.java
index bdecbc2ac..9c671f2ac 100644
--- a/baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataRowIterator.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslDataRowIterator.java
@@ -15,14 +15,16 @@
* limitations under the License.
*/
-package org.apache.baremaps.rpsl;
+package org.apache.baremaps.calcite.rpsl;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
-import org.apache.baremaps.store.DataColumn;
-import org.apache.baremaps.store.DataRow;
-import org.apache.baremaps.store.DataSchema;
+import org.apache.baremaps.calcite.DataColumn;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.DataSchema;
+import org.apache.baremaps.rpsl.RpslObject;
+import org.apache.baremaps.rpsl.RpslReader;
/**
* An iterator over DataRow objects created from RPSL data.
diff --git a/baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslDataTable.java
similarity index 82%
rename from baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslDataTable.java
index b4f1b3a1e..8aafb42ff 100644
--- a/baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/rpsl/RpslDataTable.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.baremaps.rpsl;
+package org.apache.baremaps.calcite.rpsl;
import java.io.InputStream;
import java.util.*;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
/**
* A DataTable implementation that reads RPSL data using RpslReader.
@@ -49,21 +49,21 @@ public class RpslDataTable implements DataTable {
*/
private DataSchema createSchema() {
List<DataColumn> columns = new ArrayList<>();
- columns.add(new DataColumnFixed("type", Cardinality.REQUIRED, ColumnType.STRING));
- columns.add(new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.STRING));
- columns.add(new DataColumnFixed("inetnum", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("inet6num", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("netname", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("descr", Cardinality.REPEATED, ColumnType.STRING));
- columns.add(new DataColumnFixed("country", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("admin-c", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("tech-c", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("status", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("mnt-by", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("created", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("last-modified", Cardinality.OPTIONAL, ColumnType.STRING));
- columns.add(new DataColumnFixed("changed", Cardinality.REPEATED, ColumnType.STRING));
- return new DataSchemaImpl("RpslObject", columns);
+ columns.add(new DataColumnFixed("type", Cardinality.REQUIRED, Type.STRING));
+ columns.add(new DataColumnFixed("id", Cardinality.REQUIRED, Type.STRING));
+ columns.add(new DataColumnFixed("inetnum", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("inet6num", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("netname", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("descr", Cardinality.REPEATED, Type.STRING));
+ columns.add(new DataColumnFixed("country", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("admin-c", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("tech-c", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("status", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("mnt-by", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("created", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("last-modified", Cardinality.OPTIONAL, Type.STRING));
+ columns.add(new DataColumnFixed("changed", Cardinality.REPEATED, Type.STRING));
+ return new DataSchema("RpslObject", columns);
}
@Override
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataStore.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileDataStore.java
similarity index 91%
rename from baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataStore.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileDataStore.java
index 93281c5df..fcac9961e 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataStore.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileDataStore.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.shapefile;
+package org.apache.baremaps.calcite.shapefile;
@@ -23,9 +23,9 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
-import org.apache.baremaps.store.DataStore;
-import org.apache.baremaps.store.DataStoreException;
-import org.apache.baremaps.store.DataTable;
+import org.apache.baremaps.calcite.DataStore;
+import org.apache.baremaps.calcite.DataStoreException;
+import org.apache.baremaps.calcite.DataTable;
/**
* A schema corresponding to the shapefiles of a directory.
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileDataTable.java
similarity index 63%
rename from baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataTable.java
rename to baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileDataTable.java
index 8822bb921..3a109e3f9 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataTable.java
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/shapefile/ShapefileDataTable.java
@@ -15,17 +15,17 @@
* limitations under the License.
*/
-package org.apache.baremaps.shapefile;
+package org.apache.baremaps.calcite.shapefile;
import java.io.IOException;
import java.nio.file.Path;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import org.apache.baremaps.store.DataRow;
-import org.apache.baremaps.store.DataSchema;
-import org.apache.baremaps.store.DataStoreException;
-import org.apache.baremaps.store.DataTable;
+import java.util.*;
+import org.apache.baremaps.calcite.*;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.shapefile.ShapefileInputStream;
+import org.apache.baremaps.shapefile.ShapefileReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +38,43 @@ public class ShapefileDataTable implements DataTable {
private final ShapefileReader shapeFile;
+ private final DataSchema schema;
+
+ private DataSchema getSchema(final String name) {
+ Objects.requireNonNull(name, "The row name cannot be null.");
+
+ var columns = new ArrayList<DataColumn>();
+ for (int i = 0; i < shapeFile.getDatabaseFieldsDescriptors().size(); i++) {
+ var fieldDescriptor = shapeFile.getDatabaseFieldsDescriptors().get(i);
+ var columnName = fieldDescriptor.getName();
+ var columnType = switch (fieldDescriptor.getType()) {
+ case CHARACTER -> Type.STRING;
+ case NUMBER -> fieldDescriptor.getDecimalCount() == 0 ? Type.LONG : Type.DOUBLE;
+ case CURRENCY -> Type.DOUBLE;
+ case DOUBLE -> Type.DOUBLE;
+ case INTEGER -> Type.INTEGER;
+ case AUTO_INCREMENT -> Type.INTEGER;
+
+ // TODO: Implement the following types
+ case LOGICAL -> Type.STRING;
+ case DATE -> Type.STRING;
+ case MEMO -> Type.STRING;
+ case FLOATING_POINT -> Type.STRING;
+ case PICTURE -> Type.STRING;
+ case VARI_FIELD -> Type.STRING;
+ case VARIANT -> Type.STRING;
+ case TIMESTAMP -> Type.STRING;
+ case DATE_TIME -> Type.STRING;
+ };
+ columns.add(new DataColumnFixed(columnName, Cardinality.OPTIONAL, columnType));
+ }
+
+ // Add geometry column.
+ columns.add(new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY));
+
+ return new DataSchema(name, columns);
+ }
+
private ShapefileIterator iterator;
/**
@@ -47,6 +84,7 @@ public class ShapefileDataTable implements DataTable {
*/
public ShapefileDataTable(Path file) {
this.shapeFile = new ShapefileReader(file.toString());
+ this.schema = getSchema(file.getFileName().toString());
}
/**
@@ -54,11 +92,7 @@ public class ShapefileDataTable implements DataTable {
*/
@Override
public DataSchema schema() throws DataStoreException {
- try (var input = shapeFile.read()) {
- return input.schema();
- } catch (IOException e) {
- throw new DataStoreException(e);
- }
+ return schema;
}
/**
@@ -99,11 +133,11 @@ public class ShapefileDataTable implements DataTable {
/**
* An iterator over the rows of a shapefile.
*/
- public static class ShapefileIterator implements Iterator<DataRow>, AutoCloseable {
+ public class ShapefileIterator implements Iterator<DataRow>, AutoCloseable {
private final ShapefileInputStream shapefileInputStream;
- private DataRow next;
+ private List<Object> next;
/**
* Constructs an iterator from a shapefile input stream.
@@ -144,9 +178,9 @@ public class ShapefileDataTable implements DataTable {
if (next == null) {
next = shapefileInputStream.readRow();
}
- DataRow current = next;
+ List<Object> current = next;
next = null;
- return current;
+ return new DataRow(schema, current);
} catch (Exception e) {
try {
shapefileInputStream.close();
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index d96d5ca9b..7f5258507 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
@@ -19,13 +19,11 @@ package org.apache.baremaps.calcite;
import java.sql.*;
import java.util.*;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
-import org.apache.baremaps.data.store.DataTableImpl;
-import org.apache.baremaps.data.type.DataTypeImpl;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
import org.apache.calcite.DataContext;
import org.apache.calcite.DataContexts;
import org.apache.calcite.interpreter.Interpreter;
@@ -67,34 +65,34 @@ public class CalciteTest {
SchemaPlus rootSchema = calciteConnection.getRootSchema();
// Create and add 'city' table
- DataSchema cityRowType = new DataSchemaImpl("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, ColumnType.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, ColumnType.GEOMETRY)));
+ DataSchema cityRowType = new DataSchema("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
- DataTable cityDataTable = new DataTableImpl(
+ DataTable cityDataTable = new BaremapsDataTable(
cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(cityRowType))));
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(cityRowType))));
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
rootSchema.add("city", cityDataTableAdapter);
// Create and add 'population' table
- DataSchema populationRowType = new DataSchemaImpl("population", List.of(
- new DataColumnFixed("city_id", Cardinality.OPTIONAL, ColumnType.INTEGER),
- new DataColumnFixed("population", Cardinality.OPTIONAL, ColumnType.INTEGER)));
+ DataSchema populationRowType = new DataSchema("population", List.of(
+ new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
- DataTable populationDataTable = new DataTableImpl(
+ DataTable populationDataTable = new BaremapsDataTable(
populationRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(populationRowType))));
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(populationRowType))));
- populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(1, 2_161_000)));
- populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(2, 8_336_000)));
+ populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
+ populationDataTable.add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
DataTableAdapter populationDataTableAdapter = new DataTableAdapter(populationDataTable);
rootSchema.add("population", populationDataTableAdapter);
@@ -194,19 +192,19 @@ public class CalciteTest {
rootSchema.add("MY_SCHEMA", new ListSchema(listA, listB));
// Create and add 'city' table
- DataSchema cityRowType = new DataSchemaImpl("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, ColumnType.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, ColumnType.GEOMETRY)));
+ DataSchema cityRowType = new DataSchema("city", List.of(
+ new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
- DataTable cityDataTable = new DataTableImpl(
+ DataTable cityDataTable = new BaremapsDataTable(
cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(cityRowType))));
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataRowType(cityRowType))));
GeometryFactory geometryFactory = new GeometryFactory();
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
+ cityDataTable.add(new DataRow(cityDataTable.schema(),
List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
DataTableAdapter cityDataTableAdapter = new DataTableAdapter(cityDataTable);
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java
index 69b33e354..e5e089cef 100644
--- a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTableAdapterFactoryTest.java
@@ -28,22 +28,19 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.List;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.calcite.baremaps.BaremapsDataTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.memory.Memory;
import org.apache.baremaps.data.memory.MemoryMappedDirectory;
-import org.apache.baremaps.data.store.DataTableImpl;
-import org.apache.baremaps.data.type.DataTypeImpl;
import org.apache.baremaps.data.util.FileUtils;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
class DataTableAdapterFactoryTest {
-
@Test
public void createCsvTable() throws Exception {
File file = File.createTempFile("test", ".csv");
@@ -65,7 +62,7 @@ class DataTableAdapterFactoryTest {
tables: [
{
name: 'TEST',
- factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
+ factory: 'org.apache.baremaps.calcite.DataTableFactory',
operand: {
format: 'csv',
file: '%s'
@@ -92,10 +89,10 @@ class DataTableAdapterFactoryTest {
public void createMMapTable() throws Exception {
Path path = Files.createTempDirectory("temp");
- DataSchema dataSchema = new DataSchemaImpl("test", List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
- new DataColumnFixed("name", Cardinality.REQUIRED, ColumnType.STRING),
- new DataColumnFixed("geom", Cardinality.REQUIRED, ColumnType.GEOMETRY)));
+ DataSchema dataSchema = new DataSchema("test", List.of(
+ new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.REQUIRED, Type.STRING),
+ new DataColumnFixed("geom", Cardinality.REQUIRED, Type.GEOMETRY)));
// Serialize the schema
ByteArrayOutputStream output = new ByteArrayOutputStream();
@@ -110,10 +107,11 @@ class DataTableAdapterFactoryTest {
header.put(bytes);
DataTable dataTable =
- new DataTableImpl(dataSchema, new AppendOnlyLog<>(new DataTypeImpl(dataSchema), memory));
- dataTable.add(new DataRowImpl(dataSchema,
+ new BaremapsDataTable(dataSchema,
+ new AppendOnlyLog<>(new DataRowType(dataSchema), memory));
+ dataTable.add(new DataRow(dataSchema,
List.of(1, "a", new GeometryFactory().createPoint(new Coordinate(1, 1)))));
- dataTable.add(new DataRowImpl(dataSchema,
+ dataTable.add(new DataRow(dataSchema,
List.of(2, "b", new GeometryFactory().createPoint(new Coordinate(2, 2)))));
dataTable.close();
@@ -129,9 +127,9 @@ class DataTableAdapterFactoryTest {
tables: [
{
name: 'TEST',
- factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
+ factory: 'org.apache.baremaps.calcite.DataTableFactory',
operand: {
- format: 'mmap',
+ format: 'baremaps',
directory: '%s'
}
}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTypeProvider.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTypeProvider.java
new file mode 100644
index 000000000..b3909706d
--- /dev/null
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTypeProvider.java
@@ -0,0 +1,89 @@
+/*
+ * 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 java.util.List;
+import java.util.stream.Stream;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.junit.jupiter.params.provider.Arguments;
+import org.locationtech.jts.geom.*;
+
+public class DataTypeProvider {
+
+ private static final GeometryFactory geometryFactory = new GeometryFactory();
+
+ private static final DataSchema DATA_SCHEMA = new DataSchema("row", List.of(
+ new DataColumnFixed("byte", Cardinality.OPTIONAL, Type.BYTE),
+ new DataColumnFixed("boolean", Cardinality.OPTIONAL, Type.BOOLEAN),
+ new DataColumnFixed("short", Cardinality.OPTIONAL, Type.SHORT),
+ new DataColumnFixed("integer", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("long", Cardinality.OPTIONAL, Type.LONG),
+ new DataColumnFixed("float", Cardinality.OPTIONAL, Type.FLOAT),
+ new DataColumnFixed("double", Cardinality.OPTIONAL, Type.DOUBLE),
+ new DataColumnFixed("string", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY),
+ new DataColumnFixed("point", Cardinality.OPTIONAL, Type.POINT),
+ new DataColumnFixed("linestring", Cardinality.OPTIONAL, Type.LINESTRING),
+ new DataColumnFixed("polygon", Cardinality.OPTIONAL, Type.POLYGON),
+ new DataColumnFixed("multipoint", Cardinality.OPTIONAL, Type.MULTIPOINT),
+ new DataColumnFixed("multilinestring", Cardinality.OPTIONAL, Type.MULTILINESTRING),
+ new DataColumnFixed("multipolygon", Cardinality.OPTIONAL, Type.MULTIPOLYGON),
+ new DataColumnFixed("geometrycollection", Cardinality.OPTIONAL,
+ Type.GEOMETRYCOLLECTION),
+ new DataColumnFixed("coordinate", Cardinality.OPTIONAL, Type.COORDINATE)));
+
+ private static final DataRow DATA_ROW = DATA_SCHEMA.createRow()
+ .with("byte", Byte.MAX_VALUE)
+ .with("boolean", true)
+ .with("short", Short.MAX_VALUE)
+ .with("integer", Integer.MAX_VALUE)
+ .with("long", Long.MAX_VALUE)
+ .with("float", Float.MAX_VALUE)
+ .with("double", Double.MAX_VALUE)
+ .with("string", "Hello, World!")
+ .with("geometry", geometryFactory.createPoint(new Coordinate(0, 0)))
+ .with("point", geometryFactory.createPoint(new Coordinate(0, 0)))
+ .with("linestring",
+ geometryFactory
+ .createLineString(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 1)}))
+ .with("polygon",
+ geometryFactory.createPolygon(new Coordinate[] {new Coordinate(0, 0),
+ new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0)}))
+ .with("multipoint",
+ geometryFactory
+ .createMultiPoint(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 1)}))
+ .with("multilinestring",
+ geometryFactory.createMultiLineString(new LineString[] {geometryFactory
+ .createLineString(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 1)})}))
+ .with("multipolygon",
+ geometryFactory.createMultiPolygon(
+ new Polygon[] {geometryFactory.createPolygon(new Coordinate[] {new Coordinate(0, 0),
+ new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0)})}))
+ .with("geometrycollection",
+ geometryFactory.createGeometryCollection(
+ new Geometry[] {geometryFactory.createPoint(new Coordinate(0, 0))}))
+ .with("coordinate", new Coordinate(0, 0));
+
+ private static Stream<Arguments> dataTypes() {
+ return Stream.of(Arguments.of(new DataRowType(DATA_SCHEMA), DATA_ROW));
+
+
+ }
+}
diff --git a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTypeTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTypeTest.java
new file mode 100644
index 000000000..fd3e06870
--- /dev/null
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/DataTypeTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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 static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.nio.ByteBuffer;
+import org.apache.baremaps.data.type.DataType;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+class DataTypeTest {
+
+ @ParameterizedTest
+ @MethodSource("org.apache.baremaps.calcite.DataTypeProvider#dataTypes")
+ void writeAndRead(DataType dataType, Object value) {
+ var size = dataType.size(value);
+ var buffer = ByteBuffer.allocate(size);
+ dataType.write(buffer, 0, value);
+ var recordSize = dataType.size(buffer, 0);
+ var recordValue = dataType.read(buffer, 0);
+
+ assertEquals(size, recordSize);
+
+ if (value instanceof byte[]) {
+ assertArrayEquals((byte[]) value, (byte[]) recordValue);
+ } else if (value instanceof short[]) {
+ assertArrayEquals((short[]) value, (short[]) recordValue);
+ } else if (value instanceof int[]) {
+ assertArrayEquals((int[]) value, (int[]) recordValue);
+ } else if (value instanceof long[]) {
+ assertArrayEquals((long[]) value, (long[]) recordValue);
+ } else if (value instanceof float[]) {
+ assertArrayEquals((float[]) value, (float[]) recordValue);
+ } else if (value instanceof double[]) {
+ assertArrayEquals((double[]) value, (double[]) recordValue);
+ } else if (value instanceof char[]) {
+ assertArrayEquals((char[]) value, (char[]) recordValue);
+ } else if (value instanceof boolean[]) {
+ assertArrayEquals((boolean[]) value, (boolean[]) recordValue);
+ } else {
+ assertEquals(value, recordValue);
+ }
+ }
+}
diff --git a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/MockDataTable.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/MockDataTable.java
similarity index 57%
rename from baremaps-postgres/src/test/java/org/apache/baremaps/postgres/MockDataTable.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/MockDataTable.java
index 668aaa819..adb90c06e 100644
--- a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/MockDataTable.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/MockDataTable.java
@@ -15,45 +15,47 @@
* limitations under the License.
*/
-package org.apache.baremaps.postgres;
+package org.apache.baremaps.calcite;
import java.util.Iterator;
import java.util.List;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.GeometryFactory;
public class MockDataTable implements DataTable {
+ private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
+
private final DataSchema rowType;
private final List<DataRow> rows;
public MockDataTable() {
- this.rowType = new DataSchemaImpl("mock", List.of(
- new DataColumnFixed("string", Cardinality.OPTIONAL, ColumnType.STRING),
- new DataColumnFixed("integer", Cardinality.OPTIONAL, ColumnType.INTEGER),
- new DataColumnFixed("double", Cardinality.OPTIONAL, ColumnType.DOUBLE),
- new DataColumnFixed("float", Cardinality.OPTIONAL, ColumnType.FLOAT),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, ColumnType.GEOMETRY)));
+ this.rowType = new DataSchema("mock", List.of(
+ new DataColumnFixed("string", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("integer", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("double", Cardinality.OPTIONAL, Type.DOUBLE),
+ new DataColumnFixed("float", Cardinality.OPTIONAL, Type.FLOAT),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
this.rows = List.of(
- new DataRowImpl(rowType,
+ new DataRow(rowType,
List.of("string", 1, 1.0, 1.0f,
- Constants.GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1)))),
- new DataRowImpl(rowType,
+ GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1)))),
+ new DataRow(rowType,
List.of("string", 2, 2.0, 2.0f,
- Constants.GEOMETRY_FACTORY.createPoint(new Coordinate(2, 2)))),
- new DataRowImpl(rowType,
+ GEOMETRY_FACTORY.createPoint(new Coordinate(2, 2)))),
+ new DataRow(rowType,
List.of("string", 3, 3.0, 3.0f,
- Constants.GEOMETRY_FACTORY.createPoint(new Coordinate(3, 3)))),
- new DataRowImpl(rowType,
+ GEOMETRY_FACTORY.createPoint(new Coordinate(3, 3)))),
+ new DataRow(rowType,
List.of("string", 4, 4.0, 4.0f,
- Constants.GEOMETRY_FACTORY.createPoint(new Coordinate(4, 4)))),
- new DataRowImpl(rowType,
+ GEOMETRY_FACTORY.createPoint(new Coordinate(4, 4)))),
+ new DataRow(rowType,
List.of("string", 5, 5.0, 5.0f,
- Constants.GEOMETRY_FACTORY.createPoint(new Coordinate(5, 5)))));
+ GEOMETRY_FACTORY.createPoint(new Coordinate(5, 5)))));
}
@Override
diff --git a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvDataTableGeonamesTest.java
similarity index 61%
rename from baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvDataTableGeonamesTest.java
index d46dd7728..e6816a0c0 100644
--- a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvDataTableGeonamesTest.java
@@ -15,13 +15,19 @@
* limitations under the License.
*/
-package org.apache.baremaps.csv;
+package org.apache.baremaps.calcite.csv;
import static org.apache.baremaps.testing.TestFiles.GEONAMES_CSV;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
-import org.apache.baremaps.store.*;
+import java.util.List;
+import org.apache.baremaps.calcite.DataColumn;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.calcite.DataColumnFixed;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.DataTable;
import org.junit.jupiter.api.*;
import org.locationtech.jts.geom.Point;
@@ -29,9 +35,30 @@ class CsvDataTableGeonamesTest {
@Test
void testGeonamesCsvDataTable() throws IOException {
- DataTable dataTable = new CsvDataTable("sample", GEONAMES_CSV.toFile(), '\t', false);
+ List<DataColumn> columns = List.of(
+ new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("asciiname", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("alternatenames", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("latitude", Cardinality.OPTIONAL, Type.DOUBLE),
+ new DataColumnFixed("longitude", Cardinality.OPTIONAL, Type.DOUBLE),
+ new DataColumnFixed("feature_class", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("feature_code", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("country_code", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("cc2", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("admin1_code", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("admin2_code", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("admin3_code", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("admin4_code", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("population", Cardinality.OPTIONAL, Type.LONG),
+ new DataColumnFixed("elevation", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("dem", Cardinality.OPTIONAL, Type.INTEGER),
+ new DataColumnFixed("timezone", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("modification_date", Cardinality.OPTIONAL, Type.STRING));
- assertEquals(5, dataTable.size(), "DataTable should have 5 rows.");
+ DataTable dataTable = new CsvDataTable("sample", GEONAMES_CSV.toFile(), '\t', false, columns);
+
+ assertEquals(5, dataTable.size(), "DataTable should have 4 rows.");
int rowCount = 0;
for (DataRow row : dataTable) {
diff --git a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvDataTableTest.java
similarity index 83%
rename from baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvDataTableTest.java
index 970decb5e..89bc5bcbc 100644
--- a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvDataTableTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.csv;
+package org.apache.baremaps.calcite.csv;
import static org.junit.jupiter.api.Assertions.*;
@@ -24,9 +24,12 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.apache.baremaps.calcite.DataColumn;
+import org.apache.baremaps.calcite.DataColumn.Cardinality;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.calcite.DataColumnFixed;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.DataTable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -60,10 +63,10 @@ class CsvDataTableTest {
Files.writeString(tempCsvFile.toPath(), csvContent);
// Provide an explicit schema so that the id and geom fields are parsed correctly.
List<DataColumn> columns = List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING),
- new DataColumnFixed("geom", Cardinality.OPTIONAL, ColumnType.GEOMETRY));
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', columns, true);
+ new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("geom", Cardinality.OPTIONAL, Type.GEOMETRY));
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', true, columns);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -88,10 +91,10 @@ class CsvDataTableTest {
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
List<DataColumn> columns = List.of(
- new DataColumnFixed("column1", Cardinality.REQUIRED, ColumnType.INTEGER),
- new DataColumnFixed("column2", Cardinality.OPTIONAL, ColumnType.STRING),
- new DataColumnFixed("column3", Cardinality.OPTIONAL, ColumnType.GEOMETRY));
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ';', columns, false);
+ new DataColumnFixed("column1", Cardinality.REQUIRED, Type.INTEGER),
+ new DataColumnFixed("column2", Cardinality.OPTIONAL, Type.STRING),
+ new DataColumnFixed("column3", Cardinality.OPTIONAL, Type.GEOMETRY));
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ';', false, columns);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -120,11 +123,11 @@ class CsvDataTableTest {
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
List<DataColumn> columns = List.of(
- new DataColumnFixed("int_col", Cardinality.REQUIRED, ColumnType.INTEGER),
- new DataColumnFixed("double_col", Cardinality.REQUIRED, ColumnType.DOUBLE),
- new DataColumnFixed("bool_col", Cardinality.REQUIRED, ColumnType.BOOLEAN),
- new DataColumnFixed("string_col", Cardinality.REQUIRED, ColumnType.STRING));
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', columns, true);
+ new DataColumnFixed("int_col", Cardinality.REQUIRED, Type.INTEGER),
+ new DataColumnFixed("double_col", Cardinality.REQUIRED, Type.DOUBLE),
+ new DataColumnFixed("bool_col", Cardinality.REQUIRED, Type.BOOLEAN),
+ new DataColumnFixed("string_col", Cardinality.REQUIRED, Type.STRING));
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', true, columns);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -151,10 +154,10 @@ class CsvDataTableTest {
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
List<DataColumn> columns = List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING));
+ new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING));
// Pass the explicit columns so that "id" is attempted to be parsed as an integer.
- DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', columns, true);
+ DataTable dataTable = new CsvDataTable("test_table", tempCsvFile, ',', true, columns);
assertThrows(RuntimeException.class, () -> {
for (DataRow row : dataTable) {
// This line should throw an exception because "abc" is not a valid integer.
diff --git a/baremaps-flatgeobuf/src/test/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTableTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataTableTest.java
similarity index 97%
rename from baremaps-flatgeobuf/src/test/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTableTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataTableTest.java
index 96142d9d3..8f4d8e76a 100644
--- a/baremaps-flatgeobuf/src/test/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTableTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufDataTableTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.flatgeobuf;
+package org.apache.baremaps.calcite.flatgeobuf;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/baremaps-geopackage/src/test/java/org/apache/baremaps/geopackage/GeoPackageDataStoreTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataStoreTest.java
similarity index 91%
rename from baremaps-geopackage/src/test/java/org/apache/baremaps/geopackage/GeoPackageDataStoreTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataStoreTest.java
index 8b9ef47ac..a5ef3cead 100644
--- a/baremaps-geopackage/src/test/java/org/apache/baremaps/geopackage/GeoPackageDataStoreTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geopackage/GeoPackageDataStoreTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.geopackage;
+package org.apache.baremaps.calcite.geopackage;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -30,8 +30,8 @@ class GeoPackageDataStoreTest {
var geoPackageStore = new GeoPackageDataStore(file);
var table = geoPackageStore.get("countries");
var rowType = table.schema();
- assertEquals("countries", rowType.getName());
- assertEquals(4, rowType.getColumns().size());
+ assertEquals("countries", rowType.name());
+ assertEquals(4, rowType.columns().size());
}
@Test
diff --git a/baremaps-geoparquet/src/test/java/org/apache/baremaps/geoparquet/GeoParquetDataStoreTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataStoreTest.java
similarity index 97%
rename from baremaps-geoparquet/src/test/java/org/apache/baremaps/geoparquet/GeoParquetDataStoreTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataStoreTest.java
index 4e16967db..3445789f5 100644
--- a/baremaps-geoparquet/src/test/java/org/apache/baremaps/geoparquet/GeoParquetDataStoreTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geoparquet/GeoParquetDataStoreTest.java
@@ -15,7 +15,8 @@
* limitations under the License.
*/
-package org.apache.baremaps.geoparquet;
+package org.apache.baremaps.calcite.geoparquet;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTableTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapDataTableTest.java
similarity index 89%
rename from baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTableTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapDataTableTest.java
index 35deb29db..f378a7121 100644
--- a/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTableTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/openstreetmap/OpenStreetMapDataTableTest.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.baremaps.openstreetmap;
+package org.apache.baremaps.calcite.openstreetmap;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.nio.file.Files;
@@ -33,8 +33,8 @@ class OpenStreetMapDataTableTest {
try (var inputStream = Files.newInputStream(uri)) {
var table = new OpenStreetMapDataTable(new PbfEntityReader(), inputStream);
var rowType = table.schema();
- assertEquals(rowType.getName(), "osm_data");
- assertEquals(9, rowType.getColumns().size());
+ assertEquals(rowType.name(), "osm_data");
+ assertEquals(9, rowType.columns().size());
}
}
diff --git a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataStoreTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/postgres/PostgresDataStoreTest.java
similarity index 91%
rename from baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataStoreTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/postgres/PostgresDataStoreTest.java
index 805c78318..197f69939 100644
--- a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataStoreTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/postgres/PostgresDataStoreTest.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.baremaps.postgres.store;
+package org.apache.baremaps.calcite.postgres;
import static org.junit.jupiter.api.Assertions.*;
-import org.apache.baremaps.postgres.MockDataTable;
-import org.apache.baremaps.store.DataStoreException;
+import org.apache.baremaps.calcite.DataStoreException;
+import org.apache.baremaps.calcite.MockDataTable;
import org.apache.baremaps.testing.PostgresContainerTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
diff --git a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataTableTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/postgres/PostgresDataTableTest.java
similarity index 77%
rename from baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataTableTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/postgres/PostgresDataTableTest.java
index 716c57c9b..6a8e49a7e 100644
--- a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/store/PostgresDataTableTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/postgres/PostgresDataTableTest.java
@@ -15,23 +15,25 @@
* limitations under the License.
*/
-package org.apache.baremaps.postgres.store;
+package org.apache.baremaps.calcite.postgres;
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
-import org.apache.baremaps.postgres.Constants;
-import org.apache.baremaps.postgres.MockDataTable;
-import org.apache.baremaps.store.DataRowImpl;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.MockDataTable;
import org.apache.baremaps.testing.PostgresContainerTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.GeometryFactory;
class PostgresDataTableTest extends PostgresContainerTest {
+ private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
+
private PostgresDataStore schema;
@BeforeEach
@@ -61,8 +63,8 @@ class PostgresDataTableTest extends PostgresContainerTest {
var table = schema.get("mock");
var rowType = table.schema();
assertNotNull(rowType);
- assertEquals("mock", rowType.getName());
- assertEquals(5, rowType.getColumns().size());
+ assertEquals("mock", rowType.name());
+ assertEquals(5, rowType.columns().size());
}
@Test
@@ -70,9 +72,9 @@ class PostgresDataTableTest extends PostgresContainerTest {
void add() {
var table = schema.get("mock");
var rowType = table.schema();
- var added = table.add(new DataRowImpl(rowType,
+ var added = table.add(new DataRow(rowType,
List.of("string", 6, 6.0, 6.0f,
- Constants.GEOMETRY_FACTORY.createPoint(new Coordinate(6, 6)))));
+ GEOMETRY_FACTORY.createPoint(new Coordinate(6, 6)))));
Assertions.assertTrue(added);
assertEquals(6, table.size());
}
@@ -83,12 +85,12 @@ class PostgresDataTableTest extends PostgresContainerTest {
var table = schema.get("mock");
var rowType = table.schema();
var added = table.addAll(List.of(
- new DataRowImpl(rowType,
+ new DataRow(rowType,
List.of("string", 6, 6.0, 6.0f,
- Constants.GEOMETRY_FACTORY.createPoint(new Coordinate(6, 6)))),
- new DataRowImpl(rowType,
+ GEOMETRY_FACTORY.createPoint(new Coordinate(6, 6)))),
+ new DataRow(rowType,
List.of("string", 7, 7.0, 7.0f,
- Constants.GEOMETRY_FACTORY.createPoint(new Coordinate(7, 7))))));
+ GEOMETRY_FACTORY.createPoint(new Coordinate(7, 7))))));
Assertions.assertTrue(added);
assertEquals(7, table.size());
}
diff --git a/baremaps-rpsl/src/test/java/org/apache/baremaps/rpsl/RsplDataTableTest.java b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/rpsl/RsplDataTableTest.java
similarity index 85%
rename from baremaps-rpsl/src/test/java/org/apache/baremaps/rpsl/RsplDataTableTest.java
rename to baremaps-calcite/src/test/java/org/apache/baremaps/calcite/rpsl/RsplDataTableTest.java
index 2e800a087..1a050290d 100644
--- a/baremaps-rpsl/src/test/java/org/apache/baremaps/rpsl/RsplDataTableTest.java
+++ b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/rpsl/RsplDataTableTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.baremaps.rpsl;
+package org.apache.baremaps.calcite.rpsl;
import static org.junit.jupiter.api.Assertions.*;
@@ -23,7 +23,10 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.Iterator;
import java.util.List;
-import org.apache.baremaps.store.*;
+import org.apache.baremaps.calcite.DataColumn;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.DataSchema;
+import org.apache.baremaps.calcite.DataTable;
import org.apache.baremaps.testing.TestFiles;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -42,8 +45,8 @@ class RpslDataTableTest {
@Test
void schema() {
DataSchema schema = dataTable.schema();
- assertEquals("RpslObject", schema.getName());
- List<DataColumn> columns = schema.getColumns();
+ assertEquals("RpslObject", schema.name());
+ List<DataColumn> columns = schema.columns();
assertTrue(columns.stream().anyMatch(c -> c.name().equals("type")));
assertTrue(columns.stream().anyMatch(c -> c.name().equals("id")));
assertTrue(columns.stream().anyMatch(c -> c.name().equals("inetnum")));
diff --git a/baremaps-cli/src/license/override.properties b/baremaps-cli/src/license/override.properties
index 5dcc3c88c..19189d8e9 100644
--- a/baremaps-cli/src/license/override.properties
+++ b/baremaps-cli/src/license/override.properties
@@ -148,11 +148,9 @@ net.ripe.ipresource--ipresource--1.52=BSD License
org.antlr--antlr4-runtime--4.11.1=BSD 3-Clause License
org.apache.avro--avro--1.9.2=Apache License 2.0
org.apache.baremaps--baremaps-core--0.8.1=Apache License 2.0
-org.apache.baremaps--baremaps-csv--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-data--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-dem--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-flatgeobuf--0.8.1=Apache License 2.0
-org.apache.baremaps--baremaps-geopackage--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-geoparquet--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-maplibre--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-openstreetmap--0.8.1=Apache License 2.0
@@ -161,7 +159,6 @@ org.apache.baremaps--baremaps-postgres--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-rpsl--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-server--0.8.1=Apache License 2.0
org.apache.baremaps--baremaps-shapefile--0.8.1=Apache License 2.0
-org.apache.baremaps--baremaps-store--0.8.1=Apache License 2.0
org.apache.calcite--calcite-core--1.37.0=Apache License 2.0
org.apache.calcite--calcite-linq4j--1.37.0=Apache License 2.0
org.apache.calcite.avatica--avatica-core--1.25.0=Apache License 2.0
diff --git a/baremaps-core/pom.xml b/baremaps-core/pom.xml
index faeee3c4e..50a493954 100644
--- a/baremaps-core/pom.xml
+++ b/baremaps-core/pom.xml
@@ -49,7 +49,7 @@ limitations under the License.
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-csv</artifactId>
+ <artifactId>baremaps-calcite</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
@@ -63,10 +63,6 @@ limitations under the License.
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-flatgeobuf</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-geopackage</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-geoparquet</artifactId>
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowConsumer.java b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowConsumer.java
index 88582b5ee..fabb0c650 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowConsumer.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowConsumer.java
@@ -18,7 +18,7 @@
package org.apache.baremaps.geocoder;
import java.util.function.Consumer;
-import org.apache.baremaps.store.DataRow;
+import org.apache.baremaps.calcite.DataRow;
import org.apache.lucene.index.IndexWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java
index 2398d1d4a..0efdba0b1 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java
@@ -26,10 +26,10 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
-import org.apache.baremaps.store.DataColumn;
-import org.apache.baremaps.store.DataColumn.ColumnType;
-import org.apache.baremaps.store.DataRow;
-import org.apache.baremaps.store.DataSchema;
+import org.apache.baremaps.calcite.DataColumn;
+import org.apache.baremaps.calcite.DataColumn.Type;
+import org.apache.baremaps.calcite.DataRow;
+import org.apache.baremaps.calcite.DataSchema;
import org.apache.lucene.document.*;
import org.locationtech.jts.geom.*;
import org.slf4j.Logger;
@@ -59,7 +59,7 @@ public class DataRowMapper implements Function<DataRow, Document> {
@SuppressWarnings("squid:S6541")
private void applyValue(DataColumn column, Document doc, Object value) {
String columnName = column.name();
- ColumnType type = column.type();
+ Type type = column.type();
try {
switch (type) {
case BINARY:
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataTableQueryBuilder.java b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataTableQueryBuilder.java
index 5dad38798..4bb5b7d85 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataTableQueryBuilder.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataTableQueryBuilder.java
@@ -20,8 +20,8 @@ package org.apache.baremaps.geocoder;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
-import org.apache.baremaps.store.DataColumn;
-import org.apache.baremaps.store.DataSchema;
+import org.apache.baremaps.calcite.DataColumn;
+import org.apache.baremaps.calcite.DataSchema;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.queryparser.classic.QueryParserBase;
import org.apache.lucene.queryparser.simple.SimpleQueryParser;
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoPackage.java b/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoPackage.java
index 47728e60d..bcaf923b3 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoPackage.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoPackage.java
@@ -19,11 +19,11 @@ package org.apache.baremaps.tasks;
import java.nio.file.Path;
import java.util.StringJoiner;
-import org.apache.baremaps.geopackage.GeoPackageDataStore;
+import org.apache.baremaps.calcite.DataTableGeometryMapper;
+import org.apache.baremaps.calcite.DataTableMapper;
+import org.apache.baremaps.calcite.geopackage.GeoPackageDataStore;
+import org.apache.baremaps.calcite.postgres.PostgresDataStore;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
-import org.apache.baremaps.postgres.store.PostgresDataStore;
-import org.apache.baremaps.store.DataTableGeometryMapper;
-import org.apache.baremaps.store.DataTableMapper;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
import org.slf4j.Logger;
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoParquet.java b/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoParquet.java
index 70491d6c0..704cb53fa 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoParquet.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoParquet.java
@@ -19,12 +19,12 @@ package org.apache.baremaps.tasks;
import java.net.URI;
import java.util.StringJoiner;
-import org.apache.baremaps.geoparquet.GeoParquetDataStore;
-import org.apache.baremaps.geoparquet.GeoParquetDataTable;
+import org.apache.baremaps.calcite.DataTableGeometryMapper;
+import org.apache.baremaps.calcite.DataTableMapper;
+import org.apache.baremaps.calcite.geoparquet.GeoParquetDataStore;
+import org.apache.baremaps.calcite.geoparquet.GeoParquetDataTable;
+import org.apache.baremaps.calcite.postgres.PostgresDataStore;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
-import org.apache.baremaps.postgres.store.PostgresDataStore;
-import org.apache.baremaps.store.DataTableGeometryMapper;
-import org.apache.baremaps.store.DataTableMapper;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
import org.slf4j.Logger;
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportShapefile.java b/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportShapefile.java
index 1e5f95d31..abfa5c5df 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportShapefile.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportShapefile.java
@@ -19,11 +19,11 @@ package org.apache.baremaps.tasks;
import java.nio.file.Path;
import java.util.StringJoiner;
+import org.apache.baremaps.calcite.DataTableGeometryMapper;
+import org.apache.baremaps.calcite.DataTableMapper;
+import org.apache.baremaps.calcite.postgres.PostgresDataStore;
+import org.apache.baremaps.calcite.shapefile.ShapefileDataTable;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
-import org.apache.baremaps.postgres.store.PostgresDataStore;
-import org.apache.baremaps.shapefile.ShapefileDataTable;
-import org.apache.baremaps.store.DataTableGeometryMapper;
-import org.apache.baremaps.store.DataTableMapper;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
import org.apache.baremaps.workflow.WorkflowException;
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 4c0067272..6eb62f014 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
@@ -17,112 +17,104 @@
package org.apache.baremaps.calcite;
-
- import com.google.common.collect.ImmutableList;
- import java.sql.*;
- import java.util.List;
- import java.util.Properties;
- import org.apache.baremaps.data.calcite.BaremapsTable;
- import org.apache.baremaps.data.collection.AppendOnlyLog;
- import org.apache.baremaps.data.collection.IndexedDataList;
- import org.apache.baremaps.data.store.DataTableImpl;
- import org.apache.baremaps.data.type.DataTypeImpl;
- import org.apache.baremaps.maplibre.vectortile.VectorTileFunctions;
- import org.apache.baremaps.store.*;
- import org.apache.baremaps.store.DataColumn.Cardinality;
- import org.apache.baremaps.store.DataColumn.Type;
- import org.apache.calcite.jdbc.CalciteConnection;
- import org.apache.calcite.model.ModelHandler;
- import org.apache.calcite.runtime.AccumOperation;
- import org.apache.calcite.runtime.CollectOperation;
- import org.apache.calcite.runtime.SpatialTypeFunctions;
- import org.apache.calcite.runtime.UnionOperation;
- import org.apache.calcite.schema.SchemaPlus;
- import org.apache.calcite.schema.impl.AggregateFunctionImpl;
- import org.apache.calcite.sql.fun.SqlSpatialTypeFunctions;
- import org.junit.jupiter.api.Assertions;
- import org.junit.jupiter.api.Test;
- import org.locationtech.jts.geom.*;
+// import com.google.common.collect.ImmutableList;
+// import java.sql.*;
+// import java.util.List;
+// import java.util.Properties;
+// import org.apache.baremaps.data.calcite.BaremapsTable;
+// import org.apache.baremaps.data.collection.AppendOnlyLog;
+// import org.apache.baremaps.data.collection.IndexedDataList;
+// import org.apache.baremaps.calcite.data.DataTableImpl;
+// import org.apache.baremaps.calcite.data.DataTypeImpl;
+// import org.apache.baremaps.maplibre.vectortile.VectorTileFunctions;
+// import org.apache.baremaps.store.*;
+// import org.apache.baremaps.calcite.DataColumn.Cardinality;
+// import org.apache.baremaps.calcite.DataColumn.Type;
+// import org.apache.calcite.jdbc.CalciteConnection;
+// import org.apache.calcite.model.ModelHandler;
+// import org.apache.calcite.runtime.AccumOperation;
+// import org.apache.calcite.runtime.CollectOperation;
+// import org.apache.calcite.runtime.SpatialTypeFunctions;
+// import org.apache.calcite.runtime.UnionOperation;
+// import org.apache.calcite.schema.SchemaPlus;
+// import org.apache.calcite.schema.impl.AggregateFunctionImpl;
+// import org.apache.calcite.sql.fun.SqlSpatialTypeFunctions;
+// import org.junit.jupiter.api.Assertions;
+// import org.junit.jupiter.api.Test;
+// import org.locationtech.jts.geom.*;
class CalciteTest {
- @Test
- void test() throws SQLException {
- GeometryFactory geometryFactory = new GeometryFactory();
-
- Properties info = new Properties();
- info.setProperty("lex", "MYSQL");
-
- try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
- CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
- SchemaPlus rootSchema = calciteConnection.getRootSchema();
-
- // Add the spatial functions to the root schema
- ImmutableList<String> emptyPath = ImmutableList.of();
- ModelHandler.addFunctions(rootSchema, null, emptyPath,
- SpatialTypeFunctions.class.getName(), "*", true);
- ModelHandler.addFunctions(rootSchema, null, emptyPath,
- SqlSpatialTypeFunctions.class.getName(), "*", true);
-
- rootSchema.add("ST_UNION", AggregateFunctionImpl.create(UnionOperation.class));
- rootSchema.add("ST_ACCUM", AggregateFunctionImpl.create(AccumOperation.class));
- rootSchema.add("ST_COLLECT", AggregateFunctionImpl.create(CollectOperation.class));
-
- ModelHandler.addFunctions(rootSchema, "ST_AsMVTGeom", emptyPath,
- VectorTileFunctions.class.getName(), "asVectorTileGeom", true);
- ModelHandler.addFunctions(rootSchema, "ST_AsMVT", emptyPath,
- VectorTileFunctions.class.getName(), "asVectorTile", true);
-
- // Create the city table
- DataSchema cityRowType = new DataSchemaImpl("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
- DataTable cityDataTable = new BaremapsDataTable(
- cityRowType,
- IndexedDataList.<DataRow>builder()
- .values(AppendOnlyLog.<DataRow>builder()
- .dataType(new RowDataType(cityRowType))
- .build())
- .build());
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
- List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
- cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
- List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
- SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
- rootSchema.add("city", citySqlDataTable);
-
- // Create the population table
- DataSchema populationRowType = new DataSchemaImpl("population", List.of(
- new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
- DataTable populationDataTable = new BaremapsDataTable(
- populationRowType,
- IndexedDataList.<DataRow>builder()
- .values(AppendOnlyLog.<DataRow>builder()
- .dataType(new RowDataType(populationRowType))
- .build())
- .build());
- populationDataTable
- .add(new DataRowImpl(populationDataTable.schema(), List.of(1, 2_161_000)));
- populationDataTable
- .add(new DataRowImpl(populationDataTable.schema(), List.of(2, 8_336_000)));
- SqlDataTable populationSqlDataTable = new SqlDataTable(populationDataTable);
- rootSchema.add("population", populationSqlDataTable);
-
- // Query the database
- String sql = """
- SELECT ST_AsText(ST_AsMVTGeom(
- ST_GeomFromText('POLYGON ((0 0, 10 1, 10 10, 1 10, 0 0))'),
- ST_MakeEnvelope(0, 0, 4096, 4096),
- 4096, 0, true))
- """;
-
- try (Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(sql)) {
- Assertions.assertTrue(resultSet.next());
- Assertions.assertEquals("POLYGON ((0 4096, 10 4095, 10 4086, 1 4086, 0 4096))",
- resultSet.getString(1));
- }
- }
- }
+ //
+ // @Test
+ // void test() throws SQLException {
+ // GeometryFactory geometryFactory = new GeometryFactory();
+ //
+ // Properties info = new Properties();
+ // info.setProperty("lex", "MYSQL");
+ //
+ // try (Connection connection = DriverManager.getConnection("jdbc:calcite:", info)) {
+ // CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
+ // SchemaPlus rootSchema = calciteConnection.getRootSchema();
+ //
+ // // Add the spatial functions to the root schema
+ // ImmutableList<String> emptyPath = ImmutableList.of();
+ // ModelHandler.addFunctions(rootSchema, null, emptyPath,
+ // SpatialTypeFunctions.class.getName(), "*", true);
+ // ModelHandler.addFunctions(rootSchema, null, emptyPath,
+ // SqlSpatialTypeFunctions.class.getName(), "*", true);
+ //
+ // rootSchema.add("ST_UNION", AggregateFunctionImpl.create(UnionOperation.class));
+ // rootSchema.add("ST_ACCUM", AggregateFunctionImpl.create(AccumOperation.class));
+ // rootSchema.add("ST_COLLECT", AggregateFunctionImpl.create(CollectOperation.class));
+ //
+ // ModelHandler.addFunctions(rootSchema, "ST_AsMVTGeom", emptyPath,
+ // VectorTileFunctions.class.getName(), "asVectorTileGeom", true);
+ // ModelHandler.addFunctions(rootSchema, "ST_AsMVT", emptyPath,
+ // VectorTileFunctions.class.getName(), "asVectorTile", true);
+ //
+ // // Create the city table
+ // DataSchema cityRowType = new DataSchemaImpl("city", List.of(
+ // new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
+ // new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
+ // new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+ // DataTable cityDataTable = new DataTableImpl(
+ // cityRowType,
+ // new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(cityRowType))));
+ // cityDataTable.add(new DataRow(cityDataTable.schema(),
+ // List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
+ // cityDataTable.add(new DataRow(cityDataTable.schema(),
+ // List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
+ // BaremapsTable cityBaremapsTable = new BaremapsTable(cityDataTable);
+ // rootSchema.add("city", cityBaremapsTable);
+ //
+ // // Create the population table
+ // DataSchema populationRowType = new DataSchemaImpl("population", List.of(
+ // new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
+ // new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
+ // DataTable populationDataTable = new DataTableImpl(
+ // populationRowType,
+ // new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(populationRowType))));
+ // populationDataTable
+ // .add(new DataRow(populationDataTable.schema(), List.of(1, 2_161_000)));
+ // populationDataTable
+ // .add(new DataRow(populationDataTable.schema(), List.of(2, 8_336_000)));
+ // BaremapsTable populationBaremapsTable = new BaremapsTable(populationDataTable);
+ // rootSchema.add("population", populationBaremapsTable);
+ //
+ // // Query the database
+ // String sql = """
+ // SELECT ST_AsText(ST_AsMVTGeom(
+ // ST_GeomFromText('POLYGON ((0 0, 10 1, 10 10, 1 10, 0 0))'),
+ // ST_MakeEnvelope(0, 0, 4096, 4096),
+ // 4096, 0, true))
+ // """;
+ //
+ // try (Statement statement = connection.createStatement();
+ // ResultSet resultSet = statement.executeQuery(sql)) {
+ // Assertions.assertTrue(resultSet.next());
+ // Assertions.assertEquals("POLYGON ((0 4096, 10 4095, 10 4086, 1 4086, 0 4096))",
+ // resultSet.getString(1));
+ // }
+ // }
+ // }
}
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/DataTableIndexTest.java b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/DataTableIndexTest.java
index 70f1855de..3c639659e 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/DataTableIndexTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/DataTableIndexTest.java
@@ -24,9 +24,9 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
-import org.apache.baremaps.geoparquet.GeoParquetDataTable;
+import org.apache.baremaps.calcite.geoparquet.GeoParquetDataTable;
+import org.apache.baremaps.data.util.FileUtils;
import org.apache.baremaps.testing.TestFiles;
-import org.apache.baremaps.utils.FileUtils;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/geonames/GeonamesIndexTest.java b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/geonames/GeonamesIndexTest.java
index d2ea1c0a7..f936a5289 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/geonames/GeonamesIndexTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/geonames/GeonamesIndexTest.java
@@ -24,9 +24,9 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
+import org.apache.baremaps.data.util.FileUtils;
import org.apache.baremaps.tasks.CreateGeonamesIndex;
import org.apache.baremaps.testing.TestFiles;
-import org.apache.baremaps.utils.FileUtils;
import org.apache.baremaps.workflow.WorkflowContext;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.SearcherFactory;
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/openstreetmap/OpenStreetMapIndexTest.java b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/openstreetmap/OpenStreetMapIndexTest.java
index d4b722db8..e65d0d985 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/openstreetmap/OpenStreetMapIndexTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/openstreetmap/OpenStreetMapIndexTest.java
@@ -27,8 +27,8 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.apache.baremaps.data.util.FileUtils;
import org.apache.baremaps.tasks.CreateGeocoderOpenStreetMap;
-import org.apache.baremaps.utils.FileUtils;
import org.apache.baremaps.workflow.WorkflowContext;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.LatLonShape;
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoPackageToPostgresTest.java b/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoPackageToPostgresTest.java
index aea373c8a..45f871757 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoPackageToPostgresTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoPackageToPostgresTest.java
@@ -19,8 +19,8 @@ package org.apache.baremaps.integration;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.apache.baremaps.geopackage.GeoPackageDataStore;
-import org.apache.baremaps.postgres.store.PostgresDataStore;
+import org.apache.baremaps.calcite.geopackage.GeoPackageDataStore;
+import org.apache.baremaps.calcite.postgres.PostgresDataStore;
import org.apache.baremaps.testing.PostgresContainerTest;
import org.apache.baremaps.testing.TestFiles;
import org.junit.jupiter.api.Tag;
@@ -42,8 +42,8 @@ class GeoPackageToPostgresTest extends PostgresContainerTest {
// Check the table in Postgres
var postgresTable = postgresStore.get("countries");
- assertEquals("countries", postgresTable.schema().getName());
- assertEquals(4, postgresTable.schema().getColumns().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/integration/GeoParquetToPostgresTest.java b/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoParquetToPostgresTest.java
index 1d847cb26..842128d67 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoParquetToPostgresTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/integration/GeoParquetToPostgresTest.java
@@ -19,8 +19,8 @@ package org.apache.baremaps.integration;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.apache.baremaps.geoparquet.GeoParquetDataStore;
-import org.apache.baremaps.postgres.store.PostgresDataStore;
+import org.apache.baremaps.calcite.geoparquet.GeoParquetDataStore;
+import org.apache.baremaps.calcite.postgres.PostgresDataStore;
import org.apache.baremaps.testing.PostgresContainerTest;
import org.apache.baremaps.testing.TestFiles;
import org.junit.jupiter.api.Tag;
@@ -44,8 +44,8 @@ class GeoParquetToPostgresTest extends PostgresContainerTest {
// Check the table in Postgres
var postgresTable = postgresStore.get("geoparquet");
- assertEquals("geoparquet", postgresTable.schema().getName());
- assertEquals(7, postgresTable.schema().getColumns().size());
+ assertEquals("geoparquet", postgresTable.schema().name());
+ assertEquals(7, postgresTable.schema().columns().size());
assertEquals(5L, postgresTable.size());
assertEquals(5L, postgresTable.stream().count());
}
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java b/baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java
index 5f35f8b5b..713b6a37f 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java
@@ -28,11 +28,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import net.ripe.ipresource.IpResourceRange;
+import org.apache.baremaps.data.util.FileUtils;
import org.apache.baremaps.rpsl.RpslObject;
import org.apache.baremaps.rpsl.RpslReader;
import org.apache.baremaps.tasks.CreateGeonamesIndex;
import org.apache.baremaps.testing.TestFiles;
-import org.apache.baremaps.utils.FileUtils;
import org.apache.baremaps.workflow.WorkflowContext;
import org.apache.lucene.search.SearcherFactory;
import org.apache.lucene.search.SearcherManager;
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/tasks/DownloadUrlTest.java b/baremaps-core/src/test/java/org/apache/baremaps/tasks/DownloadUrlTest.java
index d5e8864b1..b436fca8e 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/tasks/DownloadUrlTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/tasks/DownloadUrlTest.java
@@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.nio.file.Files;
-import org.apache.baremaps.utils.FileUtils;
+import org.apache.baremaps.data.util.FileUtils;
import org.apache.baremaps.workflow.WorkflowContext;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/tilestore/file/FileTileStoreTest.java b/baremaps-core/src/test/java/org/apache/baremaps/tilestore/file/FileTileStoreTest.java
index 3b78bbcf3..d229899ba 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/tilestore/file/FileTileStoreTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/tilestore/file/FileTileStoreTest.java
@@ -23,9 +23,9 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import org.apache.baremaps.data.util.FileUtils;
import org.apache.baremaps.tilestore.TileDataSchemaTest;
import org.apache.baremaps.tilestore.TileStore;
-import org.apache.baremaps.utils.FileUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/tilestore/mbtiles/MBTilesStoreTest.java b/baremaps-core/src/test/java/org/apache/baremaps/tilestore/mbtiles/MBTilesStoreTest.java
index af44d6c9d..7ef9f9887 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/tilestore/mbtiles/MBTilesStoreTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/tilestore/mbtiles/MBTilesStoreTest.java
@@ -25,8 +25,8 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
+import org.apache.baremaps.data.util.FileUtils;
import org.apache.baremaps.tilestore.TileDataSchemaTest;
-import org.apache.baremaps.utils.FileUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/baremaps-data/pom.xml b/baremaps-data/pom.xml
index 658c5ff71..e068a4822 100644
--- a/baremaps-data/pom.xml
+++ b/baremaps-data/pom.xml
@@ -25,10 +25,6 @@ limitations under the License.
<artifactId>baremaps-data</artifactId>
<name>Apache Baremaps Data</name>
<dependencies>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-store</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
diff --git a/baremaps-data/src/test/java/org/apache/baremaps/data/AppendOnlyLogTest.java b/baremaps-data/src/test/java/org/apache/baremaps/data/AppendOnlyLogTest.java
index d9b354550..fb1e2278a 100644
--- a/baremaps-data/src/test/java/org/apache/baremaps/data/AppendOnlyLogTest.java
+++ b/baremaps-data/src/test/java/org/apache/baremaps/data/AppendOnlyLogTest.java
@@ -40,10 +40,10 @@ class AppendOnlyLogTest {
.memory(new OffHeapMemory(1 << 10))
.build();
for (int i = 0; i < 1 << 20; i++) {
- assertEquals(Long.BYTES + (i << 2), collection.addPositioned(i));
+ assertEquals((i << 2), collection.addPositioned(i));
}
for (int i = 0; i < 1 << 20; i++) {
- assertEquals(i, collection.getPositioned(Long.BYTES + (i << 2)));
+ assertEquals(i, collection.getPositioned((i << 2)));
}
}
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 955732eaf..b4aad877d 100644
--- a/baremaps-data/src/test/java/org/apache/baremaps/data/type/DataTypeProvider.java
+++ b/baremaps-data/src/test/java/org/apache/baremaps/data/type/DataTypeProvider.java
@@ -21,12 +21,6 @@ package org.apache.baremaps.data.type;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
-import org.apache.baremaps.store.DataColumnFixed;
-import org.apache.baremaps.store.DataRow;
-import org.apache.baremaps.store.DataSchema;
-import org.apache.baremaps.store.DataSchemaImpl;
import org.junit.jupiter.params.provider.Arguments;
import org.locationtech.jts.geom.*;
@@ -34,58 +28,6 @@ public class DataTypeProvider {
private static final GeometryFactory geometryFactory = new GeometryFactory();
- private static final DataSchema DATA_SCHEMA = new DataSchemaImpl("row", List.of(
- new DataColumnFixed("byte", Cardinality.OPTIONAL, ColumnType.BYTE),
- new DataColumnFixed("boolean", Cardinality.OPTIONAL, ColumnType.BOOLEAN),
- new DataColumnFixed("short", Cardinality.OPTIONAL, ColumnType.SHORT),
- new DataColumnFixed("integer", Cardinality.OPTIONAL, ColumnType.INTEGER),
- new DataColumnFixed("long", Cardinality.OPTIONAL, ColumnType.LONG),
- new DataColumnFixed("float", Cardinality.OPTIONAL, ColumnType.FLOAT),
- new DataColumnFixed("double", Cardinality.OPTIONAL, ColumnType.DOUBLE),
- new DataColumnFixed("string", Cardinality.OPTIONAL, ColumnType.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, ColumnType.GEOMETRY),
- new DataColumnFixed("point", Cardinality.OPTIONAL, ColumnType.POINT),
- new DataColumnFixed("linestring", Cardinality.OPTIONAL, ColumnType.LINESTRING),
- new DataColumnFixed("polygon", Cardinality.OPTIONAL, ColumnType.POLYGON),
- new DataColumnFixed("multipoint", Cardinality.OPTIONAL, ColumnType.MULTIPOINT),
- new DataColumnFixed("multilinestring", Cardinality.OPTIONAL, ColumnType.MULTILINESTRING),
- new DataColumnFixed("multipolygon", Cardinality.OPTIONAL, ColumnType.MULTIPOLYGON),
- new DataColumnFixed("geometrycollection", Cardinality.OPTIONAL,
- ColumnType.GEOMETRYCOLLECTION),
- new DataColumnFixed("coordinate", Cardinality.OPTIONAL, ColumnType.COORDINATE)));
-
- private static final DataRow DATA_ROW = DATA_SCHEMA.createRow()
- .with("byte", Byte.MAX_VALUE)
- .with("boolean", true)
- .with("short", Short.MAX_VALUE)
- .with("integer", Integer.MAX_VALUE)
- .with("long", Long.MAX_VALUE)
- .with("float", Float.MAX_VALUE)
- .with("double", Double.MAX_VALUE)
- .with("string", "Hello, World!")
- .with("geometry", geometryFactory.createPoint(new Coordinate(0, 0)))
- .with("point", geometryFactory.createPoint(new Coordinate(0, 0)))
- .with("linestring",
- geometryFactory
- .createLineString(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 1)}))
- .with("polygon",
- geometryFactory.createPolygon(new Coordinate[] {new Coordinate(0, 0),
- new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0)}))
- .with("multipoint",
- geometryFactory
- .createMultiPoint(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 1)}))
- .with("multilinestring",
- geometryFactory.createMultiLineString(new LineString[] {geometryFactory
- .createLineString(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 1)})}))
- .with("multipolygon",
- geometryFactory.createMultiPolygon(
- new Polygon[] {geometryFactory.createPolygon(new Coordinate[] {new Coordinate(0, 0),
- new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0)})}))
- .with("geometrycollection",
- geometryFactory.createGeometryCollection(
- new Geometry[] {geometryFactory.createPoint(new Coordinate(0, 0))}))
- .with("coordinate", new Coordinate(0, 0));
-
private static Stream<Arguments> dataTypes() {
return Stream.of(
// String
@@ -194,7 +136,7 @@ public class DataTypeProvider {
Arguments.of(new CoordinateDataType(), new Coordinate(-180, -90)),
Arguments.of(new CoordinateDataType(), new Coordinate(180, 90)),
- Arguments.of(new org.apache.baremaps.data.type.LonLatDataType(), new Coordinate(-180, -90)),
+ Arguments.of(new LonLatDataType(), new Coordinate(-180, -90)),
Arguments.of(new LonLatDataType(), new Coordinate(180, 90)),
Arguments.of(new SmallIntegerDataType(1), (int) Math.pow(2, 7) - 1),
Arguments.of(new SmallIntegerDataType(1), (int) -Math.pow(2, 7)),
@@ -345,9 +287,6 @@ public class DataTypeProvider {
new Coordinate(3, 2), new Coordinate(4, 2),
new Coordinate(4, 1), new Coordinate(3, 1)})})})),
- // Row
- Arguments.of(new DataTypeImpl(DATA_SCHEMA), DATA_ROW),
-
// Geometry
Arguments.of(new GeometryDataType(),
new GeometryFactory().createEmpty(0)),
diff --git a/baremaps-flatgeobuf/pom.xml b/baremaps-flatgeobuf/pom.xml
index 62ccbf84e..c909939ae 100644
--- a/baremaps-flatgeobuf/pom.xml
+++ b/baremaps-flatgeobuf/pom.xml
@@ -34,10 +34,6 @@ limitations under the License.
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-store</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
diff --git a/baremaps-geoparquet/pom.xml b/baremaps-geoparquet/pom.xml
index 9b5629792..7f777195a 100644
--- a/baremaps-geoparquet/pom.xml
+++ b/baremaps-geoparquet/pom.xml
@@ -33,10 +33,6 @@ limitations under the License.
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-store</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
diff --git a/baremaps-openstreetmap/pom.xml b/baremaps-openstreetmap/pom.xml
index b0e59d3fd..8cffc1937 100644
--- a/baremaps-openstreetmap/pom.xml
+++ b/baremaps-openstreetmap/pom.xml
@@ -30,10 +30,6 @@ limitations under the License.
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-store</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
diff --git a/baremaps-postgres/pom.xml b/baremaps-postgres/pom.xml
index fedae8ce5..5d289d65c 100644
--- a/baremaps-postgres/pom.xml
+++ b/baremaps-postgres/pom.xml
@@ -43,10 +43,6 @@ limitations under the License.
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-openstreetmap</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-store</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
diff --git a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresTypeConversion.java b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresTypeConversion.java
deleted file mode 100644
index eae52d969..000000000
--- a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresTypeConversion.java
+++ /dev/null
@@ -1,72 +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.postgres.store;
-
-import java.util.EnumMap;
-import java.util.Map;
-import org.apache.baremaps.store.DataColumn.ColumnType;
-
-@SuppressWarnings("squid:S1192")
-public class PostgresTypeConversion {
-
- private PostgresTypeConversion() {
- // Prevent instantiation
- }
-
- protected static final Map<ColumnType, String> typeToName = new EnumMap<>(ColumnType.class);
-
- static {
- typeToName.put(ColumnType.STRING, "varchar");
- typeToName.put(ColumnType.SHORT, "int2");
- typeToName.put(ColumnType.INTEGER, "int4");
- typeToName.put(ColumnType.LONG, "int8");
- typeToName.put(ColumnType.FLOAT, "float4");
- typeToName.put(ColumnType.DOUBLE, "float8");
- typeToName.put(ColumnType.GEOMETRY, "geometry");
- typeToName.put(ColumnType.POINT, "geometry");
- typeToName.put(ColumnType.MULTIPOINT, "geometry");
- typeToName.put(ColumnType.LINESTRING, "geometry");
- typeToName.put(ColumnType.MULTILINESTRING, "geometry");
- typeToName.put(ColumnType.POLYGON, "geometry");
- typeToName.put(ColumnType.MULTIPOLYGON, "geometry");
- typeToName.put(ColumnType.GEOMETRYCOLLECTION, "geometry");
- typeToName.put(ColumnType.ENVELOPE, "geometry");
- typeToName.put(ColumnType.INET_ADDRESS, "inet");
- typeToName.put(ColumnType.INET4_ADDRESS, "inet");
- typeToName.put(ColumnType.INET6_ADDRESS, "inet");
- typeToName.put(ColumnType.LOCAL_DATE, "date");
- typeToName.put(ColumnType.LOCAL_TIME, "time");
- typeToName.put(ColumnType.LOCAL_DATE_TIME, "timestamp");
- typeToName.put(ColumnType.NESTED, "jsonb");
- }
-
- protected static final Map<String, ColumnType> nameToType = Map.ofEntries(
- Map.entry("varchar", ColumnType.STRING),
- Map.entry("int2", ColumnType.SHORT),
- Map.entry("int4", ColumnType.INTEGER),
- Map.entry("int8", ColumnType.LONG),
- Map.entry("float4", ColumnType.FLOAT),
- Map.entry("float8", ColumnType.DOUBLE),
- Map.entry("geometry", ColumnType.GEOMETRY),
- Map.entry("inet", ColumnType.INET6_ADDRESS),
- Map.entry("date", ColumnType.LOCAL_DATE),
- Map.entry("time", ColumnType.LOCAL_TIME),
- Map.entry("timestamp", ColumnType.LOCAL_DATE_TIME),
- Map.entry("jsonb", ColumnType.NESTED));
-
-}
diff --git a/baremaps-rpsl/pom.xml b/baremaps-rpsl/pom.xml
index f4ec32915..322ca3eaf 100644
--- a/baremaps-rpsl/pom.xml
+++ b/baremaps-rpsl/pom.xml
@@ -29,10 +29,6 @@ limitations under the License.
<groupId>net.ripe.ipresource</groupId>
<artifactId>ipresource</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-store</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
diff --git a/baremaps-shapefile/pom.xml b/baremaps-shapefile/pom.xml
index 0ff71c6f0..0a3d081a7 100644
--- a/baremaps-shapefile/pom.xml
+++ b/baremaps-shapefile/pom.xml
@@ -25,14 +25,14 @@ limitations under the License.
<artifactId>baremaps-shapefile</artifactId>
<name>Apache Baremaps Shapefile</name>
<dependencies>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-store</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.locationtech.jts</groupId>
+ <artifactId>jts-core</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/DbaseByteReader.java b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/DbaseByteReader.java
index 4b0d41154..aa830c063 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/DbaseByteReader.java
+++ b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/DbaseByteReader.java
@@ -27,7 +27,6 @@ import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.text.MessageFormat;
import java.util.*;
-import org.apache.baremaps.store.DataRow;
/**
* Reader of a Database Binary content.
@@ -106,7 +105,7 @@ public class DbaseByteReader extends CommonByteReader implements AutoCloseable {
*
* @param row Feature to fill.
*/
- public void loadRow(DataRow row) {
+ public void loadRow(List<Object> row) {
// TODO: ignore deleted records
getByteBuffer().get(); // denotes whether deleted or current
// read first part of record
@@ -143,7 +142,7 @@ public class DbaseByteReader extends CommonByteReader implements AutoCloseable {
case DATE_TIME -> value;
};
- row.set(fieldDescriptor.getName(), object);
+ row.add(object);
}
}
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileByteReader.java b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileByteReader.java
index ac6de721a..888b20c3c 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileByteReader.java
+++ b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileByteReader.java
@@ -24,9 +24,6 @@ import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.*;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.ColumnType;
import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateList;
@@ -51,9 +48,6 @@ public class ShapefileByteReader extends CommonByteReader {
/** Database Field descriptors. */
private List<DBaseFieldDescriptor> databaseFieldsDescriptors;
- /** Schema of the rows contained in this shapefile. */
- private DataSchema schema;
-
/** Shapefile index. */
private File shapeFileIndex;
@@ -87,7 +81,7 @@ public class ShapefileByteReader extends CommonByteReader {
loadShapefileIndexes();
}
- this.schema = getSchema(shapefile.getName());
+ // this.schema = getSchema(shapefile.getName());
}
/**
@@ -113,9 +107,9 @@ public class ShapefileByteReader extends CommonByteReader {
*
* @return the schema
*/
- public DataSchema getSchema() {
- return this.schema;
- }
+ // public DataSchema getSchema() {
+ // return this.schema;
+ // }
/**
* Create a row descriptor.
@@ -123,40 +117,40 @@ public class ShapefileByteReader extends CommonByteReader {
* @param name Name of the field.
* @return The schema.
*/
- private DataSchema getSchema(final String name) {
- Objects.requireNonNull(name, "The row name cannot be null.");
-
- var columns = new ArrayList<DataColumn>();
- for (int i = 0; i < databaseFieldsDescriptors.size(); i++) {
- var fieldDescriptor = this.databaseFieldsDescriptors.get(i);
- var columnName = fieldDescriptor.getName();
- var columnType = switch (fieldDescriptor.getType()) {
- case CHARACTER -> ColumnType.STRING;
- case NUMBER -> fieldDescriptor.getDecimalCount() == 0 ? ColumnType.LONG : ColumnType.DOUBLE;
- case CURRENCY -> ColumnType.DOUBLE;
- case DOUBLE -> ColumnType.DOUBLE;
- case INTEGER -> ColumnType.INTEGER;
- case AUTO_INCREMENT -> ColumnType.INTEGER;
-
- // TODO: Implement the following types
- case LOGICAL -> ColumnType.STRING;
- case DATE -> ColumnType.STRING;
- case MEMO -> ColumnType.STRING;
- case FLOATING_POINT -> ColumnType.STRING;
- case PICTURE -> ColumnType.STRING;
- case VARI_FIELD -> ColumnType.STRING;
- case VARIANT -> ColumnType.STRING;
- case TIMESTAMP -> ColumnType.STRING;
- case DATE_TIME -> ColumnType.STRING;
- };
- columns.add(new DataColumnFixed(columnName, Cardinality.OPTIONAL, columnType));
- }
-
- // Add geometry column.
- columns.add(new DataColumnFixed(GEOMETRY_NAME, Cardinality.OPTIONAL, ColumnType.GEOMETRY));
-
- return new DataSchemaImpl(name, columns);
- }
+ // private DataSchema getSchema(final String name) {
+ // Objects.requireNonNull(name, "The row name cannot be null.");
+ //
+ // var columns = new ArrayList<DataColumn>();
+ // for (int i = 0; i < databaseFieldsDescriptors.size(); i++) {
+ // var fieldDescriptor = this.databaseFieldsDescriptors.get(i);
+ // var columnName = fieldDescriptor.getName();
+ // var columnType = switch (fieldDescriptor.getType()) {
+ // case CHARACTER -> ColumnType.STRING;
+ // case NUMBER -> fieldDescriptor.getDecimalCount() == 0 ? ColumnType.LONG : ColumnType.DOUBLE;
+ // case CURRENCY -> ColumnType.DOUBLE;
+ // case DOUBLE -> ColumnType.DOUBLE;
+ // case INTEGER -> ColumnType.INTEGER;
+ // case AUTO_INCREMENT -> ColumnType.INTEGER;
+ //
+ // // TODO: Implement the following types
+ // case LOGICAL -> ColumnType.STRING;
+ // case DATE -> ColumnType.STRING;
+ // case MEMO -> ColumnType.STRING;
+ // case FLOATING_POINT -> ColumnType.STRING;
+ // case PICTURE -> ColumnType.STRING;
+ // case VARI_FIELD -> ColumnType.STRING;
+ // case VARIANT -> ColumnType.STRING;
+ // case TIMESTAMP -> ColumnType.STRING;
+ // case DATE_TIME -> ColumnType.STRING;
+ // };
+ // columns.add(new DataColumnFixed(columnName, Cardinality.OPTIONAL, columnType));
+ // }
+ //
+ // // Add geometry column.
+ // columns.add(new DataColumnFixed(GEOMETRY_NAME, Cardinality.OPTIONAL, ColumnType.GEOMETRY));
+ //
+ // return new DataSchemaImpl(name, columns);
+ // }
/** Load shapefile descriptor. */
private void loadDescriptor() {
@@ -255,7 +249,7 @@ public class ShapefileByteReader extends CommonByteReader {
*
* @param row the row to complete
*/
- public void completeRow(DataRow row) throws ShapefileException {
+ public void completeRow(List<Object> row) throws ShapefileException {
// insert points into some type of list
getByteBuffer().getInt(); // record number
getByteBuffer().getInt(); // content length
@@ -299,8 +293,8 @@ public class ShapefileByteReader extends CommonByteReader {
*
* @param row the row to fill.
*/
- private void loadNullRow(DataRow row) {
- row.set(GEOMETRY_NAME, null);
+ private void loadNullRow(List<Object> row) {
+ row.add(null);
}
/**
@@ -308,11 +302,11 @@ public class ShapefileByteReader extends CommonByteReader {
*
* @param row the row to fill.
*/
- private void loadPointRow(DataRow row) {
+ private void loadPointRow(List<Object> row) {
double x = getByteBuffer().getDouble();
double y = getByteBuffer().getDouble();
Point pnt = geometryFactory.createPoint(new Coordinate(x, y));
- row.set(GEOMETRY_NAME, pnt);
+ row.add(pnt);
}
/**
@@ -320,7 +314,7 @@ public class ShapefileByteReader extends CommonByteReader {
*
* @param row the row to fill.
*/
- private void loadPolygonRow(DataRow row) {
+ private void loadPolygonRow(List<Object> row) {
/* double xmin = */ getByteBuffer().getDouble();
/* double ymin = */ getByteBuffer().getDouble();
/* double xmax = */ getByteBuffer().getDouble();
@@ -331,7 +325,7 @@ public class ShapefileByteReader extends CommonByteReader {
Geometry multiPolygon = readMultiplePolygon(numParts, numPoints);
- row.set(GEOMETRY_NAME, multiPolygon);
+ row.add(multiPolygon);
}
/**
@@ -396,7 +390,7 @@ public class ShapefileByteReader extends CommonByteReader {
*
* @param row the row to fill.
*/
- private void loadPolylineRow(DataRow row) {
+ private void loadPolylineRow(List<Object> row) {
/* double xmin = */ getByteBuffer().getDouble();
/* double ymin = */ getByteBuffer().getDouble();
/* double xmax = */ getByteBuffer().getDouble();
@@ -429,7 +423,6 @@ public class ShapefileByteReader extends CommonByteReader {
}
}
- row.set(GEOMETRY_NAME,
- geometryFactory.createLineString(coordinates.toCoordinateArray()));
+ row.add(geometryFactory.createLineString(coordinates.toCoordinateArray()));
}
}
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileInputStream.java b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileInputStream.java
index ba4030819..d83d1306b 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileInputStream.java
+++ b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileInputStream.java
@@ -22,9 +22,8 @@ package org.apache.baremaps.shapefile;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.List;
-import org.apache.baremaps.store.DataRow;
-import org.apache.baremaps.store.DataSchema;
/**
* Input Stream of features.
@@ -52,7 +51,7 @@ public class ShapefileInputStream extends InputStream {
private boolean hasShapefileIndex;
/** Row type of the features contained in this shapefile. */
- private DataSchema schema;
+ // private DataSchema schema;
/** Shapefile reader. */
private ShapefileByteReader shapefileReader;
@@ -79,7 +78,6 @@ public class ShapefileInputStream extends InputStream {
this.shapefileReader =
new ShapefileByteReader(this.shapefile, this.databaseFile, this.shapefileIndex);
- this.schema = this.shapefileReader.getSchema();
}
/**
@@ -125,11 +123,11 @@ public class ShapefileInputStream extends InputStream {
* @throws ShapefileException if the current connection used to query the shapefile has been
* closed.
*/
- public DataRow readRow() throws ShapefileException {
+ public List<Object> readRow() throws ShapefileException {
if (!this.dbaseReader.nextRowAvailable()) {
return null;
}
- DataRow row = this.schema.createRow();
+ List<Object> row = new ArrayList<>();
this.dbaseReader.loadRow(row);
this.shapefileReader.setRowNum(this.dbaseReader.getRowNum());
this.shapefileReader.completeRow(row);
@@ -141,9 +139,9 @@ public class ShapefileInputStream extends InputStream {
*
* @return the schema.
*/
- public DataSchema schema() {
- return schema;
- }
+ // public DataSchema schema() {
+ // return schema;
+ // }
/**
* Returns the shapefile descriptor.
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileReader.java b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileReader.java
index 777411241..24b77ea10 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileReader.java
+++ b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileReader.java
@@ -23,7 +23,6 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
-import org.apache.baremaps.store.DataSchema;
/**
* Provides a ShapeFile Reader.
@@ -48,9 +47,6 @@ public class ShapefileReader {
/** Shapefile index, if any. */
private File shapeFileIndex;
- /** Type of the features contained in this shapefile. */
- private DataSchema schema;
-
/** Shapefile descriptor. */
private ShapefileDescriptor shapefileDescriptor;
@@ -117,15 +113,6 @@ public class ShapefileReader {
this.shapeFileIndex = new File(shpfileIndex);
}
- /**
- * Return the schema.
- *
- * @return the schema.
- */
- public DataSchema schema() {
- return this.schema;
- }
-
/**
* Returns the shapefile descriptor.
*
@@ -179,7 +166,6 @@ public class ShapefileReader {
public ShapefileInputStream read() throws IOException {
ShapefileInputStream is =
new ShapefileInputStream(this.shapefile, this.databaseFile, this.shapeFileIndex);
- this.schema = is.schema();
this.shapefileDescriptor = is.getShapefileDescriptor();
this.databaseFieldsDescriptors = is.getDatabaseFieldsDescriptors();
return is;
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataRow.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataRow.java
deleted file mode 100644
index e3a91f252..000000000
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataRow.java
+++ /dev/null
@@ -1,96 +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.store;
-
-import java.util.List;
-
-/**
- * A row in a {@link DataTable}.
- */
-public interface DataRow {
-
- /**
- * Returns the schema of the row.
- *
- * @return the schema of the row
- */
- DataSchema schema();
-
- /**
- * Returns the values of the columns in the row.
- *
- * @return the values of the columns in the row
- */
- List<Object> values();
-
- /**
- * Returns the value of the specified column.
- *
- * @param column the column
- * @return the value of the specified column
- */
- Object get(String column);
-
- /**
- * Returns the value of the specified column.
- *
- * @param index the index of the column
- * @return the value of the specified column
- */
- Object get(int index);
-
- /**
- * Sets the value of the specified column.
- *
- * @param column the column
- * @param value the value
- */
- void set(String column, Object value);
-
- /**
- * Sets the value of the specified column.
- *
- * @param index the index of the column
- * @param value the value
- */
- void set(int index, Object value);
-
- /**
- * Sets the value of the specified column and returns the row.
- *
- * @param column the column
- * @param value the value
- * @return the row
- */
- default 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
- */
- default DataRow with(int index, Object value) {
- set(index, value);
- return this;
- }
-}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchemaImpl.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchemaImpl.java
deleted file mode 100644
index 302dc7c00..000000000
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchemaImpl.java
+++ /dev/null
@@ -1,41 +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.store;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A {@link DataSchema} defines the structure of a table.
- */
-public record DataSchemaImpl(String name,
- List<DataColumn> columns) implements DataSchema, Serializable {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public DataRow createRow() {
- var values = new ArrayList<>(columns.size());
- for (int i = 0; i < columns.size(); i++) {
- values.add(null);
- }
- return new DataRowImpl(this, values);
- }
-}
diff --git a/pom.xml b/pom.xml
index 5ea81176b..a2af58698 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,11 +51,9 @@ limitations under the License.
<module>baremaps-calcite</module>
<module>baremaps-cli</module>
<module>baremaps-core</module>
- <module>baremaps-csv</module>
<module>baremaps-data</module>
<module>baremaps-dem</module>
<module>baremaps-flatgeobuf</module>
- <module>baremaps-geopackage</module>
<module>baremaps-geoparquet</module>
<module>baremaps-maplibre</module>
<module>baremaps-openstreetmap</module>
@@ -64,7 +62,6 @@ limitations under the License.
<module>baremaps-rpsl</module>
<module>baremaps-server</module>
<module>baremaps-shapefile</module>
- <module>baremaps-store</module>
<module>baremaps-testing</module>
</modules>
@@ -258,17 +255,17 @@ limitations under the License.
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-cli</artifactId>
+ <artifactId>baremaps-calcite</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-core</artifactId>
+ <artifactId>baremaps-cli</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-csv</artifactId>
+ <artifactId>baremaps-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
@@ -286,11 +283,6 @@ limitations under the License.
<artifactId>baremaps-flatgeobuf</artifactId>
<version>${project.parent.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-geopackage</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-geoparquet</artifactId>
@@ -331,11 +323,6 @@ limitations under the License.
<artifactId>baremaps-shapefile</artifactId>
<version>${project.parent.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.baremaps</groupId>
- <artifactId>baremaps-store</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
(incubator-baremaps) 05/12: Make data collection closeable
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit d3383d1a56dd4100524ee5513e3a3e3bf82c3b6f
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sat Jan 18 14:27:09 2025 +0100
Make data collection closeable
---
.../main/java/org/apache/baremaps/data/collection/DataCollection.java | 1 +
.../java/org/apache/baremaps/data/collection/DataCollectionMapper.java | 1 +
.../main/java/org/apache/baremaps/data/collection/DataConversions.java | 2 ++
3 files changed, 4 insertions(+)
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollection.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollection.java
index 5c5f549f6..c4458d180 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollection.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollection.java
@@ -17,6 +17,7 @@
package org.apache.baremaps.data.collection;
+import java.io.Closeable;
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollectionMapper.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollectionMapper.java
index 9ab9101c4..9cca2c1ca 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollectionMapper.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataCollectionMapper.java
@@ -18,6 +18,7 @@
package org.apache.baremaps.data.collection;
+import java.io.IOException;
import java.util.Iterator;
import java.util.function.Function;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataConversions.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataConversions.java
index 8f1957c16..d431ca77b 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataConversions.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/DataConversions.java
@@ -17,6 +17,8 @@
package org.apache.baremaps.data.collection;
+import java.io.Closeable;
+import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
(incubator-baremaps) 06/12: Refactor the sub modules
Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch calcite-framework
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit ae41449ac8e0de0f32e06d7a1c720fae7c9492da
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Tue Jan 21 08:42:41 2025 +0100
Refactor the sub modules
---
baremaps-calcite/pom.xml | 49 +++++++++
.../org/apache/baremaps/calcite/BaremapsTable.java | 113 +++++++++++++++++++++
.../baremaps/calcite/BaremapsTableFactory.java | 53 ++++++++++
.../com/apache/baremaps}/calcite/CalciteTest.java | 102 ++++++++++++++-----
.../apache/baremaps/geocoder/DataRowMapper.java | 3 +-
.../apache/baremaps/tasks/ImportGeoPackage.java | 26 ++---
.../org/apache/baremaps/calcite/CalciteTest.java | 51 +++++-----
.../java/org/apache/baremaps/csv/CsvDataStore.java | 2 +-
.../java/org/apache/baremaps/csv/CsvDataTable.java | 77 +++++++++-----
.../baremaps/csv/CsvDataTableGeonamesTest.java | 29 +-----
.../org/apache/baremaps/csv/CsvDataTableTest.java | 45 +++-----
.../baremaps/data/calcite/SqlDataSchema.java | 38 -------
.../apache/baremaps/data/calcite/SqlDataTable.java | 65 ------------
.../baremaps/data/calcite/SqlTypeConversion.java | 69 -------------
.../data/collection/FixedSizeDataList.java | 1 +
.../baremaps/data/collection/IndexedDataList.java | 1 +
.../apache/baremaps/data/store/DataStoreImpl.java | 59 +++++++++++
.../{BaremapsDataTable.java => DataTableImpl.java} | 24 ++++-
.../org/apache/baremaps/data/type/DataType.java | 1 +
.../type/{RowDataType.java => DataTypeImpl.java} | 47 ++++-----
.../baremaps/data/type/DataTypeProvider.java | 39 +++----
.../baremaps/flatgeobuf/FlatGeoBufDataTable.java | 41 ++++----
.../flatgeobuf/FlatGeoBufTypeConversion.java | 23 ++---
.../baremaps/geopackage/GeoPackageDataTable.java | 16 ++-
.../baremaps/geoparquet/GeoParquetDataTable.java | 8 ++
.../baremaps/geoparquet/GeoParquetReader.java | 8 +-
.../baremaps/geoparquet/GeoParquetSpliterator.java | 1 +
.../geoparquet/GeoParquetTypeConversion.java | 20 ++--
baremaps-openstreetmap/pom.xml | 5 +
.../openstreetmap/OpenStreetMapDataTable.java | 24 +++--
...> EntityDataColumnTypeGeometryBuilderTest.java} | 2 +-
.../baremaps/postgres/store/PostgresDataStore.java | 4 +-
.../baremaps/postgres/store/PostgresDataTable.java | 5 +
.../postgres/store/PostgresTypeConversion.java | 74 +++++++-------
.../apache/baremaps/postgres/MockDataTable.java | 17 ++--
.../org/apache/baremaps/rpsl/RpslDataTable.java | 35 ++++---
.../baremaps/shapefile/ShapefileByteReader.java | 34 +++----
.../baremaps/shapefile/ShapefileDataTable.java | 24 ++++-
.../apache/baremaps/shapefile/ShapefileReader.java | 1 -
baremaps-store/pom.xml | 10 ++
.../java/org/apache/baremaps/store/DataColumn.java | 14 +--
.../org/apache/baremaps/store/DataColumnFixed.java | 3 +-
.../apache/baremaps/store/DataColumnNested.java | 4 +-
.../java/org/apache/baremaps/store/DataSchema.java | 73 ++++++++++++-
.../org/apache/baremaps/store/DataSchemaImpl.java | 4 +-
.../java/org/apache/baremaps/store/DataTable.java | 2 +-
.../org/apache/baremaps/store/DataTableMapper.java | 4 +
pom.xml | 1 +
48 files changed, 823 insertions(+), 528 deletions(-)
diff --git a/baremaps-calcite/pom.xml b/baremaps-calcite/pom.xml
new file mode 100644
index 000000000..3653d0f69
--- /dev/null
+++ b/baremaps-calcite/pom.xml
@@ -0,0 +1,49 @@
+<?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.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>baremaps-calcite</artifactId>
+
+ <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>org.apache.baremaps</groupId>
+ <artifactId>baremaps-csv</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.baremaps</groupId>
+ <artifactId>baremaps-data</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>
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTable.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTable.java
new file mode 100644
index 000000000..1d7caf7a4
--- /dev/null
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTable.java
@@ -0,0 +1,113 @@
+/*
+ * 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 java.util.EnumMap;
+import org.apache.baremaps.store.DataColumn;
+import org.apache.baremaps.store.DataColumn.ColumnType;
+import org.apache.baremaps.store.DataTable;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.schema.ScannableTable;
+import org.apache.calcite.schema.impl.AbstractTable;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.locationtech.jts.geom.*;
+
+public class BaremapsTable extends AbstractTable implements ScannableTable {
+
+ private static final EnumMap<ColumnType, RelDataType> types = new EnumMap<>(ColumnType.class);
+
+ static {
+ types.put(ColumnType.BYTE, new JavaTypeFactoryImpl()
+ .createSqlType(SqlTypeName.TINYINT));
+ types.put(ColumnType.BOOLEAN, new JavaTypeFactoryImpl()
+ .createSqlType(SqlTypeName.BOOLEAN));
+ types.put(ColumnType.SHORT, new JavaTypeFactoryImpl()
+ .createSqlType(SqlTypeName.SMALLINT));
+ types.put(ColumnType.INTEGER, new JavaTypeFactoryImpl()
+ .createSqlType(SqlTypeName.INTEGER));
+ types.put(ColumnType.LONG, new JavaTypeFactoryImpl()
+ .createSqlType(SqlTypeName.BIGINT));
+ types.put(ColumnType.FLOAT, new JavaTypeFactoryImpl()
+ .createSqlType(SqlTypeName.FLOAT));
+ types.put(ColumnType.DOUBLE, new JavaTypeFactoryImpl()
+ .createSqlType(SqlTypeName.DOUBLE));
+ types.put(ColumnType.STRING, new JavaTypeFactoryImpl()
+ .createSqlType(SqlTypeName.VARCHAR));
+ types.put(ColumnType.GEOMETRY, new JavaTypeFactoryImpl()
+ .createJavaType(Geometry.class));
+ types.put(ColumnType.POINT, new JavaTypeFactoryImpl()
+ .createJavaType(Point.class));
+ types.put(ColumnType.LINESTRING, new JavaTypeFactoryImpl()
+ .createJavaType(LineString.class));
+ types.put(ColumnType.POLYGON, new JavaTypeFactoryImpl()
+ .createJavaType(Polygon.class));
+ types.put(ColumnType.MULTIPOINT, new JavaTypeFactoryImpl()
+ .createJavaType(MultiPoint.class));
+ types.put(ColumnType.MULTILINESTRING, new JavaTypeFactoryImpl()
+ .createJavaType(MultiLineString.class));
+ types.put(ColumnType.MULTIPOLYGON, new JavaTypeFactoryImpl()
+ .createJavaType(MultiPolygon.class));
+ types.put(ColumnType.GEOMETRYCOLLECTION, new JavaTypeFactoryImpl()
+ .createJavaType(GeometryCollection.class));
+ }
+
+ private final DataTable table;
+
+ private final RelProtoDataType protoRowType;
+
+ private RelDataType rowType;
+
+ public BaremapsTable(DataTable table) {
+ this.table = table;
+ this.protoRowType = null;
+ }
+
+ public BaremapsTable(DataTable table, RelProtoDataType protoRowType) {
+ this.table = table;
+ this.protoRowType = protoRowType;
+ }
+
+ @Override
+ public RelDataType getRowType(final RelDataTypeFactory typeFactory) {
+ if (rowType == null) {
+ rowType = createRowType(typeFactory);
+ }
+ return rowType;
+ }
+
+ private RelDataType createRowType(RelDataTypeFactory typeFactory) {
+ var rowTypeBuilder = new RelDataTypeFactory.Builder(typeFactory);
+ for (DataColumn column : table.schema().columns()) {
+ rowTypeBuilder.add(column.name(), types.get(column.type()));
+ }
+ return rowTypeBuilder.build();
+ }
+
+ @Override
+ public Enumerable<Object[]> scan(final DataContext root) {
+ return Linq4j.asEnumerable(() -> table.stream()
+ .map(row -> row.values().toArray())
+ .iterator());
+ }
+}
diff --git a/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
new file mode 100644
index 000000000..bd0c99b31
--- /dev/null
+++ b/baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsTableFactory.java
@@ -0,0 +1,53 @@
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.baremaps.csv.CsvDataTable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeImpl;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.TableFactory;
+
+public class BaremapsTableFactory implements TableFactory<BaremapsTable> {
+
+ public BaremapsTableFactory() {
+
+ }
+
+ @Override
+ public BaremapsTable create(SchemaPlus schema, String name,
+ Map<String, Object> operand, RelDataType rowType) {
+ final RelProtoDataType protoRowType =
+ rowType != null ? RelDataTypeImpl.proto(rowType) : null;
+ String file = (String) operand.get("file");
+ if (file != null && file.endsWith(".csv")) {
+ try {
+ return new BaremapsTable(
+ new CsvDataTable(new File(file), true),
+ protoRowType);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return new BaremapsTable(null, protoRowType);
+ }
+}
diff --git a/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java b/baremaps-calcite/src/test/java/com/apache/baremaps/calcite/CalciteTest.java
similarity index 72%
rename from baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
rename to baremaps-calcite/src/test/java/com/apache/baremaps/calcite/CalciteTest.java
index fd645d163..870263c8f 100644
--- a/baremaps-data/src/test/java/org/apache/baremaps/data/calcite/CalciteTest.java
+++ b/baremaps-calcite/src/test/java/com/apache/baremaps/calcite/CalciteTest.java
@@ -15,17 +15,20 @@
* limitations under the License.
*/
-package org.apache.baremaps.data.calcite;
+package com.apache.baremaps.calcite;
+import java.io.File;
+import java.io.PrintWriter;
import java.sql.*;
import java.util.*;
+import org.apache.baremaps.calcite.BaremapsTable;
import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.IndexedDataList;
-import org.apache.baremaps.data.store.BaremapsDataTable;
-import org.apache.baremaps.data.type.RowDataType;
+import org.apache.baremaps.data.store.DataTableImpl;
+import org.apache.baremaps.data.type.DataTypeImpl;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.apache.calcite.DataContext;
import org.apache.calcite.DataContexts;
import org.apache.calcite.interpreter.Interpreter;
@@ -43,6 +46,7 @@ import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.calcite.tools.Frameworks;
import org.apache.calcite.tools.Planner;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
@@ -50,6 +54,7 @@ import org.locationtech.jts.geom.GeometryFactory;
public class CalciteTest {
@Test
+ @Disabled
void sql() throws SQLException {
GeometryFactory geometryFactory = new GeometryFactory();
@@ -66,36 +71,36 @@ public class CalciteTest {
// Create and add 'city' table
DataSchema cityRowType = new DataSchemaImpl("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+ new DataColumnFixed("id", Cardinality.OPTIONAL, ColumnType.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, ColumnType.GEOMETRY)));
- DataTable cityDataTable = new BaremapsDataTable(
+ DataTable cityDataTable = new DataTableImpl(
cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType))));
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(cityRowType))));
cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
List.of(1, "Paris", geometryFactory.createPoint(new Coordinate(2.3522, 48.8566)))));
cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
- SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
- rootSchema.add("city", citySqlDataTable);
+ BaremapsTable cityBaremapsTable = new BaremapsTable(cityDataTable);
+ rootSchema.add("city", cityBaremapsTable);
// Create and add 'population' table
DataSchema populationRowType = new DataSchemaImpl("population", List.of(
- new DataColumnFixed("city_id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("population", Cardinality.OPTIONAL, Type.INTEGER)));
+ new DataColumnFixed("city_id", Cardinality.OPTIONAL, ColumnType.INTEGER),
+ new DataColumnFixed("population", Cardinality.OPTIONAL, ColumnType.INTEGER)));
- DataTable populationDataTable = new BaremapsDataTable(
+ DataTable populationDataTable = new DataTableImpl(
populationRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(populationRowType))));
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(populationRowType))));
populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(1, 2_161_000)));
populationDataTable.add(new DataRowImpl(populationDataTable.schema(), List.of(2, 8_336_000)));
- SqlDataTable populationSqlDataTable = new SqlDataTable(populationDataTable);
- rootSchema.add("population", populationSqlDataTable);
+ BaremapsTable populationBaremapsTable = new BaremapsTable(populationDataTable);
+ rootSchema.add("population", populationBaremapsTable);
// Create view 'city_population'
String mvSql = "SELECT c.id, c.name, c.geometry, p.population " +
@@ -181,6 +186,7 @@ public class CalciteTest {
}
@Test
+ @Disabled
void list() throws Exception {
// Initialize your Java lists
List<Integer> listA = List.of(1, 2, 3, 4, 5);
@@ -192,13 +198,13 @@ public class CalciteTest {
// Create and add 'city' table
DataSchema cityRowType = new DataSchemaImpl("city", List.of(
- new DataColumnFixed("id", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+ new DataColumnFixed("id", Cardinality.OPTIONAL, ColumnType.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, ColumnType.GEOMETRY)));
- DataTable cityDataTable = new BaremapsDataTable(
+ DataTable cityDataTable = new DataTableImpl(
cityRowType,
- new IndexedDataList<>(new AppendOnlyLog<>(new RowDataType(cityRowType))));
+ new IndexedDataList<>(new AppendOnlyLog<>(new DataTypeImpl(cityRowType))));
GeometryFactory geometryFactory = new GeometryFactory();
cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
@@ -206,8 +212,8 @@ public class CalciteTest {
cityDataTable.add(new DataRowImpl(cityDataTable.schema(),
List.of(2, "New York", geometryFactory.createPoint(new Coordinate(-74.0060, 40.7128)))));
- SqlDataTable citySqlDataTable = new SqlDataTable(cityDataTable);
- rootSchema.add("CITY", citySqlDataTable);
+ BaremapsTable cityBaremapsTable = new BaremapsTable(cityDataTable);
+ rootSchema.add("CITY", cityBaremapsTable);
// Configure the framework
FrameworkConfig config = Frameworks.newConfigBuilder()
@@ -232,7 +238,7 @@ public class CalciteTest {
Interpreter interpreter = new Interpreter(DataContexts.EMPTY, rel);
// Create an interpreter to execute the RelNode
- for (Object[] row : interpreter.asEnumerable()) {
+ for (Object[] row : interpreter) {
listB.add((Integer) row[0]);
}
@@ -241,4 +247,50 @@ public class CalciteTest {
System.out.println("List B (after SQL): " + listB);
}
+ @Test
+ public void testCsvStream() throws Exception {
+ File file = File.createTempFile("test", ".csv");
+ String csv = """
+ ID,NAME,GEOM
+ 1,Paris,POINT(2.3522 48.8566)
+ 2,New York,POINT(-74.0060 40.7128)
+ """;
+ try (PrintWriter writer = new PrintWriter(file)) {
+ writer.write(csv);
+ }
+
+ String model = """
+ {
+ version: '1.0',
+ defaultSchema: 'TEST',
+ schemas: [
+ {
+ name: 'TEST',
+ tables: [
+ {
+ name: 'TEST',
+ type: 'custom',
+ factory: 'org.apache.baremaps.calcite.BaremapsTableFactory',
+ operand: {
+ file: '%s'
+ }
+ }
+ ]
+ }
+ ]
+ }
+ """.formatted(file.getAbsolutePath());
+
+ try (Connection connection =
+ DriverManager.getConnection("jdbc:calcite:model=inline:" + model)) {
+
+ ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM TEST.TEST");
+ while (resultSet.next()) {
+ System.out.println(resultSet.getString("ID") + " " + resultSet.getString("GEOM"));
+ }
+ } finally {
+ file.delete();
+ }
+ }
+
}
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java
index df6227a98..2398d1d4a 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.apache.baremaps.store.DataColumn;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.apache.baremaps.store.DataRow;
import org.apache.baremaps.store.DataSchema;
import org.apache.lucene.document.*;
@@ -58,7 +59,7 @@ public class DataRowMapper implements Function<DataRow, Document> {
@SuppressWarnings("squid:S6541")
private void applyValue(DataColumn column, Document doc, Object value) {
String columnName = column.name();
- DataColumn.Type type = column.type();
+ ColumnType type = column.type();
try {
switch (type) {
case BINARY:
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoPackage.java b/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoPackage.java
index 93932f02e..47728e60d 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoPackage.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportGeoPackage.java
@@ -26,7 +26,6 @@ import org.apache.baremaps.store.DataTableGeometryMapper;
import org.apache.baremaps.store.DataTableMapper;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
-import org.apache.baremaps.workflow.WorkflowException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -71,20 +70,17 @@ public class ImportGeoPackage implements Task {
@Override
public void execute(WorkflowContext context) throws Exception {
var path = file.toAbsolutePath();
- try (var geoPackageDataStore = new GeoPackageDataStore(path)) {
- var dataSource = context.getDataSource(database);
- var postgresDataStore = new PostgresDataStore(dataSource);
- for (var name : geoPackageDataStore.list()) {
- var geoPackageTable = geoPackageDataStore.get(name);
- var projectionTransformer = new ProjectionTransformer(fileSrid, databaseSrid);
- var rowTransformer =
- new DataTableGeometryMapper(geoPackageTable, projectionTransformer);
- var transformedDataTable =
- new DataTableMapper(geoPackageDataStore.get(name), rowTransformer);
- postgresDataStore.add(transformedDataTable);
- }
- } catch (Exception e) {
- throw new WorkflowException(e);
+ var geoPackageDataStore = new GeoPackageDataStore(path);
+ var dataSource = context.getDataSource(database);
+ var postgresDataStore = new PostgresDataStore(dataSource);
+ for (var name : geoPackageDataStore.list()) {
+ var geoPackageTable = geoPackageDataStore.get(name);
+ var projectionTransformer = new ProjectionTransformer(fileSrid, databaseSrid);
+ var rowTransformer =
+ new DataTableGeometryMapper(geoPackageTable, projectionTransformer);
+ var transformedDataTable =
+ new DataTableMapper(geoPackageDataStore.get(name), rowTransformer);
+ postgresDataStore.add(transformedDataTable);
}
}
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java b/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index 482d15885..4c0067272 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
@@ -18,34 +18,33 @@
package org.apache.baremaps.calcite;
-import com.google.common.collect.ImmutableList;
-import java.sql.*;
-import java.util.List;
-import java.util.Properties;
-import org.apache.baremaps.data.calcite.SqlDataTable;
-import org.apache.baremaps.data.collection.AppendOnlyLog;
-import org.apache.baremaps.data.collection.IndexedDataList;
-import org.apache.baremaps.data.store.BaremapsDataTable;
-import org.apache.baremaps.data.type.RowDataType;
-import org.apache.baremaps.maplibre.vectortile.VectorTileFunctions;
-import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
-import org.apache.calcite.jdbc.CalciteConnection;
-import org.apache.calcite.model.ModelHandler;
-import org.apache.calcite.runtime.AccumOperation;
-import org.apache.calcite.runtime.CollectOperation;
-import org.apache.calcite.runtime.SpatialTypeFunctions;
-import org.apache.calcite.runtime.UnionOperation;
-import org.apache.calcite.schema.SchemaPlus;
-import org.apache.calcite.schema.impl.AggregateFunctionImpl;
-import org.apache.calcite.sql.fun.SqlSpatialTypeFunctions;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.locationtech.jts.geom.*;
+ import com.google.common.collect.ImmutableList;
+ import java.sql.*;
+ import java.util.List;
+ import java.util.Properties;
+ import org.apache.baremaps.data.calcite.BaremapsTable;
+ import org.apache.baremaps.data.collection.AppendOnlyLog;
+ import org.apache.baremaps.data.collection.IndexedDataList;
+ import org.apache.baremaps.data.store.DataTableImpl;
+ import org.apache.baremaps.data.type.DataTypeImpl;
+ import org.apache.baremaps.maplibre.vectortile.VectorTileFunctions;
+ import org.apache.baremaps.store.*;
+ import org.apache.baremaps.store.DataColumn.Cardinality;
+ import org.apache.baremaps.store.DataColumn.Type;
+ import org.apache.calcite.jdbc.CalciteConnection;
+ import org.apache.calcite.model.ModelHandler;
+ import org.apache.calcite.runtime.AccumOperation;
+ import org.apache.calcite.runtime.CollectOperation;
+ import org.apache.calcite.runtime.SpatialTypeFunctions;
+ import org.apache.calcite.runtime.UnionOperation;
+ import org.apache.calcite.schema.SchemaPlus;
+ import org.apache.calcite.schema.impl.AggregateFunctionImpl;
+ import org.apache.calcite.sql.fun.SqlSpatialTypeFunctions;
+ import org.junit.jupiter.api.Assertions;
+ import org.junit.jupiter.api.Test;
+ import org.locationtech.jts.geom.*;
class CalciteTest {
-
@Test
void test() throws SQLException {
GeometryFactory geometryFactory = new GeometryFactory();
diff --git a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
index 1dfc85298..74abb32e3 100644
--- a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
+++ b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataStore.java
@@ -49,7 +49,7 @@ public class CsvDataStore implements DataStore {
char separator) throws IOException {
this.tableName = tableName;
this.schema = schema;
- this.dataTable = new CsvDataTable(schema, csvFile, hasHeader, separator);
+ this.dataTable = new CsvDataTable(csvFile, hasHeader);
}
/**
diff --git a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
index 845e54e93..360debfae 100644
--- a/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
+++ b/baremaps-csv/src/main/java/org/apache/baremaps/csv/CsvDataTable.java
@@ -27,6 +27,8 @@ import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.apache.baremaps.store.*;
+import org.apache.baremaps.store.DataColumn.Cardinality;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.locationtech.jts.io.WKTReader;
/**
@@ -34,43 +36,57 @@ import org.locationtech.jts.io.WKTReader;
*/
public class CsvDataTable implements DataTable {
- private final DataSchema schema;
private final File csvFile;
private final CsvSchema csvSchema;
+ private final DataSchema dataSchema;
+
private final long size;
+ private JsonParser parser;
/**
* Constructs a CsvDataTable with the specified schema, CSV file, header presence, and separator.
*
- * @param schema the data schema defining the structure
* @param csvFile the CSV file to read data from
* @param hasHeader whether the CSV file includes a header row
- * @param separator the character used to separate columns in the CSV file
* @throws IOException if an I/O error occurs
*/
- public CsvDataTable(DataSchema schema, File csvFile, boolean hasHeader, char separator)
- throws IOException {
- this.schema = schema;
+ public CsvDataTable(File csvFile, boolean hasHeader) throws IOException {
this.csvFile = csvFile;
- this.csvSchema = buildCsvSchema(schema, hasHeader, separator);
+ this.csvSchema = inferCsvSchema(csvFile);
+ this.dataSchema = createDataSchema(csvFile.getName(), csvSchema);
this.size = calculateSize();
}
- /**
- * Builds the CsvSchema for Jackson based on the provided DataSchema, header presence, and
- * separator.
- *
- * @param dataSchema the data schema
- * @param hasHeader whether the CSV file includes a header row
- * @param separator the character used to separate columns
- * @return the CsvSchema for Jackson
- */
- private CsvSchema buildCsvSchema(DataSchema dataSchema, boolean hasHeader, char separator) {
- CsvSchema.Builder builder = CsvSchema.builder();
- for (DataColumn column : dataSchema.columns()) {
- builder.addColumn(column.name());
+
+ private CsvSchema inferCsvSchema(File csvFile) {
+ CsvSchema csvSchema = CsvSchema.emptySchema().withUseHeader(true).withColumnSeparator(',');
+ try (var ignored = new CsvMapper().readerFor(Map.class)
+ .with(csvSchema)
+ .createParser(csvFile)) {
+ var test = ignored.readValueAsTree();
+ return csvSchema;
+ } catch (IOException e) {
+ throw new DataStoreException("Error reading CSV file", e);
+ }
+ }
+
+ private DataSchema createDataSchema(String name, CsvSchema csvSchema) {
+ List<DataColumn> columns = new ArrayList<>();
+ for (String columnName : csvSchema.getColumnNames()) {
+ switch (csvSchema.column(columnName).getType()) {
+ case STRING -> columns
+ .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.STRING));
+ case NUMBER -> columns
+ .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.DOUBLE));
+ case BOOLEAN -> columns
+ .add(new DataColumnFixed(columnName, Cardinality.REQUIRED, ColumnType.BOOLEAN));
+ case ARRAY -> columns
+ .add(new DataColumnFixed(columnName, Cardinality.REPEATED, ColumnType.STRING));
+ default -> throw new IllegalArgumentException(
+ "Unsupported column type: " + csvSchema.column(columnName).getType());
+ }
}
- return builder.setUseHeader(hasHeader).setColumnSeparator(separator).build();
+ return new DataSchemaImpl(name, columns);
}
/**
@@ -95,7 +111,7 @@ public class CsvDataTable implements DataTable {
@Override
public DataSchema schema() {
- return schema;
+ return dataSchema;
}
@Override
@@ -117,7 +133,7 @@ public class CsvDataTable implements DataTable {
public Iterator<DataRow> iterator() {
try {
CsvMapper csvMapper = new CsvMapper();
- JsonParser parser = csvMapper.readerFor(Map.class)
+ parser = csvMapper.readerFor(Map.class)
.with(csvSchema)
.createParser(csvFile);
@@ -134,10 +150,10 @@ public class CsvDataTable implements DataTable {
@Override
public DataRow next() {
Map<String, String> csvRow = csvIterator.next();
- DataRow dataRow = schema.createRow();
+ DataRow dataRow = dataSchema.createRow();
- for (int i = 0; i < schema.columns().size(); i++) {
- DataColumn column = schema.columns().get(i);
+ for (int i = 0; i < dataSchema.columns().size(); i++) {
+ DataColumn column = dataSchema.columns().get(i);
String columnName = column.name();
String value = csvRow.get(columnName);
@@ -165,7 +181,7 @@ public class CsvDataTable implements DataTable {
* @return the parsed value
*/
private Object parseValue(DataColumn column, String value) {
- DataColumn.Type type = column.type();
+ ColumnType type = column.type();
try {
if (value == null || value.isEmpty()) {
return null;
@@ -198,4 +214,11 @@ public class CsvDataTable implements DataTable {
public Stream<DataRow> stream() {
return StreamSupport.stream(spliterator(), false);
}
+
+ @Override
+ public void close() throws IOException {
+ if (parser != null) {
+ parser.close();
+ }
+ }
}
diff --git a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
index 8bceebbc2..489634505 100644
--- a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
+++ b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableGeonamesTest.java
@@ -21,10 +21,7 @@ import static org.apache.baremaps.testing.TestFiles.GEONAMES_CSV;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
-import java.util.List;
import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
import org.junit.jupiter.api.*;
import org.locationtech.jts.geom.Point;
@@ -32,31 +29,7 @@ class CsvDataTableGeonamesTest {
@Test
void testGeonamesCsvDataTable() throws IOException {
- List<DataColumn> columns = List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("asciiname", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("alternatenames", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("latitude", Cardinality.OPTIONAL, Type.DOUBLE),
- new DataColumnFixed("longitude", Cardinality.OPTIONAL, Type.DOUBLE),
- new DataColumnFixed("feature_class", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("feature_code", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("country_code", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("cc2", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("admin1_code", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("admin2_code", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("admin3_code", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("admin4_code", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("population", Cardinality.OPTIONAL, Type.LONG),
- new DataColumnFixed("elevation", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("dem", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("timezone", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("modification_date", Cardinality.OPTIONAL, Type.STRING));
- DataSchema schema = new DataSchemaImpl("geonames", columns);
-
- boolean hasHeader = false;
- char separator = '\t';
- DataTable dataTable = new CsvDataTable(schema, GEONAMES_CSV.toFile(), hasHeader, separator);
+ DataTable dataTable = new CsvDataTable(GEONAMES_CSV.toFile(), false);
assertEquals(5, dataTable.size(), "DataTable should have 5 rows.");
diff --git a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
index cb38a516d..444b37996 100644
--- a/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
+++ b/baremaps-csv/src/test/java/org/apache/baremaps/csv/CsvDataTableTest.java
@@ -26,7 +26,7 @@ import java.nio.file.Path;
import java.util.List;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -58,12 +58,7 @@ class CsvDataTableTest {
2,PointB,"POINT(2 2)"
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
- List<DataColumn> columns = List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geom", Cardinality.OPTIONAL, Type.GEOMETRY));
- DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(schema, tempCsvFile, true, ',');
+ DataTable dataTable = new CsvDataTable(tempCsvFile, true);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -88,11 +83,11 @@ class CsvDataTableTest {
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
List<DataColumn> columns = List.of(
- new DataColumnFixed("column1", Cardinality.REQUIRED, Type.INTEGER),
- new DataColumnFixed("column2", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("column3", Cardinality.OPTIONAL, Type.GEOMETRY));
+ new DataColumnFixed("column1", Cardinality.REQUIRED, ColumnType.INTEGER),
+ new DataColumnFixed("column2", Cardinality.OPTIONAL, ColumnType.STRING),
+ new DataColumnFixed("column3", Cardinality.OPTIONAL, ColumnType.GEOMETRY));
DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(schema, tempCsvFile, false, ';');
+ DataTable dataTable = new CsvDataTable(tempCsvFile, false);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -121,12 +116,12 @@ class CsvDataTableTest {
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
List<DataColumn> columns = List.of(
- new DataColumnFixed("int_col", Cardinality.REQUIRED, Type.INTEGER),
- new DataColumnFixed("double_col", Cardinality.REQUIRED, Type.DOUBLE),
- new DataColumnFixed("bool_col", Cardinality.REQUIRED, Type.BOOLEAN),
- new DataColumnFixed("string_col", Cardinality.REQUIRED, Type.STRING));
+ new DataColumnFixed("int_col", Cardinality.REQUIRED, ColumnType.INTEGER),
+ new DataColumnFixed("double_col", Cardinality.REQUIRED, ColumnType.DOUBLE),
+ new DataColumnFixed("bool_col", Cardinality.REQUIRED, ColumnType.BOOLEAN),
+ new DataColumnFixed("string_col", Cardinality.REQUIRED, ColumnType.STRING));
DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(schema, tempCsvFile, true, ',');
+ DataTable dataTable = new CsvDataTable(tempCsvFile, true);
assertEquals(2, dataTable.size());
int rowCount = 0;
for (DataRow row : dataTable) {
@@ -153,10 +148,10 @@ class CsvDataTableTest {
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
List<DataColumn> columns = List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING));
+ new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.INTEGER),
+ new DataColumnFixed("name", Cardinality.OPTIONAL, ColumnType.STRING));
DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(schema, tempCsvFile, true, ',');
+ DataTable dataTable = new CsvDataTable(tempCsvFile, true);
assertThrows(RuntimeException.class, () -> {
for (DataRow row : dataTable) {
// This line should throw an exception because abc is not a valid integer
@@ -169,11 +164,7 @@ class CsvDataTableTest {
void testAddAndClearUnsupportedOperations() throws IOException {
String csvContent = "";
Files.writeString(tempCsvFile.toPath(), csvContent);
- List<DataColumn> columns = List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING));
- DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(schema, tempCsvFile, true, ',');
+ DataTable dataTable = new CsvDataTable(tempCsvFile, true);
assertThrows(UnsupportedOperationException.class, () -> dataTable.add(null));
assertThrows(UnsupportedOperationException.class, dataTable::clear);
}
@@ -187,11 +178,7 @@ class CsvDataTableTest {
3,Name3
""";
Files.writeString(tempCsvFile.toPath(), csvContent);
- List<DataColumn> columns = List.of(
- new DataColumnFixed("id", Cardinality.REQUIRED, Type.INTEGER),
- new DataColumnFixed("name", Cardinality.OPTIONAL, Type.STRING));
- DataSchema schema = new DataSchemaImpl("test_table", columns);
- DataTable dataTable = new CsvDataTable(schema, tempCsvFile, true, ',');
+ DataTable dataTable = new CsvDataTable(tempCsvFile, true);
assertEquals(3, dataTable.size());
}
}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataSchema.java b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataSchema.java
deleted file mode 100644
index 68651ae7e..000000000
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataSchema.java
+++ /dev/null
@@ -1,38 +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.calcite;
-
-import com.google.common.collect.ImmutableMap;
-import java.util.Map;
-import org.apache.calcite.schema.Table;
-import org.apache.calcite.schema.impl.AbstractSchema;
-
-public class SqlDataSchema extends AbstractSchema {
-
- private final Map<String, Table> tableMap;
-
- public SqlDataSchema(ImmutableMap<String, Table> tableMap) {
- this.tableMap = ImmutableMap.copyOf(tableMap);
- }
-
- @Override
- protected Map<String, Table> getTableMap() {
- return tableMap;
- }
-
-}
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
deleted file mode 100644
index 497ac237a..000000000
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.baremaps.data.calcite;
-
-import org.apache.baremaps.store.DataColumn;
-import org.apache.baremaps.store.DataTable;
-import org.apache.calcite.DataContext;
-import org.apache.calcite.linq4j.Enumerable;
-import org.apache.calcite.linq4j.Linq4j;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.schema.ScannableTable;
-import org.apache.calcite.schema.impl.AbstractTable;
-
-/**
- * A simple table based on a list.
- */
-public class SqlDataTable extends AbstractTable implements ScannableTable {
-
- private final DataTable table;
-
- private RelDataType rowType;
-
- public SqlDataTable(DataTable table) {
- this.table = table;
- }
-
- @Override
- public Enumerable<Object[]> scan(final DataContext root) {
- return Linq4j.asEnumerable(() -> table.stream()
- .map(row -> row.values().toArray())
- .iterator());
- }
-
- @Override
- public RelDataType getRowType(final RelDataTypeFactory typeFactory) {
- if (rowType == null) {
- rowType = createRowType(typeFactory);
- }
- return rowType;
- }
-
- private RelDataType createRowType(RelDataTypeFactory typeFactory) {
- var rowTypeBuilder = new RelDataTypeFactory.Builder(typeFactory);
- for (DataColumn column : table.schema().columns()) {
- rowTypeBuilder.add(column.name(), SqlTypeConversion.types.get(column.type()));
- }
- return rowTypeBuilder.build();
- }
-}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
deleted file mode 100644
index 1c320fa97..000000000
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
+++ /dev/null
@@ -1,69 +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.calcite;
-
-import java.util.EnumMap;
-import org.apache.baremaps.store.DataColumn.Type;
-import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.sql.type.SqlTypeName;
-import org.locationtech.jts.geom.*;
-
-public class SqlTypeConversion {
-
- static final EnumMap<Type, RelDataType> types = new EnumMap<>(Type.class);
-
- static {
- types.put(Type.BYTE, new JavaTypeFactoryImpl()
- .createSqlType(SqlTypeName.TINYINT));
- types.put(Type.BOOLEAN, new JavaTypeFactoryImpl()
- .createSqlType(SqlTypeName.BOOLEAN));
- types.put(Type.SHORT, new JavaTypeFactoryImpl()
- .createSqlType(SqlTypeName.SMALLINT));
- types.put(Type.INTEGER, new JavaTypeFactoryImpl()
- .createSqlType(SqlTypeName.INTEGER));
- types.put(Type.LONG, new JavaTypeFactoryImpl()
- .createSqlType(SqlTypeName.BIGINT));
- types.put(Type.FLOAT, new JavaTypeFactoryImpl()
- .createSqlType(SqlTypeName.FLOAT));
- types.put(Type.DOUBLE, new JavaTypeFactoryImpl()
- .createSqlType(SqlTypeName.DOUBLE));
- types.put(Type.STRING, new JavaTypeFactoryImpl()
- .createSqlType(SqlTypeName.VARCHAR));
- types.put(Type.GEOMETRY, new JavaTypeFactoryImpl()
- .createJavaType(Geometry.class));
- types.put(Type.POINT, new JavaTypeFactoryImpl()
- .createJavaType(Point.class));
- types.put(Type.LINESTRING, new JavaTypeFactoryImpl()
- .createJavaType(LineString.class));
- types.put(Type.POLYGON, new JavaTypeFactoryImpl()
- .createJavaType(Polygon.class));
- types.put(Type.MULTIPOINT, new JavaTypeFactoryImpl()
- .createJavaType(MultiPoint.class));
- types.put(Type.MULTILINESTRING, new JavaTypeFactoryImpl()
- .createJavaType(MultiLineString.class));
- types.put(Type.MULTIPOLYGON, new JavaTypeFactoryImpl()
- .createJavaType(MultiPolygon.class));
- types.put(Type.GEOMETRYCOLLECTION, new JavaTypeFactoryImpl()
- .createJavaType(GeometryCollection.class));
- }
-
- private SqlTypeConversion() {
- // Prevent instantiation
- }
-}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/FixedSizeDataList.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/FixedSizeDataList.java
index 5c7b57478..7ae4fc233 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/FixedSizeDataList.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/FixedSizeDataList.java
@@ -19,6 +19,7 @@ package org.apache.baremaps.data.collection;
+import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.baremaps.data.memory.Memory;
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataList.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataList.java
index 1a14640f5..d7427b37c 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataList.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataList.java
@@ -19,6 +19,7 @@ package org.apache.baremaps.data.collection;
+import java.io.IOException;
import org.apache.baremaps.data.type.LongDataType;
/**
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java b/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java
new file mode 100644
index 000000000..c866b1b41
--- /dev/null
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataStoreImpl.java
@@ -0,0 +1,59 @@
+/*
+ * 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.store;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.baremaps.store.*;
+
+public class DataStoreImpl implements DataStore {
+
+ private Map<String, DataTable> tables;
+
+ public DataStoreImpl(List<DataTable> tables) {
+ this.tables =
+ tables.stream().collect(Collectors.toMap(table -> table.schema().name(), table -> table));
+ }
+
+ @Override
+ public List<String> list() throws DataStoreException {
+ return new ArrayList<>(tables.keySet());
+ }
+
+ @Override
+ public DataTable get(String name) throws DataStoreException {
+ return tables.get(name);
+ }
+
+ @Override
+ public void add(DataTable table) throws DataStoreException {
+ tables.put(table.schema().name(), table);
+ }
+
+ @Override
+ public void add(String name, DataTable table) throws DataStoreException {
+ tables.put(name, table);
+ }
+
+ @Override
+ public void remove(String name) throws DataStoreException {
+ tables.remove(name);
+ }
+}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java b/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataTableImpl.java
similarity index 76%
rename from baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java
rename to baremaps-data/src/main/java/org/apache/baremaps/data/store/DataTableImpl.java
index 89123dab6..59c61d5d7 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/store/BaremapsDataTable.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/store/DataTableImpl.java
@@ -17,8 +17,11 @@
package org.apache.baremaps.data.store;
+import java.io.IOException;
import java.util.Iterator;
+import org.apache.baremaps.data.collection.AppendOnlyLog;
import org.apache.baremaps.data.collection.DataCollection;
+import org.apache.baremaps.data.type.DataTypeImpl;
import org.apache.baremaps.store.DataRow;
import org.apache.baremaps.store.DataSchema;
import org.apache.baremaps.store.DataTable;
@@ -26,7 +29,7 @@ import org.apache.baremaps.store.DataTable;
/**
* A {@link DataTable} is a collection of rows respecting a {@link DataSchema}.
*/
-public class BaremapsDataTable implements DataTable {
+public class DataTableImpl implements DataTable {
private final DataSchema schema;
@@ -38,11 +41,21 @@ public class BaremapsDataTable implements DataTable {
* @param schema the schema of the rows
* @param rows the rows
*/
- public BaremapsDataTable(DataSchema schema, DataCollection<DataRow> rows) {
+ public DataTableImpl(DataSchema schema, DataCollection<DataRow> rows) {
this.schema = schema;
this.rows = rows;
}
+ /**
+ * Constructs a {@link DataTable} with the specified row {@link DataSchema}.
+ *
+ * @param schema the schema of the rows
+ */
+ public DataTableImpl(DataSchema schema) {
+ this.schema = schema;
+ this.rows = new AppendOnlyLog<>(new DataTypeImpl(schema));
+ }
+
/**
* {@inheritDoc}
*/
@@ -75,12 +88,13 @@ public class BaremapsDataTable implements DataTable {
return rows.size();
}
- /**
- * {@inheritDoc}
- */
@Override
public Iterator<DataRow> iterator() {
return rows.iterator();
}
+ @Override
+ public void close() throws IOException {
+ rows.close();
+ }
}
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/type/DataType.java b/baremaps-data/src/main/java/org/apache/baremaps/data/type/DataType.java
index 26f9901b1..04ba184f4 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/type/DataType.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/type/DataType.java
@@ -63,4 +63,5 @@ public interface DataType<T> {
* @return the read value
*/
T read(final ByteBuffer buffer, final int position);
+
}
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/DataTypeImpl.java
similarity index 69%
rename from baremaps-data/src/main/java/org/apache/baremaps/data/type/RowDataType.java
rename to baremaps-data/src/main/java/org/apache/baremaps/data/type/DataTypeImpl.java
index a4ba70582..68490f496 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/DataTypeImpl.java
@@ -21,7 +21,7 @@ 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.DataColumn.ColumnType;
import org.apache.baremaps.store.DataRow;
import org.apache.baremaps.store.DataRowImpl;
import org.apache.baremaps.store.DataSchema;
@@ -29,41 +29,36 @@ import org.apache.baremaps.store.DataSchema;
/**
* A {@link DataType} for reading and writing {@link DataRow} objects in {@link ByteBuffer}s.
*/
-public class RowDataType implements DataType<DataRow> {
+public class DataTypeImpl implements DataType<DataRow> {
/**
* Map of data types for each of the supported column types.
*/
- private static final EnumMap<Type, DataType> types = new EnumMap<>(Type.class);
+ private static final EnumMap<ColumnType, DataType> types = new EnumMap<>(ColumnType.class);
static {
- types.put(Type.BYTE, new ByteDataType());
- types.put(Type.BOOLEAN, new BooleanDataType());
- types.put(Type.SHORT, new ShortDataType());
- types.put(Type.INTEGER, new IntegerDataType());
- types.put(Type.LONG, new LongDataType());
- types.put(Type.FLOAT, new FloatDataType());
- types.put(Type.DOUBLE, new DoubleDataType());
- types.put(Type.STRING, new StringDataType());
- types.put(Type.GEOMETRY, new GeometryDataType());
- types.put(Type.POINT, new PointDataType());
- types.put(Type.LINESTRING, new LineStringDataType());
- types.put(Type.POLYGON, new PolygonDataType());
- types.put(Type.MULTIPOINT, new MultiPointDataType());
- types.put(Type.MULTILINESTRING, new MultiLineStringDataType());
- types.put(Type.MULTIPOLYGON, new MultiPolygonDataType());
- types.put(Type.GEOMETRYCOLLECTION, new GeometryCollectionDataType());
- types.put(Type.COORDINATE, new CoordinateDataType());
+ types.put(ColumnType.BYTE, new ByteDataType());
+ types.put(ColumnType.BOOLEAN, new BooleanDataType());
+ types.put(ColumnType.SHORT, new ShortDataType());
+ types.put(ColumnType.INTEGER, new IntegerDataType());
+ types.put(ColumnType.LONG, new LongDataType());
+ types.put(ColumnType.FLOAT, new FloatDataType());
+ types.put(ColumnType.DOUBLE, new DoubleDataType());
+ types.put(ColumnType.STRING, new StringDataType());
+ types.put(ColumnType.GEOMETRY, new GeometryDataType());
+ types.put(ColumnType.POINT, new PointDataType());
+ types.put(ColumnType.LINESTRING, new LineStringDataType());
+ types.put(ColumnType.POLYGON, new PolygonDataType());
+ types.put(ColumnType.MULTIPOINT, new MultiPointDataType());
+ types.put(ColumnType.MULTILINESTRING, new MultiLineStringDataType());
+ types.put(ColumnType.MULTIPOLYGON, new MultiPolygonDataType());
+ types.put(ColumnType.GEOMETRYCOLLECTION, new GeometryCollectionDataType());
+ types.put(ColumnType.COORDINATE, new CoordinateDataType());
}
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 DataTypeImpl(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 1361a2b0b..955732eaf 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
@@ -22,7 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.apache.baremaps.store.DataColumnFixed;
import org.apache.baremaps.store.DataRow;
import org.apache.baremaps.store.DataSchema;
@@ -35,23 +35,24 @@ public class DataTypeProvider {
private static final GeometryFactory geometryFactory = new GeometryFactory();
private static final DataSchema DATA_SCHEMA = new DataSchemaImpl("row", List.of(
- new DataColumnFixed("byte", Cardinality.OPTIONAL, Type.BYTE),
- new DataColumnFixed("boolean", Cardinality.OPTIONAL, Type.BOOLEAN),
- new DataColumnFixed("short", Cardinality.OPTIONAL, Type.SHORT),
- new DataColumnFixed("integer", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("long", Cardinality.OPTIONAL, Type.LONG),
- new DataColumnFixed("float", Cardinality.OPTIONAL, Type.FLOAT),
- new DataColumnFixed("double", Cardinality.OPTIONAL, Type.DOUBLE),
- new DataColumnFixed("string", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY),
- new DataColumnFixed("point", Cardinality.OPTIONAL, Type.POINT),
- new DataColumnFixed("linestring", Cardinality.OPTIONAL, Type.LINESTRING),
- new DataColumnFixed("polygon", Cardinality.OPTIONAL, Type.POLYGON),
- new DataColumnFixed("multipoint", Cardinality.OPTIONAL, Type.MULTIPOINT),
- new DataColumnFixed("multilinestring", Cardinality.OPTIONAL, Type.MULTILINESTRING),
- new DataColumnFixed("multipolygon", Cardinality.OPTIONAL, Type.MULTIPOLYGON),
- new DataColumnFixed("geometrycollection", Cardinality.OPTIONAL, Type.GEOMETRYCOLLECTION),
- new DataColumnFixed("coordinate", Cardinality.OPTIONAL, Type.COORDINATE)));
+ new DataColumnFixed("byte", Cardinality.OPTIONAL, ColumnType.BYTE),
+ new DataColumnFixed("boolean", Cardinality.OPTIONAL, ColumnType.BOOLEAN),
+ new DataColumnFixed("short", Cardinality.OPTIONAL, ColumnType.SHORT),
+ new DataColumnFixed("integer", Cardinality.OPTIONAL, ColumnType.INTEGER),
+ new DataColumnFixed("long", Cardinality.OPTIONAL, ColumnType.LONG),
+ new DataColumnFixed("float", Cardinality.OPTIONAL, ColumnType.FLOAT),
+ new DataColumnFixed("double", Cardinality.OPTIONAL, ColumnType.DOUBLE),
+ new DataColumnFixed("string", Cardinality.OPTIONAL, ColumnType.STRING),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, ColumnType.GEOMETRY),
+ new DataColumnFixed("point", Cardinality.OPTIONAL, ColumnType.POINT),
+ new DataColumnFixed("linestring", Cardinality.OPTIONAL, ColumnType.LINESTRING),
+ new DataColumnFixed("polygon", Cardinality.OPTIONAL, ColumnType.POLYGON),
+ new DataColumnFixed("multipoint", Cardinality.OPTIONAL, ColumnType.MULTIPOINT),
+ new DataColumnFixed("multilinestring", Cardinality.OPTIONAL, ColumnType.MULTILINESTRING),
+ new DataColumnFixed("multipolygon", Cardinality.OPTIONAL, ColumnType.MULTIPOLYGON),
+ new DataColumnFixed("geometrycollection", Cardinality.OPTIONAL,
+ ColumnType.GEOMETRYCOLLECTION),
+ new DataColumnFixed("coordinate", Cardinality.OPTIONAL, ColumnType.COORDINATE)));
private static final DataRow DATA_ROW = DATA_SCHEMA.createRow()
.with("byte", Byte.MAX_VALUE)
@@ -345,7 +346,7 @@ public class DataTypeProvider {
new Coordinate(4, 1), new Coordinate(3, 1)})})})),
// Row
- Arguments.of(new RowDataType(DATA_SCHEMA), DATA_ROW),
+ Arguments.of(new DataTypeImpl(DATA_SCHEMA), DATA_ROW),
// Geometry
Arguments.of(new GeometryDataType(),
diff --git a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTable.java b/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTable.java
index 6e6679231..42d9467d0 100644
--- a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTable.java
+++ b/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufDataTable.java
@@ -27,7 +27,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
/**
* A {@link DataTable} that stores rows in a flatgeobuf file.
@@ -38,6 +38,8 @@ public class FlatGeoBufDataTable implements DataTable {
private final DataSchema schema;
+ private RowIterator iterator;
+
/**
* Constructs a table from a flatgeobuf file (used for reading).
*
@@ -88,13 +90,7 @@ public class FlatGeoBufDataTable implements DataTable {
@Override
public Iterator<DataRow> iterator() {
try {
- var reader = new FlatGeoBufReader(FileChannel.open(file, StandardOpenOption.READ));
-
- var header = reader.readHeader();
- reader.skipIndex();
-
- // create the feature stream
- return new RowIterator(reader, header, schema);
+ return (iterator = new RowIterator(file, schema));
} catch (IOException e) {
throw new DataStoreException(e);
}
@@ -135,7 +131,7 @@ public class FlatGeoBufDataTable implements DataTable {
schema.columns().stream()
.filter(c -> c.cardinality() == DataColumn.Cardinality.REQUIRED)
.forEach(c -> {
- if (Objects.requireNonNull(c.type()) == Type.BINARY) {
+ if (Objects.requireNonNull(c.type()) == ColumnType.BINARY) {
throw new UnsupportedOperationException();
}
});
@@ -172,10 +168,17 @@ public class FlatGeoBufDataTable implements DataTable {
}
}
+ @Override
+ public void close() throws Exception {
+ if (iterator != null) {
+ iterator.close();
+ }
+ }
+
/**
* An iterator over rows in a flatgeobuf file.
*/
- public static class RowIterator implements Iterator<DataRow> {
+ public static class RowIterator implements Iterator<DataRow>, AutoCloseable {
private final FlatGeoBuf.Header header;
@@ -188,17 +191,16 @@ public class FlatGeoBufDataTable implements DataTable {
/**
* Constructs a row iterator.
*
- * @param reader the channel to read from
- * @param header the header of the file
+ * @param file the path to the flatgeobuf file
* @param schema the schema of the table
*/
public RowIterator(
- FlatGeoBufReader reader,
- FlatGeoBuf.Header header,
- DataSchema schema) {
- this.reader = reader;
- this.header = header;
+ Path file,
+ DataSchema schema) throws IOException {
+ this.reader = new FlatGeoBufReader(FileChannel.open(file, StandardOpenOption.READ));
+ this.header = reader.readHeader();
this.schema = schema;
+ reader.skipIndex();
}
/**
@@ -222,5 +224,10 @@ public class FlatGeoBufDataTable implements DataTable {
throw new NoSuchElementException(e);
}
}
+
+ @Override
+ public void close() throws Exception {
+ reader.close();
+ }
}
}
diff --git a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufTypeConversion.java b/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufTypeConversion.java
index 252d21ca4..db109a5bb 100644
--- a/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufTypeConversion.java
+++ b/baremaps-flatgeobuf/src/main/java/org/apache/baremaps/flatgeobuf/FlatGeoBufTypeConversion.java
@@ -20,25 +20,24 @@ package org.apache.baremaps.flatgeobuf;
import java.util.*;
import org.apache.baremaps.flatgeobuf.FlatGeoBuf.Feature;
-import org.apache.baremaps.flatgeobuf.generated.ColumnType;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.locationtech.jts.geom.Geometry;
public class FlatGeoBufTypeConversion {
- private static final Map<Type, Integer> types = new EnumMap<>(Type.class);
+ private static final Map<ColumnType, Integer> types = new EnumMap<>(ColumnType.class);
static {
- types.put(Type.BYTE, ColumnType.Byte);
- types.put(Type.BOOLEAN, ColumnType.Bool);
- types.put(Type.SHORT, ColumnType.Short);
- types.put(Type.INTEGER, ColumnType.Int);
- types.put(Type.LONG, ColumnType.Long);
- types.put(Type.FLOAT, ColumnType.Float);
- types.put(Type.DOUBLE, ColumnType.Double);
- types.put(Type.STRING, ColumnType.String);
+ types.put(ColumnType.BYTE, org.apache.baremaps.flatgeobuf.generated.ColumnType.Byte);
+ types.put(ColumnType.BOOLEAN, org.apache.baremaps.flatgeobuf.generated.ColumnType.Bool);
+ types.put(ColumnType.SHORT, org.apache.baremaps.flatgeobuf.generated.ColumnType.Short);
+ types.put(ColumnType.INTEGER, org.apache.baremaps.flatgeobuf.generated.ColumnType.Int);
+ types.put(ColumnType.LONG, org.apache.baremaps.flatgeobuf.generated.ColumnType.Long);
+ types.put(ColumnType.FLOAT, org.apache.baremaps.flatgeobuf.generated.ColumnType.Float);
+ types.put(ColumnType.DOUBLE, org.apache.baremaps.flatgeobuf.generated.ColumnType.Double);
+ types.put(ColumnType.STRING, org.apache.baremaps.flatgeobuf.generated.ColumnType.String);
}
private FlatGeoBufTypeConversion() {
@@ -51,7 +50,7 @@ public class FlatGeoBufTypeConversion {
.map(column -> new DataColumnFixed(
column.name(),
column.nullable() ? Cardinality.OPTIONAL : Cardinality.REQUIRED,
- Type.fromBinding(fromColumnType(column.type()))))
+ ColumnType.fromBinding(fromColumnType(column.type()))))
.map(DataColumn.class::cast)
.toList();
return new DataSchemaImpl(name, columns);
diff --git a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java b/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java
index 59e91c180..a2e76c183 100644
--- a/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java
+++ b/baremaps-geopackage/src/main/java/org/apache/baremaps/geopackage/GeoPackageDataTable.java
@@ -18,6 +18,7 @@
package org.apache.baremaps.geopackage;
+import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
import mil.nga.geopackage.GeoPackage;
@@ -28,7 +29,7 @@ import mil.nga.geopackage.features.user.FeatureResultSet;
import mil.nga.geopackage.geom.GeoPackageGeometryData;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.locationtech.jts.geom.*;
/**
@@ -40,7 +41,7 @@ public class GeoPackageDataTable implements DataTable {
private final String name;
- private final GeoPackage geoPackage;
+ private final GeoPackage geoPackage;
private final FeatureDao featureDao;
@@ -71,11 +72,11 @@ public class GeoPackageDataTable implements DataTable {
geometryFactory = new GeometryFactory(new PrecisionModel(), (int) featureDao.getSrs().getId());
}
- private Type classType(FeatureColumn column) {
+ private ColumnType classType(FeatureColumn column) {
if (column.isGeometry()) {
- return Type.fromBinding(Geometry.class);
+ return ColumnType.fromBinding(Geometry.class);
} else {
- return Type.fromBinding(column.getDataType().getClassType());
+ return ColumnType.fromBinding(column.getDataType().getClassType());
}
}
@@ -222,6 +223,11 @@ public class GeoPackageDataTable implements DataTable {
return geometryFactory.createPoint(new Coordinate(point.getX(), point.getY()));
}
+ @Override
+ public void close() throws IOException {
+ geoPackage.close();
+ }
+
/**
* An iterator over the rows of a GeoPackage data table.
*/
diff --git a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataTable.java b/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataTable.java
index de1f8b32e..db2c2f729 100644
--- a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataTable.java
+++ b/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetDataTable.java
@@ -17,6 +17,7 @@
package org.apache.baremaps.geoparquet;
+import java.io.IOException;
import java.net.URI;
import java.util.Iterator;
import java.util.Spliterator;
@@ -95,4 +96,11 @@ public class GeoParquetDataTable implements DataTable {
throw new GeoParquetException("Fail to read the SRID from the GeoParquet metadata", e);
}
}
+
+ @Override
+ public void close() throws IOException {
+ if (reader != null) {
+ reader.close();
+ }
+ }
}
diff --git a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetReader.java b/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetReader.java
index e965d250a..6a4bd4050 100644
--- a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetReader.java
+++ b/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetReader.java
@@ -19,6 +19,7 @@ package org.apache.baremaps.geoparquet;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.Closeable;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
@@ -42,7 +43,7 @@ import org.locationtech.jts.geom.Envelope;
* automatically inferred from the files. The reader can be used to read the records in a sequential
* or parallel manner. It is also capable of filtering records based on an envelope.
*/
-public class GeoParquetReader {
+public class GeoParquetReader implements Closeable {
protected final Configuration configuration;
protected final List<FileStatus> files;
@@ -194,6 +195,11 @@ public class GeoParquetReader {
return streamGeoParquetGroups(true);
}
+ @Override
+ public void close() throws IOException {
+ // TODO: Implement close
+ }
+
private record FileInfo(
FileStatus file,
long recordCount,
diff --git a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetSpliterator.java b/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetSpliterator.java
index 12d4a2662..8ab7581ba 100644
--- a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetSpliterator.java
+++ b/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetSpliterator.java
@@ -284,4 +284,5 @@ class GeoParquetSpliterator implements Spliterator<GeoParquetGroup> {
public int characteristics() {
return NONNULL | IMMUTABLE;
}
+
}
diff --git a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetTypeConversion.java b/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetTypeConversion.java
index f35e6c010..bbf25dfcb 100644
--- a/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetTypeConversion.java
+++ b/baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetTypeConversion.java
@@ -25,7 +25,7 @@ import org.apache.baremaps.geoparquet.GeoParquetSchema.Field;
import org.apache.baremaps.geoparquet.GeoParquetSchema.GroupField;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.apache.parquet.io.api.Binary;
public class GeoParquetTypeConversion {
@@ -50,15 +50,15 @@ public class GeoParquetTypeConversion {
case REPEATED -> Cardinality.REPEATED;
};
return switch (field.type()) {
- case BINARY -> new DataColumnFixed(field.name(), cardinality, Type.BINARY);
- case BOOLEAN -> new DataColumnFixed(field.name(), cardinality, Type.BOOLEAN);
- case INTEGER -> new DataColumnFixed(field.name(), cardinality, Type.INTEGER);
- case INT96, LONG -> new DataColumnFixed(field.name(), cardinality, Type.LONG);
- case FLOAT -> new DataColumnFixed(field.name(), cardinality, Type.FLOAT);
- case DOUBLE -> new DataColumnFixed(field.name(), cardinality, Type.DOUBLE);
- case STRING -> new DataColumnFixed(field.name(), cardinality, Type.STRING);
- case GEOMETRY -> new DataColumnFixed(field.name(), cardinality, Type.GEOMETRY);
- case ENVELOPE -> new DataColumnFixed(field.name(), cardinality, Type.ENVELOPE);
+ case BINARY -> new DataColumnFixed(field.name(), cardinality, ColumnType.BINARY);
+ case BOOLEAN -> new DataColumnFixed(field.name(), cardinality, ColumnType.BOOLEAN);
+ case INTEGER -> new DataColumnFixed(field.name(), cardinality, ColumnType.INTEGER);
+ case INT96, LONG -> new DataColumnFixed(field.name(), cardinality, ColumnType.LONG);
+ case FLOAT -> new DataColumnFixed(field.name(), cardinality, ColumnType.FLOAT);
+ case DOUBLE -> new DataColumnFixed(field.name(), cardinality, ColumnType.DOUBLE);
+ case STRING -> new DataColumnFixed(field.name(), cardinality, ColumnType.STRING);
+ case GEOMETRY -> new DataColumnFixed(field.name(), cardinality, ColumnType.GEOMETRY);
+ case ENVELOPE -> new DataColumnFixed(field.name(), cardinality, ColumnType.ENVELOPE);
case GROUP -> new DataColumnNested(field.name(), cardinality,
asDataColumns(((GroupField) field).schema()));
};
diff --git a/baremaps-openstreetmap/pom.xml b/baremaps-openstreetmap/pom.xml
index b9358baa3..b0e59d3fd 100644
--- a/baremaps-openstreetmap/pom.xml
+++ b/baremaps-openstreetmap/pom.xml
@@ -43,9 +43,14 @@ limitations under the License.
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.locationtech.jts.io</groupId>
+ <artifactId>jts-io-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.locationtech.proj4j</groupId>
<artifactId>proj4j</artifactId>
+ <version>${version.lib.proj4j}</version>
</dependency>
</dependencies>
diff --git a/baremaps-openstreetmap/src/main/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTable.java b/baremaps-openstreetmap/src/main/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTable.java
index 1d1f5bb24..6101b69c1 100644
--- a/baremaps-openstreetmap/src/main/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTable.java
+++ b/baremaps-openstreetmap/src/main/java/org/apache/baremaps/openstreetmap/OpenStreetMapDataTable.java
@@ -23,6 +23,7 @@ import java.util.stream.Stream;
import org.apache.baremaps.openstreetmap.OpenStreetMapFormat.EntityReader;
import org.apache.baremaps.openstreetmap.model.*;
import org.apache.baremaps.store.*;
+import org.apache.baremaps.store.DataColumn.ColumnType;
/**
* A DataTable implementation for OpenStreetMap data.
@@ -52,17 +53,17 @@ public class OpenStreetMapDataTable implements DataTable {
*/
private DataSchema createSchema() {
List<DataColumn> columns = List.of(
- new DataColumnFixed("id", DataColumn.Cardinality.REQUIRED, DataColumn.Type.LONG),
- new DataColumnFixed("type", DataColumn.Cardinality.REQUIRED, DataColumn.Type.STRING),
- new DataColumnFixed("version", DataColumn.Cardinality.OPTIONAL, DataColumn.Type.INTEGER),
+ new DataColumnFixed("id", DataColumn.Cardinality.REQUIRED, ColumnType.LONG),
+ new DataColumnFixed("type", DataColumn.Cardinality.REQUIRED, ColumnType.STRING),
+ new DataColumnFixed("version", DataColumn.Cardinality.OPTIONAL, ColumnType.INTEGER),
new DataColumnFixed("timestamp", DataColumn.Cardinality.OPTIONAL,
- DataColumn.Type.LOCAL_DATE_TIME),
- new DataColumnFixed("uid", DataColumn.Cardinality.OPTIONAL, DataColumn.Type.INTEGER),
- new DataColumnFixed("user", DataColumn.Cardinality.OPTIONAL, DataColumn.Type.STRING),
- new DataColumnFixed("changeset", DataColumn.Cardinality.OPTIONAL, DataColumn.Type.LONG),
- new DataColumnFixed("tags", DataColumn.Cardinality.OPTIONAL, DataColumn.Type.NESTED),
+ ColumnType.LOCAL_DATE_TIME),
+ new DataColumnFixed("uid", DataColumn.Cardinality.OPTIONAL, ColumnType.INTEGER),
+ new DataColumnFixed("user", DataColumn.Cardinality.OPTIONAL, ColumnType.STRING),
+ new DataColumnFixed("changeset", DataColumn.Cardinality.OPTIONAL, ColumnType.LONG),
+ new DataColumnFixed("tags", DataColumn.Cardinality.OPTIONAL, ColumnType.NESTED),
new DataColumnFixed("geometry", DataColumn.Cardinality.OPTIONAL,
- DataColumn.Type.GEOMETRY));
+ ColumnType.GEOMETRY));
return new DataSchemaImpl("osm_data", columns);
}
@@ -132,4 +133,9 @@ public class OpenStreetMapDataTable implements DataTable {
else
return "unknown";
}
+
+ @Override
+ public void close() throws Exception {
+ inputStream.close();
+ }
}
diff --git a/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/geometry/EntityDataTypeGeometryBuilderTest.java b/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/geometry/EntityDataColumnTypeGeometryBuilderTest.java
similarity index 99%
rename from baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/geometry/EntityDataTypeGeometryBuilderTest.java
rename to baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/geometry/EntityDataColumnTypeGeometryBuilderTest.java
index 5e15daebe..19a7bd7dd 100644
--- a/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/geometry/EntityDataTypeGeometryBuilderTest.java
+++ b/baremaps-openstreetmap/src/test/java/org/apache/baremaps/openstreetmap/geometry/EntityDataColumnTypeGeometryBuilderTest.java
@@ -49,7 +49,7 @@ import org.locationtech.proj4j.CoordinateTransform;
import org.locationtech.proj4j.Proj4jException;
import org.locationtech.proj4j.ProjCoordinate;
-class EntityDataTypeGeometryBuilderTest {
+class EntityDataColumnTypeGeometryBuilderTest {
static final CRSFactory CRS_FACTORY = new CRSFactory();
diff --git a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataStore.java b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataStore.java
index 3e1170eaf..512b0b837 100644
--- a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataStore.java
+++ b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataStore.java
@@ -31,7 +31,7 @@ import org.apache.baremaps.postgres.copy.GeometryValueHandler;
import org.apache.baremaps.postgres.metadata.DatabaseMetadata;
import org.apache.baremaps.postgres.metadata.TableMetadata;
import org.apache.baremaps.store.*;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.postgresql.PGConnection;
import org.postgresql.copy.PGCopyOutputStream;
import org.slf4j.Logger;
@@ -291,7 +291,7 @@ public class PostgresDataStore implements DataStore {
* @param type the type
* @return the handler
*/
- protected BaseValueHandler getHandler(Type type) {
+ protected BaseValueHandler getHandler(ColumnType type) {
return switch (type) {
case STRING -> new StringValueHandler();
case SHORT -> new ShortValueHandler<Short>();
diff --git a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataTable.java b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataTable.java
index 7df19761b..cad98ce33 100644
--- a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataTable.java
+++ b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresDataTable.java
@@ -242,6 +242,11 @@ public class PostgresDataTable implements DataTable {
return String.format("TRUNCATE TABLE \"%s\"", schema.name());
}
+ @Override
+ public void close() throws Exception {
+ // Do nothing
+ }
+
/**
* An iterator that iterates over the rows of a table.
*/
diff --git a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresTypeConversion.java b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresTypeConversion.java
index 6d03d9392..eae52d969 100644
--- a/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresTypeConversion.java
+++ b/baremaps-postgres/src/main/java/org/apache/baremaps/postgres/store/PostgresTypeConversion.java
@@ -19,7 +19,7 @@ package org.apache.baremaps.postgres.store;
import java.util.EnumMap;
import java.util.Map;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
@SuppressWarnings("squid:S1192")
public class PostgresTypeConversion {
@@ -28,45 +28,45 @@ public class PostgresTypeConversion {
// Prevent instantiation
}
- protected static final Map<Type, String> typeToName = new EnumMap<>(Type.class);
+ protected static final Map<ColumnType, String> typeToName = new EnumMap<>(ColumnType.class);
static {
- typeToName.put(Type.STRING, "varchar");
- typeToName.put(Type.SHORT, "int2");
- typeToName.put(Type.INTEGER, "int4");
- typeToName.put(Type.LONG, "int8");
- typeToName.put(Type.FLOAT, "float4");
- typeToName.put(Type.DOUBLE, "float8");
- typeToName.put(Type.GEOMETRY, "geometry");
- typeToName.put(Type.POINT, "geometry");
- typeToName.put(Type.MULTIPOINT, "geometry");
- typeToName.put(Type.LINESTRING, "geometry");
- typeToName.put(Type.MULTILINESTRING, "geometry");
- typeToName.put(Type.POLYGON, "geometry");
- typeToName.put(Type.MULTIPOLYGON, "geometry");
- typeToName.put(Type.GEOMETRYCOLLECTION, "geometry");
- typeToName.put(Type.ENVELOPE, "geometry");
- typeToName.put(Type.INET_ADDRESS, "inet");
- typeToName.put(Type.INET4_ADDRESS, "inet");
- typeToName.put(Type.INET6_ADDRESS, "inet");
- typeToName.put(Type.LOCAL_DATE, "date");
- typeToName.put(Type.LOCAL_TIME, "time");
- typeToName.put(Type.LOCAL_DATE_TIME, "timestamp");
- typeToName.put(Type.NESTED, "jsonb");
+ typeToName.put(ColumnType.STRING, "varchar");
+ typeToName.put(ColumnType.SHORT, "int2");
+ typeToName.put(ColumnType.INTEGER, "int4");
+ typeToName.put(ColumnType.LONG, "int8");
+ typeToName.put(ColumnType.FLOAT, "float4");
+ typeToName.put(ColumnType.DOUBLE, "float8");
+ typeToName.put(ColumnType.GEOMETRY, "geometry");
+ typeToName.put(ColumnType.POINT, "geometry");
+ typeToName.put(ColumnType.MULTIPOINT, "geometry");
+ typeToName.put(ColumnType.LINESTRING, "geometry");
+ typeToName.put(ColumnType.MULTILINESTRING, "geometry");
+ typeToName.put(ColumnType.POLYGON, "geometry");
+ typeToName.put(ColumnType.MULTIPOLYGON, "geometry");
+ typeToName.put(ColumnType.GEOMETRYCOLLECTION, "geometry");
+ typeToName.put(ColumnType.ENVELOPE, "geometry");
+ typeToName.put(ColumnType.INET_ADDRESS, "inet");
+ typeToName.put(ColumnType.INET4_ADDRESS, "inet");
+ typeToName.put(ColumnType.INET6_ADDRESS, "inet");
+ typeToName.put(ColumnType.LOCAL_DATE, "date");
+ typeToName.put(ColumnType.LOCAL_TIME, "time");
+ typeToName.put(ColumnType.LOCAL_DATE_TIME, "timestamp");
+ typeToName.put(ColumnType.NESTED, "jsonb");
}
- protected static final Map<String, Type> nameToType = Map.ofEntries(
- Map.entry("varchar", Type.STRING),
- Map.entry("int2", Type.SHORT),
- Map.entry("int4", Type.INTEGER),
- Map.entry("int8", Type.LONG),
- Map.entry("float4", Type.FLOAT),
- Map.entry("float8", Type.DOUBLE),
- Map.entry("geometry", Type.GEOMETRY),
- Map.entry("inet", Type.INET6_ADDRESS),
- Map.entry("date", Type.LOCAL_DATE),
- Map.entry("time", Type.LOCAL_TIME),
- Map.entry("timestamp", Type.LOCAL_DATE_TIME),
- Map.entry("jsonb", Type.NESTED));
+ protected static final Map<String, ColumnType> nameToType = Map.ofEntries(
+ Map.entry("varchar", ColumnType.STRING),
+ Map.entry("int2", ColumnType.SHORT),
+ Map.entry("int4", ColumnType.INTEGER),
+ Map.entry("int8", ColumnType.LONG),
+ Map.entry("float4", ColumnType.FLOAT),
+ Map.entry("float8", ColumnType.DOUBLE),
+ Map.entry("geometry", ColumnType.GEOMETRY),
+ Map.entry("inet", ColumnType.INET6_ADDRESS),
+ Map.entry("date", ColumnType.LOCAL_DATE),
+ Map.entry("time", ColumnType.LOCAL_TIME),
+ Map.entry("timestamp", ColumnType.LOCAL_DATE_TIME),
+ Map.entry("jsonb", ColumnType.NESTED));
}
diff --git a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/MockDataTable.java b/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/MockDataTable.java
index 797f5608e..668aaa819 100644
--- a/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/MockDataTable.java
+++ b/baremaps-postgres/src/test/java/org/apache/baremaps/postgres/MockDataTable.java
@@ -22,7 +22,7 @@ import java.util.Iterator;
import java.util.List;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.locationtech.jts.geom.Coordinate;
public class MockDataTable implements DataTable {
@@ -33,11 +33,11 @@ public class MockDataTable implements DataTable {
public MockDataTable() {
this.rowType = new DataSchemaImpl("mock", List.of(
- new DataColumnFixed("string", Cardinality.OPTIONAL, Type.STRING),
- new DataColumnFixed("integer", Cardinality.OPTIONAL, Type.INTEGER),
- new DataColumnFixed("double", Cardinality.OPTIONAL, Type.DOUBLE),
- new DataColumnFixed("float", Cardinality.OPTIONAL, Type.FLOAT),
- new DataColumnFixed("geometry", Cardinality.OPTIONAL, Type.GEOMETRY)));
+ new DataColumnFixed("string", Cardinality.OPTIONAL, ColumnType.STRING),
+ new DataColumnFixed("integer", Cardinality.OPTIONAL, ColumnType.INTEGER),
+ new DataColumnFixed("double", Cardinality.OPTIONAL, ColumnType.DOUBLE),
+ new DataColumnFixed("float", Cardinality.OPTIONAL, ColumnType.FLOAT),
+ new DataColumnFixed("geometry", Cardinality.OPTIONAL, ColumnType.GEOMETRY)));
this.rows = List.of(
new DataRowImpl(rowType,
List.of("string", 1, 1.0, 1.0f,
@@ -75,4 +75,9 @@ public class MockDataTable implements DataTable {
public DataSchema schema() {
return rowType;
}
+
+ @Override
+ public void close() throws Exception {
+ // Do nothing
+ }
}
diff --git a/baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataTable.java b/baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataTable.java
index 9bbfeaae7..b4f1b3a1e 100644
--- a/baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataTable.java
+++ b/baremaps-rpsl/src/main/java/org/apache/baremaps/rpsl/RpslDataTable.java
@@ -22,7 +22,7 @@ import java.io.InputStream;
import java.util.*;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
/**
* A DataTable implementation that reads RPSL data using RpslReader.
@@ -49,20 +49,20 @@ public class RpslDataTable implements DataTable {
*/
private DataSchema createSchema() {
List<DataColumn> columns = new ArrayList<>();
- columns.add(new DataColumnFixed("type", Cardinality.REQUIRED, Type.STRING));
- columns.add(new DataColumnFixed("id", Cardinality.REQUIRED, Type.STRING));
- columns.add(new DataColumnFixed("inetnum", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("inet6num", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("netname", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("descr", Cardinality.REPEATED, Type.STRING));
- columns.add(new DataColumnFixed("country", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("admin-c", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("tech-c", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("status", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("mnt-by", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("created", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("last-modified", Cardinality.OPTIONAL, Type.STRING));
- columns.add(new DataColumnFixed("changed", Cardinality.REPEATED, Type.STRING));
+ columns.add(new DataColumnFixed("type", Cardinality.REQUIRED, ColumnType.STRING));
+ columns.add(new DataColumnFixed("id", Cardinality.REQUIRED, ColumnType.STRING));
+ columns.add(new DataColumnFixed("inetnum", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("inet6num", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("netname", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("descr", Cardinality.REPEATED, ColumnType.STRING));
+ columns.add(new DataColumnFixed("country", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("admin-c", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("tech-c", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("status", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("mnt-by", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("created", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("last-modified", Cardinality.OPTIONAL, ColumnType.STRING));
+ columns.add(new DataColumnFixed("changed", Cardinality.REPEATED, ColumnType.STRING));
return new DataSchemaImpl("RpslObject", columns);
}
@@ -86,4 +86,9 @@ public class RpslDataTable implements DataTable {
public void clear() {
throw new UnsupportedOperationException("Clear operation is not supported.");
}
+
+ @Override
+ public void close() throws Exception {
+ inputStream.close();
+ }
}
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileByteReader.java b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileByteReader.java
index 68b017a28..ac6de721a 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileByteReader.java
+++ b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileByteReader.java
@@ -26,7 +26,7 @@ import java.nio.channels.FileChannel;
import java.util.*;
import org.apache.baremaps.store.*;
import org.apache.baremaps.store.DataColumn.Cardinality;
-import org.apache.baremaps.store.DataColumn.Type;
+import org.apache.baremaps.store.DataColumn.ColumnType;
import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateList;
@@ -131,29 +131,29 @@ public class ShapefileByteReader extends CommonByteReader {
var fieldDescriptor = this.databaseFieldsDescriptors.get(i);
var columnName = fieldDescriptor.getName();
var columnType = switch (fieldDescriptor.getType()) {
- case CHARACTER -> Type.STRING;
- case NUMBER -> fieldDescriptor.getDecimalCount() == 0 ? Type.LONG : Type.DOUBLE;
- case CURRENCY -> Type.DOUBLE;
- case DOUBLE -> Type.DOUBLE;
- case INTEGER -> Type.INTEGER;
- case AUTO_INCREMENT -> Type.INTEGER;
+ case CHARACTER -> ColumnType.STRING;
+ case NUMBER -> fieldDescriptor.getDecimalCount() == 0 ? ColumnType.LONG : ColumnType.DOUBLE;
+ case CURRENCY -> ColumnType.DOUBLE;
+ case DOUBLE -> ColumnType.DOUBLE;
+ case INTEGER -> ColumnType.INTEGER;
+ case AUTO_INCREMENT -> ColumnType.INTEGER;
// TODO: Implement the following types
- case LOGICAL -> Type.STRING;
- case DATE -> Type.STRING;
- case MEMO -> Type.STRING;
- case FLOATING_POINT -> Type.STRING;
- case PICTURE -> Type.STRING;
- case VARI_FIELD -> Type.STRING;
- case VARIANT -> Type.STRING;
- case TIMESTAMP -> Type.STRING;
- case DATE_TIME -> Type.STRING;
+ case LOGICAL -> ColumnType.STRING;
+ case DATE -> ColumnType.STRING;
+ case MEMO -> ColumnType.STRING;
+ case FLOATING_POINT -> ColumnType.STRING;
+ case PICTURE -> ColumnType.STRING;
+ case VARI_FIELD -> ColumnType.STRING;
+ case VARIANT -> ColumnType.STRING;
+ case TIMESTAMP -> ColumnType.STRING;
+ case DATE_TIME -> ColumnType.STRING;
};
columns.add(new DataColumnFixed(columnName, Cardinality.OPTIONAL, columnType));
}
// Add geometry column.
- columns.add(new DataColumnFixed(GEOMETRY_NAME, Cardinality.OPTIONAL, Type.GEOMETRY));
+ columns.add(new DataColumnFixed(GEOMETRY_NAME, Cardinality.OPTIONAL, ColumnType.GEOMETRY));
return new DataSchemaImpl(name, columns);
}
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataTable.java b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataTable.java
index f62258dfe..8822bb921 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataTable.java
+++ b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileDataTable.java
@@ -38,6 +38,8 @@ public class ShapefileDataTable implements DataTable {
private final ShapefileReader shapeFile;
+ private ShapefileIterator iterator;
+
/**
* Constructs a table from a shapefile.
*
@@ -73,7 +75,7 @@ public class ShapefileDataTable implements DataTable {
@Override
public Iterator<DataRow> iterator() {
try {
- return new ShapefileIterator(shapeFile.read());
+ return (iterator = new ShapefileIterator(shapeFile));
} catch (IOException e) {
throw new DataStoreException(e);
}
@@ -87,10 +89,17 @@ public class ShapefileDataTable implements DataTable {
throw new UnsupportedOperationException();
}
+ @Override
+ public void close() throws Exception {
+ if (iterator != null) {
+ iterator.close();
+ }
+ }
+
/**
* An iterator over the rows of a shapefile.
*/
- public static class ShapefileIterator implements Iterator<DataRow> {
+ public static class ShapefileIterator implements Iterator<DataRow>, AutoCloseable {
private final ShapefileInputStream shapefileInputStream;
@@ -99,10 +108,10 @@ public class ShapefileDataTable implements DataTable {
/**
* Constructs an iterator from a shapefile input stream.
*
- * @param shapefileInputStream the shapefile input stream
+ * @param shapefileReader the shapefile input stream
*/
- public ShapefileIterator(ShapefileInputStream shapefileInputStream) {
- this.shapefileInputStream = shapefileInputStream;
+ public ShapefileIterator(ShapefileReader shapefileReader) throws IOException {
+ this.shapefileInputStream = shapefileReader.read();
}
/**
@@ -147,5 +156,10 @@ public class ShapefileDataTable implements DataTable {
throw new NoSuchElementException();
}
}
+
+ @Override
+ public void close() throws Exception {
+ shapefileInputStream.close();
+ }
}
}
diff --git a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileReader.java b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileReader.java
index 3a796befa..777411241 100644
--- a/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileReader.java
+++ b/baremaps-shapefile/src/main/java/org/apache/baremaps/shapefile/ShapefileReader.java
@@ -190,7 +190,6 @@ public class ShapefileReader {
* this is also automatically done when executing a query on it, by findAll.
*/
public void loadDescriptors() throws IOException {
-
try (ShapefileInputStream is = read()) {
// Doing a read is sufficient to initialize the internal descriptors.
}
diff --git a/baremaps-store/pom.xml b/baremaps-store/pom.xml
index a652d8bf2..ababb4711 100644
--- a/baremaps-store/pom.xml
+++ b/baremaps-store/pom.xml
@@ -25,6 +25,16 @@ limitations under the License.
<artifactId>baremaps-store</artifactId>
<name>Apache Baremaps Store</name>
<dependencies>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${version.lib.jackson}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${version.lib.jackson}</version>
+ </dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumn.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumn.java
index 11c5d3567..609674eb1 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumn.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumn.java
@@ -17,6 +17,7 @@
package org.apache.baremaps.store;
+import java.io.Serializable;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
@@ -29,7 +30,7 @@ import org.locationtech.jts.geom.*;
/**
* A column in a table.
*/
-public interface DataColumn {
+public interface DataColumn extends Serializable {
/**
* Returns the name of the column.
@@ -38,7 +39,6 @@ public interface DataColumn {
*/
String name();
-
Cardinality cardinality();
enum Cardinality {
@@ -52,12 +52,12 @@ public interface DataColumn {
*
* @return the type of the column
*/
- Type type();
+ ColumnType type();
/**
* An enumeration of the supported data column types.
*/
- enum Type {
+ enum ColumnType {
BINARY(byte[].class),
BYTE(Byte.class),
BOOLEAN(Boolean.class),
@@ -87,7 +87,7 @@ public interface DataColumn {
private final Class<?> binding;
- Type(Class<?> binding) {
+ ColumnType(Class<?> binding) {
this.binding = binding;
}
@@ -95,8 +95,8 @@ public interface DataColumn {
return binding;
}
- public static Type fromBinding(Class<?> binding) {
- for (Type type : Type.values()) {
+ public static ColumnType fromBinding(Class<?> binding) {
+ for (ColumnType type : ColumnType.values()) {
if (type.binding().equals(binding)) {
return type;
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnFixed.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnFixed.java
index e8e6cdd88..2f8990e9c 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnFixed.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnFixed.java
@@ -17,12 +17,13 @@
package org.apache.baremaps.store;
+
/**
* A column in a table.
*/
public record DataColumnFixed(
String name,
Cardinality cardinality,
- Type type) implements DataColumn {
+ ColumnType type) implements DataColumn {
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnNested.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnNested.java
index 176f0c626..bcf3458c1 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnNested.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataColumnNested.java
@@ -25,7 +25,7 @@ public record DataColumnNested(
List<DataColumn> columns) implements DataColumn {
@Override
- public Type type() {
- return Type.NESTED;
+ public ColumnType type() {
+ return ColumnType.NESTED;
}
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
index 48382aeb8..aef70f1e7 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchema.java
@@ -17,32 +17,97 @@
package org.apache.baremaps.store;
+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.Serializable;
+import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.List;
+import org.apache.baremaps.store.DataColumn.Cardinality;
+import org.apache.baremaps.store.DataColumn.ColumnType;
/**
* A {@link DataSchema} is a description of the structure of a row in a {@link DataTable}.
*/
-public interface DataSchema {
+public interface DataSchema extends Serializable {
/**
* Returns the name of the schema.
- *
+ *
* @return the name of the schema
*/
String name();
/**
* Returns the columns of the schema.
- *
+ *
* @return the columns of the schema
*/
List<DataColumn> columns();
/**
* Creates a new row of the schema.
- *
+ *
* @return a new row of the schema
*/
DataRow createRow();
+ 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 DataSchemaImpl(name, columns);
+ }
+
+ DataColumn deserialize(JsonNode node) {
+ String columnName = node.get("name").asText();
+ Cardinality cardinality = Cardinality.valueOf(node.get("cardinality").asText());
+ ColumnType type = ColumnType.valueOf(node.get("type").asText());
+ if (type == ColumnType.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(Path path) throws IOException {
+ var mapper = configureObjectMapper();
+ return mapper.readValue(path.toFile(), DataSchema.class);
+ }
+
+ static void write(Path path, DataSchema schema) throws IOException {
+ var mapper = configureObjectMapper();
+ mapper.writerWithDefaultPrettyPrinter().writeValue(path.toFile(), schema);
+ }
+
}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchemaImpl.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchemaImpl.java
index 7c5ad1612..302dc7c00 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchemaImpl.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataSchemaImpl.java
@@ -17,13 +17,15 @@
package org.apache.baremaps.store;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* A {@link DataSchema} defines the structure of a table.
*/
-public record DataSchemaImpl(String name, List<DataColumn> columns) implements DataSchema {
+public record DataSchemaImpl(String name,
+ List<DataColumn> columns) implements DataSchema, Serializable {
/**
* {@inheritDoc}
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTable.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataTable.java
index 11749f00c..a270f4d6b 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTable.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataTable.java
@@ -26,7 +26,7 @@ import java.util.stream.StreamSupport;
/**
* 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.
diff --git a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTableMapper.java b/baremaps-store/src/main/java/org/apache/baremaps/store/DataTableMapper.java
index 429ff18c4..a9e2ea151 100644
--- a/baremaps-store/src/main/java/org/apache/baremaps/store/DataTableMapper.java
+++ b/baremaps-store/src/main/java/org/apache/baremaps/store/DataTableMapper.java
@@ -68,4 +68,8 @@ public class DataTableMapper implements DataTable {
table.clear();
}
+ @Override
+ public void close() throws Exception {
+ table.close();
+ }
}
diff --git a/pom.xml b/pom.xml
index 5ca3c9b7d..5ea81176b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,7 @@ limitations under the License.
<modules>
<module>baremaps-benchmarking</module>
+ <module>baremaps-calcite</module>
<module>baremaps-cli</module>
<module>baremaps-core</module>
<module>baremaps-csv</module>