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
Modifier and TypeClassDescriptionstatic enum
Options for error suppression/checking when using thecoerce(Struct, Map)
method -
Field Summary
Modifier and TypeFieldDescriptionstatic final Tuple
'Helpful' constant for an empty tuple - built fromStruct.EMPTY_STRUCT
-
Constructor Summary
-
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 Tuple
static Tuple
coerce
(Struct type, Map<?, ?> rawValues, EnumSet<Tuple.CoerceOptions> options) Build a tuple from the given map, applying the type's coercion to the result.boolean
int
Estimate the number of bytes used to store thisTuple
when serialized.<T> T
fetch
(int index) <T> T
Return a value from the tuple, with an implicit cast to the receiving type<T> T
fetch
(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 RiskScapeType
they are.Shortcut for accessing the type of a memberint
hashCode()
boolean
hasNulls()
boolean
static Tuple
Convenience constructor for building an empty tuple of this typestatic Tuple
Convenience constructor for building a tuple with a single key/valuestatic Tuple
Convenience constructor for building a tuple with two keys/valuesstatic Tuple
Convenience constructor for building a tuple from an ordered (wrt to the struct) set of valuesvoid
Clears a value from the tuplevoid
remove
(@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.StructMember
as a keyvoid
Copies (appends) the values from the given source tuple into this tuple.void
Populate this tuple with the given valuesvoid
Copies the values from the given source tuple into this tuple.int
size()
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.StructMember
as 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
Tuple
when 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
Type
they are.
-