fakesnow 0.9.15__py3-none-any.whl → 0.9.17__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.
- fakesnow/fakes.py +5 -3
- fakesnow/transforms.py +35 -3
- {fakesnow-0.9.15.dist-info → fakesnow-0.9.17.dist-info}/METADATA +3 -3
- {fakesnow-0.9.15.dist-info → fakesnow-0.9.17.dist-info}/RECORD +8 -8
- {fakesnow-0.9.15.dist-info → fakesnow-0.9.17.dist-info}/LICENSE +0 -0
- {fakesnow-0.9.15.dist-info → fakesnow-0.9.17.dist-info}/WHEEL +0 -0
- {fakesnow-0.9.15.dist-info → fakesnow-0.9.17.dist-info}/entry_points.txt +0 -0
- {fakesnow-0.9.15.dist-info → fakesnow-0.9.17.dist-info}/top_level.txt +0 -0
fakesnow/fakes.py
CHANGED
@@ -158,6 +158,7 @@ class FakeSnowflakeCursor:
|
|
158
158
|
.transform(transforms.tag)
|
159
159
|
.transform(transforms.semi_structured_types)
|
160
160
|
.transform(transforms.try_parse_json)
|
161
|
+
.transform(transforms.split)
|
161
162
|
# NOTE: trim_cast_varchar must be before json_extract_cast_as_varchar
|
162
163
|
.transform(transforms.trim_cast_varchar)
|
163
164
|
# indices_to_json_extract must be before regex_substr
|
@@ -165,6 +166,7 @@ class FakeSnowflakeCursor:
|
|
165
166
|
.transform(transforms.json_extract_cast_as_varchar)
|
166
167
|
.transform(transforms.json_extract_cased_as_varchar)
|
167
168
|
.transform(transforms.json_extract_precedence)
|
169
|
+
.transform(transforms.flatten_value_cast_as_varchar)
|
168
170
|
.transform(transforms.flatten)
|
169
171
|
.transform(transforms.regex_replace)
|
170
172
|
.transform(transforms.regex_substr)
|
@@ -184,7 +186,7 @@ class FakeSnowflakeCursor:
|
|
184
186
|
.transform(transforms.random)
|
185
187
|
.transform(transforms.identifier)
|
186
188
|
.transform(transforms.array_agg_within_group)
|
187
|
-
.transform(transforms.
|
189
|
+
.transform(transforms.array_agg)
|
188
190
|
.transform(transforms.dateadd_date_cast)
|
189
191
|
.transform(transforms.dateadd_string_literal_timestamp_cast)
|
190
192
|
.transform(transforms.datediff_string_literal_timestamp_cast)
|
@@ -520,7 +522,7 @@ class FakeSnowflakeConnection:
|
|
520
522
|
self.schema = schema and schema.upper()
|
521
523
|
self.database_set = False
|
522
524
|
self.schema_set = False
|
523
|
-
self.db_path = db_path
|
525
|
+
self.db_path = Path(db_path) if db_path else None
|
524
526
|
self.nop_regexes = nop_regexes
|
525
527
|
self._paramstyle = snowflake.connector.paramstyle
|
526
528
|
|
@@ -535,7 +537,7 @@ class FakeSnowflakeConnection:
|
|
535
537
|
where catalog_name = '{self.database}'"""
|
536
538
|
).fetchone()
|
537
539
|
):
|
538
|
-
db_file = f"{
|
540
|
+
db_file = f"{self.db_path/self.database}.db" if self.db_path else ":memory:"
|
539
541
|
duck_conn.execute(f"ATTACH DATABASE '{db_file}' AS {self.database}")
|
540
542
|
duck_conn.execute(info_schema.creation_sql(self.database))
|
541
543
|
duck_conn.execute(macros.creation_sql(self.database))
|
fakesnow/transforms.py
CHANGED
@@ -41,8 +41,11 @@ def array_size(expression: exp.Expression) -> exp.Expression:
|
|
41
41
|
return expression
|
42
42
|
|
43
43
|
|
44
|
-
def
|
45
|
-
if isinstance(expression, exp.ArrayAgg):
|
44
|
+
def array_agg(expression: exp.Expression) -> exp.Expression:
|
45
|
+
if isinstance(expression, exp.ArrayAgg) and not isinstance(expression.parent, exp.Window):
|
46
|
+
return exp.Anonymous(this="TO_JSON", expressions=[expression])
|
47
|
+
|
48
|
+
if isinstance(expression, exp.Window) and isinstance(expression.this, exp.ArrayAgg):
|
46
49
|
return exp.Anonymous(this="TO_JSON", expressions=[expression])
|
47
50
|
|
48
51
|
return expression
|
@@ -436,7 +439,7 @@ def flatten(expression: exp.Expression) -> exp.Expression:
|
|
436
439
|
isinstance(expression, exp.Lateral)
|
437
440
|
and isinstance(expression.this, exp.Explode)
|
438
441
|
and (alias := expression.args.get("alias"))
|
439
|
-
# always true; when no explicit alias provided this will be
|
442
|
+
# always true; when no explicit alias provided this will be flattened
|
440
443
|
and isinstance(alias, exp.TableAlias)
|
441
444
|
):
|
442
445
|
explode_expression = expression.this.this.expression
|
@@ -460,6 +463,25 @@ def flatten(expression: exp.Expression) -> exp.Expression:
|
|
460
463
|
return expression
|
461
464
|
|
462
465
|
|
466
|
+
def flatten_value_cast_as_varchar(expression: exp.Expression) -> exp.Expression:
|
467
|
+
"""Return raw unquoted string when flatten VALUE is cast to varchar.
|
468
|
+
|
469
|
+
Returns a raw string using the Duckdb ->> operator, aka the json_extract_string function, see
|
470
|
+
https://duckdb.org/docs/extensions/json#json-extraction-functions
|
471
|
+
"""
|
472
|
+
if (
|
473
|
+
isinstance(expression, exp.Cast)
|
474
|
+
and isinstance(expression.this, exp.Column)
|
475
|
+
and expression.this.name.upper() == "VALUE"
|
476
|
+
and expression.to.this in [exp.DataType.Type.VARCHAR, exp.DataType.Type.TEXT]
|
477
|
+
and (select := expression.find_ancestor(exp.Select))
|
478
|
+
and select.find(exp.Explode)
|
479
|
+
):
|
480
|
+
return exp.JSONExtractScalar(this=expression.this, expression=exp.JSONPath(expressions=[exp.JSONPathRoot()]))
|
481
|
+
|
482
|
+
return expression
|
483
|
+
|
484
|
+
|
463
485
|
def float_to_double(expression: exp.Expression) -> exp.Expression:
|
464
486
|
"""Convert float to double for 64 bit precision.
|
465
487
|
|
@@ -931,6 +953,16 @@ def show_schemas(expression: exp.Expression, current_database: str | None = None
|
|
931
953
|
return expression
|
932
954
|
|
933
955
|
|
956
|
+
def split(expression: exp.Expression) -> exp.Expression:
|
957
|
+
"""
|
958
|
+
Convert output of duckdb str_split from varchar[] to JSON array to match Snowflake.
|
959
|
+
"""
|
960
|
+
if isinstance(expression, exp.Split):
|
961
|
+
return exp.Anonymous(this="to_json", expressions=[expression])
|
962
|
+
|
963
|
+
return expression
|
964
|
+
|
965
|
+
|
934
966
|
def tag(expression: exp.Expression) -> exp.Expression:
|
935
967
|
"""Handle tags. Transfer tags into upserts of the tag table.
|
936
968
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: fakesnow
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.17
|
4
4
|
Summary: Fake Snowflake Connector for Python. Run, mock and test Snowflake DB locally.
|
5
5
|
License: Apache License
|
6
6
|
Version 2.0, January 2004
|
@@ -210,10 +210,10 @@ Classifier: License :: OSI Approved :: MIT License
|
|
210
210
|
Requires-Python: >=3.9
|
211
211
|
Description-Content-Type: text/markdown
|
212
212
|
License-File: LICENSE
|
213
|
-
Requires-Dist: duckdb ~=0.
|
213
|
+
Requires-Dist: duckdb ~=1.0.0
|
214
214
|
Requires-Dist: pyarrow
|
215
215
|
Requires-Dist: snowflake-connector-python
|
216
|
-
Requires-Dist: sqlglot ~=
|
216
|
+
Requires-Dist: sqlglot ~=25.3.0
|
217
217
|
Provides-Extra: dev
|
218
218
|
Requires-Dist: build ~=1.0 ; extra == 'dev'
|
219
219
|
Requires-Dist: pandas-stubs ; extra == 'dev'
|
@@ -3,16 +3,16 @@ fakesnow/__main__.py,sha256=GDrGyNTvBFuqn_UfDjKs7b3LPtU6gDv1KwosVDrukIM,76
|
|
3
3
|
fakesnow/checks.py,sha256=-QMvdcrRbhN60rnzxLBJ0IkUBWyLR8gGGKKmCS0w9mA,2383
|
4
4
|
fakesnow/cli.py,sha256=9qfI-Ssr6mo8UmIlXkUAOz2z2YPBgDsrEVaZv9FjGFs,2201
|
5
5
|
fakesnow/expr.py,sha256=CAxuYIUkwI339DQIBzvFF0F-m1tcVGKEPA5rDTzmH9A,892
|
6
|
-
fakesnow/fakes.py,sha256=
|
6
|
+
fakesnow/fakes.py,sha256=lKGuMyyvrO0n4-yVplL2rTYBvNvxUi369mbNHHgm9K4,30500
|
7
7
|
fakesnow/fixtures.py,sha256=G-NkVeruSQAJ7fvSS2fR2oysUn0Yra1pohHlOvacKEk,455
|
8
8
|
fakesnow/global_database.py,sha256=WTVIP1VhNvdCeX7TQncX1TRpGQU5rBf5Pbxim40zeSU,1399
|
9
9
|
fakesnow/info_schema.py,sha256=CdIcGXHEQ_kmEAzdQKvA-PX41LA6wlK-4p1J45qgKYA,6266
|
10
10
|
fakesnow/macros.py,sha256=pX1YJDnQOkFJSHYUjQ6ErEkYIKvFI6Ncz_au0vv1csA,265
|
11
11
|
fakesnow/py.typed,sha256=B-DLSjYBi7pkKjwxCSdpVj2J02wgfJr-E7B1wOUyxYU,80
|
12
|
-
fakesnow/transforms.py,sha256=
|
13
|
-
fakesnow-0.9.
|
14
|
-
fakesnow-0.9.
|
15
|
-
fakesnow-0.9.
|
16
|
-
fakesnow-0.9.
|
17
|
-
fakesnow-0.9.
|
18
|
-
fakesnow-0.9.
|
12
|
+
fakesnow/transforms.py,sha256=OJfn5VQQnBBnaR7aumeOn-KsIR8rDmmheYXUr6iWNKc,52550
|
13
|
+
fakesnow-0.9.17.dist-info/LICENSE,sha256=kW-7NWIyaRMQiDpryfSmF2DObDZHGR1cJZ39s6B1Svg,11344
|
14
|
+
fakesnow-0.9.17.dist-info/METADATA,sha256=EeO3vtWPNrpM_Phvnaqa2unyRgync6U5Ea6YwWHtA78,17839
|
15
|
+
fakesnow-0.9.17.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
16
|
+
fakesnow-0.9.17.dist-info/entry_points.txt,sha256=2riAUgu928ZIHawtO8EsfrMEJhi-EH-z_Vq7Q44xKPM,47
|
17
|
+
fakesnow-0.9.17.dist-info/top_level.txt,sha256=500evXI1IFX9so82cizGIEMHAb_dJNPaZvd2H9dcKTA,24
|
18
|
+
fakesnow-0.9.17.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|