Skip to content

Commit 037fffc

Browse files
Merge branch 'jayvynl:main' into main
2 parents 7b74543 + 30291fa commit 037fffc

File tree

9 files changed

+47
-17
lines changed

9 files changed

+47
-17
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 1.3.2
2+
3+
- feat(aggragation-function): add anyLast function.
4+
- fix: pass DSN to clickhouse-client if configured.
5+
- feat: #108 Queryset.iterator use clickhouse_driver.Client.execute_iter.
6+
- chore: test for python3.13.
7+
18
### 1.3.1
29

310
- fix: #99 update value containing "where" cause exception.

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ run test for all supported Python version and Django version:
9898
```shell
9999
tox
100100
```
101+
102+
### Other
103+
104+
- Don't forget writing [Changelog](CHANGELOG.md)

clickhouse_backend/backend/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS):
163163
self.migration_cluster = self.settings_dict["OPTIONS"].pop(
164164
"migration_cluster", None
165165
)
166+
# https://clickhouse-driver.readthedocs.io/en/latest/quickstart.html#streaming-results
167+
self.max_block_size = self.settings_dict["OPTIONS"].pop("max_block_size", 65409)
166168
if not self.settings_dict["NAME"]:
167169
self.settings_dict["NAME"] = "default"
168170

@@ -224,6 +226,12 @@ def init_connection_state(self):
224226
def create_cursor(self, name=None):
225227
return self.connection.cursor()
226228

229+
@async_unsafe
230+
def chunked_cursor(self):
231+
cursor = self._cursor()
232+
cursor.cursor.set_stream_results(True, self.max_block_size)
233+
return cursor
234+
227235
def _savepoint(self, sid):
228236
pass
229237

clickhouse_backend/backend/client.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ def settings_to_cmd_args_env(cls, settings_dict, parameters):
1717
user = settings_dict.get("USER")
1818
passwd = settings_dict.get("PASSWORD")
1919
secure = options.get("secure")
20+
dsn = options.get("dsn")
2021

21-
if host:
22-
args += ["-h", host]
23-
if port:
24-
args += ["--port", str(port)]
25-
if user:
26-
args += ["-u", user]
27-
if passwd:
28-
args += ["--password", passwd]
29-
if dbname:
30-
args += ["-d", dbname]
31-
if secure:
32-
args += ["--secure"]
22+
if dsn:
23+
args += [dsn]
24+
else:
25+
if host:
26+
args += ["-h", host]
27+
if port:
28+
args += ["--port", str(port)]
29+
if user:
30+
args += ["-u", user]
31+
if passwd:
32+
args += ["--password", passwd]
33+
if dbname:
34+
args += ["-d", dbname]
35+
if secure:
36+
args += ["--secure"]
3337
args.extend(parameters)
3438
return args, None
3539

clickhouse_backend/driver/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ class Connection(dbapi_connection.Connection):
116116
"""Connection class with support for connection pool."""
117117

118118
def __init__(self, *args, **kwargs):
119-
super().__init__(*args, **kwargs)
120119
kwargs.setdefault("connections_min", 10)
121120
kwargs.setdefault("connections_max", 100)
121+
super().__init__(*args, **kwargs)
122122
self.pool = ClickhousePool(
123123
dsn=self.dsn,
124124
host=self.host,

clickhouse_backend/driver/pool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def __init__(self, **kwargs):
1717
self.dsn = kwargs.pop("dsn", None)
1818
self.connections_min = kwargs.pop("connections_min", 10)
1919
self.connections_max = kwargs.pop("connections_max", 20)
20-
21-
self.connection_args = {"host": kwargs.pop("host", "localhost"), **kwargs}
20+
kwargs.setdefault("host", "localhost")
21+
self.connection_args = kwargs
2222
self.closed = False
2323
self._pool = []
2424
self._used = {}

docs/Configurations.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ Migration table will be created on this cluster with [Distributed Engine](https:
4040
- `connections_min` is maximum number of connections can be kept in connection pool, default 10. Set this value to 0 will disable connection pool.
4141
- `connections_max` is maximum number of connections can be used, default 100. In fact, `connections_max` is maximum numbers of queries one can execute concurrently.
4242
Because [source code of DBAPI Connection](https://github.com/mymarilyn/clickhouse-driver/blob/0.2.5/clickhouse_driver/dbapi/connection.py#L46) shows that every cursor creates a new connection.
43+
- `max_block_size` is used for [streaming results](https://clickhouse-driver.readthedocs.io/en/latest/quickstart.html#streaming-results).
4344
- `dsn` provide connection url, for example `clickhouse://localhost/test?param1=value1&...`. If dsn is provided, all other connection parameters are ignored.
4445
- All other [clickhouse_driver.connection.Connection](https://clickhouse-driver.readthedocs.io/en/latest/api.html#connection) parameters.
4546
- `settings` can contain [clickhouse_driver.Client](https://clickhouse-driver.readthedocs.io/en/latest/api.html?highlight=client#clickhouse_driver.Client) settings and [clickhouse settings](https://clickhouse.com/docs/en/operations/settings/settings).
4647

48+
> *Changed in version 1.3.2:* Add `max_block_size`, refer [#108](https://github.com/jayvynl/django-clickhouse-backend/issues/108).
49+
4750
Valid `TEST` keys:
4851

4952
- `managed`: whether create(`True`) test database or not(`False`), default `True`.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classifiers = [
1919
"Framework :: Django :: 4.0",
2020
"Framework :: Django :: 4.1",
2121
"Framework :: Django :: 4.2",
22+
"Framework :: Django :: 5",
2223
"Framework :: Django :: 5.0",
2324
"Framework :: Django :: 5.1",
2425
"Intended Audience :: Developers",
@@ -32,6 +33,7 @@ classifiers = [
3233
"Programming Language :: Python :: 3.10",
3334
"Programming Language :: Python :: 3.11",
3435
"Programming Language :: Python :: 3.12",
36+
"Programming Language :: Python :: 3.13",
3537
]
3638
dependencies = [
3739
"django>=3.2",

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
requires =
33
tox>=4
4-
env_list = py3.7-django3.2, py{3.8,3.9,3.10,3.11,3.12}-django{3.2,4.0,4.1,4.2}, py{3.10,3.11,3.12}-django{5.0,5.1}
4+
env_list = py3.7-django3.2, py{3.8,3.9,3.10,3.11,3.12,3.13}-django{3.2,4.0,4.1,4.2}, py{3.10,3.11,3.12,3.13}-django{5.0,5.1}
55

66
[variables]
77
code = clickhouse_backend example tests
@@ -25,15 +25,17 @@ description = lint code
2525
skip_install = true
2626
deps =
2727
flake8
28+
isort
2829
commands =
30+
isort -c {[variables]code}
2931
flake8 --max-line-length=88 --extend-ignore=E203,E501 {[variables]code}
3032

3133
[testenv:format]
3234
description = format code
3335
skip_install = true
3436
deps =
3537
black==23.7.0
36-
isort==5.12.0
38+
isort
3739
commands =
3840
isort {[variables]code}
3941
black -t py37 -t py38 -t py39 -t py310 -t py311 -t py312 {[variables]code}

0 commit comments

Comments
 (0)