我不是 Java 或 Hadoop 程序员,所以我解决问题的方法可能不是最好的,但无论如何。
我花了两天时间解决了本地读取FileSeq(Linux debian amd64)没有安装hadoop的问题。
提供的样本
while (reader.next(key, val)) {
System.out.println(key + ":" + val);
}
适用于 Text,但不适用于 BytesWritable 压缩输入数据。
我做了什么?
我下载了这个实用程序来创建(编写 SequenceFiles Hadoop 数据)
github_com/shsdev/sequencefile-utility/archive/master.zip
,并让它工作,然后修改为读取输入 Hadoop SeqFiles。
Debian 从头开始运行此实用程序的说明:
sudo apt-get install maven2
sudo mvn install
sudo apt-get install openjdk-7-jdk
edit "sudo vi /usr/bin/mvn",
change `which java` to `which /usr/lib/jvm/java-7-openjdk-amd64/bin/java`
Also I've added (probably not required)
'
PATH="/home/mine/perl5/bin${PATH+:}${PATH};/usr/lib/jvm/java-7-openjdk-amd64/"; export PATH;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
export JAVA_VERSION=1.7
'
to ~/.bashrc
Then usage:
sudo mvn install
~/hadoop_tools/sequencefile-utility/sequencefile-utility-master$ /usr/lib/jvm/java-7-openjdk-amd64/bin/java -jar ./target/sequencefile-utility-1.0-jar-with-dependencies.jar
-- and this doesn't break the default java 1.6 installation that is required for FireFox/etc.
为了解决 FileSeq 兼容性错误(例如“无法为您的平台加载 native-hadoop 库......在适用的情况下使用内置 java 类”),我按原样使用来自 Hadoop 主服务器的库(一种破解):
scp root@10.15.150.223:/usr/lib/libhadoop.so.1.0.0 ~/
sudo cp ~/libhadoop.so.1.0.0 /usr/lib/
scp root@10.15.150.223:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/amd64/server/libjvm.so ~/
sudo cp ~/libjvm.so /usr/lib/
sudo ln -s /usr/lib/libhadoop.so.1.0.0 /usr/lib/libhadoop.so.1
sudo ln -s /usr/lib/libhadoop.so.1.0.0 /usr/lib/libhadoop.so
一个晚上喝咖啡,我写了这个代码来读取 FileSeq hadoop 输入文件(使用这个 cmd 来运行这个代码“/usr/lib/jvm/java-7-openjdk-amd64/bin/java -jar ./target/sequencefile-utility-1.3-jar-with-dependencies.jar -d test/ -c NONE"):
import org.apache.hadoop.io.*;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.SequenceFile.ValueBytes;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
Path file = new Path("/home/mine/mycompany/task13/data/2015-08-30");
reader = new SequenceFile.Reader(fs, file, conf);
long pos = reader.getPosition();
logger.info("GO from pos "+pos);
DataOutputBuffer rawKey = new DataOutputBuffer();
ValueBytes rawValue = reader.createValueBytes();
int DEFAULT_BUFFER_SIZE = 1024 * 1024;
DataOutputBuffer kobuf = new DataOutputBuffer(DEFAULT_BUFFER_SIZE);
kobuf.reset();
int rl;
do {
rl = reader.nextRaw(kobuf, rawValue);
logger.info("read len for current record: "+rl+" and in more details ");
if(rl >= 0)
{
logger.info("read key "+new String(kobuf.getData())+" (keylen "+kobuf.getLength()+") and data "+rawValue.getSize());
FileOutputStream fos = new FileOutputStream("/home/mine/outb");
DataOutputStream dos = new DataOutputStream(fos);
rawValue.writeUncompressedBytes(dos);
kobuf.reset();
}
} while(rl>0);
-
我刚刚将这段代码添加到文件 src/main/java/eu/scape_project/tb/lsdr/seqfileutility/SequenceFileWriter.java 的行之后
writer = SequenceFile.createWriter(fs, conf, path, keyClass,
valueClass, CompressionType.get(pc.getCompressionType()));
感谢以下信息来源:
链接:
如果使用 hadoop-core 而不是 mahour,则必须手动下载 asm-3.1.jar:
search_maven_org/remotecontent?filepath=org/ow2/util/asm/asm/3.1/asm-3.1.jar
search_maven_org/#search|ga|1|asm-3.1
可用的 mahout 存储库列表:
repo1_maven_org/maven2/org/apache/mahout/
Mahout简介:
mahout_apache_org/
学习 Hadoop Java 类的接口和源代码的好资源(我用它来编写我自己的代码来读取 FileSeq):
http://grepcode.com/file/repo1.maven.org/maven2/com.ning/metrics.action/0.2.7/org/apache/hadoop/io/BytesWritable.java
我用于创建自己的项目 FileSeq 阅读器的项目 tb-lsdr-seqfilecreator 的来源:
www_javased_com/?source_dir=scape/tb-lsdr-seqfilecreator/src/main/java/eu/scape_project/tb/lsdr/seqfileutility/ProcessParameters.java
stackoverflow_com/questions/5096128/sequence-files-in-hadoop - 相同的示例(读取不起作用的键、值)
https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/mapreduce/input/RawSequenceFileRecordReader.java - 这个帮助了我(我使用 reader.nextRaw 与 nextKeyValue() 和其他 subs 相同)
我还为本地 apache.hadoop 而不是 mahout.hadoop 更改了 ./pom.xml,但这可能不是必需的,因为 read->next(key, value) 的错误对于两者都是相同的,所以我不得不改用 read->nextRaw(keyRaw, valueRaw) :
diff ../../sequencefile-utility/sequencefile-utility-master/pom.xml ./pom.xml
9c9
< <version>1.0</version>
---
> <version>1.3</version>
63c63
< <version>2.0.1</version>
---
> <version>2.4</version>
85c85
< <groupId>org.apache.mahout.hadoop</groupId>
---
> <groupId>org.apache.hadoop</groupId>
87c87
< <version>0.20.1</version>
---
> <version>1.1.2</version>
93c93
< <version>1.1</version>
---
> <version>1.1.3</version>