2011-02-23 4 views
7

이러한 시퀀스 파일은 어떻게 생성됩니까? 시퀀스 파일에 대한 링크를 여기에서 보았습니다.Hadoop의 시퀀스 파일

http://wiki.apache.org/hadoop/SequenceFile 

기본 Java serializer를 사용하여 작성 했습니까? 시퀀스 파일을 읽으려면 어떻게해야합니까?

+0

키 클래스 및 값 클래스는 여기에 있습니다. 어디서 접속 했습니까? Plese 나를 도와주세요. 미리 감사드립니다. –

답변

16

시퀀스 파일은 MapReduce 작업에 의해 생성되며 MapReduce 작업간에 데이터를 전송하기위한 공통 형식으로 사용할 수 있습니다.

다음과 같은 방식으로 읽을 수 있습니다

Configuration config = new Configuration(); 
Path path = new Path(PATH_TO_YOUR_FILE); 
SequenceFile.Reader reader = new SequenceFile.Reader(FileSystem.get(config), path, config); 
WritableComparable key = (WritableComparable) reader.getKeyClass().newInstance(); 
Writable value = (Writable) reader.getValueClass().newInstance(); 
while (reader.next(key, value)) 
    // perform some operating 
reader.close(); 

은 또한 당신은 SequenceFile.Writer를 사용하여 직접 시퀀스 파일을 생성 할 수 있습니다. 다음은 예제에서 사용

클래스 :

import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.fs.FileSystem; 
import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.io.SequenceFile; 
import org.apache.hadoop.io.Writable; 
import org.apache.hadoop.io.WritableComparable; 

그리고 hadoop-core 받는다는 의존성에 포함되어 있습니다 : 레프 Khomich의 대답에

<dependency> 
    <groupId>org.apache.hadoop</groupId> 
    <artifactId>hadoop-core</artifactId> 
    <version>1.2.1</version> 
</dependency> 
3

덕분에, 내 문제가 해결되었습니다.

그러나이 솔루션은 잠시 사용이 중단되었으며 새 API는 더 많은 기능과 사용 편의성을 제공합니다. hadoop.io.SequenceFile의 소스 코드를 알아

확인, here 클릭

------------------------ 
https://wiki.openoffice.org/wiki/Ru/FAQ 
Version: 7 
Status: 1 (db_unfetched) 
Fetch time: Sun Apr 13 16:12:59 MDT 2014 
Modified time: Wed Dec 31 17:00:00 MST 1969 
Retries since fetch: 0 
Retry interval: 2592000 seconds (30 days) 
Score: 1.0 
Signature: null 
Metadata: 

------------------------ 
https://www.bankhapoalim.co.il/ 
Version: 7 
Status: 1 (db_unfetched) 
Fetch time: Sun Apr 13 16:12:59 MDT 2014 
Modified time: Wed Dec 31 17:00:00 MST 1969 
Retries since fetch: 0 
Retry interval: 2592000 seconds (30 days) 
Score: 1.0 
Signature: null 
Metadata: 
:

Configuration config = new Configuration(); 
Path path = new Path("/Users/myuser/sequencefile"); 
SequenceFile.Reader reader = new Reader(config, Reader.file(path)); 
WritableComparable key = (WritableComparable) reader.getKeyClass() 
     .newInstance(); 
Writable value = (Writable) reader.getValueClass().newInstance(); 

while (reader.next(key, value)) { 
    System.out.println(key); 
    System.out.println(value); 
    System.out.println("------------------------"); 
} 
reader.close(); 

추가 정보를 여기 Nutch/인젝터에 의해 생성 된 데이터 파일에 대해 실행중인 샘플 출력은

감사합니다.

+0

실제로 솔루션은 @ khomich의 것보다 더 유사합니다 : 유일한 변경 사항은 Reader 생성자를 호출하는 것입니다. 그 점을 지적 해 주면 좋았을 것입니다. – javadba

관련 문제