sqlassert 0.3.1__py3-none-any.whl → 0.4.1__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/__init__.py +1 -2
- sqlassert/__main__.py +2 -131
- sqlassert/check.py +98 -16
- sqlassert/diagnostics.py +31 -7
- sqlassert/dialects.py +504 -27
- sqlassert/discovery/bigquery.py +3 -1
- sqlassert/discovery/databricks.py +25 -2
- sqlassert/discovery/duckdb.py +61 -23
- sqlassert/discovery/fetcher.py +170 -45
- sqlassert/discovery/information_schema.py +34 -5
- sqlassert/discovery/mysql.py +22 -1
- sqlassert/discovery/postgres.py +28 -12
- sqlassert/discovery/redshift.py +3 -2
- sqlassert/discovery/snowflake.py +3 -0
- sqlassert/discovery/trino.py +2 -2
- sqlassert/edits.py +240 -0
- sqlassert/hazards.py +735 -0
- sqlassert/ir/__init__.py +6 -1
- sqlassert/ir/convert/__init__.py +13 -0
- sqlassert/ir/convert/aggregation.py +439 -0
- sqlassert/ir/convert/builtins.py +140 -0
- sqlassert/ir/convert/expressions.py +572 -0
- sqlassert/ir/convert/joins.py +264 -0
- sqlassert/ir/convert/markers.py +249 -0
- sqlassert/ir/convert/parser.py +253 -0
- sqlassert/ir/convert/queries.py +259 -0
- sqlassert/ir/convert/schema.py +606 -0
- sqlassert/ir/convert/scopes.py +205 -0
- sqlassert/ir/convert/selects.py +337 -0
- sqlassert/ir/convert/shared.py +429 -0
- sqlassert/ir/convert/sources.py +432 -0
- sqlassert/ir/convert/subqueries.py +364 -0
- sqlassert/ir/convert/value_types.py +223 -0
- sqlassert/ir/convert/windows.py +275 -0
- sqlassert/ir/model.py +247 -66
- sqlassert/ir/names.py +63 -0
- sqlassert/main.py +3 -9
- sqlassert/properties.py +12 -1
- sqlassert/provenance.py +5 -1
- sqlassert/python_engine.py +167 -50
- sqlassert/reporting.py +36 -32
- sqlassert/rewrites.py +1591 -0
- sqlassert/rules/STYLEGUIDE.md +3 -2
- sqlassert/rules/causes/__init__.py +41 -0
- sqlassert/rules/causes/coverage.py +113 -0
- sqlassert/rules/causes/domain.py +123 -0
- sqlassert/rules/causes/joins.py +73 -0
- sqlassert/rules/causes/nulls.py +154 -0
- sqlassert/rules/causes/unique.py +523 -0
- sqlassert/rules/domain.py +123 -26
- sqlassert/rules/equality.py +153 -85
- sqlassert/rules/exactly_one.py +42 -2
- sqlassert/rules/foreign_key.py +15 -13
- sqlassert/rules/join_cardinality.py +302 -39
- sqlassert/rules/nullability.py +244 -35
- sqlassert/rules/uniqueness.py +513 -86
- sqlassert/rules/value_typing.py +337 -0
- sqlassert/sql_parse.py +224 -90
- sqlassert/suggest.py +132 -57
- sqlassert-0.4.1.dist-info/METADATA +235 -0
- sqlassert-0.4.1.dist-info/RECORD +69 -0
- sqlassert-0.4.1.dist-info/entry_points.txt +2 -0
- sqlassert-0.4.1.dist-info/top_level.txt +2 -0
- sqlassert_cli.py +130 -0
- sqlassert/improvements.py +0 -528
- sqlassert/ir/convert.py +0 -2377
- sqlassert/smells.py +0 -306
- sqlassert-0.3.1.dist-info/METADATA +0 -725
- sqlassert-0.3.1.dist-info/RECORD +0 -44
- sqlassert-0.3.1.dist-info/entry_points.txt +0 -2
- sqlassert-0.3.1.dist-info/top_level.txt +0 -1
- {sqlassert-0.3.1.dist-info → sqlassert-0.4.1.dist-info}/WHEEL +0 -0
- {sqlassert-0.3.1.dist-info → sqlassert-0.4.1.dist-info}/licenses/LICENSE +0 -0
sqlassert/dialects.py
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"""What each SQL dialect means by the constructs the analysis depends on.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Before editing, read docs/dialects.md, "Every engine at once": a fact added
|
|
4
|
+
for one engine is added for every engine where the construct exists, in the
|
|
5
|
+
same change, tentative (from memory) where it is neither probed nor read.
|
|
6
|
+
|
|
7
|
+
One `DialectSemantics` per dialect name (SQLGlot's), read by `ir/convert/`
|
|
4
8
|
while it lowers SQL: which Builtins raise an error rather than return NULL,
|
|
5
|
-
which text compares by identity, what
|
|
6
|
-
which constraints the database enforces. A dialect not listed gets
|
|
9
|
+
which text compares by identity, what `||`, `concat()`, `greatest()` and
|
|
10
|
+
subscripts do with NULL, and which constraints the database enforces. A dialect not listed gets
|
|
7
11
|
`DialectSemantics()`, whose arithmetic, collation and `||` are the cautious
|
|
8
12
|
choice; only its keys are taken as enforced, as before dialects were listed.
|
|
9
13
|
|
|
10
|
-
Every flag is a claim
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
arithmetic raises or returns NULL depending on ANSI mode, so it may return
|
|
14
|
-
NULL. `docs/dialects.md` argues each entry and says how soundness is judged
|
|
14
|
+
Every flag is a claim about the dialect's latest release under its default
|
|
15
|
+
settings, strict modes on (ADR 0006): MySQL's `||` is OR, since the default
|
|
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
|
|
15
17
|
without DuckDB; `docs/dialect-provenance.json` records, per fact, the engine
|
|
16
18
|
versions it was certified on or the vendor doc it rests on
|
|
17
19
|
(`scripts/certify_dialects.py`).
|
|
@@ -19,7 +21,7 @@ versions it was certified on or the vendor doc it rests on
|
|
|
19
21
|
|
|
20
22
|
from __future__ import annotations
|
|
21
23
|
|
|
22
|
-
from dataclasses import dataclass
|
|
24
|
+
from dataclasses import dataclass, replace
|
|
23
25
|
from typing import Literal
|
|
24
26
|
|
|
25
27
|
# How a dialect treats a declared key (PRIMARY KEY, UNIQUE) or foreign key:
|
|
@@ -27,30 +29,39 @@ from typing import Literal
|
|
|
27
29
|
type KeyTrust = Literal["enforced", "rely", "unenforced"]
|
|
28
30
|
|
|
29
31
|
# What `a || b` is: concatenation whose NULL operand makes it NULL ("strict"),
|
|
30
|
-
# concatenation that may skip a NULL operand ("lenient", Postgres arrays)
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
type PipesMeaning = Literal["strict", "lenient", "ambiguous"] | None
|
|
32
|
+
# or concatenation that may skip a NULL operand ("lenient", Postgres arrays);
|
|
33
|
+
# None when it is not modelled (MySQL, where it is OR).
|
|
34
|
+
type PipesMeaning = Literal["strict", "lenient"] | None
|
|
34
35
|
|
|
35
36
|
# What `concat(a, ...)` does with NULL: makes the result NULL ("strict"), or
|
|
36
37
|
# skips it, so the result is never NULL ("skips-null"); None when not modelled.
|
|
37
38
|
type ConcatMeaning = Literal["strict", "skips-null"] | None
|
|
38
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
|
|
44
|
+
|
|
39
45
|
|
|
40
46
|
@dataclass(frozen=True)
|
|
41
47
|
class DialectSemantics:
|
|
42
|
-
# `+`, `-`, `*`, unary `-` and CAST
|
|
43
|
-
# value
|
|
48
|
+
# `+`, `-`, `*`, unary `-` and CAST of non-null values are never NULL: a
|
|
49
|
+
# bad value raises an error. Only NULL reasoning reads it: types and
|
|
50
|
+
# injectivity assume values stay in range in every dialect (ADR 0007).
|
|
44
51
|
checked_arithmetic: bool = False
|
|
45
52
|
# `/`, integer division and `%` by zero raise an error rather than return NULL.
|
|
46
53
|
checked_division: bool = False
|
|
54
|
+
# `sum` and `avg` of non-null values are never NULL: an overflow raises
|
|
55
|
+
# (or widens the type) rather than returning NULL, and NaN or infinity is
|
|
56
|
+
# a value, not NULL (SQLite turns NaN into NULL).
|
|
57
|
+
checked_sum: bool = False
|
|
47
58
|
# An implicit cast that fails raises an error, so a comparison, LIKE,
|
|
48
59
|
# BETWEEN, NOT or bitwise operator of non-null operands is never NULL.
|
|
49
60
|
casts_raise: bool = True
|
|
50
|
-
# VARCHAR and TEXT
|
|
51
|
-
#
|
|
52
|
-
# `default_collation`) is out of scope
|
|
53
|
-
#
|
|
61
|
+
# VARCHAR and TEXT compare by identity under the engine's shipped default
|
|
62
|
+
# collation. A setting that changes that default (DuckDB's
|
|
63
|
+
# `default_collation`) is out of scope, and a COLLATE is unsupported: it
|
|
64
|
+
# is opaque, and a column declared with one is untyped (docs/dialects.md).
|
|
54
65
|
text_is_binary: bool = False
|
|
55
66
|
# A DECIMAL declared without a scale keeps each value's own scale, so
|
|
56
67
|
# equal values (1.0, 1.00) may differ: neither identity nor exact.
|
|
@@ -60,13 +71,35 @@ class DialectSemantics:
|
|
|
60
71
|
# identical. Not where it keeps the zone it was given (Trino, Snowflake's
|
|
61
72
|
# TIMESTAMP_TZ, Oracle): equal instants in two zones differ as text.
|
|
62
73
|
zoned_timestamp_is_instant: bool = False
|
|
74
|
+
# Pairs `(T, U)`, as the engine names the types: comparing a T with a U,
|
|
75
|
+
# the engine casts the T to U, and that cast keeps different values
|
|
76
|
+
# different but changes each (a DATE becomes its midnight). Each side then
|
|
77
|
+
# fixes the other, though they are not equal (ADR 0009). A cast that keeps
|
|
78
|
+
# each value as it is (INT to BIGINT, TIMESTAMP(3) to TIMESTAMP(6)) is not
|
|
79
|
+
# listed: those sides are equal. Certified as `injective_cast(T->U)`: the
|
|
80
|
+
# date's midnight is equal to the U, and a later time that day is not
|
|
81
|
+
# (which an engine casting the U down to a DATE would match).
|
|
82
|
+
injective_casts: tuple[tuple[str, str], ...] = ()
|
|
63
83
|
pipes: PipesMeaning = None
|
|
64
84
|
concat: ConcatMeaning = None
|
|
65
85
|
# What `concat_ws(sep, a, ...)` does with a NULL value (a NULL separator
|
|
66
86
|
# makes it NULL either way); None where it does not exist or is not modelled.
|
|
67
87
|
concat_ws: ConcatMeaning = None
|
|
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
|
|
91
|
+
# The column order of `*` over `a JOIN b USING (k, ...)`. "standard": the
|
|
92
|
+
# USING columns first in the USING list's order, then the left input's
|
|
93
|
+
# others, then the right's. "left_position": each USING column stays at its
|
|
94
|
+
# left input's position (DuckDB, SQLite: probed). "left_order": the USING
|
|
95
|
+
# columns first, but in the left input's column order (MySQL: probed).
|
|
96
|
+
# docs/dialects.md, "Stars and names".
|
|
97
|
+
using_star_order: Literal["standard", "left_position", "left_order"] = "standard"
|
|
68
98
|
unique_keys: KeyTrust = "enforced"
|
|
69
99
|
foreign_keys: KeyTrust = "enforced"
|
|
100
|
+
# CHECK constraints. Where the dialect has none (Snowflake, BigQuery,
|
|
101
|
+
# Redshift, Trino), one in the SQL describes a table another engine holds.
|
|
102
|
+
check_constraints: KeyTrust = "enforced"
|
|
70
103
|
# A PRIMARY KEY column is NOT NULL.
|
|
71
104
|
primary_key_not_null: bool = True
|
|
72
105
|
# A column-level `REFERENCES` is enforced (MySQL before 9.0 parses and ignores it).
|
|
@@ -83,6 +116,67 @@ class DialectSemantics:
|
|
|
83
116
|
# it is no soundness claim and is not certified: a wrong True suggests SQL
|
|
84
117
|
# the engine rejects, never a wrong proof.
|
|
85
118
|
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
|
+
# The type of a number literal that is not an integer, by kind, as the
|
|
143
|
+
# engine names the type (`literal_type(KIND)=TYPE`): "decimal", a literal
|
|
144
|
+
# written with a point (`0.1`), and "exponent", one written with an exponent
|
|
145
|
+
# (`1e0`). An exact type compares by value; a float rounds. A literal of a
|
|
146
|
+
# kind not listed has no type claimed, so it types and binds nothing.
|
|
147
|
+
# Certified with the engine's type function (`scripts/certify_dialects.py`),
|
|
148
|
+
# else cited, else a best guess from memory marked tentative (ADR 0007).
|
|
149
|
+
# An integer literal is an INT where it fits, else a BIGINT, in every dialect.
|
|
150
|
+
literal_types: tuple[tuple[str, str], ...] = ()
|
|
151
|
+
# The type a VALUES column has when every non-NULL value in it is a
|
|
152
|
+
# literal of one kind (NULL does not change it), by kind, as the engine
|
|
153
|
+
# names the type (`values_type(KIND)=TYPE`): "string"; "integer", each
|
|
154
|
+
# value within INTEGER's range; "bigint", each within BIGINT's and one
|
|
155
|
+
# beyond INTEGER's (the column has its widest row's type); "decimal", each
|
|
156
|
+
# written `d.f` with a whole part that does not start with 0, a type
|
|
157
|
+
# DECIMAL(p, s) of the widest whole part and scale. A kind not listed, a
|
|
158
|
+
# column of mixed kinds, of any other literal (a boolean, an exponent, a
|
|
159
|
+
# whole part 0, an integer beyond BIGINT) and of any expression stay untyped.
|
|
160
|
+
# A string type claims only that it is text: whether it compares by
|
|
161
|
+
# identity is `text_is_binary`, as for a declared column.
|
|
162
|
+
values_types: tuple[tuple[str, str], ...] = ()
|
|
163
|
+
# The columns, in order, that `SELECT * FROM f(...)` returns for a table
|
|
164
|
+
# function (or UNNEST, as `unnest`) of one argument list, by lower-case
|
|
165
|
+
# name (`table_function(NAME)=COLUMNS`): whatever its arguments, and
|
|
166
|
+
# whether or not the alias lists column names, which rename the leading
|
|
167
|
+
# columns. A function not listed, an UNNEST of several arguments or WITH
|
|
168
|
+
# ORDINALITY has columns not known without the data or the engine. So has
|
|
169
|
+
# one whose columns follow its argument's type: Spark's `explode` has `col`
|
|
170
|
+
# for an array and `key`, `value` for a map. An UNNEST of a list of
|
|
171
|
+
# structs is the one exception no entry can state: it is one column here
|
|
172
|
+
# (named by the alias), though BigQuery and Redshift spread the struct's
|
|
173
|
+
# fields over columns (docs/dialects.md).
|
|
174
|
+
table_functions: tuple[tuple[str, tuple[str, ...]], ...] = ()
|
|
175
|
+
# The one-column functions of `table_functions` whose column an alias with
|
|
176
|
+
# no column list names, as DuckDB does (`range(3) AS r` is the column `r`).
|
|
177
|
+
# Not one whose column the engine names itself (Spark's `range(3) AS r` is
|
|
178
|
+
# still `id`).
|
|
179
|
+
alias_named_table_functions: tuple[str, ...] = ()
|
|
86
180
|
|
|
87
181
|
@property
|
|
88
182
|
def rely(self) -> bool:
|
|
@@ -90,102 +184,450 @@ class DialectSemantics:
|
|
|
90
184
|
return "rely" in (self.unique_keys, self.foreign_keys)
|
|
91
185
|
|
|
92
186
|
|
|
187
|
+
# Spark 4 and Databricks under ANSI mode, their default (ADR 0006): overflow
|
|
188
|
+
# and a bad CAST raise. Apache Spark's docs say `div` by zero is NULL and do
|
|
189
|
+
# not say a failed implicit cast in a comparison raises; Databricks's say
|
|
190
|
+
# both raise (docs/dialect-provenance.json).
|
|
93
191
|
_SPARK = DialectSemantics(
|
|
94
|
-
|
|
95
|
-
# raise or return NULL; it is on by default only in recent versions.
|
|
192
|
+
checked_arithmetic=True,
|
|
96
193
|
casts_raise=False,
|
|
194
|
+
text_is_binary=True, # UTF8_BINARY is the default collation.
|
|
97
195
|
zoned_timestamp_is_instant=True,
|
|
196
|
+
# Tentative: a DATE beside a TIMESTAMP (an instant) is its midnight in
|
|
197
|
+
# the session zone, beside a TIMESTAMP_NTZ its midnight.
|
|
198
|
+
injective_casts=(("DATE", "TIMESTAMP"), ("DATE", "TIMESTAMP_NTZ")),
|
|
98
199
|
pipes="strict",
|
|
99
200
|
concat="strict",
|
|
100
201
|
concat_ws="skips-null",
|
|
202
|
+
# Certified on Spark 4.3, not Databricks (`databricks` below drops them).
|
|
203
|
+
checked_sum=True,
|
|
204
|
+
greatest="skips-null",
|
|
205
|
+
subscript_strict=True,
|
|
101
206
|
unique_keys="rely",
|
|
102
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).
|
|
103
211
|
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
|
+
values_types=(("string", "string"), ("integer", "int"), ("bigint", "bigint"), ("decimal", "decimal")),
|
|
231
|
+
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
232
|
+
# Tentative. `range(n)` has the one column `id`, whatever its alias. Not
|
|
233
|
+
# `explode`, `posexplode` or `inline`: an array, a map or a struct gives
|
|
234
|
+
# different columns, and the SQL alone does not say which it reads.
|
|
235
|
+
table_functions=(("range", ("id",)),),
|
|
104
236
|
)
|
|
105
237
|
|
|
238
|
+
# What `json_each` and `json_tree` return, in DuckDB and SQLite alike.
|
|
239
|
+
_JSON_TABLE_COLUMNS = ("key", "value", "type", "atom", "id", "parent", "fullkey", "path")
|
|
240
|
+
|
|
106
241
|
_SEMANTICS: dict[str, DialectSemantics] = {
|
|
107
242
|
"duckdb": DialectSemantics(
|
|
243
|
+
# A DATE compared with a TIMESTAMP is its midnight (probed); with a
|
|
244
|
+
# TIMESTAMP WITH TIME ZONE, its midnight in the session zone.
|
|
245
|
+
injective_casts=(("DATE", "TIMESTAMP"), ("DATE", "TIMESTAMP WITH TIME ZONE")),
|
|
108
246
|
checked_arithmetic=True,
|
|
247
|
+
checked_sum=True,
|
|
109
248
|
text_is_binary=True,
|
|
110
249
|
zoned_timestamp_is_instant=True,
|
|
111
250
|
pipes="strict",
|
|
112
251
|
concat="skips-null",
|
|
113
252
|
concat_ws="skips-null",
|
|
253
|
+
greatest="skips-null",
|
|
254
|
+
subscript_strict=True,
|
|
255
|
+
using_star_order="left_position",
|
|
114
256
|
set_operations_all=True,
|
|
257
|
+
result_types=(
|
|
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"),
|
|
284
|
+
values_types=(("string", "VARCHAR"), ("integer", "INTEGER"), ("bigint", "BIGINT"), ("decimal", "DECIMAL")),
|
|
285
|
+
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
286
|
+
table_functions=(
|
|
287
|
+
("json_each", _JSON_TABLE_COLUMNS), ("json_tree", _JSON_TABLE_COLUMNS),
|
|
288
|
+
("range", ("range",)), ("generate_series", ("generate_series",)), ("unnest", ("unnest",)),
|
|
289
|
+
),
|
|
290
|
+
alias_named_table_functions=("range", "generate_series", "unnest"),
|
|
115
291
|
),
|
|
116
292
|
"postgres": DialectSemantics(
|
|
293
|
+
# Tentative: date = timestamp(tz) compares the date's midnight.
|
|
294
|
+
injective_casts=(("date", "timestamp"), ("date", "timestamptz")),
|
|
117
295
|
checked_arithmetic=True,
|
|
118
296
|
checked_division=True,
|
|
297
|
+
checked_sum=True,
|
|
119
298
|
text_is_binary=True,
|
|
120
299
|
unscaled_decimal=True,
|
|
121
300
|
zoned_timestamp_is_instant=True,
|
|
122
301
|
pipes="lenient", # `ARRAY[1] || NULL` is `{1}`.
|
|
123
302
|
concat="skips-null",
|
|
124
303
|
concat_ws="skips-null",
|
|
304
|
+
greatest="skips-null",
|
|
305
|
+
subscript_strict=True,
|
|
125
306
|
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
|
+
# A numeric literal with a point is an unscaled NUMERIC: no decimal is claimed.
|
|
330
|
+
values_types=(("string", "text"), ("integer", "integer"), ("bigint", "bigint")),
|
|
331
|
+
# A numeric constant with a point or an exponent is a NUMERIC (an unscaled one).
|
|
332
|
+
literal_types=(("decimal", "numeric"), ("exponent", "numeric")),
|
|
333
|
+
# Certified on Postgres 18.6 (docs/dialect-provenance.json). A function returning a base
|
|
334
|
+
# type has one column, named by the function or, for an alias with no
|
|
335
|
+
# column list, by the alias (`alias_named_table_functions`); one with a
|
|
336
|
+
# single named OUT parameter has that name whatever the alias
|
|
337
|
+
# (`jsonb_array_elements(x) AS r` is `value`), and one with several is
|
|
338
|
+
# a record of them. Not an array of rows (`unnest` spreads its fields),
|
|
339
|
+
# not several arguments (`unnest(a, b)`), not `WITH ORDINALITY`.
|
|
340
|
+
table_functions=(
|
|
341
|
+
("generate_series", ("generate_series",)), ("unnest", ("unnest",)),
|
|
342
|
+
("regexp_split_to_table", ("regexp_split_to_table",)),
|
|
343
|
+
*((name, ("value",)) for name in (
|
|
344
|
+
"jsonb_array_elements", "json_array_elements", "jsonb_array_elements_text", "json_array_elements_text",
|
|
345
|
+
)),
|
|
346
|
+
*((name, ("key", "value")) for name in ("jsonb_each", "json_each", "jsonb_each_text", "json_each_text")),
|
|
347
|
+
),
|
|
348
|
+
alias_named_table_functions=("generate_series", "unnest", "regexp_split_to_table"),
|
|
126
349
|
),
|
|
127
350
|
"mysql": DialectSemantics(
|
|
351
|
+
# Tentative: a DATE beside a DATETIME is its midnight. Not TIMESTAMP:
|
|
352
|
+
# it is compared as a local DATETIME, and the fall-back hour gives two
|
|
353
|
+
# instants one local time.
|
|
354
|
+
injective_casts=(("DATE", "DATETIME"),),
|
|
355
|
+
# `*` over USING: the USING columns first, in the left input's order (probed, 8.4).
|
|
356
|
+
using_star_order="left_order",
|
|
128
357
|
# MySQL under its default strict sql_mode only (docs/dialects.md), so
|
|
129
358
|
# a comparison of non-null operands is non-null. Not `checked_arithmetic`:
|
|
130
359
|
# `-x` of the least BIGINT is an exact DECIMAL rather than an error, and
|
|
131
360
|
# division by zero is NULL in any mode.
|
|
361
|
+
# `sum` of integers is an exact DECIMAL, and a DOUBLE holds no
|
|
362
|
+
# infinity or NaN (a DOUBLE sum that overflows is 0).
|
|
363
|
+
checked_sum=True,
|
|
132
364
|
# Not `text_is_binary`: the default collations ignore case (and
|
|
133
365
|
# accents, and some trailing spaces).
|
|
134
366
|
zoned_timestamp_is_instant=True, # TIMESTAMP is converted to UTC.
|
|
135
|
-
pipes="ambiguous",
|
|
136
367
|
concat="strict",
|
|
137
368
|
concat_ws="skips-null",
|
|
369
|
+
greatest="strict",
|
|
370
|
+
# Not `subscript_strict`: MySQL has no `xs[i]`.
|
|
138
371
|
inline_references=False,
|
|
139
372
|
foreign_key_engines=frozenset({"innodb", "ndb", "ndbcluster"}),
|
|
140
373
|
enum_strips_trailing_spaces=True,
|
|
141
374
|
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
|
+
# Every integer literal is a BIGINT. MySQL spells a row `ROW(...)`, which is not lowered.
|
|
392
|
+
values_types=(("string", "varchar"), ("integer", "bigint"), ("bigint", "bigint"), ("decimal", "decimal")),
|
|
393
|
+
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
142
394
|
),
|
|
143
395
|
"snowflake": DialectSemantics(
|
|
396
|
+
# Tentative: a DATE beside a TIMESTAMP_NTZ (TIMESTAMP and DATETIME by
|
|
397
|
+
# default) is its midnight. Not TIMESTAMP_TZ: it keeps the zone.
|
|
398
|
+
injective_casts=(("DATE", "TIMESTAMP_NTZ"), ("DATE", "TIMESTAMP"), ("DATE", "DATETIME")),
|
|
144
399
|
# Not `checked_arithmetic`: its docs never say integer overflow raises.
|
|
145
400
|
checked_division=True,
|
|
401
|
+
text_is_binary=True, # With no COLLATE, text compares by its UTF-8 representation.
|
|
146
402
|
pipes="strict",
|
|
147
403
|
concat="strict",
|
|
148
404
|
concat_ws="strict", # `concat_ws(',', 'a', NULL)` is NULL.
|
|
149
405
|
unique_keys="rely",
|
|
150
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
|
+
# 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
|
+
# `0.1` is a NUMBER(1,1) (tentative, from memory); the docs give `1e10` an exact NUMBER(11,0).
|
|
431
|
+
literal_types=(("decimal", "NUMBER"), ("exponent", "NUMBER")),
|
|
151
432
|
),
|
|
152
433
|
"bigquery": DialectSemantics(
|
|
434
|
+
# Tentative: a DATE beside a DATETIME is its midnight.
|
|
435
|
+
injective_casts=(("DATE", "DATETIME"),),
|
|
153
436
|
checked_arithmetic=True,
|
|
154
437
|
checked_division=True,
|
|
438
|
+
# Its docs: overflow raises, and NaN or an infinity makes NaN or an infinity.
|
|
439
|
+
checked_sum=True,
|
|
440
|
+
text_is_binary=True, # With no collation specification, binary collation.
|
|
155
441
|
zoned_timestamp_is_instant=True,
|
|
156
442
|
pipes="strict",
|
|
157
443
|
concat="strict",
|
|
158
444
|
unique_keys="unenforced",
|
|
159
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
|
+
# A decimal is written `NUMERIC '0.1'`: `0.1` is a FLOAT64.
|
|
480
|
+
literal_types=(("decimal", "DOUBLE"), ("exponent", "DOUBLE")),
|
|
481
|
+
# Tentative. `UNNEST(xs) AS x` has the one column `x` (SQLGlot reads the alias as a column list).
|
|
482
|
+
table_functions=(("unnest", ("unnest",)),),
|
|
160
483
|
),
|
|
161
484
|
"redshift": DialectSemantics(
|
|
485
|
+
# Tentative: a DATE beside a TIMESTAMP or TIMESTAMPTZ is its midnight.
|
|
486
|
+
injective_casts=(("DATE", "TIMESTAMP"), ("DATE", "TIMESTAMPTZ")),
|
|
162
487
|
checked_arithmetic=True,
|
|
163
488
|
checked_division=True,
|
|
489
|
+
# Not `checked_sum`: its docs say nothing of a sum that overflows or meets NaN.
|
|
490
|
+
# Not `text_is_binary`: a comparison ignores trailing spaces, in VARCHAR too.
|
|
164
491
|
zoned_timestamp_is_instant=True,
|
|
165
492
|
pipes="strict",
|
|
166
493
|
unique_keys="unenforced",
|
|
167
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
|
+
# Tentative, from memory: `0.1` is a NUMERIC as in PostgreSQL, `1e0` a DOUBLE PRECISION.
|
|
515
|
+
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
516
|
+
# Tentative. Unnesting a SUPER array, `FROM t, t.xs AS x`, has the one column `x` (SQLGlot reads it as an UNNEST).
|
|
517
|
+
table_functions=(("unnest", ("unnest",)),),
|
|
518
|
+
),
|
|
519
|
+
"databricks": replace(
|
|
520
|
+
_SPARK, checked_division=True, casts_raise=True,
|
|
521
|
+
# Certified on Apache Spark only; Databricks's docs do not say a sum meets NaN as a value.
|
|
522
|
+
checked_sum=False, greatest=None, subscript_strict=False,
|
|
168
523
|
),
|
|
169
|
-
"databricks": _SPARK,
|
|
170
524
|
"spark": _SPARK,
|
|
171
|
-
"
|
|
172
|
-
|
|
525
|
+
"hive": DialectSemantics(casts_raise=False, pipes="strict", concat="strict", unique_keys="unenforced", foreign_keys="unenforced",
|
|
526
|
+
# Tentative: a DATE beside a TIMESTAMP is its midnight.
|
|
527
|
+
injective_casts=(("DATE", "TIMESTAMP"),),
|
|
528
|
+
check_constraints="unenforced",
|
|
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"),
|
|
543
|
+
# A decimal literal is a DOUBLE unless it has a `BD` suffix.
|
|
544
|
+
literal_types=(("decimal", "DOUBLE"), ("exponent", "DOUBLE")),
|
|
545
|
+
),
|
|
546
|
+
# SQLite claims no function result type: a value's type is its own
|
|
547
|
+
# (storage class), not its expression's.
|
|
173
548
|
"sqlite": DialectSemantics(
|
|
549
|
+
# No `injective_casts`: SQLite has no date or time type.
|
|
174
550
|
pipes="strict",
|
|
175
551
|
concat_ws="skips-null",
|
|
552
|
+
using_star_order="left_position",
|
|
176
553
|
# Foreign keys are checked only under `PRAGMA foreign_keys = ON`, off by default.
|
|
177
554
|
foreign_keys="unenforced",
|
|
178
555
|
# Only an INTEGER PRIMARY KEY (the rowid) is never NULL.
|
|
179
556
|
primary_key_not_null=False,
|
|
557
|
+
table_functions=(("json_each", _JSON_TABLE_COLUMNS), ("json_tree", _JSON_TABLE_COLUMNS)),
|
|
558
|
+
# A number with a point or an exponent is a REAL, a float.
|
|
559
|
+
literal_types=(("decimal", "real"), ("exponent", "real")),
|
|
180
560
|
),
|
|
181
561
|
# A ClickHouse primary key orders and indexes a table; it never rejects a duplicate.
|
|
182
|
-
|
|
183
|
-
|
|
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
|
+
"clickhouse": DialectSemantics(
|
|
566
|
+
# Tentative: a Date beside a DateTime or DateTime64 is its midnight.
|
|
567
|
+
injective_casts=(("Date", "DateTime"), ("Date", "DateTime64")),
|
|
568
|
+
concat_ws="strict", unique_keys="unenforced", foreign_keys="unenforced", hash_functions=("MD5Digest", "SHA", "SHA2"),
|
|
569
|
+
# Tentative (probed by hand on 26.10, not certified): of a Nullable or
|
|
570
|
+
# LowCardinality argument, the result is wrapped alike. Not `abs`
|
|
571
|
+
# (Int32 gives UInt32) or `date_trunc` (by the unit).
|
|
572
|
+
result_types=(
|
|
573
|
+
*((node, "UInt64") for node in ("Length", "StrPosition", "Anonymous:octet_length",)),
|
|
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
|
+
),
|
|
583
|
+
literal_types=(("decimal", "Float64"), ("exponent", "Float64")),
|
|
584
|
+
),
|
|
585
|
+
"oracle": DialectSemantics(
|
|
586
|
+
# Tentative: a DATE beside a TIMESTAMP keeps its time of day. Not
|
|
587
|
+
# TIMESTAMP WITH TIME ZONE: it keeps the zone.
|
|
588
|
+
injective_casts=(("DATE", "TIMESTAMP"),),
|
|
589
|
+
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
|
+
# A number literal without an `f` or `d` suffix is a NUMBER, point or exponent alike.
|
|
620
|
+
literal_types=(("decimal", "NUMBER"), ("exponent", "NUMBER")),
|
|
621
|
+
),
|
|
184
622
|
# Trino has no constraint but NOT NULL: its CREATE TABLE rejects a key, so
|
|
185
623
|
# one in the SQL describes a table some other engine holds.
|
|
186
624
|
"trino": DialectSemantics(
|
|
625
|
+
# Tentative: a DATE beside a TIMESTAMP(p) is its midnight. Not
|
|
626
|
+
# TIMESTAMP WITH TIME ZONE: it keeps the zone.
|
|
627
|
+
injective_casts=(("DATE", "TIMESTAMP"),),
|
|
187
628
|
checked_arithmetic=True,
|
|
188
629
|
checked_division=True,
|
|
630
|
+
checked_sum=True,
|
|
189
631
|
# VARCHAR compares by code point and Trino has no collations.
|
|
190
632
|
text_is_binary=True,
|
|
191
633
|
# Not `zoned_timestamp_is_instant`: a TIMESTAMP WITH TIME ZONE keeps
|
|
@@ -193,11 +635,46 @@ _SEMANTICS: dict[str, DialectSemantics] = {
|
|
|
193
635
|
# Unlike Postgres, a NULL array or element operand makes `||` NULL too.
|
|
194
636
|
pipes="strict",
|
|
195
637
|
concat="strict",
|
|
638
|
+
greatest="strict",
|
|
639
|
+
# NULL for a NULL array or map; an index out of range raises.
|
|
640
|
+
subscript_strict=True,
|
|
196
641
|
# Not modelled: it skips a NULL VARCHAR, but its ARRAY(VARCHAR)
|
|
197
642
|
# overload is NULL for a NULL array, and SQLGlot parses both alike.
|
|
198
643
|
unique_keys="unenforced",
|
|
199
644
|
foreign_keys="unenforced",
|
|
645
|
+
check_constraints="unenforced",
|
|
200
646
|
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
|
+
# A string is `varchar(n)` for its longest value.
|
|
669
|
+
values_types=(("string", "varchar"), ("integer", "integer"), ("bigint", "bigint"), ("decimal", "decimal")),
|
|
670
|
+
literal_types=(("decimal", "DECIMAL"), ("exponent", "DOUBLE")),
|
|
671
|
+
# Certified on Trino 484 (docs/dialect-provenance.json). `UNNEST(xs) AS u(x)` of one
|
|
672
|
+
# array has the one column `x`: Trino requires a column list to name it
|
|
673
|
+
# (an unaliased column has no name), and rejects one of another length.
|
|
674
|
+
# Not an array of rows (one column per field), a map (`k`, `v`), several
|
|
675
|
+
# arguments, nor `WITH ORDINALITY`; an alias list longer than one name
|
|
676
|
+
# reads as one of those.
|
|
677
|
+
table_functions=(("unnest", ("unnest",)),),
|
|
201
678
|
),
|
|
202
679
|
}
|
|
203
680
|
|