This section describes how to develop UDF with the Eclipse plug-in and how to run UDF on local. The preparation and implement process is similar to UDF. You can see the example of UDF.   MaxCompute Eclipse plug-in provides two methods to run UDF: Menu Bar and run by right-clicking it.

Run UDF using Menu Bar

  1. Select Run >  > Run Configurations… from the menu bar  and the following dialog box appears:


  2. You can create a new Run Configuration. Select the UDF class and type to be executed, select MaxCompute Project and enter the information of input table. For example:


    In the preceding configuration, Table indicates the input table of UDF. Partitions indicates the partitions from which the data is read, separated by commas. Columns indicates the columns, which are considered as the parameters of UDF to be introduced. The columns are separated by commas.

  3. Click Run to run the program and the running result is displayed in the console:


Run by right-clicking

  1. Select a udf.java file (such as UDFExample.java) and right-click it. Then select Run As  > > Run UDF|UDAF|UDTF:


  2. The configuration information is shown as follows:


    In the preceding configuration, Table indicates the input table of UDF. Partitions indicates the partitions from which the data is read, separated by commas. Columns indicates the columns, which are considered as the parameters of UDF to be introduced. The columns are separated by commas.

  3. Click Finish to run UDF and get the output result.

Running customized UDF program

Right-click a project and select New  > >UDF (or select the menu bar File >  > New >  > UDF).

Enter the UDF class name and click Finish.  Generate a Java file in corresponding src directory with the same name as this UDF class. Edit this java file as follows:

package odps;
import com.aliyun.odps.udf.UDF;
public class UserUDF extends UDF {
      
       * project: example_project 
       * table: wc_in1 
       * columns: col1,col2
        
       
      public String evaluate(String a, String b) {
        return "ss2s:" + a + "," + b;
      }

Right-click this java file (such as UserUDF.java) and select Run As ->  ODPS UDF|UDTF|UDAF:



Configure the following dialog box:



Click Finish to get the result:

ss2s:A1,A2
ss2s:A1,A2
ss2s:A1,A2
ss2s:A1,A2

Only the operation instance of UDF is described in this section, and the way of UDTF operating is basically similar to the UDF.