You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "hililiwei (via GitHub)" <gi...@apache.org> on 2023/05/09 06:27:07 UTC

[GitHub] [iceberg] hililiwei commented on a diff in pull request #7494: Flink: change sink shuffle to use RowData as data type and statistics key type

hililiwei commented on code in PR #7494:
URL: https://github.com/apache/iceberg/pull/7494#discussion_r1188185907


##########
flink/v1.17/flink/src/main/java/org/apache/iceberg/flink/sink/shuffle/DataStatisticsOrRecordSerializer.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * 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.shuffle;
+
+import java.io.IOException;
+import java.util.Objects;
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeutils.CompositeTypeSerializerSnapshot;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.table.data.RowData;
+
+@Internal
+class DataStatisticsOrRecordSerializer<D extends DataStatistics<D, S>, S>
+    extends TypeSerializer<DataStatisticsOrRecord<D, S>> {
+  private final TypeSerializer<DataStatistics<D, S>> statisticsSerializer;
+  private final TypeSerializer<RowData> recordSerializer;
+
+  DataStatisticsOrRecordSerializer(
+      TypeSerializer<DataStatistics<D, S>> statisticsSerializer,
+      TypeSerializer<RowData> recordSerializer) {
+    this.statisticsSerializer = statisticsSerializer;
+    this.recordSerializer = recordSerializer;
+  }
+
+  @Override
+  public boolean isImmutableType() {
+    return false;
+  }
+
+  @SuppressWarnings("ReferenceEquality")
+  @Override
+  public TypeSerializer<DataStatisticsOrRecord<D, S>> duplicate() {
+    TypeSerializer<DataStatistics<D, S>> duplicateStatisticsSerializer =
+        statisticsSerializer.duplicate();
+    TypeSerializer<RowData> duplicateRowDataSerializer = recordSerializer.duplicate();
+    if ((statisticsSerializer != duplicateStatisticsSerializer)
+        || (recordSerializer != duplicateRowDataSerializer)) {
+      return new DataStatisticsOrRecordSerializer<>(
+          duplicateStatisticsSerializer, duplicateRowDataSerializer);
+    } else {
+      return this;
+    }
+  }
+
+  @Override
+  public DataStatisticsOrRecord<D, S> createInstance() {
+    // arbitrarily always create RowData value instance
+    return DataStatisticsOrRecord.fromRecord(recordSerializer.createInstance());
+  }
+
+  @Override
+  public DataStatisticsOrRecord<D, S> copy(DataStatisticsOrRecord<D, S> from) {
+    if (from.hasRecord()) {
+      return DataStatisticsOrRecord.fromRecord(recordSerializer.copy(from.record()));
+    } else {
+      return DataStatisticsOrRecord.fromDataStatistics(
+          statisticsSerializer.copy(from.dataStatistics()));
+    }
+  }
+
+  @Override
+  public DataStatisticsOrRecord<D, S> copy(
+      DataStatisticsOrRecord<D, S> from, DataStatisticsOrRecord<D, S> reuse) {
+    DataStatisticsOrRecord<D, S> to;
+    if (from.hasRecord()) {
+      to = DataStatisticsOrRecord.reuseRecord(reuse, recordSerializer);
+      RowData record = recordSerializer.copy(from.record(), to.record());
+      to.record(record);
+    } else {
+      to = DataStatisticsOrRecord.reuseStatistics(reuse, statisticsSerializer);
+      DataStatistics<D, S> statistics =
+          statisticsSerializer.copy(from.dataStatistics(), to.dataStatistics());
+      to.dataStatistics(statistics);
+    }
+
+    return to;
+  }
+
+  @Override
+  public int getLength() {
+    return -1;

Review Comment:
   We only care about the amount of data, not the size of data, right?
   
   



-- 
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@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org