org.apache.hadoop.hbase.coprocessor
Class ColumnInterpreter<T,S,P extends com.google.protobuf.Message,Q extends com.google.protobuf.Message,R extends com.google.protobuf.Message>

java.lang.Object
  extended by org.apache.hadoop.hbase.coprocessor.ColumnInterpreter<T,S,P,Q,R>
Type Parameters:
T - Cell value data type
S - Promoted data type
P - PB message that is used to transport initializer specific bytes
Q - PB message that is used to transport Cell () instance
R - PB message that is used to transport Promoted () instance
Direct Known Subclasses:
BigDecimalColumnInterpreter, DoubleColumnInterpreter, LongColumnInterpreter

@InterfaceAudience.Private
public abstract class ColumnInterpreter<T,S,P extends com.google.protobuf.Message,Q extends com.google.protobuf.Message,R extends com.google.protobuf.Message>
extends Object

Defines how value for specific column is interpreted and provides utility methods like compare, add, multiply etc for them. Takes column family, column qualifier and return the cell value. Its concrete implementation should handle null case gracefully. Refer to LongColumnInterpreter for an example.

Takes two generic parameters and three Message parameters. The cell value type of the interpreter is . During some computations like sum, average, the return type can be different than the cell value data type, for eg, sum of int cell values might overflow in case of a int result, we should use Long for its result. Therefore, this class mandates to use a different (promoted) data type for result of these computations . All computations are performed on the promoted data type . There is a conversion method castToReturnType(Object) which takes a type and returns a type. The AggregateImplementation uses PB messages to initialize the user's ColumnInterpreter implementation, and for sending the responses back to AggregationClient.


Constructor Summary
ColumnInterpreter()
           
 
Method Summary
abstract  S add(S l1, S l2)
           
abstract  T castToCellType(S response)
          The response message comes as type S.
abstract  S castToReturnType(T o)
          provides casting opportunity between the data types.
abstract  int compare(T l1, T l2)
          This takes care if either of arguments are null.
abstract  double divideForAvg(S o, Long l)
          used for computing average of data values.
abstract  T getCellValueFromProto(Q q)
          This method gets the PB message corresponding to the cell type
abstract  T getMaxValue()
          returns the maximum value for this type T
abstract  T getMinValue()
           
abstract  S getPromotedValueFromProto(R r)
          This method gets the promoted type from the proto message
abstract  Q getProtoForCellType(T t)
          This method gets the PB message corresponding to the cell type
abstract  R getProtoForPromotedType(S s)
          This method gets the PB message corresponding to the promoted type
abstract  P getRequestData()
          This method should return any additional data that is needed on the server side to construct the ColumnInterpreter.
 T getValue(byte[] colFamily, byte[] colQualifier, Cell c)
          TODO: when removing getValue(byte[], byte[], KeyValue), this method should be made abstract
 T getValue(byte[] colFamily, byte[] colQualifier, KeyValue kv)
          Deprecated. 
abstract  S increment(S o)
           
abstract  void initialize(P msg)
          This method should initialize any field(s) of the ColumnInterpreter with a parsing of the passed message bytes (used on the server side).
abstract  S multiply(S o1, S o2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColumnInterpreter

public ColumnInterpreter()
Method Detail

getValue

public T getValue(byte[] colFamily,
                  byte[] colQualifier,
                  Cell c)
           throws IOException
TODO: when removing getValue(byte[], byte[], KeyValue), this method should be made abstract

Parameters:
colFamily -
colQualifier -
c -
Returns:
value of type T
Throws:
IOException

getValue

@Deprecated
public T getValue(byte[] colFamily,
                             byte[] colQualifier,
                             KeyValue kv)
           throws IOException
Deprecated. 

This method used to be abstract, and is preserved for compatibility and easy of conversion from 0.94->0.96. Please override getValue(byte[], byte[], Cell) instead.

Throws:
IOException

add

public abstract S add(S l1,
                      S l2)
Parameters:
l1 -
l2 -
Returns:
sum or non null value among (if either of them is null); otherwise returns a null.

getMaxValue

public abstract T getMaxValue()
returns the maximum value for this type T

Returns:
max

getMinValue

public abstract T getMinValue()

multiply

public abstract S multiply(S o1,
                           S o2)
Parameters:
o1 -
o2 -
Returns:
multiplication

increment

public abstract S increment(S o)
Parameters:
o -
Returns:
increment

castToReturnType

public abstract S castToReturnType(T o)
provides casting opportunity between the data types.

Parameters:
o -
Returns:
cast

compare

public abstract int compare(T l1,
                            T l2)
This takes care if either of arguments are null. returns 0 if they are equal or both are null;
  • >0 if l1 > l2 or l1 is not null and l2 is null.
  • < 0 if l1 < l2 or l1 is null and l2 is not null.


divideForAvg

public abstract double divideForAvg(S o,
                                    Long l)
used for computing average of data values. Not providing the divide method that takes two values as it is not needed as of now.

Parameters:
o -
l -
Returns:
Average

getRequestData

public abstract P getRequestData()
This method should return any additional data that is needed on the server side to construct the ColumnInterpreter. The server will pass this to the initialize(P) method. If there is no ColumnInterpreter specific data (for e.g., LongColumnInterpreter) then null should be returned.

Returns:
the PB message

initialize

public abstract void initialize(P msg)
This method should initialize any field(s) of the ColumnInterpreter with a parsing of the passed message bytes (used on the server side).

Parameters:
msg -

getProtoForCellType

public abstract Q getProtoForCellType(T t)
This method gets the PB message corresponding to the cell type

Parameters:
t -
Returns:
the PB message for the cell-type instance

getCellValueFromProto

public abstract T getCellValueFromProto(Q q)
This method gets the PB message corresponding to the cell type

Parameters:
q -
Returns:
the cell-type instance from the PB message

getProtoForPromotedType

public abstract R getProtoForPromotedType(S s)
This method gets the PB message corresponding to the promoted type

Parameters:
s -
Returns:
the PB message for the promoted-type instance

getPromotedValueFromProto

public abstract S getPromotedValueFromProto(R r)
This method gets the promoted type from the proto message

Parameters:
r -
Returns:
the promoted-type instance from the PB message

castToCellType

public abstract T castToCellType(S response)
The response message comes as type S. This will convert/cast it to T. In some sense, performs the opposite of castToReturnType(Object)

Parameters:
response -
Returns:
cast


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.