Skip to content

Commit 5110d36

Browse files
authored
[format] Build fresh ORC writer options per created writer (#9583)
1 parent c10da57 commit 5110d36

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

paimon-format/src/main/java/org/apache/paimon/format/orc/OrcWriterFactory.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public class OrcWriterFactory implements FormatWriterFactory, SupportsShreddingW
6262
private final Properties writerProperties;
6363
private final Map<String, String> confMap;
6464
private final boolean legacyTimestampLtzType;
65-
66-
private OrcFile.WriterOptions writerOptions;
6765
private final int writeBatchSize;
6866
private final MemorySize writeBatchMemory;
6967

@@ -169,11 +167,10 @@ public void commitShreddingMetadata(
169167

170168
@VisibleForTesting
171169
protected OrcFile.WriterOptions getWriterOptions() {
172-
if (null == writerOptions) {
173-
writerOptions = OrcFile.writerOptions(writerProperties, configuration());
174-
writerOptions.setSchema(this.vectorizer.getSchema());
175-
}
176-
170+
// create() writes per-file state into the returned options, so it cannot be cached.
171+
OrcFile.WriterOptions writerOptions =
172+
OrcFile.writerOptions(writerProperties, configuration());
173+
writerOptions.setSchema(this.vectorizer.getSchema());
177174
return writerOptions;
178175
}
179176

paimon-format/src/test/java/org/apache/paimon/format/orc/OrcWriterFactoryTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.IOException;
3636
import java.util.ArrayList;
3737
import java.util.Arrays;
38+
import java.util.Collections;
3839
import java.util.List;
3940

4041
import static org.apache.paimon.utils.Preconditions.checkNotNull;
@@ -99,4 +100,17 @@ public void removeWriter(Path path) {}
99100
@Override
100101
public void addedRow(int rows) {}
101102
}
103+
104+
@Test
105+
void testWriterOptionsNotSharedBetweenCalls() {
106+
// create() writes per-file state into the options, so each caller needs its own.
107+
OrcWriterFactory factory =
108+
new OrcWriterFactory(
109+
new RowDataVectorizer(
110+
TypeDescription.createString(),
111+
Collections.singletonList(
112+
new DataField(0, "f0", DataTypes.STRING())),
113+
false));
114+
assertThat(factory.getWriterOptions()).isNotSameAs(factory.getWriterOptions());
115+
}
102116
}

0 commit comments

Comments
 (0)