EMsnap commented on code in PR #7878:
URL: https://github.com/apache/inlong/pull/7878#discussion_r1174498802


##########
inlong-sort/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/collections/PartitionGroupBuffer.java:
##########
@@ -0,0 +1,364 @@
+/*
+ * 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.inlong.sort.iceberg.sink.collections;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.typeutils.base.StringSerializer;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TupleTypeInfo;
+import org.apache.flink.core.memory.DataInputDeserializer;
+import org.apache.flink.core.memory.DataOutputSerializer;
+import org.apache.flink.shaded.guava18.com.google.common.base.Preconditions;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.RowData.FieldGetter;
+import org.apache.flink.table.data.util.RowDataUtil;
+import org.apache.flink.table.runtime.operators.sort.SortUtil;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+import org.apache.iceberg.PartitionKey;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.flink.FlinkSchemaUtil;
+import org.apache.iceberg.flink.RowDataWrapper;
+import org.apache.iceberg.types.Types.NestedField;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public abstract class PartitionGroupBuffer implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    protected final KVBuffer<?, RowData> buffer;
+    protected final PartitionKey partitionKey; // partition key helper
+    protected final Schema rowSchema; // the whole field schema
+    protected final Set<String> allPartition;
+    private transient RowDataWrapper wrapper;
+
+    private PartitionGroupBuffer(
+            KVBuffer<?, RowData> buffer,
+            PartitionKey partitionKey,
+            Schema rowSchema) {
+        this.buffer = buffer;
+        this.partitionKey = partitionKey;
+        this.rowSchema = rowSchema;
+        this.allPartition = new HashSet<>();
+    }
+
+    public abstract RowData add(RowData row);
+
+    public void scanPartitions(Consumer<Tuple2<?, RowData>> consumer) throws 
IOException {
+        DataOutputSerializer outputBuffer = new DataOutputSerializer(4096);
+        for (String partition : allPartition) {
+            StringSerializer.INSTANCE.serialize(partition, outputBuffer);
+            try (Stream<? extends Tuple2<?, RowData>> stream = 
buffer.scan(outputBuffer.getCopyOfBuffer())) {
+                stream.forEach(tuple -> consumer.accept(tuple));

Review Comment:
   could be simplified to stream.forEach(consumer);



-- 
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: commits-unsubscr...@inlong.apache.org

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

Reply via email to