Skip to content

Commit 6462370

Browse files
committed
docs(website): generate the Allow example and name the policy page by its label
The Allow example refuses every known difference the defaults allow that can return a different value, generated so it can't drift. The policy page is titled Refuse, allow or replace, links that quoted the old title follow it, and project.mdx and the README say the defaults. The intro to the ones that raise an error no longer claims Snowflake returns a value.
1 parent 9d5f35b commit 6462370

7 files changed

Lines changed: 61 additions & 28 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ sqlquack convert query.sql
5151

5252
Or **[try the playground](https://sqlquack.io/playground/)** - no installation needed.
5353

54-
See the [supported dialects and coverage](https://sqlquack.io/docs/coverage/), [project guide](https://sqlquack.io/docs/project/) and [conversion policy](https://sqlquack.io/docs/policy/) for the details.
54+
See the [supported dialects and coverage](https://sqlquack.io/docs/coverage/), [project guide](https://sqlquack.io/docs/project/) and [defaults for known differences](https://sqlquack.io/docs/policy/) for the details.
5555

5656
## Use it from Python
5757

‎website/scripts/generate_known_differences.py‎

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
say for each known difference what differs, when relying on it is fine, when it is wrong and how
55
it fails; `crates/sqlquack-policy/policy.toml` gives each one's default. This script writes them
66
between the generated markers of `website/src/content/docs/docs/known-differences.mdx`: first the
7-
ones that can return a different value, then the ones that raise an error instead, by area. With
8-
`--check` it writes nothing and exits 1 when the page differs from what the entries give.
7+
ones that can return a different value, then the ones that raise an error instead, by area. It also
8+
writes the `[allow]` example on `website/src/content/docs/docs/policy.mdx` that refuses each one the
9+
defaults allow that can return a different value. With `--check` it writes nothing and exits 1 when
10+
either page differs from what the entries give.
911
1012
Usage: python3 scripts/generate_known_differences.py [--check] (from website/)
1113
"""
@@ -24,13 +26,19 @@
2426
ENTRIES = POLICY / "known_differences/constants.rs"
2527
DEFAULTS = POLICY.parent / "policy.toml"
2628
PAGE = WEBSITE / "src/content/docs/docs/known-differences.mdx"
29+
POLICY_PAGE = WEBSITE / "src/content/docs/docs/policy.mdx"
2730

2831
BEGIN = (
2932
"{/* Generated by website/scripts/generate_known_differences.py from\n"
3033
" crates/sqlquack-policy/src/known_differences/constants.rs. Edit the entries, then rerun"
3134
" it. */}"
3235
)
3336
END = "{/* End of the generated known differences. */}"
37+
ALLOW_BEGIN = (
38+
"{/* Generated by website/scripts/generate_known_differences.py: each known difference that\n"
39+
" can return a different value and that the defaults allow. */}"
40+
)
41+
ALLOW_END = "{/* End of the generated [allow] example. */}"
3442

3543
CONSTANT = re.compile(r"pub const (\w+): &str =\s*" + STRING + r";", re.S)
3644
ENTRY = re.compile(r"KnownDifference \{(.*?)\}", re.S)
@@ -158,7 +166,7 @@ def table(known: list[dict[str, str]], default: dict[str, str]) -> list[str]:
158166
"",
159167
"## Raise an error instead",
160168
"",
161-
"Where one of these doesn't hold, DuckDB raises an error where Snowflake returns a value,"
169+
"Where one of these doesn't hold, DuckDB raises an error instead of returning a value,"
162170
" never a different value.",
163171
]
164172
for area, names in AREAS.items():
@@ -168,25 +176,42 @@ def table(known: list[dict[str, str]], default: dict[str, str]) -> list[str]:
168176
return lines + ["", END]
169177

170178

171-
def page(current: str, known: list[dict[str, str]], default: dict[str, str]) -> str:
172-
"""The page with its generated block replaced."""
173-
start, end = current.index(BEGIN), current.index(END) + len(END)
174-
return current[:start] + "\n".join(table(known, default)) + current[end:]
179+
def refuse_allowed(known: list[dict[str, str]], default: dict[str, str]) -> list[str]:
180+
"""An `[allow]` table refusing each one the defaults allow that can return a different value."""
181+
names = [
182+
entry["name"]
183+
for entry in known
184+
if entry["failure"] == FAILS_WITH["Value"] and default[entry["name"]] == "allowed"
185+
]
186+
refusals = [f"{name} = false" for name in names]
187+
return [ALLOW_BEGIN, "", "```toml", "[allow]", *refusals, "```", "", ALLOW_END]
188+
189+
190+
def replaced(current: str, begin: str, end: str, lines: list[str]) -> str:
191+
"""The page with the block between `begin` and `end` replaced by `lines`."""
192+
start, stop = current.index(begin), current.index(end) + len(end)
193+
return current[:start] + "\n".join(lines) + current[stop:]
175194

176195

177196
def main(argv: list[str]) -> int:
178-
current = PAGE.read_text()
179-
wanted = page(current, entries(ENTRIES.read_text(), constants()), defaults())
180-
if "--check" in argv:
181-
if current != wanted:
197+
known, default = entries(ENTRIES.read_text(), constants()), defaults()
198+
blocks = [
199+
(PAGE, BEGIN, END, table(known, default)),
200+
(POLICY_PAGE, ALLOW_BEGIN, ALLOW_END, refuse_allowed(known, default)),
201+
]
202+
stale = 0
203+
for path, begin, end, lines in blocks:
204+
current = path.read_text()
205+
wanted = replaced(current, begin, end, lines)
206+
if "--check" not in argv:
207+
path.write_text(wanted)
208+
elif current != wanted:
182209
print(
183-
f"{PAGE} is out of date; run python3 scripts/generate_known_differences.py",
210+
f"{path} is out of date; run python3 scripts/generate_known_differences.py",
184211
file=sys.stderr,
185212
)
186-
return 1
187-
return 0
188-
PAGE.write_text(wanted)
189-
return 0
213+
stale = 1
214+
return stale
190215

191216

192217
if __name__ == "__main__":

‎website/src/content/docs/docs/cli/convert.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ SQL that does not parse, or that Snowflake rejects, is refused with the same cod
6868
| `--color auto\|always\|never` | Highlight the SQL and colour diagnostics, as for [`check`](/docs/cli/check/#options). JSON is never coloured. |
6969

7070
`convert` also takes the configuration flags: `--config`, `--no-config`, `--strict` and
71-
`--python-runtime`. See [When something can't convert exactly](/docs/policy/#flags).
71+
`--python-runtime`. See [Refuse, allow or replace](/docs/policy/#flags).
7272

7373
## JSON report
7474

‎website/src/content/docs/docs/known-differences.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Where one of these doesn't hold, the converted SQL returns a value that differs
122122

123123
## Raise an error instead
124124

125-
Where one of these doesn't hold, DuckDB raises an error where Snowflake returns a value, never a different value.
125+
Where one of these doesn't hold, DuckDB raises an error instead of returning a value, never a different value.
126126

127127
### Numbers
128128

‎website/src/content/docs/docs/policy.mdx‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
2-
title: "When something can't convert exactly"
3-
description: "Refuse, allow or replace each known difference between Snowflake and DuckDB."
4-
sidebar:
5-
label: "Refuse, allow or replace"
2+
title: "Refuse, allow or replace"
3+
description: "When something can't convert exactly: refuse, allow or replace each known difference between Snowflake and DuckDB."
64
tableOfContents:
75
maxHeadingLevel: 2
86
---
@@ -76,14 +74,24 @@ hash = true
7674
A name that isn't a known difference is an error that names the nearest one. Some known
7775
differences [can return a different value](/docs/known-differences/#can-return-a-different-value)
7876
with no error, and `sqlquack explain --differences` marks
79-
them `value`. To convert only what is exact or fails with an error, refuse each of those:
77+
them `value`. To convert only what is exact or fails with an error, refuse each of those that the
78+
defaults allow:
79+
80+
{/* Generated by website/scripts/generate_known_differences.py: each known difference that
81+
can return a different value and that the defaults allow. */}
8082

8183
```toml
8284
[allow]
83-
current_time = false
85+
user_override = false
86+
declared_offset = false
8487
session_timezone_utc = false
88+
random = false
89+
uuid = false
90+
current_time = false
8591
```
8692

93+
{/* End of the generated [allow] example. */}
94+
8795
A conversion that relies on an allowed known difference names it in its last line on standard
8896
error, and `--verbose` adds a warning at each use:
8997

‎website/src/content/docs/docs/project.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ sources = "warehouse/tables"
126126
Paths are relative to the project folder, and a folder you name must exist. `functions` and
127127
`overrides` work the same way.
128128

129-
A `sqlquack.toml` holding only `[project]` keeps the built-in [policy](/docs/policy/). To use your
130-
own policy, keep the policy tables in the same file.
129+
A `sqlquack.toml` holding only `[project]` keeps [the defaults](/docs/policy/). To change them,
130+
add `[allow]` or `[replace]` to the same file.
131131

132132
## Functions
133133

‎website/src/content/docs/docs/quickstart.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ differences you refuse it, allow it or replace it with your own SQL, in `sqlquac
109109
current directory or the file `--config` names. Without one, or with `--no-config`, `convert`
110110
uses the defaults: they allow every known difference, with a warning, except five whose values can
111111
differ from Snowflake's with no error, such as `HASH`. See
112-
[When something can't convert exactly](/docs/policy/).
112+
[Refuse, allow or replace](/docs/policy/).
113113

114114
## Next steps
115115

0 commit comments

Comments
 (0)