Interface AccumuloRowSerializer
-
- All Known Implementing Classes:
LexicoderRowSerializer,StringRowSerializer
public interface AccumuloRowSerializerInterface for deserializing the data in Accumulo into a Trino row.Provides a means for end-users of the connector to customize how the data in an Accumulo row gets serialized and deserialized from/to a Trino row.
The workflow of how this class is called by the Accumulo connector for reading data is as follows:
- setRowIdName - Sets the Trino name which is the Accumulo row ID
- setRowOnly - True if only the row ID is going to be retrieved, false if more data is necessary.
- setMapping - Multiple calls for each Trino column, setting the mapping of Trino column name to Accumulo column family and qualifier
- deserialize - Called for each Accumulo entry in the same row. Implements should retrieve the Trino column value from the given key/value pair
- get* - Called to retrieve the data type for the given Trino column name
- reset - Begins a new Row, serializer is expected to clear any state
- If there are more entries left, go back to deserialize, else end!
- See Also:
LexicoderRowSerializer,StringRowSerializer
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Tdecode(Type type, byte[] value)Generic function to decode the given byte array to a Java object based on the given type.voiddeserialize(Map.Entry<org.apache.accumulo.core.data.Key,org.apache.accumulo.core.data.Value> entry)Deserialize the given Accumulo entry, retrieving data for the Trino column.byte[]encode(Type type, Object value)Encodes a Trino Java object to a byte array based on the given type.BlockgetArray(String name, Type type)Gets the array Block of the given Trino column.static List<Object>getArrayFromBlock(Type elementType, Block block)Given the array element type and Trino Block, decodes the Block into a list of values.static BlockgetBlockFromArray(Type elementType, List<?> array)Encodes the given list into a Block.static BlockgetBlockFromMap(Type mapType, Map<?,?> map)Encodes the given map into a Block.booleangetBoolean(String name)Gets the Boolean value of the given Trino column.bytegetByte(String name)Gets the Byte value of the given Trino column.DategetDate(String name)Gets the Date value of the given Trino column.static AccumuloRowSerializergetDefault()Gets the default AccumuloRowSerializer,LexicoderRowSerializer.doublegetDouble(String name)Gets the Double value of the given Trino column.floatgetFloat(String name)Gets the Float value of the given Trino column.intgetInt(String name)Gets the Integer value of the given Trino column.longgetLong(String name)Gets the Long value of the given Trino column.BlockgetMap(String name, Type type)Gets the Map value of the given Trino column and Map type.static Map<Object,Object>getMapFromBlock(Type type, Block block)Given the map type and Trino Block, decodes the Block into a map of values.shortgetShort(String name)Gets the Short value of the given Trino column.TimegetTime(String name)Gets the Time value of the given Trino column.TimestampgetTimestamp(String name)Gets the Timestamp value of the given Trino column.byte[]getVarbinary(String name)Gets the Varbinary value of the given Trino column.StringgetVarchar(String name)Gets the String value of the given Trino column.booleanisNull(String name)Gets a Boolean value indicating whether or not the Trino column is a null value.static ObjectreadObject(Type type, Block block, int position)Recursive helper function used bygetArrayFromBlock(io.trino.spi.type.Type, io.trino.spi.block.Block)andgetMapFromBlock(io.trino.spi.type.Type, io.trino.spi.block.Block)to decode the Block into a Java type.voidreset()Reset the state of the serializer to prepare for a new set of entries with the same row ID.voidsetArray(org.apache.hadoop.io.Text text, Type type, Block block)Encode the given array Block into the given Text object.voidsetBoolean(org.apache.hadoop.io.Text text, Boolean value)Encode the given Boolean value into the given Text object.voidsetByte(org.apache.hadoop.io.Text text, Byte value)Encode the given Byte value into the given Text object.voidsetDate(org.apache.hadoop.io.Text text, Date value)Encode the given Date value into the given Text object.voidsetDouble(org.apache.hadoop.io.Text text, Double value)Encode the given Double value into the given Text object.voidsetFloat(org.apache.hadoop.io.Text text, Float value)Encode the given Float value into the given Text object.voidsetInt(org.apache.hadoop.io.Text text, Integer value)Encode the given Integer value into the given Text object.voidsetLong(org.apache.hadoop.io.Text text, Long value)Encode the given Long value into the given Text object.voidsetMap(org.apache.hadoop.io.Text text, Type type, Block block)Encode the given map Block into the given Text object.voidsetMapping(String name, String family, String qualifier)Sets the mapping for the Trino column name to Accumulo family and qualifier.voidsetRowIdName(String name)Sets the Trino name which maps to the Accumulo row ID.voidsetRowOnly(boolean rowOnly)Sets a Boolean value indicating whether or not only the row ID is going to be retrieved from the serializer.voidsetShort(org.apache.hadoop.io.Text text, Short value)Encode the given Short value into the given Text object.voidsetTime(org.apache.hadoop.io.Text text, Time value)Encode the given Time value into the given Text object.voidsetTimestamp(org.apache.hadoop.io.Text text, Timestamp value)Encode the given Timestamp value into the given Text object.voidsetVarbinary(org.apache.hadoop.io.Text text, byte[] value)Encode the given byte[] value into the given Text object.voidsetVarchar(org.apache.hadoop.io.Text text, String value)Encode the given String value into the given Text object.static voidwriteObject(BlockBuilder builder, Type type, Object obj)Recursive helper function used bygetBlockFromArray(io.trino.spi.type.Type, java.util.List<?>)andgetBlockFromMap(io.trino.spi.type.Type, java.util.Map<?, ?>)to add the given object to the given block builder.
-
-
-
Method Detail
-
getDefault
static AccumuloRowSerializer getDefault()
Gets the default AccumuloRowSerializer,LexicoderRowSerializer.- Returns:
- Default serializer
-
setRowIdName
void setRowIdName(String name)
Sets the Trino name which maps to the Accumulo row ID.- Parameters:
name- Trino column name
-
setMapping
void setMapping(String name, String family, String qualifier)
Sets the mapping for the Trino column name to Accumulo family and qualifier.- Parameters:
name- Trino namefamily- Accumulo familyqualifier- Accumulo qualifier
-
setRowOnly
void setRowOnly(boolean rowOnly)
Sets a Boolean value indicating whether or not only the row ID is going to be retrieved from the serializer.- Parameters:
rowOnly- True if only the row ID is set, false otherwise
-
reset
void reset()
Reset the state of the serializer to prepare for a new set of entries with the same row ID.
-
deserialize
void deserialize(Map.Entry<org.apache.accumulo.core.data.Key,org.apache.accumulo.core.data.Value> entry)
Deserialize the given Accumulo entry, retrieving data for the Trino column.- Parameters:
entry- Entry to deserialize
-
isNull
boolean isNull(String name)
Gets a Boolean value indicating whether or not the Trino column is a null value.- Parameters:
name- Column name- Returns:
- True if null, false otherwise.
-
getArray
Block getArray(String name, Type type)
Gets the array Block of the given Trino column.- Parameters:
name- Column nametype- Array type- Returns:
- True if null, false otherwise.
-
setArray
void setArray(org.apache.hadoop.io.Text text, Type type, Block block)Encode the given array Block into the given Text object.- Parameters:
text- Text object to settype- Array typeblock- Array block
-
getBoolean
boolean getBoolean(String name)
Gets the Boolean value of the given Trino column.- Parameters:
name- Column name- Returns:
- Boolean value
-
setBoolean
void setBoolean(org.apache.hadoop.io.Text text, Boolean value)Encode the given Boolean value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getByte
byte getByte(String name)
Gets the Byte value of the given Trino column.- Parameters:
name- Column name- Returns:
- Byte value
-
setByte
void setByte(org.apache.hadoop.io.Text text, Byte value)Encode the given Byte value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getDate
Date getDate(String name)
Gets the Date value of the given Trino column.- Parameters:
name- Column name- Returns:
- Date value
-
setDate
void setDate(org.apache.hadoop.io.Text text, Date value)Encode the given Date value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getDouble
double getDouble(String name)
Gets the Double value of the given Trino column.- Parameters:
name- Column name- Returns:
- Double value
-
setDouble
void setDouble(org.apache.hadoop.io.Text text, Double value)Encode the given Double value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getFloat
float getFloat(String name)
Gets the Float value of the given Trino column.- Parameters:
name- Column name- Returns:
- Float value
-
setFloat
void setFloat(org.apache.hadoop.io.Text text, Float value)Encode the given Float value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getInt
int getInt(String name)
Gets the Integer value of the given Trino column.- Parameters:
name- Column name- Returns:
- Integer value
-
setInt
void setInt(org.apache.hadoop.io.Text text, Integer value)Encode the given Integer value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getLong
long getLong(String name)
Gets the Long value of the given Trino column.- Parameters:
name- Column name- Returns:
- Long value
-
setLong
void setLong(org.apache.hadoop.io.Text text, Long value)Encode the given Long value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getMap
Block getMap(String name, Type type)
Gets the Map value of the given Trino column and Map type.- Parameters:
name- Column nametype- Map type- Returns:
- Map value
-
setMap
void setMap(org.apache.hadoop.io.Text text, Type type, Block block)Encode the given map Block into the given Text object.- Parameters:
text- Text object to settype- Map typeblock- Map block
-
getShort
short getShort(String name)
Gets the Short value of the given Trino column.- Parameters:
name- Column name- Returns:
- Short value
-
setShort
void setShort(org.apache.hadoop.io.Text text, Short value)Encode the given Short value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getTime
Time getTime(String name)
Gets the Time value of the given Trino column.- Parameters:
name- Column name- Returns:
- Time value
-
setTime
void setTime(org.apache.hadoop.io.Text text, Time value)Encode the given Time value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getTimestamp
Timestamp getTimestamp(String name)
Gets the Timestamp value of the given Trino column.- Parameters:
name- Column name- Returns:
- Timestamp value
-
setTimestamp
void setTimestamp(org.apache.hadoop.io.Text text, Timestamp value)Encode the given Timestamp value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getVarbinary
byte[] getVarbinary(String name)
Gets the Varbinary value of the given Trino column.- Parameters:
name- Column name- Returns:
- Varbinary value
-
setVarbinary
void setVarbinary(org.apache.hadoop.io.Text text, byte[] value)Encode the given byte[] value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
getVarchar
String getVarchar(String name)
Gets the String value of the given Trino column.- Parameters:
name- Column name- Returns:
- String value
-
setVarchar
void setVarchar(org.apache.hadoop.io.Text text, String value)Encode the given String value into the given Text object.- Parameters:
text- Text object to setvalue- Value to encode
-
encode
byte[] encode(Type type, Object value)
Encodes a Trino Java object to a byte array based on the given type.Java Lists and Maps can be converted to Blocks using
getBlockFromArray(Type, java.util.List)andgetBlockFromMap(Type, Map)Type to Encode Expected Java Object ARRAY io.trino.spi.block.Block BIGINT Integer or Long BOOLEAN Boolean DATE java.sql.Date, Long DOUBLE Double INTEGER Integer Map io.trino.spi.block.Block REAL Float SMALLINT Short TIME java.sql.Time, Long TIMESTAMP java.sql.Timestamp, Long TINYINT Byte VARBINARY io.airlift.slice.Slice or byte[] VARCHAR io.airlift.slice.Slice or String - Parameters:
type- The TrinoTypevalue- The Java object per the table in the method description- Returns:
- Encoded bytes
-
decode
<T> T decode(Type type, byte[] value)
Generic function to decode the given byte array to a Java object based on the given type.Blocks from ARRAY and MAP types can be converted to Java Lists and Maps using
getArrayFromBlock(Type, Block)andgetMapFromBlock(Type, Block)Encoded Type Returned Java Object ARRAY List<?> BIGINT Long BOOLEAN Boolean DATE Long DOUBLE Double Map Map<?,?> REAL Double SMALLINT Long TIME Long TIMESTAMP Long TINYINT Long VARBINARY byte[] VARCHAR String - Type Parameters:
T- The Java type of the object that has been encoded to the given byte array- Parameters:
type- The TrinoTypevalue- Encoded bytes to decode- Returns:
- The Java object per the table in the method description
-
getArrayFromBlock
static List<Object> getArrayFromBlock(Type elementType, Block block)
Given the array element type and Trino Block, decodes the Block into a list of values.- Parameters:
elementType- Array element typeblock- Array block- Returns:
- List of values
-
getMapFromBlock
static Map<Object,Object> getMapFromBlock(Type type, Block block)
Given the map type and Trino Block, decodes the Block into a map of values.- Parameters:
type- Map typeblock- Map block- Returns:
- List of values
-
getBlockFromArray
static Block getBlockFromArray(Type elementType, List<?> array)
Encodes the given list into a Block.- Parameters:
elementType- Element type of the arrayarray- Array of elements to encode- Returns:
- Trino Block
-
getBlockFromMap
static Block getBlockFromMap(Type mapType, Map<?,?> map)
Encodes the given map into a Block.- Parameters:
mapType- Trino type of the mapmap- Map of key/value pairs to encode- Returns:
- Trino Block
-
writeObject
static void writeObject(BlockBuilder builder, Type type, Object obj)
Recursive helper function used bygetBlockFromArray(io.trino.spi.type.Type, java.util.List<?>)andgetBlockFromMap(io.trino.spi.type.Type, java.util.Map<?, ?>)to add the given object to the given block builder. Supports nested complex types!- Parameters:
builder- Block buildertype- Trino typeobj- Object to write to the block builder
-
readObject
static Object readObject(Type type, Block block, int position)
Recursive helper function used bygetArrayFromBlock(io.trino.spi.type.Type, io.trino.spi.block.Block)andgetMapFromBlock(io.trino.spi.type.Type, io.trino.spi.block.Block)to decode the Block into a Java type.- Parameters:
type- Trino typeblock- Block to decodeposition- Position in the block to get- Returns:
- Java object from the Block
-
-