Package com.gpudb
Class Type
- java.lang.Object
-
- com.gpudb.Type
-
- All Implemented Interfaces:
Serializable
public final class Type extends Object implements Serializable
Immutable collection of metadata about a GPUdb type.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classType.ColumnImmutable collection of metadata about a column that is part of a GPUdb type.
-
Constructor Summary
Constructors Constructor Description Type(Type.Column... columns)Creates aTypeobject with the specified column metadata and an empty type label.Type(String typeSchema)Creates aTypeobject with column metadata from an Avro record schema and an empty type label.Type(String label, Type.Column... columns)Creates aTypeobject with the specified metadata.Type(String label, String typeSchema, Map<String,List<String>> properties)Creates aTypeobject with metadata in the format returned from the GPUdb /show/table or /show/types endpoints.Type(String label, List<Type.Column> columns)Creates aTypeobject with the specified metadata.Type(List<Type.Column> columns)Creates aTypeobject with the specified column metadata and an empty type label.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringcreate(GPUdb gpudb)Creates a type in GPUdb based on the metadata in theTypeobject and returns the type ID for reference.booleanequals(Object obj)static TypefromDynamicSchema(String schemaString, ByteBuffer encodedData)Creates aTypeobject with the specified dynamic schema metadata and encoded dynamic table data.static TypefromTable(GPUdb gpudb, String tableName)Creates aTypeobject containing metadata for the GPUdb type of an existing table in GPUdb.static TypefromType(GPUdb gpudb, String typeId)Creates aTypeobject containing metadata for an existing type in GPUdb.Type.ColumngetColumn(int index)Gets the column with the specified index.Type.ColumngetColumn(String name)Gets the column with the specified name.intgetColumnCount()Gets the number of columns.intgetColumnIndex(String name)Gets the index of the column with the specified name.List<Type.Column>getColumns()Gets the list of columns that the type comprises.StringgetLabel()Gets the user-defined description string which can be used to differentiate between data with otherwise identical schemas.org.apache.avro.SchemagetSchema()Gets the Avro record schema for the type.inthashCode()RecordnewInstance()Creates a newRecordbased on the type.StringtoString()
-
-
-
Constructor Detail
-
Type
public Type(Type.Column... columns)
Creates aTypeobject 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 aTypeobject 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 aTypeobject with the specified metadata.- Parameters:
label- a user-defined description string which can be used to differentiate between data with otherwise identical schemascolumns- 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 aTypeobject with the specified metadata.- Parameters:
label- a user-defined description string which can be used to differentiate between data with otherwise identical schemascolumns- the list of columns that the type comprises- Throws:
IllegalArgumentException- if no columns are specified
-
Type
public Type(String typeSchema)
Creates aTypeobject with column metadata from an Avro record schema and an empty type label.- Parameters:
typeSchema- the Avro record schema for the type- Throws:
IllegalArgumentException- iftypeSchemais invalid or contains unsupported field types
-
Type
public Type(String label, String typeSchema, Map<String,List<String>> properties)
Creates aTypeobject 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 schemastypeSchema- the Avro record schema for the typeproperties- an optional map of column names to lists of properties that apply to those columns- Throws:
IllegalArgumentException- iftypeSchemais invalid or contains unsupported field types, or if anypropertiesare invalid
-
-
Method Detail
-
fromTable
public static Type fromTable(GPUdb gpudb, String tableName) throws GPUdbException
Creates aTypeobject 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- theGPUdbinstance from which to obtain the metadatatableName- the name of the table in GPUdb- Returns:
- the created
Typeobject - 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 aTypeobject containing metadata for an existing type in GPUdb. Note that this method makes a request to GPUdb to obtain the metadata.- Parameters:
gpudb- theGPUdbinstance from which to obtain the metadatatypeId- the type ID of the type in GPUdb- Returns:
- the created
Typeobject - 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 aTypeobject with the specified dynamic schema metadata and encoded dynamic table data.- Parameters:
schemaString- a String object containing the dynamic schemaencodedData- the binary encoded data that contains metadata on the dynamic schema- Returns:
- the created
Typeobject - 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 newRecordbased 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 theTypeobject 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- theGPUdbinstance 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
-
-