swapna267 commented on code in PR #17280:
URL: https://github.com/apache/iceberg/pull/17280#discussion_r3983030341


##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/source/lookup/IcebergFullCachingLookupFunction.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * 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.iceberg.flink.source.lookup;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.functions.FunctionContext;
+import org.apache.flink.table.functions.LookupFunction;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.flink.FlinkRowData;
+import org.apache.iceberg.flink.TableLoader;
+import org.apache.iceberg.flink.data.RowDataUtil;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IcebergFullCachingLookupFunction extends LookupFunction {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(IcebergFullCachingLookupFunction.class);
+
+  private final TableLoader tableLoader;
+
+  private final String[] projectedColumns;
+
+  private final RowType projectedRowType;
+
+  private final int[] lookupKeyIndices;
+
+  private final List<Expression> pushedFilters;
+
+  private final Duration refreshInterval;
+
+  private transient Table table;
+  private transient IcebergLookUpReader reader;
+  private transient RowData.FieldGetter[] lookupKeyGetters;
+  private transient RowData.FieldGetter[] cacheKeyGetters;
+  private transient RowData.FieldGetter[] rowFieldGetters;
+  private transient TypeSerializer[] fieldSerializers;
+  private transient volatile Map<RowData, List<RowData>> cache;
+  private transient volatile boolean closed;
+  private transient ScheduledExecutorService refreshExecutor;
+
+  public IcebergFullCachingLookupFunction(
+      TableLoader tableLoader,
+      String[] projectedColumns,
+      RowType projectedRowType,
+      int[] keyIndices,
+      List<Expression> pushedFilters,
+      Duration refreshInterval) {
+    this.tableLoader = tableLoader;
+    this.projectedColumns = projectedColumns;
+    this.projectedRowType = projectedRowType;
+    this.lookupKeyIndices = keyIndices;
+    this.pushedFilters = pushedFilters == null ? ImmutableList.of() : 
pushedFilters;
+    this.refreshInterval = refreshInterval;
+  }
+
+  @Override
+  public void open(FunctionContext context) throws Exception {
+    super.open(context);
+    LOG.info(
+        "IcebergFullCachingLookupFunction opening lazily, projected fields={}, 
keyIndices={}",
+        Arrays.toString(projectedColumns),
+        Arrays.toString(lookupKeyIndices));
+
+    tableLoader.open();
+    this.table = tableLoader.loadTable();
+    Schema icebergProjection = table.schema().select(projectedColumns);

Review Comment:
   As IcebergProjection is coming from Table schema and fieldGetters are based 
on index of rowType, can you verify if there are issues around reordering of 
them.



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