Hive - SYSLOG/ERRORLOG 的正则表达式

Hive - Regex for the SYSLOG/ERRORLOG

我想使用 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.

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

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' 不是配置单元 TIMESTAMP 格式,在 DDL 中将其定义为 STRING 并按照此答案进行转换:
  2. 消息在serde中表示为(\w+)组。这是错误的,因为消息包含空格。尝试 (.*?)$ 而不是消息字段的 (\w+)

    试试这个正则表达式:

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

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

还有连字符-如果字符class[方括号]外不需要屏蔽。和点。有特殊含义,字面上用作点时需要屏蔽: