之前写过一篇如何将 Oracle 表导入 hive 表。https://blog.csdn.net/u011675334/article/details/102504953
今天讲一个更为快捷的方式。
假设已经建好一个临时表,但是要给该表按日期建立分区,就可以复用该表的格式。
首先执行命令:
show create table test.template;
弹出结果如下:
CREATE TABLE `template`(
`id` string,
`ctr` double)
partitioned by (`dt` string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://cluster/apps/hive/warehouse/test.db/template'
;
TBLPROPERTIES (
'COLUMN_STATS_ACCURATE'='{\"BASIC_STATS\":\"true\"}',
'numFiles'='1',
'numRows'='35',
'rawDataSize'='773',
'totalSize'='808',
'transient_lastDdlTime'='1581422275')
在删除原来的临时表之后,只需选取 TBLPROPERTIES 以上部分即可建表。
此外,需要注意 partitioned by (`dt` string),意思是按照 dt (日期)建分区。
如果是 ORC 格式,则改为 STORED AS ORC; 且后面的 INPUTFORMAT 和 OUTPUTFORMAT 需省略。