Skip to content

Commit 70382b1

Browse files
authored
[pvfs] Fix file status and input stream for PVFS (#6397)
1 parent 35e2d25 commit 70382b1

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class PaimonVirtualFileSystem extends FileSystem {
5959
private Configuration conf;
6060

6161
private static final String USER_AGENT = "HadoopPVFS";
62+
private static final long DEFAULT_BLOCK_SIZE = 128 * 1024 * 1024L;
6263

6364
@Override
6465
public void initialize(URI uri, Configuration conf) throws IOException {
@@ -299,7 +300,7 @@ public boolean delete(Path f, boolean recursive) throws IOException {
299300
public FileStatus getFileStatus(Path f) throws IOException {
300301
VFSIdentifier vfsIdentifier = vfsOperations.getVFSIdentifier(getVirtualPath(f));
301302
if (vfsIdentifier instanceof VFSCatalogIdentifier) {
302-
return new FileStatus(0, true, 1, 1, 0, new Path(this.uri));
303+
return new FileStatus(0, true, 1, 0, 0, new Path(this.uri));
303304
} else if (vfsIdentifier instanceof VFSDatabaseIdentifier) {
304305
String databaseName = ((VFSDatabaseIdentifier) vfsIdentifier).databaseName();
305306
GetDatabaseResponse database = vfsOperations.getDatabase(databaseName);
@@ -318,7 +319,7 @@ public FileStatus getFileStatus(Path f) throws IOException {
318319
}
319320

320321
private FileStatus convertDatabase(GetDatabaseResponse database) {
321-
return new FileStatus(0, true, 1, 1, 0, new Path(new Path(this.uri), database.getName()));
322+
return new FileStatus(0, true, 1, 0, 0, new Path(new Path(this.uri), database.getName()));
322323
}
323324

324325
private FileStatus convertFileStatus(
@@ -338,11 +339,12 @@ private FileStatus convertFileStatus(
338339
childPath = "/" + childPath;
339340
}
340341
Path virtualPath = new Path(new Path(this.uri), databaseName + "/" + tableName + childPath);
342+
long blockSize = fileStatus.isDir() ? 0 : DEFAULT_BLOCK_SIZE;
341343
return new FileStatus(
342344
fileStatus.getLen(),
343345
fileStatus.isDir(),
344346
1,
345-
1,
347+
blockSize,
346348
fileStatus.getModificationTime(),
347349
virtualPath);
348350
}
@@ -375,7 +377,7 @@ private FileStatus[] convertDatabases(List<String> databases) {
375377
for (int i = 0; i < databases.size(); i++) {
376378
String database = databases.get(i);
377379
FileStatus fileStatus =
378-
new FileStatus(0, true, 1, 1, 0, new Path(new Path(this.uri), database));
380+
new FileStatus(0, true, 1, 0, 0, new Path(new Path(this.uri), database));
379381
fileStatuses[i] = fileStatus;
380382
}
381383
return fileStatuses;
@@ -387,7 +389,7 @@ private FileStatus[] convertTables(String database, List<String> tables) {
387389
String table = tables.get(i);
388390
FileStatus fileStatus =
389391
new FileStatus(
390-
0, true, 1, 1, 0, new Path(new Path(this.uri), database + "/" + table));
392+
0, true, 1, 0, 0, new Path(new Path(this.uri), database + "/" + table));
391393
fileStatuses[i] = fileStatus;
392394
}
393395
return fileStatuses;

paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/VFSInputStream.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ public int read() throws IOException {
7777
}
7878
return (n == -1) ? -1 : oneByteBuf[0] & 0xff;
7979
}
80+
81+
@Override
82+
public void close() throws IOException {
83+
in.close();
84+
}
8085
}

paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public void testMkdir() throws Exception {
137137
FileStatus fileStatus = vfs.getFileStatus(vfsPath);
138138
Assert.assertEquals(vfsPath.toString(), fileStatus.getPath().toString());
139139
Assert.assertTrue(fileStatus.isDirectory());
140+
Assert.assertEquals(0, fileStatus.getBlockSize());
140141

141142
// Mkdir in non-existing table
142143
tableName = "object_table2";
@@ -195,6 +196,7 @@ public void testCreate() throws Exception {
195196
Assert.assertEquals(vfsPath.toString(), fileStatus.getPath().toString());
196197
Assert.assertTrue(fileStatus.isFile());
197198
Assert.assertEquals(5, fileStatus.getLen());
199+
Assert.assertEquals(128 * 1024 * 1024L, fileStatus.getBlockSize());
198200

199201
FSDataInputStream in = vfs.open(vfsPath);
200202
byte[] buffer = new byte[5];

0 commit comments

Comments
 (0)