You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/06/09 11:30:52 UTC
[GitHub] [flink-table-store] tsreaper opened a new pull request, #150: [FLINK-27973] Introduce TableWrite and TableCommit as an abstraction layer above FileStore for writing RowData
tsreaper opened a new pull request, #150:
URL: https://github.com/apache/flink-table-store/pull/150
In this step we introduce `TableWrite` and `TableCommit`. They are an abstraction layer above `FileStoreWrite`, `FileStoreCommit` and `FileStoreExpire` to provide `RowData` writing and committing.
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] JingsongLi commented on a diff in pull request #150: [FLINK-27973] Introduce TableWrite and TableCommit as an abstraction layer above FileStore for writing RowData
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on code in PR #150:
URL: https://github.com/apache/flink-table-store/pull/150#discussion_r893469308
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/table/FileStoreTable.java:
##########
@@ -40,6 +45,10 @@ public interface FileStoreTable extends Serializable {
TableRead newRead(boolean incremental);
+ TableWrite newWrite(boolean overwrite);
+
+ TableCommit newCommit(@Nullable Map<String, String> overwritePartition);
Review Comment:
I prefer a builder style:
- Normal commit: `table.newCommit().commit(...)`
- Overwrite commit: `table.newCommit().withOverwritePartition(part).commit(...)`
VS Current:
- Normal commit: `table.newCommit(null).commit(...)`
- Overwrite commit: `table.newCommit(overwritePartition).commit(...)`
This is a test and user-oriented API. Assuming that 90% of the scenarios are not overwrite, it seems unfriendly that all these scenarios need to force a null parameter to be written.
For other method interfaces, I think it's for similar reasons.
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/table/ChangelogWithKeyFileStoreTable.java:
##########
@@ -126,6 +158,35 @@ protected RecordReader.RecordIterator<RowData> rowDataRecordIteratorFromKv(
};
}
+ @Override
+ public TableWrite newWrite(boolean overwrite) {
+ SinkRecordConverter recordConverter =
+ new SinkRecordConverter(store.options().bucket(), schema);
+ return new TableWrite(store.newWrite(), recordConverter, overwrite) {
+ @Override
+ protected void writeImpl(SinkRecord record, RecordWriter writer) throws Exception {
+ switch (record.row().getRowKind()) {
+ case INSERT:
+ case UPDATE_AFTER:
+ writer.write(ValueKind.ADD, record.primaryKey(), record.row());
+ break;
+ case UPDATE_BEFORE:
+ case DELETE:
+ writer.write(ValueKind.DELETE, record.primaryKey(), record.row());
+ break;
+ default:
+ throw new UnsupportedOperationException(
+ "Unknown row kind " + record.row().getRowKind());
+ }
+ }
+ };
+ }
+
+ @Override
+ public TableCommit newCommit(@Nullable Map<String, String> overwritePartition) {
+ return new TableCommit(store.newCommit(), store.newExpire(), overwritePartition);
Review Comment:
What is the different? Just provide in `AbstractFileStoreTable`?
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] JingsongLi commented on a diff in pull request #150: [FLINK-27973] Introduce TableWrite and TableCommit as an abstraction layer above FileStore for writing RowData
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on code in PR #150:
URL: https://github.com/apache/flink-table-store/pull/150#discussion_r893482664
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/table/sink/TableWrite.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.table.sink;
+
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.store.file.operation.FileStoreWrite;
+import org.apache.flink.table.store.file.writer.RecordWriter;
+import org.apache.flink.util.concurrent.ExecutorThreadFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/** An abstraction layer above {@link FileStoreWrite} to provide {@link RowData} writing. */
+public abstract class TableWrite {
+
+ private final FileStoreWrite write;
+ private final SinkRecordConverter recordConverter;
+ private final boolean overwrite;
+
+ private final Map<BinaryRowData, Map<Integer, RecordWriter>> writers;
+ private final ExecutorService compactExecutor;
+
+ protected TableWrite(
+ FileStoreWrite write, SinkRecordConverter recordConverter, boolean overwrite) {
+ this.write = write;
+ this.recordConverter = recordConverter;
+ this.overwrite = overwrite;
+
+ this.writers = new HashMap<>();
+ this.compactExecutor =
+ Executors.newSingleThreadScheduledExecutor(
+ new ExecutorThreadFactory("compaction-thread"));
+ }
+
+ public void write(RowData rowData) throws Exception {
+ SinkRecord record = recordConverter.convert(rowData);
+ RecordWriter writer = getWriter(record.partition(), record.bucket());
+ writeImpl(record, writer);
+ }
+
+ public List<FileCommittable> prepareCommit() throws Exception {
+ List<FileCommittable> result = new ArrayList<>();
+
+ Iterator<Map.Entry<BinaryRowData, Map<Integer, RecordWriter>>> partIter =
+ writers.entrySet().iterator();
+ while (partIter.hasNext()) {
+ Map.Entry<BinaryRowData, Map<Integer, RecordWriter>> partEntry = partIter.next();
+ BinaryRowData partition = partEntry.getKey();
+ Iterator<Map.Entry<Integer, RecordWriter>> bucketIter =
+ partEntry.getValue().entrySet().iterator();
+ while (bucketIter.hasNext()) {
+ Map.Entry<Integer, RecordWriter> entry = bucketIter.next();
+ int bucket = entry.getKey();
+ RecordWriter writer = entry.getValue();
+ FileCommittable committable =
+ new FileCommittable(partition, bucket, writer.prepareCommit());
+ result.add(committable);
+
+ // clear if no update
+ // we need a mechanism to clear writers, otherwise there will be more and more
+ // such as yesterday's partition that no longer needs to be written.
+ if (committable.increment().newFiles().isEmpty()) {
+ closeWriter(writer);
+ bucketIter.remove();
+ }
+ }
+
+ if (partEntry.getValue().isEmpty()) {
+ partIter.remove();
+ }
+ }
+
+ return result;
+ }
+
+ private void closeWriter(RecordWriter writer) throws Exception {
+ writer.sync();
+ writer.close();
+ }
+
+ public void close() throws Exception {
+ compactExecutor.shutdownNow();
+ for (Map<Integer, RecordWriter> bucketWriters : writers.values()) {
+ for (RecordWriter writer : bucketWriters.values()) {
+ closeWriter(writer);
+ }
+ }
+ writers.clear();
+ }
+
+ protected abstract void writeImpl(SinkRecord record, RecordWriter writer) throws Exception;
Review Comment:
Put `writeImpl` next to `write`?
Maybe a better a name: `writeSinkRecord`. `writeImpl` dose not bring any useful message.
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] JingsongLi commented on a diff in pull request #150: [FLINK-27973] Introduce TableWrite and TableCommit as an abstraction layer above FileStore for writing RowData
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on code in PR #150:
URL: https://github.com/apache/flink-table-store/pull/150#discussion_r893484862
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/table/ChangelogWithKeyFileStoreTable.java:
##########
@@ -103,7 +115,27 @@ public TableScan newScan(boolean incremental) {
return new TableScan(scan, schema, store.pathFactory()) {
@Override
protected void withNonPartitionFilter(Predicate predicate) {
- scan.withValueFilter(predicate);
+ // currently we can only perform filter push down on keys
+ // consider this case:
+ // data file 1: insert key = a, value = 1
+ // data file 2: update key = a, value = 2
+ // filter: value = 1
+ // if we perform filter push down on values, data file 1 will be chosen, but data
+ // file 2 will be ignored, and the final result will be key = a, value = 1 while the
+ // correct result is an empty set
Review Comment:
Add a TODO to support value filter.
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink-table-store] JingsongLi merged pull request #150: [FLINK-27973] Introduce TableWrite and TableCommit as an abstraction layer above FileStore for writing RowData
Posted by GitBox <gi...@apache.org>.
JingsongLi merged PR #150:
URL: https://github.com/apache/flink-table-store/pull/150
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org