com.vertica.sdk.TypeCoercion Interface Reference
Inheritance diagram for com.vertica.sdk.TypeCoercion:
Collaboration diagram for com.vertica.sdk.TypeCoercion:
| Classes | |
|---|---|
| enum | MetaType |
| Public Member Functions | |
|---|---|
| ByteBuffer | asBinaryBytes (Object value, int length, VerticaType type) |
| Boolean | asBoolean (Object value, VerticaType type) |
| ByteBuffer | asCharBytes (Object value, int length, VerticaType type) |
| java.sql.Date | asDate (Object value, VerticaType type) |
| Double | asDouble (Object value, VerticaType type) |
| Long | asLong (Object value, VerticaType type) |
| java.sql.Timestamp | asTimestamp (Object value, VerticaType type) |
| Iterator | getListIterator (Object value) |
| Iterator > | getMapIterator (Object value) |
| MetaType | getMetaType (Object value) |
| Set | getPolicy () |
| void | setPolicy (Collection policy) |
Detailed Description
An interface which allows for intelligent casting from arbitrary Java Objects to appropriate types for consumption by Vertica. Several default implementations are provided, including:
Member Function Documentation
ByteBuffer com.vertica.sdk.TypeCoercion.asBinaryBytes(Object value, int length, VerticaType type)
Coerce a value to bytes. May return null, which is different than an empty array.
Note that the 'binary' type should be padded out to the full length.
Parameters
value: The value being coerced.length: The length of the string-like type.type: The target Vertica type, which is a string-like type.
Returns a ByteBuffer with no more than 'length' bytes between its position and limit.
Implemented in com.vertica.sdk.NullTypeCoercion.
Boolean com.vertica.sdk.TypeCoercion.asBoolean(Object value, VerticaType type)
Coerce a value to a Boolean. May return null.
Parameters
value: The value being coerced.type: The target Vertica type, which is boolean.
Returns An appropriate Boolean value, or null.
Implemented in com.vertica.sdk.StandardTypeCoercion, com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
ByteBuffer com.vertica.sdk.TypeCoercion.asCharBytes(Object value, int length, VerticaType type)
Coerce a value to vertica-encoded string bytes. May return null, which is different than the empty string.
Note that the 'char' type should have trailing ASCII spaces removed. To implement this behavior, inspect the type parameter with VerticaType#isChar().
Parameters
value: The value to convert, which may be null.length: The maximum length (in bytes) of the result.type: The target Vertica type, which is some string-like type.
See Also
StringUtils::getStringBytes(String, int, boolean)
StringUtils::getStringBytes(String, int, boolean, boolean)
Returns A ByteBuffer with no more than 'length' bytes between its position and limit.
Implemented in com.vertica.sdk.StandardTypeCoercion, com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
java.sql.Date com.vertica.sdk.TypeCoercion.asDate(Object value, VerticaType type)
Coerce a value to a Date. May return null.
Note that the java.sql.Date specification requires that the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
However, that is not required by the Vertica SDK. This 'normalization' will take place later by internal components of the SDK.
Parameters
value: The value being coerced.type: The target Vertica type.
Returns An appropriate Timestamp value, or null.
Implemented in com.vertica.sdk.StandardTypeCoercion, com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
Double com.vertica.sdk.TypeCoercion.asDouble(Object value, VerticaType type)
Coerce a value to a Double. May return null.
Parameters
value: The value being coerced.type: The target Vertica type.
Returns An appropriate Double value, or null.
Implemented in com.vertica.sdk.StandardTypeCoercion, com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
Long com.vertica.sdk.TypeCoercion.asLong(Object value, VerticaType type)
Coerce a value to a Long. May return null.
Parameters
value: The value being coerced.type: The target Vertica type.
Returns An appropriate Long value, or null.
Implemented in com.vertica.sdk.StandardTypeCoercion, com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
java.sql.Timestamp com.vertica.sdk.TypeCoercion.asTimestamp(Object value, VerticaType type)
Coerce a value to a Timestamp. May return null. This is used for timestamp and timestamptz Vertica types.
The timestamp is assumed to represent a moment in the UTC timezone, which is how Vertica stores all timestamp and timestamptz values internally. Implementations should handle any translations related to timezones.
Vertica has microsecond precision for timestamp values. Any further precision on the returned value is ignored.
Parameters
value: The value being coerced.type: The target Vertica type.
Returns An appropriate Timestamp value, or null.
Implemented in com.vertica.sdk.StandardTypeCoercion, com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
Iterator com.vertica.sdk.TypeCoercion.getListIterator(Object value)
Get an iterator of values from some list-like aggregate value. This is only invoked for values which getMetaType(Object) has returned MetaType#LIST.
Parameters
value: A value that was previously identified as list-like type.
Returns An iterator over Objects. Not null.
Implemented in com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
Iterator > com.vertica.sdk.TypeCoercion.getMapIterator(Object value)
Get an iterator of values from some map-like aggregate value. This is only invoked for values which getMetaType(Object) has returned MetaType#MAP.
The elements must have only String keys. Otherwise a ClassCastException will be raised at a later time.
Parameters
value: A value that was previously identified as map-like type.
Returns An iterator over Map.Entry<String,Object>. Not null.
Implemented in com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
MetaType com.vertica.sdk.TypeCoercion.getMetaType(Object value)
Determine what genre of type the given value is. This is used when handling aggregate data structures which may include nesting of other aggregate or non-aggregate types.
The response indicates if the given value is a scalar, list, or map type. Alternatively, a response of SKIP indicates that the value should be ignored, as if it did not exist.
Parameters
value: The value of interest, which may be null.
Returns The type of the value.
See Also
Implemented in com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.
Set com.vertica.sdk.TypeCoercion.getPolicy()
Returns an unmodifiable version of the policy.
Returns The policy collection.
See Also
Implemented in com.vertica.sdk.NullTypeCoercion.
void com.vertica.sdk.TypeCoercion.setPolicy(Collection policy)
Sets the policies for this TypeCoercion instance. Policies generally dictate which scenarios generate exceptions and allow for different error handling choices without implementing a new TypeCoercion class.
Parameters
policy: The policy collection
See Also
Implemented in com.vertica.sdk.NullTypeCoercion.