- java.lang.Object
-
- com.pervasive.datarush.types.FieldRemappings
-
public class FieldRemappings extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FieldRemappings.Directive
A mapping directive to be applied to a source field.
-
Constructor Summary
Constructors Constructor Description FieldRemappings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FieldRemappings.Directive
drop(String name)
Declares a source field is to be omitted from the result.static FieldRemappings.Directive
keep(String name)
Declares a source field is to be preserved in the result, keeping the same name.static FieldRemappings.Directive
map(String from, String to)
Defines a name mapping from a source to a target field.static FieldRemapping
patternRename(String format, String... excludedFields)
Defines a simple pattern-based renaming fields of a record schema.static FieldRemapping
rename(FieldRemappings.Directive... directives)
Defines a transformation renaming fields of a record schema.static FieldRemapping
renameAndDrop(FieldRemappings.Directive... directives)
Defines a transformation renaming fields of a record schema, dropping source fields without an explicit directive.static FieldRemapping
reorder(FieldRemappings.Directive... directives)
Defines a transformation reordering and possibly renaming fields of a record schema.static FieldRemapping
reorderAndDrop(FieldRemappings.Directive... directives)
Defines a transformation reordering and possibly renaming fields of a record schema, dropping source fields without an explicit directive.
-
-
-
Method Detail
-
drop
public static FieldRemappings.Directive drop(String name)
Declares a source field is to be omitted from the result.This is useful is forcibly removing fields from the source when they otherwise would be kept, for example when using
rename(Directive...)
orreorder(Directive...)
.If the only actions being done are the dropping of unwanted fields, consider using one of
SelectFields
,RetainFields
, orRemoveFields
.- Parameters:
name
- the name of the source field to drop from the target- Returns:
- the declared directive
-
keep
public static FieldRemappings.Directive keep(String name)
Declares a source field is to be preserved in the result, keeping the same name.This is useful if renaming is not desired, but a mapping is needed to produce desired ordering or preserve a field in a type mapping.
- Parameters:
name
- the name of the source field to keep in the target- Returns:
- the declared directive
-
map
public static FieldRemappings.Directive map(String from, String to)
Defines a name mapping from a source to a target field.- Parameters:
from
- the name of the field in the sourceto
- the name of the field in the target- Returns:
- the defined mapping
-
patternRename
public static FieldRemapping patternRename(String format, String... excludedFields)
Defines a simple pattern-based renaming fields of a record schema. The relative order of fields is unchanged. For all fields not explicitly excluded, a supplied formatting pattern is applied to produce the new name.- Parameters:
format
- a pattern for renaming of fields. This is in the syntax supported byMessageFormat
. There will be exactly one argument to format - the name of the field.excludedFields
- names of fields which should not be be renamed.- Returns:
- a transform applying the specified pattern-based renaming
-
rename
public static FieldRemapping rename(FieldRemappings.Directive... directives)
Defines a transformation renaming fields of a record schema. The relative order of fields is unchanged.For example, if the source schema is {"a", "b", "c"} and the directives [ "c"->"Z", "a"->"X" ] are applied, the result is { "X", "b", "Z" }.
Note that in this context, a
keep(java.lang.String)
directive is a no-op.- Parameters:
directives
- the field mapping operations to apply.- Returns:
- a transform applying the supplied directives
-
renameAndDrop
public static FieldRemapping renameAndDrop(FieldRemappings.Directive... directives)
Defines a transformation renaming fields of a record schema, dropping source fields without an explicit directive. The relative order of fields is unchanged.For example, if the source schema is {"a", "b", "c"} and the directives [ "c"->"Z", "a"->"X" ] are applied, the result is { "X", "Z" }.
Note that in this context, a
drop(java.lang.String)
directive is a no-op. Further, this transformation is equivalent to combining a rename operation with aRetainFields
.- Parameters:
directives
- the field mapping operations to apply.- Returns:
- a transform applying the supplied directives
-
reorder
public static FieldRemapping reorder(FieldRemappings.Directive... directives)
Defines a transformation reordering and possibly renaming fields of a record schema. Source fields can be referenced multiple times (using different target names), producing "aliases" of the same field in the result. The order of fields in the result is determined as described below:- Source fields specified in the directives will appear in the same order they are referenced in the directive list.
- Source fields not referenced by any directive will appear after fields specified in the directives, in the same relative order as in the source.
Unlike
rename(Directive...)
, akeep(java.lang.String)
directive does exhibit an effect, controlling the ordering of a field in the result.- Parameters:
directives
- the field mapping operations to apply.- Returns:
- a transform applying the supplied directives
-
reorderAndDrop
public static FieldRemapping reorderAndDrop(FieldRemappings.Directive... directives)
Defines a transformation reordering and possibly renaming fields of a record schema, dropping source fields without an explicit directive. Source fields can be referenced multiple times (using different target names), producing "aliases" of the same field in the result. The order of fields in the result is the same order they are referenced in the directive list.As an example, if the source schema is {"a", "b", "c"} and the directives [ "c"->"Z", "a"->"X" ] are applied, the result is { "Z", "X" }.
Note that in this context, a
drop(java.lang.String)
directive is a no-op. Further, this transformation is equivalent to combining a renaming operation with aSelectFields
.- Parameters:
directives
- the field mapping operations to apply.- Returns:
- a transform applying the supplied directives
-
-