hililiwei commented on code in PR #4904: URL: https://github.com/apache/iceberg/pull/4904#discussion_r947380756
########## flink/v1.15/flink/src/main/java/org/apache/iceberg/flink/sink/writer/StreamWriter.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.iceberg.flink.sink.writer; + +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import org.apache.flink.api.connector.sink2.SinkWriter; +import org.apache.flink.api.connector.sink2.StatefulSink.StatefulSinkWriter; +import org.apache.flink.api.connector.sink2.TwoPhaseCommittingSink; +import org.apache.flink.table.data.RowData; +import org.apache.iceberg.flink.sink.TaskWriterFactory; +import org.apache.iceberg.flink.sink.committer.FilesCommittable; +import org.apache.iceberg.io.TaskWriter; +import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; + +public class StreamWriter + implements StatefulSinkWriter<RowData, StreamWriterState>, + SinkWriter<RowData>, + TwoPhaseCommittingSink.PrecommittingSinkWriter<RowData, FilesCommittable> { + private static final long serialVersionUID = 1L; + + private final String fullTableName; + private final TaskWriterFactory<RowData> taskWriterFactory; + private transient TaskWriter<RowData> writer; + private transient int subTaskId; + private final List<FilesCommittable> writeResultsState = Lists.newArrayList(); + + public StreamWriter( + String fullTableName, + TaskWriterFactory<RowData> taskWriterFactory, + int subTaskId, + int numberOfParallelSubtasks) { + this.fullTableName = fullTableName; + this.subTaskId = subTaskId; + + this.taskWriterFactory = taskWriterFactory; + // Initialize the task writer factory. + taskWriterFactory.initialize(numberOfParallelSubtasks, subTaskId); Review Comment: Nice catch. Honestly, this is one of the things that puzzled me. So let's talk about it. There is only one implementation of `initialize`: ``` @Override public void initialize(int taskId, int attemptId) { this.outputFileFactory = OutputFileFactory.builderFor(table, taskId, attemptId).format(format).build(); } ``` And the signature of `OutputFileFactory.builderFor` goes like this: ``` public static Builder builderFor(Table table, int partitionId, long taskId) { return new Builder(table, partitionId, taskId); } ``` so, in the `initialize` method, the pass-through relationship is as follows: ``` initialize:taskId -> builderFor.partitionId initialize:attemptId -> builderFor.taskId ``` It makes me feel a little confused. I'm trying to reestablish this relationship here: ``` numberOfParallelSubtasks -> builderFor.partitionId subTaskId -> builderFor.taskId ``` -- 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]
