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 33e04e4aca [vfs] Clean VFSIdentifier classes to remove unuse codes
33e04e4aca is described below
commit 33e04e4aca8b4df4be7451f6e741d4676102ed56
Author: JingsongLi <[email protected]>
AuthorDate: Wed Jul 23 15:06:01 2025 +0800
[vfs] Clean VFSIdentifier classes to remove unuse codes
---
.../apache/paimon/vfs/VFSCatalogIdentifier.java | 7 +-
.../apache/paimon/vfs/VFSDatabaseIdentifier.java | 10 +-
.../java/org/apache/paimon/vfs/VFSIdentifier.java | 25 +--
.../java/org/apache/paimon/vfs/VFSOperations.java | 35 ++--
.../org/apache/paimon/vfs/VFSTableIdentifier.java | 77 +++------
...STableRootIdentifier.java => VFSTableInfo.java} | 34 ++--
.../paimon/vfs/VFSTableObjectIdentifier.java | 34 ++--
.../apache/paimon/vfs/VFSTableRootIdentifier.java | 24 +--
.../paimon/vfs/hadoop/PaimonVirtualFileSystem.java | 179 ++++++++++-----------
.../paimon/vfs/hadoop/VirtualFileSystemTest.java | 1 +
10 files changed, 191 insertions(+), 235 deletions(-)
diff --git
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSCatalogIdentifier.java
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSCatalogIdentifier.java
index 3118121b93..316e6da391 100644
---
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSCatalogIdentifier.java
+++
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSCatalogIdentifier.java
@@ -19,9 +19,4 @@
package org.apache.paimon.vfs;
/** Identifier for catalog. */
-public class VFSCatalogIdentifier extends VFSIdentifier {
-
- public VFSCatalogIdentifier() {
- super(VFSFileType.CATALOG, null);
- }
-}
+public class VFSCatalogIdentifier implements VFSIdentifier {}
diff --git
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSDatabaseIdentifier.java
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSDatabaseIdentifier.java
index 02a7390788..d52f12626d 100644
---
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSDatabaseIdentifier.java
+++
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSDatabaseIdentifier.java
@@ -19,9 +19,15 @@
package org.apache.paimon.vfs;
/** Identifier for database. */
-public class VFSDatabaseIdentifier extends VFSIdentifier {
+public class VFSDatabaseIdentifier implements VFSIdentifier {
+
+ protected String databaseName;
public VFSDatabaseIdentifier(String databaseName) {
- super(VFSFileType.DATABASE, databaseName);
+ this.databaseName = databaseName;
+ }
+
+ public String databaseName() {
+ return databaseName;
}
}
diff --git
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSIdentifier.java
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSIdentifier.java
index d454cec040..172cf856dc 100644
---
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSIdentifier.java
+++
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSIdentifier.java
@@ -19,27 +19,4 @@
package org.apache.paimon.vfs;
/** Identifier for virtual path. */
-public abstract class VFSIdentifier {
- enum VFSFileType {
- CATALOG, // pvfs://catalog/
- DATABASE, // pvfs://catalog/database/
- TABLE, // pvfs://catalog/database/table/
- TABLE_OBJECT // pvfs://catalog/database/table/file.txt
- }
-
- protected VFSFileType vfsFileType;
- protected String databaseName;
-
- public VFSIdentifier(VFSFileType vfsFileType, String databaseName) {
- this.vfsFileType = vfsFileType;
- this.databaseName = databaseName;
- }
-
- public VFSFileType getVfsFileType() {
- return vfsFileType;
- }
-
- public String getDatabaseName() {
- return databaseName;
- }
-}
+public interface VFSIdentifier {}
diff --git
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSOperations.java
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSOperations.java
index 6ca09dc739..1fec65cd07 100644
---
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSOperations.java
+++
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSOperations.java
@@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -73,42 +74,32 @@ public class VFSOperations {
// parts.length >= 2: table or table object
String databaseName = parts[0];
String tableName = parts[1];
+ String relativePath = null;
+ if (parts.length > 2) {
+ relativePath = String.join("/", Arrays.copyOfRange(parts, 2,
parts.length));
+ }
Identifier identifier = new Identifier(databaseName, tableName);
// Get table from REST server
GetTableResponse table;
try {
table = loadTableMetadata(identifier);
} catch (FileNotFoundException e) {
- if (parts.length == 2) {
+ if (relativePath == null) {
return new VFSTableRootIdentifier(databaseName, tableName);
} else {
- return new VFSTableObjectIdentifier(databaseName, tableName);
+ return new VFSTableObjectIdentifier(databaseName, tableName,
relativePath);
}
}
if (table.isExternal()) {
throw new IOException("Do not support visiting external table " +
identifier);
}
- // Get real path
- StringBuilder realPath = new StringBuilder(table.getPath());
- if (parts.length > 2) {
- if (!table.getPath().endsWith("/")) {
- realPath.append("/");
- }
- for (int i = 2; i < parts.length; i++) {
- realPath.append(parts[i]);
- if (i < parts.length - 1) {
- realPath.append("/");
- }
- }
- }
-
- FileIO fileIO = new RESTTokenFileIO(context, api, identifier, new
Path(table.getPath()));
- if (parts.length == 2) {
- return new VFSTableRootIdentifier(
- table, realPath.toString(), fileIO, databaseName,
tableName);
+ Path tablePath = new Path(table.getPath());
+ FileIO fileIO = new RESTTokenFileIO(context, api, identifier,
tablePath);
+ VFSTableInfo tableInfo = new VFSTableInfo(table.getId(), tablePath,
fileIO);
+ if (relativePath == null) {
+ return new VFSTableRootIdentifier(databaseName, tableName,
tableInfo);
} else {
- return new VFSTableObjectIdentifier(
- table, realPath.toString(), fileIO, databaseName,
tableName);
+ return new VFSTableObjectIdentifier(databaseName, tableName,
relativePath, tableInfo);
}
}
diff --git
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableIdentifier.java
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableIdentifier.java
index 86f0605322..60b065ca06 100644
---
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableIdentifier.java
+++
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableIdentifier.java
@@ -18,82 +18,43 @@
package org.apache.paimon.vfs;
-import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
-import org.apache.paimon.rest.responses.GetTableResponse;
-import java.net.URI;
-import java.net.URISyntaxException;
+import javax.annotation.Nullable;
/** Identifier for table. */
-public abstract class VFSTableIdentifier extends VFSIdentifier {
- protected Path realPath;
- protected String scheme;
- protected URI realUri;
- protected String tableName;
- protected GetTableResponse table;
- protected FileIO fileIO;
- protected String tableLocation;
+public abstract class VFSTableIdentifier implements VFSIdentifier {
+
+ protected final String databaseName;
+ protected final String tableName;
+
+ protected final @Nullable VFSTableInfo tableInfo;
// Constructor for non-exist table
- public VFSTableIdentifier(VFSFileType vfsFileType, String databaseName,
String tableName) {
- super(vfsFileType, databaseName);
- this.tableName = tableName;
+ public VFSTableIdentifier(String databaseName, String tableName) {
+ this(databaseName, tableName, null);
}
// Constructor for existing table
public VFSTableIdentifier(
- VFSFileType vfsFileType,
- GetTableResponse table,
- String realPath,
- FileIO fileIO,
- String databaseName,
- String tableName) {
- super(vfsFileType, databaseName);
- this.realPath = new Path(realPath);
- try {
- this.realUri = new URI(realPath);
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
- this.scheme = realUri.getScheme();
+ String databaseName, String tableName, @Nullable VFSTableInfo
tableInfo) {
+ this.databaseName = databaseName;
this.tableName = tableName;
- this.table = table;
- this.fileIO = fileIO;
- if (table != null) {
- this.tableLocation = table.getPath();
- }
- }
-
- public Path getRealPath() {
- return realPath;
- }
-
- public URI getRealUri() {
- return realUri;
+ this.tableInfo = tableInfo;
}
- public String getScheme() {
- return scheme;
+ public String databaseName() {
+ return databaseName;
}
- public String getTableName() {
+ public String tableName() {
return tableName;
}
- public GetTableResponse getTable() {
- return table;
- }
-
- public FileIO fileIO() {
- return fileIO;
+ @Nullable
+ public VFSTableInfo tableInfo() {
+ return tableInfo;
}
- public String getTableLocation() {
- return tableLocation;
- }
-
- public boolean isTableExist() {
- return table != null;
- }
+ public abstract Path filePath();
}
diff --git
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableRootIdentifier.java
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableInfo.java
similarity index 60%
copy from
paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableRootIdentifier.java
copy to
paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableInfo.java
index ee398b06f6..f4003dc619 100644
---
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableRootIdentifier.java
+++
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableInfo.java
@@ -19,20 +19,30 @@
package org.apache.paimon.vfs;
import org.apache.paimon.fs.FileIO;
-import org.apache.paimon.rest.responses.GetTableResponse;
+import org.apache.paimon.fs.Path;
-/** Identifier for objects under a table. */
-public class VFSTableRootIdentifier extends VFSTableIdentifier {
- public VFSTableRootIdentifier(String databaseName, String tableName) {
- super(VFSFileType.TABLE, databaseName, tableName);
+/** Information for an existing table. */
+public class VFSTableInfo {
+
+ private final String tableId;
+ private final Path tablePath;
+ private final FileIO fileIO;
+
+ public VFSTableInfo(String tableId, Path tablePath, FileIO fileIO) {
+ this.tableId = tableId;
+ this.tablePath = tablePath;
+ this.fileIO = fileIO;
+ }
+
+ public String tableId() {
+ return tableId;
+ }
+
+ public Path tablePath() {
+ return tablePath;
}
- public VFSTableRootIdentifier(
- GetTableResponse table,
- String realPath,
- FileIO fileIO,
- String databaseName,
- String tableName) {
- super(VFSFileType.TABLE, table, realPath, fileIO, databaseName,
tableName);
+ public FileIO fileIO() {
+ return fileIO;
}
}
diff --git
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableObjectIdentifier.java
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableObjectIdentifier.java
index b0cdfbb1bb..395aa13ddd 100644
---
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableObjectIdentifier.java
+++
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableObjectIdentifier.java
@@ -18,21 +18,37 @@
package org.apache.paimon.vfs;
-import org.apache.paimon.fs.FileIO;
-import org.apache.paimon.rest.responses.GetTableResponse;
+import org.apache.paimon.fs.Path;
+
+import javax.annotation.Nullable;
+
+import static org.apache.paimon.utils.Preconditions.checkNotNull;
/** Identifier for objects under a table. */
public class VFSTableObjectIdentifier extends VFSTableIdentifier {
- public VFSTableObjectIdentifier(String databaseName, String tableName) {
- super(VFSFileType.TABLE_OBJECT, databaseName, tableName);
+
+ private final String relativePath;
+
+ public VFSTableObjectIdentifier(String databaseName, String tableName,
String relativePath) {
+ this(databaseName, tableName, relativePath, null);
}
public VFSTableObjectIdentifier(
- GetTableResponse table,
- String realPath,
- FileIO fileIO,
String databaseName,
- String tableName) {
- super(VFSFileType.TABLE_OBJECT, table, realPath, fileIO, databaseName,
tableName);
+ String tableName,
+ String relativePath,
+ @Nullable VFSTableInfo tableInfo) {
+ super(databaseName, tableName, tableInfo);
+ this.relativePath = relativePath;
+ }
+
+ public String relativePath() {
+ return relativePath;
+ }
+
+ @Override
+ public Path filePath() {
+ checkNotNull(tableInfo);
+ return new Path(tableInfo.tablePath(), relativePath);
}
}
diff --git
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableRootIdentifier.java
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableRootIdentifier.java
index ee398b06f6..f73b008d7c 100644
---
a/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableRootIdentifier.java
+++
b/paimon-vfs/paimon-vfs-common/src/main/java/org/apache/paimon/vfs/VFSTableRootIdentifier.java
@@ -18,21 +18,27 @@
package org.apache.paimon.vfs;
-import org.apache.paimon.fs.FileIO;
-import org.apache.paimon.rest.responses.GetTableResponse;
+import org.apache.paimon.fs.Path;
+
+import javax.annotation.Nullable;
+
+import static org.apache.paimon.utils.Preconditions.checkNotNull;
/** Identifier for objects under a table. */
public class VFSTableRootIdentifier extends VFSTableIdentifier {
+
public VFSTableRootIdentifier(String databaseName, String tableName) {
- super(VFSFileType.TABLE, databaseName, tableName);
+ super(databaseName, tableName);
}
public VFSTableRootIdentifier(
- GetTableResponse table,
- String realPath,
- FileIO fileIO,
- String databaseName,
- String tableName) {
- super(VFSFileType.TABLE, table, realPath, fileIO, databaseName,
tableName);
+ String databaseName, String tableName, @Nullable VFSTableInfo
tableInfo) {
+ super(databaseName, tableName, tableInfo);
+ }
+
+ @Override
+ public Path filePath() {
+ checkNotNull(tableInfo);
+ return tableInfo.tablePath();
}
}
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 1c0e8ceb39..e09679243c 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
@@ -22,12 +22,12 @@ import org.apache.paimon.fs.PositionOutputStream;
import org.apache.paimon.options.CatalogOptions;
import org.apache.paimon.options.Options;
import org.apache.paimon.rest.responses.GetDatabaseResponse;
-import org.apache.paimon.rest.responses.GetTableResponse;
import org.apache.paimon.vfs.VFSCatalogIdentifier;
import org.apache.paimon.vfs.VFSDatabaseIdentifier;
import org.apache.paimon.vfs.VFSIdentifier;
import org.apache.paimon.vfs.VFSOperations;
import org.apache.paimon.vfs.VFSTableIdentifier;
+import org.apache.paimon.vfs.VFSTableInfo;
import org.apache.paimon.vfs.VFSTableObjectIdentifier;
import org.apache.paimon.vfs.VFSTableRootIdentifier;
@@ -102,18 +102,16 @@ public class PaimonVirtualFileSystem extends FileSystem {
throw new IOException(
"Cannot create file for table level virtual path " + f + "
which is a table");
} else {
- VFSTableObjectIdentifier vfsTableObjectIdentifier =
- (VFSTableObjectIdentifier) vfsIdentifier;
- if (!vfsTableObjectIdentifier.isTableExist()) {
+ 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");
}
PositionOutputStream out =
- vfsTableObjectIdentifier
- .fileIO()
-
.newOutputStream(vfsTableObjectIdentifier.getRealPath(), overwrite);
+ tableInfo.fileIO().newOutputStream(identifier.filePath(),
overwrite);
return new FSDataOutputStream(out, statistics);
}
}
@@ -131,9 +129,9 @@ public class PaimonVirtualFileSystem extends FileSystem {
throw new FileNotFoundException(
"Cannot open file for virtual path " + path + " which is a
table");
} else {
- VFSTableObjectIdentifier vfsTableObjectIdentifier =
- (VFSTableObjectIdentifier) vfsIdentifier;
- if (!vfsTableObjectIdentifier.isTableExist()) {
+ VFSTableObjectIdentifier identifier = (VFSTableObjectIdentifier)
vfsIdentifier;
+ VFSTableInfo tableInfo = identifier.tableInfo();
+ if (tableInfo == null) {
throw new IOException(
"Cannot open file for virtual path "
+ path
@@ -141,10 +139,7 @@ public class PaimonVirtualFileSystem extends FileSystem {
}
VFSInputStream in =
new VFSInputStream(
- vfsTableObjectIdentifier
- .fileIO()
-
.newInputStream(vfsTableObjectIdentifier.getRealPath()),
- statistics);
+
tableInfo.fileIO().newInputStream(identifier.filePath()), statistics);
return new FSDataInputStream(in);
}
}
@@ -174,27 +169,27 @@ public class PaimonVirtualFileSystem extends FileSystem {
(VFSTableRootIdentifier) srcVfsIdentifier,
(VFSTableRootIdentifier) dstVfsIdentifier);
} else {
- if (!(dstVfsIdentifier instanceof VFSTableIdentifier)) {
+ if (!(dstVfsIdentifier instanceof VFSTableObjectIdentifier)) {
throw new IOException(
"Cannot rename to virtual path " + dst + " which is
not a table");
}
- VFSTableIdentifier srcTableIdentifier = (VFSTableIdentifier)
srcVfsIdentifier;
- VFSTableIdentifier dstTableIdentifier = (VFSTableIdentifier)
dstVfsIdentifier;
- if (!srcTableIdentifier.isTableExist()) {
+ VFSTableObjectIdentifier srcIdentifier =
(VFSTableObjectIdentifier) srcVfsIdentifier;
+ VFSTableObjectIdentifier dstIdentifier =
(VFSTableObjectIdentifier) dstVfsIdentifier;
+ VFSTableInfo srcTableInfo = srcIdentifier.tableInfo();
+ VFSTableInfo dstTableInfo = dstIdentifier.tableInfo();
+ if (srcTableInfo == null) {
throw new IOException(
"Cannot rename from virtual path "
+ src
+ " which is not in an existing table");
}
- if (!dstTableIdentifier.isTableExist()) {
+ if (dstTableInfo == null) {
throw new IOException(
"Cannot rename to virtual path "
+ dst
+ " which is not in an existing table");
}
- GetTableResponse srcTable = srcTableIdentifier.getTable();
- GetTableResponse dstTable = dstTableIdentifier.getTable();
- if (!srcTable.getId().equals(dstTable.getId())) {
+ if (!srcTableInfo.tableId().equals(dstTableInfo.tableId())) {
throw new IOException(
"Cannot rename from virtual path "
+ src
@@ -202,43 +197,39 @@ public class PaimonVirtualFileSystem extends FileSystem {
+ dst
+ " which is not in the same table");
}
- return srcTableIdentifier
- .fileIO()
- .rename(srcTableIdentifier.getRealPath(),
dstTableIdentifier.getRealPath());
+ return srcTableInfo.fileIO().rename(srcIdentifier.filePath(),
dstIdentifier.filePath());
}
}
private boolean renameTable(
VFSTableRootIdentifier srcIdentifier, VFSTableRootIdentifier
dstIdentifier)
throws IOException {
- if
(!srcIdentifier.getDatabaseName().equals(dstIdentifier.getDatabaseName())) {
+ if
(!srcIdentifier.databaseName().equals(dstIdentifier.databaseName())) {
throw new IOException("Do not support rename table with different
database");
}
- if (!srcIdentifier.isTableExist()) {
+ if (srcIdentifier.tableInfo() == null) {
// return false if src does not exist
LOG.debug(
- "Source table not found "
- + srcIdentifier.getDatabaseName()
- + "."
- + srcIdentifier.getTableName());
+ "Source table not found {}.{}",
+ srcIdentifier.databaseName(),
+ srcIdentifier.tableName());
return false;
}
- if (srcIdentifier.getTableName().equals(dstIdentifier.getTableName()))
{
+ if (srcIdentifier.tableName().equals(dstIdentifier.tableName())) {
// src equals to dst, return true
return true;
}
try {
vfsOperations.renameTable(
- srcIdentifier.getDatabaseName(),
- srcIdentifier.getTableName(),
- dstIdentifier.getTableName());
+ srcIdentifier.databaseName(),
+ srcIdentifier.tableName(),
+ dstIdentifier.tableName());
return true;
} catch (FileNotFoundException e) {
LOG.debug(
- "Source table not found "
- + srcIdentifier.getDatabaseName()
- + "."
- + srcIdentifier.getTableName());
+ "Source table not found {}.{}",
+ srcIdentifier.databaseName(),
+ srcIdentifier.tableName());
return false;
}
}
@@ -249,8 +240,9 @@ public class PaimonVirtualFileSystem extends FileSystem {
if (vfsIdentifier instanceof VFSCatalogIdentifier) {
throw new IOException("Cannot delete virtual path " + f + " which
is a catalog");
} else if (vfsIdentifier instanceof VFSDatabaseIdentifier) {
+ String databaseName = ((VFSDatabaseIdentifier)
vfsIdentifier).databaseName();
try {
- vfsOperations.dropDatabase(vfsIdentifier.getDatabaseName(),
recursive);
+ vfsOperations.dropDatabase(databaseName, recursive);
} catch (FileNotFoundException e) {
LOG.debug("Database not found for deleting path " + f);
return false;
@@ -260,23 +252,20 @@ public class PaimonVirtualFileSystem extends FileSystem {
VFSTableRootIdentifier vfsTableRootIdentifier =
(VFSTableRootIdentifier) vfsIdentifier;
try {
vfsOperations.dropTable(
- vfsTableRootIdentifier.getDatabaseName(),
- vfsTableRootIdentifier.getTableName());
+ vfsTableRootIdentifier.databaseName(),
vfsTableRootIdentifier.tableName());
} catch (FileNotFoundException e) {
LOG.debug("Table not found for deleting path " + f);
return false;
}
return true;
} else {
- VFSTableObjectIdentifier vfsTableObjectIdentifier =
- (VFSTableObjectIdentifier) vfsIdentifier;
- if (!vfsTableObjectIdentifier.isTableExist()) {
+ VFSTableObjectIdentifier identifier = (VFSTableObjectIdentifier)
vfsIdentifier;
+ VFSTableInfo tableInfo = identifier.tableInfo();
+ if (tableInfo == null) {
throw new IOException(
"Cannot delete virtual path " + f + " which is not in
an existing table");
}
- return vfsTableObjectIdentifier
- .fileIO()
- .delete(vfsTableObjectIdentifier.getRealPath(), recursive);
+ return tableInfo.fileIO().delete(identifier.filePath(), recursive);
}
}
@@ -286,17 +275,19 @@ public class PaimonVirtualFileSystem extends FileSystem {
if (vfsIdentifier instanceof VFSCatalogIdentifier) {
return new FileStatus(0, true, 1, 1, 0, new Path(this.uri));
} else if (vfsIdentifier instanceof VFSDatabaseIdentifier) {
- GetDatabaseResponse database =
- vfsOperations.getDatabase(vfsIdentifier.getDatabaseName());
+ String databaseName = ((VFSDatabaseIdentifier)
vfsIdentifier).databaseName();
+ GetDatabaseResponse database =
vfsOperations.getDatabase(databaseName);
return convertDatabase(database);
} else {
- VFSTableIdentifier vfsTableIdentifier = (VFSTableIdentifier)
vfsIdentifier;
- if (!vfsTableIdentifier.isTableExist()) {
+ VFSTableIdentifier identifier = (VFSTableIdentifier) vfsIdentifier;
+ VFSTableInfo tableInfo = identifier.tableInfo();
+ if (tableInfo == null) {
throw new FileNotFoundException("Table not found for path " +
f);
}
org.apache.paimon.fs.FileStatus fileStatus =
-
vfsTableIdentifier.fileIO().getFileStatus(vfsTableIdentifier.getRealPath());
- return convertFileStatus(vfsTableIdentifier, fileStatus);
+ tableInfo.fileIO().getFileStatus(identifier.filePath());
+ return convertFileStatus(
+ identifier.databaseName(), identifier.tableName(),
tableInfo, fileStatus);
}
}
@@ -305,33 +296,28 @@ public class PaimonVirtualFileSystem extends FileSystem {
}
private FileStatus convertFileStatus(
- VFSTableIdentifier vfsIdentifier, org.apache.paimon.fs.FileStatus
paimonFileStatus)
+ String databaseName,
+ String tableName,
+ VFSTableInfo tableInfo,
+ org.apache.paimon.fs.FileStatus fileStatus)
throws IOException {
- String realPath = paimonFileStatus.getPath().toString();
- if (!realPath.startsWith(vfsIdentifier.getTableLocation())) {
+ String tablePath = tableInfo.tablePath().toString();
+ String filePath = fileStatus.getPath().toString();
+ if (!filePath.startsWith(tablePath)) {
throw new IOException(
- "Result path "
- + realPath
- + " does not start with table location "
- + vfsIdentifier.getTableLocation());
+ "Result path " + filePath + " does not start with table
location " + tablePath);
}
- String childPath =
realPath.substring(vfsIdentifier.getTableLocation().length());
+ String childPath = filePath.substring(tablePath.length());
if (!childPath.startsWith("/")) {
childPath = "/" + childPath;
}
- Path virtualPath =
- new Path(
- new Path(this.uri),
- vfsIdentifier.getDatabaseName()
- + "/"
- + vfsIdentifier.getTableName()
- + childPath);
+ Path virtualPath = new Path(new Path(this.uri), databaseName + "/" +
tableName + childPath);
return new FileStatus(
- paimonFileStatus.getLen(),
- paimonFileStatus.isDir(),
+ fileStatus.getLen(),
+ fileStatus.isDir(),
1,
1,
- paimonFileStatus.getModificationTime(),
+ fileStatus.getModificationTime(),
virtualPath);
}
@@ -342,16 +328,19 @@ public class PaimonVirtualFileSystem extends FileSystem {
List<String> databases = vfsOperations.listDatabases();
return convertDatabases(databases);
} else if (vfsIdentifier instanceof VFSDatabaseIdentifier) {
- List<String> tables =
vfsOperations.listTables(vfsIdentifier.getDatabaseName());
- return convertTables(vfsIdentifier.getDatabaseName(), tables);
+ String databaseName = ((VFSDatabaseIdentifier)
vfsIdentifier).databaseName();
+ List<String> tables = vfsOperations.listTables(databaseName);
+ return convertTables(databaseName, tables);
} else {
- VFSTableIdentifier vfsTableIdentifier = (VFSTableIdentifier)
vfsIdentifier;
- if (!vfsTableIdentifier.isTableExist()) {
+ VFSTableIdentifier identifier = (VFSTableIdentifier) vfsIdentifier;
+ VFSTableInfo tableInfo = identifier.tableInfo();
+ if (tableInfo == null) {
throw new FileNotFoundException("Table not found for path " +
f);
}
- org.apache.paimon.fs.FileStatus[] paimonFileStatuses =
-
vfsTableIdentifier.fileIO().listStatus(vfsTableIdentifier.getRealPath());
- return convertFileStatuses(vfsTableIdentifier, paimonFileStatuses);
+ org.apache.paimon.fs.FileStatus[] fileStatuses =
+ tableInfo.fileIO().listStatus(identifier.filePath());
+ return convertFileStatuses(
+ identifier.databaseName(), identifier.tableName(),
tableInfo, fileStatuses);
}
}
@@ -379,13 +368,17 @@ public class PaimonVirtualFileSystem extends FileSystem {
}
private FileStatus[] convertFileStatuses(
- VFSTableIdentifier vfsIdentifier,
org.apache.paimon.fs.FileStatus[] paimonFileStatuses)
+ String databaseName,
+ String tableName,
+ VFSTableInfo tableInfo,
+ org.apache.paimon.fs.FileStatus[] fileStatuses)
throws IOException {
- FileStatus[] fileStatuses = new FileStatus[paimonFileStatuses.length];
- for (int i = 0; i < paimonFileStatuses.length; i++) {
- fileStatuses[i] = convertFileStatus(vfsIdentifier,
paimonFileStatuses[i]);
+ FileStatus[] virtualStatues = new FileStatus[fileStatuses.length];
+ for (int i = 0; i < fileStatuses.length; i++) {
+ virtualStatues[i] =
+ convertFileStatus(databaseName, tableName, tableInfo,
fileStatuses[i]);
}
- return fileStatuses;
+ return virtualStatues;
}
@Override
@@ -394,27 +387,27 @@ public class PaimonVirtualFileSystem extends FileSystem {
if (vfsIdentifier instanceof VFSCatalogIdentifier) {
throw new IOException("Cannot mkdirs for virtual path " + f + "
which is a catalog");
} else if (vfsIdentifier instanceof VFSDatabaseIdentifier) {
- vfsOperations.createDatabase(vfsIdentifier.getDatabaseName());
+ String databaseName = ((VFSDatabaseIdentifier)
vfsIdentifier).databaseName();
+ vfsOperations.createDatabase(databaseName);
return true;
} else if (vfsIdentifier instanceof VFSTableRootIdentifier) {
- VFSTableRootIdentifier vfsTableRootIdentifier =
(VFSTableRootIdentifier) vfsIdentifier;
- if (vfsTableRootIdentifier.isTableExist()) {
+ VFSTableRootIdentifier identifier = (VFSTableRootIdentifier)
vfsIdentifier;
+ if (identifier.tableInfo() != null) {
// Table already exists, no need to execute
return true;
}
- vfsOperations.createObjectTable(
- vfsIdentifier.getDatabaseName(),
vfsTableRootIdentifier.getTableName());
+ vfsOperations.createObjectTable(identifier.databaseName(),
identifier.tableName());
return true;
} else {
- VFSTableObjectIdentifier vfsTableObjectIdentifier =
- (VFSTableObjectIdentifier) vfsIdentifier;
- if (!vfsTableObjectIdentifier.isTableExist()) {
+ 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");
}
- return
vfsTableObjectIdentifier.fileIO().mkdirs(vfsTableObjectIdentifier.getRealPath());
+ return 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 8b63cc187d..24c817eb20 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
@@ -54,6 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link PaimonVirtualFileSystem}. */
public abstract class VirtualFileSystemTest {
+
@TempDir java.nio.file.Path tempFile;
protected String warehouse;
protected FileIO fileIO;