@@ -40,6 +40,7 @@ def jsonify(
4040 dataset2_columns : Columns ,
4141 columns_diff : Dict [str , List [str ]],
4242 with_summary : bool = False ,
43+ stats_only : bool = False ,
4344) -> "JsonDiff" :
4445 """
4546 Converts the diff result into a JSON-serializable format.
@@ -53,21 +54,13 @@ def jsonify(
5354 t1_exclusive_rows = []
5455 t2_exclusive_rows = []
5556 diff_rows = []
57+ rows = None
5658 schema = [field for field , _ in diff_info .diff_schema ]
5759
5860 t1_exclusive_rows , t2_exclusive_rows , diff_rows = _group_rows (diff_info , schema )
5961
60- diff_rows_jsonified = []
61- for row in diff_rows :
62- diff_rows_jsonified .append (_jsonify_diff (row , key_columns ))
63-
64- t1_exclusive_rows_jsonified = []
65- for row in t1_exclusive_rows :
66- t1_exclusive_rows_jsonified .append (_jsonify_exclusive (row , key_columns ))
67-
68- t2_exclusive_rows_jsonified = []
69- for row in t2_exclusive_rows :
70- t2_exclusive_rows_jsonified .append (_jsonify_exclusive (row , key_columns ))
62+ if not stats_only :
63+ rows = _make_rows_diff (t1_exclusive_rows , t2_exclusive_rows , diff_rows , key_columns )
7164
7265 summary = None
7366 if with_summary :
@@ -87,10 +80,7 @@ def jsonify(
8780 model = dbt_model ,
8881 dataset1 = list (table1 .table_path ),
8982 dataset2 = list (table2 .table_path ),
90- rows = RowsDiff (
91- exclusive = ExclusiveDiff (dataset1 = t1_exclusive_rows_jsonified , dataset2 = t2_exclusive_rows_jsonified ),
92- diff = diff_rows_jsonified ,
93- ),
83+ rows = rows ,
9484 summary = summary ,
9585 columns = columns ,
9686 ).json ()
@@ -228,7 +218,7 @@ class JsonDiff:
228218 model : str
229219 dataset1 : List [str ]
230220 dataset2 : List [str ]
231- rows : RowsDiff
221+ rows : Optional [ RowsDiff ]
232222 summary : Optional [JsonDiffSummary ]
233223 columns : Optional [JsonColumnsSummary ]
234224
@@ -259,6 +249,33 @@ def _group_rows(
259249 return t1_exclusive_rows , t2_exclusive_rows , diff_rows
260250
261251
252+ def _make_rows_diff (
253+ t1_exclusive_rows : List [Dict [str , Any ]],
254+ t2_exclusive_rows : List [Dict [str , Any ]],
255+ diff_rows : List [Dict [str , Any ]],
256+ key_columns : List [str ]
257+ ) -> RowsDiff :
258+ diff_rows_jsonified = []
259+ for row in diff_rows :
260+ diff_rows_jsonified .append (_jsonify_diff (row , key_columns ))
261+
262+ t1_exclusive_rows_jsonified = []
263+ for row in t1_exclusive_rows :
264+ t1_exclusive_rows_jsonified .append (_jsonify_exclusive (row , key_columns ))
265+
266+ t2_exclusive_rows_jsonified = []
267+ for row in t2_exclusive_rows :
268+ t2_exclusive_rows_jsonified .append (_jsonify_exclusive (row , key_columns ))
269+
270+ return RowsDiff (
271+ exclusive = ExclusiveDiff (
272+ dataset1 = t1_exclusive_rows_jsonified ,
273+ dataset2 = t2_exclusive_rows_jsonified
274+ ),
275+ diff = diff_rows_jsonified ,
276+ )
277+
278+
262279def _jsonify_diff (row : Dict [str , Any ], key_columns : List [str ]) -> Dict [str , JsonDiffRowValue ]:
263280 columns = collections .defaultdict (dict )
264281 for field , value in row .items ():
0 commit comments