正則表 SerDe - Amazon Athena

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

正則表 SerDe

正則表達式 SerDe 使用正則表達式(regex)通過將正則表達式組提取到表列中來反序列化數據。

如果資料中的某一列不符合 regex,則該列中的所有欄都會以 NULL 的形式傳回。如果某一列符合 regex 但擁有的群組數量低於預期,則遺失的群組為 NULL。如果資料中的某一列符合 regex 但具有比 regex 中的群組更多的欄,則會忽略額外的欄。

如需詳細資訊,請參閱 Apache Hive 文件 RegexSerDe中的類別

SerDe 名稱

RegexSerDe

程式庫名稱

RegexSerDe

範例

下列範例會使用 CloudFront 記錄檔建立資料表 RegExSerDe。在 s3://athena-examples-myregion/cloudfront/plaintext/ 中,以您執行 Athena 之處的區域識別符 (例如 s3://athena-examples-us-west-1/cloudfront/plaintext/) 取代 myregion

CREATE EXTERNAL TABLE IF NOT EXISTS cloudfront_logs ( `Date` DATE, Time STRING, Location STRING, Bytes INT, RequestIP STRING, Method STRING, Host STRING, Uri STRING, Status INT, Referrer STRING, os STRING, Browser STRING, BrowserVersion STRING ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' WITH SERDEPROPERTIES ( "input.regex" = "^(?!#)([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+([^ ]+)\\s+[^\(]+[\(]([^\;]+).*\%20([^\/]+)[\/](.*)$" ) LOCATION 's3://athena-examples-myregion/cloudfront/plaintext/';