2014-12-24 2 views

답변

0

/ex-seqdata/part-000 ... 의 hdfs에 시퀀스 데이터가 있다고 가정하면 part- * 데이터는 바이너리 형식입니다. 이제 명령 프롬프트에서 hadoop fs -text/ex-seqdata/part * 명령을 실행하여 사람이 읽을 수있는 형식으로 데이터를 가져올 수 있습니다.

1

난 당신이 다음과 같이 코드 몇 줄의 SequenceFile 리더를 만들 수 있다고 생각

public static void main(String[] args) throws IOException { 
    String uri = "path/to/your/sequence/file"; 
    Configuration conf = new Configuration(); 
    FileSystem fs = FileSystem.get(URI.create(uri), conf); 
    Path path = new Path(uri); 

    SequenceFile.Reader reader = null; 
    try { 
     reader = new SequenceFile.Reader(fs, path, conf); 
     Writable key = (Writable) ReflectionUtils.newInstance(
        reader.getKeyClass(), conf); 
     Writable value = (Writable) ReflectionUtils.newInstance(
        reader.getValueClass(), conf); 
     long position = reader.getPosition(); 
     while (reader.next(key, value)) { 
       System.out.println("Key: " + key + " value:" + value); 
       position = reader.getPosition(); 
      } 
     } finally { 
      reader.close(); 
    } 
} 
관련 문제