Setup
1
Open an SDF workspace
For the sake of the example, we will use our There are slight syntax differences for expanding each library.
To keep it simple, we will focus our example on tests and point
out the implementation differences for other libs.
tests
sample workspace.
However, you can always use your existing SDF workspace to follow along.To create the tests
workspace, run the following command:2
Create a New Libs Folder
Within your workspace, create a new folder. We will call it
my_lib
,
but any name would work. This is where we will add our custom logic in
later steps.If you are using the tests
example, your workspace should look like this:3
Copy SDF's Built-in Lib
One option is to copy the libraries from GitHub:Another option is to copy them from If your compilation was successful, you will see SDF’s libraries will be located under
sdfTarget
.
If you don’t have an sdfTarget
directory, all you need to do is
to compile your workspace:sdfTarget
in your
workspace:sdfTarget/dbg/.lib
.Let’s copy sdf_test
to our new custom libraries folder:You can choose to keep the library name as is,
sdf_test
,
or change it if there’s another name you’d prefer to use.4
Add Custom Library to the Workspace YML
Now, we need to add our new library to the workspace configuration.
In our Notice, we are using SDF’s built-in library name, If we want to add another type of custom lib with a non-default
name, we should add to the defaults section:
workspace.sdf.yml
file, let’s add the following section:sdf_test
.
However, we can also choose a different name to our library. If
we decide to do so, we’ll need to indicate it in the defaults.Let’s assume we call the new tests library new_tests
:- We can have more than one custom lib added to a workspace. Each lib is independent of the rest.
- We can create an environment to include the custom libs rather than include it in the main workspace configuration. It’ll look like this:
5
Expand Your Lib
Let’s add some custom logic!Open the lib file. It will be located under
my_lib/sdf_test/macro/test.jinja
.
If you changed any folder names, make sure to apply the changes to locate
the relevant file.Copy the following macro to the top of your custom tests lib:my_lib/sdf_test/macro/test.jinja
We are keeping it simple and merely checking that the column value is below 1000,
but of course, you can implement any custom and complex logic here.
6
Try It!
First, we need to add the test to our table yml file, just like for SDF’s built-in tests
(to learn more, visit our Tests Guide).
In the file Let’s run the test! In your terminal, execute:The test passed!We can look at the compiled tests query located in the file
src_metadata/raw_inapp_events.sdf.yml
, add our new custom test
to the column event_name
:src_metadata/raw_inapp_events.sdf.yml
sdftarget/dbg/preprocessed/tests_workspace/pub/test_raw_inapp_events.sql
.
Notice our custom logic in the compiled query: