User Defined Functions
This page describes how to write UDFs for Lenses SQL.
Last updated
Was this helpful?
Was this helpful?
public interface UserDefinedFunctionVarArg extends UserDefinedFunction {
String name();
/**
* Defines a mapping from input to output types.
*
* @param argTypes List of argument data types.
* @return The resulting data type.
* @throws UdfException if one or more of the given data types are not supported by this UDF.
*/
DataType typer(List<DataType> argTypes) throws UdfException;
/**
* Evaluates this UDF for the given argument.
*
* @param args List of arguments.
* @return The result of the evaluation.
* @throws UdfException if the evaluation failed for some reason.
*/
Value evaluate(List<Value> args) throws UdfException;
}SELECT STREAM foo(bar1,bar2,bar3) FROM source;public interface UserDefinedFunctionVarArg extends UserDefinedFunction {
DataType typer(List<DataType> argTypes) throws UdfException {
for (DataType dt : argTypes) {
if (!dt.isString()) {
throw new UdfException("Invalid argument. Function foo only accepts String types.");
}
}
return new LTInt();
}
}public interface UserDefinedFunctionVarArg extends UserDefinedFunction {
Value evaluate(List<Value> args) throws UdfException {
int result = 0;
for (Value value : args) {
int v = Integer.parseInt(value.get());
result += v;
}
return result;
}
}