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 5c630d65c1 [vfs] Support Mkdir & Create in non-existing table (#5942)
5c630d65c1 is described below
commit 5c630d65c126a7669086e058a0300f11718701d8
Author: Jingsong Lee <[email protected]>
AuthorDate: Wed Jul 23 16:38:13 2025 +0800
[vfs] Support Mkdir & Create in non-existing table (#5942)
---
.../paimon/vfs/hadoop/PaimonVirtualFileSystem.java | 29 +++++++++++-----------
.../paimon/vfs/hadoop/VirtualFileSystemTest.java | 23 +++++++++--------
2 files changed, 28 insertions(+), 24 deletions(-)
diff --git
a/paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java
b/paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java
index e09679243c..38cfa79f7c 100644
---
a/paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java
+++
b/paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java
@@ -103,15 +103,17 @@ public class PaimonVirtualFileSystem extends FileSystem {
"Cannot create file for table level virtual path " + f + "
which is a table");
} else {
VFSTableObjectIdentifier identifier = (VFSTableObjectIdentifier)
vfsIdentifier;
- VFSTableInfo tableInfo = identifier.tableInfo();
- if (tableInfo == null) {
- throw new IOException(
- "Cannot create a file for virtual path "
- + f
- + " which is not in an existing table");
+ if (identifier.tableInfo() == null) {
+ vfsOperations.createObjectTable(identifier.databaseName(),
identifier.tableName());
+ identifier =
+ (VFSTableObjectIdentifier)
+
vfsOperations.getVFSIdentifier(getVirtualPath(f));
}
PositionOutputStream out =
- tableInfo.fileIO().newOutputStream(identifier.filePath(),
overwrite);
+ identifier
+ .tableInfo()
+ .fileIO()
+ .newOutputStream(identifier.filePath(), overwrite);
return new FSDataOutputStream(out, statistics);
}
}
@@ -400,14 +402,13 @@ public class PaimonVirtualFileSystem extends FileSystem {
return true;
} else {
VFSTableObjectIdentifier identifier = (VFSTableObjectIdentifier)
vfsIdentifier;
- VFSTableInfo tableInfo = identifier.tableInfo();
- if (tableInfo == null) {
- throw new IOException(
- "Cannot mkdirs for virtual path "
- + f
- + " which is not in an existing table");
+ if (identifier.tableInfo() == null) {
+ vfsOperations.createObjectTable(identifier.databaseName(),
identifier.tableName());
+ identifier =
+ (VFSTableObjectIdentifier)
+
vfsOperations.getVFSIdentifier(getVirtualPath(f));
}
- return tableInfo.fileIO().mkdirs(identifier.filePath());
+ return
identifier.tableInfo().fileIO().mkdirs(identifier.filePath());
}
}
diff --git
a/paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java
b/paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java
index 24c817eb20..e410104b3b 100644
---
a/paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java
+++
b/paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java
@@ -139,11 +139,11 @@ public abstract class VirtualFileSystemTest {
// Mkdir in non-existing table
tableName = "object_table2";
vfsPath = new Path(vfsRoot, databaseName + "/" + tableName +
"/test_dir");
- try {
- vfs.mkdirs(vfsPath);
- Assert.fail();
- } catch (IOException e) {
- }
+ Assert.assertTrue(vfs.mkdirs(vfsPath));
+ Table table = catalog.getTable(new Identifier(databaseName,
tableName));
+ assertThat(table).isInstanceOf(ObjectTable.class);
+ fileStatus = vfs.getFileStatus(vfsPath);
+ Assert.assertEquals(vfsPath.toString(),
fileStatus.getPath().toString());
}
@Test
@@ -203,11 +203,14 @@ public abstract class VirtualFileSystemTest {
// Create file in non-existing table
tableName = "object_table2";
vfsPath = new Path(vfsRoot, databaseName + "/" + tableName +
"/test_dir/file.txt");
- try {
- vfs.create(vfsPath);
- Assert.fail();
- } catch (IOException e) {
- }
+ out = vfs.create(vfsPath);
+ out.write("hello".getBytes());
+ out.close();
+ in = vfs.open(vfsPath);
+ buffer = new byte[5];
+ in.read(buffer);
+ in.close();
+ Assert.assertArrayEquals("hello".getBytes(), buffer);
}
@Test