Interface ExaIterator
-
public interface ExaIteratorThis interface enables UDF scripts to iterate over input data and to emit output.Many of the interface functions in this class behave differently depending on whether they are used in the context of a "SCALAR" or a "SET" UDF script. Please refer to the section "UDF Scripts" in the Exasol online guide for an explanation of the two different types.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidemit(Object... values)Emit an output row.BigDecimalgetBigDecimal(int column)Get the value of the column at the given index asBigDecimal.BigDecimalgetBigDecimal(String name)Get the value of the column with the given name asBigDecimal.BooleangetBoolean(int column)Get the value of the column at the given index asBoolean.BooleangetBoolean(String name)Get the value of the column with the given name asBoolean.DategetDate(int column)Get the value of the column at the given index asDate.DategetDate(String name)Get the value of the column with the given name asDate.DoublegetDouble(int column)Get the value of the column at the given index asDouble.DoublegetDouble(String name)Get the value of the column with the given name asDouble.IntegergetInteger(int column)Get the value of the column at the given index asInteger.IntegergetInteger(String name)Get the value of the column with the given name asInteger.LonggetLong(int column)Get the value of the column at the given index asLong.LonggetLong(String name)Get the value of the column at the given index asLong.ObjectgetObject(int column)Get the value of the column at the given index asObject.ObjectgetObject(String name)Get the value of the column with the given name asObject.StringgetString(int column)Get the value of the column at the given index asString.StringgetString(String name)Get the value of the column with the given name asString.TimestampgetTimestamp(int column)Get the value of the column with the given name asTimestamp.TimestampgetTimestamp(String name)Get the value of the column with the given name asTimestamp.booleannext()Move the iterator to the next row of the current group, while there are still rows left.voidreset()Resets the iterator to the first input row.longsize()Get the number of input rows of the script.
-
-
-
Method Detail
-
size
long size() throws ExaIterationException
Get the number of input rows of the script.If this is a "SET" UDF script, this method returns the number of rows for the current group.
If this is a "SCALAR" UDF script, it always returns one. The logic behind this is that the input to a scalar script is a single row.
- Returns:
- number of input rows for this script.
- Throws:
ExaIterationException- if size is not available
-
next
boolean next() throws ExaIterationExceptionMove the iterator to the next row of the current group, while there are still rows left.This method only applies in the context of "SET" UDF scripts.
Initially, the iterator points to the first row, so call this method after processing a row.
The following code can be used to process all rows of a group:public static void run(ExaMetadata meta, ExaIterator iterator) throws Exception { do { // access data here, e.g. with iterator.getString("MY_COLUMN"); } while (iterator.next()); }- Returns:
true, if there is a next row and the iterator was increased to it,false, if there is no more row for this group- Throws:
ExaIterationException- ifnextis used past the end of the iterator
-
reset
void reset() throws ExaIterationExceptionResets the iterator to the first input row.This is only allowed in the context of "SET" UDF scripts.
- Throws:
ExaIterationException- if used outside "SET" script
-
emit
void emit(Object... values) throws ExaIterationException, ExaDataTypeException
Emit an output row.This is only allowed for "SET" UDF scripts.
Note that you can emit using multiple function arguments or an object array:
iterator.emit(1, "a"); iterator.emit(new Object[] { 1, "a" });- Parameters:
values- values for output columns (number must match definition)- Throws:
ExaIterationException- if object count mismatchesExaDataTypeException- if provide object does not match output column type
-
getInteger
Integer getInteger(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asInteger.This can be used for the SQL data type
DECIMAL(p, 0).- Parameters:
column- index of the column, starting at 0- Returns:
- value of the specified column of the current row as an
Integerobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getInteger
Integer getInteger(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asInteger.This can be used for the SQL data type
DECIMAL(p, 0).- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as an
Integerobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getLong
Long getLong(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asLong.This can be used for the SQL data type
DECIMAL(p, 0).- Parameters:
column- index of the column, starting at 0- Returns:
- value of the specified column of the current row as a
Longobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getLong
Long getLong(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asLong.This can be used for the SQL data type
DECIMAL(p, 0).- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as a
Longobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getBigDecimal
BigDecimal getBigDecimal(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asBigDecimal.This can be used for the SQL data types
DECIMAL(p, 0)andDECIMAL(p, s).- Parameters:
column- index of the column, starting with 0- Returns:
- value of the specified column of the current row as a
BigDecimalobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getBigDecimal
BigDecimal getBigDecimal(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asBigDecimal.This can be used for the SQL data types
DECIMAL(p, 0)andDECIMAL(p, s).- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as a
BigDecimalobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getDouble
Double getDouble(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asDouble.This can be used for the SQL data type
DOUBLE.- Parameters:
column- index of the column, starting with 0- Returns:
- value of the specified column of the current row as a
Doubleobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getDouble
Double getDouble(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asDouble.This can be used for the SQL data type
DOUBLE.- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as a
Doubleobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getString
String getString(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asString.This can be used for the SQL data type
VARCHARandCHAR.- Parameters:
column- index of the column, starting with 0- Returns:
- value of the specified column of the current row as a
Stringobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getString
String getString(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asString.This can be used for the SQL data type
VARCHARandCHAR.- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as a
Stringobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getBoolean
Boolean getBoolean(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asBoolean.This can be used for the SQL data type
BOOLEAN.- Parameters:
column- index of the column, starting with 0- Returns:
- value of the specified column of the current row as a
Booleanobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getBoolean
Boolean getBoolean(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asBoolean.This can be used for the SQL data type
BOOLEAN.- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as a
Booleanobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getDate
Date getDate(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asDate.This can be used for the SQL data type
DATE.- Parameters:
column- index of the column, starting with 0- Returns:
- value of the specified column of the current row as a
Dateobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getDate
Date getDate(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asDate.This can be used for the SQL data type
DATE.- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as a
Dateobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getTimestamp
Timestamp getTimestamp(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asTimestamp.This can be used for the SQL data type
TIMESTAMP.- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as a
Timestampobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getTimestamp
Timestamp getTimestamp(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asTimestamp.This can be used for the SQL data type
TIMESTAMP.- Parameters:
column- index of the column, starting with 0- Returns:
- value of the specified column of the current row as a
Timestampobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getObject
Object getObject(int column) throws ExaIterationException, ExaDataTypeException
Get the value of the column at the given index asObject.This can be used for all SQL data types. You have to cast the value appropriately.
- Parameters:
column- index of the column, starting with 0- Returns:
- value of the specified column of the current row as a
Objectobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
getObject
Object getObject(String name) throws ExaIterationException, ExaDataTypeException
Get the value of the column with the given name asObject.This can be used for all SQL data types. You have to cast the value appropriately.
- Parameters:
name- name of the column- Returns:
- value of the specified column of the current row as a
Objectobject ornullif the column value isNULL - Throws:
ExaIterationException- if used with invalid iterator positionExaDataTypeException- if requesting a value of an incompatible data type
-
-