Package org.voltdb

Enum Class VoltType

All Implemented Interfaces:
Serializable, Comparable<VoltType>, Constable

public enum VoltType extends Enum<VoltType>
Represents a type for a VoltTable column or a SQLStmt parameter. Note that types in the database don't map 1-1 with types in the Java Stored Procedure API. For example, VARBINARY has no equivalent java class -- just byte[]. TIMESTAMP corresponds "best" to VoltDB.TimeStampType but also, conveniently, to java.sql.Types.TIMESTAMP.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Support class to represent optional value length variability.

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    8-byte signed 2s-complement long.
    Boolean type.
    4-byte long value representing DATE
    Fixed precision=38, scale=12 storing sign and null-status in a preceding byte
    8-bytes in IEEE 754 "double format".
    Geography type, for geographical objects (polygons, etc)
    Point type, for a geographical point (long, lat)
    Special purpose internal type to describe expectations for parameters to statements that contain syntax like " integer_expr IN ? ".
    Special purpose internal type to describe expectations for parameters to statements that contain syntax like " varchar_expr IN ? ".
    4-byte signed 2s-complement integer.
    Used for uninitialized types in some places.
    Used to type java null values that have no type.
    Used for some literal constants parsed by our SQL parser.
    2-byte signed 2s-complement short.
    UTF-8 string with up to 32K chars.
    8-byte long value representing microseconds after the epoch.
    1-byte signed 2s-complement byte.
    Array of bytes of variable length
    VoltTable type for Procedure parameters
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Size in bytes of the maximum length for a VoltDB field value, presumably a STRING or VARBINARY
    static final int
    Size in characters of the maximum length for a VoltDB field value, using a worst-case estimate of 4 bytes per character
    static final long
    Null value for BIGINT.
    static final org.voltdb.VoltType.NullDateSigil
    Null value for DATE.
    static final org.voltdb.VoltType.NullDecimalSigil
    Null value for DECIMAL.
    static final double
    Null value for FLOAT.
    static final org.voltdb.VoltType.NullGeographySigil
    Null value for GEOGRAPHY.
    static final int
    Null value for INTEGER.
    static final org.voltdb.VoltType.NullPointSigil
    Null value for GEOGRAPHY_POINT.
    static final short
    Null value for SMALLINT.
    static final int
    Length value for a null string.
    static final org.voltdb.VoltType.NullStringOrVarbinarySigil
    Null value for STRING or VARBINARY.
    static final org.voltdb.VoltType.NullTimestampSigil
    Null value for TIMESTAMP.
    static final byte
    Null value for TINYINT.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    acceptsArray(Class<?> arrayArgClass)
    Most VoltTypes are not compatible with an array-typed value.
    bytesToValue(byte[] value)
    Converts a byte array with type back to the original partition value.
    boolean
    Indicate whether a value can be assigned to this type without loss of range or precision, important for index key and partition key initialization.
    static Class<?>
    classFromByteValue(byte value)
    Return the java class that is matched to the given value.
    Return the java class that is matched to a given VoltType.
    Decode a on object of this type from buffer
    int
    The size specifier for columns with a variable-length type is optional in a CREATE TABLE or ALTER TABLE statement.
    static VoltType
    get(byte val)
    Statically create an enum value from the corresponding byte.
    For JDBC, the name(s) of any type-specific parameter(s), e.g.
    Get the type that will be returned by JDBC's ResultSet.getObject(), which usually corresponds to to VoltTable.get(), except for timestamps.
    int
    Get the java.sql.Types type of this type.
    int
    Get the number of bytes required to store the fixed length type.
    int
    Get the number of bytes required to store the fixed length type.
    For JDBC, returns the prefix (if any, otherwise null) used with SQL literal constants of this type.
    For JDBC, returns the suffix (if any, otherwise null) used with SQL literal constants of this type.
    Non-integer numeric VoltTypes must override this method.
    int
    Get the maximum number of bytes required to store the type
    Returns the maximum possible value for a numeric type, as a string.
    Non-integer numeric VoltTypes must override this method.
    int
    Get the minimum number of bytes required to store the type
    Returns a string representing the most compatible Java class name corresponding to this VoltType.
    Return the name of this type as a string.
    int
    VoltDB treats nullability as orthogonal to type, so all types are nullable.
    Get a value representing whichever null value is appropriate for the current VoltType enum.
    int
    Returns the standard JDBC 'searchable' attribute.
    char
    Get a char that uniquely identifies a type.
    Returns precision and radix of this type.
    byte
    Gets the byte that corresponds to the VoltType (for serialization).
    static String
    String representation of MAX_VALUE_LENGTH.
    boolean
    Is this type an integer type? True for TINYINT, SMALLINT, INTEGER, BIGINT.
    static boolean
    isAvroRecord(Class<?> clazz)
    Tests whether a specified class is an Avro data record (a subclass of the generic Avro record class).
    boolean
    Is this type an integer type in the EE? True for TINYINT, SMALLINT, INTEGER, BIGINT and TIMESTAMP.
    boolean
    Individual VoltTypes like String can override to enable this functionality.
    boolean
    Is the type a number and is it an exact value (no rounding errors)?
    boolean
    VoltTypes for indexable non-numeric values must override.
    boolean
    Is this type visible to JDBC
    boolean
    Tests whether this Volt type is numeric.
    boolean
    VoltTypes with special restrictions about uniqueness support must override.
    Numeric types are all signed types, so return false.
    boolean
    Tests whether this type is a variable-length type.
    static boolean
    Tests whether a supplied value is the null value for this Volt type.
    Get the corresponding SQL type as for a given VoltType enum.
    Return the string representation of this type.
    static VoltType
    Ascertain the most appropriate VoltType given a java class.
    static VoltType
    Ascertain the most appropriate VoltType given a java object.
    static VoltType
    Converts string representations to an enum value.
    static VoltType
    Returns the enum constant of this class with the specified name.
    static VoltType[]
    Returns an array containing the constants of this enum class, in the order they are declared.
    static byte[]
    Converts the object into bytes for hashing.
    Return the java class that is matched to a given VoltType.

    Methods inherited from class java.lang.Enum

    compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, valueOf

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • INVALID

      public static final VoltType INVALID
      Used for uninitialized types in some places. Not a valid value for actual user data.
    • NULL

      public static final VoltType NULL
      Used to type java null values that have no type. Not a valid value for actual user data.
    • NUMERIC

      public static final VoltType NUMERIC
      Used for some literal constants parsed by our SQL parser. Not a valid value for actual user data. See DECIMAL for decimal type.
    • TINYINT

      public static final VoltType TINYINT
      1-byte signed 2s-complement byte. Lowest value means NULL in the database.
    • SMALLINT

      public static final VoltType SMALLINT
      2-byte signed 2s-complement short. Lowest value means NULL in the database.
    • INTEGER

      public static final VoltType INTEGER
      4-byte signed 2s-complement integer. Lowest value means NULL in the database.
    • BIGINT

      public static final VoltType BIGINT
      8-byte signed 2s-complement long. Lowest value means NULL in the database.
    • INLIST_OF_BIGINT

      public static final VoltType INLIST_OF_BIGINT
      Special purpose internal type to describe expectations for parameters to statements that contain syntax like " integer_expr IN ? ". This type most commonly occurs as an expected parameter type for such statements. It is not expected to ever be used as a VoltTable column type.
    • FLOAT

      public static final VoltType FLOAT
      8-bytes in IEEE 754 "double format". Some NaN values may represent NULL in the database (TBD).
    • STRING

      public static final VoltType STRING
      UTF-8 string with up to 32K chars. The database supports char arrays and varchars but the API uses strings.
    • INLIST_OF_STRING

      public static final VoltType INLIST_OF_STRING
      Special purpose internal type to describe expectations for parameters to statements that contain syntax like " varchar_expr IN ? ". This type most commonly occurs as an expected parameter type for such statements. It is not expected to ever be used as a VoltTable column type.
    • TIMESTAMP

      public static final VoltType TIMESTAMP
      8-byte long value representing microseconds after the epoch. The epoch is Jan. 1 1970 00:00:00 GMT. Negative values represent time before the epoch. This covers roughly 4000BC to 8000AD.
    • DATE

      public static final VoltType DATE
      4-byte long value representing DATE
    • VOLTTABLE

      public static final VoltType VOLTTABLE
      VoltTable type for Procedure parameters
    • DECIMAL

      public static final VoltType DECIMAL
      Fixed precision=38, scale=12 storing sign and null-status in a preceding byte
    • BOOLEAN

      public static final VoltType BOOLEAN
      Boolean type. Not (yet) a valid value for actual user data.
    • VARBINARY

      public static final VoltType VARBINARY
      Array of bytes of variable length
    • GEOGRAPHY_POINT

      public static final VoltType GEOGRAPHY_POINT
      Point type, for a geographical point (long, lat)
    • GEOGRAPHY

      public static final VoltType GEOGRAPHY
      Geography type, for geographical objects (polygons, etc)
  • Field Details

    • MAX_VALUE_LENGTH

      public static final int MAX_VALUE_LENGTH
      Size in bytes of the maximum length for a VoltDB field value, presumably a STRING or VARBINARY
      See Also:
    • MAX_VALUE_LENGTH_IN_CHARACTERS

      public static final int MAX_VALUE_LENGTH_IN_CHARACTERS
      Size in characters of the maximum length for a VoltDB field value, using a worst-case estimate of 4 bytes per character
      See Also:
    • NULL_STRING_LENGTH

      public static final int NULL_STRING_LENGTH
      Length value for a null string.
      See Also:
    • NULL_TINYINT

      public static final byte NULL_TINYINT
      Null value for TINYINT.
      See Also:
    • NULL_SMALLINT

      public static final short NULL_SMALLINT
      Null value for SMALLINT.
      See Also:
    • NULL_INTEGER

      public static final int NULL_INTEGER
      Null value for INTEGER.
      See Also:
    • NULL_BIGINT

      public static final long NULL_BIGINT
      Null value for BIGINT.
      See Also:
    • NULL_FLOAT

      public static final double NULL_FLOAT
      Null value for FLOAT.
      See Also:
    • NULL_TIMESTAMP

      public static final org.voltdb.VoltType.NullTimestampSigil NULL_TIMESTAMP
      Null value for TIMESTAMP.
    • NULL_DATE

      public static final org.voltdb.VoltType.NullDateSigil NULL_DATE
      Null value for DATE.
    • NULL_STRING_OR_VARBINARY

      public static final org.voltdb.VoltType.NullStringOrVarbinarySigil NULL_STRING_OR_VARBINARY
      Null value for STRING or VARBINARY.
    • NULL_DECIMAL

      public static final org.voltdb.VoltType.NullDecimalSigil NULL_DECIMAL
      Null value for DECIMAL.
    • NULL_POINT

      public static final org.voltdb.VoltType.NullPointSigil NULL_POINT
      Null value for GEOGRAPHY_POINT.
    • NULL_GEOGRAPHY

      public static final org.voltdb.VoltType.NullGeographySigil NULL_GEOGRAPHY
      Null value for GEOGRAPHY.
  • Method Details

    • values

      public static VoltType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static VoltType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • isAvroRecord

      public static boolean isAvroRecord(Class<?> clazz)
      Tests whether a specified class is an Avro data record (a subclass of the generic Avro record class).
      Parameters:
      clazz - the class to test
      Returns:
      true if clazz is the class of an Avro record
    • humanReadableSize

      public static String humanReadableSize(int size)
      String representation of MAX_VALUE_LENGTH.
      Parameters:
      size - The size you want to represent in human readable string.
      Returns:
      String representation of Size passed in.
    • getValue

      public byte getValue()
      Gets the byte that corresponds to the VoltType (for serialization).
      Returns:
      A byte representing the VoltType
    • classFromType

      public Class<?> classFromType()
      Return the java class that is matched to a given VoltType.
      Returns:
      A java class object.
      Throws:
      RuntimeException - if a type doesn't have an associated class, such as INVALID.
      See Also:
    • classFromByteValue

      public static Class<?> classFromByteValue(byte value)
      Return the java class that is matched to the given value.
      Parameters:
      value - of a VoltType as returned by getValue()
      Returns:
      The java class.
    • vectorClassFromType

      public Class<?> vectorClassFromType()
      Return the java class that is matched to a given VoltType.
      Returns:
      A java class object.
      Throws:
      RuntimeException - if a type doesn't have an associated class, such as INVALID.
      See Also:
    • get

      public static VoltType get(byte val)
      Statically create an enum value from the corresponding byte.
      Parameters:
      val - A byte representing an enum value
      Returns:
      The appropriate enum value
    • typeFromString

      public static VoltType typeFromString(String str)
      Converts string representations to an enum value.
      Parameters:
      str - A string in the form "TYPENAME" or "VoltType.TYPENAME", e.g. "BIGINT" or "VoltType.VARCHAR"
      Returns:
      One of the valid instances of VoltType
    • typeFromObject

      public static VoltType typeFromObject(Object obj)
      Ascertain the most appropriate VoltType given a java object.
      Parameters:
      obj - The java object to type.
      Returns:
      A VoltType.
      Throws:
      org.voltdb.VoltTypeException - if none applies.
      See Also:
    • typeFromClass

      public static VoltType typeFromClass(Class<?> cls)
      Ascertain the most appropriate VoltType given a java class.
      Parameters:
      cls - The java class to type.
      Returns:
      A VoltType.
      Throws:
      org.voltdb.VoltTypeException - if none applies.
      See Also:
    • toString

      public String toString()
      Return the string representation of this type. Note that VoltType.typeFromString(voltTypeInstance.toString) == voltTypeInstance.
      Overrides:
      toString in class Enum<VoltType>
      Returns:
      The string representation of this type.
    • getName

      public String getName()
      Return the name of this type as a string.
      Returns:
      the name of the type
    • isVariableLength

      public boolean isVariableLength()
      Tests whether this type is a variable-length type.
      Returns:
      true if variable length, false if fixed length
    • getLengthInBytesForFixedTypes

      public int getLengthInBytesForFixedTypes()
      Get the number of bytes required to store the fixed length type. Variable-length types will throw a RuntimeException.
      Returns:
      An integer value representing a number of bytes.
    • getLengthInBytesForFixedTypesWithoutCheck

      public int getLengthInBytesForFixedTypesWithoutCheck()
      Get the number of bytes required to store the fixed length type. Variable-length types will return -1.
      Returns:
      An integer value representing a number of bytes.
    • getMinLengthInBytes

      public int getMinLengthInBytes()
      Get the minimum number of bytes required to store the type
      Returns:
      An integer value representing a number of bytes.
    • getMaxLengthInBytes

      public int getMaxLengthInBytes()
      Get the maximum number of bytes required to store the type
      Returns:
      An integer value representing a number of bytes.
    • getLiteralPrefix

      public String getLiteralPrefix()
      For JDBC, returns the prefix (if any, otherwise null) used with SQL literal constants of this type. Individual VoltTypes can override to enable this, typically to return a single quote.
      Returns:
      null, or, if overridden for a type, the prefix string.
    • getLiteralSuffix

      public String getLiteralSuffix()
      For JDBC, returns the suffix (if any, otherwise null) used with SQL literal constants of this type. Individual VoltTypes can override to enable this, typically to return a single quote.
      Returns:
      null, or, if overridden for a type, the suffix string
    • getCreateParams

      public String getCreateParams()
      For JDBC, the name(s) of any type-specific parameter(s), e.g. "max_length" used when defining sql columns of this type. FUTURE?: It's not clear what format the JDBC would expect if there were more than one -- maybe comma separated?
      Returns:
      null for fixed-length types, usually "max_length" for variable length type
    • isCaseSensitive

      public boolean isCaseSensitive()
      Individual VoltTypes like String can override to enable this functionality. Normally, other types ignore case when expressed as strings, like in hex values for varbinary, or wkt values for geo types.
      Returns:
      false unless overridden for a case sensitivite type like String
    • getMinimumScale

      public Integer getMinimumScale()
      Non-integer numeric VoltTypes must override this method.
      Returns:
      0 for integer types, null for non-numeric, or some other value if overridden for a specific type like DECIMAL
    • getMaximumScale

      public Integer getMaximumScale()
      Non-integer numeric VoltTypes must override this method.
      Returns:
      0 for integer types, null for non-numeric, or some other value if overridden for a specific type like DECIMAL
    • isIndexable

      public boolean isIndexable()
      VoltTypes for indexable non-numeric values must override.
      Returns:
      true if the type is supported by VoltDB indexes
    • isUniqueIndexable

      public boolean isUniqueIndexable()
      VoltTypes with special restrictions about uniqueness support must override.
      Returns:
      true if the type is supported by VoltDB (assume)unique indexes
    • acceptsArray

      public boolean acceptsArray(Class<?> arrayArgClass)
      Most VoltTypes are not compatible with an array-typed value.
      Parameters:
      arrayArgClass - a java array class like byte[] or String[]
      Returns:
      false, unless overridden to enable a specific VoltType (like VARBINARY) to support certain specific array types (like byte[]).
      See Also:
    • toSQLString

      public String toSQLString()
      Get the corresponding SQL type as for a given VoltType enum. For example, STRING will probably convert to "VARCHAR".
      Returns:
      A string representing the SQL type.
    • isJdbcVisible

      public boolean isJdbcVisible()

      Is this type visible to JDBC

      Returns:
      JDBC visibility
    • getJdbcSqlType

      public int getJdbcSqlType()
      Get the java.sql.Types type of this type.
      Returns:
      int representing SQL type of the VoltDB type.
    • getNullable

      public int getNullable()
      VoltDB treats nullability as orthogonal to type, so all types are nullable.
      Returns:
      the jdbc constant representing a nullable type
    • getSearchable

      public int getSearchable()
      Returns the standard JDBC 'searchable' attribute.
      Returns:
      searchable attribute as integer
    • isUnsigned

      public Boolean isUnsigned()
      Numeric types are all signed types, so return false. isUnsigned is N/A to other types, so return null. If/when we support unsigned types, their VoltTypes should override this function to return true.
      Returns:
      null for non-numeric types, false for numeric, unless overridden by a (hypothetical) unsigned numeric type
    • getJdbcClass

      public String getJdbcClass()
      Get the type that will be returned by JDBC's ResultSet.getObject(), which usually corresponds to to VoltTable.get(), except for timestamps.
      Returns:
      JDBC class name
    • isExactNumeric

      public boolean isExactNumeric()
      Is the type a number and is it an exact value (no rounding errors)?
      Returns:
      true for integers and decimals. False for floats and strings and anything else
    • isBackendIntegerType

      public boolean isBackendIntegerType()
      Is this type an integer type in the EE? True for TINYINT, SMALLINT, INTEGER, BIGINT and TIMESTAMP.
      Returns:
      True if integer type. False if not
    • isAnyIntegerType

      public boolean isAnyIntegerType()
      Is this type an integer type? True for TINYINT, SMALLINT, INTEGER, BIGINT.
      Returns:
      True if integer type. False if not
    • isNumber

      public boolean isNumber()
      Tests whether this Volt type is numeric.
      Returns:
      true for numeric types, false otherwise
    • canExactlyRepresentAnyValueOf

      public boolean canExactlyRepresentAnyValueOf(VoltType otherType)
      Indicate whether a value can be assigned to this type without loss of range or precision, important for index key and partition key initialization.
      Parameters:
      otherType - the type of value to be assigned to this
      Returns:
      true if exact representation possible
    • getSignatureChar

      public char getSignatureChar()
      Get a char that uniquely identifies a type. Used to create concise schema signatures.
      Returns:
      A char representing the type.
    • getTypePrecisionAndRadix

      public Integer[] getTypePrecisionAndRadix()
      Returns precision and radix of this type.
      Returns:
      two-element Integer array; Integer[0] is the column size and Integer[1] is the radix
    • defaultLengthForVariableLengthType

      public int defaultLengthForVariableLengthType()
      The size specifier for columns with a variable-length type is optional in a CREATE TABLE or ALTER TABLE statement. If no size is specified, VoltDB chooses a default size.
      Returns:
      the default size for the given type
    • getMostCompatibleJavaTypeName

      public String getMostCompatibleJavaTypeName()
      Returns a string representing the most compatible Java class name corresponding to this VoltType.
      Returns:
      simple name of Java class, or "(unknown?)"
    • getMaxValueForKeyPadding

      public String getMaxValueForKeyPadding()
      Returns the maximum possible value for a numeric type, as a string. Intended for use in determining the maximum width of a column when represented as a string.
      Returns:
      maximum value for numeric types, or null
    • getNullValue

      public Object getNullValue()
      Get a value representing whichever null value is appropriate for the current VoltType enum. For example, if this type is TINYINT, this will return a java byte with value -128, which is the constant NULL_TINYINT in VoltDB.
      Returns:
      A new final instance with value equal to null for a given type.
    • isVoltNullValue

      public static boolean isVoltNullValue(Object obj)
      Tests whether a supplied value is the null value for this Volt type.
      Parameters:
      obj - the value to be tested
      Returns:
      true if the value represents the null value
    • valueToBytes

      public static byte[] valueToBytes(Object obj)
      Converts the object into bytes for hashing.
      Parameters:
      obj - a value to be hashed
      Returns:
      a byte array representation of obj OR null if the obj is java null or any other Volt representation of a null value.
    • bytesToValue

      public Object bytesToValue(byte[] value)
      Converts a byte array with type back to the original partition value. This is the inverse of @see VoltType#valueToBytes(Object) valueToBytes
      Parameters:
      value - Byte array representation of partition parameter.
      Returns:
      Java object of the correct type.
    • decodeValue

      public Object decodeValue(ByteBuffer buffer) throws UnsupportedOperationException
      Decode a on object of this type from buffer
      Parameters:
      buffer - to read object from
      Returns:
      Decoded object
      Throws:
      UnsupportedOperationException - if this type does not support decoding