fakesnow 0.9.11__py3-none-any.whl → 0.9.13__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/__init__.py +6 -1
- fakesnow/fakes.py +31 -12
- fakesnow/transforms.py +2 -4
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.13.dist-info}/METADATA +2 -2
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.13.dist-info}/RECORD +9 -9
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.13.dist-info}/LICENSE +0 -0
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.13.dist-info}/WHEEL +0 -0
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.13.dist-info}/entry_points.txt +0 -0
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.13.dist-info}/top_level.txt +0 -0
fakesnow/__init__.py
CHANGED
@@ -21,6 +21,7 @@ def patch(
|
|
21
21
|
create_database_on_connect: bool = True,
|
22
22
|
create_schema_on_connect: bool = True,
|
23
23
|
db_path: str | os.PathLike | None = None,
|
24
|
+
nop_regexes: list[str] | None = None,
|
24
25
|
) -> Iterator[None]:
|
25
26
|
"""Patch snowflake targets with fakes.
|
26
27
|
|
@@ -36,8 +37,11 @@ def patch(
|
|
36
37
|
|
37
38
|
create_database_on_connect (bool, optional): Create database if provided in connection. Defaults to True.
|
38
39
|
create_schema_on_connect (bool, optional): Create schema if provided in connection. Defaults to True.
|
39
|
-
db_path (str | os.PathLike | None, optional):
|
40
|
+
db_path (str | os.PathLike | None, optional): Use existing database files from this path
|
40
41
|
or create them here if they don't already exist. If None databases are in-memory. Defaults to None.
|
42
|
+
nop_regexes (list[str] | None, optional): SQL statements matching these regexes (case-insensitive) will return
|
43
|
+
the success response without being run. Useful to skip over SQL commands that aren't implemented yet.
|
44
|
+
Defaults to None.
|
41
45
|
|
42
46
|
Yields:
|
43
47
|
Iterator[None]: None.
|
@@ -57,6 +61,7 @@ def patch(
|
|
57
61
|
create_database=create_database_on_connect,
|
58
62
|
create_schema=create_schema_on_connect,
|
59
63
|
db_path=db_path,
|
64
|
+
nop_regexes=nop_regexes,
|
60
65
|
**kwargs,
|
61
66
|
),
|
62
67
|
snowflake.connector.pandas_tools.write_pandas: fakes.write_pandas,
|
fakesnow/fakes.py
CHANGED
@@ -16,6 +16,7 @@ from sqlglot import exp
|
|
16
16
|
if TYPE_CHECKING:
|
17
17
|
import pandas as pd
|
18
18
|
import pyarrow.lib
|
19
|
+
import numpy as np
|
19
20
|
import pyarrow
|
20
21
|
import snowflake.connector.converter
|
21
22
|
import snowflake.connector.errors
|
@@ -134,8 +135,11 @@ class FakeSnowflakeCursor:
|
|
134
135
|
print(f"{command};{params=}" if params else f"{command};", file=sys.stderr)
|
135
136
|
|
136
137
|
command, params = self._rewrite_with_params(command, params)
|
137
|
-
|
138
|
-
|
138
|
+
if self._conn.nop_regexes and any(re.match(p, command, re.IGNORECASE) for p in self._conn.nop_regexes):
|
139
|
+
transformed = transforms.SUCCESS_NOP
|
140
|
+
else:
|
141
|
+
expression = parse_one(command, read="snowflake")
|
142
|
+
transformed = self._transform(expression)
|
139
143
|
return self._execute(transformed, params)
|
140
144
|
except snowflake.connector.errors.ProgrammingError as e:
|
141
145
|
self._sqlstate = e.sqlstate
|
@@ -501,6 +505,7 @@ class FakeSnowflakeConnection:
|
|
501
505
|
create_database: bool = True,
|
502
506
|
create_schema: bool = True,
|
503
507
|
db_path: str | os.PathLike | None = None,
|
508
|
+
nop_regexes: list[str] | None = None,
|
504
509
|
*args: Any,
|
505
510
|
**kwargs: Any,
|
506
511
|
):
|
@@ -512,6 +517,7 @@ class FakeSnowflakeConnection:
|
|
512
517
|
self.database_set = False
|
513
518
|
self.schema_set = False
|
514
519
|
self.db_path = db_path
|
520
|
+
self.nop_regexes = nop_regexes
|
515
521
|
self._paramstyle = snowflake.connector.paramstyle
|
516
522
|
|
517
523
|
create_global_database(duck_conn)
|
@@ -606,9 +612,7 @@ class FakeSnowflakeConnection:
|
|
606
612
|
def rollback(self) -> None:
|
607
613
|
self.cursor().execute("ROLLBACK")
|
608
614
|
|
609
|
-
def _insert_df(
|
610
|
-
self, df: pd.DataFrame, table_name: str, database: str | None = None, schema: str | None = None
|
611
|
-
) -> int:
|
615
|
+
def _insert_df(self, df: pd.DataFrame, table_name: str) -> int:
|
612
616
|
# Objects in dataframes are written as parquet structs, and snowflake loads parquet structs as json strings.
|
613
617
|
# Whereas duckdb analyses a dataframe see https://duckdb.org/docs/api/python/data_ingestion.html#pandas-dataframes--object-columns
|
614
618
|
# and converts a object to the most specific type possible, eg: dict -> STRUCT, MAP or varchar, and list -> LIST
|
@@ -630,12 +634,7 @@ class FakeSnowflakeConnection:
|
|
630
634
|
df[col] = df[col].apply(lambda x: json.dumps(x) if isinstance(x, (dict, list)) else x)
|
631
635
|
|
632
636
|
escaped_cols = ",".join(f'"{col}"' for col in df.columns.to_list())
|
633
|
-
|
634
|
-
if schema:
|
635
|
-
table_name = f"{schema}.{table_name}"
|
636
|
-
if database:
|
637
|
-
name = f"{database}.{table_name}"
|
638
|
-
self._duck_conn.execute(f"INSERT INTO {name}({escaped_cols}) SELECT * FROM df")
|
637
|
+
self._duck_conn.execute(f"INSERT INTO {table_name}({escaped_cols}) SELECT * FROM df")
|
639
638
|
|
640
639
|
return self._duck_conn.fetchall()[0][0]
|
641
640
|
|
@@ -685,6 +684,15 @@ WritePandasResult = tuple[
|
|
685
684
|
]
|
686
685
|
|
687
686
|
|
687
|
+
def sql_type(dtype: np.dtype) -> str:
|
688
|
+
if str(dtype) == "int64":
|
689
|
+
return "NUMBER"
|
690
|
+
elif str(dtype) == "object":
|
691
|
+
return "VARCHAR"
|
692
|
+
else:
|
693
|
+
raise NotImplementedError(f"sql_type {dtype=}")
|
694
|
+
|
695
|
+
|
688
696
|
def write_pandas(
|
689
697
|
conn: FakeSnowflakeConnection,
|
690
698
|
df: pd.DataFrame,
|
@@ -702,7 +710,18 @@ def write_pandas(
|
|
702
710
|
table_type: Literal["", "temp", "temporary", "transient"] = "",
|
703
711
|
**kwargs: Any,
|
704
712
|
) -> WritePandasResult:
|
705
|
-
|
713
|
+
name = table_name
|
714
|
+
if schema:
|
715
|
+
name = f"{schema}.{name}"
|
716
|
+
if database:
|
717
|
+
name = f"{database}.{name}"
|
718
|
+
|
719
|
+
if auto_create_table:
|
720
|
+
cols = [f"{c} {sql_type(t)}" for c, t in df.dtypes.to_dict().items()]
|
721
|
+
|
722
|
+
conn.cursor().execute(f"CREATE TABLE IF NOT EXISTS {name} ({','.join(cols)})")
|
723
|
+
|
724
|
+
count = conn._insert_df(df, name) # noqa: SLF001
|
706
725
|
|
707
726
|
# mocks https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html#output
|
708
727
|
mock_copy_results = [("fakesnow/file0.txt", "LOADED", count, count, 1, 0, None, None, None, None)]
|
fakesnow/transforms.py
CHANGED
@@ -1122,12 +1122,10 @@ def timestamp_ntz_ns(expression: exp.Expression) -> exp.Expression:
|
|
1122
1122
|
|
1123
1123
|
if (
|
1124
1124
|
isinstance(expression, exp.DataType)
|
1125
|
-
and expression.this == exp.DataType.Type.
|
1125
|
+
and expression.this == exp.DataType.Type.TIMESTAMPNTZ
|
1126
1126
|
and exp.DataTypeParam(this=exp.Literal(this="9", is_string=False)) in expression.expressions
|
1127
1127
|
):
|
1128
|
-
|
1129
|
-
del new.args["expressions"]
|
1130
|
-
return new
|
1128
|
+
return exp.DataType(this=exp.DataType.Type.TIMESTAMP)
|
1131
1129
|
|
1132
1130
|
return expression
|
1133
1131
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: fakesnow
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.13
|
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
|
@@ -213,7 +213,7 @@ License-File: LICENSE
|
|
213
213
|
Requires-Dist: duckdb ~=0.10.0
|
214
214
|
Requires-Dist: pyarrow
|
215
215
|
Requires-Dist: snowflake-connector-python
|
216
|
-
Requires-Dist: sqlglot ~=23.
|
216
|
+
Requires-Dist: sqlglot ~=23.14.0
|
217
217
|
Provides-Extra: dev
|
218
218
|
Requires-Dist: build ~=1.0 ; extra == 'dev'
|
219
219
|
Requires-Dist: pandas-stubs ; extra == 'dev'
|
@@ -1,18 +1,18 @@
|
|
1
|
-
fakesnow/__init__.py,sha256=
|
1
|
+
fakesnow/__init__.py,sha256=7040jPjD-bNJDU4Lel42CD_DU47oeu1IsY9Fx_DlslQ,3799
|
2
2
|
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=q_mTOnNqYdXfrHohTRarGQG1ygh-QXV-7mCptpJ1OQ8,30231
|
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=gQJVehhUXNecnCe8GVC5EM9MBsSPNUHjz9_djUAyJUI,50648
|
13
|
+
fakesnow-0.9.13.dist-info/LICENSE,sha256=kW-7NWIyaRMQiDpryfSmF2DObDZHGR1cJZ39s6B1Svg,11344
|
14
|
+
fakesnow-0.9.13.dist-info/METADATA,sha256=1j1kYYfrf6tztJ24t45oMew6ShCqwnP8VDu00I4sbag,17841
|
15
|
+
fakesnow-0.9.13.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
16
|
+
fakesnow-0.9.13.dist-info/entry_points.txt,sha256=2riAUgu928ZIHawtO8EsfrMEJhi-EH-z_Vq7Q44xKPM,47
|
17
|
+
fakesnow-0.9.13.dist-info/top_level.txt,sha256=500evXI1IFX9so82cizGIEMHAb_dJNPaZvd2H9dcKTA,24
|
18
|
+
fakesnow-0.9.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|