Skip to main content

Understanding Reports

Reports are a useful way to track & analyze datatypes, metadata, and business logic throughout your data warehouse. Reports are expressed as SQL queries against the SDF Information Schema, similar to Checks. Since reports are generated with Static Analysis, executing them is fast. Reports are simply small SQL queries that run against the information schema and enable you to analyze your warehouse and metadata. Some examples of effective reports are:
  • Analyze Privacy Compliance: Get a list of all tables and columns that contain PII
  • Create a Data Deletion Report: Improve your data deletion capabilities by tracking retention and writing a report to find all tables that contain PII and are past their retention period.
  • Run a Dead Column Analysis: Optimize your warehouse by computing a list of all columns that have no dependencies, then remove them to save on storage and compute costs.
A report is very similar to a check. A check is a specialized report where the expected result of the report is empty. In this way, reports can be thought of as variables reflecting the state of your warehouse. These variables can then be used to power a check.

Writing Your First Report

Let’s write and modify a report, starting with one of the sdf samples.
1

Create a new SDF Project

Β Β Β Β CreatedΒ pii_saas_platform/.gitignore
Β Β Β Β CreatedΒ pii_saas_platform/checks/no_pii_in_external.sql
Β Β Β Β CreatedΒ pii_saas_platform/classification/taxonomy.sdf.yml
Β Β Β Β CreatedΒ pii_saas_platform/classification/users.sdf.yml
Β Β Β Β CreatedΒ pii_saas_platform/ddls/payment/public/invoices.sql
Β Β Β Β CreatedΒ pii_saas_platform/ddls/payment/public/organizations.sql
Β Β Β Β CreatedΒ pii_saas_platform/ddls/payment/public/users.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/external/invoice_stats.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/external/org_invoice_stats.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/internal/avg_invoice_amt.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/internal/invoice_payment_delay.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/internal/mau_per_org.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/internal/most_frequent_payer.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/internal/total_revenue_per_org.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/internal/users_per_domain.sql
Β Β Β Β CreatedΒ pii_saas_platform/models/internal/users_per_org.sql
Β Β Β Β CreatedΒ pii_saas_platform/reports/tables_with_pii.sql
Β Β Β Β CreatedΒ pii_saas_platform/workspace.sdf.yml
Β 
Β Β Β Β Β Β Β Β WelcomeΒ toΒ yourΒ newΒ SDFΒ Workspace!Β ToΒ helpΒ youΒ onΒ yourΒ journey:
Β Β Β Β Β Β Β Β 
Β Β Β Β Β Β Β Β πŸ’‘Β JoinΒ theΒ SDFΒ CommunityΒ SlackΒ ->Β https://sdf.com/joinΒ 
Β Β Β Β Β Β Β Β 
Β Β Β Β Β Β Β Β πŸ“šΒ ReadΒ theΒ DocsΒ toΒ GetΒ StartedΒ ->Β https://docs.sdf.com/
Β Β Β Β Β Β Β Β 
Β Β Β FinishedΒ newΒ inΒ 0.311Β secs
This sample contains a report and a workspace modeled after a simple SAAS platform.Notice the report in the reports directory. This report simply lists all tables with PII. It’s configured in the workspace.sdf.yml file with includes type report like so:
The report itself lists all tables with PII by fetching all columns with classifiers that have PII. This is done with the following SQL:
Both checks and reports must be written in the Trino SQL dialect.
This report will show us tables that contain PII only because we defined a classifier like so:
As such, this report will show tables that contain columns with any instance of the PII classifier (i.e. PII.name, PII.email, or PII.phone).
SDF stores the classifiers on a column as a string. As such, we can use the SQL LIKE operator to search for a substring.
2

Run & Modify a Report

WorkingΒ setΒ 12Β modelΒ files,Β 3Β .sdfΒ files
Β Β CompilingΒ payment.public.usersΒ (./ddls/payment/public/users.sql)
Β Β CompilingΒ payment.public.organizationsΒ (./ddls/payment/public/organizations.sql)
Β Β CompilingΒ payment.public.invoicesΒ (./ddls/payment/public/invoices.sql)
Β Β CompilingΒ transformations.internal.mau_per_orgΒ (./models/internal/mau_per_org.sql)
Β Β CompilingΒ transformations.internal.avg_invoice_amtΒ (./models/internal/avg_invoice_amt.sql)
Β Β CompilingΒ transformations.internal.invoice_payment_delayΒ (./models/internal/invoice_payment_delay.sql)
Β Β CompilingΒ transformations.internal.most_frequent_payerΒ (./models/internal/most_frequent_payer.sql)
Β Β CompilingΒ transformations.internal.users_per_domainΒ (./models/internal/users_per_domain.sql)
Β Β CompilingΒ transformations.internal.users_per_orgΒ (./models/internal/users_per_org.sql)
Β Β CompilingΒ transformations.internal.total_revenue_per_orgΒ (./models/internal/total_revenue_per_org.sql)
Β Β CompilingΒ transformations.external.invoice_statsΒ (./models/external/invoice_stats.sql)
Β Β CompilingΒ transformations.external.org_invoice_statsΒ (./models/external/org_invoice_stats.sql)
WorkingΒ setΒ 1Β reportΒ file,Β 1Β .sdfΒ file
Β Β ReportingΒ sdf.reports.tables_with_piiΒ (./reports/tables_with_pii.sql)
Β Β Β FinishedΒ 12Β modelsΒ [12Β succeeded],Β 1Β reportΒ [1Β succeeded]Β inΒ 8.851Β secsReportΒ sdf.reports.TABLES_WITH_PII
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Β table_id                                     ┆ description             ┆ dialectΒ Β Β β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ═════════════════════════β•ͺ═══════════║
β”‚Β payment.public.USERS                         ┆ DDLΒ forΒ theΒ usersΒ table ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.EXTERNAL.INVOICE_STATS       ┆                         ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.INTERNAL.USERS_PER_DOMAIN    ┆                         ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.INTERNAL.MOST_FREQUENT_PAYER ┆                         ┆ snowflakeΒ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
4Β rows.
As you can see from the output, it looks we have three tables containing columns with PII. Let’s say we also wanted to show the names of the columns that contain PII. We can do this by modifying the SQL query to include the column name like so:
Now, when we run the report, we can see the column names as well:
WorkingΒ setΒ 12Β modelΒ files,Β 3Β .sdfΒ files
WorkingΒ setΒ 1Β reportΒ file,Β 1Β .sdfΒ file
Β Β ReportingΒ sdf.reports.tables_with_piiΒ (./reports/tables_with_pii.sql)
Β Β Β FinishedΒ 12Β modelsΒ [12Β reused],Β 1Β reportΒ [1Β succeeded]Β inΒ 4.899Β secsReportΒ sdf.reports.TABLES_WITH_PII
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Β table_id                                     ┆ column_name  ┆ description             ┆ dialectΒ Β Β β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ══════════════β•ͺ═════════════════════════β•ͺ═══════════║
β”‚Β TRANSFORMATIONS.EXTERNAL.INVOICE_STATS       ┆ NAME         ┆                         ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.INTERNAL.USERS_PER_DOMAIN    ┆ EMAIL_DOMAIN ┆                         ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.INTERNAL.MOST_FREQUENT_PAYER ┆ EMAIL        ┆                         ┆ snowflakeΒ β”‚
β”‚Β payment.public.USERS                         ┆ NAME         ┆ DDLΒ forΒ theΒ usersΒ table ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.EXTERNAL.INVOICE_STATS       ┆ EMAIL        ┆                         ┆ snowflakeΒ β”‚
β”‚Β payment.public.USERS                         ┆ EMAIL        ┆ DDLΒ forΒ theΒ usersΒ table ┆ snowflakeΒ β”‚
β”‚Β payment.public.USERS                         ┆ PHONE        ┆ DDLΒ forΒ theΒ usersΒ table ┆ snowflakeΒ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
7Β rows.
3

Add a New Report

Let’s say we’d like to extend our analysis a bit but still maintain the original report. We can do this by adding a new report to the reports directory. Let’s add a new report to find the most frequently used datatypes in columns with PII. We can do this with the following SQL:
pii_datatypes.sql
Now, when we run the report, we can see the most frequently used datatypes in columns with PII:
WorkingΒ setΒ 12Β modelΒ files,Β 3Β .sdfΒ files
WorkingΒ setΒ 2Β reportΒ files,Β 1Β .sdfΒ file
Β Β ReportingΒ sdf.reports.pii_datatypesΒ (./reports/pii_datatypes.sql)
Β Β Β FinishedΒ 12Β modelsΒ [12Β reused],Β 2Β reportsΒ [1Β succeeded,Β 1Β reused]Β inΒ 3.772Β secsReportΒ sdf.reports.TABLES_WITH_PII
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Β table_id                                     ┆ column_name  ┆ description             ┆ dialectΒ Β Β β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ══════════════β•ͺ═════════════════════════β•ͺ═══════════║
β”‚Β TRANSFORMATIONS.EXTERNAL.INVOICE_STATS       ┆ EMAIL        ┆                         ┆ snowflakeΒ β”‚
β”‚Β payment.public.USERS                         ┆ EMAIL        ┆ DDLΒ forΒ theΒ usersΒ table ┆ snowflakeΒ β”‚
β”‚Β payment.public.USERS                         ┆ PHONE        ┆ DDLΒ forΒ theΒ usersΒ table ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.EXTERNAL.INVOICE_STATS       ┆ NAME         ┆                         ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.INTERNAL.USERS_PER_DOMAIN    ┆ EMAIL_DOMAIN ┆                         ┆ snowflakeΒ β”‚
β”‚Β TRANSFORMATIONS.INTERNAL.MOST_FREQUENT_PAYER ┆ EMAIL        ┆                         ┆ snowflakeΒ β”‚
β”‚Β payment.public.USERS                         ┆ NAME         ┆ DDLΒ forΒ theΒ usersΒ table ┆ snowflakeΒ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
7Β rows.ReportΒ sdf.reports.PII_DATATYPES
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Β datatype ┆ frequencyΒ β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•ͺ═══════════║
β”‚Β varchar  ┆ 7Β Β Β Β Β Β Β Β Β β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1Β rows.
4

Save the Output (Optional)

We can save the output of a report to a file by using the --format flag. Let’s save the output of our reports to a file called sdf_reports.csv:
Note that we used --show result to only show the result of the report, not any output regarding the execution of the report. In a scenario where you’d want to programatically generate valid CSVs or JSONs of your reports, this is necessary to avoid any extraneous output. See our input and output guide for more on this.

Advanced Reports

  • To learn more about transforming classifiers across functions, see: UDFs
  • To learn more about the SDF internal information schema, see: Information Schema