对于处理日志,我想使用 Apache Hive regEx serde,但我只找到使用 String 作为表列的数据类型的示例。
现在我的问题是:是否支持基于日期的类型、整数和数组,还是只是字符串?
此示例(和其他示例)仅使用字符串:
CREATE TABLE access_log (
remote_ip STRING,
request_date STRING,
method STRING,
request STRING,
protocol STRING
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
"input.regex" = "([^ ]) . . [([^]]+)] \"([^ ]) ([^ ]) ([^ \"])\" *",
"output.format.string" = "%1$s %2$s %3$s %4$s %5$s"
)
STORED AS TEXTFILE
;
- 参考SERDE的代码:RegexSerDe 代码 http://www.docjar.com/html/api/org/apache/hadoop/hive/contrib/serde2/RegexSerDe.java.html or github - RegexSerDe 代码 https://github.com/apache/hive/blob/trunk/contrib/src/java/org/apache/hadoop/hive/contrib/serde2/RegexSerDe.java,
所有列都必须是 STRING 类型。 ——摘自程序评论
- 如果你想对其进行一些调整,请编写一些自定义 Serde 代码(如果你擅长 java,然后继续)并添加为自定义 Serde jar,如下例所示csv 自定义 Serde https://github.com/ogrodnek/csv-serde/
- 如果不是,则让列类型仅为 STRING,当您想要对任何列进行操作时,请使用 Casting (hive 中的cast() 函数)在查询中。
希望这可以帮助 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)