Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Getting the source code

First of all, you need the Pig source code.

Get the source code on your local drive using SVN. Most development is done on the "trunk":

svn checkout http://svn.apache.org/repos/asf/pig/trunk/Image Removed/

or

git clone https://github.com/apache/pig.git

Making Changes

Before you start, send a message to the Pig developer mailing list, or file a bug report in Jira. Describe your proposed changes and check that they fit in with what others are doing and have planned for the project. Be patient, it may take folks a while to understand your requirements.

...

  • All public classes and methods should have informative Javadoc comments.
    • Do not use @author tags.
  • Code should be formatted according to Sun's conventions. We use four spaces (not tabs) for indentation.
  • Contributions should pass existing unit tests.
  • New unit tests should be provided to demonstrate bugs and fixes. JUnit is our test framework:
    • You must implement a class that extends junit.framework.TestCase and whose class whose class name contains Test.
    • If an HDFS cluster and/or a MapReduce cluster is needed by your test, add a field of type MiniCluster MiniGenericCluster to the class and initialize it with a statement like the following (the name of the field is not important). TestAlgebraicEval.java is an example of a test that uses cluster. The test will then run on a cluster created on the local machine.
      MiniCluster MiniGenericCluster cluster = MiniCluster MiniGenericCluster.buildCluster();
  • Define methods within your class and annotate it with @Test, and call JUnit's many assert methods to verify conditions; these methods will be executed when you run ant test.
  • Place your class in the test tree.
  • You can then run all the core unit test with the command ant test-commit. Similarly, you can run a specific unit test with the command ant test -Dtestcase=<ClassName> (For example ant test -Dtestcase=TestPigFile)

...

Make sure that your code introduces no new warnings into the javac compilation.

To compile with Hadoop 2.x:

Code Block
> ant clean jar

The latest Pig codebase only supports Hadoop 2.x which is based on YARN and has separate Resource Manager and Application Masters instead of a single JobTracker that managed both resources (cpu, memory) and running of mapreduce applications.  The exact versions of Hadoop 2.x pig compiles against is configured in ivy/libraries.properties and is usually updated to compile against the latest stable releases.

Please note that in earlier versions Pig used to support older Hadoop versions too, and there was an option to select a certain Hadoop version at build time. If you would like to contribute to older release branches (0.16.0 or below) you will have to set the hadoopversion property. It has 2 values - 20 and 23. -Dhadoopversion=20 which is the default denotes the Hadoop 0.20.x and 1.x releases which are the old versions with JobTracker. The other option, -Dhadoopversion=23 denotes the Hadoop 0.23.x and Hadoop 2.x releases.

Unit Tests

The full suite of pig unit tests has a huge number of tests and there are multiple execution modes - mapreduce (default), spark, tez against which the whole test suite can be run. Since it takes a really long time, you are not expected to run the full suite of tests before submitting the patch. You can just run and verify the test classes affected by your patch and also run test-commit which runs a core set of tests that takes 20 mins. If the fix is specific to a particular execution mode (For eg: tez or spark), run the tests with that exectype. The Pig commit build (https://builds.apache.org/job/Pig-trunk-commit) which runs daily will report any additional failures on the committed patch and a new patch can be submitted that fixes those failures later.  Some of the different test goals are test - full suite of unit tests in mapreduce mode, test-tez - full suite of unit tests in tez mode, test-commit - core set of tests in mapreduce mode.

To run the full suite of testcases in mapreduce mode with Hadoop 2.x. Usually you don't have to run this unless you are doing major changes.

Code Block
> ant clean test

To run the full suite of testcases in tez mode with Hadoop 2.x. This is a shortcut which takes care of adding -Dexectype=tez . Usually you don't have to run this unless you are doing major changes.

Code Block
> ant clean test-tez

To run a single testcase with Hadoop 2.x. You can do this to verify the new tests that you have added or run specific testcases affected by your patch.

Code Block
> ant clean test -Dtestcase=TestEvalPipeline

To run a single testcase with Hadoop 2.x and tez as execution engine

Code Block
> ant clean test -Dtestcase=TestEvalPipeline2 -Dexectype=tez

To run the core set of unit tests follow below steps. Please make sure that all the core unit tests and the tests you wrote succeed before constructing your patch. 

Code Block

> cd trunk
> ant -Djavac.args="-Xlint -Xmaxwarns 1000" clean jar test-commit

This should run in around 20 minutes.

After a while, if you see

Code Block

BUILD SUCCESSFUL

all is ok, but if you see

Code Block

BUILD FAILED

then please examine error messages in build/test and fix things before proceeding.

...

Please also check the javadoc.

Code Block

> ant docdocs
> firefox build/docs/api/index.html

Examine all public classes you've changed to see that documentation is complete and informative. Your patch must not generate any javadoc warnings.

...

Check to see what files you have modified with:

Code Block

svn stat

Add any new files with:

Code Block

svn add src/.../MyNewClass.java

Edit the CHANGES.txt file, adding a description of your change, including the bug number it fixes. If this is a new feature, or other enhancement that doesn't currently have a ticket please create one for it, then use it's number when adding your note to CHANGES.txt. You'll need this ticket to submit your patch anyway.

In order to create a patch, just type:

Code Block

svn diff > myBeautifulPatch.patch

...

  1. Write a shell script that uses 'svn mv' to rename the original files.
  2. Edit files as needed (e.g., to change package names).
  3. Create a patch file with 'svn diff --no-diff-deleted --notice-ancestry'.
  4. Submit both the shell script and the patch file.
    This way other developers can preview your change by running the script and then applying the patch.

Creating a patch with git

If working from a git repo, please be aware the the default diff format will not apply in SVN repos. Please generate patches with the --no-prefix option so they apply cleanly.

Code Block
git diff --no-prefix

h3. Testing

...

a patch (Ignore this section for now)

You can Before submitting your patch, you are encouraged to run the same tools that the automated Hudson Jenkins patch test system will run on your a patch. This enables you to fix problems with your patch before you submit itonce Jenkins or a committer points them out. The test-patch Ant target will run your patch through the same checks that Hudson Jenkins currently does except for executing the core and contrib unit tests.

To use this target, you must run it from a clean workspace (ie svn stat shows no modifications or additions). From your clean workspace, run:

Code Block

ant \
  -Dpatch.file=/patch/to/my.patch \
  -Dforrest.home=/path/to/forrest/ \
  -Dfindbugs.home=/path/to/findbugs \
  -Djava5.home=/patch/to/java5home \
  -Dscratch.dir=/path/to/a/temp/dir \ (optional)
  -Dsvn.cmd=/path/to/subversion/bin/svn \ (optional)
  -Dgrep.cmd=/path/to/grep \ (optional)
  -Dpatch.cmd=/path/to/patch \ (optional)
  test-patch

At the end, you should get a message on your console that is similar to the comment added to Jira by HudsonJenkins' s automated patch test system. The scratch directory (which defaults to the value of ${user.home}/tmp) will contain some output files that will be useful in determining what issues were found in the patch.

...

To apply a patch either you generated or found from JIRA, from the trunk directory you can issue

Code Block

patch -p0 <cool_patch.patch

if you just want to check whether the patch applies you can run patch with --dry-run option

Code Block

patch -p0 --dry-run <cool_patch.patch

...

Finally, patches should be attached to a bug report in Jira via the Attach File link on the jira. Please add a comment that asks for a code review following our code review checklist. Please note that the attachment should be granted license to ASF for inclusion in ASF works (as per the Apache License subsection 5).

When you believe that your patch is ready to be committed, select the Submit Patch link on the issue's Jira. Submitted patches will be automatically tested against "trunk" by WWW Hudson, the lucene project's continuous integration engine Jenkins. Upon test completion, Hudson Jenkins will add a success ("+1") message or failure ("-1") to your bug report in Jira. If your issue contains multiple patch versions, Hudson tests the last patch uploaded. (Note: currently this is not working and developers are running test-patch manually. We hope to have this fixed soon.)

Folks should run 'ant clean test-commit javadoc' before selecting 'Submit Patch'. Tests should all pass. Javadoc should report no warnings or errors. Hudson's tests should only double-check things, and not be used as a primary patch tester, which would create too much noise on the mailing list and in Jira. Submitting patches that fail Hudson testing is frowned on, (unless the failure is not actually due to the patch).

If your patch involves performance optimizations, they should be validated by benchmarks that demonstrate an improvement.

Once a "+1" comment is received from the automated patch testing system and a "+1, code reviewed" comment is received from a code reviewer, a committer should then evaluate it within a few days and either: commit it; or reject it with an explanation. Once your patch has been submitted, a committer should then evaluate it within a few days and either: commit it; or reject it with an explanation.

Please be patient. Committers are busy people too. If no one responds to your patch after a few days, please make friendly reminders. Please incorporate other's suggestions into into your patch if you think they're reasonable. Finally, remember that even a patch that is not committed is useful to the community.

Should your patch earn a -1 on the Hudson Jenkins test, set the issue status to 'Resume Progress', upload a patch with necessary fixes and then set the status to 'Submit Patch' again.

Committers: for non-trivial changes, it is best to you must get another committer to review your patches before commit. Use "Submit Patch" like other contributors, and then wait for a "+1" from another committer before committing. Please also try to frequently review things in the patch queue.

...

Looking for a place to start? A great first place is to peruse the JIRA and find an issue that needs resolved. Especially, here is a list of Jiras marked as "newbie". If you're looking for a bigger project, try ProposedProjectsthe Pig Journal. This gives a list of projects the Pig team would like to see worked on.