Skip to content

Commit 973cd13

Browse files
committed
Add software tests using Polars
Polars does not support writing to databases yet, nor does it support SQLAlchemy's AsyncEngine. So, this exercises `pl.read_database()` only, together with the `crate` and `postgresql+psycopg_relaxed` dialects, using urllib3 resp. Psycopg3.
1 parent 46313e5 commit 973cd13

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ release = [
7979
test = [
8080
"crate[sqlalchemy]",
8181
"pandas<2.1",
82+
"polars[pyarrow]<0.21",
8283
"pytest<8",
8384
"pytest-asyncio<1",
8485
"pytest-cov<5",

tests/test_cratedb_polars_read.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
3+
import polars as pl
4+
import pytest
5+
import sqlalchemy as sa
6+
from polars.testing import assert_frame_equal
7+
8+
REFERENCE_FRAME = pl.from_records([{"mountain": "Mont Blanc", "height": 4808}])
9+
SQL_SELECT_STATEMENT = "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 1;"
10+
11+
12+
if sys.version_info < (3, 8):
13+
pytest.skip("Does not work on Python 3.7", allow_module_level=True)
14+
15+
16+
def test_crate_read_sql(cratedb_http_host, cratedb_http_port):
17+
engine = sa.create_engine(
18+
url=f"crate://{cratedb_http_host}:{cratedb_http_port}",
19+
echo=True,
20+
)
21+
conn = engine.connect()
22+
df = pl.read_database(
23+
query=SQL_SELECT_STATEMENT,
24+
connection=conn,
25+
schema_overrides={"value": pl.Utf8},
26+
)
27+
assert_frame_equal(df, REFERENCE_FRAME)
28+
29+
30+
def test_psycopg_read_sql(cratedb_psql_host, cratedb_psql_port):
31+
engine = sa.create_engine(
32+
url=f"postgresql+psycopg_relaxed://crate@{cratedb_psql_host}:{cratedb_psql_port}",
33+
isolation_level="AUTOCOMMIT",
34+
use_native_hstore=False,
35+
echo=True,
36+
)
37+
conn = engine.connect()
38+
df = pl.read_database(
39+
query=SQL_SELECT_STATEMENT,
40+
connection=conn,
41+
schema_overrides={"value": pl.Utf8},
42+
)
43+
assert_frame_equal(df, REFERENCE_FRAME)

0 commit comments

Comments
 (0)