2

我是 hadoop 生态系统的新手。我试图使用以下查询从 CSV 文件创建配置单元表。

CREATE EXTERNAL TABLE IF NOT EXISTS proxy_data(
  date_time TIMESTAMP,time_taken INT, c_ip STRING,
  sc_status INT, s_action STRING, sc_bytes INT,
  cs_bytes INT, cs_method STRING, cs_uri STRING,
  cs_host STRING, uri_port INT, uri_path STRING,
  uri_query STRING, username STRING, auth STRING,
  supplier_name STRING, content_type STRING, referer STRING,
  user_agent STRING, filter_result STRING, categories STRING,
  x_virus_id STRING, proxy_ip STRING
)
COMMENT 'Proxy logs' 
LOCATION '/user/admin'
tblproperties ("skip.header.line.count"="1");

此查询实际上创建了一个表 proxy_data 并填充了位于指定位置的 csv 文件中的值。

现在,我想将另一组 CSV 中的值附加到同一个表中(它应该跳过 csv 文件中存在的标题)。我检查了各种解决方案,但没有什么能满足我的需要。

4

3 回答 3

2

您可以遵循以下方法:

  1. 使用此属性创建临时表(临时表) - skip.header.line.count=1
  2. 创建具有相同架构的主表(无需skip.header.line.count在此表中使用子句)。
  3. 每次有新文件时,将覆盖加载到临时表中
  4. 然后,将附加登台表的数据加载到主表中。

    create table <my_table_stg>(col1 data_type1, col2, data_type2...)
    row format delimited fields terminated by ','
    tblproperties ("skip.header.line.count"="1");
    
    create table <my_table>(col1 data_type1, col2, data_type2...);
    
    load data inpath '/file/location/my_file.csv' overwrite into table <my_table_stg>;
    
    insert into table <my_table> select * from <my_table_stg>;
    

PS:您的表语法没有row format delimited子句。请确保如上所示添加它

于 2018-03-28T22:46:36.200 回答
2

您可以向表中添加一个属性,该属性将跳过 csv 的第一行。"skip.header.line.count"="1"

在你的情况下,

Alter Table proxy_data SET TBLPROPERTIES ("skip.header.line.count"="1").
于 2018-03-28T11:32:32.100 回答
0

你能试试这个:

hive>  LOAD DATA LOCAL INPATH '/home/yourcsvfile.csv' INTO TABLE proxy_data;
于 2018-03-28T09:41:41.383 回答