voonhous commented on code in PR #19707:
URL: https://github.com/apache/hudi/pull/19707#discussion_r3833031366
##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KinesisDeaggregator.java:
##########
@@ -44,36 +59,137 @@ public static List<Record> deaggregate(List<Record>
records) {
if (records == null || records.isEmpty()) {
return new ArrayList<>();
}
- List<com.amazonaws.services.kinesis.model.Record> v1Records = new
ArrayList<>(records.size());
- for (Record r : records) {
- v1Records.add(toV1Record(r));
- }
- List<UserRecord> userRecords = UserRecord.deaggregate(v1Records);
- List<Record> result = new ArrayList<>(userRecords.size());
- for (UserRecord ur : userRecords) {
- result.add(toV2Record(ur));
+ List<Record> result = new ArrayList<>(records.size());
+ for (Record record : records) {
+ byte[] data = record.data() == null ? null : record.data().asByteArray();
+ if (!isAggregated(data)) {
+ result.add(record);
Review Comment:
Changed: a frame whose digest verifies but cannot be decoded now throws
`HoodieReadFromSourceException`, naming the sequence number and the
`enable.deaggregation=false` escape hatch, so the PERMISSIVE all-null path is
gone. The error table is not wired at this layer, so failing the read is the
mechanism. Digest-mismatch frames still pass through: an ordinary record can
begin with the magic bytes -- the trailing MD5 is the discriminator, and KCL
treats that case the same way.
##########
hudi-utilities/src/test/java/org/apache/hudi/utilities/sources/helpers/TestKinesisDeaggregator.java:
##########
@@ -0,0 +1,276 @@
+/*
+ * 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.hudi.utilities.sources.helpers;
+
+import com.google.protobuf.CodedOutputStream;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.kinesis.model.Record;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Unit tests for {@link KinesisDeaggregator}, covering KPL aggregate decoding
and the pass-through
+ * paths taken by non-aggregated, corrupt or invalid records.
+ */
+class TestKinesisDeaggregator {
+
+ private static final byte[] MAGIC = new byte[] {(byte) 0xF3, (byte) 0x89,
(byte) 0x9A, (byte) 0xC2};
+ private static final String PARENT_SEQ = "49590";
+ private static final Instant PARENT_ARRIVAL =
Instant.ofEpochMilli(1700000000000L);
+
+ // -------------------------------------------------------------------------
+ // Encoding helpers - independent of the decoder under test
Review Comment:
Checked in two byte-frozen fixtures generated with AWS's producer-side
aggregation library (`amazon-kinesis-aggregator`, the Java implementation of
the KPL wire format) and reference-decoded with the KCL deaggregator before
freezing; the ASL jars were used at generation time only. Capturing the native
KPL daemon's output needs a live stream, but this anchors the tests to an AWS
encoder, and frozen bytes cannot drift with the test-side encoder.
--
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]