[
https://issues.apache.org/jira/browse/PIG-1166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12793118#action_12793118
]
Jeff Zhang commented on PIG-1166:
---------------------------------
A better example of illustrating my idea is to build a DataBag.
The current method:
{code}
BagFactory BAGFACTORY = BagFactory.getInstance();
TupleFactory TUPLEFACTORY = TupleFactory.getInstance();
DataBag bag = BAGFACTORY.newDefaultBag();
Tuple tuple_1 = TUPLEFACTORY.newTuple(1);
tuple_1.set(0, "item_1");
bag.add(tuple_1);
Tuple tuple_2 = TUPLEFACTORY.newTuple(1);
tuple_2.set(0, "item_2");
bag.add(tuple_2);
{code}
and if we change the interface, we can write the code as following:
{code}
BagFactory BAGFACTORY = BagFactory.getInstance();
TupleFactory TUPLEFACTORY = TupleFactory.getInstance();
DataBag bag = BAGFACTORY.newDefaultBag();
bag.add(TUPLEFACTORY.newTuple(1).set(0,"item_1")).add(TUPLEFACTORY.newTuple(1).set(0,"item_2"));
{code}
The second piece of code snippet is more readable and concise in my opinion.
> A bit change of the interface of Tuple & DataBag ( make the set and append
> method return this)
> ----------------------------------------------------------------------------------------------
>
> Key: PIG-1166
> URL: https://issues.apache.org/jira/browse/PIG-1166
> Project: Pig
> Issue Type: Improvement
> Reporter: Jeff Zhang
> Priority: Minor
>
> When people write unit test for UDF, they always need to build a tuple or
> bag. If we change the interface of Tuple and DataBag, make the set and
> append method return this, it can decrease the code size. e.g. Now people
> have to write the following code to build a Tuple:
> {code}
> Tuple tuple=TupleFactory.getInstance().newTuple(3);
> tuple.set(0,"item_0");
> tuple.set(1,"item_1");
> tuple.set(2,"item_2");
> {code}
> If we change the interface, make the set and append method return this, we
> can rewrite the above code like this:
> {code}
> Tuple tuple=TupleFactory.getInstance().newTuple(3);
> tuple.set(0,"item_0").set(1,"item_1").set(2,"item_2");
> {code}
> This interface change won't have back compatibility problem and I think
> there's no performance problem too.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.