This topic describes how to use Function Studio to develop a user-defined function (UDF) and submit it to the development environment in DataStudio.

Create a project

If you have Git code, you can import the Git code to create a project. You can only import Git code from code.aliyun.com.

  1. Log on to the DataWorks console and go to the DataStudio page.
  2. Click the DataWorks icon in the upper-left corner and choose All Products > Data Development > Function Studio.
  3. On the Projects page that appears, click Import Git Project.
  4. On the Create Project page, set Git Repo URL, Name, and Description, and select a runtime environment.

    By default, the new project is not associated with the Git service. Therefore, the Settings dialog box appears after you set Git Repo URL. In this dialog box, set parameters on the SSH Key, Git Config, and Preference tabs, and click Save respectively.

    • On the SSH Key tab, set Service to code.aliyun.com, click Create SSH Key to generate a Secure Shell (SSH) public key, and then click Save.
    • On the Git Config tab, set Username and Email, and click Save.
    • On the Preference tab, set Font Size in Editor as required and click Save.
    Note If you want to modify Git settings after you create the project, move the pointer over Settings in the top-navigation bar and click SSH Key, Git Config, or Preference as required.
  5. Click Submit.
    After you create the project, Function Studio automatically pulls Git code from the project.

Add the SSH public key to code.aliyun.com

After setting parameters on the SSH Key, Git Config, and Preference tabs, you can add the SSH public key to code.aliyun.com.

  1. Visit code.aliyun.com and click Settings in the left-side navigation pane.
  2. On the page that appears, click SSH Public Key in the left-side navigation pane. On the SSH Public Key page, click Add SSH Public Key in the upper-right corner.
  3. On the Add SSH Public Key page, enter the SSH key generated on the SSH Key tab and click Add.

Test the class to run

  1. Double-click the target class in the left-side navigation pane and click the Run icon in the upper-right corner.
  2. In the Run/Debug Configurations dialog box that appears, set parameters for the class.
  3. Click Run. The test result appears in the Output section at the bottom.
    Note
    • The initial running process takes a longer time period. When you run the class again, the running duration is similar to that in a local integrated development environment (IDE).
    • You can also select the target class from the drop-down list in the upper-right corner and click the Run icon.

Submit the UDF and resource to the development environment in DataStudio

After verifying that code is correct, submit the UDF and resource to the development environment in DataStudio.

  • Submit the resource to the development environment in DataStudio.
    1. Move the pointer over the Submit icon on the Function Studio page and click Submit Resource to Development Environment.
    2. In the Submit Resource to DataStudio Development Environment dialog box that appears, set Target Workspace, Target Workflow, and Resource.
    3. Click OK.
  • Submit the UDF to the development environment in DataStudio.
    1. Move the pointer over the Submit icon on the Function Studio page and click Submit Function to Development Environment.
    2. In the Submit Function to DataStudio Development Environment dialog box that appears, set Target Workspace, Target Workflow, Resource, Class, and Function.
    3. Click OK.

After submitting the resource and UDF to the development environment in DataStudio, you can use them in SQL nodes.