vaibhavk1992 commented on code in PR #729:
URL: https://github.com/apache/incubator-xtable/pull/729#discussion_r2559690838


##########
xtable-core/src/main/java/org/apache/xtable/kernel/DeltaKernelIncrementalChangesState.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.xtable.kernel;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import lombok.Builder;
+
+import scala.Tuple2;
+import scala.collection.JavaConverters;
+import scala.collection.Seq;
+
+import com.google.common.base.Preconditions;
+
+import io.delta.kernel.Table;
+import io.delta.kernel.data.ColumnarBatch;
+import io.delta.kernel.data.Row;
+import io.delta.kernel.engine.Engine;
+import io.delta.kernel.internal.DeltaLogActionUtils;
+import io.delta.kernel.internal.TableImpl;
+import io.delta.kernel.internal.actions.AddFile;
+import io.delta.kernel.internal.actions.RemoveFile;
+import io.delta.kernel.internal.actions.RowBackedAction;
+import io.delta.kernel.utils.CloseableIterator;
+
+/** Cache store for storing incremental table changes in the Delta table. */
+public class DeltaKernelIncrementalChangesState {
+
+  private final Map<Long, List<RowBackedAction>> incrementalChangesByVersion = 
new HashMap<>();
+
+  /**
+   * Reloads the cache store with incremental changes. Intentionally thread 
safety is the
+   * responsibility of the caller.
+   *
+   * @param engine The kernel engine.
+   * @param versionToStartFrom The version to start from.
+   */
+  @Builder
+  public DeltaKernelIncrementalChangesState(
+      Long versionToStartFrom, Engine engine, Table table, Long endVersion) {
+    Set<DeltaLogActionUtils.DeltaAction> actionSet = new HashSet<>();
+    actionSet.add(DeltaLogActionUtils.DeltaAction.ADD);
+    actionSet.add(DeltaLogActionUtils.DeltaAction.REMOVE);
+    TableImpl tableImpl = (TableImpl) Table.forPath(engine, 
table.getPath(engine));
+
+    // getChanges returns CloseableIterator<ColumnarBatch>
+    try (CloseableIterator<ColumnarBatch> iter =
+        tableImpl.getChanges(engine, versionToStartFrom, endVersion, 
actionSet)) {
+      while (iter.hasNext()) {
+        ColumnarBatch batch = iter.next();
+        int addFileIndex = 
batch.getSchema().indexOf(DeltaLogActionUtils.DeltaAction.ADD.colName);
+        int removeFileIndex =
+            
batch.getSchema().indexOf(DeltaLogActionUtils.DeltaAction.REMOVE.colName);
+
+        try (CloseableIterator<Row> rows = batch.getRows()) {
+          while (rows.hasNext()) {
+            Row row = rows.next();
+
+            // Get version (first column)
+            long version = row.getLong(0);
+            List<RowBackedAction> actions =
+                incrementalChangesByVersion.computeIfAbsent(version, k -> new 
ArrayList<>());
+
+            if (!row.isNullAt(addFileIndex)) {
+              Row addFile = row.getStruct(addFileIndex);
+              AddFile addAction = new AddFile(addFile);
+              actions.add(addAction);
+            }
+            if (!row.isNullAt(removeFileIndex)) {
+              Row removeFile = row.getStruct(removeFileIndex);
+              RemoveFile removeAction = new RemoveFile(removeFile);
+              actions.add(removeAction);
+            }
+          }
+        }
+      }
+    } catch (Exception e) {
+      throw new RuntimeException("Error reading kernel changes", e);

Review Comment:
   Ok, added the read exception



##########
xtable-core/src/main/java/org/apache/xtable/kernel/DeltaKernelIncrementalChangesState.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.xtable.kernel;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import lombok.Builder;
+
+import scala.Tuple2;
+import scala.collection.JavaConverters;
+import scala.collection.Seq;
+
+import com.google.common.base.Preconditions;
+
+import io.delta.kernel.Table;
+import io.delta.kernel.data.ColumnarBatch;
+import io.delta.kernel.data.Row;
+import io.delta.kernel.engine.Engine;
+import io.delta.kernel.internal.DeltaLogActionUtils;
+import io.delta.kernel.internal.TableImpl;
+import io.delta.kernel.internal.actions.AddFile;
+import io.delta.kernel.internal.actions.RemoveFile;
+import io.delta.kernel.internal.actions.RowBackedAction;
+import io.delta.kernel.utils.CloseableIterator;
+
+/** Cache store for storing incremental table changes in the Delta table. */
+public class DeltaKernelIncrementalChangesState {
+
+  private final Map<Long, List<RowBackedAction>> incrementalChangesByVersion = 
new HashMap<>();
+
+  /**
+   * Reloads the cache store with incremental changes. Intentionally thread 
safety is the
+   * responsibility of the caller.
+   *
+   * @param engine The kernel engine.
+   * @param versionToStartFrom The version to start from.
+   */
+  @Builder
+  public DeltaKernelIncrementalChangesState(
+      Long versionToStartFrom, Engine engine, Table table, Long endVersion) {

Review Comment:
   changes has been done.



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

Reply via email to