Need to add auto increment column in a table using hive

非 Y 不嫁゛ 提交于 2019-12-10 19:54:31

问题


I have to create a table using hive. But I want to create that table with auto increment column.

i have googled but not able to find the exact answer. If Anybody knows the syntax for it . Please share it.

thanks in advance.


回答1:


You need to use a UDF (user defined function) for it. I have successfully used the UDF in this link http://svn.apache.org/repos/asf/hive/trunk/contrib/src/java/org/apache/hadoop/hive/contrib/udf/UDFRowSequence.java

Further you can learn the use of UDF in hive by this very helpful tutorial.




回答2:


INSERT INTO TEST_INC SELECT
reflect("java.util.UUID", "randomUUID"), test1, test2, test3 from TEST;

for example.




回答3:


You got to write a UDF for this purpose. Take a look at the following Jira discussion

https://issues.apache.org/jira/browse/HIVE-1304.

Download the following patch file and try it

This can be applied only for small input. Since the UDF row_sequence() is used in the reducer and the reducer count should be kept 1 inorder to keep the autoincrement field distinct



来源:https://stackoverflow.com/questions/23082763/need-to-add-auto-increment-column-in-a-table-using-hive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!