Class BasicFieldTransformer
java.lang.Object
com.northconcepts.datapipeline.transform.Transformer
com.northconcepts.datapipeline.transform.FieldTransformer
com.northconcepts.datapipeline.transform.BasicFieldTransformer
See
FieldPath for supported field name expressions.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA named step that aBasicFieldTransformerapplies to each of its fields.static classAnBasicFieldTransformer.Operationapplied to each single value in a field, including array elements and values in nested records.static classABasicFieldTransformer.SingleValueOperationthat transforms the string form of each value into a new string. -
Constructor Summary
ConstructorsConstructorDescriptionBasicFieldTransformer(String name) BasicFieldTransformer(String... names) BasicFieldTransformer(Collection<String> names) -
Method Summary
Modifier and TypeMethodDescriptionadd(BasicFieldTransformer.Operation... operation) Appends operations that run, in the order added, on each named field.addExceptionProperties(DataException exception) Adds this transformer's details to an exception raised by its host reader or writer; returns the same exception.Appendssuffixto each value, treating null values as empty strings.Converts 16-byte values (most significant bits first) to UUIDs; other lengths cause an exception.dateTimeToString(String pattern) Formats date-time values using the givenSimpleDateFormatpattern in the default time zone.dateTimeToString(String pattern, String timeZoneId) Formats date-time values using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT).dateTimeToString(DateFormat format) dateToString(String pattern) Formats date values using the givenSimpleDateFormatpattern in the default time zone.dateToString(String pattern, String timeZoneId) Formats date values using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT).dateToString(DateFormat format) Converts numbers of days since the epoch to dates (midnight in the default time zone); other values are left unchanged.Converts numbers of days since the epoch to date-times; other values are left unchanged.delete(int start, int end) Removes the characters from the 0-basedstart(inclusive) toend(exclusive, capped at the value's length).Converts empty string tonull, otherwise the original value is returned.flattenToString(String fieldSeparator) Replaces array and record values with a string of their nested values separated byfieldSeparator; null fields are left as is.Returns the last exception an operation threw on the most recently transformed field ornullif none did.Converts numbers of hours since the epoch to dates (midnight in the default time zone); other values are left unchanged.Converts numbers of hours since the epoch to date-times; other values are left unchanged.Insertstextat the 0-basedindex, or appends it if the value is not longer thanindex.Converts intervals to their millisecond part as a long, ignoring any months and years.Converts intervals to their month part as an int (a year counts as 12 months), ignoring days and smaller units.Converts intervals to the whole seconds in their millisecond part as a long, ignoring any months and years.Converts intervals to the whole years in their month part as an int, ignoring days and smaller units.booleanIndicates if exceptions thrown by operations are ignored so the remaining operations still run; the last one is kept ingetException()(default is false).left(int length) Keeps the firstlengthcharacters of each value; shorter values are unchanged.Converts values to lower case using the default locale.Converts the first character of each value to lower case, leaving the rest unchanged.Converts numbers of milliseconds since the epoch to dates (midnight in the default time zone); other values are left unchanged.Converts numbers of milliseconds since the epoch to date-times; other values are left unchanged.Converts numbers of minutes since the epoch to dates (midnight in the default time zone); other values are left unchanged.Converts numbers of minutes since the epoch to date-times; other values are left unchanged.nullToExpression(String expressionAsString) Replaces null values with the result of the given expression, evaluated against the current record.nullToValue(boolean value) Replaces null values with the given boolean.nullToValue(byte value) Replaces null values with the given byte.nullToValue(byte[] value) Replaces null values with the given bytes.nullToValue(char value) Replaces null values with the given character.nullToValue(double value) Replaces null values with the given double.nullToValue(float value) Replaces null values with the given float.nullToValue(int value) Replaces null values with the given int.nullToValue(long value) Replaces null values with the given long.nullToValue(short value) Replaces null values with the given short.nullToValue(String value) Replaces null values with the given string.nullToValue(BigDecimal value) Replaces null values with the given big decimal.nullToValue(BigInteger value) Replaces null values with the given big integer.nullToValue(Date value) Replaces null values with the given date.nullToValue(Time value) Replaces null values with the given time.nullToValue(Instant value) Replaces null values with the given instant.nullToValue(LocalDate value) Replaces null values with the given local date.nullToValue(LocalDateTime value) Replaces null values with the given local date-time.nullToValue(LocalTime value) Replaces null values with the given local time.nullToValue(Date value) Replaces null values with the given date-time.Converts numeric values to big integers, truncating any fraction.Converts the field's value totrueif non-zero, otherwisefalse.numberToDate(long multiplier) Converts numbers to dates by multiplying them bymultiplierto get milliseconds since the epoch and clearing the time of day in the default time zone; other values are left unchanged.protected BasicFieldTransformernumberToDate(String operationName, long multiplier) Adds an operation namedoperationNamethat converts numbers to dates by multiplying them bymultiplierto get milliseconds since the epoch and clearing the time of day in the default time zone; other values are left unchanged.numberToDateTime(long multiplier) Converts numbers to date-times by multiplying them bymultiplierto get milliseconds since the epoch; other values are left unchanged.protected BasicFieldTransformernumberToDateTime(String operationName, long multiplier) Adds an operation namedoperationNamethat converts numbers to date-times by multiplying them bymultiplierto get milliseconds since the epoch; other values are left unchanged.Converts numbers to intervals of that many days; other values are left unchanged.Converts numbers to intervals of that many hours; other values are left unchanged.Converts numeric values to ints, truncating any fraction.numberToInterval(String unitName) Converts numbers to intervals of that manyunitNameunits (millisecond, second, minute, hour, day, week, month or year; singular or plural, any case); other values are left unchanged.protected BasicFieldTransformernumberToInterval(String operationName, String unitName) Adds an operation namedoperationNamethat converts numbers to intervals of that manyunitNameunits; other values are left unchanged.Converts numeric values to longs, truncating any fraction.Converts numbers to intervals of that many milliseconds; other values are left unchanged.Converts numbers to intervals of that many minutes; other values are left unchanged.Converts numbers to intervals of that many months; other values are left unchanged.Converts numbers to intervals of that many seconds; other values are left unchanged.numberToString(String pattern) Formats numeric values with aDecimalFormatof the given pattern, converting them to double first.numberToString(DecimalFormat format) Formats numeric values with the givenDecimalFormat, converting them to double first.Converts numbers to intervals of that many years; other values are left unchanged.padLeft(int length, char padChar) Pads values on the left withpadCharup tolengthcharacters; longer values are unchanged and null values are padded as empty strings.padRight(int length, char padChar) Pads values on the right withpadCharup tolengthcharacters; longer values are unchanged and null values are padded as empty strings.Prependsprefixto each value, treating null values as empty strings.Replaces the characters from the 0-basedstart(inclusive) toend(exclusive, capped at the value's length) withstring.replaceAll(CharSequence regex, CharSequence replacement) Replaces every match of the regular expressionregexwithreplacement($nrefers to a captured group).replaceChar(char oldChar, char newChar) Replaces every occurrence ofoldCharwithnewChar.replaceFirst(CharSequence regex, CharSequence replacement) Replaces the first match of the regular expressionregexwithreplacement($nrefers to a captured group).replaceString(CharSequence oldString, CharSequence newString) Replaces every literal (non-regex) occurrence ofoldStringwithnewString.right(int length) Keeps the lastlengthcharacters of each value; shorter values are unchanged.Rounds numeric values with the givenRounder, producing doubles.Converts numbers of seconds since the epoch to dates (midnight in the default time zone); other values are left unchanged.Converts numbers of seconds since the epoch to date-times; other values are left unchanged.setContinueOnException(boolean continueOnException) Indicates if exceptions thrown by operations are ignored so the remaining operations still run; the last one is kept ingetException()(default is false).Parses values as big decimals usingnew BigDecimal(String).Parses values as big integers usingnew BigInteger(String).Converts the string "true" (ignoring case) totrueand any other value tofalse.stringToBoolean(boolean lenient) Converts a string to a boolean.Parses values as bytes usingByte.valueOf.Converts values to their first character, or the NUL character for empty strings.stringToDate(String pattern) Parses values as dates (java.sql.Date) using the givenSimpleDateFormatpattern in the default time zone.stringToDate(String pattern, String timeZoneId) Parses values as dates (java.sql.Date) using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT).stringToDateTime(String pattern) Parses values as date-times using the givenSimpleDateFormatpattern in the default time zone.stringToDateTime(String pattern, String timeZoneId) Parses values as date-times using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT).Parses values as doubles usingDouble.valueOf.stringToDouble(String pattern) Parses values as doubles using aDecimalFormatwith the given pattern.stringToDouble(DecimalFormat format) Parses values as doubles using the givenDecimalFormat.Parses values as floats usingFloat.valueOf.Parses values as ints usingInteger.valueOf.Parses values as longs usingLong.valueOf.Parses values as shorts usingShort.valueOf.stringToTime(String pattern) Parses values as times (java.sql.Time) using the givenSimpleDateFormatpattern in the default time zone.stringToTime(String pattern, String timeZoneId) Parses values as times (java.sql.Time) using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT).Parses values as UUIDs usingUUID.fromString.substring(int begin) Keeps the characters from the 0-basedbeginto the end; values shorter thanbeginbecome empty strings.substring(int begin, int end) Keeps the characters from the 0-basedbegin(inclusive) toend(exclusive); values shorter thanendbecome empty strings.timeToString(String pattern) Formats time values using the givenSimpleDateFormatpattern in the default time zone.timeToString(String pattern, String timeZoneId) Formats time values using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT).timeToString(DateFormat format) protected voidtransformField(Field field) Transforms the given field in place; called for each named field found in the record.trim()Removes leading and trailing characters up to and including U+0020 (the space), such as tabs and line breaks.trimLeft()Removes leading characters up to and including U+0020 (the space), such as tabs and line breaks.trimLeft(char padChar) Removes all leading occurrences of the given character.Removes trailing characters up to and including U+0020 (the space), such as tabs and line breaks.trimRight(char padChar) Removes all trailing occurrences of the given character.Converts values to upper case using the default locale.Converts the first character of each value to upper case, leaving the rest unchanged.Converts UUIDs to 16-byte arrays, most significant bits first.valueToNull(Object object) Converts a field tonullif its value matches the specified parameter.Methods inherited from class com.northconcepts.datapipeline.transform.FieldTransformer
getCurrentField, getCurrentRecord, getName, getNames, getNamesAsStrings, getValueOnException, hasValueOnException, isThrowExceptionOnMissingField, setThrowExceptionOnMissingField, setValueOnException, toString, transformMethods inherited from class com.northconcepts.datapipeline.transform.Transformer
close, geEndpoint, getEndpoint, getReader, getWriter, of, open, setWriter
-
Constructor Details
-
BasicFieldTransformer
-
BasicFieldTransformer
-
BasicFieldTransformer
-
-
Method Details
-
isContinueOnException
public boolean isContinueOnException()Indicates if exceptions thrown by operations are ignored so the remaining operations still run; the last one is kept ingetException()(default is false). -
setContinueOnException
Indicates if exceptions thrown by operations are ignored so the remaining operations still run; the last one is kept ingetException()(default is false). -
getException
Returns the last exception an operation threw on the most recently transformed field ornullif none did. -
add
Appends operations that run, in the order added, on each named field. -
transformField
Description copied from class:FieldTransformerTransforms the given field in place; called for each named field found in the record.- Specified by:
transformFieldin classFieldTransformer- Throws:
Throwable
-
addExceptionProperties
Description copied from class:TransformerAdds this transformer's details to an exception raised by its host reader or writer; returns the same exception.- Overrides:
addExceptionPropertiesin classFieldTransformer
-
valueToString
-
nullToValue
Replaces null values with the given string. -
nullToValue
Replaces null values with the given date-time. -
nullToValue
Replaces null values with the given date. -
nullToValue
Replaces null values with the given time. -
nullToValue
Replaces null values with the given int. -
nullToValue
Replaces null values with the given long. -
nullToValue
Replaces null values with the given big integer. -
nullToValue
Replaces null values with the given short. -
nullToValue
Replaces null values with the given byte. -
nullToValue
Replaces null values with the given boolean. -
nullToValue
Replaces null values with the given character. -
nullToValue
Replaces null values with the given big decimal. -
nullToValue
Replaces null values with the given double. -
nullToValue
Replaces null values with the given float. -
nullToValue
Replaces null values with the given bytes. -
nullToValue
Replaces null values with the given instant. -
nullToValue
Replaces null values with the given local date-time. -
nullToValue
Replaces null values with the given local date. -
nullToValue
Replaces null values with the given local time. -
nullToExpression
Replaces null values with the result of the given expression, evaluated against the current record. -
lowerCase
Converts values to lower case using the default locale. -
upperCase
Converts values to upper case using the default locale. -
lowerCaseFirstChar
Converts the first character of each value to lower case, leaving the rest unchanged. -
upperCaseFirstChar
Converts the first character of each value to upper case, leaving the rest unchanged. -
trim
Removes leading and trailing characters up to and including U+0020 (the space), such as tabs and line breaks. -
trimLeft
Removes leading characters up to and including U+0020 (the space), such as tabs and line breaks. -
trimRight
Removes trailing characters up to and including U+0020 (the space), such as tabs and line breaks. -
trimLeft
Removes all leading occurrences of the given character. -
trimRight
Removes all trailing occurrences of the given character. -
padLeft
Pads values on the left withpadCharup tolengthcharacters; longer values are unchanged and null values are padded as empty strings. -
padRight
Pads values on the right withpadCharup tolengthcharacters; longer values are unchanged and null values are padded as empty strings. -
left
Keeps the firstlengthcharacters of each value; shorter values are unchanged. -
right
Keeps the lastlengthcharacters of each value; shorter values are unchanged. -
substring
Keeps the characters from the 0-basedbegin(inclusive) toend(exclusive); values shorter thanendbecome empty strings. -
substring
Keeps the characters from the 0-basedbeginto the end; values shorter thanbeginbecome empty strings. -
append
Appendssuffixto each value, treating null values as empty strings. -
prepend
Prependsprefixto each value, treating null values as empty strings. -
insert
Insertstextat the 0-basedindex, or appends it if the value is not longer thanindex. -
delete
Removes the characters from the 0-basedstart(inclusive) toend(exclusive, capped at the value's length). -
replace
Replaces the characters from the 0-basedstart(inclusive) toend(exclusive, capped at the value's length) withstring. -
replaceChar
Replaces every occurrence ofoldCharwithnewChar. -
replaceString
Replaces every literal (non-regex) occurrence ofoldStringwithnewString. -
replaceAll
Replaces every match of the regular expressionregexwithreplacement($nrefers to a captured group). -
replaceFirst
Replaces the first match of the regular expressionregexwithreplacement($nrefers to a captured group). -
stringToByte
Parses values as bytes usingByte.valueOf. -
stringToShort
Parses values as shorts usingShort.valueOf. -
stringToInt
Parses values as ints usingInteger.valueOf. -
stringToLong
Parses values as longs usingLong.valueOf. -
stringToBigInteger
Parses values as big integers usingnew BigInteger(String). -
stringToBigDecimal
Parses values as big decimals usingnew BigDecimal(String). -
stringToDouble
Parses values as doubles usingDouble.valueOf. -
stringToDouble
Parses values as doubles using the givenDecimalFormat. -
stringToDouble
Parses values as doubles using aDecimalFormatwith the given pattern. -
stringToFloat
Parses values as floats usingFloat.valueOf. -
stringToBoolean
Converts the string "true" (ignoring case) totrueand any other value tofalse. -
stringToBoolean
Converts a string to a boolean. Thelenientflag indicates if "yes", "on", and "1" should also be treated astrue. -
stringToChar
Converts values to their first character, or the NUL character for empty strings. -
stringToDateTime
Parses values as date-times using the givenSimpleDateFormatpattern in the default time zone. -
stringToDateTime
Parses values as date-times using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT). -
stringToDate
Parses values as dates (java.sql.Date) using the givenSimpleDateFormatpattern in the default time zone. -
stringToDate
Parses values as dates (java.sql.Date) using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT). -
stringToTime
Parses values as times (java.sql.Time) using the givenSimpleDateFormatpattern in the default time zone. -
stringToTime
Parses values as times (java.sql.Time) using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT). -
numberToInt
Converts numeric values to ints, truncating any fraction. -
numberToLong
Converts numeric values to longs, truncating any fraction. -
numberToBigInteger
Converts numeric values to big integers, truncating any fraction. -
numberToBigDecimal
-
numberToDouble
-
numberToBoolean
Converts the field's value totrueif non-zero, otherwisefalse. -
numberToString
Formats numeric values with the givenDecimalFormat, converting them to double first. -
numberToString
Formats numeric values with aDecimalFormatof the given pattern, converting them to double first. -
round
Rounds numeric values with the givenRounder, producing doubles. -
numberToDateTime
Adds an operation namedoperationNamethat converts numbers to date-times by multiplying them bymultiplierto get milliseconds since the epoch; other values are left unchanged. -
numberToDateTime
Converts numbers to date-times by multiplying them bymultiplierto get milliseconds since the epoch; other values are left unchanged. -
millisecondsToDateTime
Converts numbers of milliseconds since the epoch to date-times; other values are left unchanged. -
secondsToDateTime
Converts numbers of seconds since the epoch to date-times; other values are left unchanged. -
minutesToDateTime
Converts numbers of minutes since the epoch to date-times; other values are left unchanged. -
hoursToDateTime
Converts numbers of hours since the epoch to date-times; other values are left unchanged. -
daysToDateTime
Converts numbers of days since the epoch to date-times; other values are left unchanged. -
numberToDate
Adds an operation namedoperationNamethat converts numbers to dates by multiplying them bymultiplierto get milliseconds since the epoch and clearing the time of day in the default time zone; other values are left unchanged. -
numberToDate
Converts numbers to dates by multiplying them bymultiplierto get milliseconds since the epoch and clearing the time of day in the default time zone; other values are left unchanged. -
millisecondsToDate
Converts numbers of milliseconds since the epoch to dates (midnight in the default time zone); other values are left unchanged. -
secondsToDate
Converts numbers of seconds since the epoch to dates (midnight in the default time zone); other values are left unchanged. -
minutesToDate
Converts numbers of minutes since the epoch to dates (midnight in the default time zone); other values are left unchanged. -
hoursToDate
Converts numbers of hours since the epoch to dates (midnight in the default time zone); other values are left unchanged. -
daysToDate
Converts numbers of days since the epoch to dates (midnight in the default time zone); other values are left unchanged. -
numberToInterval
Adds an operation namedoperationNamethat converts numbers to intervals of that manyunitNameunits; other values are left unchanged. -
numberToInterval
Converts numbers to intervals of that manyunitNameunits (millisecond, second, minute, hour, day, week, month or year; singular or plural, any case); other values are left unchanged. -
numberToMillisecond
Converts numbers to intervals of that many milliseconds; other values are left unchanged. -
numberToSeconds
Converts numbers to intervals of that many seconds; other values are left unchanged. -
numberToMinutes
Converts numbers to intervals of that many minutes; other values are left unchanged. -
numberToHours
Converts numbers to intervals of that many hours; other values are left unchanged. -
numberToDays
Converts numbers to intervals of that many days; other values are left unchanged. -
numberToMonths
Converts numbers to intervals of that many months; other values are left unchanged. -
numberToYears
Converts numbers to intervals of that many years; other values are left unchanged. -
dateTimeToString
-
dateTimeToString
Formats date-time values using the givenSimpleDateFormatpattern in the default time zone. -
dateTimeToString
Formats date-time values using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT). -
dateToString
-
dateToString
Formats date values using the givenSimpleDateFormatpattern in the default time zone. -
dateToString
Formats date values using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT). -
timeToString
-
timeToString
Formats time values using the givenSimpleDateFormatpattern in the default time zone. -
timeToString
Formats time values using the givenSimpleDateFormatpattern in the given time zone (an unknown ID falls back to GMT). -
dateTimeToDate
-
dateTimeToTime
-
intervalToMilliseconds
Converts intervals to their millisecond part as a long, ignoring any months and years. -
intervalToSeconds
Converts intervals to the whole seconds in their millisecond part as a long, ignoring any months and years. -
intervalToMonths
Converts intervals to their month part as an int (a year counts as 12 months), ignoring days and smaller units. -
intervalToYears
Converts intervals to the whole years in their month part as an int, ignoring days and smaller units. -
flattenToString
Replaces array and record values with a string of their nested values separated byfieldSeparator; null fields are left as is. -
emptyToNull
Converts empty string tonull, otherwise the original value is returned. -
valueToNull
Converts a field tonullif its value matches the specified parameter. -
stringToUuid
Parses values as UUIDs usingUUID.fromString. -
uuidToString
-
bytesToUuid
Converts 16-byte values (most significant bits first) to UUIDs; other lengths cause an exception. -
uuidToBytes
Converts UUIDs to 16-byte arrays, most significant bits first.
-