How to read hadoop sequential file?

前端 未结 1 991
萌比男神i
萌比男神i 2021-01-12 04:51

I have a sequential file which is the output of hadoop map-reduce job. In this file data is written in key value pairs ,and value itself is a map. I want to read the value a

1条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 05:28

    Check the API documentation for SequenceFile#next(Writable, Writable)

    while(reader.next(key,value))
    {
           System.out.println("Key is: "+textKey +" value is: "+val+"\n");
    }
    

    should be replaced with

    while(reader.next(key,value))
    {
           System.out.println("Key is: "+key +" value is: "+value+"\n");
    }
    

    Use SequenceFile.Reader#getValueClassName to get the value type in the SequenceFile. SequenceFile have the key/value types in the file header.

    0 讨论(0)
提交回复
热议问题