feat(hudi-query): 增加关于hdfs文件数相关的接口

This commit is contained in:
v-zhangjc9
2024-10-12 14:43:05 +08:00
parent 70c2442ff1
commit 28b3fd9ca1
3 changed files with 47 additions and 0 deletions

View File

@@ -82,4 +82,19 @@ public class HdfsController {
public Long size(@RequestParam("root") String root) throws IOException {
return hdfsService.size(root);
}
@GetMapping("count")
public Long count(@RequestParam("root") String root) throws IOException {
return hdfsService.size(root);
}
@GetMapping("file_count")
public Long fileCount(@RequestParam("root") String root) throws IOException {
return hdfsService.size(root);
}
@GetMapping("directory_count")
public Long DirectoryCount(@RequestParam("root") String root) throws IOException {
return hdfsService.size(root);
}
}

View File

@@ -8,6 +8,7 @@ import com.lanyuanxiaoyao.service.forest.service.InfoService;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.ContentSummary;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
@@ -160,4 +161,26 @@ public class HdfsService {
return fileSystem.getContentSummary(new Path(root)).getLength();
}
}
@Cacheable(value = "count-hpath", sync = true)
public Long count(String root) throws IOException {
try (FileSystem fileSystem = FileSystem.get(new Configuration())) {
ContentSummary summary = fileSystem.getContentSummary(new Path(root));
return summary.getFileCount() + summary.getDirectoryCount();
}
}
@Cacheable(value = "file-count-hpath", sync = true)
public Long countFiles(String root) throws IOException {
try (FileSystem fileSystem = FileSystem.get(new Configuration())) {
return fileSystem.getContentSummary(new Path(root)).getFileCount();
}
}
@Cacheable(value = "directory-count-hpath", sync = true)
public Long countDirectories(String root) throws IOException {
try (FileSystem fileSystem = FileSystem.get(new Configuration())) {
return fileSystem.getContentSummary(new Path(root)).getDirectoryCount();
}
}
}