cshuo commented on code in PR #19546:
URL: https://github.com/apache/hudi/pull/19546#discussion_r3735372219


##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/util/TestFlinkUtilities.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.util;
+
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.table.format.CastMap;
+
+import org.apache.flink.api.common.io.InputFormat;
+import org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend;
+import org.apache.flink.core.io.GenericInputSplit;
+import org.apache.flink.formats.json.JsonRowDataDeserializationSchema;
+import org.apache.flink.runtime.state.hashmap.HashMapStateBackend;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.RowKind;
+import org.junit.jupiter.api.Test;
+
+import java.util.NoSuchElementException;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class TestFlinkUtilities {
+
+  @Test
+  void testStateBackendConverterHandlesSupportedAndUnknownValues() {
+    FlinkStateBackendConverter converter = new FlinkStateBackendConverter();
+
+    assertInstanceOf(HashMapStateBackend.class, converter.convert("hashmap"));
+    assertInstanceOf(EmbeddedRocksDBStateBackend.class, 
converter.convert("rocksdb"));
+    HoodieException exception = assertThrows(HoodieException.class, () -> 
converter.convert("memory"));
+    assertTrue(exception.getMessage().contains("memory"));
+  }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  void testEmptyInputFormatContainsNoRecords() throws Exception {
+    InputFormat<RowData, GenericInputSplit> inputFormat =
+        (InputFormat<RowData, GenericInputSplit>) 
InputFormats.EMPTY_INPUT_FORMAT;
+    GenericInputSplit[] splits = inputFormat.createInputSplits(2);
+
+    assertEquals(1, splits.length);
+    inputFormat.open(splits[0]);
+    assertTrue(inputFormat.reachedEnd());
+    assertThrows(NoSuchElementException.class, () -> 
inputFormat.nextRecord(null));
+    inputFormat.close();
+  }
+
+  @Test
+  void testRowDataProjectionPreservesKindNullsAndSelectedOrder() {
+    RowType rowType = RowType.of(
+        DataTypes.INT().getLogicalType(),
+        DataTypes.STRING().getLogicalType());
+    GenericRowData input = GenericRowData.of(7, null);
+    input.setRowKind(RowKind.DELETE);
+
+    RowDataProjection projection = RowDataProjection.instanceV2(rowType, new 
int[] {1, 0});
+    RowData projected = projection.project(input);
+
+    assertEquals(RowKind.DELETE, projected.getRowKind());
+    assertTrue(projected.isNullAt(0));
+    assertEquals(7, projected.getInt(1));
+    assertArrayEquals(new Object[] {null, 7}, 
projection.projectAsValues(input));
+  }
+
+  @Test
+  void testRowDataProjectionFactoriesAndValidation() {
+    LogicalType[] types = {
+        DataTypes.INT().getLogicalType(),
+        DataTypes.STRING().getLogicalType()
+    };
+    RowType rowType = RowType.of(types);
+    GenericRowData input = GenericRowData.of(3, 
StringData.fromString("value"));
+
+    RowData projected = RowDataProjection.instance(rowType, new int[] {0, 
1}).project(input);
+    assertEquals(3, projected.getInt(0));
+    assertEquals("value", projected.getString(1).toString());
+    assertThrows(IllegalArgumentException.class,
+        () -> RowDataProjection.instance(types, new int[] {0}));
+  }
+
+  @Test
+  void testCastProjectionHandlesValuesAndNulls() {
+    LogicalType[] types = {
+        DataTypes.INT().getLogicalType(),
+        DataTypes.STRING().getLogicalType()
+    };
+    RowDataCastProjection projection = new RowDataCastProjection(types, new 
CastMap());
+    GenericRowData input = GenericRowData.of(11, null);
+
+    RowData projected = projection.project(input);
+    assertEquals(11, projected.getInt(0));
+    assertTrue(projected.isNullAt(1));
+  }
+
+  @Test
+  void testSharedModificationAndChangelogConstants() {
+    assertTrue(ChangelogModes.FULL.contains(RowKind.UPDATE_BEFORE));
+    assertFalse(ChangelogModes.UPSERT.contains(RowKind.UPDATE_BEFORE));
+    assertTrue(ChangelogModes.UPSERT.contains(RowKind.DELETE));
+    assertSame(DataModificationInfos.DEFAULT_DELETE_INFO, 
DataModificationInfos.DEFAULT_DELETE_INFO);
+    assertSame(DataModificationInfos.DEFAULT_UPDATE_INFO, 
DataModificationInfos.DEFAULT_UPDATE_INFO);

Review Comment:
   Updated in 19fb2764bf1: replaced the self-comparisons with assertions for 
the default delete and update modes and empty requiredColumns.



##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/source/stats/TestColumnStatsModels.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.source.stats;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class TestColumnStatsModels {
+
+  @Test
+  void testColumnStatsValueSemantics() {
+    ColumnStats stats = new ColumnStats(1, 9, 2);
+
+    assertEquals(1, stats.getMinVal());
+    assertEquals(9, stats.getMaxVal());
+    assertEquals(2, stats.getNullCnt());
+    assertEquals(stats, new ColumnStats(1, 9, 2));
+    assertEquals(stats.hashCode(), new ColumnStats(1, 9, 2).hashCode());
+    assertNotEquals(stats, new ColumnStats(null, 9, 2));
+    assertNull(new ColumnStats(null, null, 0).getMinVal());
+  }
+
+  @Test
+  void testColumnStatsSchemaConstantsResolveExpectedFields() {
+    assertNotNull(ColumnStatsSchemas.METADATA_SCHEMA);
+    assertNotNull(ColumnStatsSchemas.METADATA_DATA_TYPE);
+    assertNotNull(ColumnStatsSchemas.COL_STATS_DATA_TYPE);
+    assertEquals(6, ColumnStatsSchemas.COL_STATS_TARGET_POS.length);
+    assertArrayEquals(
+        new int[] {
+            ColumnStatsSchemas.ORD_FILE_NAME,
+            ColumnStatsSchemas.ORD_MIN_VAL,
+            ColumnStatsSchemas.ORD_MAX_VAL,
+            ColumnStatsSchemas.ORD_NULL_CNT,
+            ColumnStatsSchemas.ORD_VAL_CNT,

Review Comment:
   Updated in 19fb2764bf1: COL_STATS_TARGET_POS is now compared directly 
against expected source positions. ORD_* indexes the projected row, while the 
array values are source-schema positions, so the expected mapping is {0, 2, 3, 
5, 4, 1} rather than the ordinal sequence.



##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/source/rebalance/TestStreamReadRebalance.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.source.rebalance;
+
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.configuration.FlinkOptions;
+import org.apache.hudi.index.bucket.BucketIdentifier;
+import 
org.apache.hudi.source.rebalance.partitioner.StreamReadAppendPartitioner;
+import 
org.apache.hudi.source.rebalance.partitioner.StreamReadBucketIndexPartitioner;
+import org.apache.hudi.source.rebalance.selector.StreamReadAppendKeySelector;
+import 
org.apache.hudi.source.rebalance.selector.StreamReadBucketIndexKeySelector;
+import org.apache.hudi.table.format.mor.MergeOnReadInputSplit;
+
+import org.apache.flink.configuration.Configuration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class TestStreamReadRebalance {
+
+  @Test
+  void testAppendSelectorAndPartitionerUseSplitNumber() throws Exception {
+    MergeOnReadInputSplit split = newSplit(7, "partition", "00000003-file");
+
+    Integer key = new StreamReadAppendKeySelector().getKey(split);
+    assertEquals(7, key);
+    assertEquals(3, new StreamReadAppendPartitioner(4).partition(key, 128));
+  }
+
+  @Test
+  void testBucketSelectorAndPartitionerUsePartitionAndFileId() throws 
Exception {
+    String partition = "partition=par1";
+    String fileId = BucketIdentifier.newBucketFileIdPrefix(3);
+    MergeOnReadInputSplit split = newSplit(1, partition, fileId);
+    Pair<String, String> key = new 
StreamReadBucketIndexKeySelector().getKey(split);
+
+    assertEquals(Pair.of(partition, fileId), key);
+
+    Configuration conf = new Configuration();
+    conf.set(FlinkOptions.READ_TASKS, 4);
+    conf.set(FlinkOptions.BUCKET_INDEX_NUM_BUCKETS, 8);
+    StreamReadBucketIndexPartitioner partitioner = new 
StreamReadBucketIndexPartitioner(conf);
+    int first = partitioner.partition(key, 128);
+    int second = partitioner.partition(key, 128);
+
+    assertEquals(first, second);

Review Comment:
   Updated in 19fb2764bf1: assert exact routing via BucketIndexUtil and vary 
both the partition path and bucket id, including non-equality checks for the 
resulting routes.



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