Constructor and Reset - 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

Each function must implement a constructor that takes only a DecomposableAggregatorRuntimeContract. The function class is instantiated during planning of the query, and it informs the system about its properties through the DecomposableAggregatorRuntimeContract. The system fills in various fields in the contract (such as the input schema and the argument clauses) and passes this incomplete contract to the constructor. The constructor must fill in the function's partial and output schema and then complete the contract. Every function must also implement a reset method. This method sets the initial state of the aggregate function for each input partition.

Below is an example of a constructor and reset method for a simple decomposable aggregate function that counts the number of rows for each input partition.

...
// Instance private fields which are initialized
// during contract negotiation.
private RowHolder countRow_;
private ValueHolder countValue_;
private long count_;
private SqlType outputSqlType_;
private ArrayList<SqlType> partialSchema_ = null;

public Count(DecomposableAggregatorRuntimeContract contract) {
   reset();

   //Output Type for count() is always "bigint".
   outputSqlType_ = SqlType.bigint();

   // Construct the output schema of aggregator function.
   ArrayListColumnDefinition outputColumns = new ArrayListColumnDefinition();

   outputColumns.add(new ColumnDefinition("result", outputSqlType_));
   contract.setOutputInfo(new OutputInfo(outputColumns));

   // The partial schema.
   partialSchema_ = new ArrayList<SqlType>();
   partialSchema_.add(outputSqlType_);
   contract.setPartialResultSchema(ImmutableList
            .elementsOf(partialSchema_));
   countValue_ = new ValueHolder(outputSqlType_);

// Allocate a row to hold the aggregated value and initialize it.
countRow_ = new RowHolder(partialSchema_);

// Complete the contract.
contract.complete();
}

public void reset() {
   count_ = 0;
}