Interface AccumuloRowSerializer

  • All Known Implementing Classes:
    LexicoderRowSerializer, StringRowSerializer

    public interface AccumuloRowSerializer
    Interface 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:

    1. setRowIdName - Sets the Trino name which is the Accumulo row ID
    2. setRowOnly - True if only the row ID is going to be retrieved, false if more data is necessary.
    3. setMapping - Multiple calls for each Trino column, setting the mapping of Trino column name to Accumulo column family and qualifier
    4. deserialize - Called for each Accumulo entry in the same row. Implements should retrieve the Trino column value from the given key/value pair
    5. get* - Called to retrieve the data type for the given Trino column name
    6. reset - Begins a new Row, serializer is expected to clear any state
    7. If there are more entries left, go back to deserialize, else end!
    See Also:
    LexicoderRowSerializer, StringRowSerializer
    • Method Detail

      • 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 name
        family - Accumulo family
        qualifier - 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 name
        type - 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 set
        type - Array type
        block - 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 set
        value - 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 set
        value - 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 set
        value - 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 set
        value - 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 set
        value - 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 set
        value - 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 set
        value - 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 name
        type - 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 set
        type - Map type
        block - 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 set
        value - 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 set
        value - 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 set
        value - 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 set
        value - 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 set
        value - 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) and getBlockFromMap(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 Trino Type
        value - 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) and getMapFromBlock(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 Trino Type
        value - 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 type
        block - 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 type
        block - 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 array
        array - 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 map
        map - Map of key/value pairs to encode
        Returns:
        Trino Block