Suraj,

Your reply  was extremely useful.

I am not only new to Pig/Pigunit also new to Java so the struggle is
compounded.
But based on your code, I was able to get access to the tuples using the
PigServer call.  Since I had created a PigTest object to run the test,  I
did not change any of that just added this to get the alias' data:

Iterator <Tuple> it = PigTest.getPigServer().openIterator("my_script_alias"
);

I was not sure that I had the element and could not find the print output.
So I put a breakpoint and looked at the variable in debugger. There I was
able to confirm that I got the first tuple. I can peel off the tuples so
have control of what I compare now.

Tuple t = it.next()

Thanks so much. Saved my day.

Pat


On Mon, Jul 14, 2014 at 2:17 PM, Suraj Nayak M <[email protected]> wrote:

>  Patricia,
>
> PigUnit is used only for unit testing your Pig code, usually unit testing
> of pig code is done locally. If you run against cluster, PigUnit might not
> be able to compare the large output(if the output is large).
>
> However, below is few pointers which might help you.
>
> I guess, you can take a look at one of my github code at
> https://github.com/surajnayak/pigtutorial/blob/master/ch00/src/test/java/com/pigtutorial/ch00/TestPigCount.java
>
> In the above code, I have used
>
> *Iterator<Tuple> it = pigServer.openIterator("d"); *You can Iterate over
> the it in while loop if you need(like below code) :
> while(it.hasNext()) {
>     Tuple t = it.next();
>     // Get first Val
>     firstVal = t.get(0);
>     // Get second Val
>     second val = t.get(1);
>     // So on..
> }
>
> Or if you have a expected file with you, you can do as I have done in one
> of the github code at
> https://github.com/surajnayak/pigtutorial/blob/master/ch01/src/test/java/com/pigtutorial/ch01/TestFilter.java*.
> *You can take checkout of my public code repository at github available
> at https://github.com/surajnayak/pigtutorial.git
>
> Feel free to repost this email to community if it has helped you. It might
> help someone else someday too :)
>
> --
> Thanks
> Suraj Nayak
>
>
>  On Tuesday 15 July 2014 02:21 AM, Patricia Webster wrote:
>
> Let me post to you first before sending second to the user group.
> getAlias
> The problem is that the assert is testing against a bag - unordered. The
> fear is that if we test on the live cluster the order cannot be guaranteed
> so I was attempting to do something to the result before calling the assert
> method.
>
>  I thought if I could get control of the output, I could sort it (is only
> a few lines) before testing against the expected output.
> No matter what I do, I get a compile error. The method is supposed to
> return an iterator <tuple> but I cannot use it.
>
>  test.runScript();
>
>  Iterator <Tuple> ts = test.getAlias("sq");
>
> (tried to iterate over it.. tried to get its type.. here
>
>  If I put the name of the bag into getAlias it says it is the wrong type.
>
> *- Type mismatch: cannot convert from String[] to Iterator<Tuple>*
>
> If I leave it empty (suppose to pick up the last alias) it compiles but
> errors unable to iterate over a null iterator.
>
> *org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to
> open iterator for alias null*
>
> )
>
>
>  So just going round and round.
>
>
>  Thanks for the reply.
>
>
>
>
> On Mon, Jul 14, 2014 at 12:48 PM, Suraj Nayak M <[email protected]> wrote:
>
>> Patricia,
>>
>> If you can name few of the method names where you have difficulty in
>> understand, community can help(I would help if I know about it or I will
>> let you know how to use). The conversation (on validation) can be made part
>> of API documentation if it improves code readability and usage.
>>
>> --
>> Thanks
>> Suraj Nayak
>>
>>
>> On Monday 14 July 2014 10:47 PM, Patricia Webster wrote:
>>
>>> I really need some better documentation to understand the handful of
>>> methods one can call on in pigtest. Reading the headers is not really
>>> helpful.
>>> For example : "Gets an iterator on the content of one alias ... "
>>>
>>> I am trying to figure out what I have or can control in a pigunit test
>>> outside of checking the returned output.
>>> Is there a place that has some detailed examples and some clear
>>> discussion?
>>>
>>> Thanks
>>>
>>>
>>
>
>

Reply via email to