Skip to content

Add test: Out-of-range index throw in refactored vectorConstant (non-const haystack + const index) is untested - #106819

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr106374
Jun 11, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr106374

Conversation

@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

This is a test-only PR — no source code changes. Please review: test quality, whether the claimed coverage gaps are real, and whether test output makes sense.

Adds test coverage for 1 untested code path(s), found during automated review of PR #106374.
That PR (1) The PR makes regexpExtract(haystack, pattern) (two-arg form) default the group index to 0 (whole match) when pattern has no capturing group, instead of 1 (which was out-of-range and threw INDEX_OF_POSITIONAL_ARGUMENT_IS_OUT_OF_RANGE). The change is localized to vectorConstant, whose

1. Out-of-range index throw in refactored vectorConstant (non-const haystack + const index) is untested
src/Functions/regexpExtract.cpp:144
Risk: Call chain: executeImpl (line 96, non-const haystack + const index, isColumnConst true) -> vectorConstant -> index = index_arg.value_or(...) (line 143, refactored) -> if (index < 0 || index >= capture + 1) throw (line 144). The PR refactored exactly this function but its out-of-range test uses a const haystack, which useDefaultImplementationForConstants folds into the vectorVector path instead. RISK: if the refactor regressed the bounds check, an explicit out-of-range index on …
What's unique vs PR tests: The PR's out-of-range assertion regexpExtract('100-200', '\d+', 1) uses a const haystack, which useDefaultImplementationForConstants folds into the vectorVector path (throw at line 196). This test uses a materialized (non-const) haystack with a const index, the only input shape that reaches the vectorConstant throw at lines 144-146 — the function the PR actually refactored — which the LLVM report confirms is otherwise uncovered.
Try it on ClickHouse Fiddle

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not applicable — test-only change.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickgapai

Copy link
Copy Markdown
Contributor Author

Pre-PR Validation Gate (per ClickGap pipeline):

a) Deterministic repro? ✅
Test deterministically exercises the previously-uncovered branch and passes (correct behaviour). Confirmed across runs.

b) Root cause explained? ✅
src/Functions/regexpExtract.cpp:144-146 — if (index < 0 || index >= capture + 1) throw Exception(INDEX_OF_POSITIONAL_ARGUMENT_IS_OUT_OF_RANGE, ...) inside vectorConstant, reachable only via non-const haystack + const index, is untested across the whole suite.

c) Fix matches root cause? ✅
N/A for coverage gap — this PR adds a regression test, not a fix. Asserts current correct behaviour at the cited line.

d) Test intent preserved? / New tests added? ✅
New regression test added: 04308_regexp_extract_vector_constant_oob.sql.

e) Both directions demonstrated? ✅
Test passes (MATCH) on master proving current correctness; would fail if the cited branch regressed. Single-direction is the correct shape for a coverage gap test.

f) Fix is general, not a narrow patch? ✅
Test asserts the invariant at the cited line — covers the branch, not a specific input shape.

@antonio2368 antonio2368 added the can be tested Allows running workflows for external contributors label Jun 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [92d42b3]

Summary: ✅


AI Review

Summary

This test-only PR adds focused stateless coverage for regexpExtract out-of-range index handling when the haystack is non-constant and the index is constant, which dispatches through vectorConstant. The added assertions match the PR motivation and complement the existing constant-haystack and vector-index coverage. I did not find any review findings requiring inline comments.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.20% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 395 line(s), 25 function(s) across 126 file(s) · Details

Top files
  • src/Databases/DataLake/HiveCatalog.cpp: 51 line(s), 11 function(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 14 line(s)
  • src/Databases/DataLake/DatabaseDataLake.cpp: 12 line(s)
  • src/Databases/DatabaseFactory.cpp: 11 line(s)
  • src/IO/S3/copyS3File.cpp: 10 line(s)

Full report

@groeneai

Copy link
Copy Markdown
Collaborator

LGTM. Verified the coverage gap is real.

Dispatch in regexpExtract.cpp executeImpl:

  • const haystack -> constantVector (throw at L235)
  • non-const haystack + const/omitted index -> vectorConstant (bounds check + throw at L138-145)
  • non-const haystack + non-const index -> vectorVector (throw at L190)

useDefaultImplementationForConstants() only unwraps arguments when they are all constant, so the existing all-const-literal OOB asserts in 02562_regexp_extract (e.g. regexpExtract('100-200', '(\d+)-(\d+)', 3)) fold into the vectorVector path, not vectorConstant. materialize(haystack) with a const index is the only input shape that reaches the vectorConstant bounds check, and there was no prior test for it. So the report is accurate: that branch (the one PR #106374 refactored) was uncovered.

Ran the queries on a 26.6 debug build: output matches the committed .reference exactly. The 3 out-of-range cases throw INDEX_OF_POSITIONAL_ARGUMENT_IS_OUT_OF_RANGE, and the index-0 cases return the whole match (100-200 and 100). The error-context column descriptors confirm the throws come from vectorConstant (non-const String haystack + const index), not the folded path.

Test is correct and the can be tested label is already applied. Good catch.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 11, 2026
Merged via the queue into ClickHouse:master with commit ba3e30d Jun 11, 2026
166 of 167 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants