[ 
https://issues.apache.org/jira/browse/PIG-270?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12614226#action_12614226
 ] 

Daniel Dai commented on PIG-270:
--------------------------------

Here I am addressing syntactic error. Let me elaborate the cause of this 
problem first. 

Pig uses two seperate parser:
1. GruntParser, it will keep track of the line number of the entire Pig 
session/script. It handles dfs commands and other maintenance commands. If 
there is some syntax error in dfs/maintenance commands, GruntParser will throw 
the exception with correct line number. However, if GruntParser detects a pig 
statement(starts with "alias=", "dump", "store into", etc), it extracts this 
statement and pass it into QueryParser, QueryParser will parse it and throw 
exception if there is syntax error.

2. QueryParser take responsibility to parse pig statement. It does not have 
complete line number information, every pig statement starts with line 1. If 
there is a syntax error, QueryParser will throw the exception with wrong line 
number.

There two possible solutions:
1. Capture the exception from QueryParser and interpolate it with correct line 
number
    GruntParser.processPig should be a good place for that. The problem is we 
need to get access to line number which is now encapsulated in 
SimpleCharStream. SimpleCharStream is generated by javacc and it is better not 
to modify it directly. One thing we can do is to tell javacc to use a 
customized CharStream, so we can write CharStream class whatever we want.
Change to make: GruntParser, customized CharStream

2. Pass line number information to QueryParser
    More natual to me but more work to do. First, we need to access line number 
information as in solution 1, modify GruntParser.processPig to pass line number 
all the way down to QueryParser, and we need to change construct of QueryParser 
to pass line number to SimpleCharStream. Then javacc will automatically handle 
the line number information in error message.
Change to make: GruntParser, customized CharStream(for GruntParser), 
LogicalPlanBuilder.parse, construct for QueryParser.jjt

In short, both solutions are not neat but doable, solution 1 is easier but 
solution 2 seems to be more reasonable.

How's other's opinion?

> Show Line Number in Pig Error Messages
> --------------------------------------
>
>                 Key: PIG-270
>                 URL: https://issues.apache.org/jira/browse/PIG-270
>             Project: Pig
>          Issue Type: Improvement
>            Reporter: Amir Youssefi
>
> It will be a great help to users to show A) Line Number B) Actual Line in Pig 
> Error Messages. Currently user has to copy/paste script line by line in Grunt 
> to find out line that ran into a problem. For Grunt we can skip line number. 
> Alternatively, we can assign line numbers in Grunt and show it in command 
> prompt alongside "grunt>".  This could be a separate issue.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to