@@ -26,6 +26,7 @@ import org.apache.iceberg.PartitionKey;
 import org.apache.iceberg.PartitionSpec;
 import org.apache.iceberg.encryption.EncryptedOutputFile;
 import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
 
 /**
  * Factory responsible for generating unique but recognizable data file names.
/*
 * 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.io;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.iceberg.FileFormat;
import org.apache.iceberg.PartitionKey;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.encryption.EncryptedOutputFile;
import org.apache.iceberg.encryption.EncryptionManager;

/**
 * Factory responsible for generating unique but recognizable data file names.
 */
public class OutputFileFactory {
  private final PartitionSpec spec;
  private final FileFormat format;
  private final LocationProvider locations;
  private final FileIO io;
  private final EncryptionManager encryptionManager;
  private final int partitionId;
  private final long taskId;
  // The purpose of this uuid is to be able to know from two paths that they were written by the same operation.
  // That's useful, for example, if a Spark job dies and leaves files in the file system, you can identify them all
  // with a recursive listing and grep.
  private final String operationId;
  private final AtomicInteger fileCount = new AtomicInteger(0);

  /**
   * Constructor where a generated UUID is used as the operationId to ensure uniqueness.
   * @param spec Partition specification used by the location provider
   * @param format File format used for the extension
   * @param locations Location provider used for generating locations
   * @param io FileIO to store the files
   * @param encryptionManager Encryption manager used for encrypting the files
   * @param partitionId First part of the file name
   * @param taskId Second part of the file name
   */
  public OutputFileFactory(PartitionSpec spec, FileFormat format, LocationProvider locations, FileIO io,
                           EncryptionManager encryptionManager, int partitionId, long taskId) {
    this(spec, format, locations, io, encryptionManager, partitionId, taskId, UUID.randomUUID().toString());
  }

  /**
   * Constructor with specific operationId. The [partitionId, taskId, operationId] triplet has to be unique across JVM
   * instances otherwise the same file name could be generated by different instances of the OutputFileFactory.
   * @param spec Partition specification used by the location provider
   * @param format File format used for the extension
   * @param locations Location provider used for generating locations
   * @param io FileIO to store the files
   * @param encryptionManager Encryption manager used for encrypting the files
   * @param partitionId First part of the file name
   * @param taskId Second part of the file name
   * @param operationId Third part of the file name
   */
  public OutputFileFactory(PartitionSpec spec, FileFormat format, LocationProvider locations, FileIO io,
                           EncryptionManager encryptionManager, int partitionId, long taskId, String operationId) {
    this.spec = spec;
    this.format = format;
    this.locations = locations;
    this.io = io;
    this.encryptionManager = encryptionManager;
    this.partitionId = partitionId;
    this.taskId = taskId;
    this.operationId = operationId;
  }

  private String generateFilename() {
    return format.addExtension(
        String.format("%05d-%d-%s-%05d", partitionId, taskId, operationId, fileCount.incrementAndGet()));
  }

  /**
   * Generates EncryptedOutputFile for UnpartitionedWriter.
   */
  public EncryptedOutputFile newOutputFile() {
    OutputFile file = io.newOutputFile(locations.newDataLocation(generateFilename()));
    return encryptionManager.encrypt(file);
  }

  /**
   * Generates EncryptedOutputFile for PartitionedWriter.
   */
  public EncryptedOutputFile newOutputFile(PartitionKey key) {
    String newDataLocation = locations.newDataLocation(spec, key, generateFilename());
    OutputFile rawOutputFile = io.newOutputFile(newDataLocation);
    return encryptionManager.encrypt(rawOutputFile);
  }
}

Nit: This seems to be unused.