You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by lz...@apache.org on 2024/09/05 08:00:24 UTC
(paimon) branch master updated: [orc] Move config write.batch-size to CoreOptions (#4130)
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new ed8192151 [orc] Move config write.batch-size to CoreOptions (#4130)
ed8192151 is described below
commit ed8192151bc263e2520ae1742c0dd3e22c876899
Author: YeJunHao <41...@users.noreply.github.com>
AuthorDate: Thu Sep 5 16:00:18 2024 +0800
[orc] Move config write.batch-size to CoreOptions (#4130)
---
.../shortcodes/generated/core_configuration.html | 8 +++++-
.../shortcodes/generated/orc_configuration.html | 6 -----
.../main/java/org/apache/paimon/CoreOptions.java | 9 ++++++-
.../java/org/apache/paimon/format/FileFormat.java | 3 ++-
.../apache/paimon/format/FileFormatFactory.java | 11 ++++++--
.../java/org/apache/paimon/format/OrcOptions.java | 6 -----
.../apache/paimon/format/orc/OrcFileFormat.java | 4 ++-
.../apache/paimon/format/orc/OrcWriterFactory.java | 29 ++++++----------------
.../paimon/format/avro/AvroFileFormatTest.java | 4 +--
.../format/avro/AvroFormatReadWriteTest.java | 2 +-
.../paimon/format/orc/OrcFileFormatTest.java | 8 +++---
.../paimon/format/orc/OrcFormatReadWriteTest.java | 2 +-
.../format/orc/writer/OrcBulkWriterTest.java | 5 ++--
.../paimon/format/orc/writer/OrcZstdTest.java | 2 +-
.../format/parquet/ParquetFileFormatTest.java | 9 ++++---
.../format/parquet/ParquetFormatReadWriteTest.java | 3 ++-
16 files changed, 56 insertions(+), 55 deletions(-)
diff --git a/docs/layouts/shortcodes/generated/core_configuration.html b/docs/layouts/shortcodes/generated/core_configuration.html
index 508368559..daa0805b1 100644
--- a/docs/layouts/shortcodes/generated/core_configuration.html
+++ b/docs/layouts/shortcodes/generated/core_configuration.html
@@ -573,7 +573,7 @@ This config option does not affect the default filesystem metastore.</td>
<td><h5>read.batch-size</h5></td>
<td style="word-wrap: break-word;">1024</td>
<td>Integer</td>
- <td>Read batch size for orc and parquet.</td>
+ <td>Read batch size for any file format if it supports.</td>
</tr>
<tr>
<td><h5>record-level.expire-time</h5></td>
@@ -900,6 +900,12 @@ If the data size allocated for the sorting task is uneven,which may lead to perf
<td>Boolean</td>
<td>If set to true, compactions and snapshot expiration will be skipped. This option is used along with dedicated compact jobs.</td>
</tr>
+ <tr>
+ <td><h5>write.batch-size</h5></td>
+ <td style="word-wrap: break-word;">1024</td>
+ <td>Integer</td>
+ <td>Write batch size for any file format if it supports.</td>
+ </tr>
<tr>
<td><h5>zorder.var-length-contribution</h5></td>
<td style="word-wrap: break-word;">8</td>
diff --git a/docs/layouts/shortcodes/generated/orc_configuration.html b/docs/layouts/shortcodes/generated/orc_configuration.html
index 96c25f6f6..390b26359 100644
--- a/docs/layouts/shortcodes/generated/orc_configuration.html
+++ b/docs/layouts/shortcodes/generated/orc_configuration.html
@@ -38,11 +38,5 @@ under the License.
<td>Double</td>
<td>If the number of distinct keys in a dictionary is greater than this fraction of the total number of non-null rows, turn off dictionary encoding in orc. Use 0 to always disable dictionary encoding. Use 1 to always use dictionary encoding.</td>
</tr>
- <tr>
- <td><h5>orc.write.batch-size</h5></td>
- <td style="word-wrap: break-word;">1024</td>
- <td>Integer</td>
- <td>write batch size for orc.</td>
- </tr>
</tbody>
</table>
diff --git a/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java b/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java
index ecef7a9cb..1771626e1 100644
--- a/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java
+++ b/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java
@@ -878,7 +878,14 @@ public class CoreOptions implements Serializable {
key("read.batch-size")
.intType()
.defaultValue(1024)
- .withDescription("Read batch size for orc and parquet.");
+ .withDescription("Read batch size for any file format if it supports.");
+
+ public static final ConfigOption<Integer> WRITE_BATCH_SIZE =
+ key("write.batch-size")
+ .intType()
+ .defaultValue(1024)
+ .withFallbackKeys("orc.write.batch-size")
+ .withDescription("Write batch size for any file format if it supports.");
public static final ConfigOption<String> CONSUMER_ID =
key("consumer-id")
diff --git a/paimon-common/src/main/java/org/apache/paimon/format/FileFormat.java b/paimon-common/src/main/java/org/apache/paimon/format/FileFormat.java
index daf9e5494..78dfe1c0c 100644
--- a/paimon-common/src/main/java/org/apache/paimon/format/FileFormat.java
+++ b/paimon-common/src/main/java/org/apache/paimon/format/FileFormat.java
@@ -76,7 +76,7 @@ public abstract class FileFormat {
@VisibleForTesting
public static FileFormat fromIdentifier(String identifier, Options options) {
- return fromIdentifier(identifier, new FormatContext(options, 1024));
+ return fromIdentifier(identifier, new FormatContext(options, 1024, 1024));
}
/** Create a {@link FileFormat} from format identifier and format options. */
@@ -108,6 +108,7 @@ public abstract class FileFormat {
new FormatContext(
options.removePrefix(formatIdentifier + "."),
options.get(CoreOptions.READ_BATCH_SIZE),
+ options.get(CoreOptions.WRITE_BATCH_SIZE),
options.get(CoreOptions.FILE_COMPRESSION_ZSTD_LEVEL),
options.get(CoreOptions.FILE_BLOCK_SIZE));
return FileFormat.fromIdentifier(formatIdentifier, context);
diff --git a/paimon-common/src/main/java/org/apache/paimon/format/FileFormatFactory.java b/paimon-common/src/main/java/org/apache/paimon/format/FileFormatFactory.java
index 1bb681177..192a0f9f1 100644
--- a/paimon-common/src/main/java/org/apache/paimon/format/FileFormatFactory.java
+++ b/paimon-common/src/main/java/org/apache/paimon/format/FileFormatFactory.java
@@ -36,21 +36,24 @@ public interface FileFormatFactory {
private final Options formatOptions;
private final int readBatchSize;
+ private final int writeBatchSize;
private final int zstdLevel;
@Nullable private final MemorySize blockSize;
@VisibleForTesting
- public FormatContext(Options formatOptions, int readBatchSize) {
- this(formatOptions, readBatchSize, 1, null);
+ public FormatContext(Options formatOptions, int readBatchSize, int writeBatchSize) {
+ this(formatOptions, readBatchSize, writeBatchSize, 1, null);
}
public FormatContext(
Options formatOptions,
int readBatchSize,
+ int writeBatchSize,
int zstdLevel,
@Nullable MemorySize blockSize) {
this.formatOptions = formatOptions;
this.readBatchSize = readBatchSize;
+ this.writeBatchSize = writeBatchSize;
this.zstdLevel = zstdLevel;
this.blockSize = blockSize;
}
@@ -63,6 +66,10 @@ public interface FileFormatFactory {
return readBatchSize;
}
+ public int writeBatchSize() {
+ return writeBatchSize;
+ }
+
public int zstdLevel() {
return zstdLevel;
}
diff --git a/paimon-format/src/main/java/org/apache/paimon/format/OrcOptions.java b/paimon-format/src/main/java/org/apache/paimon/format/OrcOptions.java
index 3b72f1caa..dad262867 100644
--- a/paimon-format/src/main/java/org/apache/paimon/format/OrcOptions.java
+++ b/paimon-format/src/main/java/org/apache/paimon/format/OrcOptions.java
@@ -25,12 +25,6 @@ import static org.apache.paimon.options.ConfigOptions.key;
/** Options for orc format. */
public class OrcOptions {
- public static final ConfigOption<Integer> ORC_WRITE_BATCH_SIZE =
- key("orc.write.batch-size")
- .intType()
- .defaultValue(1024)
- .withDescription("write batch size for orc.");
-
public static final ConfigOption<Integer> ORC_COLUMN_ENCODING_DIRECT =
key("orc.column.encoding.direct")
.intType()
diff --git a/paimon-format/src/main/java/org/apache/paimon/format/orc/OrcFileFormat.java b/paimon-format/src/main/java/org/apache/paimon/format/orc/OrcFileFormat.java
index de28487b7..120fb134c 100644
--- a/paimon-format/src/main/java/org/apache/paimon/format/orc/OrcFileFormat.java
+++ b/paimon-format/src/main/java/org/apache/paimon/format/orc/OrcFileFormat.java
@@ -68,6 +68,7 @@ public class OrcFileFormat extends FileFormat {
private final org.apache.hadoop.conf.Configuration readerConf;
private final org.apache.hadoop.conf.Configuration writerConf;
private final int readBatchSize;
+ private final int writeBatchSize;
public OrcFileFormat(FormatContext formatContext) {
super(IDENTIFIER);
@@ -77,6 +78,7 @@ public class OrcFileFormat extends FileFormat {
this.writerConf = new org.apache.hadoop.conf.Configuration();
this.orcProperties.forEach((k, v) -> writerConf.set(k.toString(), v.toString()));
this.readBatchSize = formatContext.readBatchSize();
+ this.writeBatchSize = formatContext.writeBatchSize();
}
@VisibleForTesting
@@ -140,7 +142,7 @@ public class OrcFileFormat extends FileFormat {
Vectorizer<InternalRow> vectorizer =
new RowDataVectorizer(typeDescription.toString(), orcTypes);
- return new OrcWriterFactory(vectorizer, orcProperties, writerConf);
+ return new OrcWriterFactory(vectorizer, orcProperties, writerConf, writeBatchSize);
}
private static Properties getOrcProperties(Options options, FormatContext formatContext) {
diff --git a/paimon-format/src/main/java/org/apache/paimon/format/orc/OrcWriterFactory.java b/paimon-format/src/main/java/org/apache/paimon/format/orc/OrcWriterFactory.java
index 76a01f01b..701c81a84 100644
--- a/paimon-format/src/main/java/org/apache/paimon/format/orc/OrcWriterFactory.java
+++ b/paimon-format/src/main/java/org/apache/paimon/format/orc/OrcWriterFactory.java
@@ -18,7 +18,6 @@
package org.apache.paimon.format.orc;
-import org.apache.paimon.CoreOptions;
import org.apache.paimon.annotation.VisibleForTesting;
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.format.FormatWriter;
@@ -43,7 +42,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.UUID;
-import static org.apache.paimon.format.OrcOptions.ORC_WRITE_BATCH_SIZE;
import static org.apache.paimon.utils.Preconditions.checkNotNull;
/**
@@ -58,7 +56,7 @@ public class OrcWriterFactory implements FormatWriterFactory {
private final Map<String, String> confMap;
private OrcFile.WriterOptions writerOptions;
- private final CoreOptions coreOptions;
+ private final int writeBatchSize;
/**
* Creates a new OrcBulkWriterFactory using the provided Vectorizer implementation.
@@ -66,18 +64,9 @@ public class OrcWriterFactory implements FormatWriterFactory {
* @param vectorizer The vectorizer implementation to convert input record to a
* VectorizerRowBatch.
*/
- public OrcWriterFactory(Vectorizer<InternalRow> vectorizer) {
- this(vectorizer, new Configuration());
- }
-
- /**
- * Creates a new OrcBulkWriterFactory using the provided Vectorizer, Hadoop Configuration.
- *
- * @param vectorizer The vectorizer implementation to convert input record to a
- * VectorizerRowBatch.
- */
- public OrcWriterFactory(Vectorizer<InternalRow> vectorizer, Configuration configuration) {
- this(vectorizer, new Properties(), configuration);
+ @VisibleForTesting
+ OrcWriterFactory(Vectorizer<InternalRow> vectorizer) {
+ this(vectorizer, new Properties(), new Configuration(), 1024);
}
/**
@@ -91,7 +80,8 @@ public class OrcWriterFactory implements FormatWriterFactory {
public OrcWriterFactory(
Vectorizer<InternalRow> vectorizer,
Properties writerProperties,
- Configuration configuration) {
+ Configuration configuration,
+ int writeBatchSize) {
this.vectorizer = checkNotNull(vectorizer);
this.writerProperties = checkNotNull(writerProperties);
this.confMap = new HashMap<>();
@@ -100,7 +90,7 @@ public class OrcWriterFactory implements FormatWriterFactory {
for (Map.Entry<String, String> entry : configuration) {
confMap.put(entry.getKey(), entry.getValue());
}
- coreOptions = new CoreOptions(this.confMap);
+ this.writeBatchSize = writeBatchSize;
}
@Override
@@ -127,10 +117,7 @@ public class OrcWriterFactory implements FormatWriterFactory {
// the key of writer in the ORC memory manager, thus we need to make it unique.
Path unusedPath = new Path(UUID.randomUUID().toString());
return new OrcBulkWriter(
- vectorizer,
- new WriterImpl(null, unusedPath, opts),
- out,
- coreOptions.toConfiguration().get(ORC_WRITE_BATCH_SIZE));
+ vectorizer, new WriterImpl(null, unusedPath, opts), out, writeBatchSize);
}
@VisibleForTesting
diff --git a/paimon-format/src/test/java/org/apache/paimon/format/avro/AvroFileFormatTest.java b/paimon-format/src/test/java/org/apache/paimon/format/avro/AvroFileFormatTest.java
index 1f6ccfe67..bdf76649e 100644
--- a/paimon-format/src/test/java/org/apache/paimon/format/avro/AvroFileFormatTest.java
+++ b/paimon-format/src/test/java/org/apache/paimon/format/avro/AvroFileFormatTest.java
@@ -52,7 +52,7 @@ public class AvroFileFormatTest {
@BeforeAll
public static void before() {
- fileFormat = new AvroFileFormat(new FormatContext(new Options(), 1024));
+ fileFormat = new AvroFileFormat(new FormatContext(new Options(), 1024, 1024));
}
@Test
@@ -106,7 +106,7 @@ public class AvroFileFormatTest {
@Test
void testReadRowPosition() throws IOException {
RowType rowType = DataTypes.ROW(DataTypes.INT().notNull());
- FileFormat format = new AvroFileFormat(new FormatContext(new Options(), 1024));
+ FileFormat format = new AvroFileFormat(new FormatContext(new Options(), 1024, 1024));
LocalFileIO fileIO = LocalFileIO.create();
Path file = new Path(new Path(tempPath.toUri()), UUID.randomUUID().toString());
diff --git a/paimon-format/src/test/java/org/apache/paimon/format/avro/AvroFormatReadWriteTest.java b/paimon-format/src/test/java/org/apache/paimon/format/avro/AvroFormatReadWriteTest.java
index b8da2be67..4b0dcf247 100644
--- a/paimon-format/src/test/java/org/apache/paimon/format/avro/AvroFormatReadWriteTest.java
+++ b/paimon-format/src/test/java/org/apache/paimon/format/avro/AvroFormatReadWriteTest.java
@@ -32,6 +32,6 @@ public class AvroFormatReadWriteTest extends FormatReadWriteTest {
@Override
protected FileFormat fileFormat() {
- return new AvroFileFormat(new FileFormatFactory.FormatContext(new Options(), 1024));
+ return new AvroFileFormat(new FileFormatFactory.FormatContext(new Options(), 1024, 1024));
}
}
diff --git a/paimon-format/src/test/java/org/apache/paimon/format/orc/OrcFileFormatTest.java b/paimon-format/src/test/java/org/apache/paimon/format/orc/OrcFileFormatTest.java
index eeee076da..d02a0514c 100644
--- a/paimon-format/src/test/java/org/apache/paimon/format/orc/OrcFileFormatTest.java
+++ b/paimon-format/src/test/java/org/apache/paimon/format/orc/OrcFileFormatTest.java
@@ -39,7 +39,8 @@ public class OrcFileFormatTest {
public void testAbsent() {
Options options = new Options();
options.setString("haha", "1");
- OrcFileFormat orc = new OrcFileFormatFactory().create(new FormatContext(options, 1024));
+ OrcFileFormat orc =
+ new OrcFileFormatFactory().create(new FormatContext(options, 1024, 1024));
assertThat(orc.orcProperties().getProperty(IDENTIFIER + ".haha", "")).isEqualTo("1");
}
@@ -48,7 +49,8 @@ public class OrcFileFormatTest {
Options options = new Options();
options.setString("haha", "1");
options.setString("compress", "zlib");
- OrcFileFormat orc = new OrcFileFormatFactory().create(new FormatContext(options, 1024));
+ OrcFileFormat orc =
+ new OrcFileFormatFactory().create(new FormatContext(options, 1024, 1024));
assertThat(orc.orcProperties().getProperty(IDENTIFIER + ".haha", "")).isEqualTo("1");
assertThat(orc.orcProperties().getProperty(IDENTIFIER + ".compress", "")).isEqualTo("zlib");
}
@@ -56,7 +58,7 @@ public class OrcFileFormatTest {
@Test
public void testSupportedDataTypes() {
OrcFileFormat orc =
- new OrcFileFormatFactory().create(new FormatContext(new Options(), 1024));
+ new OrcFileFormatFactory().create(new FormatContext(new Options(), 1024, 1024));
int index = 0;
List<DataField> dataFields = new ArrayList<DataField>();
diff --git a/paimon-format/src/test/java/org/apache/paimon/format/orc/OrcFormatReadWriteTest.java b/paimon-format/src/test/java/org/apache/paimon/format/orc/OrcFormatReadWriteTest.java
index 3e6805862..782d0fc11 100644
--- a/paimon-format/src/test/java/org/apache/paimon/format/orc/OrcFormatReadWriteTest.java
+++ b/paimon-format/src/test/java/org/apache/paimon/format/orc/OrcFormatReadWriteTest.java
@@ -32,6 +32,6 @@ public class OrcFormatReadWriteTest extends FormatReadWriteTest {
@Override
protected FileFormat fileFormat() {
- return new OrcFileFormat(new FileFormatFactory.FormatContext(new Options(), 1024));
+ return new OrcFileFormat(new FileFormatFactory.FormatContext(new Options(), 1024, 1024));
}
}
diff --git a/paimon-format/src/test/java/org/apache/paimon/format/orc/writer/OrcBulkWriterTest.java b/paimon-format/src/test/java/org/apache/paimon/format/orc/writer/OrcBulkWriterTest.java
index 13e75cc77..899f77dc4 100644
--- a/paimon-format/src/test/java/org/apache/paimon/format/orc/writer/OrcBulkWriterTest.java
+++ b/paimon-format/src/test/java/org/apache/paimon/format/orc/writer/OrcBulkWriterTest.java
@@ -18,6 +18,7 @@
package org.apache.paimon.format.orc.writer;
+import org.apache.paimon.CoreOptions;
import org.apache.paimon.format.FileFormat;
import org.apache.paimon.format.FormatWriter;
import org.apache.paimon.format.FormatWriterFactory;
@@ -36,14 +37,12 @@ import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
-import static org.apache.paimon.format.OrcOptions.ORC_WRITE_BATCH_SIZE;
-
class OrcBulkWriterTest {
@Test
void testRowBatch(@TempDir java.nio.file.Path tempDir) throws IOException {
Options options = new Options();
- options.set(ORC_WRITE_BATCH_SIZE, 1);
+ options.set(CoreOptions.WRITE_BATCH_SIZE, 1);
FileFormat orc = FileFormat.getFileFormat(options, "orc");
Assertions.assertThat(orc).isInstanceOf(OrcFileFormat.class);
diff --git a/paimon-format/src/test/java/org/apache/paimon/format/orc/writer/OrcZstdTest.java b/paimon-format/src/test/java/org/apache/paimon/format/orc/writer/OrcZstdTest.java
index 4a1c25393..b5f74ea83 100644
--- a/paimon-format/src/test/java/org/apache/paimon/format/orc/writer/OrcZstdTest.java
+++ b/paimon-format/src/test/java/org/apache/paimon/format/orc/writer/OrcZstdTest.java
@@ -64,7 +64,7 @@ class OrcZstdTest {
options.set("compression.zstd.level", "1");
OrcFileFormat orc =
new OrcFileFormatFactory()
- .create(new FileFormatFactory.FormatContext(options, 1024));
+ .create(new FileFormatFactory.FormatContext(options, 1024, 1024));
Assertions.assertThat(orc).isInstanceOf(OrcFileFormat.class);
Assertions.assertThat(orc.orcProperties().getProperty(IDENTIFIER + ".compress", ""))
diff --git a/paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFileFormatTest.java b/paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFileFormatTest.java
index e7f0b19d4..61c24026e 100644
--- a/paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFileFormatTest.java
+++ b/paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFileFormatTest.java
@@ -47,7 +47,7 @@ public class ParquetFileFormatTest {
public void testAbsent() {
Options options = new Options();
ParquetFileFormat parquet =
- new ParquetFileFormatFactory().create(new FormatContext(options, 1024));
+ new ParquetFileFormatFactory().create(new FormatContext(options, 1024, 1024));
assertThat(parquet.formatOptions().getString(KEY1)).isEqualTo("absent");
}
@@ -56,7 +56,7 @@ public class ParquetFileFormatTest {
Options options = new Options();
options.setString(KEY1.key(), "v1");
ParquetFileFormat parquet =
- new ParquetFileFormatFactory().create(new FormatContext(options, 1024));
+ new ParquetFileFormatFactory().create(new FormatContext(options, 1024, 1024));
assertThat(parquet.formatOptions().getString(KEY1)).isEqualTo("v1");
}
@@ -69,7 +69,8 @@ public class ParquetFileFormatTest {
new RowDataParquetBuilder(
new RowType(new ArrayList<>()),
getParquetConfiguration(
- new FormatContext(conf.removePrefix(IDENTIFIER + "."), 1024)));
+ new FormatContext(
+ conf.removePrefix(IDENTIFIER + "."), 1024, 1024)));
assertThat(builder.getCompression(null)).isEqualTo(lz4);
assertThat(builder.getCompression("SNAPPY")).isEqualTo(lz4);
}
@@ -77,7 +78,7 @@ public class ParquetFileFormatTest {
@Test
public void testSupportedDataFields() {
ParquetFileFormat parquet =
- new ParquetFileFormatFactory().create(new FormatContext(new Options(), 1024));
+ new ParquetFileFormatFactory().create(new FormatContext(new Options(), 1024, 1024));
int index = 0;
List<DataField> dataFields = new ArrayList<DataField>();
diff --git a/paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFormatReadWriteTest.java b/paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFormatReadWriteTest.java
index 4cfcffe22..d5338b1e7 100644
--- a/paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFormatReadWriteTest.java
+++ b/paimon-format/src/test/java/org/apache/paimon/format/parquet/ParquetFormatReadWriteTest.java
@@ -32,6 +32,7 @@ public class ParquetFormatReadWriteTest extends FormatReadWriteTest {
@Override
protected FileFormat fileFormat() {
- return new ParquetFileFormat(new FileFormatFactory.FormatContext(new Options(), 1024));
+ return new ParquetFileFormat(
+ new FileFormatFactory.FormatContext(new Options(), 1024, 1024));
}
}