Hive - 系统日志/错误日志的正则表达式



我想使用Athena查询系统日志(基本上是我的SQL错误日志(。 这是我的示例数据。

2019-09-21T12:19:32.107Z 2019-09-21 12:19:24.17 Server      Buffer pool extension is already disabled. No action is necessary. 
2019-09-21T12:19:32.107Z 2019-09-21 12:19:24.29 Server      InitializeExternalUserGroupSid failed. Implied authentication will be disabled.

所以我创建了一个这样的表:

CREATE EXTERNAL TABLE IF NOT EXISTS bhuvi (
timestamp string,
date string,
time string,
user string,
message stringg
) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
"input.regex" = "(\w+)\s+(.*\-.*\-.*)\s+(\d+:\d+:\d+.\d+)\s+(\w+)\s+(\w+)"
) LOCATION 's3://log/sql_error_log_stream/';

但它没有给出任何结果。有人可以帮我弄清楚吗?

几点观察:

  1. 时间戳'2019-09-21T12:19:32.107Z'不是 hiveTIMESTAMP格式,在 DDL 中将其定义为STRING并像以下答案一样进行转换:https://stackoverflow.com/a/23520257/2700344
  2. Serde 中的消息表示为 (\w+( 组。这是错误的,因为消息包含空格。尝试(.*?)$而不是(\w+)消息字段。

    试试这个正则表达式:

    (\S+)\s+(.*-.*-.*)\s+(\d+:\d+:\d+\.\d+)\s+(\S+)\s+(.*?)$

使用(\S+)- 这意味着除空格之外的所有内容。(\w+)不适用于第一组,因为\w仅匹配任何字母数字字符和下划线,并且第一组(时间戳(还包含-:字符。

如果字符类之外[在方括号中]不需要屏蔽,则连字符-。 和点 . 具有特殊含义,当用作字面上的点时需要屏蔽:https://stackoverflow.com/a/57890202/2700344

最新更新