Hey all, can custom SQL tests be created in local ...
# ask-elementary-ai
j
Hey all, can custom SQL tests be created in local elementary (using DBT)? If yes, is there a documentation on the syntax to be followed for the test
.yml
file?
k
A message from kapa.ai
Yes, Elementary supports custom SQL tests in local environments using dbt. There are two main approaches to creating custom SQL tests with Elementary: 1. Using dbt Singular Tests: You can create custom SQL tests as singular tests in your dbt project. These are fully supported by Elementary for both alerts and reporting. As mentioned in the FAQ: > "Custom / Singular tests are supported by Elementary. > - Alerts: Full support. > - Report: Only tests that
ref
one model are presented in the report under the relevant model." [Elementary FAQ](https://docs.elementary-data.com/oss/general/faq) 2. Using the Elementary UI: More recently, Elementary added support for creating custom SQL tests directly through the UI, which then generates singular tests in your dbt project. This feature was added in April 2024: > "Custom query testing is a must-have to validate business logic specific to your data team. You can now create custom SQL tests with Elementary, which will be translated into singular tests in your dbt project." [Elementary Changelog](https://docs.elementary-data.com/changelog#custom-sql-tests-in-ui) For the syntax of custom SQL tests, you can add configuration to your custom test files like this:
Copy code
sql {{ config(     tags=["Tag1","Tag2"]     meta={         "description": "This is a description",         "owner": "Maayan Salom"     } ) }}  <test query here>
The query should return results only when the test fails (i.e., when there's an issue with the data). For more detailed information about custom SQL tests, you can refer to the [Custom SQL Tests documentation](https://docs.elementary-data.com/features/data-tests/custom-sql-tests), which provides guidance on when to use them, how to add them, and how to handle their results and alerts.