From 41680fe5c725a1e496e4abca931b0dfb11108ba2 Mon Sep 17 00:00:00 2001 From: Shawn Chen Date: Wed, 30 Sep 2026 22:07:09 +1300 Subject: [PATCH] Fix differential CI with ClickHouse 26.9 --- tests/differential/conftest.py | 8 +++++- tests/test_differential_runner.py | 42 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/test_differential_runner.py diff --git a/tests/differential/conftest.py b/tests/differential/conftest.py index 6b2b61d..f0f3f2f 100644 --- a/tests/differential/conftest.py +++ b/tests/differential/conftest.py @@ -83,7 +83,13 @@ def run( :param path: Optional persistent ``--path`` directory. By default ``clickhouse local`` uses an ephemeral temp dir per process. """ - args = [self.binary, "local", "--query", sql, "--format", fmt] + # Select the output format in SQL rather than with the CLI's generic + # ``--format`` option. Since ClickHouse 26.9, that option also selects + # the INSERT input format, causing inline ``VALUES`` tuples in the seed + # script to be parsed as TSV. The SQL FORMAT clause works on both the + # old 26.5 baseline and current releases. + formatted_sql = f"{sql.rstrip().rstrip(';')} FORMAT {fmt}" + args = [self.binary, "local", "--query", formatted_sql] if path is not None: args += ["--path", path] proc = subprocess.run( diff --git a/tests/test_differential_runner.py b/tests/test_differential_runner.py new file mode 100644 index 0000000..cde4e92 --- /dev/null +++ b/tests/test_differential_runner.py @@ -0,0 +1,42 @@ +"""Unit tests for the ClickHouse differential-test subprocess wrapper.""" + +from __future__ import annotations + +import subprocess + +from tests.differential import conftest as differential_conftest + + +def test_clickhouse_local_sets_only_the_output_format(monkeypatch): + """The output format must not override how inline VALUES are parsed.""" + calls = [] + + def fake_run(args, **kwargs): + calls.append((args, kwargs)) + return subprocess.CompletedProcess(args, 0, stdout="3\n", stderr="") + + monkeypatch.setattr(differential_conftest.subprocess, "run", fake_run) + + sql = ( + "CREATE TABLE t (x UInt8) ENGINE=Memory; " + "INSERT INTO t VALUES (1), (2); " + "SELECT sum(x) FROM t" + ) + runner = differential_conftest.ClickHouseLocal("/tmp/clickhouse") + + assert runner.run(sql) == "3\n" + assert calls == [ + ( + [ + "/tmp/clickhouse", + "local", + "--query", + f"{sql} FORMAT TabSeparated", + ], + { + "capture_output": True, + "text": True, + "timeout": 60, + }, + ) + ]