Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.6.0
    • Fix Version/s: 0.8.0
    • Component/s: tools
    • Labels:
      None

      Description

      Based on this conversation:

      > On Tue, Apr 20, 2010 at 6:34 PM, hc busy <hc.busy@gmail.com> wrote:
      >
      > > What about making them part of the language using symbols?
      > >
      > > instead of
      > >
      > > foreach T generate Tuple($0, $1, $2), Bag($3, $4, $5), $6, $7;
      > >
      > > have language support
      > >
      > > foreach T generate ($0, $1, $2), {$3, $4, $5}, $6, $7;
      > >
      > > or even:
      > >
      > > foreach T generate ($0, $1, $2), {$3, $4, $5}, $6#$7, $8#$9, $10, $11;
      > >
      > >
      > > Is there reason not to do the second or third other than being more
      > > complicated?
      > >
      > > Certainly I'd volunteer to put the top implementation in to the util
      > > package and submit them for builtin's, but the latter syntactic candies
      > > seems more natural..
      > >
      > >
      > >
      > > On Tue, Apr 20, 2010 at 5:24 PM, Alan Gates <gates@yahoo-inc.com> wrote:
      > >
      > >> The grouping package in piggybank is left over from back when Pig
      > allowed
      > >> users to define grouping functions (0.1). Functions like these should
      > go in
      > >> evaluation.util.
      > >>
      > >> However, I'd consider putting these in builtin (in main Pig) instead.
      > >> These are things everyone asks for and they seem like a reasonable
      > addition
      > >> to the core engine. This will be more of a burden to write (as we'll
      > hold
      > >> them to a higher standard) but of more use to people as well.
      > >>
      > >> Alan.
      > >>
      > >>
      > >> On Apr 19, 2010, at 12:53 PM, hc busy wrote:
      > >>
      > >> Some times I wonder... I mean, somebody went to the trouble of making a
      > >>> path
      > >>> called
      > >>>
      > >>> org.apache.pig.piggybank.grouping
      > >>>
      > >>> (where it seems like this code belong), but didn't check in any java
      > code
      > >>> into that package.
      > >>>
      > >>>
      > >>> Any comment about where to put this kind of utility classes?
      > >>>
      > >>>
      > >>>
      > >>> On Mon, Apr 19, 2010 at 12:07 PM, Andrey S <octo47@gmail.com> wrote:
      > >>>
      > >>> 2010/4/19 hc busy <hc.busy@gmail.com>
      > >>>>
      > >>>> That's just the way it is right now, you can't make bags or tuples
      > >>>>> directly... Maybe we should have some UDF's in piggybank for these:
      > >>>>>
      > >>>>> toBag()
      > >>>>> toTuple(); --which is kinda like exec(Tuple in)

      {return in;}

      > >>>>> TupleToBag(); --some times you need it this way for some reason.
      > >>>>>
      > >>>>>
      > >>>>> Ok. I place my current code here, may be later I make a patch (if
      > such
      > >>>> implementation is acceptable of course).
      > >>>>
      > >>>> import org.apache.pig.EvalFunc;
      > >>>> import org.apache.pig.data.BagFactory;
      > >>>> import org.apache.pig.data.DataBag;
      > >>>> import org.apache.pig.data.Tuple;
      > >>>> import org.apache.pig.data.TupleFactory;
      > >>>>
      > >>>> import java.io.IOException;
      > >>>>
      > >>>> /**
      > >>>> * Convert any sequence of fields to bag with specified count of
      > >>>> fields<br>
      > >>>> * Schema: count:int, fld1 [, fld2, fld3, fld4... ].
      > >>>> * Output: count=2, then

      { (fld1, fld2) , (fld3, fld4) ... }

      > >>>> *
      > >>>> * @author astepachev
      > >>>> */
      > >>>> public class ToBag extends EvalFunc<DataBag> {
      > >>>> public BagFactory bagFactory;
      > >>>> public TupleFactory tupleFactory;
      > >>>>
      > >>>> public ToBag()

      { > >>>> bagFactory = BagFactory.getInstance(); > >>>> tupleFactory = TupleFactory.getInstance(); > >>>> }

      > >>>>
      > >>>> @Override
      > >>>> public DataBag exec(Tuple input) throws IOException {
      > >>>> if (input.isNull())
      > >>>> return null;
      > >>>> final DataBag bag = bagFactory.newDefaultBag();
      > >>>> final Integer couter = (Integer) input.get(0);
      > >>>> if (couter == null)
      > >>>> return null;
      > >>>> Tuple tuple = tupleFactory.newTuple();
      > >>>> for (int i = 0; i < input.size() - 1; i++) {
      > >>>> if (i % couter == 0)

      { > >>>> tuple = tupleFactory.newTuple(); > >>>> bag.add(tuple); > >>>> }

      > >>>> tuple.append(input.get(i + 1));
      > >>>> }
      > >>>> return bag;
      > >>>> }
      > >>>> }
      > >>>>
      > >>>> import org.apache.pig.ExecType;
      > >>>> import org.apache.pig.PigServer;
      > >>>> import org.junit.Before;
      > >>>> import org.junit.Test;
      > >>>>
      > >>>> import java.io.IOException;
      > >>>> import java.net.URISyntaxException;
      > >>>> import java.net.URL;
      > >>>>
      > >>>> import static org.junit.Assert.assertTrue;
      > >>>>
      > >>>> /**
      > >>>> * @author astepachev
      > >>>> */
      > >>>> public class ToBagTest {
      > >>>> PigServer pigServer;
      > >>>> URL inputTxt;
      > >>>>
      > >>>> @Before
      > >>>> public void init() throws IOException, URISyntaxException

      { > >>>> pigServer = new PigServer(ExecType.LOCAL); > >>>> inputTxt = > >>>> this.getClass().getResource("bagTest.txt").toURI().toURL(); > >>>> }

      > >>>>
      > >>>> @Test
      > >>>> public void testSimple() throws IOException

      { > >>>> pigServer.registerQuery("a = load '" + inputTxt.toExternalForm() > + > >>>> "' using PigStorage(',') " + > >>>> "as (id:int, a:chararray, b:chararray, c:chararray, > >>>> d:chararray);"); > >>>> pigServer.registerQuery("last = foreach a generate flatten(" + > >>>> ToBag.class.getName() + "(2, id, a, id, b, id, c));"); > >>>> > >>>> pigServer.deleteFile("target/pigtest/func1.txt"); > >>>> pigServer.store("last", "target/pigtest/func1.txt"); > >>>> assertTrue(pigServer.fileSize("target/pigtest/func1.txt") > 0); > >>>> }

      > >>>> }
      > >>>>
      > >>>>
      > >>
      > >
      >

        Issue Links

          Activity

          Hide
          Daniel Lescohier added a comment -

          The Test file in PIG-1385-trunk.patch has a typo: 'org.paache' instead of 'org.apache'.

          +++ contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/util/TestToBagToTuple.java (revision 0)
          @@ -0,0 +1,51 @@
          +package org.paache.pig.piggybank.util;

          Show
          Daniel Lescohier added a comment - The Test file in PIG-1385 -trunk.patch has a typo: 'org.paache' instead of 'org.apache'. +++ contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/util/TestToBagToTuple.java (revision 0) @@ -0,0 +1,51 @@ +package org.paache.pig.piggybank.util;
          Hide
          hc busy added a comment -

          yeah! my first contrib. Thanks, Alan!!

          Show
          hc busy added a comment - yeah! my first contrib. Thanks, Alan!!
          Hide
          Alan Gates added a comment -

          I ran the tests that failed on the last hudson run and they all passed. I also ran the commit tests and piggybank tests. All looked good. Patch checked in. Thanks hc.

          Show
          Alan Gates added a comment - I ran the tests that failed on the last hudson run and they all passed. I also ran the commit tests and piggybank tests. All looked good. Patch checked in. Thanks hc.
          Hide
          hc busy added a comment -

          ok, ok, moving tests to evaluation.util requires that you import the classes under test.

          Here we usually have tests in the same package (but sitting under test/ instead of src/) so we can test package protected methods. Also so we don't have to import the CUT. But other than that, I guess I should follow convention. I agree with these changes.

          Show
          hc busy added a comment - ok, ok, moving tests to evaluation.util requires that you import the classes under test. Here we usually have tests in the same package (but sitting under test/ instead of src/) so we can test package protected methods. Also so we don't have to import the CUT. But other than that, I guess I should follow convention. I agree with these changes.
          Hide
          Alan Gates added a comment -

          I made a few cosmetic changes. I added the license header to each of the three files, changed all the tabs to spaces, and moved the tests to the evaluation.util package under test. Code looks good, tests pass. If you're ok with my changes I'll check it in.

          Show
          Alan Gates added a comment - I made a few cosmetic changes. I added the license header to each of the three files, changed all the tabs to spaces, and moved the tests to the evaluation.util package under test. Code looks good, tests pass. If you're ok with my changes I'll check it in.
          Hide
          Alan Gates added a comment -

          I'll review this.

          Show
          Alan Gates added a comment - I'll review this.
          Hide
          Hadoop QA added a comment -

          -1 overall. Here are the results of testing the latest attachment
          http://issues.apache.org/jira/secure/attachment/12442630/PIG-1385-trunk.patch
          against trunk revision 937095.

          +1 @author. The patch does not contain any @author tags.

          +1 tests included. The patch appears to include 3 new or modified tests.

          +1 javadoc. The javadoc tool did not generate any warning messages.

          +1 javac. The applied patch does not increase the total number of javac compiler warnings.

          +1 findbugs. The patch does not introduce any new Findbugs warnings.

          -1 release audit. The applied patch generated 538 release audit warnings (more than the trunk's current 535 warnings).

          -1 core tests. The patch failed core unit tests.

          +1 contrib tests. The patch passed contrib unit tests.

          Test results: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h7.grid.sp2.yahoo.net/300/testReport/
          Release audit warnings: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h7.grid.sp2.yahoo.net/300/artifact/trunk/patchprocess/releaseAuditDiffWarnings.txt
          Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h7.grid.sp2.yahoo.net/300/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
          Console output: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h7.grid.sp2.yahoo.net/300/console

          This message is automatically generated.

          Show
          Hadoop QA added a comment - -1 overall. Here are the results of testing the latest attachment http://issues.apache.org/jira/secure/attachment/12442630/PIG-1385-trunk.patch against trunk revision 937095. +1 @author. The patch does not contain any @author tags. +1 tests included. The patch appears to include 3 new or modified tests. +1 javadoc. The javadoc tool did not generate any warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. +1 findbugs. The patch does not introduce any new Findbugs warnings. -1 release audit. The applied patch generated 538 release audit warnings (more than the trunk's current 535 warnings). -1 core tests. The patch failed core unit tests. +1 contrib tests. The patch passed contrib unit tests. Test results: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h7.grid.sp2.yahoo.net/300/testReport/ Release audit warnings: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h7.grid.sp2.yahoo.net/300/artifact/trunk/patchprocess/releaseAuditDiffWarnings.txt Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h7.grid.sp2.yahoo.net/300/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Console output: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h7.grid.sp2.yahoo.net/300/console This message is automatically generated.
          Hide
          hc busy added a comment -

          resubmitting patch for the build system to check.

          Show
          hc busy added a comment - resubmitting patch for the build system to check.
          Hide
          hc busy added a comment -

          changed so that the unit test builds and runs.

          Show
          hc busy added a comment - changed so that the unit test builds and runs.
          Hide
          Alan Gates added a comment -

          Functions look good. Javadoc on how the functions should be used (what input they expect and what output they'll produce) should be added so that users can see how to use the functions.

          Show
          Alan Gates added a comment - Functions look good. Javadoc on how the functions should be used (what input they expect and what output they'll produce) should be added so that users can see how to use the functions.
          Hide
          Hadoop QA added a comment -

          -1 overall. Here are the results of testing the latest attachment
          http://issues.apache.org/jira/secure/attachment/12442398/PIG-1385-trunk.patch
          against trunk revision 935968.

          +1 @author. The patch does not contain any @author tags.

          +1 tests included. The patch appears to include 3 new or modified tests.

          +1 javadoc. The javadoc tool did not generate any warning messages.

          +1 javac. The applied patch does not increase the total number of javac compiler warnings.

          +1 findbugs. The patch does not introduce any new Findbugs warnings.

          -1 release audit. The applied patch generated 531 release audit warnings (more than the trunk's current 528 warnings).

          -1 core tests. The patch failed core unit tests.

          +1 contrib tests. The patch passed contrib unit tests.

          Test results: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h8.grid.sp2.yahoo.net/299/testReport/
          Release audit warnings: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h8.grid.sp2.yahoo.net/299/artifact/trunk/patchprocess/releaseAuditDiffWarnings.txt
          Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h8.grid.sp2.yahoo.net/299/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
          Console output: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h8.grid.sp2.yahoo.net/299/console

          This message is automatically generated.

          Show
          Hadoop QA added a comment - -1 overall. Here are the results of testing the latest attachment http://issues.apache.org/jira/secure/attachment/12442398/PIG-1385-trunk.patch against trunk revision 935968. +1 @author. The patch does not contain any @author tags. +1 tests included. The patch appears to include 3 new or modified tests. +1 javadoc. The javadoc tool did not generate any warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. +1 findbugs. The patch does not introduce any new Findbugs warnings. -1 release audit. The applied patch generated 531 release audit warnings (more than the trunk's current 528 warnings). -1 core tests. The patch failed core unit tests. +1 contrib tests. The patch passed contrib unit tests. Test results: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h8.grid.sp2.yahoo.net/299/testReport/ Release audit warnings: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h8.grid.sp2.yahoo.net/299/artifact/trunk/patchprocess/releaseAuditDiffWarnings.txt Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h8.grid.sp2.yahoo.net/299/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Console output: http://hudson.zones.apache.org/hudson/job/Pig-Patch-h8.grid.sp2.yahoo.net/299/console This message is automatically generated.

            People

            • Assignee:
              hc busy
              Reporter:
              hc busy
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development