Using Tuples

Accessing Primitive Types By Index

Heron Tuples support a wide variety of primitive Java types, including
strings, Booleans, byte arrays, and more.
getString
method, for example, takes an integer index and returns either a string or
null if no string value is present at that index. Analogous methods can be
found in the Javadoc.

Accessing Primitive Types By Field

In addition to being accessible via index, values stored in Heron tuples are
accessible via field name as well. The
getStringByField
method, for example, takes a field name string and returns either a string or
null if no string value is present for that field name. Analogous methods can
be found in the Javadoc.

Using Non-primitive Types

In addition to primitive types, you can access any value in a Heron Tuple as a
Java Object. As for primitive types, you can access Objects on the basis of
an index or a field name. The following methods return either an Object or
null if no object is present:

You can also retrieve all objects contained in a Heron Tuple as a Java
List using the
getValues
method.

User-defined Types

You use Heron tuples in conjunction with more complex, user-defined types using
type casting, provided
that you’ve created and registered a custom serializer for the type.
Here’s an example (which assumes that a serializer for the type
Tweet has been created and registered):

publicvoidexecute(Tupleinput){// The following return null if no value is present or throws a
// ClassCastException if type casting fails:
Tweettweet=(Tweet)input.getValue(0);List<Tweet>allTweets=input.getValues();}

Fields

The getFields method returns a
Fields
object that contains all of the fields in the tuple. More on fields can be found
below.

Other Methods

There are additional methods available for determining the size of Heron
Tuples, extracting contextual information, and more. For a full listing of
methods, see the
Javadoc.

Fields

From the methods in the list above you can see that you can retrieve single
values from a Heron tuple on the basis of their index. You can also retrieve
multiple values using a
Fields object,
which can be initialized either using varargs or a list of strings:

// Using varargs
Fieldsfruits=newFields("apple","orange","banana");// Using a list of strings
List<String>fruitNames=newLinkedList<String>();fruitNames.add("apple");// Add "orange" and "banana" as well
Fieldsfruits=newFields(fruitNames);