Create a function
To add a new function to your project, perform the following steps.- Open a SQL project.
- Click Add Entity in the project sidebar.
- Select Function.
- Name the function.
- Keep the function in the
macrosdirectory. - Click Create.
Build the function
You can build functions visually by populating the following fields.| Field | Description |
|---|---|
| Description | A summary of what the function will do. |
| Parameters | The parameters (arguments) that will be passed to the function. Parameters can be values or table names. |
| Definition | SQL code that will be executed by the function. |
Example: Concatenate columns
Use the following example to learn how to build a function and use it in your pipeline. This example demonstrates a function that concatenates values from afirst_name and last_name column in a customer table.
- Click +Add Entity in the project sidebar.
- Select Function.
- Name the function
concat_name. - Click Create.
- Add the following description:
Concatenates customer first and last names in a new column. - Add two parameters to the function:
first_nameandlast_name. - Add the following to the macro body
- Add a Reformat gem to the pipeline canvas.
- For the target column, create a new column named
full_name. - For the expression, select Function > concat_name.
- For the function parameters, choose a first name columns and a last name column.
- Save and run the gem.
full_name.
