How to sort data in map reduce hadoop?

前端 未结 1 1746
后悔当初
后悔当初 2021-01-13 18:23

I am working with a programme that has 4 MapReduce steps.the output of my first step is:

id      value
 1        20
 2         3
 3         9
 4        36


        
相关标签:
1条回答
  • 2021-01-13 19:25

    If you want to sort according to value's, make it key in map function. i.e.

    id      value
    1        20
    2         3
    3         9
    4        36
    5         3
    

    (value) (key) in map function

    output will be 
    
    key      value
    3         5
    3         2
    9         3
    20        1
    36        4
    
    map<value, id> output key/value  
    reduce <value, id>
    

    if you want id to be in the first column, this will work.

    context.write(value, key);

    Note that, id's are not going to be sorted

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