Java SDK Documentation
24.2.0
|
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) |
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.
com.vertica.sdk.StandardTypeCoercion.StandardTypeCoercion | ( | ) |
Create a default instance of StandardTypeCoercion using the default policy.
|
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).
Implements com.vertica.sdk.TypeCoercion.
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.
Implements com.vertica.sdk.TypeCoercion.
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).
value | The value being coerced. |
type | The target Vertica type, which is boolean. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().
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.
value | The value being coerced. |
type | The target Vertica type, which is boolean. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().
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.
value | The value being coerced. |
type | The target Vertica type, which is boolean. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().
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.
value | The value being coerced. |
type | The target Vertica type, which is boolean. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().
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.
value | The value being coerced. |
type | The target Vertica type, which is boolean. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asBoolean().
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.
Implements com.vertica.sdk.TypeCoercion.
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.
Implements com.vertica.sdk.TypeCoercion.
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.
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.
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.
Implements com.vertica.sdk.TypeCoercion.
BooleanEvaluation com.vertica.sdk.StandardTypeCoercion.getBooleanEvaluation | ( | ) |
Get the boolean evaluation strategy. The default is VERTICA.
DateFormat com.vertica.sdk.StandardTypeCoercion.getDateFormat | ( | ) |
Get the DateFormat used for formatting date types. This is used during asCharBytes for appropriately typed objects.
Referenced by com.vertica.sdk.StandardTypeCoercion.asCharBytes().
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.
Referenced by com.vertica.sdk.StandardTypeCoercion.parseDate().
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.
Referenced by com.vertica.sdk.StandardTypeCoercion.setDateFormat(), and com.vertica.sdk.StandardTypeCoercion.StandardTypeCoercion().
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.
Referenced by com.vertica.sdk.StandardTypeCoercion.setDateParse(), and com.vertica.sdk.StandardTypeCoercion.StandardTypeCoercion().
|
protectedinherited |
Provides the default policy installed by the constructor.
For NoopTypeCoercion, the default policy favors errors and avoids modifying data:
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.
Referenced by com.vertica.sdk.StandardTypeCoercion.setTimestampFormat(), and com.vertica.sdk.StandardTypeCoercion.StandardTypeCoercion().
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.
Referenced by com.vertica.sdk.StandardTypeCoercion.setTimestampParse(), and com.vertica.sdk.StandardTypeCoercion.StandardTypeCoercion().
|
inherited |
Provides an Iterator over Objects for a given Iterable input.
value | Something implementing Iterable<Object> |
Implements com.vertica.sdk.TypeCoercion.
|
inherited |
Provides an Iterator over map entries for a given Map.
Internal maps are assumed to have String keys. A ClassCastException will eventually result if there are internal maps with keys that are not Strings.
value | Something implementing Map<String,Object> |
Implements com.vertica.sdk.TypeCoercion.
|
inherited |
Detects Java standard Map and Iterable types.
Internal maps are assumed to have String keys. A ClassCastException will result if there are internal maps with keys that are not Strings.
Implements com.vertica.sdk.TypeCoercion.
|
inherited |
Returns an unmodifiable version of the policy.
Implements com.vertica.sdk.TypeCoercion.
Referenced by com.vertica.sdk.NoopTypeCoercion.asBinaryBytes(), com.vertica.sdk.NoopTypeCoercion.asCharBytes(), com.vertica.sdk.StandardTypeCoercion.asCharBytes(), com.vertica.sdk.NoopTypeCoercion.invalidInputType(), com.vertica.sdk.StandardTypeCoercion.invalidInputValue(), com.vertica.sdk.NullTypeCoercion.unsupportedType(), and com.vertica.sdk.NoopTypeCoercion.valueTooLarge().
DateFormat com.vertica.sdk.StandardTypeCoercion.getTimestampFormat | ( | ) |
Get the current DateFormat used for formatting timestamp types. This is used during asCharBytes for appropriately typed objects.
Referenced by com.vertica.sdk.StandardTypeCoercion.asCharBytes().
DateFormat com.vertica.sdk.StandardTypeCoercion.getTimestampParse | ( | ) |
Retrieve the current DateFormat used for parsing java.sql.Timestamp values in parseTimestamp(String, VerticaType). Does not return null.
Referenced by com.vertica.sdk.StandardTypeCoercion.parseTimestamp().
|
protectedinherited |
Throws a TypeCoercionException if the policy includes FAIL_INVALID_INPUT_TYPE. Otherwise does nothing.
value | The value being coerced. |
type | The target type. |
Referenced by com.vertica.sdk.NoopTypeCoercion.asBinaryBytes(), com.vertica.sdk.NoopTypeCoercion.asBoolean(), com.vertica.sdk.StandardTypeCoercion.asBooleanByJava(), com.vertica.sdk.StandardTypeCoercion.asBooleanByNumeric(), com.vertica.sdk.StandardTypeCoercion.asBooleanByVertica(), com.vertica.sdk.NoopTypeCoercion.asCharBytes(), com.vertica.sdk.NoopTypeCoercion.asDate(), com.vertica.sdk.StandardTypeCoercion.asDate(), com.vertica.sdk.NoopTypeCoercion.asDouble(), com.vertica.sdk.StandardTypeCoercion.asDouble(), com.vertica.sdk.NoopTypeCoercion.asLong(), com.vertica.sdk.StandardTypeCoercion.asLong(), com.vertica.sdk.NoopTypeCoercion.asTimestamp(), and com.vertica.sdk.StandardTypeCoercion.asTimestamp().
|
protected |
Throws a TypeCoercionException if the policy includes FAIL_INVALID_INPUT_VALUE. Otherwise does nothing.
value | The value being coerced. |
type | The target Vertica type. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asBooleanByVertica(), com.vertica.sdk.StandardTypeCoercion.asDouble(), com.vertica.sdk.StandardTypeCoercion.asLong(), com.vertica.sdk.StandardTypeCoercion.parseDate(), and com.vertica.sdk.StandardTypeCoercion.parseTimestamp().
java.sql.Date com.vertica.sdk.StandardTypeCoercion.parseDate | ( | String | value, |
VerticaType | type | ||
) |
Parse a date from a String using the current date parsing format.
Note that java.sql.Date specifies that values should be normalized by setting all non-day units to 0. This is not necessary or expected of return values from parseDate.
value | The String value being coerced, which is not null. |
type | The target Vertica type, which is a date type. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asDate().
|
protected |
Parses a textual representation of a number into a SpecialBigDecimal. Input text is trimmed of whitespace, then evaluated as a perfect fit to:
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 '+'.
text | A string as a character array. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asDouble(), and com.vertica.sdk.StandardTypeCoercion.asLong().
java.sql.Timestamp com.vertica.sdk.StandardTypeCoercion.parseTimestamp | ( | String | value, |
VerticaType | type | ||
) |
Parse a timestamp from a String using the current timestamp parsing format. Because DateFormat#parse(String, ParsePosition) returns a java.sql.Date, the precision of this operation is only milliseconds, which is less than Vertica's possible precision of microseconds.
Note that timestamptz (aka 'timestamp with time zone') and timestamp values are parsed in the same manner, regardless of the current session's timezone.
value | The String value being coerced, which is not null. |
type | The target Vertica type, which is either timestamp or timestamptz. |
Referenced by com.vertica.sdk.StandardTypeCoercion.asTimestamp().
void com.vertica.sdk.StandardTypeCoercion.setBooleanEvaluation | ( | BooleanEvaluation | boolEval | ) |
Set the boolean evaluation strategy. The default is VERTICA.
boolEval | A boolean evaluation strategy |
void com.vertica.sdk.StandardTypeCoercion.setDateFormat | ( | DateFormat | fmt | ) |
Set the DateFormat used for formatting date types. This is used during asCharBytes for appropriately typed objects. Only the format method will be used; other methods do not need to be implemented.
fmt | The format to use. |
void com.vertica.sdk.StandardTypeCoercion.setDateParse | ( | DateFormat | fmt | ) |
Set the DateFormat used for parsing java.sql.Date values in parseDate. If null, the default date parse format is used.
Note: Non-Lenient DateFormats are strongly encouraged. Lenient date formats can cause surprising results in some scenarios.
fmt | The format to use. |
|
inherited |
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.
policy | The policy collection |
Implements com.vertica.sdk.TypeCoercion.
Referenced by com.vertica.sdk.NullTypeCoercion.NullTypeCoercion().
void com.vertica.sdk.StandardTypeCoercion.setTimestampFormat | ( | DateFormat | fmt | ) |
Set the DateFormat used for formatting timestamp types. This is used during asCharBytes for appropriately typed objects. Only the format method will be used; other methods do not need to be implemented.
fmt | The format to use. |
void com.vertica.sdk.StandardTypeCoercion.setTimestampParse | ( | DateFormat | fmt | ) |
Set the DateFormat used for parsing java.sql.Timestamp values in parseTimestamp. If null, the default timestamp parse format is used.
Note: Non-Lenient DateFormats are strongly encouraged. Lenient date formats can cause surprising results in some scenarios.
fmt | The format to use. |
|
protectedinherited |
Throws a TypeCoercionException if the policy includes TypeCoercionPolicy#FAIL_UNSUPPORTED_TYPE. Otherwise does nothing.
value | The value provided which could not be coerced. |
type | The target Vertica type. |
Referenced by com.vertica.sdk.NullTypeCoercion.asBinaryBytes(), com.vertica.sdk.NullTypeCoercion.asBoolean(), com.vertica.sdk.NullTypeCoercion.asCharBytes(), com.vertica.sdk.NullTypeCoercion.asDate(), com.vertica.sdk.NullTypeCoercion.asDouble(), com.vertica.sdk.NullTypeCoercion.asLong(), and com.vertica.sdk.NullTypeCoercion.asTimestamp().
|
protectedinherited |
Throws a TypeCoercionException with a TRUNCATE_VALUES cause if the policy includes FAIL_INVALID_INPUT_VALUE. Otherwise does nothing.
This should only be called if the policy does not request truncation via TRUNCATE_VALUES.
value | The value being coerced. |
type | The target type. |
Referenced by com.vertica.sdk.NoopTypeCoercion.asBinaryBytes(), com.vertica.sdk.NoopTypeCoercion.asCharBytes(), and com.vertica.sdk.StandardTypeCoercion.asCharBytes().