Java SDK Documentation  24.2.0
com.vertica.sdk.TypeCoercion Interface Reference
Inheritance diagram for com.vertica.sdk.TypeCoercion:
Inheritance graph
Collaboration diagram for com.vertica.sdk.TypeCoercion:
Collaboration graph

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< Object > getListIterator (Object value)
 
Iterator< Map.Entry< String, Object > > getMapIterator (Object value)
 
MetaType getMetaType (Object value)
 
Set< TypeCoercionPolicygetPolicy ()
 
void setPolicy (Collection< TypeCoercionPolicy > 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

◆ asBinaryBytes()

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
valueThe value being coerced.
lengthThe length of the string-like type.
typeThe 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.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.

◆ asBoolean()

Boolean com.vertica.sdk.TypeCoercion.asBoolean ( Object  value,
VerticaType  type 
)

Coerce a value to a Boolean. May return null.

Parameters
valueThe value being coerced.
typeThe 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.

◆ asCharBytes()

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
valueThe value to convert, which may be null.
lengthThe maximum length (in bytes) of the result.
typeThe target Vertica type, which is some string-like type.
See also
StringUtils::getStringBytes(String, int, boolean)
StringUtils::getStringBytes(String, int, boolean, boolean)
StringUtils::getCharset()
VerticaType::isChar()
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.

◆ asDate()

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
valueThe value being coerced.
typeThe 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.

◆ asDouble()

Double com.vertica.sdk.TypeCoercion.asDouble ( Object  value,
VerticaType  type 
)

Coerce a value to a Double. May return null.

Parameters
valueThe value being coerced.
typeThe 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.

◆ asLong()

Long com.vertica.sdk.TypeCoercion.asLong ( Object  value,
VerticaType  type 
)

Coerce a value to a Long. May return null.

Parameters
valueThe value being coerced.
typeThe 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.

◆ asTimestamp()

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
valueThe value being coerced.
typeThe 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.

◆ getListIterator()

Iterator<Object> 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
valueA 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.

◆ getMapIterator()

Iterator<Map.Entry<String,Object> > 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
valueA 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.

◆ getMetaType()

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
valueThe value of interest, which may be null.
Returns
The type of the value.
See also
MetaType

Implemented in com.vertica.sdk.NoopTypeCoercion, and com.vertica.sdk.NullTypeCoercion.

◆ getPolicy()

Set<TypeCoercionPolicy> com.vertica.sdk.TypeCoercion.getPolicy ( )

Returns an unmodifiable version of the policy.

Returns
The policy collection.
See also
setPolicy

Implemented in com.vertica.sdk.NullTypeCoercion.

◆ setPolicy()

void com.vertica.sdk.TypeCoercion.setPolicy ( Collection< TypeCoercionPolicy 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
policyThe policy collection
See also
TypeCoercionPolicy
getPolicy()

Implemented in com.vertica.sdk.NullTypeCoercion.