Support Questions
Find answers, ask questions, and share your expertise

mismatched input 'AS' expecting RIGHT_PAREN in Pig

Explorer

Hi,

I want to fetch url ,methods and class from the below line using Pig Script:

Mapped "{[/aLog/transaction],methods=[POST],produces=[application/vnd.app.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity<java.lang.Object> com.fhlb.user.controller.rest.ALogService.aTransactionDetails(com.fhlb.user.beans.TansactionReportRequest,javax.servlet.http.HttpServletRequest) throws com.fhlb.commons.CustomException,java.io.FileNotFoundException

Here is my Pig Script :

extract = FOREACH logs_entry GENERATE FLATTEN(REGEX_EXTRACT_ALL(logmessage,'^(Mapped)\\"(\\{+(\\[+([^/].*)+\\]),methods=(\\[+([A-Z].*)+\\]),produces=(\\[+([^ ].*)+\\])+\\}\\)"\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(throws)\\s+(.*)
AS (t1:chararray,url:chararray,type:chararray,produces:chararray,t2:chararray,t3:chararray,classes:chararray,throw:chararray,exception:chararray);

But I got below error :

ERROR 1200: <line 9, column 229> mismatched input 'AS' expecting RIGHT_PAREN

I am not good at regex so please help me to find out the solution.

Thanks,

4 REPLIES 4

@priyal patel

Your statement has a syntax issue and that is why you are getting the current error. So if you retype your pig script as follows, you won't have the syntax error.

extract = FOREACH a GENERATE FLATTEN(REGEX_EXTRACT_ALL(rec,'^(Mapped)\\"(\\{+(\\[+([^/].*)+\\]),methods=(\\[+([A-Z].*)+\\]),produces=(\\[+([^ ].*)+\\])+\\}\\)"\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(throws)\\s+(.*)')) AS (t1:chararray,url:chararray,type:chararray,produces:chararray,t2:chararray,t3:chararray,classes:chararray,throw:chararray,exception:chararray);

Now, your regex is as is as you mentioned in the question. I need some more info regarding what you want to fetch out of this error message. And then we can work on the desired regex.

Explorer

@Rahul Soni,

Thanks,

Actually its a type mistake.I edited my question and i found that i forgot to close ' ')) '.

I want to fetch following values ,

[/aLog/transaction],POST,[application/vnd.app.v1+json || application/json]

I tried below script,

extract = FOREACH matched GENERATE FLATTEN(REGEX_EXTRACT_ALL(logmessage,'^(\\S+)\\s+"(\\{(\\S+),.*=(.*),.*=(.*)\\})"+\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+).*
(t1:chararray,t2:chararray,t3:chararray,t4:chararray,url:chararray,type:chararray,produces:chararray,t5:chararray,t6:chararray,classes:chararray,throw:chararray,exception:chararray); 

Output :

(Mapped,{[/auditConfirmation/businessDates],methods=[GET],produces=[application/vnd.app.v1+json || application/json]},[/auditConfirmation/businessDates],[GET],[application/vnd.app.v1+json || application/json],on
to,public,java.lang.String,com.fhlb.controllers.rest.auditconfirmation.AuditConfirmationRestService.getCloseOFBusinessDates(java.lang.String),throws,com.fhlb.commons.CustomException)

I fetched the output which i want But i am getting one extra schema.Could you help me with regex which extract only expected output.I want to remove "{[/auditConfirmation/businessDates],methods=[GET],produces=[application/vnd.app.v1+json || application/json]}" from the output.

I got the Expected output using below script :

output = FOREACH extract GENERATE $4 as url,$5 as requesttype,$6 as produces;

Sorry but can you please put the pattern a bit more clearly? A bit hard to understand in the format you mentioned.

Explorer

@Rahul Soni,

Hi,

I edited the comment.Please check it.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.