tsreaper commented on a change in pull request #14: URL: https://github.com/apache/flink-table-store/pull/14#discussion_r793200709
########## File path: flink-table-store-core/src/main/java/org/apache/flink/table/store/file/operation/FileStoreWriteImpl.java ########## @@ -0,0 +1,107 @@ +/* + * 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.flink.table.store.file.operation; + +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.data.binary.BinaryRowData; +import org.apache.flink.table.store.file.FileFormat; +import org.apache.flink.table.store.file.manifest.ManifestEntry; +import org.apache.flink.table.store.file.mergetree.MergeTree; +import org.apache.flink.table.store.file.mergetree.MergeTreeOptions; +import org.apache.flink.table.store.file.mergetree.compact.Accumulator; +import org.apache.flink.table.store.file.mergetree.sst.SstFile; +import org.apache.flink.table.store.file.utils.FileStorePathFactory; +import org.apache.flink.table.store.file.utils.RecordWriter; +import org.apache.flink.table.types.logical.RowType; + +import java.util.Collections; +import java.util.Comparator; +import java.util.concurrent.ExecutorService; +import java.util.stream.Collectors; + +/** Default implementation of {@link FileStoreWrite}. */ +public class FileStoreWriteImpl implements FileStoreWrite { + + private final RowType keyType; + private final RowType rowType; + private final Comparator<RowData> keyComparator; + private final Accumulator accumulator; + private final FileFormat fileFormat; + private final FileStorePathFactory pathFactory; + private final MergeTreeOptions mergeTreeOptions; + + private final FileStoreScan scan; + + public FileStoreWriteImpl( + RowType partitionType, + RowType keyType, + RowType rowType, + Comparator<RowData> keyComparator, + Accumulator accumulator, + FileFormat fileFormat, + FileStorePathFactory pathFactory, + MergeTreeOptions mergeTreeOptions) { + this.keyType = keyType; + this.rowType = rowType; + this.keyComparator = keyComparator; + this.accumulator = accumulator; + this.fileFormat = fileFormat; + this.pathFactory = pathFactory; + this.mergeTreeOptions = mergeTreeOptions; + + this.scan = new FileStoreScanImpl(partitionType, keyType, rowType, fileFormat, pathFactory); + } + + @Override + public RecordWriter createWriter( + BinaryRowData partition, int bucket, ExecutorService compactExecutor) { + Long latestSnapshotId = pathFactory.latestSnapshotId(); + if (latestSnapshotId == null) { + return createEmptyWriter(partition, bucket, compactExecutor); + } else { + MergeTree mergeTree = createMergeTree(partition, bucket, compactExecutor); + return mergeTree.createWriter( + scan.withSnapshot(latestSnapshotId) + .withPartitionFilter(Collections.singletonList(partition)) + .withBucket(bucket).plan().files().stream() + .map(ManifestEntry::file) + .collect(Collectors.toList())); + } + } + + @Override + public RecordWriter createEmptyWriter( + BinaryRowData partition, int bucket, ExecutorService compactExecutor) { + MergeTree mergeTree = createMergeTree(partition, bucket, compactExecutor); + return mergeTree.createWriter(Collections.emptyList()); + } + + private MergeTree createMergeTree( Review comment: Could you elaborate more on what exactly should be considered? Writers will be created when a new partition or bucket is written. As each bucket is itself a `MergeTree` we'll need to create one anyway. -- 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]
