krishan1390 commented on code in PR #16727:
URL: https://github.com/apache/pinot/pull/16727#discussion_r2447694277


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/stats/ColumnarSegmentPreIndexStatsContainer.java:
##########
@@ -0,0 +1,217 @@
+/**
+ * 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.pinot.segment.local.segment.creator.impl.stats;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pinot.segment.spi.creator.ColumnStatistics;
+import org.apache.pinot.segment.spi.creator.SegmentPreIndexStatsCollector;
+import org.apache.pinot.segment.spi.creator.StatsCollectorConfig;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.data.readers.ColumnReader;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Stats container that efficiently collects statistics from columnar data 
using ColumnReader instances.
+ *
+ * <p>This implementation collects statistics by iterating column-wise instead 
of row-wise,
+ * which is more efficient for columnar data sources. It supports:
+ * <ul>
+ *   <li>Column-wise statistics collection</li>
+ *   <li>Existing columns from source data</li>
+ *   <li>New columns with default values</li>
+ *   <li>Data type conversions during schema evolution</li>
+ * </ul>
+ *
+ * <p>The statistics are collected using the same underlying collectors as the 
row-based approach
+ * (SegmentPreIndexStatsCollectorImpl) but with more efficient column-wise 
iteration.
+ */
+public class ColumnarSegmentPreIndexStatsContainer implements 
SegmentPreIndexStatsCollector {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(ColumnarSegmentPreIndexStatsContainer.class);
+
+  private final Map<String, ColumnReader> _columnReaders;
+  private final StatsCollectorConfig _statsCollectorConfig;
+  private final Schema _targetSchema;
+  private final Map<String, AbstractColumnStatisticsCollector> 
_columnStatsCollectorMap;
+  private int _totalDocCount;
+
+  /**
+   * Create a ColumnarSegmentPreIndexStatsContainer.
+   *
+   * @param columnReaders Map of column name to ColumnReader instances
+   * @param statsCollectorConfig Configuration for statistics collection
+   */
+  public ColumnarSegmentPreIndexStatsContainer(Map<String, ColumnReader> 
columnReaders,
+                                              StatsCollectorConfig 
statsCollectorConfig) {
+    _columnReaders = columnReaders;
+    _statsCollectorConfig = statsCollectorConfig;
+    _targetSchema = statsCollectorConfig.getSchema();
+    _columnStatsCollectorMap = new HashMap<>();
+    _totalDocCount = -1; // indicates unset
+
+    initializeStatsCollectors();
+    collectColumnStats();
+  }
+
+  /**
+   * Initialize stats collectors for all columns in the target schema.
+   */
+  private void initializeStatsCollectors() {
+    for (FieldSpec fieldSpec : _targetSchema.getAllFieldSpecs()) {
+      if (fieldSpec.isVirtualColumn()) {
+        continue;
+      }
+
+      String columnName = fieldSpec.getName();

Review Comment:
   @rohityadav1993 we should do this change before merging the PR
   
   cc @KKcorps @noob-se7en 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to