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 1b75fa9ebc [rest] Create external table path if not exist (#5925)
1b75fa9ebc is described below
commit 1b75fa9ebc46bf734e46d331e409b5eebc71c96c
Author: Zouxxyy <[email protected]>
AuthorDate: Mon Jul 21 19:10:05 2025 +0800
[rest] Create external table path if not exist (#5925)
---
.../java/org/apache/paimon/rest/RESTCatalog.java | 14 +++++++++++
.../org/apache/paimon/rest/RESTCatalogTest.java | 27 ++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
index c7b93a484a..6f574a1ea5 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
@@ -18,6 +18,7 @@
package org.apache.paimon.rest;
+import org.apache.paimon.CoreOptions;
import org.apache.paimon.PagedList;
import org.apache.paimon.Snapshot;
import org.apache.paimon.annotation.VisibleForTesting;
@@ -428,6 +429,7 @@ public class RESTCatalog implements Catalog {
checkNotBranch(identifier, "createTable");
checkNotSystemTable(identifier, "createTable");
validateCreateTable(schema);
+ createExternalTablePathIfNotExist(schema);
api.createTable(identifier, schema);
} catch (AlreadyExistsException e) {
if (!ignoreIfExists) {
@@ -980,4 +982,16 @@ public class RESTCatalog implements Catalog {
throw new UncheckedIOException(e);
}
}
+
+ private void createExternalTablePathIfNotExist(Schema schema) throws
IOException {
+ Map<String, String> options = schema.options();
+ if (options.containsKey(CoreOptions.PATH.key())) {
+ Path path = new Path(options.get(PATH.key()));
+ try (FileIO fileIO = fileIOFromOptions(path)) {
+ if (!fileIO.exists(path)) {
+ fileIO.mkdirs(path);
+ }
+ }
+ }
+ }
}
diff --git
a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
index d0a1d35cd3..8755cb74fe 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
@@ -70,6 +70,7 @@ import
org.apache.paimon.shade.org.apache.commons.lang3.StringUtils;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.io.IOException;
@@ -583,6 +584,32 @@ public abstract class RESTCatalogTest extends
CatalogTestBase {
databaseName, databaseNamePattern, expectedTableNames);
}
+ @Test
+ public void testCreateFormatTableWithNonExistingPath(@TempDir
java.nio.file.Path path)
+ throws Exception {
+ Path nonExistingPath = new Path(path.toString(), "non_existing_path");
+
+ Map<String, String> options = new HashMap<>();
+ options.put("type", TableType.FORMAT_TABLE.toString());
+ options.put("path", nonExistingPath.toString());
+ Schema formatTableSchema =
+ new Schema(
+ Lists.newArrayList(
+ new DataField(0, "pk", DataTypes.INT()),
+ new DataField(1, "col1", DataTypes.STRING()),
+ new DataField(2, "col2", DataTypes.STRING())),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ options,
+ "");
+ restCatalog.createDatabase("test_format_table_db", true);
+ Identifier identifier = Identifier.create("test_format_table_db",
"test_format_table");
+ catalog.createTable(identifier, formatTableSchema, false);
+
+ FileIO fileIO = catalog.getTable(identifier).fileIO();
+ assertTrue(fileIO.exists(nonExistingPath));
+ }
+
protected void prepareDataForListTablesPagedGlobally(
String databaseName, String databaseName2, String[] tableNames)
throws Catalog.DatabaseAlreadyExistException,
Catalog.TableAlreadyExistException,