Vertica documentation is moving! Use our new documentation site at https://docs.rocketsoftware.com/bundle/vertica_24.1/page/index.html

com.vertica.sdk.StandardTypeCoercion Class Reference

Inheritance diagram for com.vertica.sdk.StandardTypeCoercion:

Collaboration diagram for com.vertica.sdk.StandardTypeCoercion:

Classes
enum BooleanEvaluation
class SpecialBigDecimal
Public Member Functions
StandardTypeCoercion ()
ByteBuffer asBinaryBytes (Object value, int length, VerticaType type)
Boolean asBoolean (Object value, VerticaType type)
Boolean asBooleanByJava (Object value, VerticaType type)
Boolean asBooleanByNumeric (Object value, VerticaType type)
Boolean asBooleanByPerl (Object value, VerticaType type)
Boolean asBooleanByPython (Object value, VerticaType type)
Boolean asBooleanByVertica (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)
BooleanEvaluation getBooleanEvaluation ()
DateFormat getDateFormat ()
DateFormat getDateParse ()
DateFormat getDefaultDateFormat ()
DateFormat getDefaultDateParse ()
DateFormat getDefaultTimestampFormat ()
DateFormat getDefaultTimestampParse ()
Iterator< Object > getListIterator (Object value)
Iterator< Map.Entry< String, Object > > getMapIterator (Object value)
MetaType getMetaType (Object value)
Set< TypeCoercionPolicy > getPolicy ()
DateFormat getTimestampFormat ()
DateFormat getTimestampParse ()
java.sql.Date parseDate (String value, VerticaType type)
java.sql.Timestamp parseTimestamp (String value, VerticaType type)
void setBooleanEvaluation (BooleanEvaluation boolEval)
void setDateFormat (DateFormat fmt)
void setDateParse (DateFormat fmt)
void setPolicy (Collection< TypeCoercionPolicy > policy)
void setTimestampFormat (DateFormat fmt)
void setTimestampParse (DateFormat fmt)
Protected Member Functions
Collection< TypeCoercionPolicy > getDefaultPolicy ()
void invalidInputType (Object value, VerticaType type)
void invalidInputValue (Object value, VerticaType type)
SpecialBigDecimal parseNumber (char[] text)
void unsupportedType (Object value, VerticaType type)
void valueTooLarge (Object value, VerticaType type)

Detailed Description

StandardTypeCoercion implements standard type conversions. It provides some ability to configure how certain values (such as booleans and dates) are Interpreted or formatted.

The default policy favors errors and avoids modifying data. See getDefaultPolicy(). Values may be truncated if the policy includes TRUNCATE_VALUES.

Constructor & Destructor Documentation

◆StandardTypeCoercion()

com.vertica.sdk.StandardTypeCoercion.StandardTypeCoercion()

Create a default instance of StandardTypeCoercion using the default policy.

See also

getDefaultPolicy()

Member Function Documentation

◆asBinaryBytes()

ByteBuffer com.vertica.sdk.NoopTypeCoercion.asBinaryBytes(Object value, int length, VerticaType type)

inherited Generates a ByteBuffer (or null) value out of a sequence of bytes. Acceptable input types are byte array and ByteBuffer. All other types are invalid and will result in null or a TypeCoercionException according to the policy.

In agreement with how 'binary' values are stored in Vertica, values smaller than the target length are right-extended to length with the zero byte.

The value will be truncated to length when necessary if TRUNCATE_VALUES is specified in the policy. Otherwise values that are too long are treated as invalid input values (see FAIL_INVALID_INPUT_VALUE).

See also

VerticaType::isBinary()

Implements com.vertica.sdk.TypeCoercion.

◆asBoolean()

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

Generates a Boolean (or null) value out of input values of various types, depending on the boolean evaluation strategy. Uses one of the various 'asBoolean' methods according to the current boolean evaluation strategy.

See also

setBooleanEvaluation(BooleanEvaluation)

asBooleanByVertica(Object, VerticaType)

asBooleanByPerl(Object, VerticaType)

asBooleanByPython(Object, VerticaType)

asBooleanByJava(Object, VerticaType)

asBooleanByNumeric(Object, VerticaType)

Implements com.vertica.sdk.TypeCoercion.

◆asBooleanByJava()

Boolean com.vertica.sdk.StandardTypeCoercion.asBooleanByJava(Object value, VerticaType type)

Interprets a Boolean value in a similar manner as Java's Boolean#valueOf(String) function, which handles only Strings.

  • null values are null.

  • Boolean values are used as-is.

  • String values are evaluated via Boolean.valueOf(String).

Parameters

  • value: The value being coerced.
  • type: The target Vertica type, which is boolean.

Returns value coerced to Boolean, potentially null.

Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().

◆asBooleanByNumeric()

Boolean com.vertica.sdk.StandardTypeCoercion.asBooleanByNumeric(Object value, VerticaType type)

Interprets a Boolean value in a similar manner as C/C++, where numeric values and booleans aren't strictly separated. Rather than handling only integer numerics, this handles all numerics.

  • null values are null.

  • Boolean values are used as-is.

  • Number values are evaluated based on Number#doubleValue(). 0.0 is false and all other values are true.

  • All other types are invalid input types.

Parameters

  • value: The value being coerced.
  • type: The target Vertica type, which is boolean.

Returns value coerced to Boolean, potentially null.

Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().

◆asBooleanByPerl()

Boolean com.vertica.sdk.StandardTypeCoercion.asBooleanByPerl(Object value, VerticaType type)

Interprets a Boolean value in a similar manner as Perl does. Unlike Perl which treats undef as false, the null value will give a null Boolean. Otherwise, behavior follows the Perl behavior as closely as possible.

  • null values are null.

  • Boolean values are used as-is.

  • String values are false if empty (length() == 0) or if equal to "0". Strings are true otherwise. Whitespace is NOT ignored.

  • Number values are evaluated based on doubleValue(). 0.0 is false and all other values are True.

  • Collection and Map values are false if empty (size() == 0) and true otherwise.

  • All other types are true. Therefore, this will never result in an invalid input type.

Parameters

  • value: The value being coerced.
  • type: The target Vertica type, which is boolean.

Returns value coerced to Boolean, potentially null.

Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().

◆asBooleanByPython()

Boolean com.vertica.sdk.StandardTypeCoercion.asBooleanByPython(Object value, VerticaType type)

Interprets a Boolean value in a similar manner as Python does. Unlike Python which treats None as False, the null value will give a null Boolean. Otherwise, behavior follows the Python language specification. See "5.10 Boolean operations" in the Python 2.x reference on expressions.

  • null values are null.

  • Boolean values are used as-is.

  • String values are false if empty (length() == 0) and true otherwise. Whitespace is NOT ignored.

  • Number values are evaluated based on doubleValue(). 0.0 is false and all other values are True.

  • Collection and Map values are false if empty (size() == 0) and true otherwise.

  • All other types are true. Therefore, this will never result in an invalid input type.

Parameters

  • value: The value being coerced.
  • type: The target Vertica type, which is boolean.

Returns value coerced to Boolean, potentially null.

Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().

◆asBooleanByVertica()

Boolean com.vertica.sdk.StandardTypeCoercion.asBooleanByVertica(Object value, VerticaType type)

Interprets a Boolean value in a similar manner as Vertica does internally.

  • null values are null.

  • Boolean values are used as-is.

  • The following String values are true, after trimming leading and trailing whitespace and ignoring case: 't', 'true', 'y', 'yes', '1'.

  • The following String values are false, after trimming leading and trailing whitespace and ignoring case: 'f', 'false', 'n', 'no', '0'.

  • All other String values are invalid input values.

  • Number values are evaluated based on doubleValue(). 0.0 is false and 1.0 is true. All other values are invalid input values.

  • All other types are invalid input types.

Parameters

  • value: The value being coerced.
  • type: The target Vertica type, which is boolean.

Returns value coerced to Boolean, potentially null.

Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().

◆asCharBytes()

ByteBuffer com.vertica.sdk.StandardTypeCoercion.asCharBytes(Object value, int length, VerticaType type)

Generates a ByteBuffer with the string representation of an object. Generally uses the same approach as Vertica's vsql presentation format for analogous types. Unknown types will use Java's String#valueOf(Object).

The value will be truncated to length when necessary if TRUNCATE_VALUES is specified in the policy. Otherwise values that are too long will return in either a null return value or a TypeCoercionException according to the policy (FAIL_INVALID_INPUT_VALUE).

In agreement with how 'char' values are stored in Vertica, trailing spaces will be removed if the type is 'char'.

Specifically, the following describes the textual representation of various types, which then undergoes truncation and trimming as necessary.

  • null values are null.

  • String values are used as-is.

  • Long, Integer, Short, Byte, AtomicLong, AtomicInteger, and BigInteger types are represented in decimal, without ever using scientific notation. Negative values are preceded with a '-'.

  • BigDecimal is also represented in decimal, without ever using scientific notation. BigDecimal#toPlainString() method is used.

  • All other Number types are represented by passing the Number#doubleValue() through Double#toString() which uses scientific notation and represents NaN and Infinity.

  • Boolean values are represented as 'true' or 'false'.

  • java.sql.Date values are formatted with the format given by getDateFormat()

  • java.util.Date values (including java.sql.Timestamp values) are formatted with the format given by getTimestampFormat().

  • String#valueOf(Object) is used for all other values.

See also

VerticaType::isChar()

Implements com.vertica.sdk.TypeCoercion.

◆asDate()

java.sql.Date com.vertica.sdk.StandardTypeCoercion.asDate(Object value, VerticaType type)

Generate a java.sql.Date representation of the provided object.

  • null values are null.

  • java.sql.Date values are used as-is. java.util.Date values are converted to java.sql.Date.

  • String values are handled by parseDate(String, VerticaType).

  • All other types are invalid input types.

See also

parseDate(String, VerticaType)

Implements com.vertica.sdk.TypeCoercion.

◆asDouble()

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

Generates a Double representation of the provided object.

  • null values are null.

  • Number values use Number#doubleValue().

  • Strings are parsed by the following rules. Violations are invalid input values. Note that the double data type has a limited range of precision and magnitude. Some precision may be lost. Extreme values may be represented as Infinity or -Infinity.

A hexidecimal integer value starting with '0x' or '0X' with optional leading '-' or '+'.

  • 'Infinity' (case insensitive) with optional leading '-' or '+'.

  • 'NaN' (case insensitive) with optional leading '-' or '+'.

  • A decimal number with or without scientific notation, with optional leading '-' or '+'

  • All other types are invalid input types.

Implements com.vertica.sdk.TypeCoercion.

◆asLong()

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

Generates a Long representation of the provided object.

  • null values are null.

  • Number values use Number#doubleValue(). This usually implies truncation of any fractional part of the value, regardless of the truncation policy.

  • Strings are parsed by the following rules. Violations are invalid input values. Note that the long data type has a limited range of magnitude. Values outside of this range are invalid input values. Values with fractional parts are truncated.

A hexidecimal integer value starting with '0x' or '0X' with optional leading '-' or '+'.

  • A decimal number with or without scientific notation, with optional leading '-' or '+'

  • All other types are invalid input types.

Implements com.vertica.sdk.TypeCoercion.

◆asTimestamp()

java.sql.Timestamp com.vertica.sdk.StandardTypeCoercion.asTimestamp(Object value, VerticaType type)

Generate a java.sql.Timestamp representation of the provided object.

  • null values are null.

  • java.sql.Timestamp values are used as-is. java.util.Date values are converted to java.sql.Timestamp via getTime().

  • String values are handled by parseTimestamp(String, VerticaType).

  • All other types are invalid input types.

See also

parseTimestamp(String, VerticaType)

Implements com.vertica.sdk.TypeCoercion.

◆getBooleanEvaluation()

BooleanEvaluation com.vertica.sdk.StandardTypeCoercion.getBooleanEvaluation()

Get the boolean evaluation strategy. The default is VERTICA.

Returns The current boolean evaluation strategy.

◆getDateFormat()

DateFormat com.vertica.sdk.StandardTypeCoercion.getDateFormat()

Get the DateFormat used for formatting date types. This is used during asCharBytes for appropriately typed objects.

Returns The format in use.

See also

asCharBytes(Object, int, VerticaType)

Referenced by com.vertica.sdk.StandardTypeCoercion.asCharBytes().

◆getDateParse()

DateFormat com.vertica.sdk.StandardTypeCoercion.getDateParse()

Retrieve the current DateFormat used for parsing java.sql.Date values in parseDate(String, VerticaType). Does not return null.

Returns The format in use.

See also

getDefaultDateParse()

parseDate(String, VerticaType)

Referenced by com.vertica.sdk.StandardTypeCoercion.parseDate().

◆getDefaultDateFormat()

DateFormat com.vertica.sdk.StandardTypeCoercion.getDefaultDateFormat()

Get the default DateFormat used for formatting date types to Strings. The format is 'yyyy-MM-dd' in the JVM default timezone. This is used during asCharBytes for appropriately typed objects.

Returns The default format used by new instances.

See also

asCharBytes(Object, int, VerticaType)

Referenced by

◆getDefaultDateParse()

DateFormat com.vertica.sdk.StandardTypeCoercion.getDefaultDateParse()

Get the default DateFormat used for parsing date types from Strings. The format is 'yyyy-MM-dd' in the JVM default timezone and is not lenient.

For more flexibility, override parseDate(String, VerticaType) or install a different date format.

See also

parseDate(String, VerticaType)

setDateParse(DateFormat)

Returns The default format used by new instances.

Referenced by

◆getDefaultPolicy()

Collection<TypeCoercionPolicy> com.vertica.sdk.NoopTypeCoercion.getDefaultPolicy()

protected inherited Provides the default policy installed by the constructor.

For NoopTypeCoercion, the default policy favors errors and avoids modifying data:

  • FAIL_SDK_UNSUPPORTED_TYPE

  • FAIL_UNSUPPORTED_TYPE

  • FAIL_INVALID_INPUT_TYPE

  • FAIL_INVALID_INPUT_VALUE

◆getDefaultTimestampFormat()

DateFormat com.vertica.sdk.StandardTypeCoercion.getDefaultTimestampFormat()

Get the default DateFormat used for formatting timestamp types to Strings. The format is 'yyyy-MM-dd HH:mm:ss.SSS' in the JVM default timezone. This is used during asCharBytes for appropriately typed objects.

Returns The default format used by new instances.

See also

asCharBytes(Object, int, VerticaType)

Referenced by

◆getDefaultTimestampParse()

DateFormat com.vertica.sdk.StandardTypeCoercion.getDefaultTimestampParse()

Get the default DateFormat used for parsing timestamp types from Strings. The format is 'yyyy-MM-dd HH:mm:ss.SSS' in the JVM default timezone and is not lenient.

For more flexibility, override parseTimestamp(String, VerticaType) or install a different date format.

See also

parseTimestamp(String, VerticaType)

setTimestampParse(DateFormat)

Returns The default format used by new instances.

Referenced by

◆getListIterator()

Iterator<Object> com.vertica.sdk.NoopTypeCoercion.getListIterator(Object value)

inherited Provides an Iterator over Objects for a given Iterable input.

Parameters