Argument Clauses for Java Functions - 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

Often it is useful to let the calling SQL query pass a runtime argument to the SQL-Analytics function in order to modify the behavior of the function. To support this, the API provides the useArgumentClause method for declaring argument clauses. An argument clause can contain multiple values, and a function can accept multiple argument clauses. See Query Syntax for an explanation of how the SQL user passes clauses and values.

Do not confuse argument clauses with input data. Input data, provided in the ON clause, provides the data the function operates on, while an argument clause typically sets an operating parameter the analyst has chosen to use in this running of the function.

Below is an example that passes an argument of tax rate and computes the final price for the inventory. You declare argument clauses when you declare your RuntimeContract, as shown here:

public class Final_Price implements ScalarFunction {
   // ...
   private double taxRateValue_;
   public Final_Price(ScalarRuntimeContract contract) {
      // Argument clause
      String taxRateName = "tax";
      String ArgErrorMsg = "function final_price() expects a numeric " +
               " value for" + taxRateName + " argument clause";
      ArgumentClause taxRateClause =
            contract.useArgumentClause(taxRateName);
      String taxRateValueStr = taxRateClause.getSingleValue();
      try {
         this.taxRateValue_ = Double.parseDouble(taxRateValueStr);
      } catch (NullPointerException e) {
         throw new IllegalUsageException(ArgErrorMsg);
      } catch (NumberFormatException e) {
         throw new IllegalUsageException(ArgErrorMsg);
      }
      // Specify the output and complete the contract.
      // ...
   }
   // ...
}

After you have defined the argument clauses shown in the example above, the user of your function can pass arguments in the SQL query. See Additional UDSF/UDAF Invocation Examples.