chdb 3.1.1__cp39-cp39-macosx_11_0_arm64.whl → 3.2.0__cp39-cp39-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of chdb might be problematic. Click here for more details.

chdb/__init__.py CHANGED
@@ -19,7 +19,7 @@ _process_result_format_funs = {
19
19
  # UDF script path will be f"{g_udf_path}/{func_name}.py"
20
20
  g_udf_path = ""
21
21
 
22
- chdb_version = ('3', '1', '1')
22
+ chdb_version = ('3', '2', '0')
23
23
  if sys.version_info[:2] >= (3, 7):
24
24
  # get the path of the current file
25
25
  current_path = os.path.dirname(os.path.abspath(__file__))
Binary file
chdb/session/state.py CHANGED
@@ -4,7 +4,7 @@ import warnings
4
4
 
5
5
  import chdb
6
6
  from ..state import sqlitelike as chdb_stateful
7
-
7
+ from ..state.sqlitelike import StreamingResult
8
8
 
9
9
  g_session = None
10
10
  g_session_path = None
@@ -120,3 +120,16 @@ Eg: conn = connect(f"db_path?verbose&log-level=test")"""
120
120
 
121
121
  # alias sql = query
122
122
  sql = query
123
+
124
+ def send_query(self, sql, fmt="CSV") -> StreamingResult:
125
+ """
126
+ Execute a streaming query.
127
+ """
128
+ if fmt == "Debug":
129
+ warnings.warn(
130
+ """Debug format is not supported in Session.query
131
+ Please try use parameters in connection string instead:
132
+ Eg: conn = connect(f"db_path?verbose&log-level=test")"""
133
+ )
134
+ fmt = "CSV"
135
+ return self._conn.send_query(sql, fmt)
chdb/state/sqlitelike.py CHANGED
@@ -40,6 +40,57 @@ def to_df(r):
40
40
  return t.to_pandas(use_threads=True)
41
41
 
42
42
 
43
+ class StreamingResult:
44
+ def __init__(self, c_result, conn, result_func):
45
+ self._result = c_result
46
+ self._result_func = result_func
47
+ self._conn = conn
48
+ self._exhausted = False
49
+
50
+ def fetch(self):
51
+ """Fetch next chunk of streaming results"""
52
+ if self._exhausted:
53
+ return None
54
+
55
+ try:
56
+ result = self._conn.streaming_fetch_result(self._result)
57
+ if result is None or result.rows_read() == 0:
58
+ self._exhausted = True
59
+ return None
60
+ return self._result_func(result)
61
+ except Exception as e:
62
+ self._exhausted = True
63
+ raise RuntimeError(f"Streaming query failed: {str(e)}") from e
64
+
65
+ def __iter__(self):
66
+ return self
67
+
68
+ def __next__(self):
69
+ if self._exhausted:
70
+ raise StopIteration
71
+
72
+ chunk = self.fetch()
73
+ if chunk is None:
74
+ self._exhausted = True
75
+ raise StopIteration
76
+
77
+ return chunk
78
+
79
+ def __enter__(self):
80
+ return self
81
+
82
+ def __exit__(self, exc_type, exc_val, exc_tb):
83
+ pass
84
+
85
+ def cancel(self):
86
+ self._exhausted = True
87
+
88
+ try:
89
+ self._conn.streaming_cancel_query(self._result)
90
+ except Exception as e:
91
+ raise RuntimeError(f"Failed to cancel streaming query: {str(e)}") from e
92
+
93
+
43
94
  class Connection:
44
95
  def __init__(self, connection_string: str):
45
96
  # print("Connection", connection_string)
@@ -59,6 +110,15 @@ class Connection:
59
110
  result = self._conn.query(query, format)
60
111
  return result_func(result)
61
112
 
113
+ def send_query(self, query: str, format: str = "CSV") -> StreamingResult:
114
+ lower_output_format = format.lower()
115
+ result_func = _process_result_format_funs.get(lower_output_format, lambda x: x)
116
+ if lower_output_format in _arrow_format:
117
+ format = "Arrow"
118
+
119
+ c_stream_result = self._conn.send_query(query, format)
120
+ return StreamingResult(c_stream_result, self._conn, result_func)
121
+
62
122
  def close(self) -> None:
63
123
  # print("close")
64
124
  if self._cursor:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: chdb
3
- Version: 3.1.1
3
+ Version: 3.2.0
4
4
  Summary: chDB is an in-process SQL OLAP Engine powered by ClickHouse
5
5
  Home-page: https://github.com/chdb-io/chdb
6
6
  Author: auxten
@@ -30,6 +30,7 @@ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
30
30
  License-File: LICENSE.txt
31
31
  Requires-Dist: pyarrow>=13.0.0
32
32
  Requires-Dist: pandas>=2.0.0
33
+ Dynamic: license-file
33
34
  Dynamic: requires-dist
34
35
  Dynamic: requires-python
35
36
 
@@ -95,6 +96,44 @@ python3 -m chdb "SELECT 1,'abc'" Pretty
95
96
  ### Data Input
96
97
  The following methods are available to access on-disk and in-memory data formats:
97
98
 
99
+ <details>
100
+ <summary><h4>🗂️ Connection based API (recommended)</h4></summary>
101
+
102
+ ```python
103
+ import chdb
104
+
105
+ # Create a connection (in-memory by default)
106
+ conn = chdb.connect(":memory:")
107
+ # Or use file-based: conn = chdb.connect("test.db")
108
+
109
+ # Create a cursor
110
+ cur = conn.cursor()
111
+
112
+ # Execute queries
113
+ cur.execute("SELECT number, toString(number) as str FROM system.numbers LIMIT 3")
114
+
115
+ # Fetch data in different ways
116
+ print(cur.fetchone()) # Single row: (0, '0')
117
+ print(cur.fetchmany(2)) # Multiple rows: ((1, '1'), (2, '2'))
118
+
119
+ # Get column information
120
+ print(cur.column_names()) # ['number', 'str']
121
+ print(cur.column_types()) # ['UInt64', 'String']
122
+
123
+ # Use the cursor as an iterator
124
+ cur.execute("SELECT number FROM system.numbers LIMIT 3")
125
+ for row in cur:
126
+ print(row)
127
+
128
+ # Always close resources when done
129
+ cur.close()
130
+ conn.close()
131
+ ```
132
+
133
+ For more details, see [examples/connect.py](examples/connect.py).
134
+ </details>
135
+
136
+
98
137
  <details>
99
138
  <summary><h4>🗂️ Query On File</h4> (Parquet, CSV, JSON, Arrow, ORC and 60+)</summary>
100
139
 
@@ -220,6 +259,56 @@ see also: [test_udf.py](tests/test_udf.py).
220
259
  </details>
221
260
 
222
261
 
262
+ <details>
263
+ <summary><h4>🗂️ Streaming Query</h4></summary>
264
+
265
+ Process large datasets with constant memory usage through chunked streaming.
266
+
267
+ ```python
268
+ from chdb import session as chs
269
+
270
+ sess = chs.Session()
271
+
272
+ # Example 1: Basic example of using streaming query
273
+ rows_cnt = 0
274
+ with sess.send_query("SELECT * FROM numbers(200000)", "CSV") as stream_result:
275
+ for chunk in stream_result:
276
+ rows_cnt += chunk.rows_read()
277
+
278
+ print(rows_cnt) # 200000
279
+
280
+ # Example 2: Manual iteration with fetch()
281
+ rows_cnt = 0
282
+ stream_result = sess.send_query("SELECT * FROM numbers(200000)", "CSV")
283
+ while True:
284
+ chunk = stream_result.fetch()
285
+ if chunk is None:
286
+ break
287
+ rows_cnt += chunk.rows_read()
288
+
289
+ print(rows_cnt) # 200000
290
+
291
+ # Example 3: Early cancellation demo
292
+ rows_cnt = 0
293
+ stream_result = sess.send_query("SELECT * FROM numbers(200000)", "CSV")
294
+ while True:
295
+ chunk = stream_result.fetch()
296
+ if chunk is None:
297
+ break
298
+ if rows_cnt > 0:
299
+ stream_result.cancel()
300
+ break
301
+ rows_cnt += chunk.rows_read()
302
+
303
+ print(rows_cnt) # 65409
304
+
305
+ sess.close()
306
+ ```
307
+
308
+ For more details, see [test_streaming_query.py](tests/test_streaming_query.py).
309
+ </details>
310
+
311
+
223
312
  <details>
224
313
  <summary><h4>🗂️ Python Table Engine</h4></summary>
225
314
 
@@ -1,6 +1,6 @@
1
- chdb/__init__.py,sha256=dhg9VbRbDft2hubgDzR-pUHN11SER5HucmhhaGwb9Ek,3762
1
+ chdb/__init__.py,sha256=yuWj0i3_5-uBRZCyZMBKIiBR1MmjEyAjcuxKTm076jI,3762
2
2
  chdb/__main__.py,sha256=xNNtDY38d973YM5dlxiIazcqqKhXJSpNb7JflyyrXGE,1185
3
- chdb/_chdb.cpython-39-darwin.so,sha256=avgpJK9kVGSs3U7RwdulVrE-Fw9FRpA-VFBsr50k-GM,356175536
3
+ chdb/_chdb.cpython-39-darwin.so,sha256=Rmvwl2E9IIDDclZjcVg-FG_fTMgGyXiOLCGnJerFMPU,356205472
4
4
  chdb/rwabc.py,sha256=tbiwCrXirfrfx46wCJxS64yvFe6pVWIPGdSuvrAL5Ys,2102
5
5
  chdb/dataframe/__init__.py,sha256=1_mrZZiJwqBTnH_P8_FCbbYXIWWY5sxnaFpe3-tDLF4,680
6
6
  chdb/dataframe/query.py,sha256=ggvE8A5vtabFg9gSTp99S7LCrnIEwbWtb-PtJVT8Ct0,12759
@@ -13,9 +13,9 @@ chdb/dbapi/times.py,sha256=_qXgDaYwsHntvpIKSKXp1rrYIgtq6Z9pLyLnO2XNoL0,360
13
13
  chdb/dbapi/constants/FIELD_TYPE.py,sha256=ytFzgAnGmb9hvdsBlnK68qdZv_a6jYFIXT6VSAb60z8,370
14
14
  chdb/dbapi/constants/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  chdb/session/__init__.py,sha256=fCUROZ5L1-92o2lcASiWJpFu-80-kDoSrNfouLEmLg8,50
16
- chdb/session/state.py,sha256=nx9KlqZyPTHAflToXCJVRBUSMjJFvyh6x2akP7Gc7h0,4360
16
+ chdb/session/state.py,sha256=UtObxVuyNgeqFkTXVHtmOknR90Pe1dEzbOpKFDBYOkg,4845
17
17
  chdb/state/__init__.py,sha256=RVUIWDqDi7gte4Os7Mz1wPXFyFpdHT_p1klJC7QtluI,55
18
- chdb/state/sqlitelike.py,sha256=6Y57vnf7LnA0KnpByKQq7PkEkEEOKK-ExaHQLb1bedQ,10498
18
+ chdb/state/sqlitelike.py,sha256=v0xh9jWirHzhDVq26C2213LxfaDbRulSAhSHaTiZ24c,12283
19
19
  chdb/state/test_sqlitelike.py,sha256=8Y7Up2Glkl6PpSgkMF_Rgz_3oGgx-6aLcyxaw2bzQR8,7586
20
20
  chdb/tests/test_dbapi.py,sha256=Z5KloM0ujhVFaLOES6V6slLIRWbTyg0lPyggl3m2ZqY,2765
21
21
  chdb/udf/__init__.py,sha256=qSMaPEre7w1pYz8uJ-iZtuu8wYOUNRcI_8UNuaOymGE,80
@@ -23,8 +23,8 @@ chdb/udf/udf.py,sha256=z0A1RmyZrx55bykpvvS-LpVt1lMrQOexjvU5zxCdCSA,3935
23
23
  chdb/utils/__init__.py,sha256=tXRcwBRGW2YQNBZWV4Mitw5QlCu_qlSRCjllw15XHbs,171
24
24
  chdb/utils/trace.py,sha256=W-pvDoKlnzq6H_7FiWjr5_teN40UNE4E5--zbUrjOIc,2511
25
25
  chdb/utils/types.py,sha256=MGLFIjoDvu7Uc2Wy8EDY60jjue66HmMPxbhrujjrZxQ,7530
26
- chdb-3.1.1.dist-info/LICENSE.txt,sha256=isYVtNCO5910aj6e9bJJ6kQceivkLqsMlFSNYwzGGKI,11366
27
- chdb-3.1.1.dist-info/METADATA,sha256=zzMgz3TT8nQ8oEpbgcBTuirfhG8jZnib0UxcE-jOOZI,19490
28
- chdb-3.1.1.dist-info/WHEEL,sha256=lcS7ertGdTcwg6KPpE3fBtGreaKMXtC8sl4-ZeZxMCs,107
29
- chdb-3.1.1.dist-info/top_level.txt,sha256=se0Jj0A2-ijfMW51hIjiuNyDJPqy5xJU1G8a_IEdllI,11
30
- chdb-3.1.1.dist-info/RECORD,,
26
+ chdb-3.2.0.dist-info/licenses/LICENSE.txt,sha256=isYVtNCO5910aj6e9bJJ6kQceivkLqsMlFSNYwzGGKI,11366
27
+ chdb-3.2.0.dist-info/METADATA,sha256=n8no2boSiPOzbj8PtIT3nIQUtYGXQ1TEgq4QSOFzI4U,21585
28
+ chdb-3.2.0.dist-info/WHEEL,sha256=pGnIPP3dct3nMy_HgzTd73quJsF776raA6HDn0Vi6XE,107
29
+ chdb-3.2.0.dist-info/top_level.txt,sha256=se0Jj0A2-ijfMW51hIjiuNyDJPqy5xJU1G8a_IEdllI,11
30
+ chdb-3.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (76.0.0)
2
+ Generator: setuptools (79.0.1)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp39-cp39-macosx_11_0_arm64
5
5