mxm commented on code in PR #18932:
URL: https://github.com/apache/iceberg/pull/18932#discussion_r4587326541


##########
spark/v4.2/spark/src/test/java/org/apache/iceberg/spark/actions/RewriteTablePathResultAssert.java:
##########
@@ -0,0 +1,246 @@
+/*
+ * 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.iceberg.spark.actions;
+
+import static 
org.apache.iceberg.spark.actions.RewriteTablePathSparkAction.NOT_APPLICABLE;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.apache.iceberg.RewriteTablePathUtil;
+import org.apache.iceberg.actions.RewriteTablePath;
+import org.apache.iceberg.util.Pair;
+import org.assertj.core.api.AbstractAssert;
+
+class RewriteTablePathResultAssert
+    extends AbstractAssert<RewriteTablePathResultAssert, 
RewriteTablePath.Result> {
+
+  private enum FileKind {
+    VERSION_FILE,
+    MANIFEST_LIST,
+    MANIFEST,
+    STATISTICS_FILE,
+    PARTITION_STATISTICS_FILE,
+    CONTENT_FILE;
+
+    // manifest name ends up with either "-m0.parquet" or "m1.avro"
+    private static final Pattern MANIFEST_NAME = 
Pattern.compile(".+-m\\d+\\..+");
+
+    private static FileKind of(String location) {
+      String name = RewriteTablePathUtil.fileName(location);
+      if (name.endsWith(".metadata.json")) {
+        return VERSION_FILE;
+      } else if (name.startsWith("snap-")) {
+        return MANIFEST_LIST;
+      } else if (name.startsWith("optimized-m-") || 
MANIFEST_NAME.matcher(name).matches()) {
+        return MANIFEST;
+      } else if (name.startsWith("partition-stats-")) {
+        return PARTITION_STATISTICS_FILE;
+      } else if (name.endsWith(".stats")) {
+        return STATISTICS_FILE;
+      }
+
+      return CONTENT_FILE;
+    }
+  }
+
+  private final Set<FileKind> checkedKinds = EnumSet.noneOf(FileKind.class);
+  private Map<FileKind, List<Pair<String, String>>> filesByKind;
+
+  RewriteTablePathResultAssert(RewriteTablePath.Result actual) {
+    super(actual, RewriteTablePathResultAssert.class);
+  }
+
+  static RewriteTablePathResultAssert assertThat(RewriteTablePath.Result 
actual) {
+    return new RewriteTablePathResultAssert(actual);
+  }
+
+  RewriteTablePathResultAssert hasLatestVersion(String expected) {
+    isNotNull();
+    if (!Objects.equals(actual.latestVersion(), expected)) {
+      failWithMessage("Expected latest version %s but was %s", expected, 
actual.latestVersion());
+    }
+
+    return myself;
+  }
+
+  RewriteTablePathResultAssert hasRewrittenDeleteFilePaths(int expected) {
+    isNotNull();
+    if (actual.rewrittenDeleteFilePathsCount() != expected) {
+      failWithMessage(
+          "Expected %s rewritten delete file paths but was %s",
+          expected, actual.rewrittenDeleteFilePathsCount());
+    }
+
+    return myself;
+  }
+
+  RewriteTablePathResultAssert hasNoFileList() {
+    isNotNull();
+    if (!NOT_APPLICABLE.equals(actual.fileListLocation())) {
+      failWithMessage("Expected no file list but found %s", 
actual.fileListLocation());
+    }
+
+    return myself;
+  }
+
+  RewriteTablePathResultAssert hasVersionFiles(int expected) {
+    return hasFiles(FileKind.VERSION_FILE, expected);
+  }
+
+  RewriteTablePathResultAssert hasManifestLists(int expected) {
+    return hasFiles(FileKind.MANIFEST_LIST, expected);
+  }
+
+  RewriteTablePathResultAssert hasManifests(int expected) {
+    return hasFiles(FileKind.MANIFEST, expected);
+  }
+
+  RewriteTablePathResultAssert hasStatisticsFiles(int expected) {
+    return hasFiles(FileKind.STATISTICS_FILE, expected);
+  }
+
+  RewriteTablePathResultAssert hasPartitionStatisticsFiles(int expected) {
+    return hasFiles(FileKind.PARTITION_STATISTICS_FILE, expected);
+  }
+
+  RewriteTablePathResultAssert hasContentFiles(int expected) {
+    return hasFiles(FileKind.CONTENT_FILE, expected);
+  }
+
+  RewriteTablePathResultAssert hasNoOtherFiles() {

Review Comment:
   `hasNoOtherFiles()` must come at the end of the call, otherwise a call to 
e.g. `hasContentFiles(2)` will fail. 
   
   Should we set the return type to `void` to make that clear?



##########
spark/v4.2/spark/src/test/java/org/apache/iceberg/spark/actions/TestRewriteTablePathsAction.java:
##########
@@ -577,7 +619,12 @@ public void testPositionDeletesAcrossFiles() throws 
Exception {
 
     // We have one more snapshot, an additional manifest list, and a new 
(delete) manifest,
     // and an additional position delete
-    checkFileNum(4, 3, 3, 13, result);
+    assertThat(result)
+        .hasVersionFiles(4)
+        .hasManifestLists(3)
+        .hasManifests(3)
+        .hasContentFiles(3)
+        .hasNoOtherFiles();

Review Comment:
   One side effect of this change is that it's now possible to omit certain 
checks because they are optional.
   
   I don't see a good way to prevent this if we want to keep the builder 
without an explicit `build()`.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to