Develop a Simple Function
Create a class within a Java package that implements Drill’s simple interface into the program, and include the required information for the function type. Your function must include data types that Drill supports, such as int or BigInt. For a list of supported data types, refer to the SQL Reference.
Complete the following steps to develop a simple function using Drill’s simple function interface:
Create a Maven project and add the following dependency:
<dependency> <groupId>org.apache.drill.exec</groupId> <artifactId>drill-java-exec</artifactId> <version>1.0.0-m2-incubating-SNAPSHOT</version> </dependency>
Create a class that implements the
DrillSimpleFunc
interface and identify the scope asFunctionScope.SIMPLE
.Example
@FunctionTemplate(name = "myaddints", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) public static class IntIntAdd implements DrillSimpleFunc {
Provide the variables used in the code in the
Param
andOutput
bit holders.Example
@Param IntHolder in1; @Param IntHolder in2; @Output IntHolder out;
Add the code that performs operations for the function in the
eval()
method.Example
public void setup(RecordBatch b) { } public void eval() { out.value = (int) (in1.value + in2.value); }
Use the maven-source-plugin to compile the sources and classes JAR files. Verify that an empty
drill-module.conf
is included in the resources folder of the JARs.
Drill searches this module during classpath scanning. If the file is not included in the resources folder, you can add it to the JAR file or add it toetc/drill/conf
.