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.
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.