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Β secsreports directory. This report simply lists all tables with PII. Itβs configured in the workspace.sdf.yml file with includes type report like so:PII. This is done with the following SQL:Both checks and reports must be written in the Trino SQL dialect.
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.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 Now, when we run the report, we can see the most frequently used datatypes in columns with PII:
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
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