<分区>
我是 Hadoop 编程的新手,我在 Haddop 中找到了一些关于 mapreduce 的有用链接,我可以处理。这对我和初学者都非常有用。
所有示例都显示为从 eclipse 提供输入,输出可以在 eclipse 的输出文件夹中看到。
在这里我想知道如何从 HDFS 提供输入(我的意思是而不是从 eclipse 提供)。 并将输出写入某个 Excel 文件。
请多多指教。
<分区>
我是 Hadoop 编程的新手,我在 Haddop 中找到了一些关于 mapreduce 的有用链接,我可以处理。这对我和初学者都非常有用。
所有示例都显示为从 eclipse 提供输入,输出可以在 eclipse 的输出文件夹中看到。
在这里我想知道如何从 HDFS 提供输入(我的意思是而不是从 eclipse 提供)。 并将输出写入某个 Excel 文件。
请多多指教。
最佳答案
您只需使用 Java 和 Excel 执行必要的步骤,即可使用 Hadoop 正确处理您的信息。
这里有一个关于如何进行输入的典型示例:
public void addFile(String source, String dest) throws IOException {
// Conf object will read the HDFS configuration parameters
Configuration conf = new Configuration();
conf.addResource(new Path("/home/hadoop/hadoop/conf/core-site.xml"));
conf.addResource(new Path("/home/hadoop/hadoop/conf/hdfs-site.xml"));
conf.addResource(new Path("/home/hadoop/hadoop/conf/mapred-site.xml"));
FileSystem fileSystem = FileSystem.get(conf);
// Get the filename out of the file path
String filename = source.substring(source.lastIndexOf('/') + 1, source.length());
// Create the destination path including the filename.
if (dest.charAt(dest.length() - 1) != '/') {
dest = dest + "/" + filename;
} else {
dest = dest + filename;
}
// Check if the file already exists
Path path = new Path(dest);
if (fileSystem.exists(path)) {
System.out.println("File " + dest + " already exists");
return;
}
// Create a new file and write data to it.
FSDataOutputStream out = fileSystem.create(path);
InputStream in = new BufferedInputStream(new FileInputStream(
new File(source)));
byte[] b = new byte[1024];
int numBytes = 0;
while ((numBytes = in.read(b)) > 0) {
out.write(b, 0, numBytes);
}
// Close all the file descripters
in.close();
out.close();
fileSystem.close();
}
来源:A HDFSClient for Hadoop - Linux Junkies
然后按照有关如何可视化数据输出的说明进行操作:
更多有用的信息:
Hadoop 通过轻松集成为您提供所有可能需要的工具,以优化您的数据分析和操作。
关于java - 用于从 hdfs 提供输入并将输出写入 excel 文件的 Hadoop Mapreduce 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22441669/