"skip.header.line.count"="1"
create table xxx{
...
}
...
tblproperties(
"skip.header.line.count"="1", --跳過文件首的1行
--"skip.footer.line.count"="n" --跳過文件尾的n行
)
複製代碼
注意csv文件的列的分隔符時,
、;
仍是\t
,如fields terminated by ','
node
注意是從本地文件上傳,hdfs移動,仍是查詢已有表插入到新表中,數據導入Hive表的語法不一樣,分別是load data local inpath ...
,load data inpath ...
,insert into/overwrite table xxx ... select ...
sql
--靜態分區
insert into table table1 partition(partition_col="xxx") select ... from query_table;
--動態分區,要注意分區字段和查詢的字段類型是否一致
insert into table table1 partition(col1) select col1,... from query_table;
複製代碼
from query_table
insert into table table1 [partition]
select col1,col2
insert into table table2
select *
複製代碼
insert into/overwrite
的區別,into是追加,overwrite是重寫(先刪後寫,若是涉及分區的話是重寫該分區數據)涉及到分區表插入數據時,要注意是否開啓動態分區,是採用嚴格模式仍是非嚴格的,容許建立的最大動態分區數,涉及如下幾個配置app
hive.exec.dynamic.partition
,開啓動態分區,默認truehive.exec.dynamic.partition.mode
,動態分區模式,默認是嚴格的(strict,用戶必須指定一個靜態分區)。非嚴格模式(nonstrict)容許全部分區字段都是動態的分區。【記得設置爲非嚴格的】hive.exec.max.dynamic.partitions
,總共容許建立的最大動態分區數,默認1000hive.exec.max.dynamic.ppartitions.pernode
,每一個節點上容許建立的最大動態分區數,默認100hive.exec.max.created.files
,一個MR Job中全部mappers、reducers總共容許建立的最大hdfs文件數,默認100000hive.error.on.empty.partition
,動態分區爲空時是否拋出異常,默認false,也無需設置
partition(pCol="xxx",col1)