PGX 20.2.2

UDF Configuration Guide

This chapter explains the configuration options for PGX User-Defined Functions (UDFs).

Important security notice

UDFs enable running arbitrary code into the PGX server, possibly accessing sensitive data. Additionally, any PGX session can invoke any of the UDFs that are enabled following this configuration guide.

The application administrator who enables UDFs is responsible for checking that:

  • All the UDF code can be trusted.
  • The UDFs are stored in a secure location that cannot be tampered with.

What Can Be Configured?

Each UDF configuration file in the directory specified by the udf_config_directory field in the PGX Engine config contains a list of user-defined functions.

UDF Uniqueness

all defined UDFs must be unique with regards to the combination of the following fields:

  • namespace
  • function_name
  • arguments

Content of UDF Configuration File

A UDF configuration file is a json specification containing an array of user_defined_functions:

Field Type Description Default
user_defined_functionsarray of objectlist of user defined functions[]

Each user defined function supports the following fields:

Field Type Description Default
function_namestringname of the function used as identifier in PGXrequired
languageenum[java, javascript]language the function is implemented inrequired
return_typeenum[boolean, integer, long, float, double, string]return type of the functionrequired
argumentsarray of objectlist of arguments[]
implementation_referencestringreference to the UDF implementation on the classpathnull
namespacestringnamespace of the function in PGXnull
source_codestringsource code of the function provided inlinenull
source_function_namestringname of the function in the source languagenull
source_locationstringsource code of the function provided as a unified resource identifier, either pointing to a a local file (relative to the location of this config or absolute), a web resource (prefix http://' or https://), a HDFS path (prefix hdfs:) or a classpath (prefix classpath:/ or jar:)null

The arguments for a UDF are specified using these fields:

Field Type Description Default
namestringname of the argumentrequired
typeenum[boolean, integer, long, float, double, string]type of the argumentrequired


Java-UDF on Classpath

PGX can load UDFs implemented in Java directly from the classpath by setting the implementation_reference field to the fully-qualified classname as shown in this example:


Note that the source_function_name field is not set in this example such that it defaults to the specified function_name.

  "namespace": "myNamespace",
  "function_name": "sin",
  "language": "java",
  "implementation_reference": "java.lang.Math",
  "return_type": "double",
  "arguments": [
      "name": "arg",
      "type": "double"

JavaScript-UDF from Source File

PGX can read the source code for a UDF from a file, which can be specified with the source_location configuration entry, for example:

Valid Exports

When using JavaScript for UDFs in PGX, the code has to export valid functions for PGX to pick up. Refer to the PGX UDF tutorial for an example how this can be done.

  "namespace": "myNamespace",
  "function_name": "extract",
  "language": "javascript",
  "source_location": "extract_double.js",
  "source_function_name": "extractDouble",
  "type": "double",
  "arguments": [
      "name": "arg",
      "type": "string"