Skip to content

Convert REGEXP_SUBSTR with a computed position, occurrence or group - #112

Closed
kvlonge wants to merge 3 commits into
fix/d215-lag-leadfrom
fix/d215-regexp-columns
Closed

kvlonge wants to merge 3 commits into
fix/d215-lag-leadfrom
fix/d215-regexp-columns

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #98 (fix/d215-lag-lead); review this diff against that branch.

What changes

REGEXP_SUBSTR now converts when its position, occurrence or group is computed (a column or expression), not only a literal (regexp_substr_computed). It follows A's receipts (regexp-substr.column-arguments, already on #98):

  • A NULL argument gives NULL.
  • A position or occurrence below 1, or a negative group, raises 100050 (SQLSTATE 22023). That is a new known Snowflake error of kind InvalidArgument: INVALID_PARAMETER_VALUE / REGEXP_PARAMETER_FAILURES in sqlquack-core.
  • A start past the end gives NULL, and ^ anchors at the start position.
  • Group 0 is the whole match, and a group past the pattern's last gives NULL.
  • A word boundary after a start position is refused, since no recording shows it. Parameters still need a text literal.

Evidence

The D94 gate runs on the landing head after #98 lands.

Review fix (f8a7eac)

On the computed path, a pattern that matches empty text now raises regexp_pattern_syntax, as REGEXP_COUNT and REGEXP_INSTR do. The receipts cover a start at or past the end only for patterns that can't match empty text. All 15 recorded cases still match, and the other 12 REGEXP_SUBSTR case files are unchanged (178 cases, 0 failed).

Follow-ups

  • The computed path declares the regexp_pattern_syntax divergence for every pattern. Since the pattern is a literal, conversion could decide whether it matches empty text and skip the divergence when it can't.
  • A receipt for an empty-matching pattern at p = length + 1 would let the raise be lifted.

Read as A's receipts (regexp-substr.column-arguments) record: NULL
gives NULL; a position or occurrence below 1 or a negative group raises
100050 (22023), now a known Snowflake error of kind InvalidArgument; a
start past the end gives NULL; ^ anchors at the start position; group
0 is the whole match and a group past the pattern's last gives NULL.
A word boundary after a start position is refused, since no recording
shows it. Parameters still need a text literal.

regexp-substr t002, t003, t007, t008, t010 and column-arguments
t001-t010 now match; t009 (parameters from a column) stays refused.
Against #98's baseline (4ce4490): 0 regressions, 15 statements
refused -> matching; no form changes. verify-recorded: 11606 cases,
7671 passed, 0 failed, 220 of 220 verified.
A start at or past the end leaves empty text, where DuckDB finds an
empty match ('' for x*) and Snowflake's result is unrecorded: the
receipts cover p = length + 1 and beyond only with a pattern that cannot
match empty text. Such a pattern now raises regexp_pattern_syntax on
this path, as REGEXP_COUNT and REGEXP_INSTR already do. The 15 recorded
cases still match; the other 12 REGEXP_SUBSTR case files are unchanged
(178 cases, 0 failed).
kvlonge added a commit that referenced this pull request Nov 6, 2026
'x*' on 'abc' at positions 3, 4 and 5, for #112's position handling.

kvlonge commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing: SQLQuack lands through local-gate trains, not PR merges (D94), so open PRs only add clutter (D628/D630). The branch is kept. Any work here that isn't on main yet is tracked by the train owner and lands through a train.

@kvlonge kvlonge closed this Nov 8, 2026
kvlonge added a commit that referenced this pull request Nov 9, 2026
D591's function conversion moves into sqlquack-convert's Snowflake
analysis, beside analyze and analyze_function, with this branch's crate
paths.
@kvlonge
kvlonge deleted the fix/d215-regexp-columns branch November 9, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant