how to set auto increment column value with condition

I have table like this

value nextValue
1     2
2     3
3     20
20    21
21    22
22    23
23    NULL

Value is ordered Asc, nextValue is next row Value. requirement is group by with condition nextValue-value>10, and count how many values in different groups.

For example, there should be two groups (1,2,3) and (20,21,22,23), first group count is 3, the second group count is 4.

I'm try to mark each group with unique number, so I could group by these marked nums

value nextValue mark
1     2         1
2     3         1
3     20        1
20    21        2
21    22        2
22    23        2
23    NULL      2

But I don't know how to write mark column, I need an autocrement variable when nextValue-value>10. Can I make it happen in Hive? Or there's better solution for the requirement?



Read more here: https://stackoverflow.com/questions/64399803/how-to-set-auto-increment-column-value-with-condition

Content Attribution

This content was originally published by Neil at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: