query-cache-common 2.12.0__tar.gz → 2.14.0__tar.gz
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.
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/PKG-INFO +1 -1
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/utils.py +64 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/.gitignore +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/pyproject.toml +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/__init__.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/auth.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/constants.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/decorators.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/__init__.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/_typing.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/base.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/converters.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/fields.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/__init__.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/client_telemetry_service_models.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/client_validation_service_models.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/clone_service_models.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/execution_service_models.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/explain_service_models.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/selector_service_models.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/sql_analysis_service_models.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/services/sql_service_models.py +0 -0
- {query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/shared_models.py +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import datetime
|
|
4
|
+
import re
|
|
4
5
|
import time
|
|
5
6
|
import typing as t
|
|
6
7
|
|
|
@@ -16,6 +17,9 @@ if t.TYPE_CHECKING:
|
|
|
16
17
|
from sqlglot.expressions import (
|
|
17
18
|
Expression as SqlglotExpression,
|
|
18
19
|
)
|
|
20
|
+
from sqlglot.expressions import (
|
|
21
|
+
Table as SqlglotTable,
|
|
22
|
+
)
|
|
19
23
|
|
|
20
24
|
|
|
21
25
|
def str_to_bool(s: str | None) -> bool:
|
|
@@ -172,6 +176,66 @@ def extract_fqn_parts(fqn: str, dialect: str) -> t.Tuple[str, str, str]:
|
|
|
172
176
|
return catalog.sql(dialect=dialect), schema.sql(dialect=dialect), name.sql(dialect=dialect)
|
|
173
177
|
|
|
174
178
|
|
|
179
|
+
def normalize_stage_reference(
|
|
180
|
+
table: SqlglotTable, dialect: str, default_catalog: str, default_schema: t.Optional[str]
|
|
181
|
+
) -> t.Optional[SqlglotTable]:
|
|
182
|
+
"""Normalize a Snowflake named stage reference into the form used as its dependency name.
|
|
183
|
+
|
|
184
|
+
sqlglot parses `@db.schema.stage/path (PATTERN => '...')` as a table whose name is the raw
|
|
185
|
+
stage text. The stage name is qualified with the defaults and normalized like a table name.
|
|
186
|
+
The path (case-sensitive) and pattern are kept since they scope the files read; other options
|
|
187
|
+
are dropped. Rendering the result with `.sql(dialect=...)` gives the dependency name, and
|
|
188
|
+
normalizing that again returns the same name. The location is single quoted only when the
|
|
189
|
+
path needs it, e.g. `'@"DB"."SCH"."STG"/my folder/'`.
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
The normalized stage reference, or None if `table` is not a named stage reference,
|
|
193
|
+
e.g. a table, a user stage (`@~`) or a table stage (`@%t`).
|
|
194
|
+
"""
|
|
195
|
+
from sqlglot import exp
|
|
196
|
+
from sqlglot.errors import ParseError
|
|
197
|
+
from sqlglot.optimizer.normalize_identifiers import normalize_identifiers
|
|
198
|
+
from sqlglot.optimizer.qualify_columns import quote_identifiers
|
|
199
|
+
|
|
200
|
+
if not isinstance(table.this, (exp.Var, exp.Literal)) or not table.this.name.startswith("@"):
|
|
201
|
+
return None
|
|
202
|
+
location = table.this.name[1:]
|
|
203
|
+
if location.startswith(("~", "%")):
|
|
204
|
+
return None
|
|
205
|
+
|
|
206
|
+
# The stage name ends at the first "/" outside double quotes
|
|
207
|
+
in_quotes = False
|
|
208
|
+
name_end = len(location)
|
|
209
|
+
for i, char in enumerate(location):
|
|
210
|
+
if char == '"':
|
|
211
|
+
in_quotes = not in_quotes
|
|
212
|
+
elif char == "/" and not in_quotes:
|
|
213
|
+
name_end = i
|
|
214
|
+
break
|
|
215
|
+
name, path = location[:name_end], location[name_end:]
|
|
216
|
+
|
|
217
|
+
try:
|
|
218
|
+
stage = exp.to_table(name, dialect=dialect)
|
|
219
|
+
except ParseError:
|
|
220
|
+
return None
|
|
221
|
+
if not stage.name:
|
|
222
|
+
return None
|
|
223
|
+
if not stage.db and default_schema:
|
|
224
|
+
stage.set("db", exp.parse_identifier(default_schema, dialect=dialect))
|
|
225
|
+
if stage.db and not stage.catalog:
|
|
226
|
+
stage.set("catalog", exp.parse_identifier(default_catalog, dialect=dialect))
|
|
227
|
+
stage = quote_identifiers(normalize_identifiers(stage, dialect=dialect), dialect=dialect)
|
|
228
|
+
|
|
229
|
+
location = f"@{stage.sql(dialect=dialect)}{path}"
|
|
230
|
+
# An unquoted location can't contain these, see Snowflake's _parse_location_path in sqlglot
|
|
231
|
+
needs_quotes = re.search(r"[\s,()']|--|/\*", path)
|
|
232
|
+
pattern = table.args.get("pattern")
|
|
233
|
+
return exp.Table(
|
|
234
|
+
this=exp.Literal.string(location) if needs_quotes else exp.Var(this=location),
|
|
235
|
+
pattern=pattern.copy() if pattern else None,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
|
|
175
239
|
def format_as_localtime(dt: datetime.datetime) -> str:
|
|
176
240
|
local_dt = dt.astimezone() # convert to localtime
|
|
177
241
|
return local_dt.strftime("%Y-%m-%d %H:%M:%S %Z")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/decorators.py
RENAMED
|
File without changes
|
{query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/__init__.py
RENAMED
|
File without changes
|
{query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/_typing.py
RENAMED
|
File without changes
|
{query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/base.py
RENAMED
|
File without changes
|
{query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/converters.py
RENAMED
|
File without changes
|
{query_cache_common-2.12.0 → query_cache_common-2.14.0}/src/query_cache_common/models/fields.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|