JingsongLi commented on a change in pull request #14:
URL: https://github.com/apache/flink-table-store/pull/14#discussion_r792393666



##########
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(
+            BinaryRowData partition, int bucket, ExecutorService 
compactExecutor) {
+        SstFile sstFile =
+                new SstFile(
+                        keyType,
+                        rowType,
+                        fileFormat,
+                        pathFactory.createSstPathFactory(partition, bucket),

Review comment:
       Can uuid be reused in `SstPathFactory` from `FileStorePathFactory`?

##########
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(
+            BinaryRowData partition, int bucket, ExecutorService 
compactExecutor) {
+        SstFile sstFile =
+                new SstFile(

Review comment:
       Can `readerFactory` and `writerFactory` be reused?

##########
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:
       We should consider the cost for creating a `MergeTree`.




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to