Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmarks/duckshop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ project and does not change it:
(`sql/models/intermediate/edge_cases/_sqlbuild/_hooks/sql/`) and SQLBuild does not declare.

It has 174 models (13 staging, 144 intermediate, 17 marts), 5 Python functions, a SQL table
function, a hook-created JavaScript function, 200 unit tests and 5 scenarios, in nine groups:
function, a hook-created JavaScript function, 203 unit tests and 5 scenarios, in nine groups:

| Group | Covers |
|-------|--------|
Expand All @@ -134,7 +134,7 @@ function, a hook-created JavaScript function, 200 unit tests and 5 scenarios, in
| 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"))` |
| 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; `DATEADD` past the end of a test's open cursor window, in a chained test whose upstream step lists some of its columns; a cursor window that touches no row, expected as an empty fixture; `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 |
| 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, and a scoped SQL macro collapsing whitespace whose body opens with a block comment and holds a line comment; a scoped SQL macro, `horner_ratio`, whose body nests polynomials in a subquery item without an alias, which a second `sqb format` leaves unchanged; `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 |
| 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 |
| 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; an expected CTE that joins and filters through `__ref()` of the mocked model |
| 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 |
| 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 timestamp snapshot whose `updated_at` is a `DATE`, so its validity columns are `DATE` too; a cursor-window incremental model over far-apart fixture loads; a rolling-window microbatch model whose full refresh covers its `cursor_start` through the current day; a change log merged across two loads, checked against a full rebuild, a keyed cursor `delete_insert` copy of it whose rows move out of the window between loads, and a cursor `delete_insert` copy of every version that `replace_key` replaces per shipment |
| 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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
TEST (name "int_edge_check_group_flags__expected_rows_read_the_mocked_checks");

WITH __ref__stg_edge_amount_checks AS (
SELECT
v.check_id::VARCHAR AS check_id,
v.group_code::VARCHAR AS group_code,
v.narrow_key::NUMBER(18, 0) AS narrow_key,
v.wide_key::NUMBER(38, 0) AS wide_key,
v.key_text::VARCHAR AS key_text,
v.amount::NUMBER(18, 2) AS amount,
v.ratio::FLOAT AS ratio
FROM VALUES
('AC-01', 'G-1', 7, 7, '101,7', 10.05, 0.1),
('AC-02', 'G-1', 12, 12, '2026-03-04', -0.55, 0.2),
('AC-03', 'G-2', 3, NULL, '7', 0.00, 0.3),
('AC-04', 'G-2', NULL, 40, NULL, NULL, NULL) AS v(check_id, group_code, narrow_key, wide_key, key_text, amount, ratio)
),

group_flags AS (
SELECT
v.group_code,
v.is_unpaid_group
FROM VALUES ('G-1', FALSE), ('G-2', TRUE) AS v(group_code, is_unpaid_group)
),

__expected__int_edge_check_group_flags AS (
SELECT
c.check_id,
g.is_unpaid_group
FROM __ref("stg_edge_amount_checks") AS c
INNER JOIN group_flags AS g
ON g.group_code = c.group_code
WHERE c.check_id IN (
SELECT a.check_id FROM __ref("stg_edge_amount_checks") AS a
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ pub(crate) fn shared_parsed(sql: &str, dialect: Dialect) -> Result<Parsed, Parse
},
StrictFailure::Parse(error)
| StrictFailure::Tokens(TokenizeFailure::Tokenizer(error)) => {
let offset: usize = error.start().unwrap_or_default();
let offset: usize = error.start().map_or(0, |characters| {
sql.char_indices()
.nth(characters)
.map_or(sql.len(), |(byte, _)| byte)
});
let message: String = unplaced(error);
ParserGap {
construct: message.clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::analysis_route::main::analysis_route::analysis_route;
use crate::analysis_route::main::native_gap::native_gap;
use crate::analysis_route::main::skipped_analysis::skipped_analysis;
use crate::analysis_route::models::{AnalysisRoute, GapPosition, GapSite, LocatedGap, TsqlDialect};
use crate::analysis_route::models::{
AnalysisRoute, GapPosition, GapSite, LocatedGap, SnowflakeDialect, TsqlDialect,
};
use crate::analysis_route::tests::test_types::{
NativeGapTestCase, PivotlessDialect, RouteTestCase, SkippedAnalysisTestCase, TsqlParseTestCase,
TsqlTypeTestCase,
Expand Down Expand Up @@ -192,6 +194,44 @@ fn given_model_sql_when_probing_the_native_parser_then_its_gap_is_located_after_
}
}

#[test]
fn given_multibyte_snowflake_text_when_probing_then_the_gap_column_counts_characters() {
let unexpected_eq = |column: usize, source_offset: usize| LocatedGap {
construct: "Unexpected token: Eq".to_owned(),
message: "Unexpected token: Eq".to_owned(),
line: 1,
column,
syntax: false,
source_offset: Some(source_offset),
};
let test_cases = [
NativeGapTestCase {
description: "ASCII text before the error",
sql: "SELECT 'grosse' AS label FROM orders WHERE row_key = = 1",
placeholders: &[],
expected_gap: Some(unexpected_eq(54, 53)),
},
NativeGapTestCase {
description: "multibyte text before the error, one character shorter",
sql: "SELECT 'größé' AS label FROM orders WHERE row_key = = 1",
placeholders: &[],
expected_gap: Some(unexpected_eq(53, 52)),
},
];
for test_case in test_cases {
let check = SyntaxCheck {
sql: test_case.sql.to_owned(),
placeholders: Vec::new(),
};
assert_eq!(
native_gap(&SnowflakeDialect, &check),
Ok(test_case.expected_gap),
"{}",
test_case.description
);
}
}

#[test]
fn given_a_located_gap_when_skipping_analysis_then_p026_names_the_model_its_site_and_the_gap() {
let test_cases = [
Expand Down
Loading
Loading