欢迎来到田晓东的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。
扩大
缩小

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;

posted on 2021-08-31 14:50  匍匐的仰望者  阅读(1720)  评论(0编辑  收藏  举报

导航