Interface ExaIterator
-
public interface ExaIterator
This 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 void
emit(Object... values)
Emit an output row.BigDecimal
getBigDecimal(int column)
Get the value of the column at the given index asBigDecimal
.BigDecimal
getBigDecimal(String name)
Get the value of the column with the given name asBigDecimal
.Boolean
getBoolean(int column)
Get the value of the column at the given index asBoolean
.Boolean
getBoolean(String name)
Get the value of the column with the given name asBoolean
.Date
getDate(int column)
Get the value of the column at the given index asDate
.Date
getDate(String name)
Get the value of the column with the given name asDate
.Double
getDouble(int column)
Get the value of the column at the given index asDouble
.Double
getDouble(String name)
Get the value of the column with the given name asDouble
.Integer
getInteger(int column)
Get the value of the column at the given index asInteger
.Integer
getInteger(String name)
Get the value of the column with the given name asInteger
.Long
getLong(int column)
Get the value of the column at the given index asLong
.Long
getLong(String name)
Get the value of the column at the given index asLong
.Object
getObject(int column)
Get the value of the column at the given index asObject
.Object
getObject(String name)
Get the value of the column with the given name asObject
.String
getString(int column)
Get the value of the column at the given index asString
.String
getString(String name)
Get the value of the column with the given name asString
.Timestamp
getTimestamp(int column)
Get the value of the column with the given name asTimestamp
.Timestamp
getTimestamp(String name)
Get the value of the column with the given name asTimestamp
.boolean
next()
Move the iterator to the next row of the current group, while there are still rows left.void
reset()
Resets the iterator to the first input row.long
size()
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 ExaIterationException
Move 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
- ifnext
is used past the end of the iterator
-
reset
void reset() throws ExaIterationException
Resets 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
Integer
object ornull
if 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
Integer
object ornull
if 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
Long
object ornull
if 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
Long
object ornull
if 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
BigDecimal
object ornull
if 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
BigDecimal
object ornull
if 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
Double
object ornull
if 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
Double
object ornull
if 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
VARCHAR
andCHAR
.- Parameters:
column
- index of the column, starting with 0- Returns:
- value of the specified column of the current row as a
String
object ornull
if 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
VARCHAR
andCHAR
.- Parameters:
name
- name of the column- Returns:
- value of the specified column of the current row as a
String
object ornull
if 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
Boolean
object ornull
if 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
Boolean
object ornull
if 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
Date
object ornull
if 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
Date
object ornull
if 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
Timestamp
object ornull
if 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
Timestamp
object ornull
if 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
Object
object ornull
if 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
Object
object ornull
if the column value isNULL
- Throws:
ExaIterationException
- if used with invalid iterator positionExaDataTypeException
- if requesting a value of an incompatible data type
-
-