sqlassert 0.4.1__py3-none-any.whl → 0.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlassert/declared_types.py +158 -0
- sqlassert/diagnostics.py +1 -4
- sqlassert/dialects.py +118 -396
- sqlassert/discovery/bigquery.py +2 -2
- sqlassert/discovery/databricks.py +4 -6
- sqlassert/discovery/fetcher.py +22 -52
- sqlassert/discovery/information_schema.py +7 -10
- sqlassert/discovery/mysql.py +4 -8
- sqlassert/discovery/postgres.py +17 -26
- sqlassert/discovery/redshift.py +2 -2
- sqlassert/discovery/snowflake.py +2 -2
- sqlassert/functions/__init__.py +10 -0
- sqlassert/functions/load.py +375 -0
- sqlassert/functions/table.py +2721 -0
- sqlassert/hazards.py +1 -1
- sqlassert/ir/__init__.py +13 -5
- sqlassert/ir/convert/aggregation.py +2 -3
- sqlassert/ir/convert/expressions.py +76 -67
- sqlassert/ir/convert/parser.py +0 -4
- sqlassert/ir/convert/schema.py +11 -80
- sqlassert/ir/convert/selects.py +30 -15
- sqlassert/ir/convert/shared.py +2 -3
- sqlassert/ir/convert/sources.py +2 -1
- sqlassert/ir/convert/value_types.py +12 -157
- sqlassert/ir/model.py +331 -138
- sqlassert/main.py +7 -10
- sqlassert/rules/causes/domain.py +1 -1
- sqlassert/rules/causes/unique.py +46 -5
- sqlassert/rules/domain.py +1 -1
- sqlassert/rules/join_cardinality.py +14 -21
- sqlassert/rules/nullability.py +3 -3
- sqlassert/rules/uniqueness.py +42 -41
- sqlassert/rules/value_typing.py +266 -133
- sqlassert/suggest.py +2 -2
- {sqlassert-0.4.1.dist-info → sqlassert-0.4.2.dist-info}/METADATA +18 -14
- sqlassert-0.4.2.dist-info/RECORD +72 -0
- sqlassert/ir/convert/builtins.py +0 -140
- sqlassert-0.4.1.dist-info/RECORD +0 -69
- {sqlassert-0.4.1.dist-info → sqlassert-0.4.2.dist-info}/WHEEL +0 -0
- {sqlassert-0.4.1.dist-info → sqlassert-0.4.2.dist-info}/entry_points.txt +0 -0
- {sqlassert-0.4.1.dist-info → sqlassert-0.4.2.dist-info}/licenses/LICENSE +0 -0
- {sqlassert-0.4.1.dist-info → sqlassert-0.4.2.dist-info}/top_level.txt +0 -0
sqlassert/dialects.py
CHANGED
|
@@ -6,14 +6,14 @@ same change, tentative (from memory) where it is neither probed nor read.
|
|
|
6
6
|
|
|
7
7
|
One `DialectSemantics` per dialect name (SQLGlot's), read by `ir/convert/`
|
|
8
8
|
while it lowers SQL: which Builtins raise an error rather than return NULL,
|
|
9
|
-
which text compares by identity
|
|
10
|
-
|
|
11
|
-
`DialectSemantics()`, whose arithmetic
|
|
12
|
-
choice
|
|
9
|
+
which text compares by identity. What each function does with NULL, and its
|
|
10
|
+
result type, is the function table's (`functions/table.py`). A dialect not
|
|
11
|
+
listed gets `DialectSemantics()`, whose arithmetic and collation are the
|
|
12
|
+
cautious choice. Whether a database enforces its declared constraints is not
|
|
13
|
+
modelled: every declared constraint is trusted (ADR 0012).
|
|
13
14
|
|
|
14
15
|
Every flag is a claim about the dialect's latest release under its default
|
|
15
|
-
settings, strict modes on (ADR 0006):
|
|
16
|
-
`sql_mode` has no PIPES_AS_CONCAT; Spark is modelled with ANSI mode on. `docs/dialects.md` argues each entry and says how soundness is judged
|
|
16
|
+
settings, strict modes on (ADR 0006): Spark is modelled with ANSI mode on. `docs/dialects.md` argues each entry and says how soundness is judged
|
|
17
17
|
without DuckDB; `docs/dialect-provenance.json` records, per fact, the engine
|
|
18
18
|
versions it was certified on or the vendor doc it rests on
|
|
19
19
|
(`scripts/certify_dialects.py`).
|
|
@@ -22,25 +22,13 @@ versions it was certified on or the vendor doc it rests on
|
|
|
22
22
|
from __future__ import annotations
|
|
23
23
|
|
|
24
24
|
from dataclasses import dataclass, replace
|
|
25
|
-
from typing import Literal
|
|
25
|
+
from typing import TYPE_CHECKING, Literal
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type KeyTrust = Literal["enforced", "rely", "unenforced"]
|
|
27
|
+
if TYPE_CHECKING:
|
|
28
|
+
from sqlassert.ir.model import CastKind, CastTarget, TypeFamily
|
|
30
29
|
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
# None when it is not modelled (MySQL, where it is OR).
|
|
34
|
-
type PipesMeaning = Literal["strict", "lenient"] | None
|
|
35
|
-
|
|
36
|
-
# What `concat(a, ...)` does with NULL: makes the result NULL ("strict"), or
|
|
37
|
-
# skips it, so the result is never NULL ("skips-null"); None when not modelled.
|
|
38
|
-
type ConcatMeaning = Literal["strict", "skips-null"] | None
|
|
39
|
-
|
|
40
|
-
# What `greatest(a, ...)` and `least(a, ...)` do with NULL: make the result
|
|
41
|
-
# NULL ("strict"), or skip it, so the result is NULL only when every argument
|
|
42
|
-
# is ("skips-null"); None when not modelled.
|
|
43
|
-
type GreatestMeaning = Literal["strict", "skips-null"] | None
|
|
30
|
+
# A modifier of a star (`DialectSemantics.star_modifiers`).
|
|
31
|
+
type StarModifier = Literal["except", "replace", "rename"]
|
|
44
32
|
|
|
45
33
|
|
|
46
34
|
@dataclass(frozen=True)
|
|
@@ -71,23 +59,20 @@ class DialectSemantics:
|
|
|
71
59
|
# identical. Not where it keeps the zone it was given (Trino, Snowflake's
|
|
72
60
|
# TIMESTAMP_TZ, Oracle): equal instants in two zones differ as text.
|
|
73
61
|
zoned_timestamp_is_instant: bool = False
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
greatest: GreatestMeaning = None
|
|
89
|
-
# `xs[i]` (an element of a list, array, map or struct) is NULL when `xs` is.
|
|
90
|
-
subscript_strict: bool = False
|
|
62
|
+
# The casts between type families that keep different values different,
|
|
63
|
+
# each `(source, target, kind)` (`ir.CastTable`, ADR 0011): "widening",
|
|
64
|
+
# values unchanged, or "injective", each value changed but different ones
|
|
65
|
+
# kept apart (a DATE becomes its midnight). A pair not listed is lossy.
|
|
66
|
+
# Within a family the rules are general (an integer into a wider one),
|
|
67
|
+
# except `("text", "sized text", "widening")`: a cast into a text type
|
|
68
|
+
# shorter than the value keeps it or raises, where it does not truncate.
|
|
69
|
+
# An explicit CAST asks the table, and so does a comparison of two types,
|
|
70
|
+
# for the side it casts (a DATE beside a TIMESTAMP, ADR 0009). Certified
|
|
71
|
+
# as `cast(T->U)=KIND`: as many distinct values after the cast as before,
|
|
72
|
+
# over values chosen to break it, and a DATE equal to its midnight but not
|
|
73
|
+
# to a later time that day (which an engine casting the timestamp down to
|
|
74
|
+
# a DATE would match).
|
|
75
|
+
casts: tuple[tuple[TypeFamily, CastTarget, CastKind], ...] = ()
|
|
91
76
|
# The column order of `*` over `a JOIN b USING (k, ...)`. "standard": the
|
|
92
77
|
# USING columns first in the USING list's order, then the left input's
|
|
93
78
|
# others, then the right's. "left_position": each USING column stays at its
|
|
@@ -95,17 +80,27 @@ class DialectSemantics:
|
|
|
95
80
|
# columns first, but in the left input's column order (MySQL: probed).
|
|
96
81
|
# docs/dialects.md, "Stars and names".
|
|
97
82
|
using_star_order: Literal["standard", "left_position", "left_order"] = "standard"
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
|
|
83
|
+
# The modifiers a star (`*`, `t.*`) takes, each meaning what DuckDB's
|
|
84
|
+
# does: "except" (`* EXCEPT (c)`, DuckDB's and Snowflake's EXCLUDE) drops
|
|
85
|
+
# the named columns, "replace" (`* REPLACE (e AS c)`) puts the expression
|
|
86
|
+
# in its column's place under its name, "rename" (`* RENAME (c AS d)`)
|
|
87
|
+
# renames a column in place; every other column keeps its position. Each
|
|
88
|
+
# names a column of the star's own input, and a star whose modifiers name
|
|
89
|
+
# a column twice, or a name that is no single column, stays opaque, so the
|
|
90
|
+
# order engines apply them in (Snowflake: EXCLUDE, REPLACE, RENAME) and an
|
|
91
|
+
# unmatched name (an error, or ignored by ClickHouse) never matter. A
|
|
92
|
+
# modifier not listed (Snowflake's ILIKE, ClickHouse's APPLY and
|
|
93
|
+
# COLUMNS('re'), DuckDB's COLUMNS) leaves the select opaque, as does any
|
|
94
|
+
# modifier in PostgreSQL, MySQL, SQLite, Trino, Redshift, Hive and Oracle,
|
|
95
|
+
# which have none. Certified as `star_modifier(KIND)`. docs/dialects.md,
|
|
96
|
+
# "Stars and names".
|
|
97
|
+
star_modifiers: tuple[StarModifier, ...] = ()
|
|
98
|
+
# Identifiers are case-sensitive (ClickHouse). Only star modifiers read
|
|
99
|
+
# it: a name that matches a column only up to case is ignored there, not
|
|
100
|
+
# an error, so the modifier must spell its column exactly.
|
|
101
|
+
case_sensitive_names: bool = False
|
|
103
102
|
# A PRIMARY KEY column is NOT NULL.
|
|
104
103
|
primary_key_not_null: bool = True
|
|
105
|
-
# A column-level `REFERENCES` is enforced (MySQL before 9.0 parses and ignores it).
|
|
106
|
-
inline_references: bool = True
|
|
107
|
-
# The table ENGINEs that enforce foreign keys (lower-cased), None for every table.
|
|
108
|
-
foreign_key_engines: frozenset[str] | None = None
|
|
109
104
|
# An ENUM's members lose their trailing spaces (MySQL). An ENUM holds only
|
|
110
105
|
# its members: MySQL's '' for any other value, outside strict mode or
|
|
111
106
|
# under INSERT IGNORE, is out of scope (docs/dialects.md).
|
|
@@ -116,29 +111,6 @@ class DialectSemantics:
|
|
|
116
111
|
# it is no soundness claim and is not certified: a wrong True suggests SQL
|
|
117
112
|
# the engine rejects, never a wrong proof.
|
|
118
113
|
set_operations_all: bool = False
|
|
119
|
-
# The type each function returns whatever its arguments' types, by the
|
|
120
|
-
# SQLGlot node it parses to: a select item that is such a call has that
|
|
121
|
-
# type, as a column declared with it would. Only where every argument type
|
|
122
|
-
# the engine accepts gives the same result type (`date_trunc` keeps its
|
|
123
|
-
# input's type, so it is not here). Certified with the engine's own type
|
|
124
|
-
# function (`scripts/certify_dialects.py`); a dialect without one claims none.
|
|
125
|
-
# A function SQLGlot parses as `Anonymous` is keyed `Anonymous:<lowercase name>`.
|
|
126
|
-
result_types: tuple[tuple[str, str], ...] = ()
|
|
127
|
-
# The type of a function whose result type follows one argument's, by the
|
|
128
|
-
# SQLGlot node, the argument's key in the node, and the result type for
|
|
129
|
-
# each argument type (`result_type(Node,ARGTYPE)=TYPE`), as the engine
|
|
130
|
-
# names them; `("*", "=")` makes any other argument type the result's
|
|
131
|
-
# (`result_type(Node,*)==`). An argument of a type not listed, or of
|
|
132
|
-
# unknown type, leaves the call untyped. Certified like `result_types`.
|
|
133
|
-
argument_result_types: tuple[tuple[str, str, tuple[tuple[str, str], ...]], ...] = ()
|
|
134
|
-
# Hash functions modelled as strict and total, by SQLGlot node: NULL
|
|
135
|
-
# exactly when the argument is. SQLGlot parses a hex-text hash as `MD5`,
|
|
136
|
-
# `SHA` (sha1) or `SHA2` and a raw-bytes one as `MD5Digest`, `SHA1Digest`
|
|
137
|
-
# or `SHA2Digest`, though ClickHouse's `SHA1`/`SHA256` (bytes) parse as
|
|
138
|
-
# `SHA`/`SHA2`. None is standard SQL, so each dialect claims its own.
|
|
139
|
-
# `sha2(x, n)` where `n` is free is NULL for an unsupported `n` in MySQL,
|
|
140
|
-
# Spark and Hive, so `SHA2` is claimed only where the length is fixed.
|
|
141
|
-
hash_functions: tuple[str, ...] = ()
|
|
142
114
|
# The type of a number literal that is not an integer, by kind, as the
|
|
143
115
|
# engine names the type (`literal_type(KIND)=TYPE`): "decimal", a literal
|
|
144
116
|
# written with a point (`0.1`), and "exponent", one written with an exponent
|
|
@@ -178,10 +150,29 @@ class DialectSemantics:
|
|
|
178
150
|
# still `id`).
|
|
179
151
|
alias_named_table_functions: tuple[str, ...] = ()
|
|
180
152
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
153
|
+
|
|
154
|
+
# The casts every engine keeps apart, by type family (`DialectSemantics.casts`):
|
|
155
|
+
# an integer or decimal written as text in its one canonical form (a decimal
|
|
156
|
+
# at its declared scale or without trailing zeros, either way one text per
|
|
157
|
+
# value), a boolean as 1 and 0 or as text, a date, time or timestamp as ISO
|
|
158
|
+
# text with every fraction of a second it has, a DATE as its midnight in a
|
|
159
|
+
# timestamp with no zone. Each dialect states its own; tentative where unprobed.
|
|
160
|
+
_CASTS: tuple[tuple[TypeFamily, CastTarget, CastKind], ...] = (
|
|
161
|
+
("integer", "text", "injective"),
|
|
162
|
+
("decimal", "text", "injective"),
|
|
163
|
+
("boolean", "integer", "injective"),
|
|
164
|
+
("boolean", "text", "injective"),
|
|
165
|
+
("date", "text", "injective"),
|
|
166
|
+
("time", "text", "injective"),
|
|
167
|
+
("timestamp", "text", "injective"),
|
|
168
|
+
("date", "timestamp", "injective"),
|
|
169
|
+
)
|
|
170
|
+
# A DATE as its midnight in the session zone: two dates are two instants in every zone.
|
|
171
|
+
_DATE_TO_INSTANT: tuple[TypeFamily, CastTarget, CastKind] = ("date", "timestamptz", "injective")
|
|
172
|
+
# A UUID as its canonical lower-case hyphenated text.
|
|
173
|
+
_UUID_TO_TEXT: tuple[TypeFamily, CastTarget, CastKind] = ("uuid", "text", "injective")
|
|
174
|
+
# A cast into text shorter than the value raises (or ignores the length) rather than truncate.
|
|
175
|
+
_SIZED_TEXT_KEEPS: tuple[TypeFamily, CastTarget, CastKind] = ("text", "sized text", "widening")
|
|
185
176
|
|
|
186
177
|
|
|
187
178
|
# Spark 4 and Databricks under ANSI mode, their default (ADR 0006): overflow
|
|
@@ -194,41 +185,17 @@ _SPARK = DialectSemantics(
|
|
|
194
185
|
text_is_binary=True, # UTF8_BINARY is the default collation.
|
|
195
186
|
zoned_timestamp_is_instant=True,
|
|
196
187
|
# Tentative: a DATE beside a TIMESTAMP (an instant) is its midnight in
|
|
197
|
-
# the session zone, beside a TIMESTAMP_NTZ its midnight.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
concat="strict",
|
|
201
|
-
concat_ws="skips-null",
|
|
188
|
+
# the session zone, beside a TIMESTAMP_NTZ its midnight. A cast into
|
|
189
|
+
# VARCHAR(n) is not claimed to keep the text.
|
|
190
|
+
casts=(*_CASTS, _DATE_TO_INSTANT),
|
|
202
191
|
# Certified on Spark 4.3, not Databricks (`databricks` below drops them).
|
|
203
192
|
checked_sum=True,
|
|
204
|
-
greatest="skips-null",
|
|
205
|
-
subscript_strict=True,
|
|
206
|
-
unique_keys="rely",
|
|
207
|
-
foreign_keys="rely",
|
|
208
|
-
# CHECKs are enforced (the default): only Delta tables declare one, and
|
|
209
|
-
# Delta rejects a write that violates it and checks existing rows before
|
|
210
|
-
# `ALTER TABLE ... ADD CONSTRAINT` adds one (docs/dialect-provenance.json).
|
|
211
193
|
set_operations_all=True,
|
|
212
|
-
# Tentative. Not SHA2: `sha2(x, n)` is NULL for an unsupported `n`.
|
|
213
|
-
# Not `concat`, `||` or `reverse` of arrays (arrays), nor `datediff`
|
|
214
|
-
# (INT for two arguments, BIGINT for three).
|
|
215
|
-
result_types=(
|
|
216
|
-
("MD5", "STRING"), ("SHA", "STRING"),
|
|
217
|
-
*((node, "STRING") for node in ("Lower", "Upper", "Trim", "Replace", "Left", "Right", "Substring", "Pad", "Repeat", "Initcap", "SplitPart", "Translate", "Overlay", "Chr", "ConcatWs", "RegexpReplace", "RegexpExtract", "RegexpSubstr", "Dayname", "Monthname", "TimeToStr", "ToChar",)),
|
|
218
|
-
*((node, "INT") for node in ("Length", "StrPosition", "Ascii", "BitLength", "Anonymous:octet_length", "Year", "Month", "Day", "Hour", "Minute", "Second", "Quarter", "DayOfWeek", "DayOfYear", "Week",)),
|
|
219
|
-
*((node, "BOOLEAN") for node in ("RegexpLike", "StartsWith", "EndsWith", "Contains",)),
|
|
220
|
-
*((node, "DOUBLE") for node in ("Ln", "Exp", "Sqrt", "Pow", "Log", "Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2", "Sign",)),
|
|
221
|
-
*((node, "DATE") for node in ("LastDay", "DateTrunc",)),
|
|
222
|
-
*((node, "TIMESTAMP") for node in ("TimestampTrunc",)),
|
|
223
|
-
),
|
|
224
|
-
argument_result_types=(
|
|
225
|
-
("DPipe", "this", (("STRING", "STRING"),)),
|
|
226
|
-
("Reverse", "this", (("STRING", "STRING"),)),
|
|
227
|
-
("Abs", "this", (("*", "="),)),
|
|
228
|
-
),
|
|
229
|
-
hash_functions=("MD5", "SHA"),
|
|
230
194
|
values_types=(("string", "string"), ("integer", "int"), ("bigint", "bigint"), ("decimal", "decimal")),
|
|
231
195
|
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
196
|
+
# `* EXCEPT (c)`, and `* EXCEPT (s.f)` drops the field f of a struct s
|
|
197
|
+
# (probed by hand on Spark 4.3); no REPLACE or RENAME.
|
|
198
|
+
star_modifiers=("except",),
|
|
232
199
|
# Tentative. `range(n)` has the one column `id`, whatever its alias. Not
|
|
233
200
|
# `explode`, `posexplode` or `inline`: an array, a map or a struct gives
|
|
234
201
|
# different columns, and the SQL alone does not say which it reads.
|
|
@@ -240,47 +207,17 @@ _JSON_TABLE_COLUMNS = ("key", "value", "type", "atom", "id", "parent", "fullkey"
|
|
|
240
207
|
|
|
241
208
|
_SEMANTICS: dict[str, DialectSemantics] = {
|
|
242
209
|
"duckdb": DialectSemantics(
|
|
243
|
-
# A DATE compared with a TIMESTAMP is its midnight
|
|
244
|
-
#
|
|
245
|
-
|
|
210
|
+
# A DATE compared with a TIMESTAMP is its midnight; with a TIMESTAMP
|
|
211
|
+
# WITH TIME ZONE, its midnight in the session zone. VARCHAR(n) ignores
|
|
212
|
+
# its length.
|
|
213
|
+
casts=(*_CASTS, _DATE_TO_INSTANT, _UUID_TO_TEXT, _SIZED_TEXT_KEEPS),
|
|
246
214
|
checked_arithmetic=True,
|
|
247
215
|
checked_sum=True,
|
|
248
216
|
text_is_binary=True,
|
|
249
217
|
zoned_timestamp_is_instant=True,
|
|
250
|
-
pipes="strict",
|
|
251
|
-
concat="skips-null",
|
|
252
|
-
concat_ws="skips-null",
|
|
253
|
-
greatest="skips-null",
|
|
254
|
-
subscript_strict=True,
|
|
255
218
|
using_star_order="left_position",
|
|
256
219
|
set_operations_all=True,
|
|
257
|
-
|
|
258
|
-
*((node, "VARCHAR") for node in (
|
|
259
|
-
"MD5", "SHA", "SHA2", "Lower", "Upper", "Trim", "Replace", "Left", "Right", "Substring", "ConcatWs", "Dayname", "Monthname",
|
|
260
|
-
"Pad", "RegexpReplace", "Reverse", "SplitPart", "Translate", "Overlay", "Chr", "TimeToStr", "ArrayToString", "Format",
|
|
261
|
-
"Anonymous:nfc_normalize",
|
|
262
|
-
)),
|
|
263
|
-
*((node, "BIGINT") for node in (
|
|
264
|
-
"Length", "StrPosition", "Year", "Month", "Day", "Hour", "Minute", "Second", "Quarter", "Week", "DayOfWeek",
|
|
265
|
-
"DayOfYear", "DayOfWeekIso", "DateDiff", "BitLength", "Anonymous:octet_length", "Anonymous:strlen",
|
|
266
|
-
)),
|
|
267
|
-
*((node, "DOUBLE") for node in ("Ln", "Exp", "Sqrt", "Pow", "Log", "Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2")),
|
|
268
|
-
*((node, "BOOLEAN") for node in (
|
|
269
|
-
"RegexpLike", "RegexpFullMatch", "StartsWith", "EndsWith", "Contains", "Anonymous:prefix", "Anonymous:suffix",
|
|
270
|
-
)),
|
|
271
|
-
("Ascii", "INTEGER"), ("Sign", "TINYINT"), ("LastDay", "DATE"), ("DateFromParts", "DATE"),
|
|
272
|
-
),
|
|
273
|
-
# Not `regexp_extract` (a STRUCT for a list of group names), `concat` or `repeat` of a list.
|
|
274
|
-
argument_result_types=(
|
|
275
|
-
("TimestampTrunc", "this", (
|
|
276
|
-
*((source, "TIMESTAMP") for source in ("DATE", "TIMESTAMP", "TIMESTAMP_S", "TIMESTAMP_MS", "TIMESTAMP_NS")),
|
|
277
|
-
("TIMESTAMP WITH TIME ZONE", "TIMESTAMP WITH TIME ZONE"), ("INTERVAL", "INTERVAL"),
|
|
278
|
-
)),
|
|
279
|
-
("DPipe", "this", (("VARCHAR", "VARCHAR"),)),
|
|
280
|
-
("Repeat", "this", (("VARCHAR", "VARCHAR"), ("BLOB", "BLOB"))),
|
|
281
|
-
("Abs", "this", (("*", "="),)),
|
|
282
|
-
),
|
|
283
|
-
hash_functions=("MD5", "SHA", "SHA2"),
|
|
220
|
+
star_modifiers=("except", "replace", "rename"),
|
|
284
221
|
values_types=(("string", "VARCHAR"), ("integer", "INTEGER"), ("bigint", "BIGINT"), ("decimal", "DECIMAL")),
|
|
285
222
|
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
286
223
|
table_functions=(
|
|
@@ -290,42 +227,16 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
290
227
|
alias_named_table_functions=("range", "generate_series", "unnest"),
|
|
291
228
|
),
|
|
292
229
|
"postgres": DialectSemantics(
|
|
293
|
-
# Tentative: date = timestamp(tz) compares the date's midnight.
|
|
294
|
-
|
|
230
|
+
# Tentative: date = timestamp(tz) compares the date's midnight. A cast
|
|
231
|
+
# into varchar(n) truncates silently, so it is not listed.
|
|
232
|
+
casts=(*_CASTS, _DATE_TO_INSTANT, _UUID_TO_TEXT),
|
|
295
233
|
checked_arithmetic=True,
|
|
296
234
|
checked_division=True,
|
|
297
235
|
checked_sum=True,
|
|
298
236
|
text_is_binary=True,
|
|
299
237
|
unscaled_decimal=True,
|
|
300
238
|
zoned_timestamp_is_instant=True,
|
|
301
|
-
pipes="lenient", # `ARRAY[1] || NULL` is `{1}`.
|
|
302
|
-
concat="skips-null",
|
|
303
|
-
concat_ws="skips-null",
|
|
304
|
-
greatest="skips-null",
|
|
305
|
-
subscript_strict=True,
|
|
306
239
|
set_operations_all=True,
|
|
307
|
-
# `sha256(x)` returns bytea: SHA2Digest. No Postgres SQL parses to SHA or SHA2.
|
|
308
|
-
# Tentative beyond the hashes (probed by hand on 18.6, not certified).
|
|
309
|
-
# No `year`, `last_day`, `datediff` or `dayname`: Postgres has none.
|
|
310
|
-
result_types=(
|
|
311
|
-
("MD5", "TEXT"), ("SHA2Digest", "BYTEA"),
|
|
312
|
-
*((node, "TEXT") for node in ("Lower", "Upper", "Trim", "Replace", "Left", "Right", "Substring", "Pad", "Repeat", "Reverse", "Initcap", "SplitPart", "Translate", "Overlay", "Normalize", "Chr", "Concat", "ConcatWs", "Format", "ArrayToString", "RegexpReplace", "RegexpSubstr", "TimeToStr",)),
|
|
313
|
-
*((node, "INTEGER") for node in ("Length", "StrPosition", "BitLength", "Ascii", "Anonymous:octet_length",)),
|
|
314
|
-
*((node, "DOUBLE PRECISION") for node in ("Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2",)),
|
|
315
|
-
*((node, "BOOLEAN") for node in ("RegexpLike", "StartsWith",)),
|
|
316
|
-
*((node, "DATE") for node in ("Anonymous:make_date",)),
|
|
317
|
-
),
|
|
318
|
-
# `date_trunc` of a DATE is a TIMESTAMPTZ; `ln` and the like keep a NUMERIC.
|
|
319
|
-
argument_result_types=(
|
|
320
|
-
("TimestampTrunc", "this", (("DATE", "TIMESTAMP WITH TIME ZONE"), ("TIMESTAMP", "TIMESTAMP"), ("TIMESTAMP WITH TIME ZONE", "TIMESTAMP WITH TIME ZONE"), ("INTERVAL", "INTERVAL"),)),
|
|
321
|
-
("DPipe", "this", (("TEXT", "TEXT"), ("VARCHAR", "TEXT"),)),
|
|
322
|
-
("Abs", "this", (("*", "="),)),
|
|
323
|
-
("Ln", "this", (("SMALLINT", "DOUBLE PRECISION"), ("INTEGER", "DOUBLE PRECISION"), ("BIGINT", "DOUBLE PRECISION"), ("REAL", "DOUBLE PRECISION"), ("DOUBLE PRECISION", "DOUBLE PRECISION"), ("NUMERIC", "NUMERIC"),)),
|
|
324
|
-
("Exp", "this", (("SMALLINT", "DOUBLE PRECISION"), ("INTEGER", "DOUBLE PRECISION"), ("BIGINT", "DOUBLE PRECISION"), ("REAL", "DOUBLE PRECISION"), ("DOUBLE PRECISION", "DOUBLE PRECISION"), ("NUMERIC", "NUMERIC"),)),
|
|
325
|
-
("Sqrt", "this", (("SMALLINT", "DOUBLE PRECISION"), ("INTEGER", "DOUBLE PRECISION"), ("BIGINT", "DOUBLE PRECISION"), ("REAL", "DOUBLE PRECISION"), ("DOUBLE PRECISION", "DOUBLE PRECISION"), ("NUMERIC", "NUMERIC"),)),
|
|
326
|
-
("Sign", "this", (("SMALLINT", "DOUBLE PRECISION"), ("INTEGER", "DOUBLE PRECISION"), ("BIGINT", "DOUBLE PRECISION"), ("REAL", "DOUBLE PRECISION"), ("DOUBLE PRECISION", "DOUBLE PRECISION"), ("NUMERIC", "NUMERIC"),)),
|
|
327
|
-
),
|
|
328
|
-
hash_functions=("MD5", "SHA2Digest"),
|
|
329
240
|
# A numeric literal with a point is an unscaled NUMERIC: no decimal is claimed.
|
|
330
241
|
values_types=(("string", "text"), ("integer", "integer"), ("bigint", "bigint")),
|
|
331
242
|
# A numeric constant with a point or an exponent is a NUMERIC (an unscaled one).
|
|
@@ -350,8 +261,9 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
350
261
|
"mysql": DialectSemantics(
|
|
351
262
|
# Tentative: a DATE beside a DATETIME is its midnight. Not TIMESTAMP:
|
|
352
263
|
# it is compared as a local DATETIME, and the fall-back hour gives two
|
|
353
|
-
# instants one local time.
|
|
354
|
-
|
|
264
|
+
# instants one local time. A CAST to text is a CHAR, compared ignoring
|
|
265
|
+
# case, so its entries never make a key.
|
|
266
|
+
casts=_CASTS,
|
|
355
267
|
# `*` over USING: the USING columns first, in the left input's order (probed, 8.4).
|
|
356
268
|
using_star_order="left_order",
|
|
357
269
|
# MySQL under its default strict sql_mode only (docs/dialects.md), so
|
|
@@ -364,118 +276,38 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
364
276
|
# Not `text_is_binary`: the default collations ignore case (and
|
|
365
277
|
# accents, and some trailing spaces).
|
|
366
278
|
zoned_timestamp_is_instant=True, # TIMESTAMP is converted to UTC.
|
|
367
|
-
concat="strict",
|
|
368
|
-
concat_ws="skips-null",
|
|
369
|
-
greatest="strict",
|
|
370
|
-
# Not `subscript_strict`: MySQL has no `xs[i]`.
|
|
371
|
-
inline_references=False,
|
|
372
|
-
foreign_key_engines=frozenset({"innodb", "ndb", "ndbcluster"}),
|
|
373
279
|
enum_strips_trailing_spaces=True,
|
|
374
280
|
set_operations_all=True, # Since 8.0.31.
|
|
375
|
-
# No type function to certify result types with. Not SHA2: its length is free.
|
|
376
|
-
hash_functions=("MD5", "SHA"),
|
|
377
|
-
# Tentative (probed by hand on 8.4, not certified). A text result
|
|
378
|
-
# carries its argument's length and collation, so only `regexp_replace`
|
|
379
|
-
# (always LONGTEXT) is claimed among them. `year()` is a YEAR.
|
|
380
|
-
result_types=(
|
|
381
|
-
*((node, "INT") for node in ("Length", "BitLength", "StrPosition", "Ascii", "Anonymous:octet_length", "Month", "Day", "Hour", "Minute", "Second", "Quarter", "Week", "DayOfWeek", "DayOfYear", "DateDiff", "RegexpLike",)),
|
|
382
|
-
*((node, "DOUBLE") for node in ("Ln", "Exp", "Sqrt", "Pow", "Log", "Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2",)),
|
|
383
|
-
*((node, "BIGINT") for node in ("Sign",)),
|
|
384
|
-
*((node, "YEAR") for node in ("Year",)),
|
|
385
|
-
*((node, "DATE") for node in ("LastDay",)),
|
|
386
|
-
*((node, "LONGTEXT") for node in ("RegexpReplace",)),
|
|
387
|
-
),
|
|
388
|
-
argument_result_types=(
|
|
389
|
-
("Abs", "this", (("*", "="),)),
|
|
390
|
-
),
|
|
391
281
|
# Every integer literal is a BIGINT. MySQL spells a row `ROW(...)`, which is not lowered.
|
|
392
282
|
values_types=(("string", "varchar"), ("integer", "bigint"), ("bigint", "bigint"), ("decimal", "decimal")),
|
|
393
283
|
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
394
284
|
),
|
|
395
285
|
"snowflake": DialectSemantics(
|
|
286
|
+
# Tentative (docs/dialect-provenance.json); ILIKE is opaque.
|
|
287
|
+
star_modifiers=("except", "replace", "rename"),
|
|
396
288
|
# Tentative: a DATE beside a TIMESTAMP_NTZ (TIMESTAMP and DATETIME by
|
|
397
|
-
# default) is its midnight. Not TIMESTAMP_TZ: it keeps the zone.
|
|
398
|
-
|
|
289
|
+
# default) is its midnight. Not TIMESTAMP_TZ: it keeps the zone. Not a
|
|
290
|
+
# time or timestamp as text: the default output formats drop digits
|
|
291
|
+
# (`HH24:MI:SS`, `.FF3`). A cast into VARCHAR(n) raises for a longer value.
|
|
292
|
+
casts=(*(entry for entry in _CASTS if entry[0] not in ("time", "timestamp")), _SIZED_TEXT_KEEPS),
|
|
399
293
|
# Not `checked_arithmetic`: its docs never say integer overflow raises.
|
|
400
294
|
checked_division=True,
|
|
401
295
|
text_is_binary=True, # With no COLLATE, text compares by its UTF-8 representation.
|
|
402
|
-
pipes="strict",
|
|
403
|
-
concat="strict",
|
|
404
|
-
concat_ws="strict", # `concat_ws(',', 'a', NULL)` is NULL.
|
|
405
|
-
unique_keys="rely",
|
|
406
|
-
foreign_keys="rely",
|
|
407
|
-
check_constraints="unenforced",
|
|
408
|
-
# Tentative (docs/dialect-provenance.json). `md5_binary` is MD5Digest.
|
|
409
|
-
# Tentative, from its docs. `ln` and the like are FLOAT but for a DECFLOAT.
|
|
410
|
-
result_types=(
|
|
411
|
-
("MD5", "VARCHAR"), ("SHA", "VARCHAR"), ("MD5Digest", "BINARY"),
|
|
412
|
-
*((node, "VARCHAR") for node in ("Lower", "Upper", "Trim", "Replace", "Repeat", "Translate", "Initcap", "SplitPart", "RegexpReplace", "RegexpExtract", "Chr", "Dayname", "Monthname", "ToChar",)),
|
|
413
|
-
*((node, "NUMBER") for node in ("Length", "StrPosition", "Ascii", "Year", "Month", "Day", "DateDiff",)),
|
|
414
|
-
*((node, "FLOAT") for node in ("Ln", "Exp", "Sqrt", "Pow", "Log", "Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2",)),
|
|
415
|
-
*((node, "BOOLEAN") for node in ("RegexpLike", "StartsWith", "EndsWith", "Contains",)),
|
|
416
|
-
*((node, "DATE") for node in ("LastDay",)),
|
|
417
|
-
),
|
|
418
296
|
# VARCHAR or BINARY, as the argument is.
|
|
419
|
-
argument_result_types=(
|
|
420
|
-
("Pad", "this", (("*", "="),)),
|
|
421
|
-
("Substring", "this", (("*", "="),)),
|
|
422
|
-
("Left", "this", (("*", "="),)),
|
|
423
|
-
("Right", "this", (("*", "="),)),
|
|
424
|
-
("Reverse", "this", (("*", "="),)),
|
|
425
|
-
("TimestampTrunc", "this", (("*", "="),)),
|
|
426
|
-
("Abs", "this", (("*", "="),)),
|
|
427
|
-
("DPipe", "this", (("VARCHAR", "VARCHAR"),)),
|
|
428
|
-
),
|
|
429
|
-
hash_functions=("MD5", "SHA", "MD5Digest"),
|
|
430
297
|
# `0.1` is a NUMBER(1,1) (tentative, from memory); the docs give `1e10` an exact NUMBER(11,0).
|
|
431
298
|
literal_types=(("decimal", "NUMBER"), ("exponent", "NUMBER")),
|
|
432
299
|
),
|
|
433
300
|
"bigquery": DialectSemantics(
|
|
434
|
-
# Tentative
|
|
435
|
-
|
|
301
|
+
star_modifiers=("except", "replace"), # Tentative.
|
|
302
|
+
# Tentative: a DATE beside a DATETIME is its midnight. A cast into
|
|
303
|
+
# STRING(n) raises for a longer value.
|
|
304
|
+
casts=(*_CASTS, _SIZED_TEXT_KEEPS),
|
|
436
305
|
checked_arithmetic=True,
|
|
437
306
|
checked_division=True,
|
|
438
307
|
# Its docs: overflow raises, and NaN or an infinity makes NaN or an infinity.
|
|
439
308
|
checked_sum=True,
|
|
440
309
|
text_is_binary=True, # With no collation specification, binary collation.
|
|
441
310
|
zoned_timestamp_is_instant=True,
|
|
442
|
-
pipes="strict",
|
|
443
|
-
concat="strict",
|
|
444
|
-
unique_keys="unenforced",
|
|
445
|
-
foreign_keys="unenforced",
|
|
446
|
-
check_constraints="unenforced",
|
|
447
|
-
# Tentative. `md5` and `sha256` return BYTES; `to_hex(md5(x))` parses as MD5.
|
|
448
|
-
# Tentative, from its docs. String functions return STRING or BYTES as
|
|
449
|
-
# their argument is; `floor` and the like of an INT64 are a FLOAT64.
|
|
450
|
-
result_types=(
|
|
451
|
-
("MD5", "STRING"), ("MD5Digest", "BYTES"), ("SHA1Digest", "BYTES"), ("SHA2Digest", "BYTES"),
|
|
452
|
-
*((node, "INT64") for node in ("Length", "StrPosition", "Ascii", "DateDiff",)),
|
|
453
|
-
*((node, "STRING") for node in ("Chr", "Normalize", "Initcap", "TimeToStr",)),
|
|
454
|
-
*((node, "BOOL") for node in ("RegexpLike", "StartsWith", "EndsWith",)),
|
|
455
|
-
*((node, "FLOAT64") for node in ("Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2",)),
|
|
456
|
-
*((node, "DATE") for node in ("LastDay",)),
|
|
457
|
-
),
|
|
458
|
-
argument_result_types=(
|
|
459
|
-
("Lower", "this", (("*", "="),)),
|
|
460
|
-
("Upper", "this", (("*", "="),)),
|
|
461
|
-
("Trim", "this", (("*", "="),)),
|
|
462
|
-
("Pad", "this", (("*", "="),)),
|
|
463
|
-
("Reverse", "this", (("*", "="),)),
|
|
464
|
-
("Left", "this", (("*", "="),)),
|
|
465
|
-
("Right", "this", (("*", "="),)),
|
|
466
|
-
("Replace", "this", (("*", "="),)),
|
|
467
|
-
("Substring", "this", (("*", "="),)),
|
|
468
|
-
("RegexpReplace", "this", (("*", "="),)),
|
|
469
|
-
("RegexpExtract", "this", (("*", "="),)),
|
|
470
|
-
("DPipe", "this", (("*", "="),)),
|
|
471
|
-
("Abs", "this", (("*", "="),)),
|
|
472
|
-
("Sign", "this", (("*", "="),)),
|
|
473
|
-
("DateTrunc", "this", (("*", "="),)),
|
|
474
|
-
("Ln", "this", (("INT64", "FLOAT64"), ("FLOAT64", "FLOAT64"), ("NUMERIC", "NUMERIC"), ("BIGNUMERIC", "BIGNUMERIC"),)),
|
|
475
|
-
("Exp", "this", (("INT64", "FLOAT64"), ("FLOAT64", "FLOAT64"), ("NUMERIC", "NUMERIC"), ("BIGNUMERIC", "BIGNUMERIC"),)),
|
|
476
|
-
("Sqrt", "this", (("INT64", "FLOAT64"), ("FLOAT64", "FLOAT64"), ("NUMERIC", "NUMERIC"), ("BIGNUMERIC", "BIGNUMERIC"),)),
|
|
477
|
-
),
|
|
478
|
-
hash_functions=("MD5", "MD5Digest", "SHA1Digest", "SHA2Digest"),
|
|
479
311
|
# A decimal is written `NUMERIC '0.1'`: `0.1` is a FLOAT64.
|
|
480
312
|
literal_types=(("decimal", "DOUBLE"), ("exponent", "DOUBLE")),
|
|
481
313
|
# Tentative. `UNNEST(xs) AS x` has the one column `x` (SQLGlot reads the alias as a column list).
|
|
@@ -483,34 +315,13 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
483
315
|
),
|
|
484
316
|
"redshift": DialectSemantics(
|
|
485
317
|
# Tentative: a DATE beside a TIMESTAMP or TIMESTAMPTZ is its midnight.
|
|
486
|
-
|
|
318
|
+
# A cast into VARCHAR(n) truncates.
|
|
319
|
+
casts=(*_CASTS, _DATE_TO_INSTANT),
|
|
487
320
|
checked_arithmetic=True,
|
|
488
321
|
checked_division=True,
|
|
489
322
|
# Not `checked_sum`: its docs say nothing of a sum that overflows or meets NaN.
|
|
490
323
|
# Not `text_is_binary`: a comparison ignores trailing spaces, in VARCHAR too.
|
|
491
324
|
zoned_timestamp_is_instant=True,
|
|
492
|
-
pipes="strict",
|
|
493
|
-
unique_keys="unenforced",
|
|
494
|
-
foreign_keys="unenforced",
|
|
495
|
-
check_constraints="unenforced",
|
|
496
|
-
# Tentative.
|
|
497
|
-
# Tentative, from its docs and memory. A CHAR argument may give a CHAR.
|
|
498
|
-
# `datediff` parses as TsOrDsDiff.
|
|
499
|
-
result_types=(
|
|
500
|
-
("MD5", "VARCHAR"), ("SHA", "VARCHAR"),
|
|
501
|
-
*((node, "VARCHAR") for node in ("Lower", "Upper", "Trim", "Replace", "Left", "Right", "Substring", "Pad", "Repeat", "Reverse", "Initcap", "SplitPart", "RegexpReplace", "RegexpExtract", "Concat", "TimeToStr",)),
|
|
502
|
-
*((node, "INTEGER") for node in ("Length", "StrPosition", "Ascii", "Anonymous:octet_length",)),
|
|
503
|
-
*((node, "DOUBLE PRECISION") for node in ("Ln", "Exp", "Sqrt", "Pow", "Log", "Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2",)),
|
|
504
|
-
*((node, "DATE") for node in ("LastDay",)),
|
|
505
|
-
*((node, "BIGINT") for node in ("TsOrDsDiff",)),
|
|
506
|
-
),
|
|
507
|
-
argument_result_types=(
|
|
508
|
-
("Abs", "this", (("*", "="),)),
|
|
509
|
-
("Sign", "this", (("*", "="),)),
|
|
510
|
-
("DPipe", "this", (("VARCHAR", "VARCHAR"),)),
|
|
511
|
-
("TimestampTrunc", "this", (("DATE", "TIMESTAMP"), ("TIMESTAMP", "TIMESTAMP"), ("TIMESTAMP WITH TIME ZONE", "TIMESTAMP WITH TIME ZONE"),)),
|
|
512
|
-
),
|
|
513
|
-
hash_functions=("MD5", "SHA"),
|
|
514
325
|
# Tentative, from memory: `0.1` is a NUMERIC as in PostgreSQL, `1e0` a DOUBLE PRECISION.
|
|
515
326
|
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
516
327
|
# Tentative. Unnesting a SUPER array, `FROM t, t.xs AS x`, has the one column `x` (SQLGlot reads it as an UNNEST).
|
|
@@ -519,39 +330,20 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
519
330
|
"databricks": replace(
|
|
520
331
|
_SPARK, checked_division=True, casts_raise=True,
|
|
521
332
|
# Certified on Apache Spark only; Databricks's docs do not say a sum meets NaN as a value.
|
|
522
|
-
checked_sum=False,
|
|
333
|
+
checked_sum=False,
|
|
523
334
|
),
|
|
524
335
|
"spark": _SPARK,
|
|
525
|
-
"hive": DialectSemantics(casts_raise=False,
|
|
526
|
-
# Tentative: a DATE beside a TIMESTAMP is its midnight.
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
# Tentative. Not SHA2: `sha2(x, n)` is NULL for an unsupported `n`.
|
|
530
|
-
# Tentative, from its docs and memory. Not `concat` (BINARY of BINARY);
|
|
531
|
-
# `last_day` is a STRING.
|
|
532
|
-
result_types=(
|
|
533
|
-
("MD5", "STRING"), ("SHA", "STRING"),
|
|
534
|
-
*((node, "STRING") for node in ("Lower", "Upper", "Trim", "Replace", "Substring", "Pad", "Repeat", "Reverse", "Initcap", "Translate", "Chr", "ConcatWs", "RegexpReplace", "RegexpExtract", "TimeToStr", "LastDay",)),
|
|
535
|
-
*((node, "INT") for node in ("Length", "StrPosition", "Ascii", "Year", "Month", "Day", "Hour", "Minute", "Second", "Quarter", "DateDiff",)),
|
|
536
|
-
*((node, "BOOLEAN") for node in ("RegexpLike",)),
|
|
537
|
-
*((node, "DOUBLE") for node in ("Ln", "Exp", "Sqrt", "Pow", "Log", "Sin", "Cos", "Tan", "Asin", "Acos", "Atan",)),
|
|
538
|
-
),
|
|
539
|
-
argument_result_types=(
|
|
540
|
-
("Abs", "this", (("*", "="),)),
|
|
541
|
-
),
|
|
542
|
-
hash_functions=("MD5", "SHA"),
|
|
336
|
+
"hive": DialectSemantics(casts_raise=False,
|
|
337
|
+
# Tentative: a DATE beside a TIMESTAMP is its midnight. A cast into
|
|
338
|
+
# VARCHAR(n) truncates.
|
|
339
|
+
casts=_CASTS,
|
|
543
340
|
# A decimal literal is a DOUBLE unless it has a `BD` suffix.
|
|
544
341
|
literal_types=(("decimal", "DOUBLE"), ("exponent", "DOUBLE")),
|
|
545
342
|
),
|
|
546
|
-
# SQLite claims no function result type: a value's type is its own
|
|
547
|
-
# (storage class), not its expression's.
|
|
548
343
|
"sqlite": DialectSemantics(
|
|
549
|
-
# No `
|
|
550
|
-
|
|
551
|
-
concat_ws="skips-null",
|
|
344
|
+
# No `casts`: SQLite has no date or time type, and a column's declared
|
|
345
|
+
# type does not bound the storage classes of its values.
|
|
552
346
|
using_star_order="left_position",
|
|
553
|
-
# Foreign keys are checked only under `PRAGMA foreign_keys = ON`, off by default.
|
|
554
|
-
foreign_keys="unenforced",
|
|
555
347
|
# Only an INTEGER PRIMARY KEY (the rowid) is never NULL.
|
|
556
348
|
primary_key_not_null=False,
|
|
557
349
|
table_functions=(("json_each", _JSON_TABLE_COLUMNS), ("json_tree", _JSON_TABLE_COLUMNS)),
|
|
@@ -559,63 +351,24 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
559
351
|
literal_types=(("decimal", "real"), ("exponent", "real")),
|
|
560
352
|
),
|
|
561
353
|
# A ClickHouse primary key orders and indexes a table; it never rejects a duplicate.
|
|
562
|
-
# Its `MD5`/`SHA1`/`SHA256` return FixedString bytes, wrapped in Nullable
|
|
563
|
-
# for a Nullable argument: a type that follows the argument, so no result
|
|
564
|
-
# type is claimed.
|
|
565
354
|
"clickhouse": DialectSemantics(
|
|
566
|
-
#
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
#
|
|
571
|
-
#
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
*((node, "String") for node in ("Lower", "Upper", "Trim", "Replace", "Left", "Right", "Substring", "Pad", "Repeat", "Reverse", "Initcap", "Translate", "Overlay", "Concat", "ConcatWs", "DPipe", "RegexpReplace", "RegexpExtract", "Monthname", "TimeToStr",)),
|
|
575
|
-
*((node, "UInt8") for node in ("RegexpLike", "Month", "Day",)),
|
|
576
|
-
*((node, "UInt16") for node in ("Year",)),
|
|
577
|
-
*((node, "Int32") for node in ("Ascii",)),
|
|
578
|
-
*((node, "Float64") for node in ("Ln", "Exp", "Sqrt", "Pow", "Log", "Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2",)),
|
|
579
|
-
*((node, "Int8") for node in ("Sign",)),
|
|
580
|
-
*((node, "Date") for node in ("LastDay",)),
|
|
581
|
-
*((node, "Int64") for node in ("DateDiff",)),
|
|
582
|
-
),
|
|
355
|
+
# EXCEPT and REPLACE without STRICT ignore a name no column has
|
|
356
|
+
# (probed); APPLY and COLUMNS('re') are opaque.
|
|
357
|
+
star_modifiers=("except", "replace"),
|
|
358
|
+
case_sensitive_names=True,
|
|
359
|
+
# Tentative: a Date beside a DateTime or DateTime64 is its midnight. Not a
|
|
360
|
+
# Time as text: a Time with a fraction of a second is no Time value
|
|
361
|
+
# (probed on 26.10: casting '10:00:00.001' to it fails).
|
|
362
|
+
casts=(*(entry for entry in _CASTS if entry[:2] != ("time", "text")), _UUID_TO_TEXT),
|
|
583
363
|
literal_types=(("decimal", "Float64"), ("exponent", "Float64")),
|
|
584
364
|
),
|
|
585
365
|
"oracle": DialectSemantics(
|
|
586
366
|
# Tentative: a DATE beside a TIMESTAMP keeps its time of day. Not
|
|
587
|
-
# TIMESTAMP WITH TIME ZONE: it keeps the zone.
|
|
588
|
-
|
|
367
|
+
# TIMESTAMP WITH TIME ZONE: it keeps the zone. Not a date, time or
|
|
368
|
+
# timestamp as text: the default NLS formats drop the time of day and
|
|
369
|
+
# two digits of the year.
|
|
370
|
+
casts=tuple(entry for entry in _CASTS if entry[0] not in ("date", "time", "timestamp") or entry[1] != "text"),
|
|
589
371
|
empty_string_is_null=True,
|
|
590
|
-
# Tentative, from its docs and memory: text functions return VARCHAR2
|
|
591
|
-
# or CLOB as their argument is, math functions keep NUMBER or a binary float.
|
|
592
|
-
result_types=(
|
|
593
|
-
*((node, "NUMBER") for node in ("Length", "StrPosition", "Ascii", "Sign",)),
|
|
594
|
-
*((node, "VARCHAR2") for node in ("Chr", "ToChar",)),
|
|
595
|
-
*((node, "DATE") for node in ("LastDay", "DateTrunc",)),
|
|
596
|
-
),
|
|
597
|
-
argument_result_types=(
|
|
598
|
-
("Lower", "this", (("*", "="),)),
|
|
599
|
-
("Upper", "this", (("*", "="),)),
|
|
600
|
-
("Initcap", "this", (("*", "="),)),
|
|
601
|
-
("Trim", "this", (("*", "="),)),
|
|
602
|
-
("Pad", "this", (("*", "="),)),
|
|
603
|
-
("Replace", "this", (("*", "="),)),
|
|
604
|
-
("Substring", "this", (("*", "="),)),
|
|
605
|
-
("Translate", "this", (("*", "="),)),
|
|
606
|
-
("RegexpReplace", "this", (("*", "="),)),
|
|
607
|
-
("RegexpSubstr", "this", (("*", "="),)),
|
|
608
|
-
("Abs", "this", (("*", "="),)),
|
|
609
|
-
("Ln", "this", (("*", "="),)),
|
|
610
|
-
("Exp", "this", (("*", "="),)),
|
|
611
|
-
("Sqrt", "this", (("*", "="),)),
|
|
612
|
-
("Sin", "this", (("*", "="),)),
|
|
613
|
-
("Cos", "this", (("*", "="),)),
|
|
614
|
-
("Tan", "this", (("*", "="),)),
|
|
615
|
-
("Asin", "this", (("*", "="),)),
|
|
616
|
-
("Acos", "this", (("*", "="),)),
|
|
617
|
-
("Atan", "this", (("*", "="),)),
|
|
618
|
-
),
|
|
619
372
|
# A number literal without an `f` or `d` suffix is a NUMBER, point or exponent alike.
|
|
620
373
|
literal_types=(("decimal", "NUMBER"), ("exponent", "NUMBER")),
|
|
621
374
|
),
|
|
@@ -623,8 +376,9 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
623
376
|
# one in the SQL describes a table some other engine holds.
|
|
624
377
|
"trino": DialectSemantics(
|
|
625
378
|
# Tentative: a DATE beside a TIMESTAMP(p) is its midnight. Not
|
|
626
|
-
# TIMESTAMP WITH TIME ZONE: it keeps the zone.
|
|
627
|
-
|
|
379
|
+
# TIMESTAMP WITH TIME ZONE: it keeps the zone. A cast into varchar(n)
|
|
380
|
+
# truncates.
|
|
381
|
+
casts=(*_CASTS, _UUID_TO_TEXT),
|
|
628
382
|
checked_arithmetic=True,
|
|
629
383
|
checked_division=True,
|
|
630
384
|
checked_sum=True,
|
|
@@ -632,39 +386,7 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
632
386
|
text_is_binary=True,
|
|
633
387
|
# Not `zoned_timestamp_is_instant`: a TIMESTAMP WITH TIME ZONE keeps
|
|
634
388
|
# its zone, and `CAST(ts AS VARCHAR)` writes it.
|
|
635
|
-
# Unlike Postgres, a NULL array or element operand makes `||` NULL too.
|
|
636
|
-
pipes="strict",
|
|
637
|
-
concat="strict",
|
|
638
|
-
greatest="strict",
|
|
639
|
-
# NULL for a NULL array or map; an index out of range raises.
|
|
640
|
-
subscript_strict=True,
|
|
641
|
-
# Not modelled: it skips a NULL VARCHAR, but its ARRAY(VARCHAR)
|
|
642
|
-
# overload is NULL for a NULL array, and SQLGlot parses both alike.
|
|
643
|
-
unique_keys="unenforced",
|
|
644
|
-
foreign_keys="unenforced",
|
|
645
|
-
check_constraints="unenforced",
|
|
646
389
|
set_operations_all=True,
|
|
647
|
-
# `md5`/`sha1`/`sha256` take and return VARBINARY.
|
|
648
|
-
# Beyond the hashes, tentative (probed by hand on 484, not certified).
|
|
649
|
-
# A text result keeps its argument's length, so only those that lose it
|
|
650
|
-
# are fixed; `repeat` is an array function.
|
|
651
|
-
result_types=(
|
|
652
|
-
("MD5Digest", "VARBINARY"), ("SHA", "VARBINARY"), ("SHA2Digest", "VARBINARY"),
|
|
653
|
-
*((node, "BIGINT") for node in ("Length", "StrPosition", "Year", "Month", "Day", "Hour", "Minute", "Second", "Quarter", "DayOfWeek", "DayOfYear", "DateDiff",)),
|
|
654
|
-
*((node, "VARCHAR") for node in ("Pad", "Translate", "Concat", "ConcatWs", "Normalize", "TimeToStr",)),
|
|
655
|
-
*((node, "BOOLEAN") for node in ("RegexpLike", "StartsWith",)),
|
|
656
|
-
*((node, "DOUBLE") for node in ("Ln", "Exp", "Sqrt", "Pow", "Log", "Sin", "Cos", "Tan", "Asin", "Acos", "Atan", "Atan2",)),
|
|
657
|
-
*((node, "DATE") for node in ("LastDay",)),
|
|
658
|
-
),
|
|
659
|
-
argument_result_types=(
|
|
660
|
-
("Abs", "this", (("*", "="),)),
|
|
661
|
-
("TimestampTrunc", "this", (("*", "="),)),
|
|
662
|
-
("Upper", "this", (("*", "="),)),
|
|
663
|
-
("Lower", "this", (("*", "="),)),
|
|
664
|
-
("Reverse", "this", (("*", "="),)),
|
|
665
|
-
("DPipe", "this", (("VARCHAR", "VARCHAR"),)),
|
|
666
|
-
),
|
|
667
|
-
hash_functions=("MD5Digest", "SHA", "SHA2Digest"),
|
|
668
390
|
# A string is `varchar(n)` for its longest value.
|
|
669
391
|
values_types=(("string", "varchar"), ("integer", "integer"), ("bigint", "bigint"), ("decimal", "decimal")),
|
|
670
392
|
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|