FrankChen021 commented on code in PR #19510:
URL: https://github.com/apache/druid/pull/19510#discussion_r3294101280


##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergInputSource.java:
##########
@@ -113,6 +125,16 @@ public InputSourceReader reader(
       File temporaryDirectory
   )
   {
+    if (useArrowReader) {

Review Comment:
   [P1] Arrow path bypasses residual FAIL handling
   
   The useArrowReader branch returns an IcebergArrowInputSourceReader before 
retrieveIcebergDatafiles() runs, so it skips the residual detection that 
enforces residualFilterMode=FAIL. IcebergArrowInputSourceReaderTest documents 
that a non-partition equality filter returns all rows from the file, so a spec 
with useArrowReader=true and residualFilterMode=FAIL will silently ingest 
residual rows instead of rejecting the ingestion. Please run the same residual 
check for the Arrow scan or otherwise honor the fail mode before reading.



##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergInputSource.java:
##########
@@ -113,6 +125,16 @@ public InputSourceReader reader(
       File temporaryDirectory
   )
   {
+    if (useArrowReader) {

Review Comment:
   [P2] Parallel ingestion bypasses the Arrow reader
   
   This special case only affects direct reader() calls. The input source still 
reports itself as splittable, and Druid's parallel task runners call 
createSplits() and then withSplit(); withSplit() returns the delegate input 
source, so subtasks read raw files through the old delegate path instead of 
IcebergArrowInputSourceReader. With useArrowReader=true, behavior therefore 
changes based on maxNumConcurrentSubTasks and can lose the Arrow path's Iceberg 
semantics. Please make the Arrow mode non-splittable or return split-aware 
Iceberg input sources that preserve useArrowReader.



##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergArrowInputSourceReader.java:
##########
@@ -0,0 +1,383 @@
+/*
+ * 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.druid.iceberg.input;
+
+import com.google.common.collect.Maps;
+import org.apache.arrow.vector.BigIntVector;
+import org.apache.arrow.vector.BitVector;
+import org.apache.arrow.vector.DateDayVector;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.FixedSizeBinaryVector;
+import org.apache.arrow.vector.Float4Vector;
+import org.apache.arrow.vector.Float8Vector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.SmallIntVector;
+import org.apache.arrow.vector.TimeMicroVector;
+import org.apache.arrow.vector.TimeStampMicroTZVector;
+import org.apache.arrow.vector.TimeStampMicroVector;
+import org.apache.arrow.vector.TimeStampMilliTZVector;
+import org.apache.arrow.vector.TimeStampMilliVector;
+import org.apache.arrow.vector.TimeStampNanoTZVector;
+import org.apache.arrow.vector.TimeStampNanoVector;
+import org.apache.arrow.vector.TinyIntVector;
+import org.apache.arrow.vector.VarBinaryVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.data.input.InputRowListPlusRawValues;
+import org.apache.druid.data.input.InputRowSchema;
+import org.apache.druid.data.input.InputSourceReader;
+import org.apache.druid.data.input.InputStats;
+import org.apache.druid.data.input.MapBasedInputRow;
+import org.apache.druid.iceberg.filter.IcebergFilter;
+import org.apache.druid.java.util.common.parsers.CloseableIterator;
+import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableScan;
+import org.apache.iceberg.arrow.vectorized.ArrowReader;
+import org.apache.iceberg.arrow.vectorized.ColumnarBatch;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.util.TableScanUtil;
+import org.joda.time.DateTime;
+
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Reads an Iceberg table via iceberg-arrow's {@link ArrowReader}, yielding 
{@link InputRow} objects.
+ *
+ * Delete application (V2 equality and positional deletes), type coercion, and 
schema evolution are
+ * handled entirely by the Iceberg library. Druid only consumes the resulting 
{@link ColumnarBatch}
+ * batches and maps them to {@link MapBasedInputRow}.
+ *
+ * Column projection and predicate push-down are applied at scan planning time 
so only requested
+ * columns and matching files are read from storage.
+ *
+ * Note: iceberg-arrow currently supports Parquet data files only. ORC and 
Avro files will throw
+ * {@link UnsupportedOperationException} at read time; use the standard 
delegate path for those.
+ */
+public class IcebergArrowInputSourceReader implements InputSourceReader
+{
+  static final int DEFAULT_BATCH_SIZE = 1024;
+
+  private final Table table;
+  @Nullable
+  private final IcebergFilter icebergFilter;
+  @Nullable
+  private final DateTime snapshotTime;
+  private final boolean caseSensitive;
+  private final InputRowSchema schema;
+  private final int batchSize;
+
+  public IcebergArrowInputSourceReader(
+      final Table table,
+      @Nullable final IcebergFilter icebergFilter,
+      @Nullable final DateTime snapshotTime,
+      final boolean caseSensitive,
+      final InputRowSchema schema,
+      final int batchSize
+  )
+  {
+    this.table = table;
+    this.icebergFilter = icebergFilter;
+    this.snapshotTime = snapshotTime;
+    this.caseSensitive = caseSensitive;
+    this.schema = schema;
+    this.batchSize = batchSize;
+  }
+
+  @Override
+  public CloseableIterator<InputRow> read(final InputStats inputStats) throws 
IOException
+  {
+    final TableScan scan = buildScan();
+    final CloseableIterable<CombinedScanTask> tasks = TableScanUtil.planTasks(
+        scan.planFiles(),
+        scan.targetSplitSize(),
+        scan.splitLookback(),
+        scan.splitOpenFileCost()
+    );
+    final ArrowReader arrowReader = new ArrowReader(scan, batchSize, true);
+    final org.apache.iceberg.io.CloseableIterator<ColumnarBatch> batchIter = 
arrowReader.open(tasks);
+    return new ArrowInputRowIterator(batchIter, arrowReader, tasks, 
inputStats);
+  }
+
+  @Override
+  public CloseableIterator<InputRowListPlusRawValues> sample() throws 
IOException
+  {
+    final CloseableIterator<InputRow> rows = read(new NoopInputStats());
+    return new CloseableIterator<InputRowListPlusRawValues>()
+    {
+      @Override
+      public boolean hasNext()
+      {
+        return rows.hasNext();
+      }
+
+      @Override
+      public InputRowListPlusRawValues next()
+      {
+        final InputRow row = rows.next();
+        return InputRowListPlusRawValues.of(row, ((MapBasedInputRow) 
row).getEvent());
+      }
+
+      @Override
+      public void close() throws IOException
+      {
+        rows.close();
+      }
+    };
+  }
+
+  private TableScan buildScan()
+  {
+    TableScan scan = table.newScan().caseSensitive(caseSensitive);
+
+    // Push column projection into the scan planner — only requested columns 
are read from disk.
+    final List<String> configuredDims = 
schema.getDimensionsSpec().getDimensionNames();
+    final String timestampColumn = 
schema.getTimestampSpec().getTimestampColumn();
+    if (!configuredDims.isEmpty()) {

Review Comment:
   [P1] Projection omits required non-dimension columns
   
   When fixed dimensions are configured, this projection selects only those 
dimension names plus the timestamp column. Druid carries required transform 
inputs and aggregator source fields through InputRowSchema.getColumnsFilter(), 
not DimensionsSpec alone. For example, dimensions=[name] with an aggregator 
over value will scan only ts/name, so value is missing from the event and 
downstream metrics/transforms read null. Please drive projection from the full 
columnsFilter/required fields, or avoid pruning when those required columns 
cannot be represented safely.



-- 
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