Skip to content

Commit 4e15ae9

Browse files
committed
test(duckshop): add an edge case for relations aliased first and last
A bare FIRST or LAST after a joined relation is its alias. The case joins one relation aliased with AS and one without, and checks on Snowflake that each alias names its own relation.
1 parent 2cad984 commit 4e15ae9

3 files changed

Lines changed: 98 additions & 3 deletions

File tree

‎benchmarks/duckshop/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ project and does not change it:
124124
`edge_running_peaks`, that a pre-hook of `int_edge_basket_running_peaks` creates
125125
(`models/intermediate/edge_cases/_sqlbuild/_hooks/sql/`) and SQLBuild does not declare.
126126

127-
It has 166 models (13 staging, 139 intermediate, 14 marts), 5 Python functions, a SQL table
128-
function, a hook-created JavaScript function, 191 unit tests and 4 scenarios, in nine groups:
127+
It has 167 models (13 staging, 140 intermediate, 14 marts), 5 Python functions, a SQL table
128+
function, a hook-created JavaScript function, 192 unit tests and 4 scenarios, in nine groups:
129129

130130
| Group | Covers |
131131
|-------|--------|
@@ -134,7 +134,7 @@ function, a hook-created JavaScript function, 191 unit tests and 4 scenarios, in
134134
| VARIANT comparisons | `ARRAY_MAX`, `ARRAY_MIN` and `ARRAY_REVERSE` over arrays mixing numbers, strings, booleans, JSON nulls and integers past 2^53; `MAX` across kinds and non-ASCII strings; `=` and `EQUAL_NULL` for `1`, `"1"` and `1.0`, reordered keys, JSON null and DATE or TIMESTAMP values held in a `VARIANT` against their text; `MIN_BY` and `MAX_BY` of `VARIANT` values; `PARTITION BY`, `SELECT DISTINCT` and `ARRAY_AGG(DISTINCT)` over `VARIANT`; JSON nulls in `ARRAY_REMOVE`, `ARRAY_DISTINCT` and `ARRAYS_OVERLAP`; decimals with trailing zeros in `ARRAY_CONTAINS` and `ARRAY_POSITION`; `OBJECT_CONSTRUCT(* EXCLUDE ("note"))` |
135135
| Dates and times | `TRY_TO_TIMESTAMP_NTZ` and its siblings over free text; epoch milliseconds as numbers and text; daylight-saving gaps and overlaps; fractional offsets; nanosecond truncation and epoch parts after 2242; pre-1970 text with sub-microsecond digits; date-part normalisation; month ends and leap days; week numbering across a year; sentinel timestamps; `TRY_TO_DATE` with numeric and month-name formats over unpadded fields, two-digit years, ISO `T` and `Z`, trailing letters, a long s, mixed separators and runs of spaces; text read as `TIMESTAMP_TZ` and `TIMESTAMP_LTZ` with `T`, `Z`, `+00:00`, `+0000`, `+09:00` and `-05:30`, back as the UTC instant, date, year and day start, and compared with text, `TIMESTAMP_NTZ` and `DATE`; `FIRST_VALUE` of a zoned value as a `DATE`; `DATEADD` and `TIMEADD` on `TIME(3)` and the type they return; `DATEDIFF` across units; `TIME(9)`, `FF3` and bare `FF` formats truncating; `DATE`, `TO_TIME`, `TRY_TO_TIMESTAMP` and `TO_TIMESTAMP_LTZ` of clock text, and `CURRENT_DATE` and `SYSDATE` read only for facts that hold on any day |
136136
| Ordering, numbers and text | NULL ordering under `DESC`; ties in ordered aggregates, `MAX_BY`, `MODE` and `ANY_VALUE`; default window frames; `UNION ALL BY NAME`; `ROUND` half-way values, decimal division, `MOD` and 38-digit amounts; integers past 2^53 against `FLOAT`; regular expressions and backslash escapes; `LIKE ... ESCAPE` and `ILIKE ANY`; `SPLIT_PART` and `SUBSTR` before the start; `NOT IN` with a NULL; names in many scripts; `JOIN ... USING` between `NUMBER(18,0)`, `NUMBER(38,0)` and text keys, with the types of the merged and qualified keys; NULL arithmetic and the types of NULL, decimal and exponent literals, `COUNT`, `ROW_NUMBER`, `%` and `NULLIF`; `MEDIAN` at scales 0 to 15; `DIV0` by literal zeros; `MODE`, `MEDIAN` and `COUNT_IF` over no rows; aggregates inside window functions and `QUALIFY`; `ROLLUP` totals; `TRUNC` of `FLOAT`; infinity words in other scripts; `CASE` without `ELSE` and `DECODE` over text; regular expressions with a `?` after a lazy quantifier, classes opening with `]`, empty matches and `.` against a carriage return; case-insensitive matches outside ASCII; `ILIKE` with a long s; `JAROWINKLER_SIMILARITY` of accented names in both cases; Base64 text with line feeds; `STARTSWITH`, `ENDSWITH`, `SUBSTRING`, `POSITION` with `IN` and with a comma, `CHARINDEX`, `CHR`, `REGEXP_SUBSTR_ALL`, `::STRING` and `CAST ... AS STRING`; `HEX_ENCODE`, `HEX_DECODE_STRING`, `TRY_HEX_DECODE_STRING` and `TRY_BASE64_DECODE_BINARY`; a comment attached to a text literal; `FLOOR` with and without a scale, `BITAND`, `ZEROIFNULL`, `::BIGINT` and `::DOUBLE`; `IS NOT DISTINCT FROM` and `EQUAL_NULL`; a comma join after an explicit join; `HASH_AGG` read in two row orders |
137-
| Lineage and analysis | clauses whose columns decide rows without being output (`WHERE`, `QUALIFY`, `GROUP BY` by position and `ALL`, `ORDER BY` under `LIMIT`, `EXISTS`, a `FLATTEN` input, `ROLLUP` by position, `EXCEPT` under `LIMIT`); `RIGHT JOIN ... USING`, `NATURAL JOIN`, a `USING` key under a later outer join, and unmatched `ASOF JOIN` rows; `CONNECT BY` beside a column named `level`; a recursive CTE without `RECURSIVE` whose columns shift per iteration; `LAST_DAY` with a date part; positional columns and the names Snowflake gives unaliased expressions; `TEXT(5)` and widened `COUNT` contracts; `LAG` and `LEAD` with one, two and three arguments; a comma-joined `LATERAL` whose nested derived table reads the left item; untyped and typed `FILTER` lambdas over `ARRAY_AGG` in a grouped query; column expression ranges in compiled SQL that SQL and Python macros, a variable and cursor bounds rewrote, and columns qualified by their reference call, whose ranges are dropped |
137+
| Lineage and analysis | clauses whose columns decide rows without being output (`WHERE`, `QUALIFY`, `GROUP BY` by position and `ALL`, `ORDER BY` under `LIMIT`, `EXISTS`, a `FLATTEN` input, `ROLLUP` by position, `EXCEPT` under `LIMIT`); `RIGHT JOIN ... USING`, `NATURAL JOIN`, a `USING` key under a later outer join, and unmatched `ASOF JOIN` rows; `CONNECT BY` beside a column named `level`; a recursive CTE without `RECURSIVE` whose columns shift per iteration; `LAST_DAY` with a date part; positional columns and the names Snowflake gives unaliased expressions; `TEXT(5)` and widened `COUNT` contracts; `LAG` and `LEAD` with one, two and three arguments; a comma-joined `LATERAL` whose nested derived table reads the left item; relations aliased `first` and `last`, one without `AS`, the words of Snowflake's read-order clauses; untyped and typed `FILTER` lambdas over `ARRAY_AGG` in a grouped query; column expression ranges in compiled SQL that SQL and Python macros, a variable and cursor bounds rewrote, and columns qualified by their reference call, whose ranges are dropped |
138138
| Python functions | volatile tokens and numbers from a column, a constant and no argument, and `DIV0` of a volatile call beside look-alike names, checked by assertions that hold for any values; a handler answering NULL input without `STRICT`; Python `None` as JSON null, and datetimes, Decimals and integers past 2^53 handed to `VARIANT` and `FLOAT` results |
139139
| Scenarios and lifecycle | typed values across model boundaries; `VARIANT` expected output; a star under a lower-case contract and a quoted camelCase export; a snapshot keyed and compared on quoted camelCase columns; a cursor-window incremental model over far-apart fixture loads; a change log merged across two loads, checked against a full rebuild |
140140
| Translation refusals | one model per construct that translation tools refuse or guard, most putting a construct refused only under strict checking before one refused by default, so a model shows both: `FLOAT` values through sums, averages, running totals, arrays, objects, `HASH`, `TO_CHAR` and `::NUMBER(38, 10)`; `VARIANT` dates, decimals and XML; `ARRAY_AGG` without `WITHIN GROUP`, sparse arrays and `ARRAY(NUMBER)` casts; `REDUCE`, `FILTER` and `TRANSFORM` lambdas; patterns and `REGEXP_REPLACE` replacements built from columns, and lazy patterns; `TRY_TO_DATE` with a format from a column; zoned literals, `CONVERT_TIMEZONE` from `CURRENT_TIMESTAMP`, `SEQ8`, `GENERATOR` with an expression `ROWCOUNT`; `PIVOT`, `ANY_VALUE`, `IGNORE NULLS` around `IFF`, unaliased columns read by Snowflake's name, `UNION` branches whose column is always NULL; `TO_NUMBER`, `TO_DECIMAL` and `TRY_BASE64_DECODE_BINARY`; an open (uncontracted) source `edge__supplier_notes`, the table function, read for one basket and after `LATERAL` for every basket, and the hook-created function. `rpt_edge_case_model_keys` and `rpt_edge_case_array_model_keys` read every model in the group, so a refusal there also refuses a downstream model |
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
MODEL (
2+
description """
3+
One row per amount check with its group name read through relations aliased first and last, the
4+
words of Snowflake's read-order clauses: each alias names its relation, so neither join is
5+
unused, and a condition on the last relation decides which of its rows match
6+
""",
7+
tags [edge_case],
8+
columns (
9+
check_id (type VARCHAR, nullable false, audits [not_null, unique]),
10+
first_group_name (type VARCHAR),
11+
last_group_name (type VARCHAR),
12+
),
13+
);
14+
15+
WITH checks AS (
16+
SELECT
17+
c.check_id,
18+
c.group_code
19+
FROM __ref("stg_edge_amount_checks") AS c
20+
),
21+
22+
group_names AS (
23+
SELECT
24+
v.group_code,
25+
v.group_name
26+
FROM VALUES ('G-1', 'Mallard desk'), ('G-2', 'Teal desk') AS v(group_code, group_name)
27+
),
28+
29+
final AS (
30+
SELECT
31+
c.check_id::VARCHAR AS check_id,
32+
first.group_name::VARCHAR AS first_group_name,
33+
last.group_name::VARCHAR AS last_group_name
34+
FROM checks AS c
35+
LEFT JOIN group_names AS first ON c.group_code = first.group_code
36+
LEFT JOIN group_names last
37+
ON c.group_code = last.group_code
38+
AND last.group_name <> 'Teal desk'
39+
)
40+
41+
SELECT *
42+
FROM final
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
TEST (name "int_edge_first_last_aliases__reads_each_group_name_through_its_aliased_relation");
2+
3+
WITH __ref__stg_edge_amount_checks AS (
4+
SELECT
5+
v.check_id,
6+
v.group_code,
7+
v.narrow_key::NUMBER(18, 0) AS narrow_key,
8+
v.wide_key::NUMBER(38, 0) AS wide_key,
9+
v.key_text,
10+
v.amount::NUMBER(18, 2) AS amount,
11+
v.fine_amount::NUMBER(20, 15) AS fine_amount,
12+
v.ratio::FLOAT AS ratio,
13+
v.json_text
14+
FROM VALUES
15+
('AC-01', 'G-1', 7, '7', '01', 10.00, 0.123456789012345, 0.29, NULL),
16+
('AC-02', 'G-1', 12, '12345678901234567890123', '1', -0.50, 0.123456789012344, 1.005, NULL),
17+
('AC-03', 'G-1', NULL, '12', '12', 2.50, 0.5, 2.675, NULL),
18+
('AC-04', 'G-2', 123456789012345678, '123456789012345678', ' 7', 0.00, 1, -155.5, NULL),
19+
('AC-05', 'G-2', 99, NULL, NULL, NULL, NULL, NULL, NULL),
20+
('AC-06', 'G-3', 5, '5', 'n/a', 999999999999.99, 0.000000000000001, 0.57, NULL) AS v(check_id, group_code, narrow_key, wide_key, key_text, amount, fine_amount, ratio, json_text)
21+
),
22+
23+
__expected__int_edge_first_last_aliases AS (
24+
SELECT
25+
'AC-01' AS check_id,
26+
'Mallard desk' AS first_group_name,
27+
'Mallard desk' AS last_group_name
28+
UNION ALL
29+
SELECT
30+
'AC-02' AS check_id,
31+
'Mallard desk' AS first_group_name,
32+
'Mallard desk' AS last_group_name
33+
UNION ALL
34+
SELECT
35+
'AC-03' AS check_id,
36+
'Mallard desk' AS first_group_name,
37+
'Mallard desk' AS last_group_name
38+
UNION ALL
39+
SELECT
40+
'AC-04' AS check_id,
41+
'Teal desk' AS first_group_name,
42+
CAST(NULL AS VARCHAR) AS last_group_name
43+
UNION ALL
44+
SELECT
45+
'AC-05' AS check_id,
46+
'Teal desk' AS first_group_name,
47+
CAST(NULL AS VARCHAR) AS last_group_name
48+
UNION ALL
49+
SELECT
50+
'AC-06' AS check_id,
51+
CAST(NULL AS VARCHAR) AS first_group_name,
52+
CAST(NULL AS VARCHAR) AS last_group_name
53+
)

0 commit comments

Comments
 (0)