acryl-datahub 0.15.0.3rc1__py3-none-any.whl → 0.15.0.4rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of acryl-datahub might be problematic. Click here for more details.

@@ -2,7 +2,6 @@ import contextlib
2
2
  import dataclasses
3
3
  import enum
4
4
  import functools
5
- import itertools
6
5
  import json
7
6
  import logging
8
7
  import os
@@ -63,6 +62,7 @@ from datahub.utilities.file_backed_collections import (
63
62
  FileBackedDict,
64
63
  FileBackedList,
65
64
  )
65
+ from datahub.utilities.groupby import groupby_unsorted
66
66
  from datahub.utilities.lossy_collections import LossyDict, LossyList
67
67
  from datahub.utilities.ordered_set import OrderedSet
68
68
  from datahub.utilities.perf_timer import PerfTimer
@@ -1314,8 +1314,8 @@ class SqlParsingAggregator(Closeable):
1314
1314
  upstream_aspect.fineGrainedLineages = []
1315
1315
  for downstream_column, all_upstream_columns in cll.items():
1316
1316
  # Group by query ID.
1317
- for query_id, upstream_columns_for_query in itertools.groupby(
1318
- sorted(all_upstream_columns.items(), key=lambda x: x[1]),
1317
+ for query_id, upstream_columns_for_query in groupby_unsorted(
1318
+ all_upstream_columns.items(),
1319
1319
  key=lambda x: x[1],
1320
1320
  ):
1321
1321
  upstream_columns = [x[0] for x in upstream_columns_for_query]
@@ -0,0 +1,17 @@
1
+ import collections
2
+ from typing import Callable, Iterable, Tuple, TypeVar
3
+
4
+ T = TypeVar("T")
5
+ K = TypeVar("K")
6
+
7
+
8
+ def groupby_unsorted(
9
+ iterable: Iterable[T], key: Callable[[T], K]
10
+ ) -> Iterable[Tuple[K, Iterable[T]]]:
11
+ """The default itertools.groupby() requires that the iterable is already sorted by the key.
12
+ This method is similar to groupby() but without the pre-sorted requirement."""
13
+
14
+ values = collections.defaultdict(list)
15
+ for v in iterable:
16
+ values[key(v)].append(v)
17
+ return values.items()