JingsongLi commented on code in PR #2605: URL: https://github.com/apache/incubator-paimon/pull/2605#discussion_r1440020941
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/lookup/PrimaryKeyLRULookupTable.java: ########## @@ -0,0 +1,117 @@ +/* + * 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.paimon.flink.lookup; + +import org.apache.paimon.data.BinaryRow; +import org.apache.paimon.data.InternalRow; +import org.apache.paimon.disk.IOManagerImpl; +import org.apache.paimon.io.DataFileMeta; +import org.apache.paimon.table.FileStoreTable; +import org.apache.paimon.table.query.TableQuery; +import org.apache.paimon.table.source.DataSplit; +import org.apache.paimon.table.source.Split; +import org.apache.paimon.utils.Projection; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.function.Predicate; + +/** Lookup table for primary key which supports to read the LSM tree directly. */ +public class PrimaryKeyLRULookupTable implements LookupTable { + + private static final Logger LOG = LoggerFactory.getLogger(PrimaryKeyLRULookupTable.class); + + private final FixedBucketKeyExtractor extractor; + + private final TableQuery tableQuery; + + public PrimaryKeyLRULookupTable(FileStoreTable table, int[] projection, File path) { + this.tableQuery = + table.newTableQuery() + .withValueProjection(Projection.of(projection).toNestedIndexes()) + .withIOManager(new IOManagerImpl(path.toString())); + this.extractor = new FixedBucketKeyExtractor(table.schema()); + } + + @Override + public List<InternalRow> get(InternalRow key) throws IOException { + extractor.setRecord(key); + int bucket = extractor.bucket(); + BinaryRow partition = extractor.partition(); + + InternalRow kv = tableQuery.lookup(partition, bucket, key); + if (kv == null) { + return Collections.emptyList(); + } else { + return Collections.singletonList(kv); + } + } + + @Override + public void refresh(List<Split> splits) { + for (Split split : splits) { + if (!(split instanceof DataSplit)) { + throw new IllegalArgumentException("Unsupported split: " + split.getClass()); + } + BinaryRow partition = ((DataSplit) split).partition(); + int bucket = ((DataSplit) split).bucket(); + List<DataFileMeta> before = ((DataSplit) split).beforeFiles(); + List<DataFileMeta> after = ((DataSplit) split).dataFiles(); + + tableQuery.refreshFiles(partition, bucket, before, after); + } + } + + @Override + public Predicate<InternalRow> recordFilter() { + throw new UnsupportedOperationException(); Review Comment: So many `UnsupportedOperationException`s, you could add an interface `FullCacheLookupTable`? ########## paimon-core/src/main/java/org/apache/paimon/table/query/TableQueryImpl.java: ########## @@ -0,0 +1,197 @@ +/* + * + * 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.paimon.table.query; + +import org.apache.paimon.CoreOptions; +import org.apache.paimon.KeyValue; +import org.apache.paimon.data.BinaryRow; +import org.apache.paimon.data.InternalRow; +import org.apache.paimon.disk.IOManager; +import org.apache.paimon.format.FileFormatDiscover; +import org.apache.paimon.io.DataFileMeta; +import org.apache.paimon.io.KeyValueFileReaderFactory; +import org.apache.paimon.io.cache.CacheManager; +import org.apache.paimon.lookup.hash.HashLookupStoreFactory; +import org.apache.paimon.mergetree.Levels; +import org.apache.paimon.mergetree.LookupLevels; +import org.apache.paimon.schema.KeyValueFieldsExtractor; +import org.apache.paimon.schema.SchemaManager; +import org.apache.paimon.table.FileStoreTable; +import org.apache.paimon.table.PrimaryKeyTableUtils; +import org.apache.paimon.types.RowType; +import org.apache.paimon.utils.FileStorePathFactory; +import org.apache.paimon.utils.KeyComparatorSupplier; +import org.apache.paimon.utils.Preconditions; +import org.apache.paimon.utils.Projection; + +import javax.annotation.Nullable; + +import java.io.IOException; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +import static org.apache.paimon.CoreOptions.LOOKUP_CACHE_MAX_MEMORY_SIZE; + +/** Implementation for {@link TableQuery}. */ +public class TableQueryImpl implements TableQuery { Review Comment: Can you add some tests in `PrimaryKeyFileStoreTableTest`? ########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkConnectorOptions.java: ########## @@ -280,6 +280,13 @@ public class FlinkConnectorOptions { .defaultValue(16) .withDescription("The thread number for lookup async."); + @ExcludeFromDocumentation("Not finish yet") Review Comment: `Not finish yet`? What is the next? ########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkConnectorOptions.java: ########## @@ -280,6 +280,13 @@ public class FlinkConnectorOptions { .defaultValue(16) .withDescription("The thread number for lookup async."); + @ExcludeFromDocumentation("Not finish yet") + public static final ConfigOption<LookupCacheMode> LOOKUP_CACHE_MODE = + ConfigOptions.key("lookup.cache.mode") Review Comment: See `https://cwiki.apache.org/confluence/display/FLINK/FLIP-221%3A+Abstraction+for+lookup+source+cache+and+metric`. lookup.cache => Enum of NONE, PARTIAL and FULL We are better to be consistent with Flink. -- 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]
