Updated on 2024-04-02 GMT+08:00

Registering a UDF

  1. Build a JAR file.

    You can build a JAR file in either of the following ways:

    • Method 1:

      Choose Maven, locate the target project name, and double-click clean under Lifecycle to run the clean command of Maven.

      Choose Maven, locate the target project name, and double-click install under Lifecycle to run the install command of Maven.

      Figure 1 Maven clean and install
    • Method 2: Go to the directory where the pom.xml file is located in the Terminal window of IDEA, and run the mvn clean install command to build the file.
      Figure 2 Building result after mvn clean install is entered

      After the build is complete, message "BUILD SUCCESS" is displayed, the target directory is generated, and the generated JAR file is stored in the target directory.

  2. Import the dependent JAR file.

    Log in to the node where IoTDBServer is located as user root, run su - omm to switch to user omm, and import the JAR file generated in 1 to the $BIGDATA_HOME/FusionInsight_IoTDB_*/install/FusionInsight-IoTDB-*/iotdb/ext/udf directory.

    • During cluster deployment, ensure that a corresponding JAR package exists in the UDF JAR package path of each IoTDBServer node. You can modify IoTDB configuration udf_root_dir to specify the root path for the UDF to load JAR files.
    • To view the IP address of the node where IoTDBServer is deployed, log in to the MRS cluster management console, choose Components, click IoTDB, and click the Instances tab.
  3. Run the following SQL statement to register the UDF:

    CREATE FUNCTION <UDF-NAME> AS '<UDF-CLASS-FULL-PATHNAME>'

    For example, you can run the following statement to register a UDF named example:

    CREATE FUNCTION example AS 'com.huawei.bigdata.iotdb.UDTFExample'