-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from bmsuisse/executesql
Bug Fixes and Testing
- Loading branch information
Showing
22 changed files
with
455 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Python Test | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
paths-ignore: ["README.md", "docs", ".github"] | ||
pull_request: | ||
branches: ["main"] | ||
paths-ignore: ["README.md", "docs", ".github"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.11"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Setup Rust | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
- name: Install tooling dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install maturin | ||
- name: Install Dependencies | ||
run: | | ||
pip install pytest polars pyarrow pytest-asyncio pyright python-dotenv docker pyright cffi | ||
- name: Install Project | ||
run: maturin develop | ||
- name: pytest | ||
shell: bash | ||
run: pytest | ||
- name: Pyright | ||
run: poetry run pyright . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
import lakeapi2sql._lowlevel as lvd | ||
from lakeapi2sql.utils import prepare_connection_string | ||
from typing import TypedDict | ||
|
||
|
||
class TdsColumn(TypedDict): | ||
name: str | ||
column_type: str | ||
|
||
|
||
class TdsResult(TypedDict): | ||
columns: list[TdsColumn] | ||
rows: list[dict] | ||
|
||
|
||
class TdsConnection: | ||
def __init__(self, connection_string: str, aad_token: str | None = None) -> None: | ||
connection_string, aad_token = await prepare_connection_string(connection_string, aad_token) | ||
self._connection_string = connection_string | ||
self._aad_token = aad_token | ||
|
||
async def __aenter__(self) -> "TdsConnection": | ||
self._connection = await lvd.connect_sql(self.connection_string, self.aad_token) | ||
connection_string, aad_token = await prepare_connection_string(self._connection_string, self._aad_token) | ||
|
||
self._connection = await lvd.connect_sql(connection_string, aad_token) | ||
return self | ||
|
||
async def __aexit__(self, exc_type, exc_value, traceback) -> None: | ||
async def __aexit__(self, *args, **kwargs) -> None: | ||
pass | ||
|
||
async def execute_sql(self, sql: str, arguments: list[str | int | float | bool | None]) -> list[int]: | ||
return await lvd.execute_sql(self._connection, sql, arguments) | ||
async def execute_sql(self, sql: str, arguments: list[str | int | float | bool | None] = None) -> list[int]: | ||
return await lvd.execute_sql(self._connection, sql, arguments or []) | ||
|
||
async def execute_sql_with_result(self, sql: str, arguments: list[str | int | float | bool | None]) -> list[int]: | ||
return await lvd.execute_sql_with_result(self._connection, sql, arguments) | ||
async def execute_sql_with_result( | ||
self, sql: str, arguments: list[str | int | float | bool | None] = None | ||
) -> TdsResult: | ||
return await lvd.execute_sql_with_result(self._connection, sql, arguments or []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from pathlib import Path | ||
import docker | ||
from docker.models.containers import Container | ||
from time import sleep | ||
from typing import cast | ||
import docker.errors | ||
import os | ||
|
||
|
||
def _getenvs(): | ||
envs = dict() | ||
with open("test_server/sql_docker.env", "r") as f: | ||
lines = f.readlines() | ||
envs = { | ||
item[0].strip(): item[1].strip() | ||
for item in [line.split("=") for line in lines if len(line.strip()) > 0 and not line.startswith("#")] | ||
} | ||
return envs | ||
|
||
|
||
def start_mssql_server() -> Container: | ||
client = docker.from_env() # code taken from https://github.com/fsspec/adlfs/blob/main/adlfs/tests/conftest.py#L72 | ||
sql_server: Container | None = None | ||
try: | ||
m = cast(Container, client.containers.get("test4sql_lakeapi2sql")) | ||
if m.status == "running": | ||
return m | ||
else: | ||
sql_server = m | ||
except docker.errors.NotFound: | ||
pass | ||
|
||
envs = _getenvs() | ||
|
||
if sql_server is None: | ||
# using podman: podman run --env-file=TESTS/SQL_DOCKER.ENV --publish=1439:1433 --name=mssql1 chriseaton/adventureworks:light | ||
# podman kill mssql1 | ||
sql_server = client.containers.run( | ||
"mcr.microsoft.com/mssql/server:2022-latest", | ||
environment=envs, | ||
detach=True, | ||
name="test4sql_lakeapi2sql", | ||
ports={"1433/tcp": "1444"}, | ||
) # type: ignore | ||
assert sql_server is not None | ||
sql_server.start() | ||
print(sql_server.status) | ||
sleep(15) | ||
print("Successfully created sql container...") | ||
return sql_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SA_PASSWORD=MyPass@word4tests | ||
ACCEPT_EULA=Y | ||
MSSQL_PID=Express | ||
MSSQL_SA_PASSWORD=MyPass@word4tests |
File renamed without changes.
Oops, something went wrong.