Skip to content

Commit

Permalink
tests with select goes through locally
Browse files Browse the repository at this point in the history
  • Loading branch information
aersam committed May 3, 2024
1 parent 81441b3 commit f3c4de9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 12 additions & 1 deletion lakeapi2sql/sql_connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
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:
Expand All @@ -21,5 +32,5 @@ async def execute_sql(self, sql: str, arguments: list[str | int | float | bool |

async def execute_sql_with_result(
self, sql: str, arguments: list[str | int | float | bool | None] = None
) -> list[int]:
) -> TdsResult:
return await lvd.execute_sql_with_result(self._connection, sql, arguments or [])
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use error::LakeApi2SqlError;
use futures::{StreamExt, TryStreamExt};
use pyo3::exceptions::{PyConnectionError, PyIOError, PyTypeError};
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyInt, PyList, PyString};
use pyo3::types::{PyDict, PyInt, PyList, PyString, PyTuple};
mod arrow_convert;
pub mod bulk_insert;
pub mod connect;
Expand Down Expand Up @@ -63,7 +63,7 @@ fn into_dict_result<'a>(py: Python<'a>, meta: Option<ResultMetadata>, rows: Vec<
let mut py_rows = PyList::new(
py,
rows.iter().map(|row| {
PyList::new(
PyTuple::new(
py,
row.cells()
.map(|(c, val)| match val {
Expand Down
11 changes: 9 additions & 2 deletions tests/test_insert_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ async def test_insert_simple(connection: "DB_Connection"):

batchreader = pa.RecordBatchReader.from_batches(batch.schema, [batch])
async with connection.new_connection() as con:
await con.execute_sql("drop table if exists ##ft;create table ##ft(f0 bigint, f1 nvarchar(100), f2 bit)")
await con.execute_sql(
"drop table if exists dbo.test1;create table dbo.test1(f0 bigint, f1 nvarchar(100), f2 bit)"
)

await insert_record_batch_to_sql(
connection.conn_str,
"##ft",
"dbo.test1",
batchreader,
["f0", "f1", "f2"],
)
async with connection.new_connection() as con:
res = await con.execute_sql_with_result("select * from dbo.test1")
print(res["columns"])
assert [c["name"] for c in res["columns"]] == ["f0", "f1", "f2"]
assert res["rows"] == [(1, "foo", True), (2, "bar", None), (3, "$ä,àE", False), (4, None, True)]

0 comments on commit f3c4de9

Please sign in to comment.