首页 文章

如何将数据添加到现有的Hive Metastore?

提问于
浏览
0

我在S3中有多个包含.orc文件的子目录 . 我正在尝试创建一个hive Metastore,这样我就可以用Presto / Hive等查询数据 . 数据结构很差(没有一致的分隔符,丑陋的字符等) . 这是一个擦洗过的样本:

1488736466 199.199.199.199 0_b.www.sphericalcow.com.f9b1.qk-g6m6z24tdr.v4.url.name.com TXT IN: NXDOMAIN/0/143
1488736466 6.6.5.4 0.3399.186472.4306.6668.638.cb5a.names-things.update.url.name.com TXT IN: NOERROR/3/306 0\009253\009http://az.blargi.ng/%D3%AB%EF%BF%BD%EF%BF%BD/\009 0\009253\009http://casinoroyal.online/\009 0\009253\009http://d2njbfxlilvpsq.cloudfront.net/b_zq_ym_bangvideo/bangvideo0826.apk\009

我能够使用serde正则表达式创建一个指向其中一个子目录的表,并且字段正确解析,但据我所知,我一次只能加载一个子文件夹 .

如何向现有的hive Metastore添加更多数据?

这是我的hive metastore create语句与regex serde位的示例:

DROP TABLE IF EXISTS test;

CREATE EXTERNAL TABLE test (field1 string, field2 string, field3 string, field4 string)
COMMENT 'fill all the tables with the datas.' 
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' 
  WITH SERDEPROPERTIES (
"input.regex" = "([0-9]{10}) ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) (\\S*) (.*)",
"output.format.string" = "%1$s %2$s %3$s %4$s"
)
STORED AS ORC
LOCATION 's3://path/to/one/of/10/folders/'
tblproperties ("orc.compress" = "SNAPPY", "skip.header.line.count"="2");

select * from test limit 10;

我意识到可能有一个非常简单的解决方案,但我尝试使用INSERT INTO代替CREATE EXTERNAL TABLE,但可以理解的是抱怨输入,我查看了hive和serde文档以获取帮助但是无法找到引用添加到现有商店 .

2 回答

  • 0

    使用分区的可能方案 .

    CREATE EXTERNAL TABLE test (field1 string, field2 string, field3 string, field4 string) 
    partitioned by (mypartcol string)
    ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' 
      WITH SERDEPROPERTIES (
    "input.regex" = "([0-9]{10}) ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) (\\S*) (.*)"
    )
    LOCATION 's3://whatever/as/long/as/it/is/empty'
    tblproperties ("skip.header.line.count"="2");
    

    alter table test add partition (mypartcol='folder 1') location 's3://path/to/1st/of/10/folders/';
    alter table test add partition (mypartcol='folder 2') location 's3://path/to/2nd/of/10/folders/';
    .
    .
    .
    alter table test add partition (mypartcol='folder 10') location 's3://path/to/10th/of/10/folders/';
    
  • 0

    对于@TheProletariat(OP)

    似乎不需要RegexSerDe,因为列是由空格分隔的(' ') .
    注意 tblproperties ("serialization.last.column.takes.rest"="true") 的使用

    create external table test 
    (
        field1 bigint
       ,field2 string
       ,field3 string
       ,field4 string
    )
    row format delimited
    fields terminated by ' '
    tblproperties ("serialization.last.column.takes.rest"="true")
    ;
    

相关问题