fakesnow 0.9.16__py3-none-any.whl → 0.9.18__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 +4 -2
- fakesnow/transforms.py +38 -4
- {fakesnow-0.9.16.dist-info → fakesnow-0.9.18.dist-info}/METADATA +3 -3
- {fakesnow-0.9.16.dist-info → fakesnow-0.9.18.dist-info}/RECORD +8 -8
- {fakesnow-0.9.16.dist-info → fakesnow-0.9.18.dist-info}/LICENSE +0 -0
- {fakesnow-0.9.16.dist-info → fakesnow-0.9.18.dist-info}/WHEEL +0 -0
- {fakesnow-0.9.16.dist-info → fakesnow-0.9.18.dist-info}/entry_points.txt +0 -0
- {fakesnow-0.9.16.dist-info → fakesnow-0.9.18.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)
|
@@ -609,7 +611,7 @@ class FakeSnowflakeConnection:
|
|
609
611
|
cursors = [
|
610
612
|
self.cursor(cursor_class).execute(e.sql(dialect="snowflake"))
|
611
613
|
for e in sqlglot.parse(sql_text, read="snowflake")
|
612
|
-
if e
|
614
|
+
if e and not isinstance(e, exp.Semicolon) # ignore comments
|
613
615
|
]
|
614
616
|
return cursors if return_cursors else []
|
615
617
|
|
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
|
@@ -116,9 +119,11 @@ def create_database(expression: exp.Expression, db_path: Path | None = None) ->
|
|
116
119
|
db_name = ident.this
|
117
120
|
db_file = f"{db_path/db_name}.db" if db_path else ":memory:"
|
118
121
|
|
122
|
+
if_not_exists = "IF NOT EXISTS " if expression.args.get("exists") else ""
|
123
|
+
|
119
124
|
return exp.Command(
|
120
125
|
this="ATTACH",
|
121
|
-
expression=exp.Literal(this=f"DATABASE '{db_file}' AS {db_name}", is_string=True),
|
126
|
+
expression=exp.Literal(this=f"{if_not_exists}DATABASE '{db_file}' AS {db_name}", is_string=True),
|
122
127
|
create_db_name=db_name,
|
123
128
|
)
|
124
129
|
|
@@ -436,7 +441,7 @@ def flatten(expression: exp.Expression) -> exp.Expression:
|
|
436
441
|
isinstance(expression, exp.Lateral)
|
437
442
|
and isinstance(expression.this, exp.Explode)
|
438
443
|
and (alias := expression.args.get("alias"))
|
439
|
-
# always true; when no explicit alias provided this will be
|
444
|
+
# always true; when no explicit alias provided this will be flattened
|
440
445
|
and isinstance(alias, exp.TableAlias)
|
441
446
|
):
|
442
447
|
explode_expression = expression.this.this.expression
|
@@ -460,6 +465,25 @@ def flatten(expression: exp.Expression) -> exp.Expression:
|
|
460
465
|
return expression
|
461
466
|
|
462
467
|
|
468
|
+
def flatten_value_cast_as_varchar(expression: exp.Expression) -> exp.Expression:
|
469
|
+
"""Return raw unquoted string when flatten VALUE is cast to varchar.
|
470
|
+
|
471
|
+
Returns a raw string using the Duckdb ->> operator, aka the json_extract_string function, see
|
472
|
+
https://duckdb.org/docs/extensions/json#json-extraction-functions
|
473
|
+
"""
|
474
|
+
if (
|
475
|
+
isinstance(expression, exp.Cast)
|
476
|
+
and isinstance(expression.this, exp.Column)
|
477
|
+
and expression.this.name.upper() == "VALUE"
|
478
|
+
and expression.to.this in [exp.DataType.Type.VARCHAR, exp.DataType.Type.TEXT]
|
479
|
+
and (select := expression.find_ancestor(exp.Select))
|
480
|
+
and select.find(exp.Explode)
|
481
|
+
):
|
482
|
+
return exp.JSONExtractScalar(this=expression.this, expression=exp.JSONPath(expressions=[exp.JSONPathRoot()]))
|
483
|
+
|
484
|
+
return expression
|
485
|
+
|
486
|
+
|
463
487
|
def float_to_double(expression: exp.Expression) -> exp.Expression:
|
464
488
|
"""Convert float to double for 64 bit precision.
|
465
489
|
|
@@ -931,6 +955,16 @@ def show_schemas(expression: exp.Expression, current_database: str | None = None
|
|
931
955
|
return expression
|
932
956
|
|
933
957
|
|
958
|
+
def split(expression: exp.Expression) -> exp.Expression:
|
959
|
+
"""
|
960
|
+
Convert output of duckdb str_split from varchar[] to JSON array to match Snowflake.
|
961
|
+
"""
|
962
|
+
if isinstance(expression, exp.Split):
|
963
|
+
return exp.Anonymous(this="to_json", expressions=[expression])
|
964
|
+
|
965
|
+
return expression
|
966
|
+
|
967
|
+
|
934
968
|
def tag(expression: exp.Expression) -> exp.Expression:
|
935
969
|
"""Handle tags. Transfer tags into upserts of the tag table.
|
936
970
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: fakesnow
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.18
|
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=u2EDQ_fXQFFx5bq5pgLrUXV33Flgg5U82L7LIvFiqGw,30556
|
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=1xok38tft_VowwSm8kKA3P3OEZEeGF09hqfpawxXNaY,52648
|
13
|
+
fakesnow-0.9.18.dist-info/LICENSE,sha256=kW-7NWIyaRMQiDpryfSmF2DObDZHGR1cJZ39s6B1Svg,11344
|
14
|
+
fakesnow-0.9.18.dist-info/METADATA,sha256=cmS6VqDOHlkSZgfhT7biB03DuSktq4DNtv3EYbFDrrg,17839
|
15
|
+
fakesnow-0.9.18.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
16
|
+
fakesnow-0.9.18.dist-info/entry_points.txt,sha256=2riAUgu928ZIHawtO8EsfrMEJhi-EH-z_Vq7Q44xKPM,47
|
17
|
+
fakesnow-0.9.18.dist-info/top_level.txt,sha256=500evXI1IFX9so82cizGIEMHAb_dJNPaZvd2H9dcKTA,24
|
18
|
+
fakesnow-0.9.18.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|