All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.iceberg.TableOperations Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
/*
 * 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;

import java.util.UUID;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.encryption.PlaintextEncryptionManager;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.LocationProvider;

/**
 * SPI interface to abstract table metadata access and updates.
 */
public interface TableOperations {

  /**
   * Return the currently loaded table metadata, without checking for updates.
   *
   * @return table metadata
   */
  TableMetadata current();

  /**
   * Return the current table metadata after checking for updates.
   *
   * @return table metadata
   */
  TableMetadata refresh();

  /**
   * Replace the base table metadata with a new version.
   * 

* This method should implement and document atomicity guarantees. *

* Implementations must check that the base metadata is current to avoid overwriting updates. * Once the atomic commit operation succeeds, implementations must not perform any operations that * may fail because failure in this method cannot be distinguished from commit failure. * * @param base table metadata on which changes were based * @param metadata new table metadata with updates */ void commit(TableMetadata base, TableMetadata metadata); /** * @return a {@link FileIO} to read and write table data and metadata files */ FileIO io(); /** * @return a {@link org.apache.iceberg.encryption.EncryptionManager} to encrypt and decrypt * data files. */ default EncryptionManager encryption() { return new PlaintextEncryptionManager(); } /** * Given the name of a metadata file, obtain the full path of that file using an appropriate base * location of the implementation's choosing. *

* The file may not exist yet, in which case the path should be returned as if it were to be created * by e.g. {@link FileIO#newOutputFile(String)}. */ String metadataFileLocation(String fileName); /** * Returns a {@link LocationProvider} that supplies locations for new new data files. * * @return a location provider configured for the current table state */ LocationProvider locationProvider(); /** * Return a temporary {@link TableOperations} instance that uses configuration from uncommitted metadata. *

* This is called by transactions when uncommitted table metadata should be used; for example, to create a metadata * file location based on metadata in the transaction that has not been committed. *

* Transactions will not call {@link #refresh()} or {@link #commit(TableMetadata, TableMetadata)}. * * @param uncommittedMetadata uncommitted table metadata * @return a temporary table operations that behaves like the uncommitted metadata is current */ default TableOperations temp(TableMetadata uncommittedMetadata) { return this; } /** * Create a new ID for a Snapshot * * @return a long snapshot ID */ default long newSnapshotId() { UUID uuid = UUID.randomUUID(); long mostSignificantBits = uuid.getMostSignificantBits(); long leastSignificantBits = uuid.getLeastSignificantBits(); return Math.abs(mostSignificantBits ^ leastSignificantBits); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy