hudi-agent commented on code in PR #19546: URL: https://github.com/apache/hudi/pull/19546#discussion_r3727690419
########## 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: 🤖 nit: `assertSame(X, X)` compares a constant reference to itself — it can never fail and doesn't verify anything about `DataModificationInfos`. Could you replace these with assertions that actually exercise the type, e.g. `assertNotNull(DataModificationInfos.DEFAULT_DELETE_INFO)` or check a specific field value? <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub> ########## 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: 🤖 nit: this `assertArrayEquals` checks that the ordinal constants `ORD_*` equal `{0, 1, 2, 3, 4, 5}` — but the test name says it validates that `COL_STATS_TARGET_POS` resolves the expected fields. Could you flip the assertion to compare `COL_STATS_TARGET_POS` against `new int[]{ORD_FILE_NAME, ORD_MIN_VAL, ...}` instead? That's the array a future change could accidentally break. <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub> -- 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]
