次の形式でHive QLの「外部テーブルの作成」ステートメントにフィードできる正規表現を探しています
"input.regex"="the regex goes here"
条件は、RegexSerDe が読み取る必要があるファイル内のログが次の形式であることです。
2013-02-12 12:03:22,323 [DEBUG] 2636hd3e-432g-dfg3-dwq3-y4dsfq3ew91b Some message that can contain any special character, including linebreaks. This one does not have a linebreak. It just has spaces on the same line.
2013-02-12 12:03:24,527 [DEBUG] 265y7d3e-432g-dfg3-dwq3-y4dsfq3ew91b Some other message that can contain any special character, including linebreaks. This one does not have one either. It just has spaces on the same line.
2013-02-12 12:03:24,946 [ERROR] 261rtd3e-432g-dfg3-dwq3-y4dsfq3ew91b Some message that can contain any special character, including linebreaks.
This is a special one.
This has a message that is multi-lined.
This is line number 4 of the same log.
Line 5.
2013-02-12 12:03:24,988 [INFO] 2632323e-432g-dfg3-dwq3-y4dsfq3ew91b Another 1-line log
2013-02-12 12:03:25,121 [DEBUG] 263tgd3e-432g-dfg3-dwq3-y4dsfq3ew91b Yet another one line log.
次の外部テーブル作成コードを使用しています。
CREATE EXTERNAL TABLE applogs (logdatetime STRING, logtype STRING, requestid STRING, verbosedata STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES
(
"input.regex" = "(\\A[[0-9:-] ]{19},[0-9]{3}) (\\[[A-Z]*\\]) ([0-9a-z-]*) (.*)?(?=(?:\\A[[0-9:-] ]{19},[0-9]|\\z))",
"output.format.string" = "%1$s \\[%2$s\\] %3$s %4$s"
)
STORED AS TEXTFILE
LOCATION 'hdfs:///logs-application';
つまりね:
各ログのすべての最初の行を取得できます。ただし、複数の行があるログの他の行は対象外です。すべてのリンクを試し、最後に に置き換え\z
、andまたはに置き換えましたが、何も機能しませんでした。output.format.string に何か不足していますか? または、正規表現を適切に使用していませんか?\Z
\A
^
\Z
\z
$
%4$s
正規表現の機能:
最初にタイムスタンプに一致し、次にログタイプ (DEBUG
またはINFO
その他)、次にID
(小文字のアルファベット、数字、およびハイフンの組み合わせ) に続いて、次のタイムスタンプが見つかるまで、または入力の最後が見つかるまで、すべてが続きます。最後のログ エントリと一致します。また、最後に を追加しようとし/m
ましたが、その場合、生成されたテーブルにはすべて NULL 値が含まれます。