hadoop에서 대량의 작은 파일을 sequenceFile 파일로 생성합니다
그래서 항상 연결이 되지 않는 문제가 발생합니다. (Retrying connect to server:localhost/127.0.1:8020. Already tried 0 time(s).
그래서 프로그램을 실행할 때 Hadoop에 연결되지 않는 문제가 생겼을 때 프로그램이 잘못 썼는지 고려합니다.
2) sequenceFile에는 파일 이름(또는 다른 값)을 키로 하고 파일 내용은 값으로 저장됩니다.그러나 SequenceFileAsTextInputFormat로 읽을 때 키 값은 파일의 첫 줄로 읽힙니다
원본 코드를 분석하지 않아 원인을 알 수 없다
3) sequenceFile에서 처리할 수 있습니다.gz 파일 (실험이 없으면 안 됩니다. 말하자면.gz 파일은 블록으로 저장할 수 없습니다??? 논리적으로는 하나입니다)
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
public class sequeneceFile{
public static void main(String[] args) throws IOException {
//String seqFsUrl = "hdfs://localhost:9000/user/mjiang/target-seq/sdfgz.seq";
String seqFsUrl = "user/mjiang/target-seq/sdfgz.seq";
Configuration conf = new Configuration();
//conf.set("fs.default.name", "hdfs://venus:9000");
//conf.set("hadoop.job.user", "mjiang");
//conf.set("mapred.job.tracker", "venus:9001");
FileSystem fs = FileSystem.get(URI.create(seqFsUrl),conf);
Path seqPath = new Path(seqFsUrl);
//Text key = new Text();
Text value = new Text();
String filesPath = "/home/mjiang/java/eclipse/hadoop/sequenceFile/data/sdfgz/";
File gzFilesDir = new File(filesPath);
String[] gzFiles = gzFilesDir.list();
int filesLen=gzFiles.length;
SequenceFile.Writer writer = null;
try {// SequenceFile.Writer path path
writer = SequenceFile.createWriter(fs, conf, seqPath,NullWritable.class, value.getClass());
//for (int i=0;i<2;i++){
while (filesLen>0){
File gzFile = new File(filesPath+gzFiles[filesLen-1]);
InputStream in = new BufferedInputStream(new FileInputStream(gzFile));
long len = gzFile.length();
byte[] buff = new byte[(int)len];
if ((len = in.read(buff))!= -1) {
value.set(buff);
writer.append(NullWritable.get(), value);// SequenceFile.Writer
}
//process
System.out.println(gzFiles[filesLen-1]);
//key.clear();
value.clear();
IOUtils.closeStream(in);
filesLen--;//!!
}
//filesLen = 2; }
} finally {
IOUtils.closeStream(writer);
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Access Request, Session and Application in Struts2If we want to use request, Session and application in JSP, what should we do? We can obtain Map type objects such as Req...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.