org.apache.hadoop.zebra.pig.comparator
Class ExprUtils

java.lang.Object
  extended by org.apache.hadoop.zebra.pig.comparator.ExprUtils

public class ExprUtils
extends Object


Constructor Summary
ExprUtils()
           
 
Method Summary
static ComparatorExpr bagComparator(int index, ComparatorExpr expr)
          Make a bag comparator expression.
static String exprToString(ComparatorExpr expr)
          Converting an expression to a string.
static ComparatorExpr negationComparator(ComparatorExpr expr)
          Negate comparator
static ComparatorExpr primitiveComparator(int index, int type)
          Comparator for primitive types.
static ComparatorExpr tupleComparator(Collection<? extends ComparatorExpr> exprs)
          Make a Tuple comparator expression.
static ComparatorExpr tupleComparator(ComparatorExpr... exprs)
          Make a Tuple comparator expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExprUtils

public ExprUtils()
Method Detail

bagComparator

public static ComparatorExpr bagComparator(int index,
                                           ComparatorExpr expr)
Make a bag comparator expression.

Parameters:
index - the index of datum in the source tuple that is a DataBag object.
expr - a comparator expression that corresponds to the member tuples in the bag.
Returns:
A comparator expression.

Example: suppose we have tuple schema as follows: Tuple { int a; String b; Bag { Tuple { Bytes c; int d; String e; } } f } We would like to sort by Tuple(b, Bag(Negate(Tuple(e, c)))), we can construct the ComparatorExpr as follows; ComparatorExpr expr = tupleComparator( leafComparator(1, DataType.CHARARRAY), bagComparator(2, negateComparator( tupleComparator( leafCmparator(2, DataType.CHARARRAY), leafComparator(0, DataType.BYTEARRAY)))))


exprToString

public static String exprToString(ComparatorExpr expr)
Converting an expression to a string.

Parameters:
expr -
Returns:
A string representation of the comparator expression.

primitiveComparator

public static ComparatorExpr primitiveComparator(int index,
                                                 int type)
Comparator for primitive types.

Parameters:
index - Index in the source tuple.
type - One of the constants defined in DataType for primitive types.
Returns:
Comparator expression.

negationComparator

public static ComparatorExpr negationComparator(ComparatorExpr expr)
Negate comparator

Parameters:
expr - expression to perform negation on.
Returns:
A comparator expression.

tupleComparator

public static ComparatorExpr tupleComparator(Collection<? extends ComparatorExpr> exprs)
Make a Tuple comparator expression.

Parameters:
exprs - member comparator expressions.
Returns:
A comparator expression.

tupleComparator

public static ComparatorExpr tupleComparator(ComparatorExpr... exprs)
Make a Tuple comparator expression.

Parameters:
exprs - member comparator expressions.
Returns:
A comparator expression.


Copyright © 2007-2012 The Apache Software Foundation