voonhous commented on code in PR #19875:
URL: https://github.com/apache/hudi/pull/19875#discussion_r3975339274
##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/HoodieDataTableValidator.java:
##########
@@ -212,7 +212,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
- HoodieMetadataTableValidator.Config config =
(HoodieMetadataTableValidator.Config) o;
+ Config config = (Config) o;
Review Comment:
Converted to `Objects.equals(basePath, config.basePath)` and added the
default-instance case (two `new Config()` are equal, same hash code); the case
NPEs without the change. Done in f687e1763e26.
##########
hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHoodieDataTableValidator.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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;
+
+import org.apache.hudi.client.SparkRDDWriteClient;
+import org.apache.hudi.client.WriteClientTestUtils;
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.exception.HoodieValidationException;
+import org.apache.hudi.testutils.HoodieSparkClientTestBase;
+
+import org.apache.spark.api.java.JavaRDD;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Stream;
+
+import static
org.apache.hudi.common.testutils.HoodieTestDataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+import static
org.apache.hudi.common.testutils.HoodieTestDataGenerator.DEFAULT_SECOND_PARTITION_PATH;
+import static
org.apache.hudi.common.testutils.HoodieTestDataGenerator.DEFAULT_THIRD_PARTITION_PATH;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests {@link HoodieDataTableValidator} against a small three-partition COW
table, with and without
+ * data files that the timeline does not account for.
+ */
+public class TestHoodieDataTableValidator extends HoodieSparkClientTestBase {
+
+ private static final int RECORDS_PER_PARTITION = 4;
+
+ private HoodieDataTableValidator.Config validatorConfig(boolean
ignoreFailed) {
+ HoodieDataTableValidator.Config cfg = new
HoodieDataTableValidator.Config();
+ cfg.basePath = basePath;
+ cfg.parallelism = 2;
+ cfg.ignoreFailed = ignoreFailed;
+ return cfg;
+ }
+
+ private String writeOneCommit() {
+ HoodieWriteConfig writeConfig = getConfigBuilder().build();
+ try (SparkRDDWriteClient client = getHoodieWriteClient(writeConfig)) {
+ String instantTime = WriteClientTestUtils.createNewInstantTime();
+ List<HoodieRecord> records = new ArrayList<>();
+ for (String partition : Arrays.asList(
+ DEFAULT_FIRST_PARTITION_PATH, DEFAULT_SECOND_PARTITION_PATH,
DEFAULT_THIRD_PARTITION_PATH)) {
+ records.addAll(dataGen.generateInsertsForPartition(instantTime,
RECORDS_PER_PARTITION, partition));
+ }
+ WriteClientTestUtils.startCommitWithTime(client, instantTime);
+ JavaRDD<WriteStatus> writeStatuses =
client.insert(jsc.parallelize(records, 1), instantTime);
+ client.commit(instantTime, writeStatuses);
+ return instantTime;
+ }
+ }
+
+ /**
+ * Copies an existing base file of the first partition to a new base file
named after {@code instantTime} and a
+ * brand new file id, which is exactly the shape of a data file the timeline
does not account for.
+ */
+ private void addUnaccountedBaseFile(String instantTime) throws IOException {
+ Path partitionDir = Paths.get(basePath, DEFAULT_FIRST_PARTITION_PATH);
+ Path source;
+ try (Stream<Path> files = Files.list(partitionDir)) {
+ source = files.filter(p -> p.toString().endsWith(".parquet")).findFirst()
+ .orElseThrow(() -> new IllegalStateException("no base file written
under " + partitionDir));
+ }
+ String danglingName =
+ FSUtils.makeBaseFileName(instantTime, "1-0-1",
UUID.randomUUID().toString(), ".parquet");
+ Files.copy(source, partitionDir.resolve(danglingName));
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ public void testValidationPassesOnAHealthyTable(boolean
readPropsFromFileSystem) throws IOException {
+ writeOneCommit();
+ HoodieDataTableValidator.Config cfg = validatorConfig(false);
+ if (readPropsFromFileSystem) {
+ Path propsFile = tempDir.resolve("validator.properties");
+ Files.write(propsFile,
+ Collections.singletonList(HoodieWriteConfig.TBL_NAME.key() + "=" +
metaClient.getTableConfig().getTableName()),
+ StandardCharsets.UTF_8);
+ cfg.propsFilePath = propsFile.toAbsolutePath().toString();
Review Comment:
The field is write-only: assigned in the constructor and never read again,
so `--props` is a no-op for this tool today. Dropped the parameterization;
`testMissingPropsFileFails` still exercises `readConfigFromFileSystem`. Wiring
the props through to something would be a behaviour change on its own, so it is
left out here. Done in f687e1763e26.
--
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]