sqlscope-rs 0.4.1__tar.gz → 0.6.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.
- {sqlscope_rs-0.4.1 → sqlscope_rs-0.6.0}/PKG-INFO +1 -1
- {sqlscope_rs-0.4.1 → sqlscope_rs-0.6.0}/src/sqlscope/__init__.py +11 -5
- {sqlscope_rs-0.4.1 → sqlscope_rs-0.6.0}/tests/test_sqlscope.py +15 -0
- {sqlscope_rs-0.4.1 → sqlscope_rs-0.6.0}/.gitignore +0 -0
- {sqlscope_rs-0.4.1 → sqlscope_rs-0.6.0}/README.md +0 -0
- {sqlscope_rs-0.4.1 → sqlscope_rs-0.6.0}/pyproject.toml +0 -0
- {sqlscope_rs-0.4.1 → sqlscope_rs-0.6.0}/src/sqlscope/_library.py +0 -0
- {sqlscope_rs-0.4.1 → sqlscope_rs-0.6.0}/src/sqlscope/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sqlscope-rs
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Scope-aware SQL analysis and rewriting: row filters, CTE injection, table rewrites, column lineage.
|
|
5
5
|
Project-URL: Repository, https://github.com/dcalsky/sqlscope
|
|
6
6
|
License-Expression: MIT
|
|
@@ -5,7 +5,7 @@ Function Purpose
|
|
|
5
5
|
===================== ==========================================================
|
|
6
6
|
apply_row_filter Filter every in-scope table by a predicate.
|
|
7
7
|
inject_ctes Prepend CTE definitions to a query's root ``WITH``.
|
|
8
|
-
rewrite_tables Replace table references with derived tables.
|
|
8
|
+
rewrite_tables Replace table references with other tables or derived tables.
|
|
9
9
|
column_origins Source columns whose values reach the result (lineage).
|
|
10
10
|
output_columns Names of the columns a statement outputs.
|
|
11
11
|
referenced_columns Columns referenced anywhere, per table.
|
|
@@ -41,7 +41,7 @@ from ._library import (
|
|
|
41
41
|
load,
|
|
42
42
|
)
|
|
43
43
|
|
|
44
|
-
__version__ = "0.
|
|
44
|
+
__version__ = "0.6.0"
|
|
45
45
|
|
|
46
46
|
__all__ = [
|
|
47
47
|
"Clause",
|
|
@@ -107,12 +107,15 @@ class UnionRewrite:
|
|
|
107
107
|
class TableRewrite:
|
|
108
108
|
"""Replaces references to ``match_key`` (``schema.table``).
|
|
109
109
|
|
|
110
|
-
Set exactly one of ``inline
|
|
110
|
+
Set exactly one of ``inline``, ``union``, or ``rename``. Optional ``columns``
|
|
111
|
+
selects identifier values from the inline target (empty selects all).
|
|
111
112
|
"""
|
|
112
113
|
|
|
113
114
|
match_key: str
|
|
114
115
|
inline: Optional[TableRef] = None
|
|
115
116
|
union: Optional[UnionRewrite] = None
|
|
117
|
+
columns: Optional[Sequence[str]] = None
|
|
118
|
+
rename: Optional[TableRef] = None
|
|
116
119
|
|
|
117
120
|
|
|
118
121
|
class Clause(str, Enum):
|
|
@@ -190,7 +193,8 @@ def apply_row_filter(
|
|
|
190
193
|
By default every physical table is filtered; ``table_names`` (bare,
|
|
191
194
|
``schema.table`` or ``catalog.schema.table``), ``table_patterns`` (regular
|
|
192
195
|
expressions) and ``default_db`` restrict the scope. CTE references, table
|
|
193
|
-
functions and ``DUAL``
|
|
196
|
+
functions and the ``DUAL`` dummy table (Oracle, the MySQL family,
|
|
197
|
+
Snowflake) are never wrapped. ``predicate`` is parsed as one
|
|
194
198
|
boolean expression; bind or escape its values before calling. Returns the
|
|
195
199
|
input unchanged when no table is in scope.
|
|
196
200
|
"""
|
|
@@ -238,7 +242,7 @@ def rewrite_tables(
|
|
|
238
242
|
) -> str:
|
|
239
243
|
"""Replace physical table references according to ``rewrites``.
|
|
240
244
|
|
|
241
|
-
Matched references
|
|
245
|
+
Matched references keep their alias (or bare
|
|
242
246
|
name); qualified column references are rebound onto it. Catalogs listed in
|
|
243
247
|
``strip_catalogs`` are transparent while matching. Returns the input
|
|
244
248
|
unchanged when nothing matches.
|
|
@@ -247,6 +251,8 @@ def rewrite_tables(
|
|
|
247
251
|
{
|
|
248
252
|
"matchKey": rewrite.match_key,
|
|
249
253
|
"inline": _table(rewrite.inline) if rewrite.inline is not None else None,
|
|
254
|
+
**({"columns": list(rewrite.columns)} if rewrite.columns else {}),
|
|
255
|
+
**({"rename": _table(rewrite.rename)} if rewrite.rename is not None else {}),
|
|
250
256
|
"union": {
|
|
251
257
|
"tableAlias": rewrite.union.table_alias,
|
|
252
258
|
"columns": list(rewrite.union.columns),
|
|
@@ -40,6 +40,21 @@ def test_rewrite_tables():
|
|
|
40
40
|
)
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
def test_project_from_injected_cte():
|
|
44
|
+
query = sqlscope.rewrite_tables("SELECT t.a FROM s.t", [
|
|
45
|
+
TableRewrite("s.t", inline=TableRef("permitted"), columns=["a", "end"])
|
|
46
|
+
])
|
|
47
|
+
query = sqlscope.inject_ctes(query, [CteDef("permitted", "SELECT * FROM src.t")])
|
|
48
|
+
assert query == 'WITH permitted AS (SELECT * FROM src.t) SELECT t.a FROM (SELECT a, "end" FROM permitted) AS t'
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_rename_table_argument():
|
|
52
|
+
query = sqlscope.rewrite_tables("SELECT * FROM ML.PREDICT(MODEL s.t, TABLE s.t)", [
|
|
53
|
+
TableRewrite("s.t", rename=TableRef("u", "v"))
|
|
54
|
+
], dialect="bigquery")
|
|
55
|
+
assert query == "SELECT * FROM ML.PREDICT(MODEL s.t, TABLE v.u)"
|
|
56
|
+
|
|
57
|
+
|
|
43
58
|
def test_rewrite_tables_requires_one_target():
|
|
44
59
|
with pytest.raises(sqlscope.InvalidArgumentError):
|
|
45
60
|
sqlscope.rewrite_tables("SELECT 1", [TableRewrite("s.t")])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|