org.kitesdk.data
Class FieldPartitioner<S,T>

java.lang.Object
  extended by org.kitesdk.data.FieldPartitioner<S,T>
Type Parameters:
S - The type of the source field in the entity. The partition function must accept values of this type.
T - The type of the target field, which is the type of the return value of the partition function.
All Implemented Interfaces:
com.google.common.base.Function<S,T>, Comparator<T>
Direct Known Subclasses:
CalendarFieldPartitioner, DateFormatPartitioner, HashFieldPartitioner, IdentityFieldPartitioner, IntRangeFieldPartitioner, ListFieldPartitioner, RangeFieldPartitioner

@Immutable
public abstract class FieldPartitioner<S,T>
extends Object
implements com.google.common.base.Function<S,T>, Comparator<T>

Partitions values for a named field.

Used by a PartitionStrategy to calculate which partition an entity belongs in, based on the value of a given field, called the source field. A field partitioner can, in some cases, provide meaningful cardinality hints to query systems. A good example of this is a hash partitioner which always knows the number of buckets produced by the function.

Implementations of FieldPartitioner are immutable.

See Also:
PartitionStrategy

Constructor Summary
protected FieldPartitioner(String name, Class<S> sourceType, Class<T> type, int cardinality)
           
protected FieldPartitioner(String sourceName, String name, Class<S> sourceType, Class<T> type, int cardinality)
           
 
Method Summary
abstract  T apply(S value)
           Apply the partition function to the given value.
 int getCardinality()
           
 String getName()
           
 String getSourceName()
           
 Class<S> getSourceType()
           The type of the source field, which is the type of the type expected by the apply function.
 Class<T> getType()
           The type of the target field, which is the type of the return value of the partition function.
abstract  com.google.common.base.Predicate<T> project(com.google.common.base.Predicate<S> predicate)
          Projects a source-data constraint Predicate into the image of the backing partition function.
abstract  T valueFromString(String stringValue)
          Deprecated. will be removed in 0.12.0
 String valueToString(T value)
          Deprecated. will be removed in 0.12.0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.common.base.Function
equals
 
Methods inherited from interface java.util.Comparator
compare, equals
 

Constructor Detail

FieldPartitioner

protected FieldPartitioner(String name,
                           Class<S> sourceType,
                           Class<T> type,
                           int cardinality)

FieldPartitioner

protected FieldPartitioner(String sourceName,
                           String name,
                           Class<S> sourceType,
                           Class<T> type,
                           int cardinality)
Method Detail

getName

public String getName()
Returns:
the name of the partition field. Note that the partition field is derived from getSourceName() and does not appear in the dataset entity.

getSourceName

public String getSourceName()
Returns:
the name of the field from which the partition field is derived.
Since:
0.3.0

getCardinality

public int getCardinality()
Returns:
the number of buckets in the partition.

apply

public abstract T apply(S value)

Apply the partition function to the given value.

The type of value must be compatible with the field partitioner implementation. Normally, this is validated at the time of initial configuration rather than at runtime.

Specified by:
apply in interface com.google.common.base.Function<S,T>

valueFromString

@Deprecated
public abstract T valueFromString(String stringValue)
Deprecated. will be removed in 0.12.0

Retrieve the value for the field from the string representation.

Since:
0.3.0

valueToString

@Deprecated
public String valueToString(T value)
Deprecated. will be removed in 0.12.0

Retrieve the value for the field formatted as a String. By default, this is the object's Object.toString() representation, but some FieldPartitioners may choose to provide a different representation.

Since:
0.4.0

getSourceType

public Class<S> getSourceType()

The type of the source field, which is the type of the type expected by the apply function.

Since:
0.8.0

getType

public Class<T> getType()

The type of the target field, which is the type of the return value of the partition function.

Since:
0.8.0

project

public abstract com.google.common.base.Predicate<T> project(com.google.common.base.Predicate<S> predicate)
Projects a source-data constraint Predicate into the image of the backing partition function. If the function cannot be projected exactly, the resulting predicate must be more permissive than the original predicate.

Since:
0.11.0


Copyright © 2013–2014. All rights reserved.