Support Questions
Find answers, ask questions, and share your expertise

Is there any default way of generating sequence in hive? Like do we have functions to generate sequence number or id?


@Bala Vignesh N V

We don't have support for auto_increment, sequence still in Hive.

There is the following UDF but you would have to restrict the number of mappers to 1 to make this work.

Dear All,

I need to generate the surrogate keys(which are sequential) in HIVE.I do not want to go and use the method (java.util.UUID) since it generates 33 bytes of lenghth and i do not want that much length(Though it was unique).So predominantly i can do that in 2 ways if i am not wrong:

1st Method:

To restrict the number of mappers to 1 and use the code for random unique generation of UDF in HIVE.The code repository as mentioned in the above post.

2nd Method:

  • 1)Load data to a temp hive table
  • 2)Lets get the max value in the table
  • 3)Lets use row_number over() to generate row_number+1 and load to actual table.

**** Please Note : I think we cannot restrict the number of mappers to 1 and hence both the methods fail for the creation of unique keys. ****

Please let me know if there is a way to do this?



Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.