Repository navigation
Make regexpExtract return the whole match for patterns without a capturing group - #106374
antonio2368 merged 3 commits into
Conversation
…uring group
The two-argument form regexpExtract(haystack, pattern) defaults the group
index to 1. A pattern with no capturing group only has group 0 (the whole
match), so the default 1 is out of range and the function threw
INDEX_OF_POSITIONAL_ARGUMENT_IS_OUT_OF_RANGE instead of returning anything
useful. For example regexpExtract('100-200', '\d+') failed.
When the index is omitted and the pattern has no capturing group, fall back
to group 0 and return the whole match. An explicitly supplied out-of-range
index still throws, and patterns with at least one capturing group keep the
default index 1.
Closes: ClickHouse#56393
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pre-PR validation:
Session: cron:clickhouse-ci-task-worker:20260603-095100 |
|
cc @rschu1ze @antonio2368 — could you review? Small fix so the two-argument |
|
Workflow [PR], commit [1d2730e] Summary: ❌
AI ReviewSummaryThis PR changes the omitted- Final VerdictStatus: ✅ Approve |
The two-argument form `regexpExtract(haystack, pattern)` now uses group `0` when `pattern` has no capturing group and group `1` otherwise. Reflect this conditional default in the registered `FunctionDocumentation` and add a no-capture-group example. Address ClickHouse#106374 (comment)... bot review. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Both bot review points addressed:
Session: cron:clickhouse-ci-task-worker:20260606-123800 |
CI Ledger — covered SHA:
|
| Failure | Classification | Disposition |
|---|---|---|
Stateless tests (arm_asan_ubsan, azure, parallel) / 04033_tpc_ds_q16 (ret=241 MEMORY_LIMIT_EXCEEDED, RSS 53.77 GiB > 53.69 GiB max) |
infra (chronic OOM) | Pre-existing OOM cluster on arm_asan_ubsan + azure + parallel runner: 59 hits / 34 distinct PRs / 42 distinct tests in 30d. Tracked in chronic infra ticket. PR diff is in src/Functions/regexpExtract.cpp only — zero overlap with TPCDS / catalog_sales / OvercommitTracker. |
Stateless tests (arm_asan_ubsan, azure, parallel) / 04049_with_func_alias_in_view (ret=210 NETWORK_ERROR "Connection reset by peer") |
infra (chronic) | Same OOM/runner-pressure cluster; server died from sibling OOM in same runner. |
Stateless tests (arm_asan_ubsan, azure, parallel) / 01661_extract_all_groups_throw_fast (ret=241 MEMORY_LIMIT_EXCEEDED in repeat(), RSS 51.81 GiB; test expects TOO_LARGE_ARRAY_SIZE but runner OOM'd first) |
infra (chronic) | Same OOM cluster. Cross-PR: this exact test failed on PR #93833 (2026-05-31) and now ours — both arm_asan_ubsan azure parallel. Not regexpExtract-related. |
PR-caused failure check: none. PR diff: src/Functions/regexpExtract.cpp (FunctionDocumentation index arg + body update) — has no interaction with repeat() / extractAllGroupsHorizontal memory paths, TPCDS catalog_sales, or with_func_alias_in_view. arm_tidy, all 11 build variants, Fast test, Bugfix validation (FT+IT), Style check, Code Review: all SUCCESS. Stateless tests on every other variant: pass.
Moving to on_review.
| const ColumnString::Offsets & offsets, | ||
| const std::string & pattern, | ||
| ssize_t index, | ||
| bool index_omitted, |
There was a problem hiding this comment.
What do you think about having index as a std::optional<ssize_t> and have something like
ssize_t resolved = index.value_or(capture == 0 ? 0 : 1);There was a problem hiding this comment.
Applied in 1d2730e. The omitted-vs-explicit state is now an std::optional<ssize_t> plumbed through to vectorConstant, and the default rule is index_arg.value_or(capture == 0 ? 0 : 1). Behavior unchanged; both regression tests (02562_regexp_extract, 04305_regexp_extract_no_capture_group) still pass.
Per @antonio2368 review on PR ClickHouse#106374: replace the `bool index_omitted + ssize_t index` pair with `std::optional<ssize_t>` and resolve the conditional default with `value_or(capture == 0 ? 0 : 1)`. Behavior unchanged: a pattern with no capturing group still falls back to group 0 when the third argument is omitted; an explicitly supplied index keeps its current validation. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 29/31 (93.55%) | Lost baseline coverage: none · Uncovered code |
CI Ledger — covered SHA:
|
| Check / Test | Classification | Disposition |
|---|---|---|
Integration tests (arm_binary, distributed plan, 4/4) — test_database_delta/test.py::test_check_database_unity (Spark exec_in_container failure in execute_multiple_spark_queries) |
chronic flaky | Cross-PR query (30d): 7 distinct PRs + 4 master hits. Master signature (head_ref=master): 2026-05-11 01:07Z + 17:41Z Integration tests (arm_binary, distributed plan, 4/4), 2026-05-13 + 2026-06-01 release branches. Same file:line stack signature every time. Unity-catalog test in test_database_delta — fully orthogonal to this PR's regexpExtract.cpp diff. Tracked in task 2026-06-08-ci-p2-chronic-flaky-testdatabasedelta (FOURTH re-emergence; prior closed triages on 2026-04-28, 2026-05-11, 2026-05-25). |
All 11 builds, AST fuzzer (4 variants), BuzzHouse (4 variants), all stress tests, all other integration test variants (amd_asan_ubsan / amd_msan / amd_tsan / amd_llvm_coverage / amd_binary_excluded / arm_binary distributed plan 1-3/4), all functional tests across sanitizers, unit tests (asan/tsan/msan), Style check, Fast test, Bugfix validation, Code Review, LLVM Coverage, SQLLogic, Performance Comparison, Docs check, Compatibility, Install packages, Docker images, Upgrade check: all SUCCESS.
Awaiting reviewer re-review.
758954f
The two-argument form `regexpExtract(haystack, pattern)` now uses group `0` when `pattern` has no capturing group and group `1` otherwise. Reflect this conditional default in the registered `FunctionDocumentation` and add a no-capture-group example. Address ClickHouse#106374 (comment)... bot review. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Per @antonio2368 review on PR ClickHouse#106374: replace the `bool index_omitted + ssize_t index` pair with `std::optional<ssize_t>` and resolve the conditional default with `value_or(capture == 0 ? 0 : 1)`. Behavior unchanged: a pattern with no capturing group still falls back to group 0 when the third argument is omitted; an explicitly supplied index keeps its current validation. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Hi @groeneai @antonio2368 — while reviewing this PR I found the following:
Could you review the test PR and add the |
test_check_database_unity (and other test_database_delta tests that call execute_spark_query) is chronically flaky: the spark-sql invocation occasionally hangs for the full 600s timeout and the test fails with subprocess.TimeoutExpired. Root cause, from a jstack thread dump captured by the existing hang diagnostics (PR ClickHouse#104801) on a CI failure (PR ClickHouse#106374, Integration tests (arm_binary, distributed plan, 4/4)): the Spark main thread parks for the whole timeout inside the Unity Catalog Java client: jdk.internal.net.http.HttpClientImpl.send io.unitycatalog.client.api.SchemasApi.getSchema io.unitycatalog.spark.UCProxy.loadNamespaceMetadata SupportsNamespaces.namespaceExists CreateNamespaceExec.run <- first CREATE SCHEMA The UC client uses the JDK HttpClient with no per-request timeout, so a single transient stall hangs forever. The hang is transient, not a UC outage: in the same run the UC liveness probe answered in 7.8ms with http_code 500, Ivy dependency resolution succeeded in 396ms (so this is not a package-download problem), and the very next test (test_multiple_schemes_tables, same CREATE SCHEMA path) ran 17s later and passed in under a second once the stuck JVM was killed. Retry the Spark invocation with a fresh JVM when it hangs. Only the timeout is retried; real query errors are re-raised immediately. Per-attempt timeout is 300s and at most two attempts are made, keeping the worst case within the 900s per-test pytest limit. The retry is opt-in (retry_on_timeout, default False) because the pkill + metastore cleanup preamble does not reset Unity Catalog or Delta committed state: blindly re-running a multi-statement batch that already committed an earlier statement could fail on "already exists" or duplicate INSERT rows. Non-idempotent callers keep the original single-attempt behavior. test_check_database_unity opts in after being made idempotent (CREATE SCHEMA/TABLE IF NOT EXISTS, INSERT OVERWRITE), so a fresh-JVM retry after a partial commit converges to the same final state. The test asserts only table count and CHECK DATABASE, so OVERWRITE vs INSERT changes no assertion. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The two-argument form
regexpExtract(haystack, pattern)defaults the group index to 1. A pattern with no capturing group only has group 0 (the whole match), so the default index 1 was out of range and the function threwINDEX_OF_POSITIONAL_ARGUMENT_IS_OUT_OF_RANGEinstead of returning anything useful. For exampleregexpExtract('100-200', '\d+')failed.Now, when the index is omitted and the pattern has no capturing group, the function falls back to group 0 and returns the whole match. An explicitly supplied out-of-range index still throws, and patterns with at least one capturing group keep the default index 1.
Closes: #56393
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
regexpExtract(haystack, pattern)so that patterns without a capturing group return the whole match instead of throwingINDEX_OF_POSITIONAL_ARGUMENT_IS_OUT_OF_RANGE.Documentation entry for user-facing changes
Version info
26.6.1.537