Package com.streambase.sb
Class TupleCopier
java.lang.Object
com.streambase.sb.TupleCopier
A utility class which copies the fields from one tuple to another. TupleCopier uses the given
schemas to determine which fields to copy from one Tuple to another. The strict flag on the ctor
determines if an Exception is thrown if the fields in the destination schema do not match the fields
in the source schema. Fields are matched by name and type. With the strict flag set to false
the TupleCopier will only copy the fields between the source and destination that match field name
and type. TupleCopier is more efficient than using Tuple's getField(), setField() methods to
copy portions of a tuple. TupleCopier's constructor sets up the TupleCopier so that repeated
calls to copyTuple() are more efficient.
If a full copy is desired Tuple.clone() is probably a more efficient option.
An example usage:
... TupleCopier input2OutputCopier = new TupleCopier(inputSchema, outputSchema, true); while (true) { outputTuple.clear(); input2OutputCopier.copyTuple(getInputTuple(), outputTuple); sendOutput(port, outputTuple); }
- Since:
- 6.4.5
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionTupleCopier
(Schema sourceSchema, Schema destSchema, boolean strict) Create the TupleCopier.TupleCopier
(Schema sourceSchema, Schema destSchema, EnumSet<TupleCopier.Options> options) Create the TupleCopier. -
Method Summary
Modifier and TypeMethodDescription(package private) static void
copyField
(Tuple sourceTuple, Schema.Field sourceField, Tuple destTuple, Schema.Field destField, com.streambase.sb.DataTypeCopier fieldCopier) Copy the field from the source tuple to the destination tupleprotected static List<?>
copyList
(com.streambase.sb.DataTypeCopier fieldCopier, CompleteDataType destType, List<?> sourceList) a common method to do the list coping(package private) List<?>
Copy the given listvoid
Copy the fields from the sourceTuple to the destTuple.(package private) static com.streambase.sb.DataTypeCopier
createCopier
(CompleteDataType sourceType, CompleteDataType destType, EnumSet<TupleCopier.Options> options) Create a DataTypeCopier
-
Constructor Details
-
TupleCopier
Create the TupleCopier. Do some up front error checking and setting up Schema maps. This constructor will create a TupleCopier with #CopyByName semantics.- Parameters:
sourceSchema
- The schema of the source TupledestSchema
- The schema of the destination tuplestrict
- set to true will throw exceptions if schema fields do not match by name and type. Set to false and the TupleCopier will copy only fields that match by name and type.- Throws:
TupleException
- with strict on if the fields do not match by name and type
-
TupleCopier
public TupleCopier(Schema sourceSchema, Schema destSchema, EnumSet<TupleCopier.Options> options) throws TupleException Create the TupleCopier. Do some up front error checking and setting up Schema maps.- Parameters:
sourceSchema
- The schema of the source TupledestSchema
- The schema of the destination tupleoptions
- options fromTupleCopier.Options
- Throws:
TupleException
- with strict on if the fields do not match by name and type- Since:
- 7.0
-
-
Method Details
-
copyTuple
Copy the fields from the sourceTuple to the destTuple. It is assumed that the destination Tuple is either new or has been cleared.- Parameters:
sourceTuple
- the source tupledestTuple
- the cleared destination tuple- Throws:
TupleException
- on field copy errors
-
copyList
Copy the given list- Parameters:
sourceList
- the list to copy- Returns:
- a new list
- Throws:
TupleException
- on error
-
createCopier
static com.streambase.sb.DataTypeCopier createCopier(CompleteDataType sourceType, CompleteDataType destType, EnumSet<TupleCopier.Options> options) throws TupleException Create a DataTypeCopier- Parameters:
sourceType
- source data typedestType
- destination data typeoptions
- copy options- Returns:
- appropriate DataTypeCopier
- Throws:
TupleException
- on error
-
copyField
static void copyField(Tuple sourceTuple, Schema.Field sourceField, Tuple destTuple, Schema.Field destField, com.streambase.sb.DataTypeCopier fieldCopier) throws TupleException Copy the field from the source tuple to the destination tuple- Parameters:
sourceTuple
- source tuplesourceField
- source filedestTuple
- destination tupledestField
- destination fieldfieldCopier
- field copier- Throws:
TupleException
- on error
-
copyList
protected static List<?> copyList(com.streambase.sb.DataTypeCopier fieldCopier, CompleteDataType destType, List<?> sourceList) throws TupleException a common method to do the list coping- Parameters:
fieldCopier
- the field copierdestType
- the dest typesourceList
- the source list- Returns:
- a copy of the list or null if the sourceList was null
- Throws:
TupleException
- on error
-