sqlframe 3.4.0__py3-none-any.whl → 3.4.1__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.
sqlframe/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '3.4.0'
16
- __version_tuple__ = version_tuple = (3, 4, 0)
15
+ __version__ = version = '3.4.1'
16
+ __version_tuple__ = version_tuple = (3, 4, 1)
@@ -15,7 +15,7 @@ from dataclasses import dataclass
15
15
 
16
16
  import sqlglot
17
17
  from prettytable import PrettyTable
18
- from sqlglot import Dialect
18
+ from sqlglot import Dialect, maybe_parse
19
19
  from sqlglot import expressions as exp
20
20
  from sqlglot import lineage as sqlglot_lineage
21
21
  from sqlglot.helper import ensure_list, flatten, object_to_dict, seq_get
@@ -460,16 +460,40 @@ class _BaseDataFrame(t.Generic[SESSION, WRITER, NA, STAT, GROUP_DATA]):
460
460
  df.expression.ctes[-1].set("cache_storage_level", storage_level)
461
461
  return df
462
462
 
463
- @classmethod
464
- def _add_ctes_to_expression(cls, expression: exp.Select, ctes: t.List[exp.CTE]) -> exp.Select:
463
+ def _add_ctes_to_expression(self, expression: exp.Select, ctes: t.List[exp.CTE]) -> exp.Select:
465
464
  expression = expression.copy()
466
465
  with_expression = expression.args.get("with")
467
466
  if with_expression:
468
467
  existing_ctes = with_expression.expressions
469
- existsing_cte_names = {x.alias_or_name for x in existing_ctes}
468
+ existing_cte_counts = {x.alias_or_name: 0 for x in existing_ctes}
469
+ replaced_cte_names = {} # type: ignore
470
470
  for cte in ctes:
471
- if cte.alias_or_name not in existsing_cte_names:
472
- existing_ctes.append(cte)
471
+ if replaced_cte_names:
472
+ cte = cte.transform(replace_id_value, replaced_cte_names) # type: ignore
473
+ if cte.alias_or_name in existing_cte_counts:
474
+ existing_cte_counts[cte.alias_or_name] += 10
475
+ cte.set(
476
+ "this",
477
+ cte.this.where(
478
+ exp.EQ(
479
+ this=exp.Literal.number(existing_cte_counts[cte.alias_or_name]),
480
+ expression=exp.Literal.number(
481
+ existing_cte_counts[cte.alias_or_name]
482
+ ),
483
+ )
484
+ ),
485
+ )
486
+ new_cte_alias = self._create_hash_from_expression(cte.this)
487
+ replaced_cte_names[cte.args["alias"].this] = maybe_parse(
488
+ new_cte_alias, dialect=self.session.input_dialect, into=exp.Identifier
489
+ )
490
+ cte.set(
491
+ "alias",
492
+ maybe_parse(
493
+ new_cte_alias, dialect=self.session.input_dialect, into=exp.TableAlias
494
+ ),
495
+ )
496
+ existing_ctes.append(cte)
473
497
  else:
474
498
  existing_ctes = ctes
475
499
  expression.set("with", exp.With(expressions=existing_ctes))
@@ -843,11 +867,11 @@ class _BaseDataFrame(t.Generic[SESSION, WRITER, NA, STAT, GROUP_DATA]):
843
867
  logger.warning("Got no value for on. This appears to change the join to a cross join.")
844
868
  how = "cross"
845
869
  other_df = other_df._convert_leaf_to_cte()
870
+ join_expression = self._add_ctes_to_expression(self.expression, other_df.expression.ctes)
846
871
  # We will determine actual "join on" expression later so we don't provide it at first
847
- join_expression = self.expression.join(
848
- other_df.latest_cte_name, join_type=how.replace("_", " ")
872
+ join_expression = join_expression.join(
873
+ join_expression.ctes[-1].alias, join_type=how.replace("_", " ")
849
874
  )
850
- join_expression = self._add_ctes_to_expression(join_expression, other_df.expression.ctes)
851
875
  self_columns = self._get_outer_select_columns(join_expression)
852
876
  other_columns = self._get_outer_select_columns(other_df.expression)
853
877
  join_columns = self._ensure_and_normalize_cols(on)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlframe
3
- Version: 3.4.0
3
+ Version: 3.4.1
4
4
  Summary: Turning PySpark Into a Universal DataFrame API
5
5
  Home-page: https://github.com/eakmanrq/sqlframe
6
6
  Author: Ryan Eakman
@@ -1,10 +1,10 @@
1
1
  sqlframe/__init__.py,sha256=E3qCJ4PSEgKz6Hg3ves6LWt3JrQOV8c9HVLSIUOzKNc,3106
2
- sqlframe/_version.py,sha256=YWGqQYvejjlymmjzg4jncyBgDC760jlRmyon_Rd-2uQ,411
2
+ sqlframe/_version.py,sha256=LQZJn_TZdGacASGuhVlLDchuihNUob4wWhR-2F34rXE,411
3
3
  sqlframe/base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  sqlframe/base/_typing.py,sha256=b2clI5HI1zEZKB_3Msx3FeAJQyft44ubUifJwQRVXyQ,1298
5
5
  sqlframe/base/catalog.py,sha256=SzFQalTWdhWzxUY-4ut1f9TfOECp_JmJEgNPfrRKCe0,38457
6
6
  sqlframe/base/column.py,sha256=C2xj6OHMsJbEgjbI-m5HuIvqHYt2DbbUtCjssKpplNk,17748
7
- sqlframe/base/dataframe.py,sha256=uTM46auSPniww-ZMtI5s0hrrCG1nOICMEhdZZ8E4cu8,71636
7
+ sqlframe/base/dataframe.py,sha256=coeUwntwYbT1g6YKVwk3ZfWMfJqAzd1ECYabBSsNsV0,72892
8
8
  sqlframe/base/decorators.py,sha256=Jy4bf8MhZ-AJ6CWTj59bBJRqamtLbPC0USUMFrY6g0w,449
9
9
  sqlframe/base/exceptions.py,sha256=9Uwvqn2eAkDpqm4BrRgbL61qM-GMCbJEMAW8otxO46s,370
10
10
  sqlframe/base/function_alternatives.py,sha256=IxNBqplehkAEkpzA625Dif-9Xyi4Hrho81A9U262rV0,50714
@@ -107,8 +107,8 @@ sqlframe/standalone/udf.py,sha256=azmgtUjHNIPs0WMVNId05SHwiYn41MKVBhKXsQJ5dmY,27
107
107
  sqlframe/standalone/window.py,sha256=6GKPzuxeSapJakBaKBeT9VpED1ACdjggDv9JRILDyV0,35
108
108
  sqlframe/testing/__init__.py,sha256=VVCosQhitU74A3NnE52O4mNtGZONapuEXcc20QmSlnQ,132
109
109
  sqlframe/testing/utils.py,sha256=9DDYVuocO7tygee3RaajuJNZ24sJwf_LY556kKg7kTw,13011
110
- sqlframe-3.4.0.dist-info/LICENSE,sha256=VZu79YgW780qxaFJMr0t5ZgbOYEh04xWoxaWOaqIGWk,1068
111
- sqlframe-3.4.0.dist-info/METADATA,sha256=IDBAwEcCrJfWwGuAaa8kfV3Jxlte38uOYO87zcFWJfY,8639
112
- sqlframe-3.4.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
113
- sqlframe-3.4.0.dist-info/top_level.txt,sha256=T0_RpoygaZSF6heeWwIDQgaP0varUdSK1pzjeJZRjM8,9
114
- sqlframe-3.4.0.dist-info/RECORD,,
110
+ sqlframe-3.4.1.dist-info/LICENSE,sha256=VZu79YgW780qxaFJMr0t5ZgbOYEh04xWoxaWOaqIGWk,1068
111
+ sqlframe-3.4.1.dist-info/METADATA,sha256=AhBfRu7B6juTMVvsb9xiFk3pbpINYWEKKz8hASjyfgU,8639
112
+ sqlframe-3.4.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
113
+ sqlframe-3.4.1.dist-info/top_level.txt,sha256=T0_RpoygaZSF6heeWwIDQgaP0varUdSK1pzjeJZRjM8,9
114
+ sqlframe-3.4.1.dist-info/RECORD,,