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
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionTupleCopier
(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 TypeMethodDescriptionprotected static List
<?> copyList
(com.streambase.sb.DataTypeCopier fieldCopier, CompleteDataType destType, List<?> sourceList) a common method to do the list copingvoid
Copy the fields from the sourceTuple to the destTuple.
-
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
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
-