voonhous commented on code in PR #19416:
URL: https://github.com/apache/hudi/pull/19416#discussion_r3689402956


##########
hudi-utilities/src/test/java/org/apache/hudi/utilities/schema/TestRowBasedSchemaProvider.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.schema;
+
+import org.apache.hudi.common.config.TypedProperties;
+
+import org.apache.avro.Schema;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.StructType;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Unit tests for {@link RowBasedSchemaProvider}.
+ */
+class TestRowBasedSchemaProvider {
+
+  @Test
+  void testSourceSchemaIsDerivedFromRowStruct() {
+    Schema sourceSchema = new RowBasedSchemaProvider(
+        new StructType().add("id", DataTypes.LongType, 
false)).getSourceSchema();
+
+    assertEquals(RowBasedSchemaProvider.HOODIE_RECORD_STRUCT_NAME, 
sourceSchema.getName());
+    assertEquals(RowBasedSchemaProvider.HOODIE_RECORD_NAMESPACE, 
sourceSchema.getNamespace());
+    assertNotNull(sourceSchema.getField("id"));
+    assertEquals(Schema.Type.LONG, 
sourceSchema.getField("id").schema().getType());
+  }
+
+  @Test
+  void testPropsBasedConstructor() {
+    // the (props, jssc) constructor is the signature HoodieStreamer resolves 
reflectively

Review Comment:
   You're right, only `UtilHelpers.createRowBasedSchemaProvider` builds it -- 
dropped the test.



##########
hudi-utilities/src/test/java/org/apache/hudi/utilities/sources/TestS3EventsSource.java:
##########
@@ -103,9 +116,56 @@ public void testReadingFromSource(boolean 
persistSourceRdd) throws IOException {
     verifyRddsArePersisted(sourceFormatAdapter, fetch2, persistSourceRdd);
   }
 
+  /**
+   * Without a schema provider the event schema is inferred from the SQS 
payload instead of being
+   * applied on read.
+   */
+  @Test
+  public void testReadingFromSourceWithoutSchemaProvider() {
+    S3EventsSource source = prepareS3EventsSource(generateProperties(false), 
null);
+    generateMessageInQueue("1");
+
+    Pair<Option<Dataset<Row>>, Checkpoint> batch = 
source.fetchNextBatch(Option.empty(), Long.MAX_VALUE);
+    Dataset<Row> eventRecords = batch.getLeft().get();
+    assertEquals(1, eventRecords.count());
+    // inference has to recover the whole sqs event, nested structs included: 
a payload spark fails
+    // to infer surfaces as a single _corrupt_record column instead
+    assertEquals(Arrays.asList("awsRegion", "eventName", "eventSource", 
"eventTime", "eventVersion",

Review Comment:
   Added `glacierEventData` to the SQS fixture (real S3 event field, undeclared 
in `s3-metadata.avsc`, not stripped by the selector) and assert it appears -- 
only inference can produce it.



##########
hudi-utilities/src/test/java/org/apache/hudi/utilities/callback/TestKafkaCallbackProvider.java:
##########
@@ -72,20 +84,58 @@ public static void cleanupClass() throws IOException {
 
   @Test
   public void testCallbackMessage() {
-    testUtils.createTopic(testTopicName, 2);
-
-    HoodieWriteConfig hoodieConfig = createConfigForKafkaCallback();
-    HoodieWriteCommitCallback commitCallback = 
HoodieCommitCallbackFactory.create(hoodieConfig);
+    int numPartitions = 2;
+    testUtils.createTopic(testTopicName, numPartitions);
 
     List<HoodieWriteStat> stats = generateFakeHoodieWriteStat(1);
 
-    assertDoesNotThrow(() -> commitCallback.call(new 
HoodieWriteCommitCallbackMessage(makeNewCommitTime(), 
hoodieConfig.getTableName(), hoodieConfig.getBasePath(), stats)));
+    // without a partition config the message is routed by hashing the table 
name key
+    HoodieWriteConfig defaultRoutedConfig = createConfigForKafkaCallback(null);
+    HoodieWriteCommitCallback defaultRoutedCallback = 
HoodieCommitCallbackFactory.create(defaultRoutedConfig);
+    assertDoesNotThrow(() -> defaultRoutedCallback.call(new 
HoodieWriteCommitCallbackMessage(
+        makeNewCommitTime(), defaultRoutedConfig.getTableName(), 
defaultRoutedConfig.getBasePath(), stats)));
+
+    // an explicit partition config overrides the key hashing
+    HoodieWriteConfig pinnedConfig = createConfigForKafkaCallback("1");
+    HoodieWriteCommitCallback pinnedCallback = 
HoodieCommitCallbackFactory.create(pinnedConfig);
+    assertDoesNotThrow(() -> pinnedCallback.call(new 
HoodieWriteCommitCallbackMessage(

Review Comment:
   Okay, dropped the wrappers. The test now asserts each partition's consumed 
body carries the commit time that produced it, so a swallowed send failure 
fails the test.



-- 
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]

Reply via email to