如何将正则表达式apache日志日期和时间转换为hive

时间:2017-12-16 13:11:18

标签: apache logging hive

我想将我的日志文件放入蜂巢(亚马逊雅典娜)

我的正则表达式没问题,测试人员说:https://regex101.com/r/hF4fP8/11

我的创建表是这样的:

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
WebDriver d = new FirefoxDriver();
d.get("http://www.moneycontrol.com/stocks/advice/display_more.php");    
System.out.println(new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[@class='gray2_11']//a"))).size());

create table语句有效

如果我想选择这个错误发生的表

CREATE EXTERNAL TABLE IF NOT EXISTS webservicelogs.Test15 (
         `day` int,
         `month` string,
         `year` int,
         `hour` int,
         `minute` int,
         `second` int,
         `offset` string 
) 
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES ('input.regex' = '\[(\d{2})\/([a-zA-Z]{3})\/(\d{4}):(\d{2}):(\d{2}):(\d{2})\s(\+\d{4})]' ) 
LOCATION 's3://getag-athena/Test/' 
TBLPROPERTIES ('has_encrypted_data'='false')

您的查询有以下错误:

SELECT * FROM "webservicelogs"."test15" limit 10;

我要解析的日志文件是这样的:

HIVE_CURSOR_ERROR: Number of matching groups doesn't match the number of columns

1 个答案:

答案 0 :(得分:0)

我自己回答并得到了同事的帮助

所有的ses都必须使用另一个反斜杠进行转义,更好:所有转义的特殊字符必须双重转义,这是一个java的东西

(.*)\\s(.*)\\s(.*)\\s\\[(\\d{2})\\/([a-zA-Z]{3})\\/(\\d{4}):(\\d{2}):(\\d{2}):(\\d{2})\\s(\\+\\d{4})].*?$