Operate Function: computeValue() - Aster Execution Engine

Teradata Aster® Developer Guide

Product
Aster Execution Engine
Release Number
7.00.02
Published
July 2017
Language
English (United States)
Last Update
2018-04-13
dita:mapPath
xnl1494366523182.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
ffu1489104705746
lifecycle
previous
Product Category
Software

A ScalarFunction must implement computeValue(). This function is given a RowView, which is an abstract of table row. This row is provided by RowIterator and is run by the scalar execution engine. This function emits ValueHolder to the scalar execution engine and the database.

Below is an example of a simple function that computes the factorial for one given numerical column.

public ValueHolder computeValue(RowView row) {
   this.outputValue_.setNull();
   if (!row.isNullAt(0)) {
      row.getValueAt(0, this.outputValue_);
      long result = this.outputValue_.toLong();
      if (result < 0) {
         throw new ClientVisibleException(
            "negative factorial is not defined: " +
            result);
      } else if (result == 0) {
         result = 1; // 0! = 1
      } else { // result > 0
         for (long i=result-1; i>1; i--) {
            result *= i;
            if (result < 0)
               throw new ClientVisibleException(
               "result overflow " + result);
         }
      }
      this.outputValue_.setLong(result);
   }
   return this.outputValue_;
}

See the scalar-sdk/ directory in the SQL-Analytics SDK for sample user defined scalar functions. For reference information on the user defined scalar functions and other SQL-Analytics API, see the Javadoc reference in the SDK bundle.