query-cache-common 2.11.0__tar.gz → 2.12.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.
Files changed (23) hide show
  1. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/PKG-INFO +1 -1
  2. query_cache_common-2.12.0/src/query_cache_common/models/services/sql_analysis_service_models.py +32 -0
  3. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/utils.py +30 -0
  4. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/.gitignore +0 -0
  5. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/pyproject.toml +0 -0
  6. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/__init__.py +0 -0
  7. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/auth.py +0 -0
  8. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/constants.py +0 -0
  9. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/decorators.py +0 -0
  10. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/__init__.py +0 -0
  11. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/_typing.py +0 -0
  12. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/base.py +0 -0
  13. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/converters.py +0 -0
  14. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/fields.py +0 -0
  15. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/services/__init__.py +0 -0
  16. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/services/client_telemetry_service_models.py +0 -0
  17. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/services/client_validation_service_models.py +0 -0
  18. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/services/clone_service_models.py +0 -0
  19. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/services/execution_service_models.py +0 -0
  20. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/services/explain_service_models.py +0 -0
  21. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/services/selector_service_models.py +0 -0
  22. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/services/sql_service_models.py +0 -0
  23. {query_cache_common-2.11.0 → query_cache_common-2.12.0}/src/query_cache_common/models/shared_models.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: query-cache-common
3
- Version: 2.11.0
3
+ Version: 2.12.0
4
4
  Summary: Common code for Query Cache shared across client and server
5
5
  License:
6
6
  Apache License
@@ -0,0 +1,32 @@
1
+ from __future__ import annotations
2
+
3
+ import typing as t
4
+ from dataclasses import field
5
+
6
+ from query_cache_protobuf.query_cache.services import sql_analysis_service_pb2
7
+
8
+ from query_cache_common.decorators import proto_dataclass
9
+ from query_cache_common.models.base import BaseSerDeModel
10
+
11
+
12
+ @proto_dataclass(sql_analysis_service_pb2.ExtractTableReferencesRequest)
13
+ class ExtractTableReferencesRequest(BaseSerDeModel):
14
+ dialect: str
15
+ sqls: t.List[str] = field(default_factory=list)
16
+
17
+
18
+ @proto_dataclass(sql_analysis_service_pb2.TableReference)
19
+ class TableReference(BaseSerDeModel):
20
+ parts: t.List[str] = field(default_factory=list)
21
+ fqn: str = ""
22
+
23
+
24
+ @proto_dataclass(sql_analysis_service_pb2.SqlTableReferences)
25
+ class SqlTableReferences(BaseSerDeModel):
26
+ parsed: bool
27
+ references: t.List[TableReference] = field(default_factory=list)
28
+
29
+
30
+ @proto_dataclass(sql_analysis_service_pb2.ExtractTableReferencesResponse)
31
+ class ExtractTableReferencesResponse(BaseSerDeModel):
32
+ results: t.List[SqlTableReferences] = field(default_factory=list)
@@ -10,6 +10,9 @@ if t.TYPE_CHECKING:
10
10
  from sqlglot.expressions import (
11
11
  Create as CreateStatement,
12
12
  )
13
+ from sqlglot.expressions import (
14
+ Expr as SqlglotExpr,
15
+ )
13
16
  from sqlglot.expressions import (
14
17
  Expression as SqlglotExpression,
15
18
  )
@@ -94,6 +97,33 @@ def unwrap_subquery(query: SqlglotExpression) -> SqlglotExpression:
94
97
  return query
95
98
 
96
99
 
100
+ def is_udtf_argument_query(query: SqlglotExpr) -> bool:
101
+ """True for a query passed directly to a UDTF other than UNNEST / LATERAL, e.g. EXPLODE((SELECT ...)).
102
+
103
+ sqlglot's scope builder treats these as scope boundaries but only traverses the arguments of
104
+ UNNEST and LATERAL, so their tables are invisible to `traverse_scope` and `qualify`.
105
+ """
106
+ from sqlglot import exp
107
+
108
+ return isinstance(query.parent, exp.UDTF) and not isinstance(
109
+ query.parent, (exp.Unnest, exp.Lateral)
110
+ )
111
+
112
+
113
+ def expose_udtf_argument_subqueries(expression: SqlglotExpr) -> None:
114
+ """Wrap every `is_udtf_argument_query` query in parentheses, in place, so sqlglot scopes it
115
+ like any other subquery."""
116
+ from sqlglot import exp
117
+
118
+ for query in list(expression.find_all(exp.Query)):
119
+ if is_udtf_argument_query(query):
120
+ # Re-parent the original node rather than a copy, so nested matches still found by this loop stay in
121
+ # the tree
122
+ paren = exp.Paren()
123
+ query.replace(paren)
124
+ paren.set("this", query)
125
+
126
+
97
127
  def extract_fqn_parts(fqn: str, dialect: str) -> t.Tuple[str, str, str]:
98
128
  """
99
129
  Given a fully-qualified table name string, eg: