【问题标题】:How to specify a STRING as a delimiter in HIVE table creation如何在 HIVE 表创建中指定 STRING 作为分隔符
【发布时间】:2012-12-17 13:07:14
【问题描述】:

我的数据如下:

a||b||c

要获取数据,我的 create table 语句是:

创建表

(col1 字符串,

col2 字符串,

col3 字符串)

以“||”结尾的行格式分隔字段;

但是这里需要'|'作为分隔符而不是“||”。

谁能帮我解决这个问题?

【问题讨论】:

标签: hive delimiter


【解决方案1】:

在处理多字符分隔符字符串时,您可以使用RegexSerDe

create table mytable (
  col1 string,
  col2 string,
  col3 string
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
"input.regex" = "^([^\\|]+)\\|\\|([^\\|]+)\\|\\|([^\\|]+)$",
"output.format.string" = "%1$s %2$s %3$s")
STORED AS TEXTFILE
LOCATION '/path/to/data';

注意:优化正则表达式以满足您的需求

【讨论】:

    猜你喜欢
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    相关资源
    最近更新 更多