vkorukanti commented on code in PR #15755:
URL: https://github.com/apache/druid/pull/15755#discussion_r1476750537


##########
extensions-contrib/druid-deltalake-extensions/src/main/java/org/apache/druid/delta/input/DeltaInputSourceReader.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.delta.input;
+
+import io.delta.kernel.data.FilteredColumnarBatch;
+import io.delta.kernel.data.Row;
+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.java.util.common.parsers.CloseableIterator;
+
+import java.io.IOException;
+import java.util.NoSuchElementException;
+
+/**
+ * A reader for the Delta Lake input source. It initializes an iterator {@link 
DeltaInputSourceIterator}
+ * for a subset of Delta records given by {@link FilteredColumnarBatch} and 
schema {@link InputRowSchema}.
+ *
+ */
+public class DeltaInputSourceReader implements InputSourceReader
+{
+  private final io.delta.kernel.utils.CloseableIterator<FilteredColumnarBatch> 
filteredColumnarBatchCloseableIterator;
+  private final InputRowSchema inputRowSchema;
+
+  public DeltaInputSourceReader(
+      io.delta.kernel.utils.CloseableIterator<FilteredColumnarBatch> 
filteredColumnarBatchCloseableIterator,
+      InputRowSchema inputRowSchema
+  )
+  {
+    this.filteredColumnarBatchCloseableIterator = 
filteredColumnarBatchCloseableIterator;
+    this.inputRowSchema = inputRowSchema;
+  }
+
+  @Override
+  public CloseableIterator<InputRow> read()
+  {
+    return new 
DeltaInputSourceIterator(filteredColumnarBatchCloseableIterator, 
inputRowSchema);
+  }
+
+  @Override
+  public CloseableIterator<InputRow> read(InputStats inputStats)
+  {
+    return new 
DeltaInputSourceIterator(filteredColumnarBatchCloseableIterator, 
inputRowSchema);
+  }
+
+  @Override
+  public CloseableIterator<InputRowListPlusRawValues> sample()
+  {
+
+    CloseableIterator<InputRow> inner = read();
+    return new CloseableIterator<InputRowListPlusRawValues>()
+    {
+      @Override
+      public void close() throws IOException
+      {
+        inner.close();
+      }
+
+      @Override
+      public boolean hasNext()
+      {
+        return inner.hasNext();
+      }
+
+      @Override
+      public InputRowListPlusRawValues next()
+      {
+        DeltaInputRow deltaInputRow = (DeltaInputRow) inner.next();
+        return InputRowListPlusRawValues.of(deltaInputRow, 
deltaInputRow.getRawRowAsMap());
+      }
+    };
+  }
+
+  private static class DeltaInputSourceIterator implements 
CloseableIterator<InputRow>
+  {
+    private final 
io.delta.kernel.utils.CloseableIterator<FilteredColumnarBatch> 
filteredColumnarBatchCloseableIterator;
+
+    private io.delta.kernel.utils.CloseableIterator<Row> currentBatch = null;
+    private final InputRowSchema inputRowSchema;
+
+    public DeltaInputSourceIterator(
+        io.delta.kernel.utils.CloseableIterator<FilteredColumnarBatch> 
filteredColumnarBatchCloseableIterator,
+        InputRowSchema inputRowSchema
+    )
+    {
+      this.filteredColumnarBatchCloseableIterator = 
filteredColumnarBatchCloseableIterator;
+      this.inputRowSchema = inputRowSchema;
+    }
+
+    @Override
+    public boolean hasNext()
+    {
+      while (currentBatch == null || !currentBatch.hasNext()) {
+        if (!filteredColumnarBatchCloseableIterator.hasNext()) {
+          return false; // No more batches or records to read!
+        }
+        currentBatch = filteredColumnarBatchCloseableIterator.next().getRows();

Review Comment:
   one qn: do we want to check if the `currentBatch` can return `hasNext` to 
true? because it could contain zero rows due to the selection vector.



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