This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch data-refactoring
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 5914c17fe3847c772af1c3a58de5100ea2d33033
Author: Bertil Chapuis <[email protected]>
AuthorDate: Sat Apr 5 12:09:57 2025 +0200

    Use the builder pattern for the IndexedDataList
---
 .../java/org/apache/baremaps/calcite/CalciteTest.java   | 16 ++++++++++------
 .../baremaps/data/collection/IndexedDataList.java       | 17 ++++-------------
 .../java/org/apache/baremaps/data/DataListTest.java     | 10 ++++++----
 .../baremaps/data/sort/ExternalMergeSortTest.java       |  9 +++++----
 4 files changed, 25 insertions(+), 27 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 4f6cc2031..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
@@ -80,9 +80,11 @@ class CalciteTest {
           new DataColumnFixed("geometry", Cardinality.OPTIONAL, 
Type.GEOMETRY)));
       DataTable cityDataTable = new BaremapsDataTable(
           cityRowType,
-          new IndexedDataList<>(AppendOnlyLog.<DataRow>builder()
-              .dataType(new RowDataType(cityRowType))
-              .build()));
+          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(),
@@ -96,9 +98,11 @@ class CalciteTest {
           new DataColumnFixed("population", Cardinality.OPTIONAL, 
Type.INTEGER)));
       DataTable populationDataTable = new BaremapsDataTable(
           populationRowType,
-          new IndexedDataList<>(AppendOnlyLog.<DataRow>builder()
-              .dataType(new RowDataType(populationRowType))
-              .build()));
+          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
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 89b887044..da973b83f 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
@@ -86,29 +86,20 @@ public class IndexedDataList<E> implements DataList<E> {
       }
 
       if (index == null) {
-        return new IndexedDataList<>(values);
-      } else {
-        return new IndexedDataList<>(index, values);
+        index = new MemoryAlignedDataList<>(new LongDataType());
       }
+      
+      return new IndexedDataList<>(index, values);
     }
   }
 
-  /**
-   * Constructs a {@link IndexedDataList}.
-   *
-   * @param values the values
-   */
-  public IndexedDataList(AppendOnlyLog<E> values) {
-    this(new MemoryAlignedDataList<>(new LongDataType()), values);
-  }
-
   /**
    * Constructs a {@link IndexedDataList}.
    *
    * @param index the index
    * @param values the values
    */
-  public IndexedDataList(DataList<Long> index, AppendOnlyLog<E> values) {
+  private IndexedDataList(DataList<Long> index, AppendOnlyLog<E> values) {
     this.index = index;
     this.values = values;
   }
diff --git 
a/baremaps-data/src/test/java/org/apache/baremaps/data/DataListTest.java 
b/baremaps-data/src/test/java/org/apache/baremaps/data/DataListTest.java
index c94858bb6..6b1a1db76 100644
--- a/baremaps-data/src/test/java/org/apache/baremaps/data/DataListTest.java
+++ b/baremaps-data/src/test/java/org/apache/baremaps/data/DataListTest.java
@@ -78,10 +78,12 @@ class DataListTest {
         Arguments.of(FixedSizeDataList.<Long>builder()
                 .dataType(new LongDataType())
                 .build()),
-        Arguments.of(new IndexedDataList<>(new MemoryAlignedDataList<>(new 
LongDataType()),
-            AppendOnlyLog.<Long>builder()
-                .dataType(new LongDataType())
-                .build())),
+        Arguments.of(IndexedDataList.<Long>builder()
+                .index(new MemoryAlignedDataList<>(new LongDataType()))
+                .values(AppendOnlyLog.<Long>builder()
+                    .dataType(new LongDataType())
+                    .build())
+                .build()),
         Arguments.of(new MemoryAlignedDataList<>(new LongDataType())));
   }
 }
diff --git 
a/baremaps-data/src/test/java/org/apache/baremaps/data/sort/ExternalMergeSortTest.java
 
b/baremaps-data/src/test/java/org/apache/baremaps/data/sort/ExternalMergeSortTest.java
index c42b9a89b..c4c51f0cf 100644
--- 
a/baremaps-data/src/test/java/org/apache/baremaps/data/sort/ExternalMergeSortTest.java
+++ 
b/baremaps-data/src/test/java/org/apache/baremaps/data/sort/ExternalMergeSortTest.java
@@ -53,12 +53,13 @@ class ExternalMergeSortTest {
     stringsAsc = strings.stream().sorted(Comparator.naturalOrder()).toList();
     stringsDsc = strings.stream().sorted(Comparator.reverseOrder()).toList();
     stringsDistinct = stringsAsc.stream().distinct().toList();
-    supplier = () -> new IndexedDataList<>(
-        new MemoryAlignedDataList<>(new LongDataType(), new OnHeapMemory()),
-        AppendOnlyLog.<String>builder()
+    supplier = () -> IndexedDataList.<String>builder()
+        .index(new MemoryAlignedDataList<>(new LongDataType(), new 
OnHeapMemory()))
+        .values(AppendOnlyLog.<String>builder()
             .dataType(new StringDataType())
             .memory(new OnHeapMemory())
-            .build());
+            .build())
+        .build();
     input = supplier.get();
     output = supplier.get();
     for (var string : strings) {

Reply via email to