Interface Tuple
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractTuple, Row
A tuple is an immutable ordered finite list (sequence) of elements.
Allows both native primitive access and generic access by ordinal,
which will incur boxing overhead for primitives.
It is invalid to use the native primitive interface to retrieve a value that is null, instead a user must check `isNullAt` before attempting to retrieve a value that might be null.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleananyNull()Returns true if the tuple has null/missing values.default Objectapply(int i) Returns the value at position i.default ObjectReturns the value by field name.get(int i) Returns the value at position i.default ObjectReturns the value by field name.default <T> T[]getArray(int i) Returns the value at position i of array type.default <T> T[]Returns the field value of array type.default <T> TgetAs(int i) Returns the value at position i.default <T> TReturns the value of a given fieldName.default booleangetBoolean(int i) Returns the value at position i as a primitive boolean.default booleangetBoolean(String field) Returns the field value as a primitive boolean.default bytegetByte(int i) Returns the value at position i as a primitive byte.default byteReturns the field value as a primitive byte.default chargetChar(int i) Returns the value at position i as a primitive byte.default charReturns the field value as a primitive byte.default LocalDategetDate(int i) Returns the value at position i of date type as java.time.LocalDate.default LocalDateReturns the field value of date type as java.time.LocalDate.default LocalDateTimegetDateTime(int i) Returns the value at position i of date type as java.time.LocalDateTime.default LocalDateTimegetDateTime(String field) Returns the field value of date type as java.time.LocalDateTime.default BigDecimalgetDecimal(int i) Returns the value at position i of decimal type as java.math.BigDecimal.default BigDecimalgetDecimal(String field) Returns the field value of decimal type as java.math.BigDecimal.default doublegetDouble(int i) Returns the value at position i as a primitive double.default doubleReturns the field value as a primitive double.default floatgetFloat(int i) Returns the value at position i as a primitive float.default floatReturns the field value as a primitive float.default intgetInt(int i) Returns the value at position i as a primitive int.default intReturns the field value as a primitive int.default longgetLong(int i) Returns the value at position i as a primitive long.default longReturns the field value as a primitive long.default StringgetScale(int i) Returns the value at position i of NominalScale or OrdinalScale.default StringReturns the field value of NominalScale or OrdinalScale.default shortgetShort(int i) Returns the value at position i as a primitive short.default shortReturns the field value as a primitive short.default StringgetString(int i) Returns the value at position i as a String object.default StringReturns the field value as a String object.default TuplegetStruct(int i) Returns the value at position i of struct type.default TupleReturns the field value of struct type.default LocalTimegetTime(int i) Returns the value at position i of date type as java.time.LocalTime.default LocalTimeReturns the field value of date type as java.time.LocalTime.default intReturns the index of a given field name.default booleanisNullAt(int i) Checks whether the value at the given position is null.default booleanChecks whether the field value is null.default intlength()Returns the number of elements in the Tuple.static Tupleof(StructType schema, double[] row) Returns a double array based tuple.static Tupleof(StructType schema, int[] row) Returns an integer array based tuple.static Tupleof(StructType schema, Object[] row) Returns an object array based tuple.static Tupleof(StructType schema, ResultSet rs) Returns the current row of a JDBC ResultSet as a tuple.schema()Returns the schema of tuple.default double[]toArray(boolean bias, CategoricalEncoder encoder, String... fields) Return an array obtained by converting the fields to numeric mode.default double[]Return an array obtained by converting the fields to numeric mode.default StringtoString(int i) Returns the string representation of the value at position i.default StringReturns the string representation of the field value.
-
Method Details
-
schema
-
length
default int length()Returns the number of elements in the Tuple.- Returns:
- the number of elements in the Tuple.
-
toArray
Return an array obtained by converting the fields to numeric mode. Missing values/nulls will be encoded as Double.NaN.- Parameters:
fields- the fields to export. If empty, all fields will be used.- Returns:
- the tuple as an array of doubles.
-
toArray
Return an array obtained by converting the fields to numeric mode. Missing values/nulls will be encoded as Double.NaN.- Parameters:
bias- if true, add the first element of 1.encoder- the categorical variable encoder.fields- the fields to export. If empty, all fields will be used.- Returns:
- the tuple as an array of doubles.
-
get
Returns the value at position i. The value may be null.- Parameters:
i- the index of field.- Returns:
- the field value.
-
get
-
apply
-
apply
-
isNullAt
default boolean isNullAt(int i) Checks whether the value at the given position is null.- Parameters:
i- the index of field.- Returns:
- true if the field value is null.
-
isNullAt
Checks whether the field value is null.- Parameters:
field- the name of field.- Returns:
- true if the field value is null.
-
anyNull
default boolean anyNull()Returns true if the tuple has null/missing values.- Returns:
- true if the tuple has null/missing values.
-
getBoolean
default boolean getBoolean(int i) Returns the value at position i as a primitive boolean.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getBoolean
Returns the field value as a primitive boolean.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getChar
default char getChar(int i) Returns the value at position i as a primitive byte.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getChar
Returns the field value as a primitive byte.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getByte
default byte getByte(int i) Returns the value at position i as a primitive byte.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getByte
Returns the field value as a primitive byte.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getShort
default short getShort(int i) Returns the value at position i as a primitive short.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getShort
Returns the field value as a primitive short.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getInt
default int getInt(int i) Returns the value at position i as a primitive int.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getInt
Returns the field value as a primitive int.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getLong
default long getLong(int i) Returns the value at position i as a primitive long.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getLong
Returns the field value as a primitive long.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getFloat
default float getFloat(int i) Returns the value at position i as a primitive float. Throws an exception if the type mismatches or if the value is null.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getFloat
Returns the field value as a primitive float. Throws an exception if the type mismatches or if the value is null.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getDouble
default double getDouble(int i) Returns the value at position i as a primitive double.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getDouble
Returns the field value as a primitive double.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.NullPointerException- when value is null.
-
getString
Returns the value at position i as a String object.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getString
Returns the field value as a String object.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
toString
Returns the string representation of the value at position i.- Parameters:
i- the index of field.- Returns:
- the string representation of field value.
-
toString
-
getDecimal
Returns the value at position i of decimal type as java.math.BigDecimal.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getDecimal
Returns the field value of decimal type as java.math.BigDecimal.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getDate
Returns the value at position i of date type as java.time.LocalDate.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getDate
Returns the field value of date type as java.time.LocalDate.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getTime
Returns the value at position i of date type as java.time.LocalTime.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getTime
Returns the field value of date type as java.time.LocalTime.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getDateTime
Returns the value at position i of date type as java.time.LocalDateTime.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getDateTime
Returns the field value of date type as java.time.LocalDateTime.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getScale
Returns the value at position i of NominalScale or OrdinalScale.- Parameters:
i- the index of field.- Returns:
- the field scale.
-
getScale
Returns the field value of NominalScale or OrdinalScale.- Parameters:
field- the name of field.- Returns:
- the field scale.
- Throws:
ClassCastException- when the data is not nominal or ordinal.
-
getArray
default <T> T[] getArray(int i) Returns the value at position i of array type.- Type Parameters:
T- the data type of array elements.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getArray
Returns the field value of array type.- Type Parameters:
T- the data type of array elements.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getStruct
Returns the value at position i of struct type.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getStruct
Returns the field value of struct type.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getAs
default <T> T getAs(int i) Returns the value at position i. For primitive types if value is null it returns 'zero value' specific for primitive i.e. 0 for Int - use isNullAt to ensure that value is not null- Type Parameters:
T- the data type of field.- Parameters:
i- the index of field.- Returns:
- the field value.
- Throws:
ClassCastException- when data type does not match.
-
getAs
Returns the value of a given fieldName. For primitive types if value is null it returns 'zero value' specific for primitive i.e. 0 for Int - use isNullAt to ensure that value is not null- Type Parameters:
T- the data type of field.- Parameters:
field- the name of field.- Returns:
- the field value.
- Throws:
UnsupportedOperationException- when schema is not defined.IllegalArgumentException- when fieldName do not exist.ClassCastException- when data type does not match.
-
indexOf
Returns the index of a given field name.- Parameters:
field- the name of field.- Returns:
- the field index.
- Throws:
IllegalArgumentException- when a field `name` does not exist.
-
of
Returns an object array based tuple.- Parameters:
schema- the schema of tuple.row- the object array.- Returns:
- the tuple.
-
of
Returns a double array based tuple.- Parameters:
schema- the schema of tuple.row- the double array.- Returns:
- the tuple.
-
of
Returns an integer array based tuple.- Parameters:
schema- the schema of tuple.row- the int array.- Returns:
- the tuple.
-
of
Returns the current row of a JDBC ResultSet as a tuple.- Parameters:
schema- the schema of tuple.rs- the JDBC ResultSet.- Returns:
- the tuple.
- Throws:
SQLException- when JDBC operation fails.
-