Add Data Metric Function cleanup support#28
Merged
jonhopper-dataengineers merged 1 commit intoMay 16, 2026
Conversation
Contributor
Reviewer's GuideAdds a dedicated clean_data_metric_functions dbt macro and wires it into the clean_objects orchestrator while ensuring regular function cleanup excludes Data Metric Functions, plus associated versioning and docs updates. Sequence diagram for clean_objects invoking clean_data_metric_functionssequenceDiagram
actor DbtUser
participant clean_objects
participant clean_functions
participant clean_data_metric_functions
participant Snowflake
participant dbt_graph as dbt_graph_nodes
participant drop_object
DbtUser->>clean_objects: clean_objects(database, clean_targets, object_types)
clean_objects->>clean_functions: clean_functions(database, dry_run)
Note over clean_functions: Filters functions with is_data_metric = 'NO'
clean_objects->>clean_data_metric_functions: clean_data_metric_functions(database, dry_run)
clean_data_metric_functions->>Snowflake: SELECT FROM information_schema.functions
Note over Snowflake: WHERE is_data_metric = 'YES'
clean_data_metric_functions->>dbt_graph: iterate graph.nodes
Note over dbt_graph: Find nodes with materialized = data_metric_function
clean_data_metric_functions->>drop_object: drop_object("FUNCTION", database, snowflake_dmfs_to_drop, dry_run)
drop_object-->>Snowflake: DROP FUNCTION IF EXISTS ...
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider wrapping
clean_data_metric_functionsin the sameif execute/flags.WHICH/target.nameguards used byclean_objectsand other clean macros so it doesn’t run in unexpected contexts (e.g. parsing or docs generation). - The
node.config.get(...)calls inclean_data_metric_functionsassumeconfigis a dict, but in dbt it is a config object; accessing meta/override_name via attributes (and/orgetattr) will be safer and avoid runtime errors. - The iteration over
snowflake_dmf_resultsusingresult.values()[0/1/2]relies on implicit ordering; using explicit column access (e.g.snowflake_dmf_results.columnsandrowsor named indices) would make the macro more robust to changes in the query shape.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider wrapping `clean_data_metric_functions` in the same `if execute`/`flags.WHICH`/`target.name` guards used by `clean_objects` and other clean macros so it doesn’t run in unexpected contexts (e.g. parsing or docs generation).
- The `node.config.get(...)` calls in `clean_data_metric_functions` assume `config` is a dict, but in dbt it is a config object; accessing meta/override_name via attributes (and/or `getattr`) will be safer and avoid runtime errors.
- The iteration over `snowflake_dmf_results` using `result.values()[0/1/2]` relies on implicit ordering; using explicit column access (e.g. `snowflake_dmf_results.columns` and `rows` or named indices) would make the macro more robust to changes in the query shape.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
14f4da5 to
9862a3a
Compare
DMFs are now cleaned as a separate object type to prevent them from being incorrectly dropped by the regular function cleanup macro. .... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code) Co-Authored-By: Cortex Code <noreply@snowflake.com>
9862a3a to
7378238
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
clean_data_metric_functionsmacro to reconcile dbt-defined Data Metric Functions (DMFs) against deployed DMFs in Snowflake and drop orphaned onesdata_metric_functionsas a supportedobject_typein theclean_objectsorchestrator (included in default list)clean_functionsto exclude DMFs (is_data_metric = 'NO'filter) so they are handled exclusively by the new dedicated macroDetails
DMFs live in
information_schema.functionswithis_data_metric = 'YES'and haveTABLE(...)argument signatures. They must be dropped withDROP FUNCTION(notDROP DATA METRIC FUNCTION). The newclean_data_metric_functionsmacro:information_schema.functionsfiltered tois_data_metric = 'YES'config.materialized = 'data_metric_function'(from the companiondbt-snowflake-datops-materilizationspackage)DROP FUNCTION IF EXISTSwith the full signatureTest plan
clean_data_metric_functionsidentifies and drops orphaned DMFs in a test databaseclean_functionsno longer picks up DMFs (theis_data_metric = 'NO'filter excludes them)clean_objectswith defaultobject_typesincludesdata_metric_functionsin the cleanup run.... Generated with Cortex Code
Summary by Sourcery
Add dedicated cleanup support for Snowflake Data Metric Functions and wire it into the existing clean orchestration while updating package metadata.
New Features:
Enhancements:
Build:
Documentation: