- They are only available for connectors that are SQL-based and that support row-level expressions in derived fields and custom metrics.
- They are only available for functions that perform row-level operations, and not aggregation operations (for example, standard deviation or rank).
If a connector supports derived fields, it also supports row-level expressions.
For more information, see:
Activate Admin-Defined Functions
Activate an admin-defined function in Self-Service Analytics-
Create a JSON file containing your admin-defined function definitions. This JSON file should reside on the same machine as the connector server. The recommended location for this JSON file is
/etc/zoomdata(for example,/etc/zoomdata/edc-impala-functions.json). See Admin-Defined Function JSON Files for more information about creating this JSON file. -
Update the connector server configuration so the connector knows where to find the file containing the admin-defined functions you have created. Complete these steps:
-
Locate and edit the properties file for the connector in the
/etc/zoomdatadirectory. For example, the Impala properties file is callededc-impala.properties. -
Locate and update the
functions.template.json.pathproperty in the Functions section of the properties file. Supply the path to the JSON file containing your admin-defined functions in the property. In the following example, the path for theedc-impala-functions.jsonfile is specified.All admin-defined functions for a connector should be defined in the same JSON file, so only one path is needed per data source. - Save the properties file.
-
Locate and edit the properties file for the connector in the
- Restart the connector server.
Admin-Defined Function JSON Files
Use a single JSON file to define all the admin-defined functions for a single connector. Store this JSON file in the appropriate location for your environment.- Linux:
/etc/zoomdata. As an example,/etc/zoomdata/edc-impala-functions.json. - Windows:
<install-path>/conf-modify. As an example,<install-path>/conf-modify/edc-impala-functions.json.
JSON File Structure
The basic structure of an admin-defined function in the JSON file is shown below. Each section is described.function
The function name is the identifier used for the row-level admin-defined function. This name is displayed in the UI. The function name must start with a letter or an underscore and can contain letters, underscores, numbers, and periods.template
The template defines the SQL string that will be used in the SQL query to a data source. You are fully responsible for the validity of the template string. Self-Service Analytics cannot fully validate it. The template references arguments defined later in the JSON file. The arguments are surrounded by braces (curly braces) and are replaced by their SQL representations at run time. Self-Service Analytics does validate missing arguments when the connector associated with this JSON file starts. You can use a backslash (\) as an escape character. It can be used to escape the following three characters: \ { } anywhere in the SQL template string (including inside the argument placeholders).
Here is an example:
returnType
There are three possible returnTypes:simple, generic, and array. The returnType used for the whole function must be simple or generic; the array returnType is not supported for the whole function. However, all three returnTypes are supported in the arguments defined within an admin-defined function.
Each returnType in the JSON provides a type specification and a name.
simple returnTypes
Five simple returnTypes are supported : NUMBER, INTEGER, STRING, DATE, or BOOLEAN. Here is an example of a simple returnType:
simple or generic. Here is an example:
arguments
The arguments section defines the argument keys and definitions. You do not have to specify an arguments section if there are no arguments. The argument keys are used in the SQL template string at the beginning of the function definition. An argument definition consists of a name, a returnType, and description. The name and description are used to display the argument in the UI. The returnType is used for argument type validation and function returnType inference. The argument returnType can besimple, generic or array.
description
The description is an optional string you can specify to describe a function or an argument in the JSON file and in the UI.Validating Your JSON File
You can validate your JSON against a JSON schema filefunctions-schema.json that Self-Service Analytics provides in the appropriate directory for your environment.
- Linux:
/opt/zoomdata/docs/<edc-connector>. For example, the Impala JSON schema is in/opt/zoomdata/docs/edc-impala/functions-schema.json. - Windows:
<install-path>/docs/<edc-connector>. For example, the Impala JSON schema is in<install-path>/docs/edc-impala/functions-schema.json.
- Link to the JSON Schema Validator at https://www.jsonschemavalidator.net/.
- Copy the schema found in the JSON schema file for your connector (see above) to the left side of the JSON Schema Validator screen.
- Copy your JSON file admin-defined function definitions in the Input JSON section on the right side of the JSON Schema Validator screen.
Example
In the following JSON file, two admin-defined functions,TEST_ADD and TEST_ADD_YEAR, are defined.
Before using this example, be sure to remove the comments. Comments are not allowed in JSON.