sqlscope 1.0.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 (57) hide show
  1. sqlscope-1.0.0/.gitignore +186 -0
  2. sqlscope-1.0.0/.readthedocs.yaml +35 -0
  3. sqlscope-1.0.0/LICENSE +21 -0
  4. sqlscope-1.0.0/Makefile +53 -0
  5. sqlscope-1.0.0/PKG-INFO +52 -0
  6. sqlscope-1.0.0/README.md +31 -0
  7. sqlscope-1.0.0/datasets/catalogs/constraints.json +343 -0
  8. sqlscope-1.0.0/datasets/catalogs/miedema.json +392 -0
  9. sqlscope-1.0.0/datasets/sql/constraints.sql +38 -0
  10. sqlscope-1.0.0/datasets/sql/miedema.sql +85 -0
  11. sqlscope-1.0.0/docs/Makefile +20 -0
  12. sqlscope-1.0.0/docs/conf.py +40 -0
  13. sqlscope-1.0.0/docs/index.rst +40 -0
  14. sqlscope-1.0.0/docs/make.bat +35 -0
  15. sqlscope-1.0.0/docs/requirements.txt +1 -0
  16. sqlscope-1.0.0/pyproject.toml +31 -0
  17. sqlscope-1.0.0/requirements.txt +16 -0
  18. sqlscope-1.0.0/src/sqlscope/__init__.py +4 -0
  19. sqlscope-1.0.0/src/sqlscope/catalog/__init__.py +12 -0
  20. sqlscope-1.0.0/src/sqlscope/catalog/builder/__init__.py +8 -0
  21. sqlscope-1.0.0/src/sqlscope/catalog/builder/postgres.py +207 -0
  22. sqlscope-1.0.0/src/sqlscope/catalog/builder/sql.py +219 -0
  23. sqlscope-1.0.0/src/sqlscope/catalog/catalog.py +147 -0
  24. sqlscope-1.0.0/src/sqlscope/catalog/column.py +68 -0
  25. sqlscope-1.0.0/src/sqlscope/catalog/constraint.py +83 -0
  26. sqlscope-1.0.0/src/sqlscope/catalog/schema.py +60 -0
  27. sqlscope-1.0.0/src/sqlscope/catalog/table.py +112 -0
  28. sqlscope-1.0.0/src/sqlscope/query/__init__.py +5 -0
  29. sqlscope-1.0.0/src/sqlscope/query/extractors.py +118 -0
  30. sqlscope-1.0.0/src/sqlscope/query/query.py +191 -0
  31. sqlscope-1.0.0/src/sqlscope/query/set_operations/__init__.py +181 -0
  32. sqlscope-1.0.0/src/sqlscope/query/set_operations/binary_set_operation.py +162 -0
  33. sqlscope-1.0.0/src/sqlscope/query/set_operations/select.py +664 -0
  34. sqlscope-1.0.0/src/sqlscope/query/set_operations/set_operation.py +59 -0
  35. sqlscope-1.0.0/src/sqlscope/query/smt.py +334 -0
  36. sqlscope-1.0.0/src/sqlscope/query/tokenized_sql.py +70 -0
  37. sqlscope-1.0.0/src/sqlscope/query/typechecking/__init__.py +21 -0
  38. sqlscope-1.0.0/src/sqlscope/query/typechecking/base.py +9 -0
  39. sqlscope-1.0.0/src/sqlscope/query/typechecking/binary_ops.py +57 -0
  40. sqlscope-1.0.0/src/sqlscope/query/typechecking/functions.py +81 -0
  41. sqlscope-1.0.0/src/sqlscope/query/typechecking/predicates.py +123 -0
  42. sqlscope-1.0.0/src/sqlscope/query/typechecking/primitives.py +80 -0
  43. sqlscope-1.0.0/src/sqlscope/query/typechecking/queries.py +35 -0
  44. sqlscope-1.0.0/src/sqlscope/query/typechecking/types.py +59 -0
  45. sqlscope-1.0.0/src/sqlscope/query/typechecking/unary_ops.py +51 -0
  46. sqlscope-1.0.0/src/sqlscope/query/typechecking/util.py +51 -0
  47. sqlscope-1.0.0/src/sqlscope/util/__init__.py +18 -0
  48. sqlscope-1.0.0/src/sqlscope/util/ast/__init__.py +55 -0
  49. sqlscope-1.0.0/src/sqlscope/util/ast/column.py +55 -0
  50. sqlscope-1.0.0/src/sqlscope/util/ast/function.py +10 -0
  51. sqlscope-1.0.0/src/sqlscope/util/ast/subquery.py +23 -0
  52. sqlscope-1.0.0/src/sqlscope/util/ast/table.py +36 -0
  53. sqlscope-1.0.0/src/sqlscope/util/sql.py +27 -0
  54. sqlscope-1.0.0/src/sqlscope/util/tokens.py +17 -0
  55. sqlscope-1.0.0/tests/test_extractors.py +42 -0
  56. sqlscope-1.0.0/tests/test_query.py +307 -0
  57. sqlscope-1.0.0/tests/test_typechecking.py +109 -0
@@ -0,0 +1,186 @@
1
+ # CUSTOM
2
+ test_q.sql
3
+ test_s?.sql
4
+
5
+
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ .pybuilder/
81
+ target/
82
+
83
+ # Jupyter Notebook
84
+ .ipynb_checkpoints
85
+
86
+ # IPython
87
+ profile_default/
88
+ ipython_config.py
89
+
90
+ # pyenv
91
+ # For a library or package, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ # .python-version
94
+
95
+ # pipenv
96
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
98
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
99
+ # install all needed dependencies.
100
+ #Pipfile.lock
101
+
102
+ # UV
103
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ #uv.lock
107
+
108
+ # poetry
109
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
110
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
111
+ # commonly ignored for libraries.
112
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
113
+ #poetry.lock
114
+
115
+ # pdm
116
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
117
+ #pdm.lock
118
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
119
+ # in version control.
120
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
121
+ .pdm.toml
122
+ .pdm-python
123
+ .pdm-build/
124
+
125
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
126
+ __pypackages__/
127
+
128
+ # Celery stuff
129
+ celerybeat-schedule
130
+ celerybeat.pid
131
+
132
+ # SageMath parsed files
133
+ *.sage.py
134
+
135
+ # Environments
136
+ .env
137
+ .venv
138
+ env/
139
+ venv/
140
+ ENV/
141
+ env.bak/
142
+ venv.bak/
143
+
144
+ # Spyder project settings
145
+ .spyderproject
146
+ .spyproject
147
+
148
+ # Rope project settings
149
+ .ropeproject
150
+
151
+ # mkdocs documentation
152
+ /site
153
+
154
+ # mypy
155
+ .mypy_cache/
156
+ .dmypy.json
157
+ dmypy.json
158
+
159
+ # Pyre type checker
160
+ .pyre/
161
+
162
+ # pytype static type analyzer
163
+ .pytype/
164
+
165
+ # Cython debug symbols
166
+ cython_debug/
167
+
168
+ # PyCharm
169
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
170
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
171
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
172
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
173
+ #.idea/
174
+
175
+ # Ruff stuff:
176
+ .ruff_cache/
177
+
178
+ # PyPI configuration file
179
+ .pypirc
180
+
181
+ <<<<<<< Updated upstream
182
+ # VS Code
183
+ .vscode/
184
+ =======
185
+ .vscode
186
+ >>>>>>> Stashed changes
@@ -0,0 +1,35 @@
1
+ # Read the Docs configuration file for Sphinx projects
2
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
+
4
+ # Required
5
+ version: 2
6
+
7
+ # Set the OS, Python version and other tools you might need
8
+ build:
9
+ os: ubuntu-22.04
10
+ tools:
11
+ python: "3.11"
12
+ # You can also specify other tool versions:
13
+ # nodejs: "20"
14
+ # rust: "1.70"
15
+ # golang: "1.20"
16
+
17
+ # Build documentation in the "docs/" directory with Sphinx
18
+ sphinx:
19
+ configuration: docs/conf.py
20
+ # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
21
+ # builder: "dirhtml"
22
+ # Fail on all warnings to avoid broken references
23
+ # fail_on_warning: true
24
+
25
+ # Optionally build your docs in additional formats such as PDF and ePub
26
+ # formats:
27
+ # - pdf
28
+ # - epub
29
+
30
+ # Optional but recommended, declare the Python requirements required
31
+ # to build your documentation
32
+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
33
+ python:
34
+ install:
35
+ - requirements: docs/requirements.txt
sqlscope-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [Davide Ponzini, Davide Miggiano]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,53 @@
1
+ ########## Makefile start ##########
2
+ # Type: PyPi
3
+ # Author: Davide Ponzini
4
+
5
+ NAME=sqlscope
6
+ VENV=./venv
7
+ REQUIREMENTS=requirements.txt
8
+
9
+ ifeq ($(OS),Windows_NT)
10
+ VENV_BIN=$(VENV)/Scripts
11
+ else
12
+ VENV_BIN=$(VENV)/bin
13
+ endif
14
+
15
+ .PHONY: install build uninstall documentation test upload download clean coverage
16
+
17
+ $(VENV):
18
+ python -m venv --clear $(VENV)
19
+ touch -a $(REQUIREMENTS)
20
+ $(VENV_BIN)/python -m pip install --upgrade -r $(REQUIREMENTS)
21
+
22
+ $(VENV)_upgrade: $(VENV)
23
+ $(VENV_BIN)/python -m pip install --upgrade -r $(REQUIREMENTS)
24
+
25
+
26
+ install: uninstall build
27
+ $(VENV_BIN)/python -m pip install ./dist/*.whl
28
+
29
+ build: $(VENV)
30
+ rm -rf dist/
31
+ $(VENV_BIN)/python -m build
32
+
33
+ uninstall: $(VENV)
34
+ $(VENV_BIN)/python -m pip uninstall -y $(NAME)
35
+
36
+ documentation:
37
+ make html SPHINXBUILD="../$(VENV_BIN)/sphinx-build" -C docs/
38
+
39
+ test: install
40
+ $(VENV_BIN)/python -m pytest
41
+
42
+ upload: test documentation
43
+ $(VENV_BIN)/python -m pip install --upgrade twine
44
+ $(VENV_BIN)/python -m twine upload --verbose dist/*
45
+
46
+ download: uninstall
47
+ $(VENV_BIN)/python -m pip install $(NAME)
48
+
49
+ clean:
50
+ find . -type d -name '__pycache__' -print0 | xargs -0 rm -r || true
51
+ rm -rf dist docs/_build .pytest_cache .coverage tests/htmlcov
52
+
53
+ ########## Makefile end ##########
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: sqlscope
3
+ Version: 1.0.0
4
+ Summary: This project extracts catalog and query metadata from a SQL query.
5
+ Project-URL: Repository, https://github.com/DavidePonzini/sqlscope
6
+ Project-URL: Documentation, https://sqlscope.readthedocs.io/en/latest/index.html
7
+ Project-URL: Bug Tracker, https://github.com/DavidePonzini/sqlscope/issues
8
+ Author-email: Davide Ponzini <davide.ponzini95@gmail.com>
9
+ License-File: LICENSE
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.11
14
+ Requires-Dist: psycopg2
15
+ Requires-Dist: python-dateutil
16
+ Requires-Dist: pyyaml
17
+ Requires-Dist: sqlglot
18
+ Requires-Dist: sqlparse
19
+ Requires-Dist: z3-solver
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Introduction
23
+ This project extracts catalog and query metadata from a SQL query.
24
+ Each SELECT statement is parsed as a list of tokens as well as an AST.
25
+ The former works even for incomplete or invalid SQL queries, while the latter
26
+ requires a valid SQL syntax.
27
+ Additionally, catalog metadata is extracted from the database schema.
28
+
29
+ # Details
30
+ For each SELECT statement, the package extracts:
31
+ - the list of SELECT queries (in case of set operations, nested queries, or ctes)
32
+ - the main SELECT query
33
+ - the list of schemas/tables/columns available in the catalog
34
+ - the list of tables referenced in each query
35
+ - the resulting table from each query execution, including its columns and their types
36
+ - each clause of each query
37
+
38
+ The catalog extract schema/table/column metadata.
39
+ For each column, the following information are extracted:
40
+ - name
41
+ - data type
42
+ - nullability
43
+ - foreign key
44
+
45
+ Additionally, for each table, PRIMARY KEY/UNIQUE constraints are extracted. This is also computed for the result of each SELECT query.
46
+
47
+
48
+ # Credits
49
+ Special thanks to Flavio Venturini for his valuable contributions to the development of this project.
50
+
51
+ # Limitations
52
+ - Fully identified schema names are not supported when specifying column names (e.g. `SELECT schema.table.column [...]`)
@@ -0,0 +1,31 @@
1
+ # Introduction
2
+ This project extracts catalog and query metadata from a SQL query.
3
+ Each SELECT statement is parsed as a list of tokens as well as an AST.
4
+ The former works even for incomplete or invalid SQL queries, while the latter
5
+ requires a valid SQL syntax.
6
+ Additionally, catalog metadata is extracted from the database schema.
7
+
8
+ # Details
9
+ For each SELECT statement, the package extracts:
10
+ - the list of SELECT queries (in case of set operations, nested queries, or ctes)
11
+ - the main SELECT query
12
+ - the list of schemas/tables/columns available in the catalog
13
+ - the list of tables referenced in each query
14
+ - the resulting table from each query execution, including its columns and their types
15
+ - each clause of each query
16
+
17
+ The catalog extract schema/table/column metadata.
18
+ For each column, the following information are extracted:
19
+ - name
20
+ - data type
21
+ - nullability
22
+ - foreign key
23
+
24
+ Additionally, for each table, PRIMARY KEY/UNIQUE constraints are extracted. This is also computed for the result of each SELECT query.
25
+
26
+
27
+ # Credits
28
+ Special thanks to Flavio Venturini for his valuable contributions to the development of this project.
29
+
30
+ # Limitations
31
+ - Fully identified schema names are not supported when specifying column names (e.g. `SELECT schema.table.column [...]`)