Package org.voltdb
Enum Class VoltType
- All Implemented Interfaces:
Serializable,Comparable<VoltType>,Constable
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 ClassesModifier and TypeClassDescriptionstatic final classSupport 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 ConstantsEnum ConstantDescription8-byte signed 2s-complement long.Boolean type.4-byte long value representing DATEFixed precision=38, scale=12 storing sign and null-status in a preceding byte8-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 lengthVoltTable type for Procedure parameters -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSize in bytes of the maximum length for a VoltDB field value, presumably aSTRINGorVARBINARYstatic final intSize in characters of the maximum length for a VoltDB field value, using a worst-case estimate of 4 bytes per characterstatic final longNull value forBIGINT.static final org.voltdb.VoltType.NullDateSigilNull value forDATE.static final org.voltdb.VoltType.NullDecimalSigilNull value forDECIMAL.static final doubleNull value forFLOAT.static final org.voltdb.VoltType.NullGeographySigilNull value forGEOGRAPHY.static final intNull value forINTEGER.static final org.voltdb.VoltType.NullPointSigilNull value forGEOGRAPHY_POINT.static final shortNull value forSMALLINT.static final intLength value for a null string.static final org.voltdb.VoltType.NullStringOrVarbinarySigilNull value forSTRINGorVARBINARY.static final org.voltdb.VoltType.NullTimestampSigilNull value forTIMESTAMP.static final byteNull value forTINYINT. -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptsArray(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.booleancanExactlyRepresentAnyValueOf(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.static Class<?>classFromByteValue(byte value) Return the java class that is matched to the given value.Class<?>Return the java class that is matched to a givenVoltType.decodeValue(ByteBuffer buffer) Decode a on object of this type frombufferintThe size specifier for columns with a variable-length type is optional in a CREATE TABLE or ALTER TABLE statement.static VoltTypeget(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.intGet the java.sql.Types type of this type.intGet the number of bytes required to store the fixed length type.intGet 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.intGet the maximum number of bytes required to store the typeReturns the maximum possible value for a numeric type, as a string.Non-integer numeric VoltTypes must override this method.intGet the minimum number of bytes required to store the typeReturns a string representing the most compatible Java class name corresponding to this VoltType.getName()Return the name of this type as a string.intVoltDB treats nullability as orthogonal to type, so all types are nullable.Get a value representing whichever null value is appropriate for the currentVoltTypeenum.intReturns the standard JDBC 'searchable' attribute.charGet a char that uniquely identifies a type.Integer[]Returns precision and radix of this type.bytegetValue()Gets the byte that corresponds to the VoltType (for serialization).static StringhumanReadableSize(int size) String representation ofMAX_VALUE_LENGTH.booleanIs this type an integer type? True forTINYINT,SMALLINT,INTEGER,BIGINT.static booleanisAvroRecord(Class<?> clazz) Tests whether a specified class is an Avro data record (a subclass of the generic Avro record class).booleanIs this type an integer type in the EE? True forTINYINT,SMALLINT,INTEGER,BIGINTandTIMESTAMP.booleanIndividual VoltTypes like String can override to enable this functionality.booleanIs the type a number and is it an exact value (no rounding errors)?booleanVoltTypes for indexable non-numeric values must override.booleanIs this type visible to JDBCbooleanisNumber()Tests whether this Volt type is numeric.booleanVoltTypes with special restrictions about uniqueness support must override.Numeric types are all signed types, so return false.booleanTests whether this type is a variable-length type.static booleanisVoltNullValue(Object obj) Tests whether a supplied value is the null value for this Volt type.Get the corresponding SQL type as for a givenVoltTypeenum.toString()Return the string representation of this type.static VoltTypetypeFromClass(Class<?> cls) Ascertain the most appropriateVoltTypegiven a java class.static VoltTypetypeFromObject(Object obj) Ascertain the most appropriateVoltTypegiven a java object.static VoltTypetypeFromString(String str) Converts string representations to an enum value.static VoltTypeReturns the enum constant of this class with the specified name.static VoltType[]values()Returns an array containing the constants of this enum class, in the order they are declared.static byte[]valueToBytes(Object obj) Converts the object into bytes for hashing.Class<?>Return the java class that is matched to a givenVoltType.
-
Enum Constant Details
-
INVALID
Used for uninitialized types in some places. Not a valid value for actual user data. -
NULL
Used to type java null values that have no type. Not a valid value for actual user data. -
NUMERIC
Used for some literal constants parsed by our SQL parser. Not a valid value for actual user data. SeeDECIMALfor decimal type. -
TINYINT
1-byte signed 2s-complement byte. Lowest value means NULL in the database. -
SMALLINT
2-byte signed 2s-complement short. Lowest value means NULL in the database. -
INTEGER
4-byte signed 2s-complement integer. Lowest value means NULL in the database. -
BIGINT
8-byte signed 2s-complement long. Lowest value means NULL in the database. -
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
8-bytes in IEEE 754 "double format". Some NaN values may represent NULL in the database (TBD). -
STRING
UTF-8 string with up to 32K chars. The database supports char arrays and varchars but the API uses strings. -
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
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
4-byte long value representing DATE -
VOLTTABLE
VoltTable type for Procedure parameters -
DECIMAL
Fixed precision=38, scale=12 storing sign and null-status in a preceding byte -
BOOLEAN
Boolean type. Not (yet) a valid value for actual user data. -
VARBINARY
Array of bytes of variable length -
GEOGRAPHY_POINT
Point type, for a geographical point (long, lat) -
GEOGRAPHY
Geography type, for geographical objects (polygons, etc)
-
-
Field Details
-
MAX_VALUE_LENGTH
public static final int MAX_VALUE_LENGTHSize in bytes of the maximum length for a VoltDB field value, presumably aSTRINGorVARBINARY- See Also:
-
MAX_VALUE_LENGTH_IN_CHARACTERS
public static final int MAX_VALUE_LENGTH_IN_CHARACTERSSize 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_LENGTHLength value for a null string.- See Also:
-
NULL_TINYINT
public static final byte NULL_TINYINTNull value forTINYINT.- See Also:
-
NULL_SMALLINT
public static final short NULL_SMALLINTNull value forSMALLINT.- See Also:
-
NULL_INTEGER
public static final int NULL_INTEGERNull value forINTEGER.- See Also:
-
NULL_BIGINT
public static final long NULL_BIGINTNull value forBIGINT.- See Also:
-
NULL_FLOAT
public static final double NULL_FLOATNull value forFLOAT.- See Also:
-
NULL_TIMESTAMP
public static final org.voltdb.VoltType.NullTimestampSigil NULL_TIMESTAMPNull value forTIMESTAMP. -
NULL_DATE
public static final org.voltdb.VoltType.NullDateSigil NULL_DATENull value forDATE. -
NULL_STRING_OR_VARBINARY
public static final org.voltdb.VoltType.NullStringOrVarbinarySigil NULL_STRING_OR_VARBINARYNull value forSTRINGorVARBINARY. -
NULL_DECIMAL
public static final org.voltdb.VoltType.NullDecimalSigil NULL_DECIMALNull value forDECIMAL. -
NULL_POINT
public static final org.voltdb.VoltType.NullPointSigil NULL_POINTNull value forGEOGRAPHY_POINT. -
NULL_GEOGRAPHY
public static final org.voltdb.VoltType.NullGeographySigil NULL_GEOGRAPHYNull value forGEOGRAPHY.
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
isAvroRecord
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
clazzis the class of an Avro record
-
humanReadableSize
String representation ofMAX_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
Return the java class that is matched to a givenVoltType.- Returns:
- A java class object.
- Throws:
RuntimeException- if a type doesn't have an associated class, such asINVALID.- See Also:
-
classFromByteValue
Return the java class that is matched to the given value.- Parameters:
value- of a VoltType as returned bygetValue()- Returns:
- The java class.
-
vectorClassFromType
Return the java class that is matched to a givenVoltType.- Returns:
- A java class object.
- Throws:
RuntimeException- if a type doesn't have an associated class, such asINVALID.- See Also:
-
get
Statically create an enum value from the corresponding byte.- Parameters:
val- A byte representing an enum value- Returns:
- The appropriate enum value
-
typeFromString
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
Ascertain the most appropriateVoltTypegiven a java object.- Parameters:
obj- The java object to type.- Returns:
- A
VoltType. - Throws:
org.voltdb.VoltTypeException- if none applies.- See Also:
-
typeFromClass
Ascertain the most appropriateVoltTypegiven a java class.- Parameters:
cls- The java class to type.- Returns:
- A
VoltType. - Throws:
org.voltdb.VoltTypeException- if none applies.- See Also:
-
toString
Return the string representation of this type. Note thatVoltType.typeFromString(voltTypeInstance.toString) == voltTypeInstance. -
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
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
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
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
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
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
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
Get the corresponding SQL type as for a givenVoltTypeenum. For example,STRINGwill 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
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
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 forTINYINT,SMALLINT,INTEGER,BIGINTandTIMESTAMP.- Returns:
- True if integer type. False if not
-
isAnyIntegerType
public boolean isAnyIntegerType()Is this type an integer type? True forTINYINT,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
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
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
Returns a string representing the most compatible Java class name corresponding to this VoltType.- Returns:
- simple name of Java class, or "(unknown?)"
-
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
Get a value representing whichever null value is appropriate for the currentVoltTypeenum. For example, if this type isTINYINT, this will return a javabytewith 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
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
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
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
Decode a on object of this type frombuffer- Parameters:
buffer- to read object from- Returns:
- Decoded object
- Throws:
UnsupportedOperationException- if this type does not support decoding
-