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.
  • 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.
    • 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
      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_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)
    • 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()
    • isVariableLength

      public boolean isVariableLength()
    • getLengthInBytesForFixedTypes

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

      public int getLengthInBytesForFixedTypesWithoutCheck()
    • 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()
    • 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()
    • 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()
    • canExactlyRepresentAnyValueOf

      public boolean canExactlyRepresentAnyValueOf(VoltType otherType)
    • 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()
    • 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()
    • getMaxValueForKeyPadding

      public String getMaxValueForKeyPadding()
    • 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)
    • 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