You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/06/21 22:15:54 UTC

[GitHub] [iceberg] RussellSpitzer commented on a change in pull request #2608: Core : Repair manifests

RussellSpitzer commented on a change in pull request #2608:
URL: https://github.com/apache/iceberg/pull/2608#discussion_r655739073



##########
File path: spark/src/main/java/org/apache/iceberg/spark/actions/BaseRepairManifestsSparkAction.java
##########
@@ -0,0 +1,313 @@
+/*
+ * 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 java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.hadoop.fs.Path;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.ManifestFile;
+import org.apache.iceberg.ManifestFiles;
+import org.apache.iceberg.ManifestWriter;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.SerializableTable;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.actions.BaseRepairManifestsActionResult;
+import org.apache.iceberg.actions.RepairManifests;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Streams;
+import org.apache.iceberg.spark.JobGroupInfo;
+import org.apache.iceberg.spark.SparkDataFile;
+import org.apache.iceberg.types.Types;
+import org.apache.spark.api.java.JavaPairRDD;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.function.Function;
+import org.apache.spark.broadcast.Broadcast;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Encoders;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.types.StructType;
+import org.apache.spark.util.SerializableConfiguration;
+import scala.Tuple2;
+
+import static org.apache.iceberg.MetadataTableType.ENTRIES;
+
+/**
+ * An action that repairs manifests in a distributed manner, reading metadata of the data files to repair
+ * manifest entries in each manifest.
+ * <p>
+ * By default, this action repairs all manifests by checking the data file status and reading the data file headers.
+ * This can be changed by passing in repair options like {@link #repairMetrics(boolean)}, and manifest predicates
+ * via {@link #repairIf(Predicate)}.
+ * <p>
+ * In addition, there is a way to configure a custom location for new manifests via {@link #stagingLocation}.
+ */
+public class BaseRepairManifestsSparkAction extends BaseManifestSparkAction<RepairManifests, RepairManifests.Result>
+    implements RepairManifests {
+
+  private final int formatVersion;
+  private final SerializableConfiguration hadoopConf;
+
+  private Predicate<ManifestFile> predicate = manifest -> true;
+  private String stagingLocation;
+  private boolean repairMetrics = true;
+
+  public BaseRepairManifestsSparkAction(SparkSession spark, Table table) {
+    super(spark, table);
+
+    this.hadoopConf = new SerializableConfiguration(spark.sessionState().newHadoopConf());
+
+    // default the staging location to the metadata location
+    TableOperations ops = ((HasTableOperations) getTable()).operations();
+    Path metadataFilePath = new Path(ops.metadataFileLocation("file"));
+    this.stagingLocation = metadataFilePath.getParent().toString();
+
+    // use the current table format version for repaired manifests
+    this.formatVersion = ops.current().formatVersion();
+  }
+
+  @Override
+  public RepairManifests repairIf(Predicate<ManifestFile> newPredicate) {
+    this.predicate = newPredicate;
+    return this;
+  }
+
+  @Override
+  public RepairManifests stagingLocation(String newStagingLocation) {
+    this.stagingLocation = newStagingLocation;
+    return this;
+  }
+
+  @Override
+  public RepairManifests repairMetrics(boolean repair) {
+    this.repairMetrics = repair;
+    return this;
+  }
+
+  @Override
+  protected RepairManifests self() {
+    return this;
+  }
+
+  @Override
+  public Result execute() {
+    String desc = String.format("Rewriting manifests (staging location=%s) of %s", stagingLocation, getTable().name());

Review comment:
       Repairing manifests ?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org