【问题标题】:Data parsing in HiveHive 中的数据解析
【发布时间】:2017-04-24 17:09:01
【问题描述】:

我有类似的数据

state:us,gallery:45,fin:UN,mode:normal,rate:3346 

作为配置单元表之一中的字符串数据类型。我想提取像

这样的数据
state gallery fin mode    rate
------------------------------
us    45      UN  normal  3346

作为目标表的行。我如何使用 hive 做到这一点

有时需要一个通用的方法来代替逗号 # 可能会出现 那是 state?us#gallery?45#fin?UN#mode?normal#rate?3346

【问题讨论】:

  • 要求的结果不清楚
  • 对不起,我需要我们,45,UN,normal,3346

标签: hadoop hive


【解决方案1】:
with t as (select 'state:us,gallery:45,fin:UN,mode:normal,rate:3346' as mycol)

select  mycol_map['state']      as state
       ,mycol_map['gallery']    as gallery
       ,mycol_map['fin']        as fin
       ,mycol_map['mode']       as mode
       ,mycol_map['rate']       as rate

from   (select  str_to_map(mycol) as mycol_map
        from    t
        ) t

+-------+---------+-----+--------+------+
| state | gallery | fin |  mode  | rate |
+-------+---------+-----+--------+------+
| us    |      45 | UN  | normal | 3346 |
+-------+---------+-----+--------+------+

【讨论】:

  • 需要状态、图库等作为我提到的列和对应的数据。有时用#代替逗号thise
  • @BigD,仍然不清楚。花点时间发布一个包含多行的良好数据样本。使用 ctrl+k 格式化文本
  • 附言。您可以使用网站senseful.github.io/web-tools/text-table 将您的文本格式化为表格。使用制表符分隔的文本。
  • 谢谢@Dudu。我已经编辑了我的问题。我想问的是,如果我有上一部分问题中提到的数据,你的解决方案会起作用吗?
  • 是的,您可以使用除默认值之外的其他分隔符,它会起作用。阅读str_to_mapcwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 2021-12-18
  • 1970-01-01
  • 1970-01-01
  • 2013-06-10
相关资源
最近更新 更多