Skip to content

v4.5.1

Latest

Choose a tag to compare

@auxten auxten released this 18 Nov 06:26
13fddb6

chdb 4.5.1

Requires chdb-core>=26.11.1, unchanged from 4.5.0.

New

Direct PyArrow queries (#806): chdb.query_arrow() returns a pyarrow.Table, and chdb.query_arrow_batches() returns a closable iterator of record batches. Both read results through the Arrow C Data interface, so they skip the Arrow IPC encoding that query(sql, "ArrowTable") does.

import chdb
import pyarrow as pa

table = chdb.query_arrow("SELECT number, number * 2 AS doubled FROM numbers(5)")

with chdb.query_arrow_batches("SELECT number FROM numbers(1000000)") as batches:
    for batch in batches:
        ...

events = pa.table({"id": [1, 2, 3]})
with chdb.arrow.connect() as session:
    with session.register_arrow(events) as source:
        session.query_arrow(f"SELECT sum(id) AS total FROM {source.sql_expr}")
    session.execute("CREATE TABLE dst (id Int64) ENGINE=Memory")
    session.insert_arrow("dst", events)
  • chdb.arrow.connect(path, settings=...) opens a session. register_arrow() takes a PyArrow table, record batch, or anything with __arrow_c_stream__ and schema, and returns a source you use in SQL through source.sql_expr. insert_arrow() writes one into an existing table.
  • A path that already has a query string, such as "data.db?mode=ro", keeps it when settings are added. The connection stays read-only and rejects writes.
  • Only one module-level batch stream can run at a time. Starting another query while a stream is open raises RuntimeError("Finish the active Arrow batch stream first") and does not block. A stream that is closed early or interrupted cancels its query and releases the engine.
  • query(sql, "ArrowTable") is unchanged.

See direct PyArrow queries.

Fixed

  • DataStore: when(...).otherwise(...) with only integer literals returns int64, as pandas does (np.where / np.select). It used to return ClickHouse's uint8, which wrapped around on later subtraction (#804).

Full Changelog: v4.5.0...v4.5.1