pvary commented on code in PR #18144: URL: https://github.com/apache/iceberg/pull/18144#discussion_r4069731757
########## flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/source/lookup/IcebergFullCachingLookupFunction.java: ########## @@ -0,0 +1,244 @@ +/* + * 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.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.metrics.Counter; +import org.apache.flink.metrics.MetricGroup; +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.Snapshot; +import org.apache.iceberg.Table; +import org.apache.iceberg.TableProperties; +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.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.types.Types; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A full caching lookup function: the whole projected Iceberg dimension table is loaded into an + * in-memory cache on the first lookup, and every lookup is served from that cache. + */ +public class IcebergFullCachingLookupFunction extends LookupFunction { + + private static final Logger LOG = LoggerFactory.getLogger(IcebergFullCachingLookupFunction.class); + + private static final String METRIC_GROUP = "icebergLookupCache"; + private static final long UNKNOWN = -1L; + + private final TableLoader tableLoader; + private final RowType projectedRowType; + private final int[] lookupKeyIndices; + private final List<Expression> pushedFilters; + private final boolean caseSensitive; + private final boolean eagerLoad; + + 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 IcebergLookupCache cache; + + private transient Counter cacheHitCounter; + private transient Counter cacheMissCounter; + private transient volatile long currentSnapshotId; + private transient volatile int cachedRows; + + public IcebergFullCachingLookupFunction( + TableLoader tableLoader, + RowType projectedRowType, + int[] keyIndices, + List<Expression> pushedFilters, + boolean caseSensitive, + boolean eagerLoad) { + this.tableLoader = tableLoader; + this.projectedRowType = projectedRowType; + this.lookupKeyIndices = keyIndices; + this.pushedFilters = pushedFilters == null ? ImmutableList.of() : pushedFilters; + this.caseSensitive = caseSensitive; + this.eagerLoad = eagerLoad; Review Comment: Maybe on `eagerLoad` we should get a snapshotId, to read - so at least we have a consistent view of the data in the beginning. Later we loose this with refresh, but at least provide the possiblity? WDYT? -- 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]
