【问题标题】:Hive with data that does not have a delimiter带有没有分隔符的数据的 Hive
【发布时间】:2017-05-15 19:08:55
【问题描述】:

我在 HDFS 中有一些没有分隔符的数据。也就是说,各个数据字段由它们在行中的位置来标识。

例如,

CountryXTOWNYCRIMEVALUEZ

所以这里的国家是 0 到 7,城镇是 8 到 12,犯罪统计数据是 13 到 23。

有没有办法将这样组织的数据直接导入 Hive?我想一个可行的方法是设计一个划分数据的map reduce作业,但我想知道是否有一个Hive命令可以用来直接导入数据?

【问题讨论】:

    标签: hadoop hive hdfs hiveql


    【解决方案1】:

    RegexSerDe

    create external table mytable 
    ( 
        country         string
       ,town            string
       ,crime_statistic string 
    )
    row format serde 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
    with serdeproperties  
    (
        'input.regex' = '^(.{8})(.{5})(.*)$'
    )
    location '/...location of the data...'
    ;
    

    select * from mytable
    ;
    

    +----------+-------+-----------------+
    | country  | town  | crime_statistic |
    +----------+-------+-----------------+
    | CountryX | TOWNY | CRIMEVALUEZ     |
    +----------+-------+-----------------+
    

    【讨论】:

      猜你喜欢
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      • 1970-01-01
      相关资源
      最近更新 更多