Skip to main content
Package com.gpudb

Class Type

java.lang.Object
com.gpudb.Type
All Implemented Interfaces:

public final class Type extends Object implements Serializable
Immutable collection of metadata about a GPUdb type.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Immutable collection of metadata about a column that is part of a GPUdb type.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Type(Type.Column… columns)
    Creates a Type object with the specified column metadata and an empty type label.
    Type(String typeSchema)
    Creates a Type object with column metadata from an Avro record schema and an empty type label.
    Type(String label, Type.Column… columns)
    Creates a Type object with the specified metadata.
    Type(String label, String typeSchema, Map<String,List<String>> properties)
    Creates a Type object with metadata in the format returned from the GPUdb /show/table or /show/types endpoints.
    Type(String label, List<Type.Column> columns)
    Creates a Type object with the specified metadata.
    Type(List<Type.Column> columns)
    Creates a Type object with the specified column metadata and an empty type label.
  • Method Summary

    Modifier and Type
    Method
    Description
    create(GPUdb gpudb)
    Creates a type in GPUdb based on the metadata in the Type object and returns the type ID for reference.
    boolean
     
    static Type
    fromDynamicSchema(String schemaString, ByteBuffer encodedData)
    Creates a Type object with the specified dynamic schema metadata and encoded dynamic table data.
    static Type
    fromTable(GPUdb gpudb, String tableName)
    Creates a Type object containing metadata for the GPUdb type of an existing table in GPUdb.
    static Type
    fromType(GPUdb gpudb, String typeId)
    Creates a Type object containing metadata for an existing type in GPUdb.
    Returns the columns of this type with their Avro base types, as a JSON array of [name, base type] pairs, followed by “nullable” for a nullable column; e.g., [[“id”,“long”],[“name”,“string”,“nullable”]].
    getColumn(int index)
    Gets the column with the specified index.
    Gets the column with the specified name.
    int
    Gets the number of columns.
    int
    Gets the index of the column with the specified name.
    Gets the list of columns that the type comprises.
    Returns the columns of this type with their full types and properties, as a JSON array with one entry per column: the column name, its type, then each of its remaining properties as a separate element; e.g., [[“id”,“long”,“primary_key”],[“code”,“char8”,“primary_key”,“nullable”],[“price”,“decimal(10,2)”]].
    Gets the user-defined description string which can be used to differentiate between data with otherwise identical schemas.
    org.apache.avro.Schema
    Gets the Avro record schema for the type.
    int
     
    Creates a new Record based on the type.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Type

      public Type(Type.Column… columns)
      Creates a Type object with the specified column metadata and an empty type label.
      Parameters:
      columns - the list of columns that the type comprises
      Throws:
      IllegalArgumentException - if no columns are specified
    • Type

      public Type(List<Type.Column> columns)
      Creates a Type object with the specified column metadata and an empty type label.
      Parameters:
      columns - the list of columns that the type comprises
      Throws:
      IllegalArgumentException - if no columns are specified
    • Type

      public Type(String label, Type.Column… columns)
      Creates a Type object with the specified metadata.
      Parameters:
      label - a user-defined description string which can be used to differentiate between data with otherwise identical schemas
      columns - the list of columns that the type comprises
      Throws:
      IllegalArgumentException - if no columns are specified
    • Type

      public Type(String label, List<Type.Column> columns)
      Creates a Type object with the specified metadata.
      Parameters:
      label - a user-defined description string which can be used to differentiate between data with otherwise identical schemas
      columns - the list of columns that the type comprises
      Throws:
      IllegalArgumentException - if no columns are specified
    • Type

      public Type(String typeSchema)
      Creates a Type object with column metadata from an Avro record schema and an empty type label.
      Parameters:
      typeSchema - the Avro record schema for the type
      Throws:
      IllegalArgumentException - if typeSchema is invalid or contains unsupported field types
    • Type

      public Type(String label, String typeSchema, Map<String,List<String>> properties)
      Creates a Type object with metadata in the format returned from the GPUdb /show/table or /show/types endpoints.
      Parameters:
      label - a user-defined description string which can be used to differentiate between data with otherwise identical schemas
      typeSchema - the Avro record schema for the type
      properties - an optional map of column names to lists of properties that apply to those columns
      Throws:
      IllegalArgumentException - if typeSchema is invalid or contains unsupported field types, or if any properties are invalid
  • Method Details

    • fromTable

      public static Type fromTable(GPUdb gpudb, String tableName) throws GPUdbException
      Creates a Type object containing metadata for the GPUdb type of an existing table in GPUdb. Note that this method makes a request to GPUdb to obtain the metadata.
      Parameters:
      gpudb - the GPUdb instance from which to obtain the metadata
      tableName - the name of the table in GPUdb
      Returns:
      the created Type object
      Throws:
      GPUdbException - if the table does not exist or is not homogeneous, or if an error occurs during the request for metadata
    • fromType

      public static Type fromType(GPUdb gpudb, String typeId) throws GPUdbException
      Creates a Type object containing metadata for an existing type in GPUdb. Note that this method makes a request to GPUdb to obtain the metadata.
      Parameters:
      gpudb - the GPUdb instance from which to obtain the metadata
      typeId - the type ID of the type in GPUdb
      Returns:
      the created Type object
      Throws:
      GPUdbException - if the type does not exist or if an error occurs during the request for metadata
    • fromDynamicSchema

      public static Type fromDynamicSchema(String schemaString, ByteBuffer encodedData) throws GPUdbException
      Creates a Type object with the specified dynamic schema metadata and encoded dynamic table data.
      Parameters:
      schemaString - a String object containing the dynamic schema
      encodedData - the binary encoded data that contains metadata on the dynamic schema
      Returns:
      the created Type object
      Throws:
      GPUdbException - if an error occurs during the processing of the metadata
    • getLabel

      public String getLabel()
      Gets the user-defined description string which can be used to differentiate between data with otherwise identical schemas.
      Returns:
      the label string
    • getColumns

      public List<Type.Column> getColumns()
      Gets the list of columns that the type comprises.
      Returns:
      the list of columns that the type comprises
    • getColumn

      public Type.Column getColumn(int index)
      Gets the column with the specified index.
      Parameters:
      index - the column index
      Returns:
      the column with the specified index
      Throws:
      IndexOutOfBoundsException - if the specified index is out of range
    • getColumn

      public Type.Column getColumn(String name)
      Gets the column with the specified name.
      Parameters:
      name - the column name
      Returns:
      the column with the specified name, or null if no such column exists
    • getColumnCount

      public int getColumnCount()
      Gets the number of columns.
      Returns:
      the number of columns
    • getColumnIndex

      public int getColumnIndex(String name)
      Gets the index of the column with the specified name.
      Parameters:
      name - the column name
      Returns:
      the index of the column with the specified name, or -1 if no such column exists
    • getSchema

      public org.apache.avro.Schema getSchema()
      Gets the Avro record schema for the type.
      Returns:
      the Avro record schema for the type
    • newInstance

      public Record newInstance()
      Creates a new Record based on the type.
      Returns:
      a new Record
    • create

      public String create(GPUdb gpudb) throws GPUdbException
      Creates a type in GPUdb based on the metadata in the Type object and returns the type ID for reference. If an identical type already exists in GPUdb, the type ID of the existing type will be returned and no new type will be created.
      Parameters:
      gpudb - the GPUdb instance in which to create the type
      Returns:
      the type ID of the type in GPUdb
      Throws:
      GPUdbException - if an error occurs while creating the type
    • getBaseDefinition

      public String getBaseDefinition()
      Returns the columns of this type with their Avro base types, as a JSON array of [name, base type] pairs, followed by “nullable” for a nullable column; e.g., [[“id”,“long”],[“name”,“string”,“nullable”]]. Other column properties are omitted.
      Returns:
      the base definition of this type
    • getFullDefinition

      public String getFullDefinition()
      Returns the columns of this type with their full types and properties, as a JSON array with one entry per column: the column name, its type, then each of its remaining properties as a separate element; e.g., [[“id”,“long”,“primary_key”],[“code”,“char8”,“primary_key”,“nullable”],[“price”,“decimal(10,2)”]]. This is the column-definition form the server accepts for a request schema, such as the request_schema_str option of /insert/records.

      A column’s type is the property that names it, such as char16, uuid or decimal(10,2), where it has one, and its Avro base type otherwise; the server accepts only one type per column. This Type is not modified.

      Returns:
      the full definition of this type
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object