Skip to content

Commit 8f0bee7

Browse files
paxcodesjayvynl
authored andcommitted
docs: Update changelog and add documentation on set_query_execution_args
1 parent cb955c4 commit 8f0bee7

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 1.4.0
2+
3+
- feat: #119 Allow query results returned in columns and deserialized to `numpy` objects
4+
15
### 1.3.2
26

37
- feat(aggragation-function): add anyLast function.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Read [Documentation](https://github.com/jayvynl/django-clickhouse-backend/blob/m
2929
- Support most clickhouse data types.
3030
- Support [SETTINGS in SELECT Query](https://clickhouse.com/docs/en/sql-reference/statements/select/#settings-in-select-query).
3131
- Support [PREWHERE clause](https://clickhouse.com/docs/en/sql-reference/statements/select/prewhere).
32+
- Support query results returned in columns and [deserialized to `numpy` objects](https://clickhouse-driver.readthedocs.io/en/latest/features.html#numpy-pandas-support).
3233

3334
**Notes:**
3435

@@ -381,6 +382,60 @@ and [distributed table engine](https://clickhouse.com/docs/en/engines/table-engi
381382
The following example assumes that a cluster defined by [docker compose in this repository](https://github.com/jayvynl/django-clickhouse-backend/blob/main/compose.yaml) is used.
382383
This cluster name is `cluster`, it has 2 shards, every shard has 2 replica.
383384

385+
Query results returned as columns and/or deserialized into `numpy` objects
386+
---
387+
388+
`clickhouse-driver` allows results to be returned as columns and/or deserialized into
389+
`numpy` objects. This backend supports both options by using the context manager,
390+
`Cursor.set_query_execution_args()`.
391+
392+
```python
393+
import numpy as np
394+
from django.db import connection
395+
396+
sql = """
397+
SELECT toDateTime32('2022-01-01 01:00:05', 'UTC'), number, number*2.5
398+
FROM system.numbers
399+
LIMIT 3
400+
"""
401+
with connection.cursor() as cursorWrapper:
402+
with cursorWrapper.cursor.set_query_execution_args(
403+
columnar=True, use_numpy=True
404+
) as cursor:
405+
cursor.execute(sql)
406+
np.testing.assert_equal(
407+
cursor.fetchall(),
408+
[
409+
np.array(
410+
[
411+
np.datetime64("2022-01-01T01:00:05"),
412+
np.datetime64("2022-01-01T01:00:05"),
413+
np.datetime64("2022-01-01T01:00:05"),
414+
],
415+
dtype="datetime64[s]",
416+
),
417+
np.array([0, 1, 2], dtype=np.uint64),
418+
np.array([0, 2.5, 5.0], dtype=np.float64),
419+
],
420+
)
421+
422+
cursor.execute(sql)
423+
np.testing.assert_equal(
424+
cursor.fetchmany(2),
425+
[
426+
np.array(
427+
[
428+
np.datetime64("2022-01-01T01:00:05"),
429+
np.datetime64("2022-01-01T01:00:05"),
430+
np.datetime64("2022-01-01T01:00:05"),
431+
],
432+
dtype="datetime64[s]",
433+
),
434+
np.array([0, 1, 2], dtype=np.uint64),
435+
],
436+
)
437+
```
438+
384439
### Configuration
385440

386441
```python

0 commit comments

Comments
 (0)