Skip to content

Commit e230f5d

Browse files
authored
Data: Add partition stats writer and reader (#11216)
1 parent b87edbb commit e230f5d

File tree

6 files changed

+920
-38
lines changed

6 files changed

+920
-38
lines changed

api/src/main/java/org/apache/iceberg/UpdatePartitionStatistics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public interface UpdatePartitionStatistics extends PendingUpdate<List<PartitionStatisticsFile>> {
2525
/**
2626
* Set the table's partition statistics file for given snapshot, replacing the previous partition
27-
* statistics file for the snapshot if any exists.
27+
* statistics file for the snapshot if any exists. No-op if the provided file is null.
2828
*
2929
* @return this for method chaining
3030
*/

core/src/main/java/org/apache/iceberg/SetPartitionStatistics.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222
import java.util.Map;
2323
import java.util.Set;
24-
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
2524
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
2625
import org.apache.iceberg.relocated.com.google.common.collect.Sets;
2726

@@ -36,7 +35,10 @@ public SetPartitionStatistics(TableOperations ops) {
3635

3736
@Override
3837
public UpdatePartitionStatistics setPartitionStatistics(PartitionStatisticsFile file) {
39-
Preconditions.checkArgument(null != file, "partition statistics file must not be null");
38+
if (file == null) {
39+
return this;
40+
}
41+
4042
statsToSet.put(file.snapshotId(), file);
4143
return this;
4244
}

core/src/test/java/org/apache/iceberg/TestRowLineageMetadata.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ public void testEnableRowLineageViaPropertyAtTableCreation() {
316316
tableDir,
317317
"test",
318318
TEST_SCHEMA,
319-
ImmutableMap.of(TableProperties.ROW_LINEAGE, "true"),
320-
formatVersion);
319+
PartitionSpec.unpartitioned(),
320+
formatVersion,
321+
ImmutableMap.of(TableProperties.ROW_LINEAGE, "true"));
321322
assertThat(table.ops().current().rowLineageEnabled()).isTrue();
322323
}
323324

core/src/test/java/org/apache/iceberg/TestTables.java

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,13 @@ public static TestTable create(
5353
}
5454

5555
public static TestTable create(
56-
File temp, String name, Schema schema, Map<String, String> properties, int formatVersion) {
57-
TestTableOperations ops = new TestTableOperations(name, temp);
58-
if (ops.current() != null) {
59-
throw new AlreadyExistsException("Table %s already exists at location: %s", name, temp);
60-
}
61-
62-
ops.commit(
63-
null,
64-
newTableMetadata(
65-
schema,
66-
PartitionSpec.unpartitioned(),
67-
SortOrder.unsorted(),
68-
temp.toString(),
69-
properties,
70-
formatVersion));
71-
72-
return new TestTable(ops);
56+
File temp,
57+
String name,
58+
Schema schema,
59+
PartitionSpec spec,
60+
SortOrder sortOrder,
61+
int formatVersion) {
62+
return createTable(temp, name, schema, spec, formatVersion, ImmutableMap.of(), sortOrder, null);
7363
}
7464

7565
public static TestTable create(
@@ -78,27 +68,31 @@ public static TestTable create(
7868
Schema schema,
7969
PartitionSpec spec,
8070
SortOrder sortOrder,
81-
int formatVersion) {
82-
TestTableOperations ops = new TestTableOperations(name, temp);
83-
if (ops.current() != null) {
84-
throw new AlreadyExistsException("Table %s already exists at location: %s", name, temp);
85-
}
86-
87-
ops.commit(
88-
null,
89-
newTableMetadata(
90-
schema, spec, sortOrder, temp.toString(), ImmutableMap.of(), formatVersion));
91-
92-
return new TestTable(ops);
71+
int formatVersion,
72+
MetricsReporter reporter) {
73+
return createTable(
74+
temp, name, schema, spec, formatVersion, ImmutableMap.of(), sortOrder, reporter);
9375
}
9476

9577
public static TestTable create(
9678
File temp,
9779
String name,
9880
Schema schema,
9981
PartitionSpec spec,
100-
SortOrder sortOrder,
10182
int formatVersion,
83+
Map<String, String> properties) {
84+
return createTable(
85+
temp, name, schema, spec, formatVersion, properties, SortOrder.unsorted(), null);
86+
}
87+
88+
private static TestTable createTable(
89+
File temp,
90+
String name,
91+
Schema schema,
92+
PartitionSpec spec,
93+
int formatVersion,
94+
Map<String, String> properties,
95+
SortOrder sortOrder,
10296
MetricsReporter reporter) {
10397
TestTableOperations ops = new TestTableOperations(name, temp);
10498
if (ops.current() != null) {
@@ -107,10 +101,13 @@ public static TestTable create(
107101

108102
ops.commit(
109103
null,
110-
newTableMetadata(
111-
schema, spec, sortOrder, temp.toString(), ImmutableMap.of(), formatVersion));
104+
newTableMetadata(schema, spec, sortOrder, temp.toString(), properties, formatVersion));
112105

113-
return new TestTable(ops, reporter);
106+
if (reporter != null) {
107+
return new TestTable(ops, reporter);
108+
} else {
109+
return new TestTable(ops);
110+
}
114111
}
115112

116113
public static Transaction beginCreate(File temp, String name, Schema schema, PartitionSpec spec) {

0 commit comments

Comments
 (0)