Class Conversions


  • public class Conversions
    extends Object
    Provides implementations of common type conversion functions. These functions are for conversions which would not normally be permitted by the token type system as they are either possibly "lossy" (such as type narrowing) or ambiguous (such as string formatting).
    See Also:
    ScalarValuedFunction, DeriveFields
    • Method Detail

      • asBoolean

        public static ScalarValuedFunction asBoolean​(String field)
        Convert an int typed field into a boolean type. Unmapped values will be set to null.
        Parameters:
        field - a field whose type is an int
        Returns:
        the function that provides the conversion
      • asBoolean

        public static ScalarValuedFunction asBoolean​(String field,
                                                     int truth,
                                                     int falsity)
        Convert an int typed field into a boolean type. Unmapped values will be set to null.
        Parameters:
        field - a field whose type is an int
        truth - int representing the value of true
        falsity - int representing the value of false
        Returns:
        the function that provides the conversion
      • asBoolean

        public static ScalarValuedFunction asBoolean​(ScalarValuedFunction expr,
                                                     int truth,
                                                     int falsity)
        Convert an int typed field into a boolean type. Unmapped values will be set to null.
        Parameters:
        expr - a function expression whose return type is an int
        truth - int representing the value of true
        falsity - int representing the value of false
        Returns:
        the function that provides the conversion
      • asFloat

        public static ScalarValuedFunction asFloat​(String field)
        Convert a numeric typed field into a float type. Note that precision may be lost during the conversion.
        Parameters:
        field - a field whose type is a number
        Returns:
        the function that provides the conversion
      • asFloat

        public static ScalarValuedFunction asFloat​(ScalarValuedFunction expr)
        Convert a numeric typed expression into a float type. Note that precision may be lost during the conversion.
        Parameters:
        expr - a function expression whose return type is a number
        Returns:
        the function that provides the conversion
      • asDouble

        public static ScalarValuedFunction asDouble​(String field)
        Convert a numeric typed field into a double type. Note that precision may be lost during the conversion.
        Parameters:
        field - a field whose type is a number
        Returns:
        the function that provides the conversion
      • asDouble

        public static ScalarValuedFunction asDouble​(ScalarValuedFunction expr)
        Convert a numeric typed expression into a double type. Note that precision may be lost during the conversion.
        Parameters:
        expr - a function expression whose return type is a number
        Returns:
        the function that provides the conversion
      • asInt

        public static ScalarValuedFunction asInt​(String field)
        Convert a numeric typed field into an integer type. Note that precision may be lost during the conversion.
        Parameters:
        field - a field whose type is a number
        Returns:
        the function that provides the conversion
      • asInt

        public static ScalarValuedFunction asInt​(ScalarValuedFunction expr)
        Convert a numeric typed expression into an integer type. Note that precision may be lost during the conversion.
        Parameters:
        expr - a function expression whose return type is a number
        Returns:
        the function that provides the conversion
      • asLong

        public static ScalarValuedFunction asLong​(String field)
        Convert a numeric typed field into a long type. Note that precision may be lost during the conversion.
        Parameters:
        field - a field whose type is a number
        Returns:
        the function that provides the conversion
      • asLong

        public static ScalarValuedFunction asLong​(ScalarValuedFunction expr)
        Convert a numeric typed expression into a long type. Note that precision may be lost during the conversion.
        Parameters:
        expr - a function expression whose return type is a number
        Returns:
        the function that provides the conversion
      • asMoney

        public static ScalarValuedFunction asMoney​(String field)
        Convert a numeric typed field into a money type. Note that precision may be lost during the conversion.
        Parameters:
        field - a field whose type is a number
        Returns:
        the function that provides the conversion
      • asMoney

        public static ScalarValuedFunction asMoney​(ScalarValuedFunction expr)
        Convert a numeric typed expression into a money type. Note that precision may be lost during the conversion.
        Parameters:
        expr - a function expression whose return type is a number
        Returns:
        the function that provides the conversion
      • asNumeric

        public static ScalarValuedFunction asNumeric​(String field)
        Convert a numeric typed field into a numeric type. The numeric type is typically backed by a BigDecimal object.
        Parameters:
        field - a field whose type is a number
        Returns:
        the function that provides the conversion
      • asTime

        public static ScalarValuedFunction asTime​(String field)
        Convert a timestamp typed field into a time field. This down casting essentially drops the date portion of the timestamp field leaving only the time portion. The timestamp is interpreted using the timezone offset associated with it.
        Parameters:
        field - a field whose type is timestamp
        Returns:
        the function that provides the conversion
      • asTime

        public static ScalarValuedFunction asTime​(ScalarValuedFunction expr)
        Convert a timestamp expression result into a time field. This down casting essentially drops the date portion of the timestamp field leaving only the time portion. The timestamp is interpreted using the timezone offset associated with it.
        Parameters:
        expr - a function expression whose return type is timestamp
        Returns:
        the function that provides the conversion
      • asNumeric

        public static ScalarValuedFunction asNumeric​(ScalarValuedFunction expr)
        Convert a numeric typed expression into a numeric type. The numeric type is typically backed by a BigDecimal object.
        Parameters:
        expr - a function expression whose return type is a number
        Returns:
        the function that provides the conversion
      • asDate

        public static ScalarValuedFunction asDate​(String field)
        Convert a timestamp typed field into a date field. This down casting essentially drops the time portion of the timestamp field leaving only the date portion.
        Parameters:
        field - a field whose type is timestamp
        Returns:
        the function that provides the conversion
      • asDate

        public static ScalarValuedFunction asDate​(ScalarValuedFunction expr)
        Convert a timestamp expression result into a date field. This down casting essentially drops the time portion of the timestamp field leaving only the date portion.
        Parameters:
        expr - a function expression whose return type is timestamp
        Returns:
        the function that provides the conversion
      • toBinary

        public static ScalarValuedFunction toBinary​(String fieldName)
        Convert a string typed field into a binary type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toBinary

        public static ScalarValuedFunction toBinary​(ScalarValuedFunction expr)
        Convert a string typed expression into a binary type.
        Parameters:
        expr - an expression whose type is string
        Returns:
        the function that provides the conversion
      • toChar

        public static ScalarValuedFunction toChar​(String fieldName)
        Convert a string typed field into a char type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toChar

        public static ScalarValuedFunction toChar​(ScalarValuedFunction expr)
        Convert a string typed expression into a char type.
        Parameters:
        expr - an expression whose type is string
        Returns:
        the function that provides the conversion
      • toDouble

        public static ScalarValuedFunction toDouble​(String field)
        Convert a string typed field into a double type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toDouble

        public static ScalarValuedFunction toDouble​(ScalarValuedFunction expr)
        Convert a string typed expression into a double type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toDouble

        public static ScalarValuedFunction toDouble​(String field,
                                                    String format)
        Convert a string typed field into a double type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert strings to doubles
        Returns:
        the function that provides the conversion
      • toDouble

        public static ScalarValuedFunction toDouble​(String field,
                                                    NumberFormat format)
        Convert a string typed field into a double type using the given format.
        Parameters:
        field - a field whose type is string
        format - formatter instance to use to convert strings to doubles
        Returns:
        the function that provides the conversion
      • toDouble

        public static ScalarValuedFunction toDouble​(ScalarValuedFunction expr,
                                                    NumberFormat format)
        Convert a string typed expression into a double type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - formatter instance to use to convert strings to doubles
        Returns:
        the function that provides the conversion
      • toFloat

        public static ScalarValuedFunction toFloat​(String field)
        Convert a string typed field into a float type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toFloat

        public static ScalarValuedFunction toFloat​(ScalarValuedFunction expr)
        Convert a string typed expression into a float type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toFloat

        public static ScalarValuedFunction toFloat​(String field,
                                                   String format)
        Convert a string typed field into a float type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert string to floats
        Returns:
        the function that provides the conversion
      • toFloat

        public static ScalarValuedFunction toFloat​(String field,
                                                   NumberFormat format)
        Convert a string typed field into a float type using the given format.
        Parameters:
        field - a field whose type is string
        format - formatter instance to use to convert strings to floats
        Returns:
        the function that provides the conversion
      • toFloat

        public static ScalarValuedFunction toFloat​(ScalarValuedFunction expr,
                                                   NumberFormat format)
        Convert a string typed expression into a float type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - formatter instance to use to convert strings to floats
        Returns:
        the function that provides the conversion
      • toInt

        public static ScalarValuedFunction toInt​(String field)
        Convert a string typed field into a integer type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toInt

        public static ScalarValuedFunction toInt​(ScalarValuedFunction expr)
        Convert a string typed expression into a integer type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toInt

        public static ScalarValuedFunction toInt​(String field,
                                                 String format)
        Convert a string typed field into a integer type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert strings to integers
        Returns:
        the function that provides the conversion
      • toInt

        public static ScalarValuedFunction toInt​(String field,
                                                 NumberFormat format)
        Convert a string typed field into a integer type using the given format.
        Parameters:
        field - a field whose type is string
        format - formatter instance to use to convert strings to integers
        Returns:
        the function that provides the conversion
      • toInt

        public static ScalarValuedFunction toInt​(ScalarValuedFunction expr,
                                                 NumberFormat format)
        Convert a string typed expression into a integer type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - formatter instance to use to convert strings to integers
        Returns:
        the function that provides the conversion
      • toLong

        public static ScalarValuedFunction toLong​(String field)
        Convert a string typed field into a long type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toLong

        public static ScalarValuedFunction toLong​(ScalarValuedFunction expr)
        Convert a string typed expression into a long type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toLong

        public static ScalarValuedFunction toLong​(String field,
                                                  String format)
        Convert a string typed field into a long type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert strings to longs
        Returns:
        the function that provides the conversion
      • toLong

        public static ScalarValuedFunction toLong​(String field,
                                                  NumberFormat format)
        Convert a string typed field into a long type using the given format.
        Parameters:
        field - a field whose type is string
        format - formatter instance to use to convert strings to longs
        Returns:
        the function that provides the conversion
      • toLong

        public static ScalarValuedFunction toLong​(ScalarValuedFunction expr,
                                                  NumberFormat format)
        Convert a string typed expression into a long type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - formatter instance to use to convert strings to longs
        Returns:
        the function that provides the conversion
      • toMoney

        public static ScalarValuedFunction toMoney​(String field)
        Convert a string typed field into a money type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toMoney

        public static ScalarValuedFunction toMoney​(ScalarValuedFunction expr)
        Convert a string typed expression into a money type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toMoney

        public static ScalarValuedFunction toMoney​(String field,
                                                   String format)
        Convert a string typed field into a money type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert strings to money
        Returns:
        the function that provides the conversion
      • toMoney

        public static ScalarValuedFunction toMoney​(String field,
                                                   NumberFormat format)
        Convert a string typed field into a money type using the given format.
        Parameters:
        field - a field whose type is string
        format - formatter instance to use to convert strings to money
        Returns:
        the function that provides the conversion
      • toMoney

        public static ScalarValuedFunction toMoney​(ScalarValuedFunction expr,
                                                   NumberFormat format)
        Convert a string typed expression into a money type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - formatter instance to use to convert strings to money
        Returns:
        the function that provides the conversion
      • toNumeric

        public static ScalarValuedFunction toNumeric​(String field)
        Convert a string typed field into a numeric type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toNumeric

        public static ScalarValuedFunction toNumeric​(ScalarValuedFunction expr)
        Convert a string typed expression into a numeric type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toNumeric

        public static ScalarValuedFunction toNumeric​(String field,
                                                     String format)
        Convert a string typed field into a numeric type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert strings to numerics
        Returns:
        the function that provides the conversion
      • toNumeric

        public static ScalarValuedFunction toNumeric​(String field,
                                                     NumberFormat format)
        Convert a string typed field into a numeric type using the given format.
        Parameters:
        field - a field whose type is string
        format - formatter instance to use to convert strings to numeric
        Returns:
        the function that provides the conversion
      • toNumeric

        public static ScalarValuedFunction toNumeric​(ScalarValuedFunction expr,
                                                     NumberFormat format)
        Convert a string typed expression into a numeric type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - formatter instance to use to convert strings to numeric
        Returns:
        the function that provides the conversion
      • toBoolean

        public static ScalarValuedFunction toBoolean​(String field,
                                                     String truth,
                                                     String falsity)
        Convert a string typed field into a boolean type.
        Parameters:
        field - a field whose type is string
        truth - text representing the value of true
        falsity - text representing the value of false
        Returns:
        the function that provides the conversion
      • toBoolean

        public static ScalarValuedFunction toBoolean​(ScalarValuedFunction expr,
                                                     String truth,
                                                     String falsity)
        Convert a string typed expression into a boolean type.
        Parameters:
        expr - a function expression whose return type is string
        truth - text representing the value of true
        falsity - text representing the value of false
        Returns:
        the function that provides the conversion
      • toBoolean

        public static ScalarValuedFunction toBoolean​(String field,
                                                     TruthValues mapping)
        Convert a string typed field into a boolean type.
        Parameters:
        field - a field whose type is string
        mapping - a truthvalue mapping between boolean values and strings
        Returns:
        the function that provides the conversion
      • toBoolean

        public static ScalarValuedFunction toBoolean​(ScalarValuedFunction expr,
                                                     TruthValues mapping)
        Convert a string typed expression into a boolean type.
        Parameters:
        expr - a function expression whose return type is string
        mapping - a truthvalue mapping between boolean values and strings
        Returns:
        the function that provides the conversion
      • toDate

        public static ScalarValuedFunction toDate​(String field)
        Convert a string typed field into a date type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toDate

        public static ScalarValuedFunction toDate​(ScalarValuedFunction expr)
        Convert a string typed expression into a date type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toDate

        public static ScalarValuedFunction toDate​(String field,
                                                  String format)
        Convert a string typed field into a date type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert string to date
        Returns:
        the function that provides the conversion
      • toDate

        public static ScalarValuedFunction toDate​(String field,
                                                  DateTimeFormatting format)
        Convert a string typed field into a date type using the given format.
        Parameters:
        field - a field whose type is string
        format - format instance to use to convert string to date
        Returns:
        the function that provides the conversion
      • toDate

        public static ScalarValuedFunction toDate​(ScalarValuedFunction expr,
                                                  DateTimeFormatting format)
        Convert a string typed expression into a date type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - format instance to use to convert string to date
        Returns:
        the function that provides the conversion
      • toTime

        public static ScalarValuedFunction toTime​(String field)
        Convert a string typed field into a time type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toTime

        public static ScalarValuedFunction toTime​(ScalarValuedFunction expr)
        Convert a string typed expression into a time type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toTime

        public static ScalarValuedFunction toTime​(String field,
                                                  String format)
        Convert a string typed field into a time type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert string to time
        Returns:
        the function that provides the conversion
      • toTime

        public static ScalarValuedFunction toTime​(String field,
                                                  DateTimeFormatting format)
        Convert a string typed field into a time type using the given format.
        Parameters:
        field - a field whose type is string
        format - format instance to use to convert string to time
        Returns:
        the function that provides the conversion
      • toTime

        public static ScalarValuedFunction toTime​(ScalarValuedFunction expr,
                                                  DateTimeFormatting format)
        Convert a string typed expression into a time type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - format instance to use to convert string to time
        Returns:
        the function that provides the conversion
      • toTimestamp

        public static ScalarValuedFunction toTimestamp​(String field)
        Convert a string typed field into a timestamp type.
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toTimestamp

        public static ScalarValuedFunction toTimestamp​(ScalarValuedFunction expr)
        Convert a string typed expression into a timestamp type.
        Parameters:
        expr - a function expression whose return type is string
        Returns:
        the function that provides the conversion
      • toTimestamp

        public static ScalarValuedFunction toTimestamp​(String field,
                                                       String format)
        Convert a string typed field into a timestamp type using the given format.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert string to timestamp
        Returns:
        the function that provides the conversion
      • toTimestamp

        public static ScalarValuedFunction toTimestamp​(String field,
                                                       DateTimeFormatting format)
        Convert a string typed field into a timestamp type using the given format.
        Parameters:
        field - a field whose type is string
        format - format instance to use to convert string to timestamp
        Returns:
        the function that provides the conversion
      • toTimestamp

        public static ScalarValuedFunction toTimestamp​(ScalarValuedFunction expr,
                                                       DateTimeFormatting format)
        Convert a string typed expression into a timestamp type using the given format.
        Parameters:
        expr - a function expression whose return type is string
        format - format instance to use to convert string to timestamp
        Returns:
        the function that provides the conversion
      • toString

        public static ScalarValuedFunction toString​(String field)
        Convert a scalar type field into a string value. The default formatting per data type will be used. To specify a format, use toText(String, Format).
        Parameters:
        field - a field whose type is string
        Returns:
        the function that provides the conversion
      • toString

        public static ScalarValuedFunction toString​(ScalarValuedFunction expr)
        Convert the value of an expression into a string value. The default formatting per data type will be used. To specify a format, use toText(String, Format).
        Parameters:
        expr - the expression to convert
        Returns:
        the function that provides the conversion
      • toText

        public static ScalarValuedFunction toText​(String field,
                                                  Format formatter)
        Convert a scalar type field into text using the given format. The format object instance must be able to format the token type of the field being converted.
        Parameters:
        field - a field whose type is string
        formatter - format instance to use to convert values to strings
        Returns:
        the function that provides the conversion
      • toText

        public static ScalarValuedFunction toText​(ScalarValuedFunction expr,
                                                  Format formatter)
        Convert the value of an expression into text using the given format. The format object instance must be able to format the token type of the field being converted.
        Parameters:
        expr - the expression to convert
        formatter - format instance to use to convert values to strings
        Returns:
        the function that provides the conversion
      • toText

        public static ScalarValuedFunction toText​(String field,
                                                  String format)
        Convert a scalar type field into text using the given format. The format specification must be acceptable to a formatter for the token type of the field being converted.
        Parameters:
        field - a field whose type is string
        format - format specification to use to convert values to strings
        Returns:
        the function that provides the conversion
      • toText

        public static ScalarValuedFunction toText​(ScalarValuedFunction expr,
                                                  String format)
        Convert the value of an expression into text using the given format. The format specification must be acceptable to a formatter for the token type of the field being converted.
        Parameters:
        expr - the expression to convert
        format - format specification to use to convert values to strings
        Returns:
        the function that provides the conversion