Skip to content

Commit 03f2af8

Browse files
authored
Core: Deprecate and remove GenericAppenderFactory from tests (#14353)
1 parent e8e9763 commit 03f2af8

65 files changed

Lines changed: 605 additions & 1247 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public final class MetricsConfig implements Serializable {
5555
private static final MetricsMode DEFAULT_MODE =
5656
MetricsModes.fromString(DEFAULT_WRITE_METRICS_MODE_DEFAULT);
5757
private static final MetricsConfig DEFAULT = new MetricsConfig(ImmutableMap.of(), DEFAULT_MODE);
58+
private static final MetricsConfig POSITION_DELETE_MODE =
59+
new MetricsConfig(
60+
ImmutableMap.of(
61+
MetadataColumns.DELETE_FILE_PATH.name(),
62+
MetricsModes.Full.get(),
63+
MetadataColumns.DELETE_FILE_POS.name(),
64+
MetricsModes.Full.get()),
65+
DEFAULT_MODE);
5866

5967
private final Map<String, MetricsMode> columnModes;
6068
private final MetricsMode defaultMode;
@@ -68,6 +76,10 @@ public static MetricsConfig getDefault() {
6876
return DEFAULT;
6977
}
7078

79+
public static MetricsConfig forPositionDelete() {
80+
return POSITION_DELETE_MODE;
81+
}
82+
7183
/**
7284
* Creates a metrics config from table configuration.
7385
*
@@ -92,7 +104,11 @@ public static MetricsConfig forTable(Table table) {
92104
* Creates a metrics config for a position delete file.
93105
*
94106
* @param table an Iceberg table
107+
* @deprecated This method is deprecated as of version 1.11.0 and will be removed in 1.12.0.
108+
* Position deletes that include row data are no longer supported. Use {@link
109+
* #forPositionDelete()} instead.
95110
*/
111+
@Deprecated
96112
public static MetricsConfig forPositionDelete(Table table) {
97113
ImmutableMap.Builder<String, MetricsMode> columnModes = ImmutableMap.builder();
98114

core/src/main/java/org/apache/iceberg/io/SortedPosDeleteWriter.java

Lines changed: 0 additions & 214 deletions
This file was deleted.

data/src/main/java/org/apache/iceberg/data/BaseFileWriterFactory.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ protected BaseFileWriterFactory(
150150
public DataWriter<T> newDataWriter(
151151
EncryptedOutputFile file, PartitionSpec spec, StructLike partition) {
152152
EncryptionKeyMetadata keyMetadata = file.keyMetadata();
153-
Map<String, String> properties = table.properties();
154-
MetricsConfig metricsConfig = MetricsConfig.forTable(table);
153+
Map<String, String> properties = table == null ? ImmutableMap.of() : table.properties();
154+
MetricsConfig metricsConfig =
155+
table == null ? MetricsConfig.getDefault() : MetricsConfig.forTable(table);
155156

156157
try {
157158
switch (dataFileFormat) {
@@ -219,8 +220,9 @@ public DataWriter<T> newDataWriter(
219220
public EqualityDeleteWriter<T> newEqualityDeleteWriter(
220221
EncryptedOutputFile file, PartitionSpec spec, StructLike partition) {
221222
EncryptionKeyMetadata keyMetadata = file.keyMetadata();
222-
Map<String, String> properties = table.properties();
223-
MetricsConfig metricsConfig = MetricsConfig.forTable(table);
223+
Map<String, String> properties = table == null ? ImmutableMap.of() : table.properties();
224+
MetricsConfig metricsConfig =
225+
table == null ? MetricsConfig.getDefault() : MetricsConfig.forTable(table);
224226

225227
try {
226228
switch (deleteFileFormat) {
@@ -291,8 +293,9 @@ public EqualityDeleteWriter<T> newEqualityDeleteWriter(
291293
public PositionDeleteWriter<T> newPositionDeleteWriter(
292294
EncryptedOutputFile file, PartitionSpec spec, StructLike partition) {
293295
EncryptionKeyMetadata keyMetadata = file.keyMetadata();
294-
Map<String, String> properties = table.properties();
295-
MetricsConfig metricsConfig = MetricsConfig.forPositionDelete(table);
296+
Map<String, String> properties = table == null ? ImmutableMap.of() : table.properties();
297+
MetricsConfig metricsConfig =
298+
table == null ? MetricsConfig.forPositionDelete() : MetricsConfig.forPositionDelete(table);
296299

297300
try {
298301
switch (deleteFileFormat) {

data/src/main/java/org/apache/iceberg/data/GenericAppenderFactory.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
4545
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
4646

47-
/** Factory to create a new {@link FileAppender} to write {@link Record}s. */
47+
/**
48+
* Factory to create a new {@link FileAppender} to write {@link Record}s.
49+
*
50+
* @deprecated will be removed in 1.12.0; use {@link GenericFileWriterFactory} instead.
51+
*/
52+
@Deprecated
4853
public class GenericAppenderFactory implements FileAppenderFactory<Record> {
4954
private final Table table;
5055
private final Schema schema;
@@ -62,12 +67,6 @@ public GenericAppenderFactory(Schema schema, PartitionSpec spec) {
6267
this(schema, spec, null, null, null);
6368
}
6469

65-
/**
66-
* @deprecated This constructor is deprecated as of version 1.11.0 and will be removed in 1.12.0.
67-
* Position deletes that include row data are no longer supported. Use {@link
68-
* #GenericAppenderFactory(Schema, PartitionSpec, int[], Schema)} instead.
69-
*/
70-
@Deprecated
7170
public GenericAppenderFactory(
7271
Schema schema,
7372
PartitionSpec spec,

data/src/main/java/org/apache/iceberg/data/GenericFileWriterFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ public static class Builder {
177177
private Schema positionDeleteRowSchema;
178178
private Map<String, String> writerProperties = ImmutableMap.of();
179179

180+
public Builder() {
181+
this.table = null;
182+
}
183+
180184
public Builder(Table table) {
181185
this.table = table;
182186
this.dataSchema = table.schema();

data/src/test/java/org/apache/iceberg/TestMergingMetrics.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.iceberg.data.GenericRecord;
3333
import org.apache.iceberg.data.RandomGenericData;
3434
import org.apache.iceberg.data.Record;
35-
import org.apache.iceberg.io.FileAppender;
3635
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
3736
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
3837
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
@@ -105,7 +104,7 @@ public abstract class TestMergingMetrics<T> {
105104
MAP_FIELD_2,
106105
STRUCT_FIELD);
107106

108-
protected abstract FileAppender<T> writeAndGetAppender(List<Record> records) throws Exception;
107+
protected abstract DataFile writeAndGetDataFile(List<Record> records) throws Exception;
109108

110109
@Parameters(name = "fileFormat = {0}")
111110
public static List<Object> parameters() {
@@ -131,11 +130,10 @@ public void verifySingleRecordMetric() throws Exception {
131130
ImmutableMap.of(
132131
0, 0D, 1, Double.NaN, 2, 2D, 3, Double.NaN, 4, Double.NaN)); // MAP_FIELD_2 - 3
133132

134-
FileAppender<T> appender = writeAndGetAppender(ImmutableList.of(record));
135-
Metrics metrics = appender.metrics();
136-
Map<Integer, Long> nanValueCount = metrics.nanValueCounts();
137-
Map<Integer, ByteBuffer> upperBounds = metrics.upperBounds();
138-
Map<Integer, ByteBuffer> lowerBounds = metrics.lowerBounds();
133+
DataFile dataFile = writeAndGetDataFile(ImmutableList.of(record));
134+
Map<Integer, Long> nanValueCount = dataFile.nanValueCounts();
135+
Map<Integer, ByteBuffer> upperBounds = dataFile.upperBounds();
136+
Map<Integer, ByteBuffer> lowerBounds = dataFile.lowerBounds();
139137

140138
assertThat(nanValueCount).hasSize(2);
141139
assertNaNCountMatch(1L, nanValueCount, FLOAT_FIELD);
@@ -153,28 +151,27 @@ public void verifyRandomlyGeneratedRecordsMetric() throws Exception {
153151
// too big of the record count will more likely to make all upper/lower bounds +/-infinity,
154152
// which makes the tests easier to pass
155153
List<Record> recordList = RandomGenericData.generate(SCHEMA, 5, 250L);
156-
FileAppender<T> appender = writeAndGetAppender(recordList);
154+
DataFile dataFile = writeAndGetDataFile(recordList);
157155

158156
Map<Types.NestedField, AtomicReference<Number>> expectedUpperBounds = Maps.newHashMap();
159157
Map<Types.NestedField, AtomicReference<Number>> expectedLowerBounds = Maps.newHashMap();
160158
Map<Types.NestedField, AtomicLong> expectedNaNCount = Maps.newHashMap();
161159

162160
populateExpectedValues(recordList, expectedUpperBounds, expectedLowerBounds, expectedNaNCount);
163161

164-
Metrics metrics = appender.metrics();
165162
expectedUpperBounds.forEach(
166-
(key, value) -> assertBoundValueMatch(value.get(), metrics.upperBounds(), key));
163+
(key, value) -> assertBoundValueMatch(value.get(), dataFile.upperBounds(), key));
167164
expectedLowerBounds.forEach(
168-
(key, value) -> assertBoundValueMatch(value.get(), metrics.lowerBounds(), key));
165+
(key, value) -> assertBoundValueMatch(value.get(), dataFile.lowerBounds(), key));
169166
expectedNaNCount.forEach(
170-
(key, value) -> assertNaNCountMatch(value.get(), metrics.nanValueCounts(), key));
167+
(key, value) -> assertNaNCountMatch(value.get(), dataFile.nanValueCounts(), key));
171168

172169
SCHEMA.columns().stream()
173170
.filter(column -> !FIELDS_WITH_NAN_COUNT_TO_ID.containsKey(column))
174171
.map(Types.NestedField::fieldId)
175172
.forEach(
176173
id ->
177-
assertThat(metrics.nanValueCounts().get(id))
174+
assertThat(dataFile.nanValueCounts().get(id))
178175
.as("NaN count for field %s should be null")
179176
.isNull());
180177
}

0 commit comments

Comments
 (0)