Updated on 2024-08-30 GMT+08:00

UDF Development

This topic describes the rules and suggestions for developing Doris UDF programs.

Doris UDF Development Rules

  • The UDF invocation must be thread-safe.
  • Do not load external large files to the memory when implementing a UDF. Otherwise, the memory could be used up.
  • Avoid a large number of recursive calls. Otherwise, stack overflow or OOM may occur.
  • Do not create objects or arrays continuously. Otherwise, the memory could be used up.
  • Use a Java UDF to capture and process possible exceptions. Do not send exceptions to services. Use the try-catch block to handle exceptions and record exception information if necessary.
  • In the UDF, do not define static collection classes for storing temporary data or query large objects in external data. Otherwise, the memory usage is high.
  • Ensure that the imported packages in the class do not conflict with the packages on the server. You can run the grep -lr "Fully-qualified class name" command to check JAR package conflicts. Use fully-qualified class names to avoid such conflicts.

Doris UDF Development Suggestions

  • To prevent stack memory overflow, do not copy a large amount of data.
  • Do not concatenate a large number of strings. Otherwise, the memory usage is high.
  • Java UDFs should use meaningful names so that other developers can easily understand their purpose. Use camel-case names and end a name with a UDF, for example, MyFunctionUDF.
  • A Java UDF should specify the data type of the return value and must have a return value. Do not set the return value to NULL when it should be the default value or when an exception occurs. Use basic data types or Java classes as return value types.