33import os
44import pickle
55from collections import defaultdict , deque
6- from typing import Any , Dict , Iterable , List , Optional , Set , Tuple
6+ from typing import (
7+ Any ,
8+ Dict ,
9+ Iterable ,
10+ List ,
11+ Literal ,
12+ Optional ,
13+ Sequence ,
14+ Set ,
15+ Tuple ,
16+ Union ,
17+ )
718
819import networkx as nx # type: ignore
920import sqlparse
5061
5162graph_file_name = "graph.gpickle"
5263
64+ StatsKeyType = Union [NodeType , Literal ["catalogs" ]]
65+
5366
54- def print_compile_stats (stats : Dict [NodeType , int ]):
67+ def print_compile_stats (stats : Dict [StatsKeyType , int ]):
5568 # create tracking event for resource_counts
5669 if dbt .tracking .active_user is not None :
57- resource_counts = {k .pluralize (): v for k , v in stats .items ()}
70+ resource_counts = {}
71+ for k , v in stats .items ():
72+ if isinstance (k , NodeType ):
73+ resource_counts [k .pluralize ()] = v
74+ else :
75+ resource_counts [k ] = v
5876 dbt .tracking .track_resource_counts (resource_counts )
5977
6078 # do not include resource types that are not actually defined in the project
@@ -72,8 +90,10 @@ def _node_enabled(node: ManifestNode):
7290 return True
7391
7492
75- def _generate_stats (manifest : Manifest ) -> Dict [NodeType , int ]:
76- stats : Dict [NodeType , int ] = defaultdict (int )
93+ def _generate_stats (
94+ manifest : Manifest , catalogs : Optional [Sequence [Any ]] = None
95+ ) -> Dict [StatsKeyType , int ]:
96+ stats : Dict [StatsKeyType , int ] = defaultdict (int )
7797 for node in manifest .nodes .values ():
7898 if _node_enabled (node ):
7999 stats [node .resource_type ] += 1
@@ -87,6 +107,8 @@ def _generate_stats(manifest: Manifest) -> Dict[NodeType, int]:
87107 stats [NodeType .SemanticModel ] += len (manifest .semantic_models )
88108 stats [NodeType .SavedQuery ] += len (manifest .saved_queries )
89109 stats [NodeType .Unit ] += len (manifest .unit_tests )
110+ if catalogs is not None :
111+ stats ["catalogs" ] = len (catalogs )
90112
91113 # TODO: should we be counting dimensions + entities?
92114
@@ -705,7 +727,13 @@ def _compile_relation_for_foreign_key_constraint_to(
705727 # This method doesn't actually "compile" any of the nodes. That is done by the
706728 # "compile_node" method. This creates a Linker and builds the networkx graph,
707729 # writes out the graph.gpickle file, and prints the stats, returning a Graph object.
708- def compile (self , manifest : Manifest , write = True , add_test_edges = False ) -> Graph :
730+ def compile (
731+ self ,
732+ manifest : Manifest ,
733+ write = True ,
734+ add_test_edges = False ,
735+ catalogs : Optional [Sequence [Any ]] = None ,
736+ ) -> Graph :
709737 self .initialize ()
710738 linker = Linker ()
711739 linker .link_graph (manifest )
@@ -737,14 +765,12 @@ def compile(self, manifest: Manifest, write=True, add_test_edges=False) -> Graph
737765 )
738766 )
739767
740- stats = _generate_stats (manifest )
741-
742768 if write :
743769 self .write_graph_file (linker , manifest )
744770
745771 # Do not print these for list command
746772 if self .config .args .which != "list" :
747- stats = _generate_stats (manifest )
773+ stats = _generate_stats (manifest , catalogs )
748774 print_compile_stats (stats )
749775
750776 return Graph (linker .graph )
0 commit comments