2017-03-02 55 views
1

是否可以使用用戶指定的記錄數創建配置單元表?如何用用戶指定的記錄數創建Hive表?

例如,我想創建一個x行數的表(其中x由用戶定義)。該表有兩列1.唯一行ID [可以自動遞增] 2.隨機生成的字符串。

這可能使用Hive嗎?

+0

附:還有你的另一篇文章 - http://stackoverflow.com/questions/42562705/how-to-generate-large-amount-of-data-using-mapreduce-process。我很好奇你爲什麼要刪除它 –

回答

0

在創建表時指定的行的數目的限制可能是不可能的,但是,其可能使用LIMIT子句

-- <filename:dbloader.sql> 

create table {hiveconf:TABLENAME} (id int, string1 string) 

insert into newtable 
select id,string1 from oldtable limit {hiveconf:ROWLIMIT}; 

限制可以被插入到表中的行的數量和同時提交蜂房腳本 -

hive --hiveconf TABLENAME='XYZ' --hiveconf ROWLIMIT=1000 -f dbloader.sql 

至於創建唯一的增量ID,你將不得不爲它編寫UDF。

+0

你可以使用row_number()作爲增量id。 –

+1

這不回答這個問題 –

0
set N=7; 

select pe.i+1                   as n 
     ,java_method ('org.apache.commons.lang.RandomStringUtils','randomAlphabetic',10) as str 

from (select 1) x 
     lateral view posexplode(split(space(${hiveconf:N}-1),' ')) pe as i,x 
; 

+---+------------+ 
| n | str  | 
+---+------------+ 
| 1 | udttBCmtxT | 
| 2 | kkrMQmirSG | 
| 3 | iYDABgXOvW | 
| 4 | DKHKgtXKPS | 
| 5 | ylebKcdcGj | 
| 6 | DaujBCkCtz | 
| 7 | VMaWfbtzFY | 
+---+------------+ 

posexplode
java_method
RandomStringUtils

相關問題