用Scala计数HDFS目录中的文件

发布于 2025-01-23 01:23:26 字数 208 浏览 1 评论 0原文

在Scala中,我正在尝试计算HDFS目录的文件。 我尝试获取具有val files = fs.listfiles(path,false)的文件列表,并依靠它或获取大小,但它不适用于files类型IS 远程标准器[stuentfilestatus]

关于如何处理的任何想法?

感谢您的帮助

In Scala, I am trying to count the files from an Hdfs directory.
I tryed to get a list of the files with val files = fs.listFiles(path, false) and make a count on it or get it's size, but it doesn't work as files type is RemoteIterator[LocatedFileStatus]

Any idea on how I should process ?

Thank's for helping

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

划一舟意中人 2025-01-30 01:23:27

这是之前已经完成的,但人们通常使用fsimage。 (名称节点文件的副本。)

然后他们将其扔进蜂巢表中,然后您可以查询有关HDFS文件系统的信息。

这是 /a>说明如何导出FSIMAGE并将其扔进蜂巢桌。

这是另一个我想我喜欢

获取并将fsimage文件复制到HDFS中
#Connect与HDFS用户

的任何Hadoop群集节点

  #downloads从Namenode
HDFS dfsadmin -fetchimage /tmp

#convert fsimage文件到选项卡中的划界文件
HDFS OIV -I /TMP /FSIMAGE_000000000000450297390 -O /TMP/FSIMAGE.CSV -P界定

#Remove标题并将其复制到HDFS
sed -i -e“ 1d” fsimage.csv
HDFS DFS -MKDIR /TMP /FSIMAGE
HDFS DFS -CopyFromlocal /Tmp/fsimage.csv /tmp /fsimage

#在Impala中创建中间桌
创建外部表HDFS_META_D( 
 路径字符串, 
 repl int, 
 modification_time字符串, 
 访问时间字符串, 
 preferredblocksize int, 
 封锁双重, 
 文件大小,double, 
 nsquota int, 
 dsquota int, 
 权限字符串, 
 用户名字符串, 
 groupName字符串) 
行格式定界
由“ \ t”终止的字段
位置'/tmp/fsimage';
 

在表中,您确实可以在Scala/Spark中完成其余的HDFS用户。

This has been done before but generally people use the FSImage. (A copy of the name node file.)

They'll then throw that into a hive table and then you can query it for information about your hdfs file system.

Here's a really good tutorial that explains how to export the fsimage and throw it into a hive table.

Here's another that I think I prefer:

Fetch and copy the fsimage file into HDFS
#connect to any hadoop cluster node as hdfs user

#downloads the fsimage file from namenode
hdfs dfsadmin -fetchImage /tmp

#converts the fsimage file into tab delimited file
hdfs oiv -i /tmp/fsimage_0000000000450297390 -o /tmp/fsimage.csv -p Delimited

#remove the header and copy to HDFS
sed -i -e "1d" fsimage.csv
hdfs dfs -mkdir /tmp/fsimage
hdfs dfs -copyFromLocal /tmp/fsimage.csv /tmp/fsimage

#create the intermediate external table in impala
CREATE EXTERNAL TABLE HDFS_META_D ( 
 PATH STRING , 
 REPL INT , 
 MODIFICATION_TIME STRING , 
 ACCESSTIME STRING , 
 PREFERREDBLOCKSIZE INT , 
 BLOCKCOUNT DOUBLE, 
 FILESIZE DOUBLE , 
 NSQUOTA INT , 
 DSQUOTA INT , 
 PERMISSION STRING , 
 USERNAME STRING , 
 GROUPNAME STRING) 
row format delimited
fields terminated by '\t'
LOCATION '/tmp/fsimage';

Once it's in a table you really can do the rest in scala/spark.

时光匆匆的小流年 2025-01-30 01:23:27

我最终使用:

var count: Int = 0
while (files.hasNext) {
  files.next
  count += 1
}

作为Scala Begginer,我不知道如何制作count ++(答案是count> count+= 1)。这实际上很安静

I end up using:

var count: Int = 0
while (files.hasNext) {
  files.next
  count += 1
}

As a Scala begginer, I didn't know how to make a count++ (the answear is count += 1). This actually works quiet well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文