Skip to content

Commit

Permalink
API, Core: Move @Value.Immutable usage from iceberg-api to iceberg-co…
Browse files Browse the repository at this point in the history
…re (apache#8099)
  • Loading branch information
nastra authored Jul 31, 2023
1 parent 84e526f commit 6bdb841
Show file tree
Hide file tree
Showing 19 changed files with 400 additions and 44 deletions.
24 changes: 24 additions & 0 deletions .palantir/revapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,30 @@ acceptedBreaks:
\ of type erasure and the original type is always returned"
"1.3.0":
org.apache.iceberg:iceberg-api:
- code: "java.class.removed"
old: "class org.apache.iceberg.actions.ImmutableDeleteOrphanFiles"
justification: "Moving from iceberg-api to iceberg-core"
- code: "java.class.removed"
old: "class org.apache.iceberg.actions.ImmutableDeleteReachableFiles"
justification: "Moving from iceberg-api to iceberg-core"
- code: "java.class.removed"
old: "class org.apache.iceberg.actions.ImmutableExpireSnapshots"
justification: "Moving from iceberg-api to iceberg-core"
- code: "java.class.removed"
old: "class org.apache.iceberg.actions.ImmutableMigrateTable"
justification: "Moving from iceberg-api to iceberg-core"
- code: "java.class.removed"
old: "class org.apache.iceberg.actions.ImmutableRewriteDataFiles"
justification: "Moving from iceberg-api to iceberg-core"
- code: "java.class.removed"
old: "class org.apache.iceberg.actions.ImmutableRewriteManifests"
justification: "Moving from iceberg-api to iceberg-core"
- code: "java.class.removed"
old: "class org.apache.iceberg.actions.ImmutableRewritePositionDeleteFiles"
justification: "Moving from iceberg-api to iceberg-core"
- code: "java.class.removed"
old: "class org.apache.iceberg.actions.ImmutableSnapshotTable"
justification: "Moving from iceberg-api to iceberg-core"
- code: "java.class.removed"
old: "class org.apache.iceberg.view.ImmutableSQLViewRepresentation"
justification: "Moving from iceberg-api to iceberg-core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
import java.util.function.Consumer;
import org.apache.iceberg.io.SupportsBulkOperations;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.immutables.value.Value;

/**
* An action that deletes orphan metadata, data and delete files in a table.
*
* <p>A file is considered orphan if it is not reachable by any valid snapshot. The set of actual
* files is built by listing the underlying storage which makes this operation expensive.
*/
@Value.Enclosing
public interface DeleteOrphanFiles extends Action<DeleteOrphanFiles, DeleteOrphanFiles.Result> {
/**
* Passes a location which should be scanned for orphan files.
Expand Down Expand Up @@ -141,7 +139,6 @@ default DeleteOrphanFiles equalAuthorities(Map<String, String> newEqualAuthoriti
}

/** The action result that contains a summary of the execution. */
@Value.Immutable
interface Result {
/** Returns locations of orphan files. */
Iterable<String> orphanFileLocations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.function.Consumer;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.SupportsBulkOperations;
import org.immutables.value.Value;

/**
* An action that deletes all files referenced by a table metadata file.
Expand All @@ -33,7 +32,6 @@
*
* <p>Implementations may use a query engine to distribute parts of work.
*/
@Value.Enclosing
public interface DeleteReachableFiles
extends Action<DeleteReachableFiles, DeleteReachableFiles.Result> {

Expand Down Expand Up @@ -67,7 +65,6 @@ public interface DeleteReachableFiles
DeleteReachableFiles io(FileIO io);

/** The action result that contains a summary of the execution. */
@Value.Immutable
interface Result {

/** Returns the number of deleted data files. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
import java.util.function.Consumer;
import org.apache.iceberg.Snapshot;
import org.apache.iceberg.io.SupportsBulkOperations;
import org.immutables.value.Value;

/**
* An action that expires snapshots in a table.
*
* <p>Similar to {@link org.apache.iceberg.ExpireSnapshots} but may use a query engine to distribute
* parts of the work.
*/
@Value.Enclosing
public interface ExpireSnapshots extends Action<ExpireSnapshots, ExpireSnapshots.Result> {
/**
* Expires a specific {@link Snapshot} identified by id.
Expand Down Expand Up @@ -100,7 +98,6 @@ public interface ExpireSnapshots extends Action<ExpireSnapshots, ExpireSnapshots
ExpireSnapshots executeDeleteWith(ExecutorService executorService);

/** The action result that contains a summary of the execution. */
@Value.Immutable
interface Result {
/** Returns the number of deleted data files. */
long deletedDataFilesCount();
Expand All @@ -118,7 +115,6 @@ interface Result {
long deletedManifestListsCount();

/** Returns the number of deleted statistics files. */
@Value.Default
default long deletedStatisticsFilesCount() {
return 0L;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
package org.apache.iceberg.actions;

import java.util.Map;
import org.immutables.value.Value;

/** An action that migrates an existing table to Iceberg. */
@Value.Enclosing
public interface MigrateTable extends Action<MigrateTable, MigrateTable.Result> {
/**
* Sets table properties in the newly created Iceberg table. Any properties with the same key name
Expand Down Expand Up @@ -53,7 +51,6 @@ default MigrateTable dropBackup() {
}

/** The action result that contains a summary of the execution. */
@Value.Immutable
interface Result {
/** Returns the number of migrated data files. */
long migratedDataFilesCount();
Expand Down
12 changes: 0 additions & 12 deletions api/src/main/java/org/apache/iceberg/actions/RewriteDataFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import org.apache.iceberg.StructLike;
import org.apache.iceberg.expressions.Expression;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.immutables.value.Value;

/**
* An action for rewriting data files according to a rewrite strategy. Generally used for optimizing
* the sizing and layout of data files within a table.
*/
@Value.Enclosing
public interface RewriteDataFiles
extends SnapshotUpdate<RewriteDataFiles, RewriteDataFiles.Result> {

Expand Down Expand Up @@ -178,33 +176,27 @@ default RewriteDataFiles zOrder(String... columns) {
* null then that particular file group failed. We should only have failed groups if partial
* progress is enabled otherwise we will report a total failure for the job.
*/
@Value.Immutable
interface Result {
List<FileGroupRewriteResult> rewriteResults();

@Value.Default
default List<FileGroupFailureResult> rewriteFailures() {
return ImmutableList.of();
}

@Value.Default
default int addedDataFilesCount() {
return rewriteResults().stream().mapToInt(FileGroupRewriteResult::addedDataFilesCount).sum();
}

@Value.Default
default int rewrittenDataFilesCount() {
return rewriteResults().stream()
.mapToInt(FileGroupRewriteResult::rewrittenDataFilesCount)
.sum();
}

@Value.Default
default long rewrittenBytesCount() {
return rewriteResults().stream().mapToLong(FileGroupRewriteResult::rewrittenBytesCount).sum();
}

@Value.Default
default int failedDataFilesCount() {
return rewriteFailures().stream().mapToInt(FileGroupFailureResult::dataFilesCount).sum();
}
Expand All @@ -214,22 +206,19 @@ default int failedDataFilesCount() {
* For a particular file group, the number of files which are newly created and the number of
* files which were formerly part of the table but have been rewritten.
*/
@Value.Immutable
interface FileGroupRewriteResult {
FileGroupInfo info();

int addedDataFilesCount();

int rewrittenDataFilesCount();

@Value.Default
default long rewrittenBytesCount() {
return 0L;
}
}

/** For a file group that failed to rewrite. */
@Value.Immutable
interface FileGroupFailureResult {
FileGroupInfo info();

Expand All @@ -240,7 +229,6 @@ interface FileGroupFailureResult {
* A description of a file group, when it was processed, and within which partition. For use
* tracking rewrite operations and for returning results.
*/
@Value.Immutable
interface FileGroupInfo {

/** returns which file group this is out of the total set of file groups for this rewrite */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

import java.util.function.Predicate;
import org.apache.iceberg.ManifestFile;
import org.immutables.value.Value;

/** An action that rewrites manifests. */
@Value.Enclosing
public interface RewriteManifests
extends SnapshotUpdate<RewriteManifests, RewriteManifests.Result> {
/**
Expand Down Expand Up @@ -57,7 +55,6 @@ public interface RewriteManifests
RewriteManifests stagingLocation(String stagingLocation);

/** The action result that contains a summary of the execution. */
@Value.Immutable
interface Result {
/** Returns rewritten manifests. */
Iterable<ManifestFile> rewrittenManifests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
import org.apache.iceberg.RewriteJobOrder;
import org.apache.iceberg.StructLike;
import org.apache.iceberg.expressions.Expression;
import org.immutables.value.Value;

/**
* An action for rewriting position delete files.
*
* <p>Generally used for optimizing the size and layout of position delete files within a table.
*/
@Value.Enclosing
public interface RewritePositionDeleteFiles
extends SnapshotUpdate<RewritePositionDeleteFiles, RewritePositionDeleteFiles.Result> {

Expand Down Expand Up @@ -93,7 +91,6 @@ public interface RewritePositionDeleteFiles
RewritePositionDeleteFiles filter(Expression expression);

/** The action result that contains a summary of the execution. */
@Value.Immutable
interface Result {
List<FileGroupRewriteResult> rewriteResults();

Expand Down Expand Up @@ -127,7 +124,6 @@ default long addedBytesCount() {
* newly created and the number of files which were formerly part of the table but have been
* rewritten.
*/
@Value.Immutable
interface FileGroupRewriteResult {
/** Description of this position delete file group. */
FileGroupInfo info();
Expand All @@ -149,7 +145,6 @@ interface FileGroupRewriteResult {
* A description of a position delete file group, when it was processed, and within which
* partition. For use tracking rewrite operations and for returning results.
*/
@Value.Immutable
interface FileGroupInfo {
/**
* Returns which position delete file group this is out of the total set of file groups for this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
package org.apache.iceberg.actions;

import java.util.Map;
import org.immutables.value.Value;

/** An action that creates an independent snapshot of an existing table. */
@Value.Enclosing
public interface SnapshotTable extends Action<SnapshotTable, SnapshotTable.Result> {
/**
* Sets the table identifier for the newly created Iceberg table.
Expand Down Expand Up @@ -60,7 +58,6 @@ public interface SnapshotTable extends Action<SnapshotTable, SnapshotTable.Resul
SnapshotTable tableProperty(String key, String value);

/** The action result that contains a summary of the execution. */
@Value.Immutable
interface Result {
/** Returns the number of imported data files. */
long importedDataFilesCount();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.actions;

import org.immutables.value.Value;
import org.immutables.value.Value.Style.BuilderVisibility;
import org.immutables.value.Value.Style.ImplementationVisibility;

@Value.Enclosing
@SuppressWarnings("ImmutablesStyle")
@Value.Style(
typeImmutableEnclosing = "ImmutableDeleteOrphanFiles",
visibility = ImplementationVisibility.PUBLIC,
builderVisibility = BuilderVisibility.PUBLIC)
interface BaseDeleteOrphanFiles extends DeleteOrphanFiles {

@Value.Immutable
interface Result extends DeleteOrphanFiles.Result {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.actions;

import org.immutables.value.Value;
import org.immutables.value.Value.Style.BuilderVisibility;
import org.immutables.value.Value.Style.ImplementationVisibility;

@Value.Enclosing
@SuppressWarnings("ImmutablesStyle")
@Value.Style(
typeImmutableEnclosing = "ImmutableDeleteReachableFiles",
visibility = ImplementationVisibility.PUBLIC,
builderVisibility = BuilderVisibility.PUBLIC)
interface BaseDeleteReachableFiles extends DeleteReachableFiles {

@Value.Immutable
interface Result extends DeleteReachableFiles.Result {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.actions;

import org.immutables.value.Value;
import org.immutables.value.Value.Style.BuilderVisibility;
import org.immutables.value.Value.Style.ImplementationVisibility;

@Value.Enclosing
@SuppressWarnings("ImmutablesStyle")
@Value.Style(
typeImmutableEnclosing = "ImmutableExpireSnapshots",
visibility = ImplementationVisibility.PUBLIC,
builderVisibility = BuilderVisibility.PUBLIC)
interface BaseExpireSnapshots extends ExpireSnapshots {

@Value.Immutable
interface Result extends ExpireSnapshots.Result {
@Override
@Value.Default
default long deletedStatisticsFilesCount() {
return ExpireSnapshots.Result.super.deletedStatisticsFilesCount();
}
}
}
Loading

0 comments on commit 6bdb841

Please sign in to comment.