You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ya...@apache.org on 2026/04/18 15:22:50 UTC

(pinot) branch master updated: Fix AIOOBE in MapColumnPreIndexStatsCollector when all map rows are empty (#18198)

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

yashmayya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ae0861a2bf Fix AIOOBE in MapColumnPreIndexStatsCollector when all map rows are empty (#18198)
7ae0861a2bf is described below

commit 7ae0861a2bf33116b09eeba75d2d274c69398055
Author: Yash Mayya <ya...@gmail.com>
AuthorDate: Sat Apr 18 08:22:44 2026 -0700

    Fix AIOOBE in MapColumnPreIndexStatsCollector when all map rows are empty (#18198)
---
 .../stats/MapColumnPreIndexStatsCollector.java     | 10 +++--
 .../stats/MapColumnPreIndexStatsCollectorTest.java | 47 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollector.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollector.java
index 9d41d9ecadb..4494073038d 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollector.java
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollector.java
@@ -23,6 +23,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
 import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.Map;
+import javax.annotation.Nullable;
 import org.apache.pinot.common.utils.PinotDataType;
 import org.apache.pinot.segment.spi.creator.StatsCollectorConfig;
 import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
@@ -206,26 +207,29 @@ public class MapColumnPreIndexStatsCollector extends AbstractColumnStatisticsCol
     }
   }
 
+  @Nullable
   @Override
   public String getMinValue() {
     if (_sealed) {
-      return _sortedKeys[0];
+      return _sortedKeys.length > 0 ? _sortedKeys[0] : null;
     }
     throw new IllegalStateException("you must seal the collector first before asking for min value");
   }
 
+  @Nullable
   @Override
   public String getMaxValue() {
     if (_sealed) {
-      return _sortedKeys[_sortedKeys.length - 1];
+      return _sortedKeys.length > 0 ? _sortedKeys[_sortedKeys.length - 1] : null;
     }
     throw new IllegalStateException("you must seal the collector first before asking for max value");
   }
 
+  @Nullable
   @Override
   public String[] getUniqueValuesSet() {
     if (_sealed) {
-      return _sortedKeys;
+      return _sortedKeys.length > 0 ? _sortedKeys : null;
     }
     throw new IllegalStateException("you must seal the collector first before asking for unique values set");
   }
diff --git a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollectorTest.java b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollectorTest.java
index ae9b8c5a233..0c09fda42f2 100644
--- a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollectorTest.java
+++ b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollectorTest.java
@@ -501,6 +501,53 @@ public class MapColumnPreIndexStatsCollectorTest {
     assertEquals(keys1, keys2);
   }
 
+  @Test
+  public void testAllEmptyMaps() {
+    StatsCollectorConfig cfg = newConfig(false);
+    MapColumnPreIndexStatsCollector col = new MapColumnPreIndexStatsCollector("col", cfg);
+
+    // Collect multiple rows with empty maps
+    col.collect(new HashMap<>());
+    col.collect(new HashMap<>());
+    col.collect(new HashMap<>());
+    col.seal();
+
+    // Should not throw AIOOBE; should return null for min/max/uniqueValuesSet
+    assertNull(col.getMinValue());
+    assertNull(col.getMaxValue());
+    assertNull(col.getUniqueValuesSet());
+    assertEquals(col.getCardinality(), 0);
+    assertEquals(col.getTotalNumberOfEntries(), 3);
+    // Serialized empty map is Integer.BYTES (4) bytes
+    assertEquals(col.getLengthOfShortestElement(), Integer.BYTES);
+    assertEquals(col.getLengthOfLongestElement(), Integer.BYTES);
+    assertEquals(col.getMaxRowLengthInBytes(), Integer.BYTES);
+    assertTrue(col.getAllKeyFrequencies().isEmpty());
+  }
+
+  @Test
+  public void testMixOfEmptyAndNonEmptyMaps() {
+    StatsCollectorConfig cfg = newConfig(false);
+    MapColumnPreIndexStatsCollector col = new MapColumnPreIndexStatsCollector("col", cfg);
+
+    col.collect(new HashMap<>());
+    col.collect(Map.of("k1", "v1"));
+    col.collect(new HashMap<>());
+    col.seal();
+
+    assertEquals(col.getMinValue(), "k1");
+    assertEquals(col.getMaxValue(), "k1");
+    assertNotNull(col.getUniqueValuesSet());
+    assertEquals(col.getUniqueValuesSet(), new String[]{"k1"});
+    assertEquals(col.getCardinality(), 1);
+    assertEquals(col.getTotalNumberOfEntries(), 3);
+
+    // Key appeared in 1 of 3 rows, so seal() inserted one default null value (2 total)
+    AbstractColumnStatisticsCollector k1Stats = col.getKeyStatistics("k1");
+    assertNotNull(k1Stats);
+    assertEquals(k1Stats.getTotalNumberOfEntries(), 2);
+  }
+
   @Test
   public void testNoDictCreatesNoDictChildCollectors() {
     StatsCollectorConfig cfgNoDict = newConfig(true);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org