Package com.gpudb

Class Avro


  • public final class Avro
    extends Object
    Utility class containing static methods for encoding and decoding Avro binary objects.
    • Method Detail

      • decode

        public static <T extends org.apache.avro.generic.IndexedRecord> T decode​(T object,
                                                                                 ByteBuffer encodedObject)
                                                                          throws GPUdbException
        Decodes an Avro binary object into a pre-created destination object.
        Type Parameters:
        T - the type of object being decoded
        Parameters:
        object - the destination object
        encodedObject - the Avro binary object
        Returns:
        the destination object (same as object parameter)
        Throws:
        GPUdbException - if a decoding error occurs
      • decode

        public static <T> T decode​(Object typeDescriptor,
                                   ByteBuffer encodedObject)
                            throws GPUdbException
        Decodes an Avro binary object.
        Type Parameters:
        T - the type of object being decoded
        Parameters:
        typeDescriptor - type descriptor for the type of object being decoded
        encodedObject - the Avro binary object
        Returns:
        the decoded object
        Throws:
        IllegalArgumentException - if typeDescriptor is not a Schema, Type, TypeObjectMap, or Class that implements IndexedRecord
        GPUdbException - if a decoding error occurs
        GPUdbRuntimeException - if unable to instantiate the class specified by typeDescriptor
      • decode

        public static <T> List<T> decode​(Object typeDescriptor,
                                         List<ByteBuffer> encodedObjects,
                                         int start,
                                         int count)
                                  throws GPUdbException
        Decodes a homogeneous portion of a list of Avro binary objects.
        Type Parameters:
        T - the type of objects being decoded
        Parameters:
        typeDescriptor - type descriptor for the type of objects being decoded
        encodedObjects - list of Avro binary objects
        start - index of first object within encodedObjects to decode
        count - number of objects within encodedObjects to decode
        Returns:
        list of decoded objects
        Throws:
        IndexOutOfBoundsException - if start is less than zero, count is less than zero, or start plus count exceeds the length of encodedObjects
        IllegalArgumentException - if typeDescriptor is not a Schema, Type, TypeObjectMap, or Class that implements IndexedRecord
        GPUdbException - if a decoding error occurs
        GPUdbRuntimeException - if unable to instantiate the class specified by typeDescriptor
      • decode

        public static <T> List<T> decode​(Object typeDescriptor,
                                         List<ByteBuffer> encodedObjects,
                                         int start,
                                         int count,
                                         int threadCount,
                                         ExecutorService executor)
                                  throws GPUdbException
        Decodes a homogeneous portion of a list of Avro binary objects, optionally using multiple threads, with or without a supplied executor.
        Type Parameters:
        T - the type of objects being decoded
        Parameters:
        typeDescriptor - type descriptor for the type of objects being decoded
        encodedObjects - list of Avro binary objects
        start - index of first object within encodedObjects to decode
        count - number of objects within encodedObjects to decode
        threadCount - number of threads to use for decoding.
        executor - optional executor responsible for managing threads; null to create threads on demand
        Returns:
        list of decoded objects
        Throws:
        IndexOutOfBoundsException - if start is less than zero, count is less than zero, or start plus count exceeds the length of encodedObjects
        IllegalArgumentException - if threadCount is less than one or typeDescriptor is not a Schema, Type, TypeObjectMap, or Class that implements IndexedRecord
        GPUdbException - if a decoding error occurs
        GPUdbRuntimeException - if unable to instantiate the class specified by typeDescriptor
      • decode

        public static <T> List<T> decode​(Object typeDescriptor,
                                         List<ByteBuffer> encodedObjects)
                                  throws GPUdbException
        Decodes a homogeneous list of Avro binary objects.
        Type Parameters:
        T - the type of objects being decoded
        Parameters:
        typeDescriptor - type descriptor for the type of objects being decoded
        encodedObjects - list of Avro binary objects
        Returns:
        list of decoded objects
        Throws:
        IllegalArgumentException - if typeDescriptor is not a Type, a TypeObjectMap, a Schema, or a Class that implements IndexedRecord
        GPUdbException - if a decoding error occurs
        GPUdbRuntimeException - if unable to instantiate the class specified by typeDescriptor
      • decode

        public static <T> List<T> decode​(Object typeDescriptor,
                                         List<ByteBuffer> encodedObjects,
                                         int threadCount,
                                         ExecutorService executor)
                                  throws GPUdbException
        Decodes a homogeneous list of Avro binary objects, optionally using multiple threads and/or a supplied executor.
        Type Parameters:
        T - the type of objects being decoded
        Parameters:
        typeDescriptor - type descriptor for the type of objects being decoded
        encodedObjects - list of Avro binary objects
        threadCount - number of threads to use for decoding.
        executor - optional executor responsible for managing threads; null to create threads on demand
        Returns:
        list of decoded objects
        Throws:
        IllegalArgumentException - if threadCount is less than one or typeDescriptor is not a Type, a TypeObjectMap, a Schema, or a Class that implements IndexedRecord
        GPUdbException - if a decoding error occurs
        GPUdbRuntimeException - if unable to instantiate the class specified by typeDescriptor
      • encode

        public static <T extends org.apache.avro.generic.IndexedRecord> ByteBuffer encode​(T object)
                                                                                   throws GPUdbException
        Encodes an Avro-compatible object into Avro binary format.
        Type Parameters:
        T - the type of object being encoded
        Parameters:
        object - the object to encode
        Returns:
        the encoded object
        Throws:
        GPUdbException - if an encoding error occurs
      • encode

        public static <T> ByteBuffer encode​(TypeObjectMap<T> typeObjectMap,
                                            T object)
                                     throws GPUdbException
        Encodes a non-Avro-compatible object into Avro binary format using the specified type object map.
        Type Parameters:
        T - the type of object being encoded
        Parameters:
        typeObjectMap - the type object map
        object - the object to encode
        Returns:
        the encoded object
        Throws:
        GPUdbException - if an encoding error occurs
      • encode

        public static <T> ArrayList<ByteBuffer> encode​(List<T> objects)
                                                throws GPUdbException
        Encodes a list of Avro-compatible objects into Avro binary format.
        Type Parameters:
        T - the type of objects being encoded
        Parameters:
        objects - list of objects to encode
        Returns:
        list of encoded objects
        Throws:
        GPUdbException - if an encoding error occurs