Skip to content

Commit 4e8da3a

Browse files
authored
Port StatementExecutionExt from UCX (#31)
This initial commit ports code from https://github.com/databrickslabs/ucx
1 parent 1ed7a00 commit 4e8da3a

32 files changed

+2857
-927
lines changed

.codegen.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": {
3+
"src/databricks/labs/lsql/__about__.py": "__version__ = \"$VERSION\""
4+
},
5+
"toolchain": {
6+
"required": ["python3"],
7+
"pre_setup": [
8+
"python3 -m pip install hatch==1.7.0",
9+
"python3 -m hatch env create"
10+
],
11+
"prepend_path": ".venv/bin",
12+
"acceptance_path": "tests/integration",
13+
"test": [
14+
"pytest -n 4 --cov src --cov-report=xml --timeout 30 tests/unit --durations 20"
15+
]
16+
}
17+
}

.github/workflows/acceptance.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: acceptance
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, ready_for_review ]
6+
7+
permissions:
8+
id-token: write
9+
contents: read
10+
pull-requests: write
11+
12+
concurrency:
13+
group: single-acceptance-job-per-repo
14+
15+
jobs:
16+
integration:
17+
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
18+
environment: runtime
19+
runs-on: larger
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v2.5.0
23+
24+
- name: Unshallow
25+
run: git fetch --prune --unshallow
26+
27+
- name: Install Python
28+
uses: actions/setup-python@v4
29+
with:
30+
cache: 'pip'
31+
cache-dependency-path: '**/pyproject.toml'
32+
python-version: '3.10'
33+
34+
- name: Install hatch
35+
run: pip install hatch==1.7.0
36+
37+
- name: Run integration tests
38+
uses: databrickslabs/sandbox/acceptance@acceptance/v0.1.4
39+
with:
40+
vault_uri: ${{ secrets.VAULT_URI }}
41+
timeout: 45m
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
45+
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}

.github/workflows/push.yml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ on:
1414
branches:
1515
- main
1616

17-
env:
18-
HATCH_VERSION: 1.7.0
19-
2017
jobs:
2118
ci:
2219
strategy:
20+
fail-fast: false
2321
matrix:
24-
pyVersion: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
22+
pyVersion: [ '3.10', '3.11', '3.12' ]
2523
runs-on: ubuntu-latest
2624
steps:
2725
- name: Checkout
@@ -34,11 +32,10 @@ jobs:
3432
cache-dependency-path: '**/pyproject.toml'
3533
python-version: ${{ matrix.pyVersion }}
3634

37-
- name: Install hatch
38-
run: pip install hatch==$HATCH_VERSION
39-
4035
- name: Run unit tests
41-
run: hatch run unit:test
36+
run: |
37+
pip install hatch==1.7.0
38+
make test
4239
4340
- name: Publish test coverage
4441
uses: codecov/codecov-action@v1
@@ -49,15 +46,8 @@ jobs:
4946
- name: Checkout
5047
uses: actions/checkout@v3
5148

52-
- name: Install Python
53-
uses: actions/setup-python@v4
54-
with:
55-
cache: 'pip'
56-
cache-dependency-path: '**/pyproject.toml'
57-
python-version: 3.10.x
58-
59-
- name: Install hatch
60-
run: pip install hatch==$HATCH_VERSION
49+
- name: Format all files
50+
run: make dev fmt
6151

62-
- name: Verify linting
63-
run: hatch run lint:verify
52+
- name: Fail on differences
53+
run: git diff --exit-code

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
environment: release
12+
permissions:
13+
# Used to authenticate to PyPI via OIDC and sign the release's artifacts with sigstore-python.
14+
id-token: write
15+
# Used to attach signing artifacts to the published release.
16+
contents: write
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- uses: actions/setup-python@v4
21+
with:
22+
cache: 'pip'
23+
cache-dependency-path: '**/pyproject.toml'
24+
python-version: '3.10'
25+
26+
- name: Build wheels
27+
run: |
28+
pip install hatch==1.7.0
29+
hatch build
30+
31+
- name: Draft release
32+
uses: softprops/action-gh-release@v1
33+
with:
34+
draft: true
35+
files: |
36+
dist/databricks_*.whl
37+
dist/databricks_*.tar.gz
38+
39+
- uses: pypa/gh-action-pypi-publish@release/v1
40+
name: Publish package distributions to PyPI
41+
42+
- name: Sign artifacts with Sigstore
43+
uses: sigstore/gh-action-sigstore-python@v2.1.1
44+
with:
45+
inputs: |
46+
dist/databricks_*.whl
47+
dist/databricks_*.tar.gz
48+
release-signing-artifacts: true

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Version changelog
2+
3+
## 0.0.0
4+
5+
Initial commit

CONTRIBUTING.md

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,117 @@
1-
To setup local dev environment, you have to install `hatch` tooling: `pip install hatch`.
1+
# Contributing
22

3-
After, you have to configure your IDE with it: `hatch run python -c "import sys; print(sys.executable)" | pbcopy`
3+
## First Principles
4+
5+
Favoring standard libraries over external dependencies, especially in specific contexts like Databricks, is a best practice in software
6+
development.
7+
8+
There are several reasons why this approach is encouraged:
9+
- Standard libraries are typically well-vetted, thoroughly tested, and maintained by the official maintainers of the programming language or platform. This ensures a higher level of stability and reliability.
10+
- External dependencies, especially lesser-known or unmaintained ones, can introduce bugs, security vulnerabilities, or compatibility issues that can be challenging to resolve. Adding external dependencies increases the complexity of your codebase.
11+
- Each dependency may have its own set of dependencies, potentially leading to a complex web of dependencies that can be difficult to manage. This complexity can lead to maintenance challenges, increased risk, and longer build times.
12+
- External dependencies can pose security risks. If a library or package has known security vulnerabilities and is widely used, it becomes an attractive target for attackers. Minimizing external dependencies reduces the potential attack surface and makes it easier to keep your code secure.
13+
- Relying on standard libraries enhances code portability. It ensures your code can run on different platforms and environments without being tightly coupled to specific external dependencies. This is particularly important in settings like Databricks, where you may need to run your code on different clusters or setups.
14+
- External dependencies may have their versioning schemes and compatibility issues. When using standard libraries, you have more control over versioning and can avoid conflicts between different dependencies in your project.
15+
- Fewer external dependencies mean faster build and deployment times. Downloading, installing, and managing external packages can slow down these processes, especially in large-scale projects or distributed computing environments like Databricks.
16+
- External dependencies can be abandoned or go unmaintained over time. This can lead to situations where your project relies on outdated or unsupported code. When you depend on standard libraries, you have confidence that the core functionality you rely on will continue to be maintained and improved.
17+
18+
While minimizing external dependencies is essential, exceptions can be made case-by-case. There are situations where external dependencies are
19+
justified, such as when a well-established and actively maintained library provides significant benefits, like time savings, performance improvements,
20+
or specialized functionality unavailable in standard libraries.
21+
22+
## Common fixes for `mypy` errors
23+
24+
See https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html for more details
25+
26+
### ..., expression has type "None", variable has type "str"
27+
28+
* Add `assert ... is not None` if it's a body of a method. Example:
29+
30+
```
31+
# error: Argument 1 to "delete" of "DashboardWidgetsAPI" has incompatible type "str | None"; expected "str"
32+
self._ws.dashboard_widgets.delete(widget.id)
33+
```
34+
35+
after
36+
37+
```
38+
assert widget.id is not None
39+
self._ws.dashboard_widgets.delete(widget.id)
40+
```
41+
42+
* Add `... | None` if it's in the dataclass. Example: `cloud: str = None` -> `cloud: str | None = None`
43+
44+
### ..., has incompatible type "Path"; expected "str"
45+
46+
Add `.as_posix()` to convert Path to str
47+
48+
### Argument 2 to "get" of "dict" has incompatible type "None"; expected ...
49+
50+
Add a valid default value for the dictionary return.
51+
52+
Example:
53+
```python
54+
def viz_type(self) -> str:
55+
return self.viz.get("type", None)
56+
```
57+
58+
after:
59+
60+
Example:
61+
```python
62+
def viz_type(self) -> str:
63+
return self.viz.get("type", "UNKNOWN")
64+
```
65+
66+
## Local Setup
67+
68+
This section provides a step-by-step guide to set up and start working on the project. These steps will help you set up your project environment and dependencies for efficient development.
69+
70+
To begin, run `make dev` create the default environment and install development dependencies, assuming you've already cloned the github repo.
71+
72+
```shell
73+
make dev
74+
```
75+
76+
Verify installation with
77+
```shell
78+
make test
79+
```
80+
81+
Before every commit, apply the consistent formatting of the code, as we want our codebase look consistent:
82+
```shell
83+
make fmt
84+
```
85+
86+
Before every commit, run automated bug detector (`make lint`) and unit tests (`make test`) to ensure that automated
87+
pull request checks do pass, before your code is reviewed by others:
88+
```shell
89+
make test
90+
```
91+
92+
## First contribution
93+
94+
Here are the example steps to submit your first contribution:
95+
96+
1. Make a Fork from ucx repo (if you really want to contribute)
97+
2. `git clone`
98+
3. `git checkout main` (or `gcm` if you're using [ohmyzsh](https://ohmyz.sh/)).
99+
4. `git pull` (or `gl` if you're using [ohmyzsh](https://ohmyz.sh/)).
100+
5. `git checkout -b FEATURENAME` (or `gcb FEATURENAME` if you're using [ohmyzsh](https://ohmyz.sh/)).
101+
6. .. do the work
102+
7. `make fmt`
103+
8. `make lint`
104+
9. .. fix if any
105+
10. `make test`
106+
11. .. fix if any
107+
12. `git commit -a`. Make sure to enter meaningful commit message title.
108+
13. `git push origin FEATURENAME`
109+
14. Go to GitHub UI and create PR. Alternatively, `gh pr create` (if you have [GitHub CLI](https://cli.github.com/) installed).
110+
Use a meaningful pull request title because it'll appear in the release notes. Use `Resolves #NUMBER` in pull
111+
request description to [automatically link it](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue)
112+
to an existing issue.
113+
15. announce PR for the review
114+
115+
## Troubleshooting
116+
117+
If you encounter any package dependency errors after `git pull`, run `make clean`

LICENSE

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,69 @@
1-
DB license
1+
Databricks License
2+
Copyright (2024) Databricks, Inc.
23

3-
Copyright (2023) Databricks, Inc.
4+
Definitions.
5+
6+
Agreement: The agreement between Databricks, Inc., and you governing
7+
the use of the Databricks Services, as that term is defined in
8+
the Master Cloud Services Agreement (MCSA) located at
9+
www.databricks.com/legal/mcsa.
10+
11+
Licensed Materials: The source code, object code, data, and/or other
12+
works to which this license applies.
413

5-
Definitions.
14+
Scope of Use. You may not use the Licensed Materials except in
15+
connection with your use of the Databricks Services pursuant to
16+
the Agreement. Your use of the Licensed Materials must comply at all
17+
times with any restrictions applicable to the Databricks Services,
18+
generally, and must be used in accordance with any applicable
19+
documentation. You may view, use, copy, modify, publish, and/or
20+
distribute the Licensed Materials solely for the purposes of using
21+
the Licensed Materials within or connecting to the Databricks Services.
22+
If you do not agree to these terms, you may not view, use, copy,
23+
modify, publish, and/or distribute the Licensed Materials.
24+
25+
Redistribution. You may redistribute and sublicense the Licensed
26+
Materials so long as all use is in compliance with these terms.
27+
In addition:
28+
29+
- You must give any other recipients a copy of this License;
30+
- You must cause any modified files to carry prominent notices
31+
stating that you changed the files;
32+
- You must retain, in any derivative works that you distribute,
33+
all copyright, patent, trademark, and attribution notices,
34+
excluding those notices that do not pertain to any part of
35+
the derivative works; and
36+
- If a "NOTICE" text file is provided as part of its
37+
distribution, then any derivative works that you distribute
38+
must include a readable copy of the attribution notices
39+
contained within such NOTICE file, excluding those notices
40+
that do not pertain to any part of the derivative works.
641

7-
Agreement: The agreement between Databricks, Inc., and you governing the use of the Databricks Services, which shall be, with respect to Databricks, the Databricks Terms of Service located at www.databricks.com/termsofservice, and with respect to Databricks Community Edition, the Community Edition Terms of Service located at www.databricks.com/ce-termsofuse, in each case unless you have entered into a separate written agreement with Databricks governing the use of the applicable Databricks Services.
42+
You may add your own copyright statement to your modifications and may
43+
provide additional license terms and conditions for use, reproduction,
44+
or distribution of your modifications, or for any such derivative works
45+
as a whole, provided your use, reproduction, and distribution of
46+
the Licensed Materials otherwise complies with the conditions stated
47+
in this License.
848

9-
Software: The source code and object code to which this license applies.
49+
Termination. This license terminates automatically upon your breach of
50+
these terms or upon the termination of your Agreement. Additionally,
51+
Databricks may terminate this license at any time on notice. Upon
52+
termination, you must permanently delete the Licensed Materials and
53+
all copies thereof.
1054

11-
Scope of Use. You may not use this Software except in connection with your use of the Databricks Services pursuant to the Agreement. Your use of the Software must comply at all times with any restrictions applicable to the Databricks Services, generally, and must be used in accordance with any applicable documentation. You may view, use, copy, modify, publish, and/or distribute the Software solely for the purposes of using the code within or connecting to the Databricks Services. If you do not agree to these terms, you may not view, use, copy, modify, publish, and/or distribute the Software.
55+
DISCLAIMER; LIMITATION OF LIABILITY.
1256

13-
Redistribution. You may redistribute and sublicense the Software so long as all use is in compliance with these terms. In addition:
14-
15-
You must give any other recipients a copy of this License;
16-
You must cause any modified files to carry prominent notices stating that you changed the files;
17-
You must retain, in the source code form of any derivative works that you distribute, all copyright, patent, trademark, and attribution notices from the source code form, excluding those notices that do not pertain to any part of the derivative works; and
18-
If the source code form includes a "NOTICE" text file as part of its distribution, then any derivative works that you distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the derivative works.
19-
You may add your own copyright statement to your modifications and may provide additional license terms and conditions for use, reproduction, or distribution of your modifications, or for any such derivative works as a whole, provided your use, reproduction, and distribution of the Software otherwise complies with the conditions stated in this License.
20-
21-
Termination. This license terminates automatically upon your breach of these terms or upon the termination of your Agreement. Additionally, Databricks may terminate this license at any time on notice. Upon termination, you must permanently delete the Software and all copies thereof.
22-
23-
DISCLAIMER; LIMITATION OF LIABILITY.
24-
25-
THE SOFTWARE IS PROVIDED “AS-IS” AND WITH ALL FAULTS. DATABRICKS, ON BEHALF OF ITSELF AND ITS LICENSORS, SPECIFICALLY DISCLAIMS ALL WARRANTIES RELATING TO THE SOURCE CODE, EXPRESS AND IMPLIED, INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES, CONDITIONS AND OTHER TERMS OF MERCHANTABILITY, SATISFACTORY QUALITY OR FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. DATABRICKS AND ITS LICENSORS TOTAL AGGREGATE LIABILITY RELATING TO OR ARISING OUT OF YOUR USE OF OR DATABRICKS’ PROVISIONING OF THE SOURCE CODE SHALL BE LIMITED TO ONE THOUSAND ($1,000) DOLLARS. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57+
THE LICENSED MATERIALS ARE PROVIDED “AS-IS” AND WITH ALL FAULTS.
58+
DATABRICKS, ON BEHALF OF ITSELF AND ITS LICENSORS, SPECIFICALLY
59+
DISCLAIMS ALL WARRANTIES RELATING TO THE LICENSED MATERIALS, EXPRESS
60+
AND IMPLIED, INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES,
61+
CONDITIONS AND OTHER TERMS OF MERCHANTABILITY, SATISFACTORY QUALITY OR
62+
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. DATABRICKS AND
63+
ITS LICENSORS TOTAL AGGREGATE LIABILITY RELATING TO OR ARISING OUT OF
64+
YOUR USE OF OR DATABRICKS’ PROVISIONING OF THE LICENSED MATERIALS SHALL
65+
BE LIMITED TO ONE THOUSAND ($1,000) DOLLARS. IN NO EVENT SHALL
66+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
67+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
68+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE LICENSED MATERIALS OR
69+
THE USE OR OTHER DEALINGS IN THE LICENSED MATERIALS.

0 commit comments

Comments
 (0)