我是Hadoop的新手,最近被要求使用Hadoop进行测试项目。
因此,当我阅读BigData时,偶然知道了Pail。现在我要做的就是这样。首先创建一个简单的对象,然后使用Thrift对其进行序列化,然后使用Pail将其放入HDFS。然后,我想在map函数中获取该对象并做我想做的事情。但是我不知道如何在 map 函数中添加tat对象。
有人可以告诉我任何引用资料或解释如何做吗?
最佳答案
我可以想到三种选择:
-files
选项并在HDFS中命名文件(最好是任务跟踪器将为该节点上运行的所有作业下载一次文件)对于某些代码,将加载逻辑放入映射器的
setup(...)
或configure(..)方法中(取决于您使用的是新API还是旧API),如下所示:protected void setup(Context context) {
// the -files option makes the named file available in the local directory
File file = new File("filename.dat");
// open file and load contents ...
// load the file directly from HDFS
FileSystem fs = FileSystem.get(context.getConfiguration());
InputStream hdfsInputStream = fs.open("/path/to/file/in/hdfs/filename.dat");
// load file contents from stream...
}
DistributedCache在Javadocs中有一些示例代码