hive 以like方式建表(攜帶表結構)


hive建表語句:

CREATE TABLE `hive_ttt_999`(
`id` bigint COMMENT 'ID,主鍵', 
`name` string COMMENT '姓名', 
`address` string COMMENT '地址', 
`mobile` string COMMENT '手機號', 
`other_info` string COMMENT '其他信息', 
`tenant_id` string COMMENT '租戶ID', 
`created_by` string COMMENT '創建者', 
`created_time` string COMMENT '創建時間', 
`updated_time` string COMMENT '更新時間', 
`updated_by` string COMMENT '更新者', 
`version` bigint COMMENT '版本號,樂觀鎖', 
`is_deleted` bigint COMMENT '是否刪除')
ROW FORMAT SERDE 
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
WITH SERDEPROPERTIES ( 
'field.delim'='|', 
'serialization.format'='|') 
STORED AS INPUTFORMAT 
'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://nameservice1/user/hive/warehouse/ttt.db/hive_ttt_999'
TBLPROPERTIES (
'transient_lastDdlTime'='1629364931')

創建表:(以hive_ttt_999為模板)

use ttt;
create table burrowsTest_0 like hive_ttt_999;

用此腳本實現批量打印所需建表/刪表語句
num = 3200
target_table = 'dct_test_from'

for x in range(800, num):
	print(f'create table hive_ttt_{x} like {target_table};')
	#print(f'drop table hive_ttt_{x};')
	#print(f"create index hive_ttt_index_{x} on table hive_ttt_{x}(id) as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild;")

給hive表建索引

create index index_01 on table hive_ttt_999(id) as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM