This is an automated email from the ASF dual-hosted git repository.
JingsongLi 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 fc97098ebd [core] Allow Format Tables to omit data file format
suffixes (#11009)
fc97098ebd is described below
commit fc97098ebd40e32b628e35189c1d2d6eae49c9e7
Author: tonymtu <[email protected]>
AuthorDate: Fri Nov 6 23:56:27 2026 +0800
[core] Allow Format Tables to omit data file format suffixes (#11009)
---
docs/generated/core_configuration.html | 6 ++
.../main/java/org/apache/paimon/CoreOptions.java | 9 +++
.../paimon/io/FormatTableFilePathFactory.java | 77 ++++++++++++++++++++++
.../paimon/io/FormatTableRollingFileWriter.java | 2 +-
.../paimon/table/format/FormatTableFileWriter.java | 12 +++-
.../table/format/FormatTableRecordWriter.java | 6 +-
.../paimon/table/format/FormatTableWriteTest.java | 75 +++++++++++++++++++++
.../paimon/spark/table/PaimonFormatTableTest.scala | 44 +++++++++++++
8 files changed, 226 insertions(+), 5 deletions(-)
diff --git a/docs/generated/core_configuration.html
b/docs/generated/core_configuration.html
index 29dc82ec7e..e7cabf15b6 100644
--- a/docs/generated/core_configuration.html
+++ b/docs/generated/core_configuration.html
@@ -848,6 +848,12 @@ under the License.
<td>String</td>
<td>Format table file compression.</td>
</tr>
+ <tr>
+ <td><h5>format-table.file.suffix.enabled</h5></td>
+ <td style="word-wrap: break-word;">true</td>
+ <td>Boolean</td>
+ <td>Whether to include the file format suffix in data file names
written by the Paimon implementation of a format table. Compression suffixes
are unaffected.</td>
+ </tr>
<tr>
<td><h5>format-table.implementation</h5></td>
<td style="word-wrap: break-word;">paimon</td>
diff --git a/paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
b/paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
index 3a9fabb372..4a76cbd236 100644
--- a/paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
+++ b/paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
@@ -2877,6 +2877,15 @@ public class CoreOptions implements Serializable {
.withFallbackKeys(FILE_COMPRESSION.key())
.withDescription("Format table file compression.");
+ public static final ConfigOption<Boolean> FORMAT_TABLE_FILE_SUFFIX_ENABLED
=
+ key("format-table.file.suffix.enabled")
+ .booleanType()
+ .defaultValue(true)
+ .withDescription(
+ "Whether to include the file format suffix in data
file names written "
+ + "by the Paimon implementation of a
format table. Compression "
+ + "suffixes are unaffected.");
+
public static final ConfigOption<String> FORMAT_TABLE_COMMIT_HIVE_SYNC_URI
=
ConfigOptions.key("format-table.commit-hive-sync-url")
.stringType()
diff --git
a/paimon-core/src/main/java/org/apache/paimon/io/FormatTableFilePathFactory.java
b/paimon-core/src/main/java/org/apache/paimon/io/FormatTableFilePathFactory.java
new file mode 100644
index 0000000000..ea30e747a2
--- /dev/null
+++
b/paimon-core/src/main/java/org/apache/paimon/io/FormatTableFilePathFactory.java
@@ -0,0 +1,77 @@
+/*
+ * 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.paimon.io;
+
+import org.apache.paimon.format.HadoopCompressionType;
+import org.apache.paimon.fs.Path;
+
+import javax.annotation.Nullable;
+
+import static org.apache.paimon.utils.StringUtils.isEmpty;
+
+/** Data-file path factory used by a Format Table writer. */
+public class FormatTableFilePathFactory {
+
+ private final DataFilePathFactory delegate;
+ private final String formatIdentifier;
+ private final boolean fileSuffixIncludeCompression;
+ @Nullable private final String compressionExtension;
+ private final boolean includeFormatSuffix;
+
+ public FormatTableFilePathFactory(
+ DataFilePathFactory delegate,
+ String formatIdentifier,
+ boolean fileSuffixIncludeCompression,
+ String fileCompression,
+ boolean includeFormatSuffix) {
+ this.delegate = delegate;
+ this.formatIdentifier = formatIdentifier;
+ this.fileSuffixIncludeCompression = fileSuffixIncludeCompression;
+ this.compressionExtension = compressionExtension(fileCompression);
+ this.includeFormatSuffix = includeFormatSuffix;
+ }
+
+ public Path newPath() {
+ if (includeFormatSuffix) {
+ return delegate.newPath();
+ }
+ String extension =
+ compressionExtension != null
+ && (isTextFormat(formatIdentifier) ||
fileSuffixIncludeCompression)
+ ? "." + compressionExtension
+ : "";
+ return delegate.newPathFromExtension(extension);
+ }
+
+ @Nullable
+ private static String compressionExtension(String compression) {
+ if (isEmpty(compression)) {
+ return null;
+ }
+ java.util.Optional<HadoopCompressionType> type =
+ HadoopCompressionType.fromValue(compression);
+ return type.isPresent() ? type.get().fileExtension() : compression;
+ }
+
+ private static boolean isTextFormat(String formatIdentifier) {
+ return "json".equalsIgnoreCase(formatIdentifier)
+ || "csv".equalsIgnoreCase(formatIdentifier)
+ || "text".equalsIgnoreCase(formatIdentifier);
+ }
+}
diff --git
a/paimon-core/src/main/java/org/apache/paimon/io/FormatTableRollingFileWriter.java
b/paimon-core/src/main/java/org/apache/paimon/io/FormatTableRollingFileWriter.java
index 31ed14fbb1..e62612fd60 100644
---
a/paimon-core/src/main/java/org/apache/paimon/io/FormatTableRollingFileWriter.java
+++
b/paimon-core/src/main/java/org/apache/paimon/io/FormatTableRollingFileWriter.java
@@ -58,7 +58,7 @@ public class FormatTableRollingFileWriter implements
AutoCloseable {
long targetFileSize,
long targetFileRowNum,
RowType writeSchema,
- DataFilePathFactory pathFactory,
+ FormatTableFilePathFactory pathFactory,
String fileCompression) {
Preconditions.checkArgument(
targetFileRowNum > 0,
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTableFileWriter.java
b/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTableFileWriter.java
index 66453d402a..1f52eb9d45 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTableFileWriter.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTableFileWriter.java
@@ -24,6 +24,8 @@ import org.apache.paimon.data.InternalRow;
import org.apache.paimon.format.FileFormat;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
+import org.apache.paimon.io.DataFilePathFactory;
+import org.apache.paimon.io.FormatTableFilePathFactory;
import org.apache.paimon.io.FormatTableWrittenFile;
import org.apache.paimon.table.sink.CommitMessage;
import org.apache.paimon.types.RowType;
@@ -142,12 +144,20 @@ public class FormatTableFileWriter {
partValues.values(), onlyValueInPath,
options.partitionDefaultName());
parent = new Path(parent, generatePartitionPathUtil(partValues,
onlyValueInPath));
}
+ DataFilePathFactory dataFilePathFactory =
+ pathFactory.createDataFilePathFactory(parent, null);
return new FormatTableRecordWriter(
fileIO,
fileFormat,
options.targetFileSize(false),
options.targetFileRowNum(),
- pathFactory.createDataFilePathFactory(parent, null),
+ new FormatTableFilePathFactory(
+ dataFilePathFactory,
+ options.fileFormatString(),
+ options.fileSuffixIncludeCompression(),
+ options.formatTableFileCompression(),
+ options.toConfiguration()
+
.get(CoreOptions.FORMAT_TABLE_FILE_SUFFIX_ENABLED)),
writeRowType,
options.formatTableFileCompression());
}
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTableRecordWriter.java
b/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTableRecordWriter.java
index 3e54f27df9..492302403c 100644
---
a/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTableRecordWriter.java
+++
b/paimon-core/src/main/java/org/apache/paimon/table/format/FormatTableRecordWriter.java
@@ -21,7 +21,7 @@ package org.apache.paimon.table.format;
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.format.FileFormat;
import org.apache.paimon.fs.FileIO;
-import org.apache.paimon.io.DataFilePathFactory;
+import org.apache.paimon.io.FormatTableFilePathFactory;
import org.apache.paimon.io.FormatTableRollingFileWriter;
import org.apache.paimon.io.FormatTableWrittenFile;
import org.apache.paimon.types.RowType;
@@ -33,7 +33,7 @@ import java.util.List;
public class FormatTableRecordWriter implements AutoCloseable {
private final FileIO fileIO;
- private final DataFilePathFactory pathFactory;
+ private final FormatTableFilePathFactory pathFactory;
private final RowType writeSchema;
private final String fileCompression;
private final FileFormat fileFormat;
@@ -46,7 +46,7 @@ public class FormatTableRecordWriter implements AutoCloseable
{
FileFormat fileFormat,
long targetFileSize,
long targetFileRowNum,
- DataFilePathFactory pathFactory,
+ FormatTableFilePathFactory pathFactory,
RowType writeSchema,
String fileCompression) {
this.fileIO = fileIO;
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/format/FormatTableWriteTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/format/FormatTableWriteTest.java
index 4ca81e6a0b..4748708bb2 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/format/FormatTableWriteTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/format/FormatTableWriteTest.java
@@ -20,21 +20,28 @@ package org.apache.paimon.table.format;
import org.apache.paimon.catalog.Identifier;
import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.data.BinaryString;
import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.data.InternalRow;
import org.apache.paimon.fs.Path;
import org.apache.paimon.fs.TwoPhaseOutputStream;
import org.apache.paimon.fs.local.LocalFileIO;
import org.apache.paimon.options.Options;
+import org.apache.paimon.reader.RecordReader;
import org.apache.paimon.table.FormatTable;
import org.apache.paimon.table.sink.BatchTableCommit;
import org.apache.paimon.table.sink.BatchTableWrite;
import org.apache.paimon.table.sink.BatchWriteBuilder;
import org.apache.paimon.table.sink.CommitMessage;
+import org.apache.paimon.table.source.ReadBuilder;
+import org.apache.paimon.table.source.Split;
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.types.RowType;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import java.io.BufferedReader;
import java.io.IOException;
@@ -46,11 +53,16 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static org.apache.paimon.CoreOptions.FILE_COMPRESSION;
import static org.apache.paimon.CoreOptions.FILE_FORMAT;
+import static org.apache.paimon.CoreOptions.FILE_SUFFIX_INCLUDE_COMPRESSION;
+import static org.apache.paimon.CoreOptions.FORMAT_TABLE_FILE_SUFFIX_ENABLED;
import static org.apache.paimon.CoreOptions.PATH;
import static org.apache.paimon.CoreOptions.TARGET_FILE_ROW_NUM;
import static org.apache.paimon.CoreOptions.TARGET_FILE_SIZE;
@@ -98,6 +110,7 @@ class FormatTableWriteTest {
}
assertThat(reportedSizes).hasSize(messages.size());
List<Path> dataFiles = new ArrayList<>(reportedSizes.keySet());
+ assertThat(dataFiles).allSatisfy(path ->
assertThat(path.getName()).endsWith(".csv"));
try (BatchTableCommit commit = writeBuilder.newCommit()) {
commit.commit(messages);
}
@@ -126,6 +139,68 @@ class FormatTableWriteTest {
assertThat(rowCounts).containsExactlyInAnyOrder(2L, 2L, 1L);
}
+ @ParameterizedTest
+ @CsvSource({
+ "csv, none, false, ''",
+ "csv, gzip, false, .gz",
+ "csv, gzip, true, .gz",
+ "json, gzip, false, .gz",
+ "text, gzip, false, .gz",
+ "parquet, snappy, false, ''",
+ "parquet, snappy, true, .snappy",
+ "orc, none, false, ''"
+ })
+ void testWriteAndReadWithoutFormatSuffix(
+ String format, String compression, boolean includeCompression,
String expectedSuffix)
+ throws Exception {
+ Path tablePath = new Path(tempDir.toUri());
+ Map<String, String> options = new HashMap<>();
+ options.put(PATH.key(), tablePath.toString());
+ options.put(FILE_FORMAT.key(), format);
+ options.put(FILE_COMPRESSION.key(), compression);
+ options.put(FILE_SUFFIX_INCLUDE_COMPRESSION.key(),
Boolean.toString(includeCompression));
+ options.put(FORMAT_TABLE_FILE_SUFFIX_ENABLED.key(), "false");
+ options.put(TARGET_FILE_ROW_NUM.key(), "2");
+ FormatTable table =
+ FormatTable.builder()
+ .fileIO(LocalFileIO.create())
+ .identifier(Identifier.create("test_db", "test_table"))
+ .rowType(RowType.of(DataTypes.STRING()))
+ .partitionKeys(Collections.emptyList())
+ .location(tablePath.toString())
+
.format(FormatTable.Format.valueOf(format.toUpperCase(Locale.ROOT)))
+ .options(options)
+ .build();
+
+ BatchWriteBuilder builder = table.newBatchWriteBuilder();
+ List<CommitMessage> messages;
+ try (BatchTableWrite write = builder.newWrite()) {
+ for (int i = 0; i < 5; i++) {
+ write.write(GenericRow.of(BinaryString.fromString("value-" +
i)));
+ }
+ messages = write.prepareCommit();
+ }
+ assertThat(messages).hasSize(3);
+ for (CommitMessage message : messages) {
+ Path path = ((TwoPhaseCommitMessage)
message).getCommitter().targetPath();
+ assertThat(path.getName())
+ .matches("data-[0-9a-f-]{36}-[0-9]+" +
Pattern.quote(expectedSuffix));
+ }
+ try (BatchTableCommit commit = builder.newCommit()) {
+ commit.commit(messages);
+ }
+
+ ReadBuilder read = table.newReadBuilder();
+ List<String> values = new ArrayList<>();
+ for (Split split : read.newScan().plan().splits()) {
+ try (RecordReader<InternalRow> reader =
read.newRead().createReader(split)) {
+ reader.forEachRemaining(row ->
values.add(row.getString(0).toString()));
+ }
+ }
+ assertThat(values)
+ .containsExactlyInAnyOrder("value-0", "value-1", "value-2",
"value-3", "value-4");
+ }
+
@Test
void testRejectsNonPositiveTargetRowNumber() throws Exception {
Path tablePath = new Path(tempDir.toUri());
diff --git
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/table/PaimonFormatTableTest.scala
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/table/PaimonFormatTableTest.scala
index 57aa2baf7a..28202fa484 100644
---
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/table/PaimonFormatTableTest.scala
+++
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/table/PaimonFormatTableTest.scala
@@ -23,6 +23,7 @@ import org.apache.paimon.fs.Path
import org.apache.paimon.spark.PaimonSparkTestWithRestCatalogBase
import org.apache.paimon.table.FormatTable
import org.apache.paimon.table.format.FormatDataSplit
+import org.apache.paimon.utils.PartitionPathUtils
import org.apache.spark.sql.Row
import org.apache.spark.sql.connector.catalog.TableCapability
@@ -32,6 +33,49 @@ import scala.collection.JavaConverters._
class PaimonFormatTableTest extends PaimonSparkTestWithRestCatalogBase {
+ test("PaimonFormatTable: omit file format suffix") {
+ for (compression <- Seq("none", "gzip")) {
+ val tableName = s"format_file_suffix_$compression"
+ val codecSuffix = if (compression == "gzip") ".gz" else ""
+ withTable(tableName) {
+ sql(
+ s"CREATE TABLE $tableName (id INT, v STRING, pt INT) USING csv
PARTITIONED BY (pt) " +
+ "TBLPROPERTIES ('metastore.partitioned-table'='true', " +
+ s"'format-table.implementation'='paimon',
'file.compression'='$compression', " +
+ "'target-file-row-num'='1')")
+ sql(s"INSERT INTO $tableName VALUES (0, 'old', 1)")
+ val table =
+ paimonCatalog.getTable(Identifier.create("test_db",
tableName)).asInstanceOf[FormatTable]
+ def fileNames(partition: Int): Set[String] = {
+ table
+ .fileIO()
+ .listStatus(new Path(table.location(), s"pt=$partition"))
+ .filter(file =>
!PartitionPathUtils.isHiddenName(file.getPath.getName))
+ .map(_.getPath.getName)
+ .toSet
+ }
+ val oldFiles = fileNames(1)
+ assert(oldFiles.size == 1)
+ assert(oldFiles.forall(_.endsWith(".csv" + codecSuffix)))
+
+ sql(
+ s"ALTER TABLE $tableName SET TBLPROPERTIES " +
+ "('format-table.file.suffix.enabled'='false')")
+ sql(s"INSERT INTO $tableName VALUES (1, 'one', 1), (2, 'two', 2), (3,
'three', 1)")
+ val allFiles = fileNames(1) ++ fileNames(2)
+ assert(oldFiles.subsetOf(allFiles))
+ val newFiles = allFiles -- oldFiles
+ assert(newFiles.size == 3)
+ assert(
+ newFiles.forall(_.matches("data-[0-9a-f-]{36}-[0-9]+" +
+ java.util.regex.Pattern.quote(codecSuffix))))
+ val expected = Seq(Row(0, "old", 1), Row(1, "one", 1), Row(2, "two",
2), Row(3, "three", 1))
+ checkAnswer(sql(s"SELECT * FROM $tableName"), expected)
+ checkAnswer(spark.read.schema("id INT, v STRING, pt
INT").csv(table.location()), expected)
+ }
+ }
+ }
+
test("PaimonFormatTable: partition file formats survive reads statistics and
overwrite") {
val tableName = "partition_file_formats"
withTable(tableName) {