You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ch...@apache.org on 2013/06/01 22:03:58 UTC
svn commit: r1488584 - in /pig/trunk: CHANGES.txt
src/org/apache/pig/builtin/IN.java
src/org/apache/pig/parser/LogicalPlanGenerator.g
src/org/apache/pig/parser/QueryParser.g
test/org/apache/pig/builtin/TestInUdf.java
Author: cheolsoo
Date: Sat Jun 1 20:03:58 2013
New Revision: 1488584
URL: http://svn.apache.org/r1488584
Log:
PIG-3336: Change IN operator to use or-expressions instead of EvalFunc (cheolsoo)
Removed:
pig/trunk/src/org/apache/pig/builtin/IN.java
pig/trunk/test/org/apache/pig/builtin/TestInUdf.java
Modified:
pig/trunk/CHANGES.txt
pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g
pig/trunk/src/org/apache/pig/parser/QueryParser.g
Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1488584&r1=1488583&r2=1488584&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Sat Jun 1 20:03:58 2013
@@ -28,9 +28,7 @@ PIG-3174: Remove rpm and deb artifacts
IMPROVEMENTS
-PIG-3335: TestErrorHandling.tesNegative7 fails on MR2 (xuefuz)
-
-PIG-3316: Pig failed to interpret DateTime values in some special cases (xuefuz)
+PIG-3336: Change IN operator to use or-expressions instead of EvalFunc (cheolsoo)
PIG-3339: Move pattern compilation in ToDate as a static variable (rohini)
@@ -192,6 +190,10 @@ PIG-3013: BinInterSedes improve chararra
BUG FIXES
+PIG-3335: TestErrorHandling.tesNegative7 fails on MR2 (xuefuz)
+
+PIG-3316: Pig failed to interpret DateTime values in some special cases (xuefuz)
+
PIG-2956: Invalid cache specification for some streaming statement (daijy)
PIG-3310: ImplicitSplitInserter does not generate new uids for nested schema fields, leading to miscomputations (cstenac via daijy)
Modified: pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g?rev=1488584&r1=1488583&r2=1488584&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g Sat Jun 1 20:03:58 2013
@@ -783,13 +783,27 @@ cond[LogicalExpressionPlan exprPlan] ret
in_eval[LogicalExpressionPlan plan] returns[LogicalExpression expr]
@init {
- List<LogicalExpression> args = new ArrayList<LogicalExpression>();
+ List<LogicalExpression> exprs = new ArrayList<LogicalExpression>();
}
- : ^( IN exp1 = expr[$plan] { args.add( $exp1.expr ); } ( exp2 = expr[$plan] { args.add( $exp2.expr ); } )+ )
- {
- SourceLocation loc = new SourceLocation( (PigParserNode)$IN );
- $expr = builder.buildUDF( loc, $plan, "IN", args );
- }
+ : ^( IN ( expr[$plan] { exprs.add($expr.expr); } )+ )
+ {
+ // Convert IN tree to nested or expressions. Please also see
+ // QueryParser.g for how IN tree is constructed from IN expression.
+ EqualExpression firstBoolExpr = new EqualExpression(plan, exprs.get(0), exprs.get(1));
+ if (exprs.size() == 2) {
+ $expr = firstBoolExpr;
+ } else {
+ OrExpression currOrExpr = null;
+ OrExpression prevOrExpr = null;
+ for (int i = 2; i < exprs.size(); i = i + 2) {
+ EqualExpression boolExpr = new EqualExpression(plan, exprs.get(i), exprs.get(i+1));
+ currOrExpr = new OrExpression( $plan, prevOrExpr == null ? firstBoolExpr : prevOrExpr, boolExpr );
+ prevOrExpr = currOrExpr;
+ }
+ $expr = currOrExpr;
+ }
+ $expr.setLocation( new SourceLocation( (PigParserNode)$in_eval.start ) );
+ }
;
func_eval[LogicalExpressionPlan plan] returns[LogicalExpression expr]
Modified: pig/trunk/src/org/apache/pig/parser/QueryParser.g
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/QueryParser.g?rev=1488584&r1=1488583&r2=1488584&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/QueryParser.g (original)
+++ pig/trunk/src/org/apache/pig/parser/QueryParser.g Sat Jun 1 20:03:58 2013
@@ -625,17 +625,36 @@ unary_cond
// brackets, and otherwise we'll assume its an "expr" (and so
// we'll have to strip off the BOOL_COND token the "cast_expr"
// rule added)
- Tree tree = (Tree)retval.getTree();
+ BaseTree tree = (BaseTree) retval.getTree();
if(tree.getType() == BOOL_COND
&& tree.getChild(0).getType() == EXPR_IN_PAREN
&& BOOLEAN_TOKENS.contains(tree.getChild(0).getChild(0).getType())) {
retval.tree = tree.getChild(0).getChild(0);
adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
}
+
+ // For IN expression, we clone the lhs expression (1st child of the
+ // returned tree) and insert it before every rhs expression. For example,
+ //
+ // lhs IN (rhs1, rhs2, rhs3)
+ // =>
+ // ^( IN lhs, rhs1, lhs, rhs2, lhs, rhs3 )
+ //
+ // Note that lhs appears three times at index 0, 2 and 4.
+ //
+ // This is needed because in LogicalPlanGenerator.g, we translate this
+ // tree to nested or expressions, and we need to construct a new
+ // LogicalExpression object per rhs expression.
+ if(tree.getType() == IN) {
+ Tree lhs = tree.getChild(0);
+ for(int i = 2; i < tree.getChildCount(); i = i + 2) {
+ tree.insertChild(i, deepCopy(lhs));
+ }
+ }
}
: exp1 = expr
( ( IS NOT? NULL -> ^( NULL $exp1 NOT? ) )
- | ( IN LEFT_PAREN ( expr ( COMMA expr )* ) RIGHT_PAREN -> ^( IN $exp1 expr+ ) )
+ | ( IN LEFT_PAREN ( expr ( COMMA expr )* ) RIGHT_PAREN -> ^( IN expr+ ) )
| ( rel_op exp2 = expr -> ^( rel_op $exp1 $exp2 ) )
| ( -> ^(BOOL_COND expr) ) )
;