Pig
  1. Pig
  2. PIG-59

A new "ILLUSTRATE" command which will help people debug their pig programs

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.1.0
    • Component/s: grunt
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      I propose to add a new "ILLUSTRATE" command to Pig, which will help people debug their Pig programs.

      The idea is to select a few example data items, and illustrate how they are transformed by the sequence of Pig commands in the user's program. I have an algorithm that can select an appropriate and concise set of example data items automatically. It does a better job than random sampling would do; for example, random sampling suffers from the drawback that selective operations such as filters or joins can eliminate all the sampled data items, giving you empty results which is of no help in debugging.

      This "ILLUSTRATE" functionality will avoid people having to test their Pig programs on large data sets, which has a long turnaround time and wastes system resources.

      Proposed Implementation:

      I will create a new package called org.apache.pig.exgen, which will contain the aforementioned algorithm. The algorithm uses the "Local" execution operators (it does not run on hadoop), so as to generate illustrative example data in near-real-time for the user.

      For my algorithm to work properly, it needs to trace the "lineage" (sometimes called "provenance") of data items as they flow through the local operator tree corresponding to the user's Pig program. So I will have to add a "lineage tracer" to the Local operators, which maintains a side data structure to represent the lineage, or derivation sequence, among data items. The lineage tracer will be DISABLED BY DEFAULT, so it will not affect normal Pig operation.

      I will add a new method to PigServer called "PigServer.showExamples(LogicalPlan)", which will cause my exgen algorithm to be invoked.

      I will also add a new command to Grunt, called ILLUSTRATE. Syntactically it will work the same way as the STORE command. For example, a user might type:

      grunt> visits = load 'visits.txt' as (user, url, timestamp);
      grunt> recent_visits = filter visits by timestamp >= '20071201';
      grunt> user_visits = group recent_visits by user;
      grunt> num_user_visits = foreach user_visits generate group, COUNT(recent_visits);
      grunt> illustrate num_user_visits

      This would trigger my exgen algorithm, which will display something like:

      visits:
      (Amy, www.cnn.com, 20070218)
      (Fred, www.harvard.edu, 20071204)
      (Amy, www.bbc.com, 20071205)
      (Fred, www.stanford.edu, 20071206)

      recent_visits:
      (Fred, www.harvard.edu, 20071204)
      (Amy, www.bbc.com, 20071205)
      (Fred, www.stanford.edu, 20071206)

      user_visits:
      (Fred,

      { (Fred, www.harvard.edu, 20071204), (Fred, www.stanford.edu, 20071206) }

      )
      (Amy,

      { (Amy, www.bbc.com, 20071205) }

      )

      num_user_visits:
      (Fred, 2)
      (Amy, 1)

      1. displayAlternate.patch
        2 kB
        Shubham Chopra
      2. ExampleGenerator.patch
        116 kB
        Shubham Chopra
      3. ExampleGenerator.patch
        115 kB
        Shubham Chopra
      4. ExampleGenerator.patch
        116 kB
        Shubham Chopra

        Issue Links

          Activity

          Hide
          Shubham Chopra added a comment -

          Patch for the Example Generator. Contains implementation of the example generator algorithms and changes needed in PigHead to get it working.

          Show
          Shubham Chopra added a comment - Patch for the Example Generator. Contains implementation of the example generator algorithms and changes needed in PigHead to get it working.
          Hide
          Shubham Chopra added a comment -

          Patch implementing the above changes attached.

          Show
          Shubham Chopra added a comment - Patch implementing the above changes attached.
          Hide
          Utkarsh Srivastava added a comment -

          Shubham, sorry for the delay in reviewing this. Chris, a TODO item in there for you. Here are my comments on the patch:

          Major comments:

          • Is this patch before or after PIG-32? I guess before. I think you will have to merge the new trunk and generate a new patch.
          • Most of the logic is one monolithic class Exgen.java. Is there some logical way to break out the functionality into smaller classes?
          • I didn't check the functionality of ExGen.java itself. Chris, can you do that? I merely checked for the effects on the current code.
          • POLoad
            Why are the changes not in a if(lineageTracer!=null) block?

          Other minor comments:

          • Test pattern in build.xml:
            Why did you have to change build.xml? The tests should be in the same suite.
          • LineageTracer
            Why is the ASF License removed?
          Show
          Utkarsh Srivastava added a comment - Shubham, sorry for the delay in reviewing this. Chris, a TODO item in there for you. Here are my comments on the patch: Major comments: Is this patch before or after PIG-32 ? I guess before. I think you will have to merge the new trunk and generate a new patch. Most of the logic is one monolithic class Exgen.java. Is there some logical way to break out the functionality into smaller classes? I didn't check the functionality of ExGen.java itself. Chris, can you do that? I merely checked for the effects on the current code. POLoad Why are the changes not in a if(lineageTracer!=null) block? Other minor comments: Test pattern in build.xml: Why did you have to change build.xml? The tests should be in the same suite. LineageTracer Why is the ASF License removed?
          Hide
          Shubham Chopra added a comment -

          Example Generator patch

          Show
          Shubham Chopra added a comment - Example Generator patch
          Hide
          Olga Natkovich added a comment -

          cleared "patch available" flag since the patch needs to be merged with PIG-32 changes

          Show
          Olga Natkovich added a comment - cleared "patch available" flag since the patch needs to be merged with PIG-32 changes
          Hide
          Shubham Chopra added a comment -

          New patch incorporating changes needed by PIG-32

          Show
          Shubham Chopra added a comment - New patch incorporating changes needed by PIG-32
          Hide
          Shubham Chopra added a comment -

          Displays wrong results for scripts which require the updation of the base data multiple times.

          Problem script was
          a = load ... as (x, y);
          b = load ... as (x, y);
          c = cogroup a by x, b by x;
          d = cogroup a by y, b by y;
          e = cogroup c by $0, d by $0;

          This requires the updation of a and b twice. Working on fixing this bug.

          Show
          Shubham Chopra added a comment - Displays wrong results for scripts which require the updation of the base data multiple times. Problem script was a = load ... as (x, y); b = load ... as (x, y); c = cogroup a by x, b by x; d = cogroup a by y, b by y; e = cogroup c by $0, d by $0; This requires the updation of a and b twice. Working on fixing this bug.
          Hide
          Shubham Chopra added a comment - - edited

          Patch with the example generator slightly modified to give complete results with a lower conciseness in those corner cases. Also included some printing functions to display neat tables and abbreviate the data before displaying to avoid a cluttered view.

          Show
          Shubham Chopra added a comment - - edited Patch with the example generator slightly modified to give complete results with a lower conciseness in those corner cases. Also included some printing functions to display neat tables and abbreviate the data before displaying to avoid a cluttered view.
          Hide
          Alan Gates added a comment -

          Shubham,

          I looked over the patch, and it looks good. However, when I tried to apply it to the code to run the tests, it has gotten out of sync in a number of places. Could you please resync it with top of trunk and resubmit the patch. Then I can run the tests on it.

          Thanks.

          Show
          Alan Gates added a comment - Shubham, I looked over the patch, and it looks good. However, when I tried to apply it to the code to run the tests, it has gotten out of sync in a number of places. Could you please resync it with top of trunk and resubmit the patch. Then I can run the tests on it. Thanks.
          Hide
          Shubham Chopra added a comment - - edited

          Patch for the latest trunk. I think there is a bug in grunt. You can't call dump twice after a foreach statement. For eg;
          A = load ..
          B = foreach A generate $0;
          dump B;
          dump B;
          gives the following error;
          2008-04-10 18:34:33,341 [main] ERROR org.apache.pig.tools.grunt.GruntParser - java.io.IOException: Unable to open iterator for alias: b
          at org.apache.pig.impl.util.WrappedIOException.wrap(WrappedIOException.java:16)
          at org.apache.pig.PigServer.openIterator(PigServer.java:335)
          at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:258)
          at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:162)
          at org.apache.pig.tools.grunt.GruntParser.parseContOnError(GruntParser.java:72)
          at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:54)
          at org.apache.pig.Main.main(Main.java:288)
          Caused by: org.apache.pig.backend.executionengine.ExecException: java.lang.NullPointerException
          at org.apache.pig.backend.local.executionengine.LocalExecutionEngine.execute(LocalExecutionEngine.java:141)
          at org.apache.pig.backend.local.executionengine.LocalExecutionEngine.execute(LocalExecutionEngine.java:32)
          at org.apache.pig.PigServer.optimizeAndRunQuery(PigServer.java:405)
          at org.apache.pig.PigServer.openIterator(PigServer.java:324)
          ... 5 more
          Caused by: java.lang.NullPointerException
          at org.apache.pig.impl.eval.GenerateSpec$1.add(GenerateSpec.java:86)
          at org.apache.pig.backend.local.executionengine.POEval.getNext(POEval.java:113)
          at org.apache.pig.backend.local.executionengine.LocalExecutionEngine.execute(LocalExecutionEngine.java:134)
          ... 8 more

          And this is blocking the example generator.

          Show
          Shubham Chopra added a comment - - edited Patch for the latest trunk. I think there is a bug in grunt. You can't call dump twice after a foreach statement. For eg; A = load .. B = foreach A generate $0; dump B; dump B; gives the following error; 2008-04-10 18:34:33,341 [main] ERROR org.apache.pig.tools.grunt.GruntParser - java.io.IOException: Unable to open iterator for alias: b at org.apache.pig.impl.util.WrappedIOException.wrap(WrappedIOException.java:16) at org.apache.pig.PigServer.openIterator(PigServer.java:335) at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:258) at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:162) at org.apache.pig.tools.grunt.GruntParser.parseContOnError(GruntParser.java:72) at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:54) at org.apache.pig.Main.main(Main.java:288) Caused by: org.apache.pig.backend.executionengine.ExecException: java.lang.NullPointerException at org.apache.pig.backend.local.executionengine.LocalExecutionEngine.execute(LocalExecutionEngine.java:141) at org.apache.pig.backend.local.executionengine.LocalExecutionEngine.execute(LocalExecutionEngine.java:32) at org.apache.pig.PigServer.optimizeAndRunQuery(PigServer.java:405) at org.apache.pig.PigServer.openIterator(PigServer.java:324) ... 5 more Caused by: java.lang.NullPointerException at org.apache.pig.impl.eval.GenerateSpec$1.add(GenerateSpec.java:86) at org.apache.pig.backend.local.executionengine.POEval.getNext(POEval.java:113) at org.apache.pig.backend.local.executionengine.LocalExecutionEngine.execute(LocalExecutionEngine.java:134) ... 8 more And this is blocking the example generator.
          Hide
          Shubham Chopra added a comment -

          New patch fixing the bug.

          Show
          Shubham Chopra added a comment - New patch fixing the bug.
          Hide
          Alan Gates added a comment -

          Checked in at revision 647253. Thanks Shubham for all your work on this.

          Show
          Alan Gates added a comment - Checked in at revision 647253. Thanks Shubham for all your work on this.
          Hide
          Shubham Chopra added a comment -

          Patch for using an alternate output display scheme. No data is shortened.

          Show
          Shubham Chopra added a comment - Patch for using an alternate output display scheme. No data is shortened.
          Hide
          Olga Natkovich added a comment -

          Shubham, it would be good to open new issues for bugs/enhancements rather than attaching patches to old issues especially of they are already resolved.

          Show
          Olga Natkovich added a comment - Shubham, it would be good to open new issues for bugs/enhancements rather than attaching patches to old issues especially of they are already resolved.
          Hide
          Olga Natkovich added a comment -

          Sorry, I meant to address my comment to Shubham.

          Show
          Olga Natkovich added a comment - Sorry, I meant to address my comment to Shubham.

            People

            • Assignee:
              Shubham Chopra
              Reporter:
              Shubham Chopra
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development