Class Tuple
Offers quick, efficient, Map-like storage (populating the map is 100% quicker than a HashMap where the keys
are defined according to a Struct. Random access to values is slightly slower (~30%) than with a standard
HashMap. Does not guarantee type correctness in the same way that the Value class does
Tuples are used to store user data as it flows through the pipeline. A tuple is a set of attributes (e.g. a row of input data), but tuples can also be comprised of other tuples (e.g. the 'exposure' tuple contains all the exposure-layer attributes). When a tuple is passed to a user's Python function, it gets converted into a Python dictionary.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumOptions for error suppression/checking when using thecoerce(Struct, Map)method -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Tuple'Helpful' constant for an empty tuple - built fromStruct.EMPTY_STRUCT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Perform a tuple-aware clone of this tuple, performing a shallow copy of the entry array, unless the entry is itself a tuple, which will be recursively clonedstatic Tuplestatic Tuplecoerce(Struct type, Map<?, ?> rawValues, EnumSet<Tuple.CoerceOptions> options) Build a tuple from the given map, applying the type's coercion to the result.booleanintEstimate the number of bytes used to store thisTuplewhen serialized.<T> Tfetch(int index) <T> TReturn a value from the tuple, with an implicit cast to the receiving type<T> Tfetch(Struct.StructMember entry) Return a value from the tuple, with an implicit cast to the receiving typefetchChild(String key) TBD is this actually necessary?The struct defines the shape of the data - the attribute keys and what RiskScapeTypethey are.Shortcut for accessing the type of a memberinthashCode()booleanhasNulls()booleanstatic TupleConvenience constructor for building an empty tuple of this typestatic TupleConvenience constructor for building a tuple with a single key/valuestatic TupleConvenience constructor for building a tuple with two keys/valuesstatic TupleConvenience constructor for building a tuple from an ordered (wrt to the struct) set of valuesvoidClears a value from the tuplevoidremove(@NonNull Struct.StructMember key) Clears a value from the tupleSet a value using its struct indexSet a value by its keyset(@NonNull Struct.StructMember key, Object value) Set a value using aStruct.StructMemberas a keyvoidCopies (appends) the values from the given source tuple into this tuple.voidPopulate this tuple with the given valuesvoidCopies the values from the given source tuple into this tuple.intsize()Object[]toArray()toMap()toString()
-
Field Details
-
EMPTY_TUPLE
'Helpful' constant for an empty tuple - built from
Struct.EMPTY_STRUCT
-
-
Constructor Details
-
Tuple
-
Tuple
-
-
Method Details
-
of
Convenience constructor for building an empty tuple of this type
-
of
Convenience constructor for building a tuple with a single key/value
-
of
Convenience constructor for building a tuple with two keys/values
-
ofValues
Convenience constructor for building a tuple from an ordered (wrt to the struct) set of values
-
coerce
-
coerce
Build a tuple from the given map, applying the type's coercion to the result.
- Parameters:
type- The type to coerce the map torawValues- A map of uncoerced valuesoptions- Options for error handling- Returns:
- a fresh tuple
-
set
Set a value by its key
- Returns:
- this to allow tuple.set("foo", bar).set("baz", foo)...
- Throws:
NoSuchMemberException- if no member named key in underlying struct
-
set
Set a value using a
Struct.StructMemberas a key- Returns:
- this to allow tuple.set("foo", bar).set("baz", foo)...
- Throws:
IllegalArgumentException- if key doesn't belong to struct this tuple is of
-
set
Set a value using its struct index
-
setAll
Populate this tuple with the given values
-
setAll
Copies (appends) the values from the given source tuple into this tuple. Useful when merging or combining tuples together
- Parameters:
source- Tuple containing the values to copydestOffset- The struct index in this tuple to start copying into
-
setAll
Copies the values from the given source tuple into this tuple.
-
remove
Clears a value from the tuple
-
remove
Clears a value from the tuple
-
fetch
Return a value from the tuple, with an implicit cast to the receiving type
-
fetch
Return a value from the tuple, with an implicit cast to the receiving type
- Parameters:
entry- the member of the struct we're fetching. Slightly more efficient than lookup by key
-
fetch
public <T> T fetch(int index) -
fetchChild
TBD is this actually necessary?
-
getType
Shortcut for accessing the type of a member
- Parameters:
key-- Returns:
- Type of member
-
clone
Perform a tuple-aware clone of this tuple, performing a shallow copy of the entry array, unless the entry is itself a tuple, which will be recursively cloned
-
hashCode
public int hashCode() -
equals
-
size
public int size() -
hasNulls
public boolean hasNulls()- Returns:
- if any of this tuples entries are null.
-
hasRequiredNulls
public boolean hasRequiredNulls()- Returns:
- if any of this tuples non-nullable entries are null.
-
estimateSize
public int estimateSize()Estimate the number of bytes used to store this
Tuplewhen serialized.- Returns:
- the number of bytes.
-
toString
-
getValues
- Returns:
- a read-only view on to the underlying values that back this tuple
-
toMap
-
toArray
-
getStruct
The struct defines the shape of the data - the attribute keys and what RiskScape
Typethey are.
-