Skip to content

Commit 94062de

Browse files
committed
Convert LAG/LEAD negative offsets, POSITION starts, SPLIT_PART column delimiters and GENERATOR constants
Ports the earlier branch fix/d215-lag-lead (pull request 98) onto current main, with its cases and recorded results: - LAG and LEAD with a negative integer literal offset swap direction, except with IGNORE NULLS. - CHARINDEX(s, t, p) and POSITION(s, t, p) find the first match at or after an integer start p, counted from the start of t; a NULL text, needle or start gives NULL. - SPLIT_PART takes a delimiter from a column; an empty delimiter gives the whole text for parts 0, 1 and -1 and empty text otherwise. - GENERATOR takes a ROWCOUNT written as a constant integer expression, NULL and absent arguments, and a literal TIMELIMIT of 1 second or more. The REGEXP_SUBSTR column-argument cases recorded on that branch come with it and stay refused until their conversion lands.
1 parent 041825b commit 94062de

29 files changed

Lines changed: 1094 additions & 89 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
category = "translation"
2+
construct = "sf.functions.position.position"
3+
session_profile = "utc-v1"
4+
5+
[[case]]
6+
id = "t001_empty_needle_start_pos"
7+
description = "An empty needle with a start position, inside, at and past the end of the haystack, with an empty haystack, and with zero and negative starts. Records what POSITION returns for each start."
8+
columns = [{ name = "a", type = "VARCHAR" }, { name = "b", type = "VARCHAR" }, { name = "p", type = "NUMBER(38,0)" }]
9+
rows = [
10+
["''", "'abc'", "1"],
11+
["''", "'abc'", "2"],
12+
["''", "'abc'", "3"],
13+
["''", "'abc'", "4"],
14+
["''", "'abc'", "5"],
15+
["''", "'abc'", "10"],
16+
["''", "''", "2"],
17+
["''", "'abc'", "0"],
18+
["''", "'abc'", "-1"],
19+
]
20+
query = "SELECT POSITION(a, b, p) AS r FROM input ORDER BY ordinal"
21+
order = "ordered"
22+
tags = ["type-combination", "boundary", "empty"]
23+
24+
[[case]]
25+
id = "t002_charindex_empty_needle_start_pos"
26+
description = "The same rows through CHARINDEX(a, b, p)."
27+
columns = [{ name = "a", type = "VARCHAR" }, { name = "b", type = "VARCHAR" }, { name = "p", type = "NUMBER(38,0)" }]
28+
rows = [
29+
["''", "'abc'", "1"],
30+
["''", "'abc'", "2"],
31+
["''", "'abc'", "3"],
32+
["''", "'abc'", "4"],
33+
["''", "'abc'", "5"],
34+
["''", "'abc'", "10"],
35+
["''", "''", "2"],
36+
["''", "'abc'", "0"],
37+
["''", "'abc'", "-1"],
38+
]
39+
query = "SELECT CHARINDEX(a, b, p) AS r FROM input ORDER BY ordinal"
40+
order = "ordered"
41+
tags = ["type-combination", "boundary", "empty"]
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
category = "translation"
2+
construct = "sf.functions.regexp-substr"
3+
session_profile = "utc-v1"
4+
5+
[[case]]
6+
id = "t001_position_zero"
7+
description = "REGEXP_SUBSTR with position 0 and occurrence 1 taken from columns, outside the recorded range. One row per case, since it may raise."
8+
columns = [{ name = "a", type = "VARCHAR" }, { name = "n", type = "NUMBER(38,0)" }, { name = "o", type = "NUMBER(38,0)" }]
9+
rows = [["'a1b2c3d4'", "0", "1"]]
10+
query = "SELECT REGEXP_SUBSTR(a, '[0-9]', n, o) AS r FROM input ORDER BY ordinal"
11+
order = "ordered"
12+
tags = ["type-combination", "boundary"]
13+
14+
[[case]]
15+
id = "t002_position_negative"
16+
description = "REGEXP_SUBSTR with position -1 and occurrence 1 taken from columns, outside the recorded range. One row per case, since it may raise."
17+
columns = [{ name = "a", type = "VARCHAR" }, { name = "n", type = "NUMBER(38,0)" }, { name = "o", type = "NUMBER(38,0)" }]
18+
rows = [["'a1b2c3d4'", "-1", "1"]]
19+
query = "SELECT REGEXP_SUBSTR(a, '[0-9]', n, o) AS r FROM input ORDER BY ordinal"
20+
order = "ordered"
21+
tags = ["type-combination", "boundary"]
22+
23+
[[case]]
24+
id = "t003_position_past_end"
25+
description = "REGEXP_SUBSTR with position 9 and occurrence 1 taken from columns, outside the recorded range. One row per case, since it may raise."
26+
columns = [{ name = "a", type = "VARCHAR" }, { name = "n", type = "NUMBER(38,0)" }, { name = "o", type = "NUMBER(38,0)" }]
27+
rows = [["'a1b2c3d4'", "9", "1"]]
28+
query = "SELECT REGEXP_SUBSTR(a, '[0-9]', n, o) AS r FROM input ORDER BY ordinal"
29+
order = "ordered"
30+
tags = ["type-combination", "boundary"]
31+
32+
[[case]]
33+
id = "t004_position_far_past_end"
34+
description = "REGEXP_SUBSTR with position 20 and occurrence 1 taken from columns, outside the recorded range. One row per case, since it may raise."
35+
columns = [{ name = "a", type = "VARCHAR" }, { name = "n", type = "NUMBER(38,0)" }, { name = "o", type = "NUMBER(38,0)" }]
36+
rows = [["'a1b2c3d4'", "20", "1"]]
37+
query = "SELECT REGEXP_SUBSTR(a, '[0-9]', n, o) AS r FROM input ORDER BY ordinal"
38+
order = "ordered"
39+
tags = ["type-combination", "boundary"]
40+
41+
[[case]]
42+
id = "t005_occurrence_zero"
43+
description = "REGEXP_SUBSTR with position 1 and occurrence 0 taken from columns, outside the recorded range. One row per case, since it may raise."
44+
columns = [{ name = "a", type = "VARCHAR" }, { name = "n", type = "NUMBER(38,0)" }, { name = "o", type = "NUMBER(38,0)" }]
45+
rows = [["'a1b2c3d4'", "1", "0"]]
46+
query = "SELECT REGEXP_SUBSTR(a, '[0-9]', n, o) AS r FROM input ORDER BY ordinal"
47+
order = "ordered"
48+
tags = ["type-combination", "boundary"]
49+
50+
[[case]]
51+
id = "t006_occurrence_negative"
52+
description = "REGEXP_SUBSTR with position 1 and occurrence -1 taken from columns, outside the recorded range. One row per case, since it may raise."
53+
columns = [{ name = "a", type = "VARCHAR" }, { name = "n", type = "NUMBER(38,0)" }, { name = "o", type = "NUMBER(38,0)" }]
54+
rows = [["'a1b2c3d4'", "1", "-1"]]
55+
query = "SELECT REGEXP_SUBSTR(a, '[0-9]', n, o) AS r FROM input ORDER BY ordinal"
56+
order = "ordered"
57+
tags = ["type-combination", "boundary"]
58+
59+
[[case]]
60+
id = "t007_group_zero"
61+
description = "REGEXP_SUBSTR with the 'e' parameter and group 0 taken from a column, outside the pattern's two groups. One row per case, since it may raise."
62+
columns = [{ name = "a", type = "VARCHAR" }, { name = "g", type = "NUMBER(38,0)" }]
63+
rows = [["'k1=v22 k2=v3'", "0"]]
64+
query = "SELECT REGEXP_SUBSTR(a, 'k([0-9])=v([0-9]+)', 1, 1, 'e', g) AS r FROM input ORDER BY ordinal"
65+
order = "ordered"
66+
tags = ["type-combination", "boundary"]
67+
68+
[[case]]
69+
id = "t008_group_past_last"
70+
description = "REGEXP_SUBSTR with the 'e' parameter and group 3 taken from a column, outside the pattern's two groups. One row per case, since it may raise."
71+
columns = [{ name = "a", type = "VARCHAR" }, { name = "g", type = "NUMBER(38,0)" }]
72+
rows = [["'k1=v22 k2=v3'", "3"]]
73+
query = "SELECT REGEXP_SUBSTR(a, 'k([0-9])=v([0-9]+)', 1, 1, 'e', g) AS r FROM input ORDER BY ordinal"
74+
order = "ordered"
75+
tags = ["type-combination", "boundary"]
76+
77+
[[case]]
78+
id = "t009_group_negative"
79+
description = "REGEXP_SUBSTR with the 'e' parameter and group -1 taken from a column, outside the pattern's two groups. One row per case, since it may raise."
80+
columns = [{ name = "a", type = "VARCHAR" }, { name = "g", type = "NUMBER(38,0)" }]
81+
rows = [["'k1=v22 k2=v3'", "-1"]]
82+
query = "SELECT REGEXP_SUBSTR(a, 'k([0-9])=v([0-9]+)', 1, 1, 'e', g) AS r FROM input ORDER BY ordinal"
83+
order = "ordered"
84+
tags = ["type-combination", "boundary"]
85+
86+
[[case]]
87+
id = "t010_anchor_after_start_position"
88+
description = "A ^ anchor with a start position of 2: shows whether ^ anchors at the start position or at the start of the text."
89+
columns = [{ name = "a", type = "VARCHAR" }, { name = "n", type = "NUMBER(38,0)" }]
90+
rows = [["'a1b2'", "2"]]
91+
query = "SELECT REGEXP_SUBSTR(a, '^[0-9]', n) AS r FROM input ORDER BY ordinal"
92+
order = "ordered"
93+
tags = ["type-combination", "boundary"]

‎coverage/sql-size/baseline.json‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@
383383
"fidelity/part_functions.toml#year_of_timestamps~canonical": 893,
384384
"fidelity/position.toml#position_comma": 957,
385385
"fidelity/position.toml#position_comma~canonical": 957,
386+
"fidelity/position.toml#position_from": 1326,
387+
"fidelity/position.toml#position_from~canonical": 1326,
386388
"fidelity/position.toml#position_in": 460,
387389
"fidelity/position.toml#position_in~canonical": 460,
388390
"fidelity/rlike.toml#not_rlike": 363,
@@ -6109,6 +6111,8 @@
61096111
"imported/sqlglot_numeric.toml#trunc_scale_two": 207,
61106112
"imported/sqlglot_numeric.toml#trunc_scale_two_up": 205,
61116113
"imported/sqlglot_relational.toml#order_by_mixed_nulls": 1031,
6114+
"imported/sqlglot_string.toml#charindex_column_start": 1143,
6115+
"imported/sqlglot_string.toml#charindex_negative_start": 573,
61126116
"imported/sqlglot_string.toml#endswith_literal": 164,
61136117
"imported/sqlglot_string.toml#ltrim_rtrim": 508,
61146118
"imported/sqlglot_string.toml#replace_with_replacement": 788,
@@ -8294,9 +8298,13 @@
82948298
"translation/functions/cast.double-colon.toml#t004_precision": 211,
82958299
"translation/functions/cast.double-colon.toml#t005_null_source_expr": 1513,
82968300
"translation/functions/charindex.toml#t001_varchar": 396,
8301+
"translation/functions/charindex.toml#t002_start_pos": 860,
82978302
"translation/functions/charindex.toml#t004_null_expr1": 324,
82988303
"translation/functions/charindex.toml#t005_null_expr2": 321,
82998304
"translation/functions/charindex.toml#t006_empty_needle": 301,
8305+
"translation/functions/charindex.toml#t007_null_start_pos": 733,
8306+
"translation/functions/charindex.toml#t008_start_past_end": 733,
8307+
"translation/functions/charindex.toml#t009_start_zero_negative": 733,
83008308
"translation/functions/chr.toml#t001_number": 748,
83018309
"translation/functions/chr.toml#t002_null_input": 560,
83028310
"translation/functions/chr.toml#t003_negative": 466,
@@ -8476,6 +8484,10 @@
84768484
"translation/functions/flatten.toml#t004_recursive": 2828,
84778485
"translation/functions/flatten.toml#t005_mode": 3003,
84788486
"translation/functions/flatten.toml#t006_null_input": 1592,
8487+
"translation/functions/generator.generator-rowcount.toml#t001_rowcount": 577,
8488+
"translation/functions/generator.generator-rowcount.toml#t003_null_count": 238,
8489+
"translation/functions/generator.generator.toml#t001_no_arguments": 238,
8490+
"translation/functions/generator.generator.toml#t003_null_sec": 238,
84798491
"translation/functions/get-path.colon.toml#t001_paths": 1083,
84808492
"translation/functions/get-path.colon.toml#t002_case": 773,
84818493
"translation/functions/get-path.colon.toml#t003_null_column_identifier": 463,
@@ -8567,6 +8579,7 @@
85678579
"translation/functions/jarowinkler-similarity.toml#t004_empty": 1381,
85688580
"translation/functions/lag.toml#t001_offset_default": 1217,
85698581
"translation/functions/lag.toml#t002_ignore_nulls": 1179,
8582+
"translation/functions/lag.toml#t003_negative_offset": 1167,
85708583
"translation/functions/lag.toml#t004_null_expr": 1166,
85718584
"translation/functions/last-day.toml#t001_date": 291,
85728585
"translation/functions/last-day.toml#t003_timestamp": 330,
@@ -8578,6 +8591,7 @@
85788591
"translation/functions/last-value.toml#t004_null_expr": 691,
85798592
"translation/functions/lead.toml#t001_offset_default": 1218,
85808593
"translation/functions/lead.toml#t002_ignore_nulls": 1180,
8594+
"translation/functions/lead.toml#t003_negative_offset": 1166,
85818595
"translation/functions/lead.toml#t004_null_expr": 1167,
85828596
"translation/functions/least.toml#t001_number": 634,
85838597
"translation/functions/least.toml#t003_varchar": 431,
@@ -8745,14 +8759,20 @@
87458759
"translation/functions/percentile-disc.by.toml#t003_ends": 762,
87468760
"translation/functions/percentile-disc.by.toml#t005_null_order_by_expr": 702,
87478761
"translation/functions/percentile-disc.by.toml#t006_empty_input": 244,
8762+
"translation/functions/position.empty-needle-start.toml#t001_empty_needle_start_pos": 1541,
8763+
"translation/functions/position.empty-needle-start.toml#t002_charindex_empty_needle_start_pos": 1541,
87488764
"translation/functions/position.position-in.toml#t001_varchar": 396,
87498765
"translation/functions/position.position-in.toml#t003_null_expr1": 324,
87508766
"translation/functions/position.position-in.toml#t004_null_expr2": 321,
87518767
"translation/functions/position.position-in.toml#t005_empty_needle": 301,
87528768
"translation/functions/position.position.toml#t001_varchar": 396,
8769+
"translation/functions/position.position.toml#t002_start_pos": 860,
87538770
"translation/functions/position.position.toml#t004_null_expr1": 324,
87548771
"translation/functions/position.position.toml#t005_null_expr2": 321,
87558772
"translation/functions/position.position.toml#t006_empty_needle": 301,
8773+
"translation/functions/position.position.toml#t007_null_start_pos": 733,
8774+
"translation/functions/position.position.toml#t008_start_past_end": 733,
8775+
"translation/functions/position.position.toml#t009_start_zero_negative": 733,
87568776
"translation/functions/pow.power-of-two.toml#t001_whole_exponents": 2278,
87578777
"translation/functions/pow.power-of-two.toml#t002_literal_exponents_in_a_sum": 902,
87588778
"translation/functions/pow.power-of-two.toml#t003_range_edges": 419,
@@ -8851,9 +8871,12 @@
88518871
"translation/functions/sign.toml#t003_float": 380,
88528872
"translation/functions/sign.toml#t004_null": 217,
88538873
"translation/functions/sign.toml#t005_extremes": 484,
8874+
"translation/functions/split-part.toml#t001_varchar": 786,
88548875
"translation/functions/split-part.toml#t002_part_zero": 297,
88558876
"translation/functions/split-part.toml#t003_null_string": 383,
8877+
"translation/functions/split-part.toml#t004_null_delimiter": 590,
88568878
"translation/functions/split-part.toml#t005_null_partnumber": 380,
8879+
"translation/functions/split-part.toml#t006_empty_parts": 776,
88578880
"translation/functions/split-part.toml#t007_out_of_range": 380,
88588881
"translation/functions/split.toml#t001_varchar": 580,
88598882
"translation/functions/split.toml#t002_null_string": 538,

0 commit comments

Comments
 (0)