当我们在一些处理后使用 Spark 时,我将结果存储到文件并使用带有简单代码的 snappy 编解码器:
data.saveAsTextFile("/data/2014-11-29",classOf[org.apache.hadoop.io.compress.SnappyCodec])
之后,当我使用 Spark 读取此文件夹文件时,一切正常!但是今天我尝试在我的电脑中使用 java snappy (java-snappy 1.1.1.2) 来解压缩结果文件夹中的文件(这个文件是从这个文件夹下载到我的电脑的文件之一)
Maven依赖:
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.1.1.2</version>
</dependency>
我使用此代码解压缩:
File fileIn = new File("E:\\dt\\part-00000.snappy");
File fileOut = new File("E:\\dt\\adv1417971604684.dat");
FileOutputStream fos = new FileOutputStream(fileOut, true);
byte[] fileBytes = Files.readAllBytes(Paths.get(fileIn.getPath()));
byte[] fileBytesOut = Snappy.uncompress(fileBytes);
fos.write(fileBytesOut);
但是:(我立即收到此错误:
java.io.IOException: FAILED_TO_UNCOMPRESS(5)
at org.xerial.snappy.SnappyNative.throw_error(SnappyNative.java:84)
at org.xerial.snappy.SnappyNative.rawUncompress(Native Method)
at org.xerial.snappy.Snappy.rawUncompress(Snappy.java:444)
at org.xerial.snappy.Snappy.uncompress(Snappy.java:480)
at org.xerial.snappy.Snappy.uncompress(Snappy.java:456)
at
在火花集群中,我们使用:
spark 1.1.0 && hadoop 2.5.1(带有原生 hadoop snappy)
这是我运行hadoop checknative -a时的结果:
14/12/09 16:16:57 INFO bzip2.Bzip2Factory: Successfully loaded & initialized native-bzip2 library system-native
14/12/09 16:16:57 INFO zlib.ZlibFactory: Successfully loaded & initialized native-zlib library
Native library checking:
hadoop: true /usr/local/hadoop/hadoop2.5.1/lib/native/libhadoop.so
zlib: true /lib64/libz.so.1
snappy: true /usr/local/hadoop/hadoop2.5.1/lib/native/libsnappy.so.1
lz4: true revision:99
bzip2: true /lib64/libbz2.so.1
我从链接下载并构建了 snappy native:
https://code.google.com/p/snappy/ 和来源: https ://drive.google.com/file/d/0B0xs9kK-b5nMOWIxWGJhMXd6aGs/edit?usp=sharing
有人请解释这个奇怪的错误!hadoop使用本机snappy压缩数据时是否有一些差异使用java-snappy??????