mxm commented on code in PR #18149: URL: https://github.com/apache/iceberg/pull/18149#discussion_r4585235708
########## flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/source/lookup/FullCacheReloadTriggerFactory.java: ########## @@ -0,0 +1,48 @@ +/* + * 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 javax.annotation.Nullable; +import org.apache.flink.annotation.Internal; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.table.connector.source.lookup.LookupOptions; +import org.apache.flink.table.connector.source.lookup.LookupOptions.LookupCacheType; +import org.apache.flink.table.connector.source.lookup.cache.trigger.CacheReloadTrigger; +import org.apache.flink.table.connector.source.lookup.cache.trigger.PeriodicCacheReloadTrigger; +import org.apache.flink.table.connector.source.lookup.cache.trigger.TimedCacheReloadTrigger; + +@Internal +public class FullCacheReloadTriggerFactory { + + public static @Nullable CacheReloadTrigger create(Configuration lookupConf) { + if (!lookupConf.contains(LookupOptions.FULL_CACHE_RELOAD_STRATEGY)) { Review Comment: It's a bit confusing to have `periodic-reload.interval`, but without `reload-strategy` set to `PERIODIC` nothing gets reloaded. There are also two more options for the fixed time loading. Should we reduce these to one option, e.g. `full-cache.reload-strategy` and set it to `FIXED=5min` or `TIME=timestamp`? ########## flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/source/TestIcebergLookupJoinSql.java: ########## @@ -288,8 +395,34 @@ private void createDimTable(Record... records) throws IOException { helper.appendToTable(dataFile); } + private static void createRepeatingOrdersTable( + TableEnvironment tableEnvironment, String tableName, int numberOfKeys) { + SqlHelpers.sql( + tableEnvironment, + "CREATE TEMPORARY TABLE %s (\n" + + " user_id BIGINT,\n" + + " proc_time AS PROCTIME()\n" + + ") WITH (\n" + + " 'connector' = 'datagen',\n" + + " 'fields.user_id.kind' = 'random',\n" + + " 'fields.user_id.min' = '1',\n" + + " 'fields.user_id.max' = '%d',\n" + + " 'rows-per-second' = '50'\n" + + ")", + tableName, + numberOfKeys); + } + private static void createOrdersTable( TableEnvironment tableEnvironment, String tableName, int numberOfRows) { + createOrdersTable(tableEnvironment, tableName, numberOfRows, ""); + } + + private static void createOrdersTable( + TableEnvironment tableEnvironment, + String tableName, + int numberOfRows, + String additionalOptions) { Review Comment: `additionalOptions` appears to be always `""`. Should we drop the parameter? ########## flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/source/lookup/IcebergFullCachingLookupFunction.java: ########## @@ -181,22 +245,32 @@ private void loadCache() throws IOException { long start = System.currentTimeMillis(); try (CloseableIterable<RowData> rows = reader.read(snapshotId)) { for (RowData row : rows) { + if (closed) { + return; + } + loaded.add(extractKey(row), rowSerializer.toBinaryRow(row).copy()); Review Comment: Is it safe to reuse the key serializer across the lookup processing and the reload trigger, which is a separate thread? I don't think RowDataSerializer is thread-safe, unless we forbid it to reuse rows. ########## flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/source/lookup/TestIcebergLookup.java: ########## @@ -247,15 +254,114 @@ void lookupFunctionAppliesPushedFilters() throws Exception { .satisfies(row -> assertRow(row, 2L, "bob", "B")); } + @Test + void lookupFunctionReloadsCacheFromTrigger() throws Exception { + Table table = createTableWithRecords(); + ManualCacheReloadTrigger reloadTrigger = new ManualCacheReloadTrigger(); + + lookupFunction = newLookupFunction(ID_KEY_INDEXES, true, reloadTrigger); + lookupFunction.open(new FunctionContext(null)); + + assertThat(lookupFunction.lookup(keyRow(1L))) + .singleElement() + .satisfies(row -> assertRow(row, 1L, "alice", "A")); + + assertThat(lookupFunction.lookup(keyRow(6L))).isEmpty(); + + appendRecords(table, ImmutableList.of(record(6L, "frank", "D"))); + + reloadTrigger.triggerReload().join(); + + assertThat(lookupFunction.lookup(keyRow(6L))) + .singleElement() + .satisfies(row -> assertRow(row, 6L, "frank", "D")); + assertThat(lookupFunction.lookup(keyRow(1L))) + .singleElement() + .satisfies(row -> assertRow(row, 1L, "alice", "A")); Review Comment: Could we also overwrite keys in this test? -- 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]
