How to handle id generation on a hadoop cluster?

后端 未结 3 924
陌清茗
陌清茗 2020-12-20 03:40

I am building a dictionary on a hadoop cluster and need to generate a numeric id for each token. How should I do it?

3条回答
  •  遥遥无期
    2020-12-20 04:02

    You have two problems. First you want to make sure that you assign exactly one id for each token. To do that you should sort and group records by token and make the assignment in a reducer. Once you've made sure that the reducer method is called exactly once for each token you can use the partition number from the context and a unique numeric id maintained by the reducer (one instance per partition) - just use an instance variable initialized to 1 in the setup method and incremented in the reduce method.

提交回复
热议问题