com.datasalt.pangool.tuplemr
Class OrderBy

java.lang.Object
  extended by com.datasalt.pangool.tuplemr.OrderBy

public class OrderBy
extends Object

OrderBy is a convenience builder used by TupleMRConfig , similar to Criteria. The main difference is that OrderBy is mutable using the concatenation pattern and allows to specify schemaOrder.

The OrderBy instances are converted to immutable Criteria objects by TupleMRConfig.


Constructor Summary
OrderBy()
           
OrderBy(List<Criteria.SortElement> elements)
           
 
Method Summary
 OrderBy add(String name, Criteria.Order order)
          Adds a new field to order by and its specified order.
 OrderBy add(String name, Criteria.Order order, Criteria.NullOrder nullOrder)
          Adds a new field to order by and its specified order.
 OrderBy add(String name, Criteria.Order order, Criteria.NullOrder nullOrder, org.apache.hadoop.io.RawComparator<?> comparator)
          Same as OrderBy#add(String, Order) but adding the possibility to specify a custom comparator for that field.
 OrderBy addSchemaOrder(Criteria.Order order)
          This method,unlike the traditional OrderBy#add(String, Order, NullOrder, RawComparator) method, adds a symbolic elements to order by.
 boolean containsBeforeSchemaOrder(String field)
          True if field was added before calling #addSchemaOrder(Order)
 boolean containsFieldName(String field)
          True if field was added using #add(String, Order)
 List<Criteria.SortElement> getElements()
          Returns a Criteria.SortElement object for every field added to this builder.
 Criteria.Order getSchemaOrder()
          Gets the schemaOrder if set.
 Integer getSchemaOrderIndex()
          Returns the position in the list where schemaOrder was added using OrderBy#addSchemaOrder(Order)
static OrderBy parse(String orderBy)
          Parse in the form "field1:asc, field2:desc,...,fieldn:asc|null_smallest"
Examples:
"f1,f2,f3"
"f1:asc,f2:desc,f3"
"f1,f2:asc|null_smallest,f3:desc|null_biggest"
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderBy

public OrderBy(List<Criteria.SortElement> elements)

OrderBy

public OrderBy()
Method Detail

parse

public static OrderBy parse(String orderBy)
Parse in the form "field1:asc, field2:desc,...,fieldn:asc|null_smallest"
Examples:
"f1,f2,f3"
"f1:asc,f2:desc,f3"
"f1,f2:asc|null_smallest,f3:desc|null_biggest"


add

public OrderBy add(String name,
                   Criteria.Order order)
Adds a new field to order by and its specified order.
The default @{link NullOrder} used is for nullable fields is @{link NullOrder#NULL_SMALLEST}

Parameters:
name - Field's name
order - Field's order
See Also:
Criteria.Order

add

public OrderBy add(String name,
                   Criteria.Order order,
                   Criteria.NullOrder nullOrder)
Adds a new field to order by and its specified order.

Parameters:
name - Field's name
order - Field's order
nullOrder - Sorting of null values in nullable fields. Criteria.NullOrder.NULL_SMALLEST if you want nulls to be the smallest value or Criteria.NullOrder.NULL_BIGGEST if you want nulls to be the biggest. Ignored if fields are not nullable. Cannot be null.
See Also:
Criteria.Order, Criteria.NullOrder

add

public OrderBy add(String name,
                   Criteria.Order order,
                   Criteria.NullOrder nullOrder,
                   org.apache.hadoop.io.RawComparator<?> comparator)
Same as OrderBy#add(String, Order) but adding the possibility to specify a custom comparator for that field.

Parameters:
name - Field's name
order - Field's order
nullOrder - Sorting of null values in nullable fields. Criteria.NullOrder.NULL_SMALLEST if you want nulls to be the smallest value or Criteria.NullOrder.NULL_BIGGEST if you want nulls to be the biggest. Ignored if fields are not nullable. Cannot be null.
comparator - Custom comparator instance
See Also:
Criteria.Order, Criteria.NullOrder

addSchemaOrder

public OrderBy addSchemaOrder(Criteria.Order order)
This method,unlike the traditional OrderBy#add(String, Order, NullOrder, RawComparator) method, adds a symbolic elements to order by.

This method only works in a multi-schema scenario, and it specifies that tuples will be sorted by their schema,not by a field's name.

Example :
b.addIntermediateSchema(schema1); b.addIntermediateSchema(schema2);
b.setOrderBy(new OrderBy().add("user_id",Order.ASC).addSchemaOrder(Order.DESC));

In the case above, tuples will be first sorted by user_id and then if they compare as equals then tuples from schema2 will sort before those from schema1.

This method must be called just once, and it's not allowed in TupleMRConfigBuilder.setSpecificOrderBy(String, OrderBy)


getElements

public List<Criteria.SortElement> getElements()
Returns a Criteria.SortElement object for every field added to this builder.

See Also:
Criteria.SortElement

getSchemaOrder

public Criteria.Order getSchemaOrder()
Gets the schemaOrder if set.


getSchemaOrderIndex

public Integer getSchemaOrderIndex()
Returns the position in the list where schemaOrder was added using OrderBy#addSchemaOrder(Order)


containsFieldName

public boolean containsFieldName(String field)
True if field was added using #add(String, Order)


containsBeforeSchemaOrder

public boolean containsBeforeSchemaOrder(String field)
True if field was added before calling #addSchemaOrder(Order)


toString

public String toString()
Overrides:
toString in class Object


Copyright © –2014 Datasalt Systems S.L.. All rights reserved.