问题描述
我正在流式传输一个R mapreduce工作,我需要获取文件名。我知道Hadoop在开始之前为当前作业设置环境变量,我可以使用Sys.getenv()访问R中的env vars。我发现:
和Sys.getenv(mapred_job_id)工作正常,但这不是我需要的。我只需要文件名,而不是作业ID或名称。我还发现:
但这也没有帮助。当从R流式传输时,最简单的获取当前文件名的方法是什么?谢谢
我没有尝试过这个,但是从你提供的第二个链接来看,这在环境中可用变量名为 map.input.file
。然后,这应该工作:
Sys.getenv(map.input.file)
编辑:
进一步调查后,我了解到需要用下划线替换点,所以这是做的方式它:
Sys.getenv(map_input_file)
但是,(Hadoop 2.x)中已经不推荐使用map.input.file属性,因此应该使用新的名称:
Sys.getenv(mapreduce_map_input_file)
I am streaming an R mapreduce job and I am need to get the filename. I know that Hadoop sets environment variables for the current job before it starts and I can access env vars in R with Sys.getenv().
I found :Get input file name in streaming hadoop program
and Sys.getenv(mapred_job_id) works fine, but it is not what I need. I just need the filename and not the job id or name. I also found: How to get filename when running mapreduce job on EC2?
But this isn't helpful either. What is the easiest way to get the current filename while streaming from R? Thank you
I have not tried this, but from the second link you provided, it seems that this is available in an environment variable called map.input.file
. Then, this should work:
Sys.getenv("map.input.file")
EDIT:Upon further investigation, I learned that you need to replace the dots with underscores, so this is the way to do it:
Sys.getenv("map_input_file")
However, the map.input.file property has been deprecated in YARN (Hadoop 2.x), so the new name should be used instead:
Sys.getenv("mapreduce_map_input_file")
这篇关于如何从R中的流映射减少作业获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!