Register an E-MapReduce (EMR) function in DataWorks to use custom UDFs in EMR SQL statements.
Prerequisites
-
EMR engine types include DataLake and Hadoop. Complete the required preparations in both EMR and DataWorks based on your engine type.
-
DataLake: For more information, see DataLake cluster configuration and DataWorks configuration.
-
-
Upload resources before registering a function. For more information, see Create and use EMR resources.
Procedure
-
Go to the DataStudio page.
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.
-
Create a workflow. For more information, see Create a scheduled workflow.
-
Write your program in a local Java environment, package it into a JAR file, and then create and submit a JAR resource. For more information, see Create and use EMR resources.
-
Create a function.
-
Open the workflow you want, right-click EMR, and select Create Function.
-
In the Create Function dialog box, enter a Name, and select an Engine Instance and a Path.
-
Click Create.
-
In the Register Function dialog box, configure the following parameters.
Parameter
Description
Function Type
Select a function type. Options include Mathematical Operation Functions, Aggregate Functions, String Processing Functions, Date Functions, Window Functions, and Other Functions.
EMR engine instance
A default value is displayed and cannot be changed.
EMR engine type
A default value is displayed and cannot be changed.
EMR database
Select a database from the drop-down list. To create a new database, click Create Database. In the Create Database dialog box, configure the parameters and click OK.
Function Name
The UDF name used in SQL statements. This name must be globally unique and cannot be changed after registration.
Owner
The owner is displayed by default.
Class Name
Required. The main class name that implements the UDF.
Resources
Required. Select a resource in the current workspace. To create a resource, click Create Resource. In the Create Resource dialog box, configure the parameters and click Determine.
Description
A brief description of the UDF.
Expression Syntax
Example usage of the UDF, such as
test.Parameter Description
The supported input and return parameter types.
Return Value
Optional. The return value, such as 1.
Example
Optional. A usage example.
-
-
Click the Save icon
in the toolbar. -
Submit the function.
-
Click the Submit icon
in the toolbar.NoteWhen you submit the function, select a scheduling resource group. A serverless resource group is recommended. With a serverless resource group, DataWorks submits the function registration task to the EMR engine, which runs the task and prints execution logs for troubleshooting. If no serverless resource group is available, purchase and configure one. For more information, see Use serverless resource groups.
-
In the Commit Node dialog box, enter a Change Description.
-
Click OK.
-