public abstract class Tuple extends Object implements Cloneable, com.streambase.sb.internal.CloneableData, Serializable
To create a new Tuple
object, use the Schema.createTuple()
method on
a Schema
instance.
The DataType
of each Field must be appropriate for the get and set methods invoked on the
Field. For example, the Tuple.getDouble(Schema.Field)
& Tuple.setDouble(Schema.Field, double)
methods work
only on double fields. The Tuple.setField(Schema.Field, Object)
will do default conversions from
different types.
For performance-critical paths, use the type-specific get and set methods that take a parameter of type Schema.Field
(as opposed
to the the methods that take an int or a String).
Note that all methods accepting a Schema.Field
argument will throw an IllegalArgumentException
if the Field object was not obtained from the Schema
associated with this Tuple
instance (Tuple.getSchema()
).
This class is not thread safe. If instances of this class are accessed from multiple threads, access must be synchronized.
Note: Serializations of instances of this class that are created (e.g., by using
ObjectOutputStream
) in one version of StreamBase in general will not be
deserializable in any other version of StreamBase.
Modifier and Type | Class and Description |
---|---|
static class |
Tuple.DefaultTupleFormatter
A default formatter that converts each type to String using Java
default String conversions.
|
static interface |
Tuple.SetResult
An interface containing flags returned from certain setXXXX calls
|
static interface |
Tuple.TupleFormatter
This interface is not public API, and should not be implemented by users.
|
Modifier and Type | Field and Description |
---|---|
protected static int |
CREATE_IF_NULL
during a get create tuple if it is null
|
static Tuple |
EMPTY_TUPLE |
protected static int |
NO_FLAGS
no flags
|
static String |
NULL_STRING
The default String representation of a null valued field (value "null")
|
protected static int |
THROW_ON_NULL
during a get throw an exception on null
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkType(Schema.Field resolvedField,
DataType dataType) |
protected int |
checkTypeAndNonNull(Schema.Field resolvedField,
DataType dataType)
check the type and make sure it is non null
|
abstract void |
clear()
Sets all of this tuple's fields to null values.
|
Tuple |
clone()
Clone this tuple, the new tuple will not share any buffers or data with the original
|
void |
copyField(Schema.Field sourceField,
Tuple destTuple,
Schema.Field destField)
Copy the field from this tuple to the destination tuple
|
protected void |
copyTuple(Tuple sourceTuple)
copy the source tuple to this tuple
|
abstract Tuple |
createReadOnlyTuple()
Return a new tuple that is guaranteed to be read only
|
abstract Tuple |
createWritableTuple()
Return a new tuple that is guaranteed to be writable
|
boolean |
equals(Object obj)
Test whether the given object is equal to this one.
|
Tuple |
getAllocatedTuple(int fieldIndex)
Return a reference (not a copy) to the specified nested tuple field.
|
Tuple |
getAllocatedTuple(Schema.Field field)
Return a reference (not a copy) to the specified nested tuple field.
|
Tuple |
getAllocatedTuple(String fieldPathName)
Return a reference (not a copy) to the specified nested tuple field.
|
ByteArrayView |
getBlobBuffer(int fieldIndex)
Return a ByteArrayView for a given blob field.
|
ByteArrayView |
getBlobBuffer(Schema.Field field)
Return a ByteArrayView for a given blob field.
|
ByteArrayView |
getBlobBuffer(String fieldPathName)
Return a ByteArrayView for a given blob field.
|
boolean |
getBoolean(int fieldIndex)
Return the value of the boolean field at a specified field index.
|
boolean |
getBoolean(Schema.Field field)
Return the value of a specified boolean field.
|
boolean |
getBoolean(String fieldPathName)
Return the value of a named boolean field.
|
Tuple |
getCapture(int fieldIndex)
Return the value of the named capture field.
|
Tuple |
getCapture(Schema.Field field)
Return the value of the named capture field.
|
Tuple |
getCapture(String fieldPathName)
Return the value of the named capture field.
|
protected abstract Tuple |
getCaptureImpl(Schema.Field field) |
double |
getDouble(int fieldIndex)
Return the value of the double field at a specified field index.
|
double |
getDouble(Schema.Field field)
Return the value of a specified double field.
|
double |
getDouble(String fieldPathName)
Return the value of a named double field.
|
Object |
getField(int fieldIndex)
Return the value of the field at a specified field index.
|
Object |
getField(Schema.Field field)
Return the value of a specified field.
|
Object |
getField(String fieldPathName)
Return the value of a named field.
|
String |
getFieldAsString(Schema.Field field,
Tuple.TupleFormatter formatter)
Get the current field as a human readable string, using the
Tuple.TupleFormatter provided. |
Map<String,Object> |
getFields()
Deprecated.
|
Function |
getFunction(int fieldIndex)
Return the value of the function field at a specified field index.
|
Function |
getFunction(Schema.Field field)
Return the value of the given function field.
|
Function |
getFunction(String fieldName)
Return the value of the named function field.
|
int |
getInt(int fieldIndex)
Return the value of the int field at a specified field index.
|
int |
getInt(Schema.Field field)
Return the value of a specified int field.
|
int |
getInt(String fieldPathName)
Return the value of a named int field.
|
List<?> |
getList(int fieldIndex)
Return the value of the list field at a specified field index.
|
List<?> |
getList(Schema.Field field)
Return the value of a specified list field.
|
List<?> |
getList(String fieldPathName)
Return the value of a named list field.
|
long |
getLong(int fieldIndex)
Return the value of the long field at a specified field index.
|
long |
getLong(Schema.Field field)
Return the value of a specified long field.
|
long |
getLong(String fieldPathName)
Return the value of a named long field.
|
Schema |
getSchema()
Return the Schema for this Tuple
|
String |
getString(int fieldIndex)
Return the value of the named string field.
|
String |
getString(Schema.Field field)
Return the value of a specified string field.
|
String |
getString(String fieldPathName)
Return the value of the named string field.
|
Timestamp |
getTimestamp(int fieldIndex)
Return the value of the timestamp field at a specified field index.
|
Timestamp |
getTimestamp(Schema.Field field)
Return the value of a specified timestamp field.
|
Timestamp |
getTimestamp(String fieldPathName)
Return the value of a named timestamp field.
|
Tuple |
getTuple(int fieldIndex)
Return a reference (not a copy) to the specified nested tuple field.
|
Tuple |
getTuple(Schema.Field field)
Return a reference (not a copy) to the specified nested tuple field.
|
Tuple |
getTuple(String fieldPathName)
Return a reference (not a copy) to the specified nested tuple field.
|
static Tuple.TupleFormatter |
getTupleFormatter()
Returns a shared instance of the default tuple field formatter that converts each type
to String using Java default String conversions.
|
int |
hashCode()
Compute a hashCode for the object.
|
boolean |
isNull(int fieldIndex)
Determines whether a field in the tuple is null.
|
boolean |
isNull(Schema.Field field)
Determines whether the given field's value in this Tuple is null.
|
boolean |
isNull(String fieldPathName)
Determines whether a field in the tuple is null.
|
abstract boolean |
isReadOnly()
Returns true if this is a read only tuple
(read only tuples throw an UnsupportedOperationException when setter methods are called)
|
void |
serialize(com.streambase.sb.util.ByteOrderedDataOutput output)
Serialize this tuple into a ByteOrderedDataOutput
|
abstract void |
serialize(com.streambase.sb.util.ByteOrderedDataOutput output,
int tupleId)
Serialize this tuple into a ByteOrderedDataOutput while specifing the
tupleId.
|
void |
setBlobBuffer(int fieldIndex,
ByteArrayView value)
Set the blob field at a specified field index to a copy of a specified blob.
|
void |
setBlobBuffer(Schema.Field field,
ByteArrayView value)
Set a specified blob field to a copy of a specified blob.
|
void |
setBlobBuffer(String fieldPathName,
ByteArrayView value)
Set a named blob field to a copy of a specified blob.
|
void |
setBoolean(int fieldIndex,
boolean value)
Set the boolean field at a specified field index to a specified value.
|
void |
setBoolean(Schema.Field field,
boolean value)
Set a named boolean field to a specified value.
|
void |
setBoolean(String fieldPathName,
boolean value)
Set a named boolean field to a specified value.
|
void |
setCapture(int field,
Tuple value)
Set a specified capture field to a copy of a specified tuple.
|
void |
setCapture(Schema.Field field,
Tuple value)
Set a specified capture field to a copy of a specified tuple.
|
void |
setCapture(String field,
Tuple value)
Set a specified capture field to a copy of a specified tuple.
|
void |
setDouble(int fieldIndex,
double value)
Set the double field at a specified field index to a specified value.
|
void |
setDouble(Schema.Field field,
double value)
Set a named double field to a specified value.
|
void |
setDouble(String fieldPathName,
double value)
Set a named double field to a specified value.
|
void |
setField(int fieldIndex,
Object value)
Set the field at a specified field index to a specified boxed value.
|
void |
setField(Schema.Field field,
Object value)
Set a specified field to a specified boxed value.
|
void |
setField(Schema.Field field,
Object value,
com.streambase.sb.util.CSV.FormatInfo format)
Set the field at a specified field name to a specified boxed value.
|
void |
setField(String fieldPathName,
Object value)
Set the named field to a specified value.
|
void |
setField(String fieldPathName,
Object value,
com.streambase.sb.util.CSV.FormatInfo format)
Set the field at a specified field name to a specified boxed value.
|
void |
setFields(Map<String,Object> fields)
Takes a map of field names and values as Objects and sets the corresponding tuple field with the supplied value.
|
void |
setFunction(int field,
Function value)
Set a specified function field to the given
Function |
void |
setFunction(Schema.Field field,
Function value)
Set a specified function field to the given
Function |
void |
setFunction(String field,
Function value)
Set a specified function field to the given
Function |
void |
setInt(int fieldIndex,
int value)
Set the int field at a specified field index to a specified value.
|
void |
setInt(Schema.Field field,
int value)
Set a specified int field to a specified value.
|
void |
setInt(String fieldPathName,
int value)
Set the named int field to a specified value.
|
void |
setList(int fieldIndex,
List<?> value)
Set the list field at a specified field index to a copy of the specified value.
|
void |
setList(Schema.Field field,
List<?> value)
Set a specified list field to a copy of a specified value.
|
void |
setList(String fieldPathName,
List<?> value)
Set a named list field to a copy of a specified value.
|
void |
setLong(int fieldIndex,
long value)
Set the long field at a specified field index to a specified value.
|
void |
setLong(Schema.Field field,
long value)
Set a specified long field to a specified value.
|
void |
setLong(String fieldPathName,
long value)
Set a named long field to a specified value.
|
void |
setNull(int fieldIndex)
Set the field at a specified field index to null.
|
void |
setNull(Schema.Field field)
Set the specified field to null
|
void |
setNull(String fieldPathName)
Set a named field to null.
|
void |
setString(int fieldIndex,
CharSequence value)
Set the string field at a specified field index to a specified value.
|
void |
setString(Schema.Field field,
CharSequence value)
Set a specified string field to a specified value.
|
void |
setString(String fieldPathName,
CharSequence value)
Set a named field to a specified value.
|
void |
setTimestamp(int fieldIndex,
Timestamp value)
Set the timestamp field at a specified field index to a specified value.
|
void |
setTimestamp(Schema.Field field,
Timestamp value)
Set a named timestamp field to a specified value.
|
void |
setTimestamp(String fieldPathName,
Timestamp value)
Set a named timestamp field to a specified value.
|
void |
setTuple(int fieldIndex,
Tuple value)
Set a specified nested tuple field to that of the specified tuple.
|
void |
setTuple(Schema.Field field,
Tuple value)
Set a specified nested tuple field to that of the specified tuple
NOTE: A copy of the the tuple may be made to convert the given tuple to the appropriate
internal representation.
|
void |
setTuple(String fieldPathName,
Tuple value)
Set a named nested tuple field to a specified tuple.
|
String |
toDelimitedString(char delimiter)
Return the tuple as a string delimited by the given character.
|
Map<String,Object> |
toMapView()
Returns a view on this Tuple that implements the Map<String, Object> interface.
|
String |
toString(boolean verbose)
Return a string representation of this Tuple.
|
String |
toString(char delimiter,
boolean verbose)
Deprecated.
|
String |
toString(char delimiter,
char quoteChar,
boolean verbose)
Return a string representation of this Tuple.
|
String |
toString(char delimiter,
char quoteChar,
boolean verbose,
boolean showTupleId)
Return a string representation of this Tuple.
|
String |
toString(char delimiter,
char quoteChar,
boolean verbose,
boolean showTupleId,
String nullString)
Return a string representation of this Tuple.
|
String |
toString(char delimiter,
char quoteChar,
boolean verbose,
String nullString)
Return a string representation of this Tuple.
|
public static final Tuple EMPTY_TUPLE
protected static final int NO_FLAGS
protected static final int THROW_ON_NULL
protected static final int CREATE_IF_NULL
public static final String NULL_STRING
public abstract boolean isReadOnly()
public Tuple clone() throws CloneNotSupportedException
clone
in interface com.streambase.sb.internal.CloneableData
clone
in class Object
CloneNotSupportedException
public final Schema getSchema()
public abstract void clear()
public final void serialize(com.streambase.sb.util.ByteOrderedDataOutput output)
output
- the output streampublic abstract void serialize(com.streambase.sb.util.ByteOrderedDataOutput output, int tupleId)
Tuple.serialize(ByteOrderedDataOutput)
output
- the output streamtupleId
- the tupleId to attach to this tupleTuple.serialize(ByteOrderedDataOutput)
public final boolean getBoolean(String fieldPathName) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedpublic final boolean getBoolean(int fieldIndex) throws TupleException, NullValueException
fieldIndex
- the index of the field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic boolean getBoolean(Schema.Field field) throws TupleException, NullValueException
field
- the field to getTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedpublic final double getDouble(String fieldPathName) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedpublic final double getDouble(int fieldIndex) throws TupleException, NullValueException
fieldIndex
- the index of the field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic double getDouble(Schema.Field field) throws TupleException, NullValueException
field
- the double field to getTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedpublic final int getInt(String fieldPathName) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedpublic final int getInt(int fieldIndex) throws TupleException, NullValueException
fieldIndex
- the index of the field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic int getInt(Schema.Field field) throws TupleException, NullValueException
field
- the int field to getTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedpublic final long getLong(String fieldPathName) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedpublic final long getLong(int fieldIndex) throws TupleException, NullValueException
fieldIndex
- the index of the field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic long getLong(Schema.Field field) throws TupleException, NullValueException
field
- the long field to getTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedpublic final List<?> getList(String fieldPathName) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedpublic final List<?> getList(int fieldIndex) throws TupleException, NullValueException
fieldIndex
- the index of the field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic List<?> getList(Schema.Field field) throws TupleException, NullValueException
field
- the list field to getTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedpublic final String getString(String fieldPathName) throws TupleException, NullValueException
Tuple.getField(String)
.fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedpublic final String getString(int fieldIndex) throws TupleException, NullValueException
Tuple.getField(String)
.fieldIndex
- the index of the field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic String getString(Schema.Field field) throws TupleException, NullValueException
field
- the fieldTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedpublic final Timestamp getTimestamp(String fieldPathName) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedpublic final Timestamp getTimestamp(int fieldIndex) throws TupleException, NullValueException
fieldIndex
- the index of the field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic Timestamp getTimestamp(Schema.Field field) throws TupleException, NullValueException
field
- the Timestamp field to getTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedpublic final ByteArrayView getBlobBuffer(String fieldPathName) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedpublic final ByteArrayView getBlobBuffer(int fieldIndex) throws TupleException, NullValueException
fieldIndex
- the index of the field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic ByteArrayView getBlobBuffer(Schema.Field field) throws TupleException, NullValueException
field
- the field to getTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedpublic Tuple getTuple(Schema.Field field) throws TupleException, NullValueException
Tuple.setTuple(Schema.Field, Tuple)
.field
- the field to getTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the Field providedTuple.getAllocatedTuple(Schema.Field)
public Tuple getAllocatedTuple(Schema.Field field) throws TupleException
Tuple.setTuple(Schema.Field, Tuple)
to update the parent tuple.field
- the field to getTupleException
- if there was a conversion errorpublic final Tuple getTuple(String fieldPathName) throws TupleException, NullValueException
Tuple.setTuple(String, Tuple)
.fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedTuple.getAllocatedTuple(String)
public final Tuple getAllocatedTuple(String fieldPathName) throws TupleException
Tuple.setTuple(Schema.Field, Tuple)
to update the parent tuple.fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- if there was a conversion errorpublic final Tuple getTuple(int fieldIndex) throws TupleException, NullValueException
Tuple.setTuple(int, Tuple)
.fieldIndex
- the index of a field to get (starting at 0)TupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is null or a null sub-field was encountered while traversing to the field providedTuple.getAllocatedTuple(int)
public final Tuple getAllocatedTuple(int fieldIndex) throws TupleException
Tuple.setTuple(Schema.Field, Tuple)
to update the parent tuple.fieldIndex
- the index of a field to get (starting at 0)TupleException
- if there was a conversion errorpublic final Tuple getCapture(Schema.Field field) throws TupleException
field
- the field to getTupleException
- on error with the capture fieldpublic final Tuple getCapture(String fieldPathName) throws NullValueException, TupleException
fieldPathName
- the field to getTupleException
- on error with the capture fieldNullValueException
- if the value of the field is nullpublic final Tuple getCapture(int fieldIndex) throws NullValueException, TupleException
fieldIndex
- the index of the field to getTupleException
- on error with the capture fieldNullValueException
- if the value of the field is nullprotected abstract Tuple getCaptureImpl(Schema.Field field) throws TupleException
TupleException
public final Object getField(Schema.Field field)
field
- the field to getRuntimeException
- if the field doesn't existpublic final Object getField(int fieldIndex) throws TupleException
fieldIndex
- the index of the field to get (starting at 0)TupleException
- if the field doesn't existpublic final String getFieldAsString(Schema.Field field, Tuple.TupleFormatter formatter)
Tuple.TupleFormatter
provided.
StreamBase provides a default formatter via Tuple.getTupleFormatter()
as a convenience.field
- the field to getformatter
- used to format the field valueRuntimeException
- if there was a conversion error or if the field doesn't exist (also applies to fields
contained in a field of type Tuple whose current value is null)public final Object getField(String fieldPathName) throws TupleException
Escaping field names and path segments:
Path name segments may begin with #"
(hash, double-quote) and end with "
(double-quote) in order to escape
normally disallowed characters. When using this syntax, all inner quotes and backslashes must be escaped with
backslashes, similar to syntax used for SSQL string literals.
fieldPathName
- the path name of the field to getTupleException
- if the field doesn't existpublic final boolean isNull(String fieldPathName) throws TupleException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- when a field with the given path name does not exist in this Tuplepublic final boolean isNull(int fieldIndex) throws TupleException
fieldIndex
- the index (0-based) of the field to check for a null valueTupleException
- when a field with the given path name does not exist in this Tuplepublic boolean isNull(Schema.Field field)
The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Field object that has been created by the user or retrieved from a different Schema will not work.
field
- the field to check for a null valuepublic final void setBoolean(String fieldPathName, boolean value) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic final void setBoolean(int fieldIndex, boolean value) throws TupleException, NullValueException
fieldIndex
- The index of the field to set (starting at 0)value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic void setBoolean(Schema.Field field, boolean value) throws TupleException
field
- the field to setvalue
- the value to set the field toTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setDouble(String fieldPathName, double value) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic final void setDouble(int fieldIndex, double value) throws TupleException, NullValueException
fieldIndex
- The index of the field to set (starting at 0)value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic void setDouble(Schema.Field field, double value) throws TupleException
field
- the field to setvalue
- the value to set the field toTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setInt(String fieldPathName, int value) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic final void setInt(int fieldIndex, int value) throws TupleException, NullValueException
fieldIndex
- The index of the field to set (starting at 0)value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic void setInt(Schema.Field field, int value) throws TupleException
field
- the field to setvalue
- the value to set the field toTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setBlobBuffer(String fieldPathName, ByteArrayView value) throws TupleException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field to. This can be null to set the field to null.TupleException
- if there was a conversion error or if the field doesn't existpublic final void setBlobBuffer(int fieldIndex, ByteArrayView value) throws TupleException
fieldIndex
- The index of the field to set (starting at 0)value
- the value to set the field to. This can be null to set the field to null.TupleException
- if there was a conversion error or if the field doesn't existpublic void setBlobBuffer(Schema.Field field, ByteArrayView value) throws TupleException
field
- the field to setvalue
- the value to set the field to. This can be null to set the field to null.TupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setLong(String fieldPathName, long value) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic final void setLong(int fieldIndex, long value) throws TupleException, NullValueException
fieldIndex
- The index of the field to set (starting at 0)value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic void setLong(Schema.Field field, long value) throws TupleException
field
- the field to setvalue
- the value to set the field toTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setList(String fieldPathName, List<?> value) throws TupleException, NullValueException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic final void setList(int fieldIndex, List<?> value) throws TupleException, NullValueException
fieldIndex
- The index of the field to set (starting at 0)value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value of the field is nullpublic void setList(Schema.Field field, List<?> value) throws TupleException
field
- the field to setvalue
- the value to set the field toTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setString(String fieldPathName, CharSequence value) throws TupleException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field to. This can be null to set the field to null.TupleException
- if there was a conversion error or if the field doesn't existpublic final void setString(int fieldIndex, CharSequence value) throws TupleException
fieldIndex
- The index of the field to set (starting at 0)value
- the value to set the field to. This can be null to set the field to null.TupleException
- if there was a conversion error or if the field doesn't existpublic final void setString(Schema.Field field, CharSequence value) throws TupleException
field
- The field to setvalue
- the value to set the field to. This can be null to set the field to null.TupleException
- if there was a conversion error or if the field doesn't existpublic final void setTimestamp(String fieldPathName, Timestamp value) throws TupleException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existpublic final void setTimestamp(int fieldIndex, Timestamp value) throws TupleException
fieldIndex
- The index of the field to set (starting at 0)value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existpublic void setTimestamp(Schema.Field field, Timestamp value) throws TupleException
field
- The field to setvalue
- the value to set the field toTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setTuple(String fieldPathName, Tuple value) throws TupleException
NOTE: A copy of the tuple may be made to convert the given tuple to the appropriate
internal representation. Use Tuple.getAllocatedTuple(String)
if you require a
reference (not a copy) of the nested tuple to achieve a zero copy setTuple. For example:
Tuple nestedReference = tuple.getAllocatedTuple("fieldName"); nestedReference.set...; nestedReference.set...; // tuple.setTuple("fieldName", nestedReference); is not needed
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existpublic final void setTuple(int fieldIndex, Tuple value) throws TupleException
NOTE: A copy of the tuple may be made to convert the given tuple to the appropriate
internal representation. Use Tuple.getAllocatedTuple(Schema.Field)
if you require a
reference (not a copy) of the nested tuple to achieve a zero copy setTuple. For example:
Tuple nestedReference = tuple.getAllocatedTuple(field); nestedReference.set...; nestedReference.set...; // tuple.setTuple("fieldName", nestedReference); is not needed
fieldIndex
- the index of the field to set (starting at 0)value
- the value to set the field toTupleException
- if there was a conversion error or if the field doesn't existpublic void setTuple(Schema.Field field, Tuple value) throws TupleException
Tuple.getAllocatedTuple(Schema.Field)
if you require a reference (not a copy) of the nested tuple
For a zero copy setTuple do the following:
Tuple nestedReference = tuple.getAllocatedTuple(field); nestedReference.set...; nestedReference.set...; // tuple.setTuple(field, nestedReference); is not needed and // in fact would cause an extra copy
field
- the field to setvalue
- the tuple to set the field toTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic Map<String,Object> getFields()
Tuple.toMapView()
Tuple.toMapView()
public void setFields(Map<String,Object> fields) throws TupleException
fields
- map of field names and valuesTupleException
- thrown if there was a conversion errorpublic final void setCapture(Schema.Field field, Tuple value) throws TupleException
field
- the field to setvalue
- the value to set the field to. Must be of the correct type for this capture fieldTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setCapture(String field, Tuple value) throws TupleException
field
- the field to setvalue
- the value to set the field to. Must be of the correct type for this capture fieldTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setCapture(int field, Tuple value) throws TupleException
field
- the field to setvalue
- the value to set the field to. Must be of the correct type for this capture fieldTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final Function getFunction(int fieldIndex) throws TupleException
fieldIndex
- the index of the field to get (starting at 0)Function
for the given fieldTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic final Function getFunction(String fieldName) throws TupleException
fieldName
- the name of the field to getFunction
for the given fieldTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic final Function getFunction(Schema.Field field) throws TupleException
field
- the field to getFunction
for the given fieldTupleException
- if there was a conversion error or if the field doesn't existNullValueException
- if the value is nullpublic final void setFunction(int field, Function value) throws TupleException
Function
field
- the index of the field to setvalue
- the value to set the field to. Must be of the correct type for this function field.TupleException
- if there was a value conversion error, or the field doesn't exist in this Tuple.public final void setFunction(String field, Function value) throws TupleException
Function
field
- the name or path of the field to setvalue
- the value to set the field to. Must be of the correct type for this function fieldTupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setFunction(Schema.Field field, Function value) throws TupleException
Function
field
- the field to setvalue
- the value to set the field to. Must be of the correct type for this function field.
This can be null to set this field to null.TupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setField(String fieldPathName, Object value) throws TupleException
See Tuple.setField(Schema.Field, Object)
for a discussion of possible conversions of the value.
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.value
- the value to set the field to. This can be null to set the
field to null.TupleException
- if there was a conversion error or if the field doesn't existpublic final void setField(String fieldPathName, Object value, com.streambase.sb.util.CSV.FormatInfo format) throws TupleException
See Tuple.setField(Schema.Field, Object)
for a discussion of possible conversions of the value.
fieldPathName
- the name of the field to setvalue
- the value to set the field to. This can be null to set the
field to null.format
- the FormatInfo to use when parsing items, such as timestamp strings, in the value.TupleException
- if there was a conversion error or if the field doesn't existpublic final void setField(int fieldIndex, Object value) throws TupleException
See Tuple.setField(Schema.Field, Object)
for a discussion of possible conversions of the value.
fieldIndex
- the index of the field to set (starting at 0)value
- the value to set the field to. This can be null to set the
field to null.TupleException
- if there was a conversion error or if the field doesn't existpublic final void setField(Schema.Field field, Object value) throws TupleException
If the value is not a natural type for the type of the specified field, this method attempts to convert the value based on the field's type. (A "natural type" for a field type is the Java type that is acceptable to a type-specific setXxx() method for that field. In the list below, the natural types for each StreamBase type are listed in parentheses after each type.)
Conversions:
Integer
), double (Double
), long (Long
)String
(with Object.toString()
) and an attempt is made to
parse the string into a numeric value of the required type.Boolean
):String
):ByteArrayView
and byte[]
are assigned by converting the bytes to a string
using an internal StreamBase conversion routine.
For all other value types, the value is
converted to a String
with Object.toString()
.Timestamp
):Date
are converted with
Timestamp.Timestamp(java.util.Date)
. Numeric value types
are treated as a number of seconds (time interval).ByteArrayView
):String
, it's
converted to an array of bytes, representing the ASCII encoding of the string's characters
unless overridden by the setting of the streambase.tuple-charset
Java property.Tuple
):String
, it's parsed
as a CSV-formatted list of field values (e.g., "1,foo").
List
):String
, it's parsed
as a square-bracketed, CSV-formatted list of element values (e.g., "[1,3,5]").
If a conversion is required but none of the above conversions apply, a TupleException
exception is thrown
Note on CSV (comma-separated values) format: In the case of list or tuple fields which themselves contain list or tuple values, care must be taken to properly use double quotes where necessary. (The presence of commas in those nested values in the CSV string requires them to be surrounded by quotes. Further nesting may require increased quoting.) See RFC 4180 for details on CSV format.
field
- field to setvalue
- the value to set the field to. This can be null to set the
field to null.TupleException
- if there was a value conversion error, the field doesn't exist in this Tuple or while traversing
to a sub-field a null value was encounteredpublic final void setField(Schema.Field field, Object value, com.streambase.sb.util.CSV.FormatInfo format) throws TupleException
See Tuple.setField(Schema.Field, Object)
for a discussion of possible conversions of the value.
field
- field to setvalue
- the value to set the field to. This can be null to set the
field to null.format
- the FormatInfo to use when parsing items, such as timestamp strings, in the value.TupleException
- if there was a conversion error or if the field doesn't existpublic final void setNull(String fieldPathName) throws TupleException
fieldPathName
- the path name of the field to get. See Tuple.getField(String)
for notes on path segment syntax.TupleException
- thrown when the Field cannot be foundpublic final void setNull(int fieldIndex)
fieldIndex
- the index of the field to set to null (starting at 0)public void setNull(Schema.Field field)
field
- the field to set to nullpublic String toString(boolean verbose)
verbose
- should field names and tuple id (if available) be included?public String toString(char delimiter, boolean verbose)
delimiter
- the character to insert between each fieldverbose
- should field names and tuple id (if available) be included?Tuple.toString(char,char,boolean)
public String toString(char delimiter, char quoteChar, boolean verbose)
delimiter
- the character to insert between each fieldquoteChar
- the character used to surround string fieldsverbose
- should field names and tuple id (if available) be included?public String toString(char delimiter, char quoteChar, boolean verbose, boolean showTupleId)
delimiter
- the character to insert between each fieldquoteChar
- the character used to surround string fieldsverbose
- should field names be included?showTupleId
- should the tuple id, if available, be shown?public String toString(char delimiter, char quoteChar, boolean verbose, String nullString)
delimiter
- the character to insert between each fieldquoteChar
- the character used to surround string fieldsverbose
- should field names and tuple id (if available) be included?nullString
- the string to use for null field valuespublic String toString(char delimiter, char quoteChar, boolean verbose, boolean showTupleId, String nullString)
delimiter
- the character to insert between each fieldquoteChar
- the character used to surround string fieldsverbose
- should field names be included?showTupleId
- should the tuple id, if available, be shown?nullString
- the string to use for null field valuespublic boolean equals(Object obj)
public int hashCode()
public String toDelimitedString(char delimiter)
delimiter
- the delimiterpublic abstract Tuple createWritableTuple()
public abstract Tuple createReadOnlyTuple()
public void copyField(Schema.Field sourceField, Tuple destTuple, Schema.Field destField) throws TupleException
sourceField
- the source fielddestTuple
- the destination tupledestField
- the destination fieldTupleException
- if type mismatch, missing fieldspublic Map<String,Object> toMapView()
The keys of this map are the field names of the schema of this tuple.
The values of this map are the current values of this map. These values are the
same as returned by Tuple.getField(String)
.
Map<String, Object>.get(Object key) will return a null for fields that are null and that do not exist in this Tuple. Use Map<String, Object>.containsKey(Object key) to determine if a key is a valid field in this Tuple.
Repeated calls to Tuple.toMapView()
will return the same instance of Map<String, Object>.
This Map<String, Object> does not support any remove operations. This Map is backed by a Tuple with a fixed schema. Any modify operations that attempt to address keys that are not in the fixed schema are not supported.
public static Tuple.TupleFormatter getTupleFormatter()
Tuple.DefaultTupleFormatter
.Tuple.TupleFormatter
instance suitable for use in Tuple.getFieldAsString(Schema.Field, TupleFormatter)
protected int checkTypeAndNonNull(Schema.Field resolvedField, DataType dataType) throws TupleException
resolvedField
- resolved fielddataType
- data typeTupleException
- on errorprotected void checkType(Schema.Field resolvedField, DataType dataType) throws TupleException
TupleException
protected void copyTuple(Tuple sourceTuple) throws TupleException
sourceTuple
- source tuple to be copiedTupleException
- on error