Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions core/src/main/java/org/apache/iceberg/AllDeleteFilesTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 org.apache.iceberg.io.CloseableIterable;

/**
* A {@link Table} implementation that exposes a table's valid delete files as rows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant a before table's valid delete files?

@szehon-ho szehon-ho May 5, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm not sure about if its redundant ( 'table' needs an article, right?). How about:
A table implementation that exposes its valid delete files as rows

* <p>
* A valid delete file is one that is readable from any snapshot currently tracked by the table.
* <p>
* This table may return duplicate rows.
*/
public class AllDeleteFilesTable extends BaseFilesTable {

AllDeleteFilesTable(TableOperations ops, Table table) {
this(ops, table, table.name() + ".all_delete_files");
}

AllDeleteFilesTable(TableOperations ops, Table table, String name) {
super(ops, table, name);
}

@Override
public TableScan newScan() {
return new AllDataFilesTableScan(operations(), table(), schema());
}

@Override
MetadataTableType metadataTableType() {
return MetadataTableType.ALL_DELETE_FILES;
}

public static class AllDataFilesTableScan extends BaseAllFilesTableScan {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be AllDeleteFilesTableScan

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch ..


AllDataFilesTableScan(TableOperations ops, Table table, Schema schema) {
super(ops, table, schema, MetadataTableType.ALL_DELETE_FILES);
}

private AllDataFilesTableScan(TableOperations ops, Table table, Schema schema,
TableScanContext context) {
super(ops, table, schema, MetadataTableType.ALL_DELETE_FILES, context);
}

@Override
protected TableScan newRefinedScan(TableOperations ops, Table table, Schema schema, TableScanContext context) {
return new AllDataFilesTableScan(ops, table, schema, context);
}

@Override
protected CloseableIterable<ManifestFile> manifests() {
return reachableManifests(Snapshot::deleteManifests);
}
}
}
72 changes: 72 additions & 0 deletions core/src/main/java/org/apache/iceberg/AllFilesTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 org.apache.iceberg.io.CloseableIterable;

/**
* A {@link Table} implementation that exposes a table's valid files as rows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: also redundant a

* <p>
* A valid file is one that is readable from any snapshot currently tracked by the table.
* <p>
* This table may return duplicate rows.
*/
public class AllFilesTable extends BaseFilesTable {

AllFilesTable(TableOperations ops, Table table) {
this(ops, table, table.name() + ".all_files");
}

AllFilesTable(TableOperations ops, Table table, String name) {
super(ops, table, name);
}

@Override
public TableScan newScan() {
return new AllDataFilesTableScan(operations(), table(), schema());
}

@Override
MetadataTableType metadataTableType() {
return MetadataTableType.ALL_FILES;
}

public static class AllDataFilesTableScan extends BaseAllFilesTableScan {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the name as well.


AllDataFilesTableScan(TableOperations ops, Table table, Schema schema) {
super(ops, table, schema, MetadataTableType.ALL_FILES);
}

private AllDataFilesTableScan(TableOperations ops, Table table, Schema schema,
TableScanContext context) {
super(ops, table, schema, MetadataTableType.ALL_FILES, context);
}

@Override
protected TableScan newRefinedScan(TableOperations ops, Table table, Schema schema, TableScanContext context) {
return new AllDataFilesTableScan(ops, table, schema, context);
}

@Override
protected CloseableIterable<ManifestFile> manifests() {
return reachableManifests(Snapshot::allManifests);
}
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/org/apache/iceberg/MetadataTableType.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public enum MetadataTableType {
MANIFESTS,
PARTITIONS,
ALL_DATA_FILES,
ALL_DELETE_FILES,
ALL_FILES,
ALL_MANIFESTS,
ALL_ENTRIES;

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/apache/iceberg/MetadataTableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ private static Table createMetadataTableInstance(TableOperations ops, Table base
return new PartitionsTable(ops, baseTable, metadataTableName);
case ALL_DATA_FILES:
return new AllDataFilesTable(ops, baseTable, metadataTableName);
case ALL_DELETE_FILES:
return new AllDeleteFilesTable(ops, baseTable, metadataTableName);
case ALL_FILES:
return new AllFilesTable(ops, baseTable, metadataTableName);
case ALL_MANIFESTS:
return new AllManifestsTable(ops, baseTable, metadataTableName);
case ALL_ENTRIES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.io.CloseableIterable;
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
import org.apache.iceberg.relocated.com.google.common.collect.Sets;
import org.apache.iceberg.types.Conversions;
import org.apache.iceberg.types.Types;
import org.junit.Assert;
Expand All @@ -51,7 +52,10 @@ public static Object[][] parameters() {
{ MetadataTableType.FILES, 1 },
{ MetadataTableType.FILES, 2 },
{ MetadataTableType.ALL_DATA_FILES, 1 },
{ MetadataTableType.ALL_DATA_FILES, 2 }
{ MetadataTableType.ALL_DATA_FILES, 2 },
{ MetadataTableType.ALL_DELETE_FILES, 2 },
{ MetadataTableType.ALL_FILES, 1 },
{ MetadataTableType.ALL_FILES, 2 }
};
}

Expand Down Expand Up @@ -95,7 +99,7 @@ public void setupTable() throws Exception {
.commit();
}

if (type.equals(MetadataTableType.ALL_DATA_FILES)) {
if (allFileTableTest(type)) {
// Clear all files from current snapshot to test whether 'all' Files tables scans previous files
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Moves file entries to DELETED state
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Removes all entries
Expand All @@ -114,6 +118,10 @@ private Table createMetadataTable() {
return new DeleteFilesTable(table.ops(), table);
case ALL_DATA_FILES:
return new AllDataFilesTable(table.ops(), table);
case ALL_DELETE_FILES:
return new AllDeleteFilesTable(table.ops(), table);
case ALL_FILES:
return new AllFilesTable(table.ops(), table);
default:
throw new IllegalArgumentException("Unsupported metadata table type:" + type);
}
Expand All @@ -129,14 +137,28 @@ private int expectedScanTaskCount(int partitions) {
}
case DATA_FILES:
case DELETE_FILES:
case ALL_DELETE_FILES:
return partitions;
case ALL_DATA_FILES:
return partitions * 2; // ScanTask for Data Manifest in DELETED and ADDED states
case ALL_FILES:
if (formatVersion == 1) {
return partitions * 2; // ScanTask for Data Manifest in DELETED and ADDED states
} else {
return partitions * 4; // ScanTask for Delete and Data File in DELETED and ADDED states
}
default:
throw new IllegalArgumentException("Unsupported metadata table type:" + type);
}
}

private boolean allFileTableTest(MetadataTableType tableType) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This might read better as isAllFilesTable, though I recognize there is an AllFilesTable now.

Maybe isOneOfAllFilesType or isTableAggregatedFromAllSnapshots?

Given there will be an ALL_FILES table, I'm not sure of the best name to add for this but throwing those out there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about isAggFileTable?

return Sets.newHashSet(MetadataTableType.ALL_DATA_FILES,
MetadataTableType.ALL_DATA_FILES,
MetadataTableType.ALL_FILES)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Consider making this a static final constant.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for a constant

.contains(tableType);
}

@Test
public void testNoFilter() {
Table metadataTable = createMetadataTable();
Expand Down Expand Up @@ -288,7 +310,7 @@ public void testPartitionSpecEvolutionRemovalV1() {
table.newFastAppend().appendFile(data10).commit();
table.newFastAppend().appendFile(data11).commit();

if (type.equals(MetadataTableType.ALL_DATA_FILES)) {
if (allFileTableTest(type)) {
// Clear all files from current snapshot to test whether 'all' Files tables scans previous files
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Moves file entries to DELETED state
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Removes all entries
Expand Down Expand Up @@ -363,7 +385,7 @@ public void testPartitionSpecEvolutionRemovalV2() {
table.newRowDelta().addDeletes(delete11).commit();
}

if (type.equals(MetadataTableType.ALL_DATA_FILES)) {
if (allFileTableTest(type)) {
// Clear all files from current snapshot to test whether 'all' Files tables scans previous files
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Moves file entries to DELETED state
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Removes all entries
Expand Down Expand Up @@ -424,7 +446,7 @@ public void testPartitionSpecEvolutionAdditiveV1() {
table.newFastAppend().appendFile(data10).commit();
table.newFastAppend().appendFile(data11).commit();

if (type.equals(MetadataTableType.ALL_DATA_FILES)) {
if (allFileTableTest(type)) {
// Clear all files from current snapshot to test whether 'all' Files tables scans previous files
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Moves file entries to DELETED state
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Removes all entries
Expand Down Expand Up @@ -499,7 +521,7 @@ public void testPartitionSpecEvolutionAdditiveV2() {
table.newRowDelta().addDeletes(delete11).commit();
}

if (type.equals(MetadataTableType.ALL_DATA_FILES)) {
if (allFileTableTest(type)) {
// Clear all files from current snapshot to test whether 'all' Files tables scans previous files
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Moves file entries to DELETED state
table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit(); // Removes all entries
Expand Down
Loading