Skip to content

Commit 596399e

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/count-star-modifiers
2 parents 144dc45 + 05c97e7 commit 596399e

60 files changed

Lines changed: 1720 additions & 82 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ A `VALUES` list of more than 1,000 rows is refused for now.
107107
session parameters yet and convert under `utc-v1`.
108108

109109
`convert`, `function`, `census` and `index` read `sqlquack.toml` (or `--policy`); without one they
110-
exit 2 unless `--builtin-policy` asks for the built-in default, which refuses every known divergence.
110+
use the built-in policy, which refuses every known divergence, as `--builtin-policy` asks for.
111111
They share the policy flags (`--policy`, `--builtin-policy`, `--strict`, `--utc-session`,
112112
`--confirm-declared-offsets`, `--python-runtime` and `--loud-divergences-only`, which relies only
113113
on divergences whose converted SQL raises rather than returns another value). Every command with a report takes
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
category = "translation"
2+
construct = "sf.functions.flatten"
3+
session_profile = "utc-v1"
4+
5+
[[case]]
6+
id = "t001_object_under_path"
7+
description = "PATH reaching an object: one row per key, with KEY, VALUE and a PATH prefixed with the given path, for a plain key and one with a space. Catches: the prefix joined without a dot, or a quoted key written as a plain one"
8+
columns = [{ name = "a", type = "VARCHAR" }]
9+
rows = [
10+
["'{\"x\":{\"y\":{\"b\":1,\"a c\":2}}}'"],
11+
]
12+
query = "SELECT i.ordinal, f.key, f.index, f.value, f.path FROM input i, LATERAL FLATTEN(INPUT => PARSE_JSON(i.a), PATH => 'x.y') f ORDER BY i.ordinal, f.key"
13+
order = "ordered"
14+
tags = ["type-combination"]
15+
16+
[[case]]
17+
id = "t002_path_key_case"
18+
description = "PATH keys match case-sensitively: 'Items' finds nothing where the key is items, and one-step 'items' reaches the array. Catches: keys matched ignoring case"
19+
columns = [{ name = "a", type = "VARCHAR" }]
20+
rows = [
21+
["'{\"items\":[10,20]}'"],
22+
]
23+
query = "SELECT 'lower' AS k, f.index, f.value, f.path FROM input i, LATERAL FLATTEN(INPUT => PARSE_JSON(i.a), PATH => 'items') f UNION ALL SELECT 'upper', f.index, f.value, f.path FROM input i, LATERAL FLATTEN(INPUT => PARSE_JSON(i.a), PATH => 'Items') f ORDER BY 1, 2"
24+
order = "ordered"
25+
tags = ["type-combination"]
26+
27+
[[case]]
28+
id = "t003_scalar_and_null_at_path"
29+
description = "PATH reaching a scalar, a JSON null and an empty array gives no rows. Catches: a scalar flattened into one row, or a JSON null giving a row"
30+
columns = [{ name = "a", type = "VARCHAR" }]
31+
rows = [
32+
["'{\"x\":5}'"],
33+
["'{\"x\":null}'"],
34+
["'{\"x\":[]}'"],
35+
["'{\"x\":[7]}'"],
36+
]
37+
query = "SELECT i.ordinal, f.index, f.value, f.path FROM input i, LATERAL FLATTEN(INPUT => PARSE_JSON(i.a), PATH => 'x') f ORDER BY i.ordinal, f.index"
38+
order = "ordered"
39+
tags = ["type-combination"]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
category = "translation"
2+
construct = "sf.functions.pow.power"
3+
session_profile = "utc-v1"
4+
5+
[[case]]
6+
id = "t001_whole_exponents"
7+
description = "POWER(2, n) for whole exponents from -52 to 64, as dbt_utils.date_spine writes it for each bit. Catches: an inexact power of two, an integer result, or a lost low bit past 2^53"
8+
columns = [{ name = "n", type = "NUMBER(38,0)" }]
9+
rows = [
10+
["0"], ["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"], ["11"],
11+
["31"], ["32"], ["52"], ["53"], ["62"], ["63"], ["64"],
12+
["-1"], ["-2"], ["-52"],
13+
]
14+
query = "SELECT POWER(2, n) AS r FROM input ORDER BY ordinal"
15+
order = "ordered"
16+
tags = ["type-combination"]
17+
18+
[[case]]
19+
id = "t002_literal_exponents_in_a_sum"
20+
description = "The dbt_utils.date_spine shape: a NUMBER times POWER(2, k) for literal k, summed, plus 1. Catches: the result typed NUMBER instead of FLOAT, or a power other than 2^k"
21+
columns = [{ name = "a", type = "NUMBER(38,0)" }, { name = "b", type = "NUMBER(38,0)" }]
22+
rows = [
23+
["0", "0"],
24+
["1", "0"],
25+
["1", "1"],
26+
["NULL", "1"],
27+
]
28+
query = "SELECT a * POWER(2, 0) + b * POWER(2, 1) + 1 AS r FROM input ORDER BY ordinal"
29+
order = "ordered"
30+
tags = ["type-combination"]
31+
32+
[[case]]
33+
id = "t003_range_edges"
34+
description = "The largest and smallest finite powers of two in a double, 2^1023 and 2^-1074, and 2^-1075 below the smallest. Catches: 2^1023 overflowing, or the subnormal 2^-1074 flushed to 0"
35+
columns = [{ name = "n", type = "NUMBER(38,0)" }]
36+
rows = [["1023"], ["-1074"], ["-1075"]]
37+
query = "SELECT POWER(2, n) AS r FROM input ORDER BY ordinal"
38+
order = "ordered"
39+
tags = ["type-combination"]
40+
41+
[[case]]
42+
id = "t004_overflow"
43+
description = "2^1024, past the largest double. Catches: a finite value or an error where Snowflake gives its overflow result"
44+
columns = [{ name = "n", type = "NUMBER(38,0)" }]
45+
rows = [["1024"]]
46+
query = "SELECT POWER(2, n) AS r FROM input ORDER BY ordinal"
47+
order = "ordered"
48+
tags = ["type-combination"]
49+
50+
[[case]]
51+
id = "t005_null_exponent"
52+
description = "POWER(2, NULL). Catches: 1 or 2 returned instead of NULL"
53+
columns = [{ name = "n", type = "NUMBER(38,0)" }]
54+
rows = [["NULL"], ["3"]]
55+
query = "SELECT POWER(2, n) AS r FROM input ORDER BY ordinal"
56+
order = "ordered"
57+
tags = ["null"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
category = "translation"
2+
construct = "sf.functions.regexp-substr"
3+
session_profile = "utc-v1"
4+
5+
[[case]]
6+
id = "t001_empty_match_at_and_past_the_end"
7+
description = "REGEXP_SUBSTR(a, 'x*', n) on 'abc' with n at the last character, one past it and two past it, where 'x*' matches the empty string. Catches: '' where Snowflake gives NULL, or an error past the end where Snowflake answers"
8+
columns = [{ name = "a", type = "VARCHAR" }, { name = "n", type = "NUMBER(38,0)" }]
9+
rows = [
10+
["'abc'", "3"],
11+
["'abc'", "4"],
12+
["'abc'", "5"],
13+
]
14+
query = "SELECT n, REGEXP_SUBSTR(a, 'x*', n) AS r FROM input ORDER BY ordinal"
15+
order = "ordered"
16+
tags = ["type-combination"]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
category = "translation"
2+
construct = "sf.functions.to-char.to-char"
3+
session_profile = "utc-v1"
4+
5+
[[case]]
6+
id = "t001_mon_every_month"
7+
description = "TO_CHAR(date, 'MON') for a date in every month, as dbt_date.get_date_dimension writes month_name_short. Catches: the month number written, the wrong letter case, or a locale's abbreviation"
8+
columns = [{ name = "d", type = "DATE" }]
9+
rows = [
10+
["'2024-01-15'"], ["'2024-02-29'"], ["'2024-03-15'"], ["'2024-04-15'"], ["'2024-05-15'"], ["'2024-06-15'"],
11+
["'2024-07-15'"], ["'2024-08-15'"], ["'2024-09-15'"], ["'2024-10-15'"], ["'2024-11-15'"], ["'2024-12-31'"],
12+
]
13+
query = "SELECT TO_CHAR(d, 'MON') AS r FROM input ORDER BY ordinal"
14+
order = "ordered"
15+
tags = ["type-combination"]
16+
17+
[[case]]
18+
id = "t002_mmmm_every_month"
19+
description = "TO_CHAR(date, 'MMMM') for a date in every month, as dbt_date.get_date_dimension writes month_name. Catches: MMMM read as MM twice ('0101'), the wrong letter case, or an abbreviation"
20+
columns = [{ name = "d", type = "DATE" }]
21+
rows = [
22+
["'2024-01-15'"], ["'2024-02-29'"], ["'2024-03-15'"], ["'2024-04-15'"], ["'2024-05-15'"], ["'2024-06-15'"],
23+
["'2024-07-15'"], ["'2024-08-15'"], ["'2024-09-15'"], ["'2024-10-15'"], ["'2024-11-15'"], ["'2024-12-31'"],
24+
]
25+
query = "SELECT TO_CHAR(d, 'MMMM') AS r FROM input ORDER BY ordinal"
26+
order = "ordered"
27+
tags = ["type-combination"]
28+
29+
[[case]]
30+
id = "t003_month_names_in_a_format"
31+
description = "MON and MMMM beside other fields and on a timestamp. Catches: a field next to the name misread, or the timestamp's time leaking into the name"
32+
columns = [{ name = "d", type = "DATE" }, { name = "t", type = "TIMESTAMP_NTZ(9)" }]
33+
rows = [
34+
["'2024-09-05'", "'2024-05-01 23:59:59'"],
35+
]
36+
query = "SELECT TO_CHAR(d, 'DD MON YYYY') AS a, TO_CHAR(d, 'MMMM DD, YYYY') AS b, TO_CHAR(t, 'MON') AS c, TO_CHAR(t, 'MMMM') AS e FROM input ORDER BY ordinal"
37+
order = "ordered"
38+
tags = ["type-combination"]
39+
40+
[[case]]
41+
id = "t004_null"
42+
description = "A NULL date. Catches: a month name for NULL"
43+
columns = [{ name = "d", type = "DATE" }]
44+
rows = [["NULL"], ["'2024-03-01'"]]
45+
query = "SELECT TO_CHAR(d, 'MON') AS a, TO_CHAR(d, 'MMMM') AS b FROM input ORDER BY ordinal"
46+
order = "ordered"
47+
tags = ["null"]
48+
49+
[[case]]
50+
id = "t007_names_beside_month_and_day"
51+
description = "MONMM and MMMMDD, a name directly before another field. Catches: the name's letters read as part of the next field"
52+
columns = [{ name = "d", type = "DATE" }]
53+
rows = [["'2024-09-05'"]]
54+
query = "SELECT TO_CHAR(d, 'MONMM') AS a, TO_CHAR(d, 'MMMMDD') AS b FROM input ORDER BY ordinal"
55+
order = "ordered"
56+
tags = ["type-combination"]

‎coverage/translation/results-baseline.json‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6919,7 +6919,7 @@
69196919
"semi-structured/flatten_outer.toml#flatten_top_level_outer_plain": "matching",
69206920
"semi-structured/flatten_outer.toml#flatten_top_level_outer_recursive": "refused",
69216921
"semi-structured/flatten_outer.toml#lateral_subquery_without_rows": "matching",
6922-
"semi-structured/flatten_recursive.toml#flatten_path_option": "refused",
6922+
"semi-structured/flatten_recursive.toml#flatten_path_option": "matching",
69236923
"semi-structured/flatten_recursive.toml#flatten_recursive": "matching",
69246924
"semi-structured/flatten_recursive.toml#flatten_recursive_deep": "matching",
69256925
"semi-structured/flatten_recursive.toml#flatten_recursive_filtered": "matching",
@@ -9388,8 +9388,11 @@
93889388
"translation/functions/first-value.toml#t002_ignore_nulls": "matching",
93899389
"translation/functions/first-value.toml#t003_frame": "matching",
93909390
"translation/functions/first-value.toml#t004_null_expr": "matching",
9391+
"translation/functions/flatten.path.toml#t001_object_under_path": "matching",
9392+
"translation/functions/flatten.path.toml#t002_path_key_case": "matching",
9393+
"translation/functions/flatten.path.toml#t003_scalar_and_null_at_path": "matching",
93919394
"translation/functions/flatten.toml#t001_default": "matching",
9392-
"translation/functions/flatten.toml#t002_path": "refused",
9395+
"translation/functions/flatten.toml#t002_path": "matching",
93939396
"translation/functions/flatten.toml#t003_outer": "matching",
93949397
"translation/functions/flatten.toml#t004_recursive": "matching",
93959398
"translation/functions/flatten.toml#t005_mode": "matching",
@@ -10228,6 +10231,11 @@
1022810231
"translation/functions/pow.pow.toml#t007_overflow_inf": "refused",
1022910232
"translation/functions/pow.pow.toml#t008_neg_base": "refused",
1023010233
"translation/functions/pow.pow.toml#t009_neg_frac": "refused",
10234+
"translation/functions/pow.power-of-two.toml#t001_whole_exponents": "matching",
10235+
"translation/functions/pow.power-of-two.toml#t002_literal_exponents_in_a_sum": "matching",
10236+
"translation/functions/pow.power-of-two.toml#t003_range_edges": "matching",
10237+
"translation/functions/pow.power-of-two.toml#t004_overflow": "matching",
10238+
"translation/functions/pow.power-of-two.toml#t005_null_exponent": "matching",
1023110239
"translation/functions/pow.power.toml#t001_int": "refused",
1023210240
"translation/functions/pow.power.toml#t002_dec": "refused",
1023310241
"translation/functions/pow.power.toml#t003_float": "refused",
@@ -10320,6 +10328,7 @@
1032010328
"translation/functions/regexp-substr-all.toml#t009_null_regex_parameters": "refused",
1032110329
"translation/functions/regexp-substr-all.toml#t010_null_group_num": "refused",
1032210330
"translation/functions/regexp-substr-all.toml#t011_empty": "matching",
10331+
"translation/functions/regexp-substr.empty-match-position.toml#t001_empty_match_at_and_past_the_end": "refused",
1032310332
"translation/functions/regexp-substr.toml#t001_varchar": "matching",
1032410333
"translation/functions/regexp-substr.toml#t002_position_occurrence": "refused",
1032510334
"translation/functions/regexp-substr.toml#t003_group": "refused",
@@ -11155,13 +11164,18 @@
1115511164
"translation/functions/to-boolean.toml#t003_invalid_string": "matching_error",
1115611165
"translation/functions/to-boolean.toml#t004_nan": "refused",
1115711166
"translation/functions/to-boolean.toml#t005_null_string_or_numeric_expr": "matching",
11167+
"translation/functions/to-char.month-names.toml#t001_mon_every_month": "matching",
11168+
"translation/functions/to-char.month-names.toml#t002_mmmm_every_month": "matching",
11169+
"translation/functions/to-char.month-names.toml#t003_month_names_in_a_format": "refused",
11170+
"translation/functions/to-char.month-names.toml#t004_null": "matching",
11171+
"translation/functions/to-char.month-names.toml#t007_names_beside_month_and_day": "refused",
1115811172
"translation/functions/to-char.to-char.toml#t001_number_format": "refused",
11159-
"translation/functions/to-char.to-char.toml#t002_date_format": "refused",
11173+
"translation/functions/to-char.to-char.toml#t002_date_format": "matching",
1116011174
"translation/functions/to-char.to-char.toml#t003_binary_format": "refused",
1116111175
"translation/functions/to-char.to-char.toml#t004_variant": "refused",
1116211176
"translation/functions/to-char.to-char.toml#t005_null_expr": "matching",
1116311177
"translation/functions/to-char.to-varchar.toml#t001_number_format": "refused",
11164-
"translation/functions/to-char.to-varchar.toml#t002_date_format": "refused",
11178+
"translation/functions/to-char.to-varchar.toml#t002_date_format": "matching",
1116511179
"translation/functions/to-char.to-varchar.toml#t003_binary_format": "refused",
1116611180
"translation/functions/to-char.to-varchar.toml#t004_variant": "matching",
1116711181
"translation/functions/to-char.to-varchar.toml#t005_null_expr": "matching",

‎crates/sqlquack-core/src/diagnostics/constants.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub const CODES: &[CodeEntry] = &[
155155
help: Some(
156156
"the help names the divergence and the fixes that work in the current mode: allow \
157157
it in the policy file, drop --strict or --loud-divergences-only, or confirm its \
158-
assumption; --builtin-policy refuses every one",
158+
assumption; the built-in policy refuses every one",
159159
),
160160
explanation: "The construct at the span converts only by relying on the known \
161161
divergence the label names, where DuckDB may raise or differ from Snowflake as the \

‎crates/sqlquack-python/src/bindings/_helpers/convert_json.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use sqlquack::cli::main::convert_report::convert_report;
66
use sqlquack::cli::models::{ConvertArguments, OutputArguments, OutputFormat, PolicyArguments};
77
use sqlquack_core::diagnostics::main::render_diagnostics::render_diagnostics;
88
use sqlquack_core::diagnostics::models::Diagnostic;
9-
use sqlquack_policy::policy::constants::POLICY_FILE_NAME;
109

1110
use crate::bindings::models::{ConvertRequest, Rendered};
1211

@@ -26,7 +25,7 @@ pub(crate) fn convert_json(sql: &str, request: &str, path: &str) -> PyResult<Str
2625
json: false,
2726
},
2827
conversion: PolicyArguments {
29-
policy: request.policy.unwrap_or_else(|| POLICY_FILE_NAME.into()),
28+
policy: request.policy,
3029
builtin_policy: request.builtin_policy,
3130
strict: request.strict,
3231
utc_session: request.utc_session,

0 commit comments

Comments
 (0)