github ClickHouse/clickhouse-connect v1.14.0

one hour ago

Highlights

This release has many correctness fixes across inserts, query parameters, the Rust codec, and the SQLAlchemy and Alembic integration. It also adds new Alembic view and materialized view operations and makes several read and insert paths faster. It ships with clickhouse-connect-core 0.2.4.

Features

  • Alembic can create ordinary and materialized views with explicit columns, a definer, and a SQL security mode. op.modify_clickhouse_view_sql_security changes the mode or definer of an existing view. #1260
  • Alembic materialized views support refresh schedules through ClickHouseRefresh, inner engines, comments, and empty=True. New helpers modify refresh schedules and SELECT queries. All create forms now use CreateClickHouseMaterializedViewOp, so policy hooks should inspect its engine and refresh fields. #1204

Performance

  • query_df is faster for results with many blocks, such as two-level GROUP BY aggregations. Closes #1203. #1205
  • query_np is faster for mixed-type results with object columns, about 18% on a 1M row, 10 column query. #1193
  • Map column reads are faster with the C extensions, and query_np and query_df are faster for numeric Map columns without them. #1207
  • The Python codec builds UUID insert columns in one pass. #1152

Bug Fixes

Inserts and types

  • Python codec UUID inserts no longer write wrong values. Wrong-length byte values raise DataError. A leading None or unsupported value no longer decides the whole block. NaN and pd.NA in insert_df store the zero UUID. #1227
  • Python codec inserts accept NumPy integer scalars in 128 and 256 bit int columns, NumPy float arrays in BFloat16 columns, and nested Dynamic values. #1232
  • JSON values accept NumPy scalars and arrays, and row inserts accept NumPy datetime64 scalars in DateTime and DateTime64 columns. On the Rust codec this needs clickhouse-connect-core>=0.2.4. #1234
  • Insert methods quote each part of database-qualified table names, and create_table and create_table_from_arrow_schema quote column names. #1231
  • Enum labels in client-supplied type names decode the same backslash escapes as the server parser. Closes #1191. #1194

Rust codec

  • query_np, query_df and their streams return numeric and Bool LowCardinality columns with the same dtypes as the Python codec, including LowCardinality(Nullable(T)). Before, query_df could round LowCardinality(UInt64) values above 2**63. #1263

Raw binary query parameters

  • Raw binary $name$ parameters are inserted only at markers outside comments, strings, identifiers and heredocs. A value that would end its own heredoc, or an earlier unclosed one, raises ProgrammingError. #1228, #1235

SQLAlchemy

  • metadata.create_all() and drop_all() include Dictionary objects, and select(dictionary) compiles. Dictionary DDL rejects unsupported column clauses with CompileError. #1220
  • Dictionary reflection handles array literal defaults and attribute options. Closes #1221 and #1222. #1233
  • limit_by() converts limit and offset with int(). #1218
  • On SQLAlchemy 1.4, selecting string literals or Unicode, UnicodeText or Enum columns no longer raises TypeError. #1217
  • Engine arguments zk_path, replica and config_section are escaped, and invalid setting names raise ValueError. #1224

Alembic

  • op.create_table keeps a positional engine, ClickHouseIndex or ClickHouseProjection, as sa.Table does. #1224
  • Literal percent signs are preserved in DDL, operation helpers, autogenerate comparisons and offline output. #1206
  • Autogenerate treats ([a, b]) the same as [a, b], and alter_column checks for existing_type before renaming.

Upgrade notes

A few fixes change behavior that existing code may work around:

  • Percent signs: if you doubled % in Alembic helpers or raw table clauses to work around the old behavior, use single percents now. A ClickHouseIndex or ClickHouseProjection created from %% metadata on 1.13.0 or earlier is stored with %. Update the metadata to % before you run autogenerate, or it will drop and re-add the index or projection.
  • Positional op.create_table args: positional indexes and projections used to be dropped without an error. If a later migration adds the same index as a workaround, it now fails on a fresh database. When both a positional and a keyword engine are given, the positional engine wins.
  • Engine string arguments: pass raw values for zk_path, replica and config_section. Values you escaped by hand will now be escaped twice.

See the CHANGELOG and the core CHANGELOG for full details.

Installation

pip install --upgrade clickhouse-connect

Rust codec users should upgrade both packages. Upgrading only the driver keeps an older installed core.

pip install --upgrade "clickhouse-connect[rust]==1.14.0" "clickhouse-connect-core==0.2.4"

Don't miss a new clickhouse-connect release

NewReleases is sending notifications on new releases.