Package com.exasol

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 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 - if next 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 mismatches
        ExaDataTypeException - 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 as Integer.

        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 or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - 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 as Long.

        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 or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - 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 as BigDecimal.

        This can be used for the SQL data types DECIMAL(p, 0) and DECIMAL(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 or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - 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 as Double.

        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 or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - 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 as String.

        This can be used for the SQL data type VARCHAR and CHAR.

        Parameters:
        column - index of the column, starting with 0
        Returns:
        value of the specified column of the current row as a String object or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - 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 as Boolean.

        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 or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - 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 as Date.

        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 or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - 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 as Object.

        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 or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - 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 as Object.

        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 or null if the column value is NULL
        Throws:
        ExaIterationException - if used with invalid iterator position
        ExaDataTypeException - if requesting a value of an incompatible data type