pytrilogy 0.0.2.44__py3-none-any.whl → 0.0.2.46__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 pytrilogy might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytrilogy
3
- Version: 0.0.2.44
3
+ Version: 0.0.2.46
4
4
  Summary: Declarative, typed query language that compiles to SQL.
5
5
  Home-page:
6
6
  Author:
@@ -1,4 +1,4 @@
1
- trilogy/__init__.py,sha256=fIzmFgsTur7NoKb9nhIHJxXi92LDugIbBG7NvACkML0,291
1
+ trilogy/__init__.py,sha256=q-cYTIW_OeTndnX4REcP9y6FQJIbng3ilR-7zaKPUyc,291
2
2
  trilogy/compiler.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  trilogy/constants.py,sha256=UPymm94T2c6a55XdDaXw0aleTe1pOJ6lf6gOWLKZyKg,1430
4
4
  trilogy/engine.py,sha256=R5ubIxYyrxRExz07aZCUfrTsoXCHQ8DKFTDsobXdWdA,1102
@@ -16,7 +16,7 @@ trilogy/core/exceptions.py,sha256=1c1lQCwSw4_5CQS3q7scOkXU8GQvullJXfPHubprl90,61
16
16
  trilogy/core/functions.py,sha256=IhVpt3n6wEanKHnGu3oA2w6-hKIlxWpEyz7fHN66mpo,10720
17
17
  trilogy/core/graph_models.py,sha256=mameUTiuCajtihDw_2-W218xyJlvTusOWrEKP1yAWgk,2003
18
18
  trilogy/core/internal.py,sha256=jNGFHKENnbMiMCtAgsnLZYVSENDK4b5ALecXFZpTDzQ,1075
19
- trilogy/core/models.py,sha256=Fos3AY_biCCYh-Y9p-n9di8CJ9UvdxnNgiNTxYjlH-4,163631
19
+ trilogy/core/models.py,sha256=WxmOgW0cTUgcBVu_gLPUwA9j3KWYPH5FsxKzBSJukEg,164085
20
20
  trilogy/core/optimization.py,sha256=VFSvJLNoCCOraip-PZUKeE4qrlxtXARjQUzJZiW-yRk,7325
21
21
  trilogy/core/query_processor.py,sha256=mbcZlgjChrRjDHkdmMbKe-T70UpbBkJhS09MyU5a6UY,17785
22
22
  trilogy/core/optimizations/__init__.py,sha256=bWQecbeiwiDx9LJnLsa7dkWxdbl2wcnkcTN69JyP8iI,356
@@ -50,7 +50,7 @@ trilogy/core/processing/nodes/select_node_v2.py,sha256=7WoFxeGEAzhpS4y4Zw2nH2tt7
50
50
  trilogy/core/processing/nodes/unnest_node.py,sha256=mAmFluzm2yeeiQ6NfIB7BU_8atRGh-UJfPf9ROwbhr8,2152
51
51
  trilogy/core/processing/nodes/window_node.py,sha256=ro0QfMFi4ZmIn5Q4D0M_vJWfnHH_C0MN7XkVkx8Gygg,1214
52
52
  trilogy/dialect/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
- trilogy/dialect/base.py,sha256=Aj0U5JUFPzBuo-5LNASYIkJVIYiMhL3A4nGEslY7xAg,36301
53
+ trilogy/dialect/base.py,sha256=YyJy20CNJfOmuHg-WhYEwIamJzAQxb48_lqghriTm8c,36261
54
54
  trilogy/dialect/bigquery.py,sha256=15KJ-cOpBlk9O7FPviPgmg8xIydJeKx7WfmL3SSsPE8,2953
55
55
  trilogy/dialect/common.py,sha256=eqJi_Si1iyb2sV0siTf8g8JOHueWu6RkdtQZtutKazk,3826
56
56
  trilogy/dialect/config.py,sha256=tLVEMctaTDhUgARKXUNfHUcIolGaALkQ0RavUvXAY4w,2994
@@ -75,9 +75,9 @@ trilogy/parsing/render.py,sha256=-qqpXQg4yHcv284Vosjnsc_vrPveH6oaYbeCd3ZSvs0,156
75
75
  trilogy/parsing/trilogy.lark,sha256=B6NM3-rBHtYB_WSEti0DiS8Z-I8YH3kZU47xNzQvBx4,12389
76
76
  trilogy/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
77
  trilogy/scripts/trilogy.py,sha256=PHxvv6f2ODv0esyyhWxlARgra8dVhqQhYl0lTrSyVNo,3729
78
- pytrilogy-0.0.2.44.dist-info/LICENSE.md,sha256=5ZRvtTyCCFwz1THxDTjAu3Lidds9WjPvvzgVwPSYNDo,1042
79
- pytrilogy-0.0.2.44.dist-info/METADATA,sha256=RxCccw965AUjLdlWfAfnBSub9kBZAD5Hh-qJgcY9i90,8426
80
- pytrilogy-0.0.2.44.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
81
- pytrilogy-0.0.2.44.dist-info/entry_points.txt,sha256=0petKryjvvtEfTlbZC1AuMFumH_WQ9v8A19LvoS6G6c,54
82
- pytrilogy-0.0.2.44.dist-info/top_level.txt,sha256=cAy__NW_eMAa_yT9UnUNlZLFfxcg6eimUAZ184cdNiE,8
83
- pytrilogy-0.0.2.44.dist-info/RECORD,,
78
+ pytrilogy-0.0.2.46.dist-info/LICENSE.md,sha256=5ZRvtTyCCFwz1THxDTjAu3Lidds9WjPvvzgVwPSYNDo,1042
79
+ pytrilogy-0.0.2.46.dist-info/METADATA,sha256=L7_5Dv6L1KqiOvLlUnSRzmGZajKdmZ3p_TMYt2Y5iq8,8426
80
+ pytrilogy-0.0.2.46.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
81
+ pytrilogy-0.0.2.46.dist-info/entry_points.txt,sha256=0petKryjvvtEfTlbZC1AuMFumH_WQ9v8A19LvoS6G6c,54
82
+ pytrilogy-0.0.2.46.dist-info/top_level.txt,sha256=cAy__NW_eMAa_yT9UnUNlZLFfxcg6eimUAZ184cdNiE,8
83
+ pytrilogy-0.0.2.46.dist-info/RECORD,,
trilogy/__init__.py CHANGED
@@ -4,6 +4,6 @@ from trilogy.executor import Executor
4
4
  from trilogy.parser import parse
5
5
  from trilogy.constants import CONFIG
6
6
 
7
- __version__ = "0.0.2.44"
7
+ __version__ = "0.0.2.46"
8
8
 
9
9
  __all__ = ["parse", "Executor", "Dialects", "Environment", "CONFIG"]
trilogy/core/models.py CHANGED
@@ -2307,9 +2307,11 @@ class UnnestJoin(BaseModel):
2307
2307
  rendering_required: bool = True
2308
2308
 
2309
2309
  def __hash__(self):
2310
- return (
2311
- self.alias + "".join([str(s.address) for s in self.concepts])
2312
- ).__hash__()
2310
+ return self.safe_identifier.__hash__()
2311
+
2312
+ @property
2313
+ def safe_identifier(self) -> str:
2314
+ return self.alias + "".join([str(s.address) for s in self.concepts])
2313
2315
 
2314
2316
 
2315
2317
  class InstantiatedUnnestJoin(BaseModel):
@@ -2544,7 +2546,7 @@ class QueryDatasource(BaseModel):
2544
2546
  return True
2545
2547
  return False
2546
2548
 
2547
- def __add__(self, other):
2549
+ def __add__(self, other) -> "QueryDatasource":
2548
2550
  # these are syntax errors to avoid being caught by current
2549
2551
  if not isinstance(other, QueryDatasource):
2550
2552
  raise SyntaxError("Can only merge two query datasources")
@@ -2570,7 +2572,7 @@ class QueryDatasource(BaseModel):
2570
2572
  f" {other.name} with {[c.address for c in other.output_concepts]} concepts"
2571
2573
  )
2572
2574
 
2573
- merged_datasources = {}
2575
+ merged_datasources: dict[str, Union[Datasource, "QueryDatasource"]] = {}
2574
2576
 
2575
2577
  for ds in [*self.datasources, *other.datasources]:
2576
2578
  if ds.safe_identifier in merged_datasources:
@@ -2580,20 +2582,29 @@ class QueryDatasource(BaseModel):
2580
2582
  else:
2581
2583
  merged_datasources[ds.safe_identifier] = ds
2582
2584
 
2583
- final_source_map = defaultdict(set)
2585
+ final_source_map: defaultdict[
2586
+ str, Set[Union[Datasource, "QueryDatasource", "UnnestJoin"]]
2587
+ ] = defaultdict(set)
2588
+
2589
+ # add our sources
2584
2590
  for key in self.source_map:
2585
2591
  final_source_map[key] = self.source_map[key].union(
2586
2592
  other.source_map.get(key, set())
2587
2593
  )
2594
+ # add their sources
2588
2595
  for key in other.source_map:
2589
2596
  if key not in final_source_map:
2590
2597
  final_source_map[key] = other.source_map[key]
2598
+
2599
+ # if a ds was merged (to combine columns), we need to update the source map
2600
+ # to use the merged item
2591
2601
  for k, v in final_source_map.items():
2592
2602
  final_source_map[k] = set(
2593
- merged_datasources[x.safe_identifier] for x in list(v)
2603
+ merged_datasources.get(x.safe_identifier, x) for x in list(v)
2594
2604
  )
2595
2605
  self_hidden = self.hidden_concepts or []
2596
2606
  other_hidden = other.hidden_concepts or []
2607
+ # hidden is the minimum overlapping set
2597
2608
  hidden = [x for x in self_hidden if x.address in other_hidden]
2598
2609
  qds = QueryDatasource(
2599
2610
  input_concepts=unique(
@@ -2606,11 +2617,10 @@ class QueryDatasource(BaseModel):
2606
2617
  datasources=list(merged_datasources.values()),
2607
2618
  grain=self.grain,
2608
2619
  joins=unique(self.joins + other.joins, "unique_id"),
2609
- # joins = self.joins,
2610
2620
  condition=(
2611
2621
  self.condition + other.condition
2612
- if (self.condition or other.condition)
2613
- else None
2622
+ if self.condition and other.condition
2623
+ else self.condition or other.condition
2614
2624
  ),
2615
2625
  source_type=self.source_type,
2616
2626
  partial_concepts=unique(
trilogy/dialect/base.py CHANGED
@@ -313,10 +313,18 @@ class BaseDialect:
313
313
  )
314
314
  for x in c.lineage.over
315
315
  ]
316
- rval = f"{self.WINDOW_FUNCTION_MAP[c.lineage.type](concept = self.render_concept_sql(c.lineage.content,
317
- cte=cte, alias=False, raise_invalid=raise_invalid),
318
- window=','.join(rendered_over_components), sort=','.join(rendered_order_components),
319
- offset=c.lineage.index)}" # noqa: E501
316
+
317
+ rval = self.WINDOW_FUNCTION_MAP[c.lineage.type](
318
+ concept=self.render_concept_sql(
319
+ c.lineage.content,
320
+ cte=cte,
321
+ alias=False,
322
+ raise_invalid=raise_invalid,
323
+ ),
324
+ window=",".join(rendered_over_components),
325
+ sort=",".join(rendered_order_components),
326
+ offset=c.lineage.index,
327
+ )
320
328
  elif isinstance(c.lineage, FilterItem):
321
329
  # for cases when we've optimized this
322
330
  if cte.condition == c.lineage.where.conditional: