sqlmesh 0.188.2.dev17__py3-none-any.whl → 0.188.2.dev18__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.
- sqlmesh/_version.py +2 -2
- sqlmesh/core/console.py +1 -1
- sqlmesh/core/context.py +5 -1
- sqlmesh/core/dialect.py +2 -1
- sqlmesh/core/engine_adapter/_typing.py +1 -1
- sqlmesh/core/engine_adapter/base.py +15 -2
- sqlmesh/core/engine_adapter/bigquery.py +3 -1
- sqlmesh/core/engine_adapter/clickhouse.py +2 -1
- sqlmesh/core/engine_adapter/databricks.py +4 -1
- sqlmesh/core/engine_adapter/mssql.py +7 -2
- sqlmesh/core/engine_adapter/redshift.py +6 -1
- sqlmesh/core/engine_adapter/snowflake.py +6 -2
- sqlmesh/core/engine_adapter/spark.py +3 -1
- sqlmesh/core/engine_adapter/trino.py +4 -2
- sqlmesh/core/model/definition.py +2 -1
- sqlmesh/core/model/seed.py +5 -1
- sqlmesh/core/snapshot/evaluator.py +4 -1
- sqlmesh/core/state_sync/db/environment.py +7 -1
- sqlmesh/core/state_sync/db/interval.py +7 -1
- sqlmesh/core/state_sync/db/snapshot.py +6 -1
- sqlmesh/core/state_sync/db/version.py +2 -1
- sqlmesh/core/table_diff.py +18 -2
- sqlmesh/core/test/definition.py +13 -2
- sqlmesh/dbt/adapter.py +2 -1
- sqlmesh/dbt/util.py +5 -1
- sqlmesh/migrations/v0007_env_table_info_to_kind.py +2 -1
- sqlmesh/migrations/v0009_remove_pre_post_hooks.py +2 -1
- sqlmesh/migrations/v0011_add_model_kind_name.py +2 -1
- sqlmesh/migrations/v0012_update_jinja_expressions.py +2 -1
- sqlmesh/migrations/v0013_serde_using_model_dialects.py +2 -1
- sqlmesh/migrations/v0016_fix_windows_path.py +2 -1
- sqlmesh/migrations/v0017_fix_windows_seed_path.py +2 -1
- sqlmesh/migrations/v0018_rename_snapshot_model_to_node.py +2 -1
- sqlmesh/migrations/v0020_remove_redundant_attributes_from_dbt_models.py +2 -1
- sqlmesh/migrations/v0021_fix_table_properties.py +2 -1
- sqlmesh/migrations/v0022_move_project_to_model.py +2 -1
- sqlmesh/migrations/v0024_replace_model_kind_name_enum_with_value.py +2 -1
- sqlmesh/migrations/v0025_fix_intervals_and_missing_change_category.py +2 -1
- sqlmesh/migrations/v0026_remove_dialect_from_seed.py +2 -1
- sqlmesh/migrations/v0027_minute_interval_to_five.py +2 -1
- sqlmesh/migrations/v0029_generate_schema_types_using_dialect.py +2 -1
- sqlmesh/migrations/v0030_update_unrestorable_snapshots.py +2 -1
- sqlmesh/migrations/v0031_remove_dbt_target_fields.py +2 -1
- sqlmesh/migrations/v0034_add_default_catalog.py +2 -1
- sqlmesh/migrations/v0037_remove_dbt_is_incremental_macro.py +2 -1
- sqlmesh/migrations/v0038_add_expiration_ts_to_snapshot.py +2 -1
- sqlmesh/migrations/v0039_include_environment_in_plan_dag_spec.py +2 -1
- sqlmesh/migrations/v0041_remove_hash_raw_query_attribute.py +2 -1
- sqlmesh/migrations/v0042_trim_indirect_versions.py +2 -1
- sqlmesh/migrations/v0043_fix_remove_obsolete_attributes_in_plan_dags.py +2 -1
- sqlmesh/migrations/v0045_move_gateway_variable.py +2 -1
- sqlmesh/migrations/v0048_drop_indirect_versions.py +2 -1
- sqlmesh/migrations/v0051_rename_column_descriptions.py +2 -1
- sqlmesh/migrations/v0055_add_updated_ts_unpaused_ts_ttl_ms_unrestorable_to_snapshot.py +2 -1
- sqlmesh/migrations/v0060_move_audits_to_model.py +2 -1
- sqlmesh/migrations/v0063_change_signals.py +2 -1
- sqlmesh/migrations/v0064_join_when_matched_strings.py +2 -1
- sqlmesh/migrations/v0069_update_dev_table_suffix.py +2 -1
- sqlmesh/migrations/v0071_add_dev_version_to_intervals.py +4 -1
- sqlmesh/migrations/v0073_remove_symbolic_disable_restatement.py +2 -1
- sqlmesh/migrations/v0075_remove_validate_query.py +2 -1
- sqlmesh/migrations/v0081_update_partitioned_by.py +2 -1
- sqlmesh/utils/date.py +9 -2
- sqlmesh/utils/pandas.py +43 -33
- {sqlmesh-0.188.2.dev17.dist-info → sqlmesh-0.188.2.dev18.dist-info}/METADATA +1 -1
- {sqlmesh-0.188.2.dev17.dist-info → sqlmesh-0.188.2.dev18.dist-info}/RECORD +72 -72
- web/server/api/endpoints/commands.py +2 -1
- web/server/utils.py +3 -1
- {sqlmesh-0.188.2.dev17.dist-info → sqlmesh-0.188.2.dev18.dist-info}/WHEEL +0 -0
- {sqlmesh-0.188.2.dev17.dist-info → sqlmesh-0.188.2.dev18.dist-info}/entry_points.txt +0 -0
- {sqlmesh-0.188.2.dev17.dist-info → sqlmesh-0.188.2.dev18.dist-info}/licenses/LICENSE +0 -0
- {sqlmesh-0.188.2.dev17.dist-info → sqlmesh-0.188.2.dev18.dist-info}/top_level.txt +0 -0
sqlmesh/_version.py
CHANGED
|
@@ -17,5 +17,5 @@ __version__: str
|
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
|
18
18
|
version_tuple: VERSION_TUPLE
|
|
19
19
|
|
|
20
|
-
__version__ = version = '0.188.2.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 188, 2, '
|
|
20
|
+
__version__ = version = '0.188.2.dev18'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 188, 2, 'dev18')
|
sqlmesh/core/console.py
CHANGED
|
@@ -8,7 +8,6 @@ import uuid
|
|
|
8
8
|
import logging
|
|
9
9
|
import textwrap
|
|
10
10
|
from pathlib import Path
|
|
11
|
-
import pandas as pd
|
|
12
11
|
import numpy as np
|
|
13
12
|
from hyperscript import h
|
|
14
13
|
from rich.console import Console as RichConsole
|
|
@@ -2497,6 +2496,7 @@ class TerminalConsole(Console):
|
|
|
2497
2496
|
|
|
2498
2497
|
def _cells_match(x: t.Any, y: t.Any) -> bool:
|
|
2499
2498
|
"""Helper function to compare two cells and returns true if they're equal, handling array objects."""
|
|
2499
|
+
import pandas as pd
|
|
2500
2500
|
|
|
2501
2501
|
# Convert array-like objects to list for consistent comparison
|
|
2502
2502
|
def _normalize(val: t.Any) -> t.Any:
|
sqlmesh/core/context.py
CHANGED
|
@@ -48,7 +48,6 @@ from pathlib import Path
|
|
|
48
48
|
from shutil import rmtree
|
|
49
49
|
from types import MappingProxyType
|
|
50
50
|
|
|
51
|
-
import pandas as pd
|
|
52
51
|
from sqlglot import Dialect, exp
|
|
53
52
|
from sqlglot.helper import first
|
|
54
53
|
from sqlglot.lineage import GraphHTML
|
|
@@ -134,6 +133,7 @@ from sqlmesh.utils.config import print_config
|
|
|
134
133
|
from sqlmesh.utils.jinja import JinjaMacroRegistry
|
|
135
134
|
|
|
136
135
|
if t.TYPE_CHECKING:
|
|
136
|
+
import pandas as pd
|
|
137
137
|
from typing_extensions import Literal
|
|
138
138
|
|
|
139
139
|
from sqlmesh.core.engine_adapter._typing import (
|
|
@@ -1007,6 +1007,8 @@ class GenericContext(BaseContext, t.Generic[C]):
|
|
|
1007
1007
|
expand = self.dag.upstream(model.fqn) if expand is True else expand or []
|
|
1008
1008
|
|
|
1009
1009
|
if model.is_seed:
|
|
1010
|
+
import pandas as pd
|
|
1011
|
+
|
|
1010
1012
|
df = next(
|
|
1011
1013
|
model.render(
|
|
1012
1014
|
context=self.execution_context(
|
|
@@ -2013,6 +2015,8 @@ class GenericContext(BaseContext, t.Generic[C]):
|
|
|
2013
2015
|
) -> ModelTextTestResult:
|
|
2014
2016
|
"""Discover and run model tests"""
|
|
2015
2017
|
if verbosity >= Verbosity.VERBOSE:
|
|
2018
|
+
import pandas as pd
|
|
2019
|
+
|
|
2016
2020
|
pd.set_option("display.max_columns", None)
|
|
2017
2021
|
|
|
2018
2022
|
test_meta = self.load_model_tests(tests=tests, patterns=match_patterns)
|
sqlmesh/core/dialect.py
CHANGED
|
@@ -10,7 +10,6 @@ from difflib import unified_diff
|
|
|
10
10
|
from enum import Enum, auto
|
|
11
11
|
from functools import lru_cache
|
|
12
12
|
|
|
13
|
-
import pandas as pd
|
|
14
13
|
from sqlglot import Dialect, Generator, ParseError, Parser, Tokenizer, TokenType, exp
|
|
15
14
|
from sqlglot.dialects.dialect import DialectType
|
|
16
15
|
from sqlglot.dialects import DuckDB, Snowflake
|
|
@@ -27,6 +26,8 @@ from sqlmesh.utils.errors import SQLMeshError, ConfigError
|
|
|
27
26
|
from sqlmesh.utils.pandas import columns_to_types_from_df
|
|
28
27
|
|
|
29
28
|
if t.TYPE_CHECKING:
|
|
29
|
+
import pandas as pd
|
|
30
|
+
|
|
30
31
|
from sqlglot._typing import E
|
|
31
32
|
|
|
32
33
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import typing as t
|
|
2
2
|
|
|
3
|
-
import pandas as pd
|
|
4
3
|
from sqlglot import exp
|
|
5
4
|
|
|
6
5
|
from sqlmesh.utils import optional_import
|
|
7
6
|
|
|
8
7
|
if t.TYPE_CHECKING:
|
|
8
|
+
import pandas as pd
|
|
9
9
|
import pyspark
|
|
10
10
|
import pyspark.sql.connect.dataframe
|
|
11
11
|
from bigframes.session import Session as BigframeSession # noqa
|
|
@@ -16,7 +16,6 @@ import sys
|
|
|
16
16
|
import typing as t
|
|
17
17
|
from functools import partial
|
|
18
18
|
|
|
19
|
-
import pandas as pd
|
|
20
19
|
from sqlglot import Dialect, exp
|
|
21
20
|
from sqlglot.errors import ErrorLevel
|
|
22
21
|
from sqlglot.helper import ensure_list
|
|
@@ -51,6 +50,8 @@ from sqlmesh.utils.errors import (
|
|
|
51
50
|
from sqlmesh.utils.pandas import columns_to_types_from_df
|
|
52
51
|
|
|
53
52
|
if t.TYPE_CHECKING:
|
|
53
|
+
import pandas as pd
|
|
54
|
+
|
|
54
55
|
from sqlmesh.core._typing import SchemaName, SessionProperties, TableName
|
|
55
56
|
from sqlmesh.core.engine_adapter._typing import (
|
|
56
57
|
BigframeSession,
|
|
@@ -217,6 +218,8 @@ class EngineAdapter:
|
|
|
217
218
|
*,
|
|
218
219
|
batch_size: t.Optional[int] = None,
|
|
219
220
|
) -> t.List[SourceQuery]:
|
|
221
|
+
import pandas as pd
|
|
222
|
+
|
|
220
223
|
batch_size = self.DEFAULT_BATCH_SIZE if batch_size is None else batch_size
|
|
221
224
|
if isinstance(query_or_df, (exp.Query, exp.DerivedTable)):
|
|
222
225
|
return [SourceQuery(query_factory=lambda: query_or_df)] # type: ignore
|
|
@@ -244,6 +247,8 @@ class EngineAdapter:
|
|
|
244
247
|
batch_size: int,
|
|
245
248
|
target_table: TableName,
|
|
246
249
|
) -> t.List[SourceQuery]:
|
|
250
|
+
import pandas as pd
|
|
251
|
+
|
|
247
252
|
assert isinstance(df, pd.DataFrame)
|
|
248
253
|
num_rows = len(df.index)
|
|
249
254
|
batch_size = sys.maxsize if batch_size == 0 else batch_size
|
|
@@ -257,7 +262,7 @@ class EngineAdapter:
|
|
|
257
262
|
SourceQuery(
|
|
258
263
|
query_factory=partial(
|
|
259
264
|
self._values_to_sql,
|
|
260
|
-
values=values,
|
|
265
|
+
values=values, # type: ignore
|
|
261
266
|
columns_to_types=columns_to_types,
|
|
262
267
|
batch_start=i,
|
|
263
268
|
batch_end=min(i + batch_size, num_rows),
|
|
@@ -295,6 +300,8 @@ class EngineAdapter:
|
|
|
295
300
|
def _columns_to_types(
|
|
296
301
|
self, query_or_df: QueryOrDF, columns_to_types: t.Optional[t.Dict[str, exp.DataType]] = None
|
|
297
302
|
) -> t.Optional[t.Dict[str, exp.DataType]]:
|
|
303
|
+
import pandas as pd
|
|
304
|
+
|
|
298
305
|
if columns_to_types:
|
|
299
306
|
return columns_to_types
|
|
300
307
|
if isinstance(query_or_df, pd.DataFrame):
|
|
@@ -1006,6 +1013,8 @@ class EngineAdapter:
|
|
|
1006
1013
|
view_properties: Optional view properties to add to the view.
|
|
1007
1014
|
create_kwargs: Additional kwargs to pass into the Create expression
|
|
1008
1015
|
"""
|
|
1016
|
+
import pandas as pd
|
|
1017
|
+
|
|
1009
1018
|
if materialized_properties and not materialized:
|
|
1010
1019
|
raise SQLMeshError("Materialized properties are only supported for materialized views")
|
|
1011
1020
|
|
|
@@ -2012,6 +2021,8 @@ class EngineAdapter:
|
|
|
2012
2021
|
"""
|
|
2013
2022
|
Take a "native" DataFrame (eg Pyspark, Bigframe, Snowpark etc) and convert it to Pandas
|
|
2014
2023
|
"""
|
|
2024
|
+
import pandas as pd
|
|
2025
|
+
|
|
2015
2026
|
if isinstance(query_or_df, (exp.Query, exp.DerivedTable, pd.DataFrame)):
|
|
2016
2027
|
return query_or_df
|
|
2017
2028
|
|
|
@@ -2022,6 +2033,8 @@ class EngineAdapter:
|
|
|
2022
2033
|
self, query: t.Union[exp.Expression, str], quote_identifiers: bool = False
|
|
2023
2034
|
) -> pd.DataFrame:
|
|
2024
2035
|
"""Fetches a Pandas DataFrame from the cursor"""
|
|
2036
|
+
import pandas as pd
|
|
2037
|
+
|
|
2025
2038
|
df = self._fetch_native_df(query, quote_identifiers=quote_identifiers)
|
|
2026
2039
|
if not isinstance(df, pd.DataFrame):
|
|
2027
2040
|
raise NotImplementedError(
|
|
@@ -4,7 +4,6 @@ import logging
|
|
|
4
4
|
import typing as t
|
|
5
5
|
from collections import defaultdict
|
|
6
6
|
|
|
7
|
-
import pandas as pd
|
|
8
7
|
from sqlglot import exp, parse_one
|
|
9
8
|
from sqlglot.transforms import remove_precision_parameterized_types
|
|
10
9
|
|
|
@@ -29,6 +28,7 @@ from sqlmesh.utils.errors import SQLMeshError
|
|
|
29
28
|
from sqlmesh.utils.pandas import columns_to_types_from_dtypes
|
|
30
29
|
|
|
31
30
|
if t.TYPE_CHECKING:
|
|
31
|
+
import pandas as pd
|
|
32
32
|
from google.api_core.retry import Retry
|
|
33
33
|
from google.cloud import bigquery
|
|
34
34
|
from google.cloud.bigquery import StandardSqlDataType
|
|
@@ -147,6 +147,8 @@ class BigQueryEngineAdapter(InsertOverwriteWithMergeMixin, ClusteredByMixin, Row
|
|
|
147
147
|
batch_size: int,
|
|
148
148
|
target_table: TableName,
|
|
149
149
|
) -> t.List[SourceQuery]:
|
|
150
|
+
import pandas as pd
|
|
151
|
+
|
|
150
152
|
temp_bq_table = self.__get_temp_bq_table(
|
|
151
153
|
self._get_temp_table(target_table or "pandas"), columns_to_types
|
|
152
154
|
)
|
|
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing as t
|
|
4
4
|
import logging
|
|
5
|
-
import pandas as pd
|
|
6
5
|
import re
|
|
7
6
|
from sqlglot import exp, maybe_parse
|
|
8
7
|
from sqlmesh.core.dialect import to_schema
|
|
@@ -19,6 +18,8 @@ from sqlmesh.core.engine_adapter.shared import (
|
|
|
19
18
|
from sqlmesh.core.schema_diff import SchemaDiffer
|
|
20
19
|
|
|
21
20
|
if t.TYPE_CHECKING:
|
|
21
|
+
import pandas as pd
|
|
22
|
+
|
|
22
23
|
from sqlmesh.core._typing import SchemaName, TableName
|
|
23
24
|
from sqlmesh.core.engine_adapter._typing import DF, Query, QueryOrDF
|
|
24
25
|
|
|
@@ -4,7 +4,6 @@ import logging
|
|
|
4
4
|
import typing as t
|
|
5
5
|
from functools import partial
|
|
6
6
|
|
|
7
|
-
import pandas as pd
|
|
8
7
|
from sqlglot import exp
|
|
9
8
|
from sqlmesh.core.dialect import to_schema
|
|
10
9
|
from sqlmesh.core.engine_adapter.shared import (
|
|
@@ -21,6 +20,8 @@ from sqlmesh.engines.spark.db_api.spark_session import connection, SparkSessionC
|
|
|
21
20
|
from sqlmesh.utils.errors import SQLMeshError, MissingDefaultCatalogError
|
|
22
21
|
|
|
23
22
|
if t.TYPE_CHECKING:
|
|
23
|
+
import pandas as pd
|
|
24
|
+
|
|
24
25
|
from sqlmesh.core._typing import SchemaName, TableName, SessionProperties
|
|
25
26
|
from sqlmesh.core.engine_adapter._typing import DF, PySparkSession, Query
|
|
26
27
|
|
|
@@ -199,6 +200,8 @@ class DatabricksEngineAdapter(SparkEngineAdapter):
|
|
|
199
200
|
"""
|
|
200
201
|
Returns a Pandas DataFrame from a query or expression.
|
|
201
202
|
"""
|
|
203
|
+
import pandas as pd
|
|
204
|
+
|
|
202
205
|
df = self._fetch_native_df(query, quote_identifiers=quote_identifiers)
|
|
203
206
|
if not isinstance(df, pd.DataFrame):
|
|
204
207
|
return df.toPandas()
|
|
@@ -5,8 +5,6 @@ from __future__ import annotations
|
|
|
5
5
|
import typing as t
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
|
-
import pandas as pd
|
|
9
|
-
from pandas.api.types import is_datetime64_any_dtype # type: ignore
|
|
10
8
|
from sqlglot import exp
|
|
11
9
|
|
|
12
10
|
from sqlmesh.core.dialect import to_schema
|
|
@@ -189,6 +187,9 @@ class MSSQLEngineAdapter(
|
|
|
189
187
|
super().drop_schema(schema_name, ignore_if_not_exists=ignore_if_not_exists, cascade=False)
|
|
190
188
|
|
|
191
189
|
def _convert_df_datetime(self, df: DF, columns_to_types: t.Dict[str, exp.DataType]) -> None:
|
|
190
|
+
import pandas as pd
|
|
191
|
+
from pandas.api.types import is_datetime64_any_dtype # type: ignore
|
|
192
|
+
|
|
192
193
|
# pymssql doesn't convert Pandas Timestamp (datetime64) types
|
|
193
194
|
# - this code is based on snowflake adapter implementation
|
|
194
195
|
for column, kind in columns_to_types.items():
|
|
@@ -213,6 +214,8 @@ class MSSQLEngineAdapter(
|
|
|
213
214
|
batch_size: int,
|
|
214
215
|
target_table: TableName,
|
|
215
216
|
) -> t.List[SourceQuery]:
|
|
217
|
+
import pandas as pd
|
|
218
|
+
|
|
216
219
|
assert isinstance(df, pd.DataFrame)
|
|
217
220
|
temp_table = self._get_temp_table(target_table or "pandas")
|
|
218
221
|
|
|
@@ -247,6 +250,8 @@ class MSSQLEngineAdapter(
|
|
|
247
250
|
"""
|
|
248
251
|
Returns all the data objects that exist in the given schema and catalog.
|
|
249
252
|
"""
|
|
253
|
+
import pandas as pd
|
|
254
|
+
|
|
250
255
|
catalog = self.get_current_catalog()
|
|
251
256
|
query = (
|
|
252
257
|
exp.select(
|
|
@@ -3,7 +3,6 @@ from __future__ import annotations
|
|
|
3
3
|
import logging
|
|
4
4
|
import typing as t
|
|
5
5
|
|
|
6
|
-
import pandas as pd
|
|
7
6
|
from sqlglot import exp
|
|
8
7
|
|
|
9
8
|
from sqlmesh.core.dialect import to_schema
|
|
@@ -27,6 +26,8 @@ from sqlmesh.core.schema_diff import SchemaDiffer
|
|
|
27
26
|
from sqlmesh.utils.errors import SQLMeshError
|
|
28
27
|
|
|
29
28
|
if t.TYPE_CHECKING:
|
|
29
|
+
import pandas as pd
|
|
30
|
+
|
|
30
31
|
from sqlmesh.core._typing import SchemaName, TableName
|
|
31
32
|
from sqlmesh.core.engine_adapter.base import QueryOrDF, Query
|
|
32
33
|
|
|
@@ -142,6 +143,8 @@ class RedshiftEngineAdapter(
|
|
|
142
143
|
self, query: t.Union[exp.Expression, str], quote_identifiers: bool = False
|
|
143
144
|
) -> pd.DataFrame:
|
|
144
145
|
"""Fetches a Pandas DataFrame from the cursor"""
|
|
146
|
+
import pandas as pd
|
|
147
|
+
|
|
145
148
|
self.execute(query, quote_identifiers=quote_identifiers)
|
|
146
149
|
|
|
147
150
|
# We manually build the `DataFrame` here because the driver's `fetch_dataframe`
|
|
@@ -257,6 +260,8 @@ class RedshiftEngineAdapter(
|
|
|
257
260
|
If it does exist then we need to do the:
|
|
258
261
|
`CREATE TABLE...`, `INSERT INTO...`, `RENAME TABLE...`, `RENAME TABLE...`, DROP TABLE...` dance.
|
|
259
262
|
"""
|
|
263
|
+
import pandas as pd
|
|
264
|
+
|
|
260
265
|
if not isinstance(query_or_df, pd.DataFrame) or not self.table_exists(table_name):
|
|
261
266
|
return super().replace_query(
|
|
262
267
|
table_name,
|
|
@@ -4,8 +4,6 @@ import contextlib
|
|
|
4
4
|
import logging
|
|
5
5
|
import typing as t
|
|
6
6
|
|
|
7
|
-
import pandas as pd
|
|
8
|
-
from pandas.api.types import is_datetime64_any_dtype # type: ignore
|
|
9
7
|
from sqlglot import exp
|
|
10
8
|
from sqlglot.helper import ensure_list
|
|
11
9
|
from sqlglot.optimizer.normalize_identifiers import normalize_identifiers
|
|
@@ -33,6 +31,8 @@ logger = logging.getLogger(__name__)
|
|
|
33
31
|
snowpark = optional_import("snowflake.snowpark")
|
|
34
32
|
|
|
35
33
|
if t.TYPE_CHECKING:
|
|
34
|
+
import pandas as pd
|
|
35
|
+
|
|
36
36
|
from sqlmesh.core._typing import SchemaName, SessionProperties, TableName
|
|
37
37
|
from sqlmesh.core.engine_adapter._typing import DF, Query, QueryOrDF, SnowparkSession
|
|
38
38
|
from sqlmesh.core.node import IntervalUnit
|
|
@@ -290,6 +290,9 @@ class SnowflakeEngineAdapter(GetCurrentCatalogFromFunctionMixin, ClusteredByMixi
|
|
|
290
290
|
batch_size: int,
|
|
291
291
|
target_table: TableName,
|
|
292
292
|
) -> t.List[SourceQuery]:
|
|
293
|
+
import pandas as pd
|
|
294
|
+
from pandas.api.types import is_datetime64_any_dtype
|
|
295
|
+
|
|
293
296
|
temp_table = self._get_temp_table(
|
|
294
297
|
target_table or "pandas", quoted=False
|
|
295
298
|
) # write_pandas() re-quotes everything without checking if its already quoted
|
|
@@ -391,6 +394,7 @@ class SnowflakeEngineAdapter(GetCurrentCatalogFromFunctionMixin, ClusteredByMixi
|
|
|
391
394
|
def _fetch_native_df(
|
|
392
395
|
self, query: t.Union[exp.Expression, str], quote_identifiers: bool = False
|
|
393
396
|
) -> DF:
|
|
397
|
+
import pandas as pd
|
|
394
398
|
from snowflake.connector.errors import NotSupportedError
|
|
395
399
|
|
|
396
400
|
self.execute(query, quote_identifiers=quote_identifiers)
|
|
@@ -4,7 +4,6 @@ import logging
|
|
|
4
4
|
import typing as t
|
|
5
5
|
from functools import partial
|
|
6
6
|
|
|
7
|
-
import pandas as pd
|
|
8
7
|
from sqlglot import exp
|
|
9
8
|
|
|
10
9
|
from sqlmesh.core.dialect import to_schema
|
|
@@ -28,6 +27,7 @@ from sqlmesh.utils import classproperty
|
|
|
28
27
|
from sqlmesh.utils.errors import SQLMeshError
|
|
29
28
|
|
|
30
29
|
if t.TYPE_CHECKING:
|
|
30
|
+
import pandas as pd
|
|
31
31
|
from pyspark.sql import types as spark_types
|
|
32
32
|
|
|
33
33
|
from sqlmesh.core._typing import SchemaName, TableName
|
|
@@ -232,6 +232,8 @@ class SparkEngineAdapter(
|
|
|
232
232
|
|
|
233
233
|
@classmethod
|
|
234
234
|
def try_get_pandas_df(cls, value: t.Any) -> t.Optional[pd.DataFrame]:
|
|
235
|
+
import pandas as pd
|
|
236
|
+
|
|
235
237
|
if isinstance(value, pd.DataFrame):
|
|
236
238
|
return value
|
|
237
239
|
return None
|
|
@@ -2,8 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
import re
|
|
3
3
|
import typing as t
|
|
4
4
|
from functools import lru_cache
|
|
5
|
-
|
|
6
|
-
from pandas.api.types import is_datetime64_any_dtype # type: ignore
|
|
5
|
+
|
|
7
6
|
from sqlglot import exp
|
|
8
7
|
from sqlglot.helper import seq_get
|
|
9
8
|
from tenacity import retry, wait_fixed, stop_after_attempt, retry_if_result
|
|
@@ -194,6 +193,9 @@ class TrinoEngineAdapter(
|
|
|
194
193
|
batch_size: int,
|
|
195
194
|
target_table: TableName,
|
|
196
195
|
) -> t.List[SourceQuery]:
|
|
196
|
+
import pandas as pd
|
|
197
|
+
from pandas.api.types import is_datetime64_any_dtype # type: ignore
|
|
198
|
+
|
|
197
199
|
assert isinstance(df, pd.DataFrame)
|
|
198
200
|
|
|
199
201
|
# Trino does not accept timestamps in ISOFORMAT that include the "T". `execution_time` is stored in
|
sqlmesh/core/model/definition.py
CHANGED
|
@@ -8,7 +8,6 @@ import typing as t
|
|
|
8
8
|
from functools import cached_property, partial
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
|
|
11
|
-
import pandas as pd
|
|
12
11
|
import numpy as np
|
|
13
12
|
from pydantic import Field
|
|
14
13
|
from sqlglot import diff, exp
|
|
@@ -1596,6 +1595,8 @@ class SeedModel(_Model):
|
|
|
1596
1595
|
|
|
1597
1596
|
# convert all date/time types to native pandas timestamp
|
|
1598
1597
|
for column in [*date_columns, *datetime_columns]:
|
|
1598
|
+
import pandas as pd
|
|
1599
|
+
|
|
1599
1600
|
df[column] = pd.to_datetime(df[column])
|
|
1600
1601
|
|
|
1601
1602
|
# extract datetime.date from pandas timestamp for DATE columns
|
sqlmesh/core/model/seed.py
CHANGED
|
@@ -6,7 +6,6 @@ import zlib
|
|
|
6
6
|
from io import StringIO
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
|
-
import pandas as pd
|
|
10
9
|
from sqlglot import exp
|
|
11
10
|
from sqlglot.dialects.dialect import UNESCAPED_SEQUENCES
|
|
12
11
|
from sqlglot.helper import seq_get
|
|
@@ -16,6 +15,9 @@ from sqlmesh.core.model.common import parse_bool
|
|
|
16
15
|
from sqlmesh.utils.pandas import columns_to_types_from_df
|
|
17
16
|
from sqlmesh.utils.pydantic import PydanticModel, field_validator
|
|
18
17
|
|
|
18
|
+
if t.TYPE_CHECKING:
|
|
19
|
+
import pandas as pd
|
|
20
|
+
|
|
19
21
|
logger = logging.getLogger(__name__)
|
|
20
22
|
|
|
21
23
|
NaHashables = t.List[t.Union[int, str, bool, t.Literal[None]]]
|
|
@@ -115,6 +117,8 @@ class CsvSeedReader:
|
|
|
115
117
|
batch_start += batch_size
|
|
116
118
|
|
|
117
119
|
def _get_df(self) -> pd.DataFrame:
|
|
120
|
+
import pandas as pd
|
|
121
|
+
|
|
118
122
|
if self._df is None:
|
|
119
123
|
self._df = pd.read_csv(
|
|
120
124
|
StringIO(self.content),
|
|
@@ -30,7 +30,6 @@ from collections import defaultdict
|
|
|
30
30
|
from contextlib import contextmanager
|
|
31
31
|
from functools import reduce
|
|
32
32
|
|
|
33
|
-
import pandas as pd
|
|
34
33
|
from sqlglot import exp, select
|
|
35
34
|
from sqlglot.executor import execute
|
|
36
35
|
|
|
@@ -736,6 +735,8 @@ class SnapshotEvaluator:
|
|
|
736
735
|
)
|
|
737
736
|
|
|
738
737
|
if limit is not None:
|
|
738
|
+
import pandas as pd
|
|
739
|
+
|
|
739
740
|
query_or_df = next(queries_or_dfs)
|
|
740
741
|
if isinstance(query_or_df, pd.DataFrame):
|
|
741
742
|
return query_or_df.head(limit)
|
|
@@ -769,6 +770,8 @@ class SnapshotEvaluator:
|
|
|
769
770
|
)
|
|
770
771
|
and snapshot.is_incremental_by_time_range
|
|
771
772
|
):
|
|
773
|
+
import pandas as pd
|
|
774
|
+
|
|
772
775
|
query_or_df = reduce(
|
|
773
776
|
lambda a, b: (
|
|
774
777
|
pd.concat([a, b], ignore_index=True) # type: ignore
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import typing as t
|
|
4
|
-
import pandas as pd
|
|
5
4
|
import json
|
|
6
5
|
import logging
|
|
7
6
|
from sqlglot import exp
|
|
@@ -17,6 +16,9 @@ from sqlmesh.utils.migration import index_text_type, blob_text_type
|
|
|
17
16
|
from sqlmesh.utils.date import now_timestamp, time_like_to_str
|
|
18
17
|
from sqlmesh.utils.errors import SQLMeshError
|
|
19
18
|
|
|
19
|
+
if t.TYPE_CHECKING:
|
|
20
|
+
import pandas as pd
|
|
21
|
+
|
|
20
22
|
|
|
21
23
|
logger = logging.getLogger(__name__)
|
|
22
24
|
|
|
@@ -330,6 +332,8 @@ class EnvironmentState:
|
|
|
330
332
|
|
|
331
333
|
|
|
332
334
|
def _environment_to_df(environment: Environment) -> pd.DataFrame:
|
|
335
|
+
import pandas as pd
|
|
336
|
+
|
|
333
337
|
return pd.DataFrame(
|
|
334
338
|
[
|
|
335
339
|
{
|
|
@@ -364,6 +368,8 @@ def _environment_to_df(environment: Environment) -> pd.DataFrame:
|
|
|
364
368
|
def _environment_statements_to_df(
|
|
365
369
|
environment_name: str, plan_id: str, environment_statements: t.List[EnvironmentStatements]
|
|
366
370
|
) -> pd.DataFrame:
|
|
371
|
+
import pandas as pd
|
|
372
|
+
|
|
367
373
|
return pd.DataFrame(
|
|
368
374
|
[
|
|
369
375
|
{
|
|
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing as t
|
|
4
4
|
import logging
|
|
5
|
-
import pandas as pd
|
|
6
5
|
|
|
7
6
|
from sqlglot import exp
|
|
8
7
|
|
|
@@ -27,6 +26,9 @@ from sqlmesh.utils.migration import index_text_type
|
|
|
27
26
|
from sqlmesh.utils import random_id
|
|
28
27
|
from sqlmesh.utils.date import now_timestamp
|
|
29
28
|
|
|
29
|
+
if t.TYPE_CHECKING:
|
|
30
|
+
import pandas as pd
|
|
31
|
+
|
|
30
32
|
|
|
31
33
|
logger = logging.getLogger(__name__)
|
|
32
34
|
|
|
@@ -205,6 +207,8 @@ class IntervalState:
|
|
|
205
207
|
snapshots: t.Iterable[t.Union[Snapshot, SnapshotIntervals]],
|
|
206
208
|
is_compacted: bool = False,
|
|
207
209
|
) -> None:
|
|
210
|
+
import pandas as pd
|
|
211
|
+
|
|
208
212
|
new_intervals = []
|
|
209
213
|
for snapshot in snapshots:
|
|
210
214
|
logger.info("Pushing intervals for snapshot %s", snapshot.snapshot_id)
|
|
@@ -430,6 +434,8 @@ def _intervals_to_df(
|
|
|
430
434
|
is_dev: bool,
|
|
431
435
|
is_removed: bool,
|
|
432
436
|
) -> pd.DataFrame:
|
|
437
|
+
import pandas as pd
|
|
438
|
+
|
|
433
439
|
return pd.DataFrame(
|
|
434
440
|
[
|
|
435
441
|
_interval_to_df(
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import typing as t
|
|
4
|
-
import pandas as pd
|
|
5
4
|
import json
|
|
6
5
|
import logging
|
|
7
6
|
from pathlib import Path
|
|
@@ -39,6 +38,8 @@ from sqlmesh.utils.pydantic import PydanticModel
|
|
|
39
38
|
from sqlmesh.utils import unique
|
|
40
39
|
|
|
41
40
|
if t.TYPE_CHECKING:
|
|
41
|
+
import pandas as pd
|
|
42
|
+
|
|
42
43
|
from sqlmesh.core.state_sync.db.interval import IntervalState
|
|
43
44
|
|
|
44
45
|
|
|
@@ -674,6 +675,8 @@ def _snapshot_to_json(snapshot: Snapshot) -> str:
|
|
|
674
675
|
|
|
675
676
|
|
|
676
677
|
def _snapshots_to_df(snapshots: t.Iterable[Snapshot]) -> pd.DataFrame:
|
|
678
|
+
import pandas as pd
|
|
679
|
+
|
|
677
680
|
return pd.DataFrame(
|
|
678
681
|
[
|
|
679
682
|
{
|
|
@@ -693,6 +696,8 @@ def _snapshots_to_df(snapshots: t.Iterable[Snapshot]) -> pd.DataFrame:
|
|
|
693
696
|
|
|
694
697
|
|
|
695
698
|
def _auto_restatements_to_df(auto_restatements: t.Dict[SnapshotNameVersion, int]) -> pd.DataFrame:
|
|
699
|
+
import pandas as pd
|
|
700
|
+
|
|
696
701
|
return pd.DataFrame(
|
|
697
702
|
[
|
|
698
703
|
{
|
|
@@ -3,7 +3,6 @@ from __future__ import annotations
|
|
|
3
3
|
import logging
|
|
4
4
|
import typing as t
|
|
5
5
|
|
|
6
|
-
import pandas as pd
|
|
7
6
|
from sqlglot import __version__ as SQLGLOT_VERSION
|
|
8
7
|
from sqlglot import exp
|
|
9
8
|
from sqlglot.helper import seq_get
|
|
@@ -40,6 +39,8 @@ class VersionState:
|
|
|
40
39
|
sqlglot_version: str = SQLGLOT_VERSION,
|
|
41
40
|
sqlmesh_version: str = SQLMESH_VERSION,
|
|
42
41
|
) -> None:
|
|
42
|
+
import pandas as pd
|
|
43
|
+
|
|
43
44
|
self.engine_adapter.delete_from(self.versions_table, "TRUE")
|
|
44
45
|
|
|
45
46
|
self.engine_adapter.insert_append(
|
sqlmesh/core/table_diff.py
CHANGED
|
@@ -4,8 +4,6 @@ import math
|
|
|
4
4
|
import typing as t
|
|
5
5
|
from functools import cached_property
|
|
6
6
|
|
|
7
|
-
import pandas as pd
|
|
8
|
-
|
|
9
7
|
from sqlmesh.core.dialect import to_schema
|
|
10
8
|
from sqlmesh.core.engine_adapter.mixins import RowDiffMixin
|
|
11
9
|
from sqlmesh.core.engine_adapter.athena import AthenaEngineAdapter
|
|
@@ -18,7 +16,10 @@ from sqlglot.optimizer.scope import find_all_in_scope
|
|
|
18
16
|
from sqlmesh.utils.pydantic import PydanticModel
|
|
19
17
|
from sqlmesh.utils.errors import SQLMeshError
|
|
20
18
|
|
|
19
|
+
|
|
21
20
|
if t.TYPE_CHECKING:
|
|
21
|
+
import pandas as pd
|
|
22
|
+
|
|
22
23
|
from sqlmesh.core._typing import TableName
|
|
23
24
|
from sqlmesh.core.engine_adapter import EngineAdapter
|
|
24
25
|
|
|
@@ -75,6 +76,21 @@ class RowDiff(PydanticModel, frozen=True):
|
|
|
75
76
|
model_name: t.Optional[str] = None
|
|
76
77
|
decimals: int = 3
|
|
77
78
|
|
|
79
|
+
_types_resolved: t.ClassVar[bool] = False
|
|
80
|
+
|
|
81
|
+
def __new__(cls, *args: t.Any, **kwargs: t.Any) -> RowDiff:
|
|
82
|
+
if not cls._types_resolved:
|
|
83
|
+
cls._resolve_types()
|
|
84
|
+
return super().__new__(cls)
|
|
85
|
+
|
|
86
|
+
@classmethod
|
|
87
|
+
def _resolve_types(cls) -> None:
|
|
88
|
+
# Pandas is imported by type checking so we need to resolve the types with the real import before instantiating
|
|
89
|
+
import pandas as pd # noqa
|
|
90
|
+
|
|
91
|
+
cls.model_rebuild()
|
|
92
|
+
cls._types_resolved = True
|
|
93
|
+
|
|
78
94
|
@property
|
|
79
95
|
def source_count(self) -> int:
|
|
80
96
|
"""Count of the source."""
|