sqllens 1.0.0 → 1.2.0
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.
- package/LICENSE +0 -10
- package/README.md +95 -85
- package/THIRD-PARTY-NOTICES.md +70 -5
- package/dist/api.d.ts +5 -3
- package/dist/api.js +17 -4
- package/dist/bigquery/behavior.d.ts +2 -0
- package/dist/bigquery/behavior.js +20 -0
- package/dist/bigquery/dot-path.d.ts +0 -2
- package/dist/bigquery/dot-path.js +0 -1
- package/dist/bigquery/fold.d.ts +8 -0
- package/dist/bigquery/fold.js +39 -0
- package/dist/bigquery/index.d.ts +7 -0
- package/dist/bigquery/index.js +10 -0
- package/dist/{infer/bigquery.d.ts → bigquery/infer.d.ts} +2 -2
- package/dist/{infer/bigquery.js → bigquery/infer.js} +4 -3
- package/dist/bigquery/lower.js +35 -12
- package/dist/bigquery/signatures.generated.d.ts +6 -0
- package/dist/bigquery/signatures.generated.js +1068 -0
- package/dist/completion/atn-walk.d.ts +13 -2
- package/dist/completion/atn-walk.js +13 -10
- package/dist/completion/complete.d.ts +4 -3
- package/dist/completion/complete.js +101 -45
- package/dist/completion/config.js +66 -0
- package/dist/completion/jinja-slot.d.ts +24 -0
- package/dist/completion/jinja-slot.js +126 -0
- package/dist/completion/parser-factory.d.ts +13 -1
- package/dist/completion/parser-factory.js +48 -0
- package/dist/databricks/behavior.d.ts +2 -0
- package/dist/databricks/behavior.js +19 -0
- package/dist/databricks/fold.d.ts +8 -0
- package/dist/databricks/fold.js +27 -0
- package/dist/databricks/index.d.ts +7 -0
- package/dist/databricks/index.js +10 -0
- package/dist/databricks/infer.d.ts +6 -0
- package/dist/databricks/infer.js +638 -0
- package/dist/databricks/signatures.generated.d.ts +6 -0
- package/dist/databricks/signatures.generated.js +1745 -0
- package/dist/derived-dialects.js +19 -1
- package/dist/dialect-behavior/behavior.d.ts +26 -0
- package/dist/dialect-behavior/behavior.js +1 -0
- package/dist/dialect-behavior/carrier.d.ts +5 -0
- package/dist/dialect-behavior/carrier.js +5 -0
- package/dist/dialect-behavior/coerce-rules.d.ts +7 -0
- package/dist/dialect-behavior/coerce-rules.js +69 -0
- package/dist/dialect-behavior/public-fold.d.ts +6 -0
- package/dist/dialect-behavior/public-fold.js +9 -0
- package/dist/dialect-behavior/registry.d.ts +6 -0
- package/dist/dialect-behavior/registry.js +34 -0
- package/dist/dialect-symbols.js +22 -17
- package/dist/dialect.d.ts +2 -2
- package/dist/document/document.d.ts +1 -1
- package/dist/document/document.js +8 -7
- package/dist/duckdb/behavior.d.ts +2 -0
- package/dist/duckdb/behavior.js +21 -0
- package/dist/duckdb/fold.d.ts +8 -0
- package/dist/duckdb/fold.js +29 -0
- package/dist/duckdb/index.d.ts +7 -0
- package/dist/duckdb/index.js +10 -0
- package/dist/{infer/duckdb.d.ts → duckdb/infer.d.ts} +2 -2
- package/dist/{infer/duckdb.js → duckdb/infer.js} +4 -3
- package/dist/duckdb/lower.js +47 -15
- package/dist/duckdb/signatures.generated.d.ts +6 -0
- package/dist/duckdb/signatures.generated.js +1072 -0
- package/dist/generated/bigquery/GoogleSQLParser.js +0 -7060
- package/dist/generated/databricks/DatabricksParser.js +0 -4800
- package/dist/generated/duckdb/DuckdbParser.js +0 -9100
- package/dist/generated/minijinja/MinijinjaParser.js +0 -380
- package/dist/generated/mysql/MysqlLexer.js +7357 -0
- package/dist/generated/mysql/MysqlParser.js +78520 -0
- package/dist/generated/postgres/PostgresParser.js +0 -8530
- package/dist/generated/redshift/RedshiftParser.js +0 -10970
- package/dist/generated/snowflake/SnowflakeParser.js +0 -7320
- package/dist/generated/sqlite/SqliteLexer.js +945 -0
- package/dist/generated/sqlite/SqliteParser.js +14682 -0
- package/dist/generated/trino/TrinoParser.js +0 -3770
- package/dist/generated/tsql/TSqlParser.js +0 -8420
- package/dist/ident/fold.d.ts +24 -15
- package/dist/ident/fold.js +12 -145
- package/dist/index.d.ts +6 -2
- package/dist/index.js +14 -8
- package/dist/infer/functions.d.ts +22 -11
- package/dist/infer/functions.js +26 -888
- package/dist/infer/infer.js +16 -14
- package/dist/infer/nullability.js +3 -4
- package/dist/infer/types.d.ts +1 -1
- package/dist/infer/types.js +7 -7
- package/dist/ir/ir.d.ts +26 -17
- package/dist/ir/part-span.d.ts +16 -1
- package/dist/ir/part-span.js +38 -10
- package/dist/ir/span.js +0 -2
- package/dist/ir/walk.js +3 -3
- package/dist/lineage/hops.js +13 -10
- package/dist/lineage/lineage.js +10 -7
- package/dist/minijinja/apply-tags.d.ts +14 -7
- package/dist/minijinja/apply-tags.js +66 -121
- package/dist/minijinja/parse.js +6 -6
- package/dist/minijinja/tag-ast.d.ts +29 -36
- package/dist/minijinja/tag-ast.js +210 -90
- package/dist/mysql/behavior.d.ts +2 -0
- package/dist/mysql/behavior.js +21 -0
- package/dist/mysql/fold.d.ts +8 -0
- package/dist/mysql/fold.js +49 -0
- package/dist/mysql/index.d.ts +7 -0
- package/dist/mysql/index.js +10 -0
- package/dist/mysql/infer.d.ts +20 -0
- package/dist/mysql/infer.js +156 -0
- package/dist/mysql/lower.d.ts +13 -0
- package/dist/mysql/lower.js +1443 -0
- package/dist/mysql/parse.d.ts +10 -0
- package/dist/mysql/parse.js +70 -0
- package/dist/mysql/signatures.generated.d.ts +6 -0
- package/dist/mysql/signatures.generated.js +508 -0
- package/dist/postgres/behavior.d.ts +2 -0
- package/dist/postgres/behavior.js +19 -0
- package/dist/postgres/fold.d.ts +8 -0
- package/dist/postgres/fold.js +30 -0
- package/dist/postgres/index.d.ts +7 -0
- package/dist/postgres/index.js +10 -0
- package/dist/{infer/postgres.d.ts → postgres/infer.d.ts} +2 -2
- package/dist/{infer/postgres.js → postgres/infer.js} +4 -3
- package/dist/postgres/lower.js +2 -2
- package/dist/postgres/signatures.generated.d.ts +6 -0
- package/dist/postgres/signatures.generated.js +2973 -0
- package/dist/qualify/check-calls.js +80 -134
- package/dist/qualify/qualify.js +16 -14
- package/dist/qualify/schema-provider.js +2 -2
- package/dist/qualify/schema.js +3 -3
- package/dist/qualify/template-provider.d.ts +45 -12
- package/dist/qualify/template-provider.js +69 -38
- package/dist/redshift/behavior.d.ts +2 -0
- package/dist/redshift/behavior.js +19 -0
- package/dist/redshift/fold.d.ts +8 -0
- package/dist/redshift/fold.js +31 -0
- package/dist/redshift/index.d.ts +7 -0
- package/dist/redshift/index.js +10 -0
- package/dist/{infer/redshift.d.ts → redshift/infer.d.ts} +2 -2
- package/dist/{infer/redshift.js → redshift/infer.js} +4 -3
- package/dist/redshift/lower.js +2 -2
- package/dist/redshift/signatures.generated.d.ts +6 -0
- package/dist/redshift/signatures.generated.js +757 -0
- package/dist/references/references.js +17 -12
- package/dist/scope/like-pattern.d.ts +2 -0
- package/dist/scope/like-pattern.js +15 -0
- package/dist/scope/scope.d.ts +5 -5
- package/dist/scope/scope.js +48 -42
- package/dist/sema/resolve.js +17 -12
- package/dist/session.d.ts +2 -2
- package/dist/signature/signature.d.ts +14 -6
- package/dist/signature/signature.js +30 -22
- package/dist/signature/signatures.d.ts +14 -12
- package/dist/signature/signatures.js +42 -582
- package/dist/snowflake/behavior.d.ts +2 -0
- package/dist/snowflake/behavior.js +22 -0
- package/dist/snowflake/fold.d.ts +8 -0
- package/dist/snowflake/fold.js +25 -0
- package/dist/snowflake/index.d.ts +7 -0
- package/dist/snowflake/index.js +10 -0
- package/dist/{infer/snowflake.d.ts → snowflake/infer.d.ts} +2 -2
- package/dist/{infer/snowflake.js → snowflake/infer.js} +4 -3
- package/dist/snowflake/lower.js +59 -19
- package/dist/snowflake/signatures.generated.d.ts +6 -0
- package/dist/snowflake/signatures.generated.js +2080 -0
- package/dist/sqlite/behavior.d.ts +2 -0
- package/dist/sqlite/behavior.js +19 -0
- package/dist/sqlite/fold.d.ts +8 -0
- package/dist/sqlite/fold.js +41 -0
- package/dist/sqlite/index.d.ts +7 -0
- package/dist/sqlite/index.js +10 -0
- package/dist/sqlite/infer.d.ts +12 -0
- package/dist/sqlite/infer.js +122 -0
- package/dist/sqlite/lower.d.ts +11 -0
- package/dist/sqlite/lower.js +1093 -0
- package/dist/sqlite/parse.d.ts +10 -0
- package/dist/sqlite/parse.js +70 -0
- package/dist/sqlite/signatures.generated.d.ts +6 -0
- package/dist/sqlite/signatures.generated.js +277 -0
- package/dist/symbols/symbols.js +14 -12
- package/dist/token/classify.js +31 -0
- package/dist/token/tokenize.js +4 -0
- package/dist/trino/behavior.d.ts +2 -0
- package/dist/trino/behavior.js +21 -0
- package/dist/trino/fold.d.ts +8 -0
- package/dist/trino/fold.js +39 -0
- package/dist/trino/index.d.ts +7 -0
- package/dist/trino/index.js +10 -0
- package/dist/{infer/trino.d.ts → trino/infer.d.ts} +2 -2
- package/dist/{infer/trino.js → trino/infer.js} +4 -3
- package/dist/trino/lower.js +5 -5
- package/dist/trino/signatures.generated.d.ts +6 -0
- package/dist/trino/signatures.generated.js +968 -0
- package/dist/tsql/behavior.d.ts +2 -0
- package/dist/tsql/behavior.js +20 -0
- package/dist/tsql/fold.d.ts +8 -0
- package/dist/tsql/fold.js +34 -0
- package/dist/tsql/index.d.ts +7 -0
- package/dist/tsql/index.js +10 -0
- package/dist/tsql/infer.d.ts +16 -0
- package/dist/tsql/infer.js +289 -0
- package/dist/tsql/lower.js +4 -4
- package/dist/tsql/signatures.generated.d.ts +6 -0
- package/dist/tsql/signatures.generated.js +640 -0
- package/package.json +15 -11
- package/dist/generated/bigquery/GoogleSQLLexer.d.ts +0 -407
- package/dist/generated/bigquery/GoogleSQLParser.d.ts +0 -9558
- package/dist/generated/bigquery/GoogleSQLParserListener.d.ts +0 -7777
- package/dist/generated/bigquery/GoogleSQLParserListener.js +0 -7070
- package/dist/generated/databricks/DatabricksLexer.d.ts +0 -566
- package/dist/generated/databricks/DatabricksParser.d.ts +0 -7771
- package/dist/generated/databricks/DatabricksParserListener.d.ts +0 -5737
- package/dist/generated/databricks/DatabricksParserListener.js +0 -5256
- package/dist/generated/duckdb/DuckdbLexer.d.ts +0 -691
- package/dist/generated/duckdb/DuckdbParser.d.ts +0 -13932
- package/dist/generated/duckdb/DuckdbParserListener.d.ts +0 -10049
- package/dist/generated/duckdb/DuckdbParserListener.js +0 -9138
- package/dist/generated/minijinja/MinijinjaLexer.d.ts +0 -108
- package/dist/generated/minijinja/MinijinjaParser.d.ts +0 -604
- package/dist/generated/minijinja/MinijinjaParserListener.d.ts +0 -449
- package/dist/generated/minijinja/MinijinjaParserListener.js +0 -410
- package/dist/generated/postgres/PostgresLexer.d.ts +0 -663
- package/dist/generated/postgres/PostgresParser.d.ts +0 -12963
- package/dist/generated/postgres/PostgresParserListener.d.ts +0 -9408
- package/dist/generated/postgres/PostgresParserListener.js +0 -8554
- package/dist/generated/redshift/RedshiftLexer.d.ts +0 -954
- package/dist/generated/redshift/RedshiftParser.d.ts +0 -16939
- package/dist/generated/redshift/RedshiftParserListener.d.ts +0 -12092
- package/dist/generated/redshift/RedshiftParserListener.js +0 -10994
- package/dist/generated/snowflake/SnowflakeLexer.d.ts +0 -1046
- package/dist/generated/snowflake/SnowflakeParser.d.ts +0 -14196
- package/dist/generated/snowflake/SnowflakeParserListener.d.ts +0 -8063
- package/dist/generated/snowflake/SnowflakeParserListener.js +0 -7330
- package/dist/generated/trino/TrinoLexer.d.ts +0 -381
- package/dist/generated/trino/TrinoParser.d.ts +0 -5340
- package/dist/generated/trino/TrinoParserListener.d.ts +0 -4704
- package/dist/generated/trino/TrinoParserListener.js +0 -4326
- package/dist/generated/tsql/TSqlLexer.d.ts +0 -1278
- package/dist/generated/tsql/TSqlParser.d.ts +0 -17267
- package/dist/generated/tsql/TSqlParserListener.d.ts +0 -9697
- package/dist/generated/tsql/TSqlParserListener.js +0 -8854
- package/dist/infer/dialect.d.ts +0 -21
- package/dist/infer/dialect.js +0 -74
- package/dist/infer/literals.d.ts +0 -6
- package/dist/infer/literals.js +0 -44
- package/dist/signature/generated/tsql.d.ts +0 -3
- package/dist/signature/generated/tsql.js +0 -260
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
import { commonType, widenSum } from "../infer/coerce.js";
|
|
2
|
+
import { B, BIG, BIN, D, DATE, I, INTERVAL, S, TS, arrayOfCommon, arrayOfFirst, common, concatRule, dateArg, elementOf, fixed, firstArg, group, mapKeys, mapValues, restCommon, } from "../infer/functions.js";
|
|
3
|
+
import { parseType, scalar, UNKNOWN } from "../infer/types.js";
|
|
4
|
+
import { fold } from "./fold.js";
|
|
5
|
+
// Function return-type registry for Databricks/Spark SQL, from the built-in function
|
|
6
|
+
// reference (the language spec — NOT the corpus; the corpus is only a validation gate). A
|
|
7
|
+
// rule is `(argTypes) => Type`. A function is absent (→ unknown) only when its return type is
|
|
8
|
+
// genuinely arg/lambda/schema-dependent in a way we don't model yet (transform, from_json,
|
|
9
|
+
// named_struct, …). We never guess: a missing rule yields `unknown`, never a wrong type.
|
|
10
|
+
//
|
|
11
|
+
// Why a rule is a *function* and not a fixed type string — and what each dialect calls a
|
|
12
|
+
// return-type-follows-input ("templated"/"polymorphic"/generic) function: docs/type-polymorphism.md.
|
|
13
|
+
export const DATABRICKS_FUNCTION_RETURNS = {
|
|
14
|
+
...group(fixed(S), [
|
|
15
|
+
"concat_ws",
|
|
16
|
+
"upper",
|
|
17
|
+
"lower",
|
|
18
|
+
"lcase",
|
|
19
|
+
"ucase",
|
|
20
|
+
"trim",
|
|
21
|
+
"ltrim",
|
|
22
|
+
"rtrim",
|
|
23
|
+
"btrim",
|
|
24
|
+
"lpad",
|
|
25
|
+
"rpad",
|
|
26
|
+
"substr",
|
|
27
|
+
"substring",
|
|
28
|
+
"substring_index",
|
|
29
|
+
"replace",
|
|
30
|
+
"translate",
|
|
31
|
+
"repeat",
|
|
32
|
+
"split_part",
|
|
33
|
+
"chr",
|
|
34
|
+
"char",
|
|
35
|
+
"initcap",
|
|
36
|
+
"overlay",
|
|
37
|
+
"format_string",
|
|
38
|
+
"format_number",
|
|
39
|
+
"printf",
|
|
40
|
+
"soundex",
|
|
41
|
+
"space",
|
|
42
|
+
"hex",
|
|
43
|
+
"base64",
|
|
44
|
+
"to_char",
|
|
45
|
+
"to_varchar",
|
|
46
|
+
"quote",
|
|
47
|
+
"regexp_extract",
|
|
48
|
+
"regexp_replace",
|
|
49
|
+
"regexp_substr",
|
|
50
|
+
"url_encode",
|
|
51
|
+
"url_decode",
|
|
52
|
+
"bin",
|
|
53
|
+
"conv",
|
|
54
|
+
"md5",
|
|
55
|
+
"sha",
|
|
56
|
+
"sha1",
|
|
57
|
+
"sha2",
|
|
58
|
+
"date_format",
|
|
59
|
+
"dayname",
|
|
60
|
+
"monthname",
|
|
61
|
+
"string_agg",
|
|
62
|
+
"listagg",
|
|
63
|
+
"to_json",
|
|
64
|
+
"get_json_object",
|
|
65
|
+
"string",
|
|
66
|
+
]),
|
|
67
|
+
...group(fixed(I), [
|
|
68
|
+
"ascii",
|
|
69
|
+
"instr",
|
|
70
|
+
"locate",
|
|
71
|
+
"position",
|
|
72
|
+
"find_in_set",
|
|
73
|
+
"levenshtein",
|
|
74
|
+
"length",
|
|
75
|
+
"char_length",
|
|
76
|
+
"character_length",
|
|
77
|
+
"octet_length",
|
|
78
|
+
"bit_length",
|
|
79
|
+
"regexp_count",
|
|
80
|
+
"regexp_instr",
|
|
81
|
+
"sign",
|
|
82
|
+
"signum",
|
|
83
|
+
"bit_get",
|
|
84
|
+
"getbit",
|
|
85
|
+
"day",
|
|
86
|
+
"dayofmonth",
|
|
87
|
+
"dayofweek",
|
|
88
|
+
"dayofyear",
|
|
89
|
+
"month",
|
|
90
|
+
"year",
|
|
91
|
+
"hour",
|
|
92
|
+
"minute",
|
|
93
|
+
"second",
|
|
94
|
+
"quarter",
|
|
95
|
+
"weekday",
|
|
96
|
+
"weekofyear",
|
|
97
|
+
"unix_date",
|
|
98
|
+
"size",
|
|
99
|
+
"array_size",
|
|
100
|
+
"cardinality",
|
|
101
|
+
"array_position",
|
|
102
|
+
"hash",
|
|
103
|
+
"json_array_length",
|
|
104
|
+
"datediff",
|
|
105
|
+
"date_diff",
|
|
106
|
+
"date_part",
|
|
107
|
+
"datepart",
|
|
108
|
+
"int",
|
|
109
|
+
"integer",
|
|
110
|
+
"tinyint",
|
|
111
|
+
"smallint",
|
|
112
|
+
]),
|
|
113
|
+
...group(fixed(BIG), [
|
|
114
|
+
"count",
|
|
115
|
+
"count_if",
|
|
116
|
+
"approx_count_distinct",
|
|
117
|
+
"div",
|
|
118
|
+
"bit_count",
|
|
119
|
+
"bit_and",
|
|
120
|
+
"bit_or",
|
|
121
|
+
"bit_xor",
|
|
122
|
+
"shiftrightunsigned",
|
|
123
|
+
"width_bucket",
|
|
124
|
+
"unix_timestamp",
|
|
125
|
+
"unix_millis",
|
|
126
|
+
"unix_micros",
|
|
127
|
+
"unix_seconds",
|
|
128
|
+
"crc32",
|
|
129
|
+
"xxhash64",
|
|
130
|
+
"bigint",
|
|
131
|
+
"long",
|
|
132
|
+
]),
|
|
133
|
+
...group(fixed(D), [
|
|
134
|
+
"avg",
|
|
135
|
+
"sqrt",
|
|
136
|
+
"cbrt",
|
|
137
|
+
"exp",
|
|
138
|
+
"expm1",
|
|
139
|
+
"log",
|
|
140
|
+
"ln",
|
|
141
|
+
"log10",
|
|
142
|
+
"log2",
|
|
143
|
+
"log1p",
|
|
144
|
+
"sin",
|
|
145
|
+
"cos",
|
|
146
|
+
"tan",
|
|
147
|
+
"asin",
|
|
148
|
+
"acos",
|
|
149
|
+
"atan",
|
|
150
|
+
"sinh",
|
|
151
|
+
"cosh",
|
|
152
|
+
"tanh",
|
|
153
|
+
"asinh",
|
|
154
|
+
"acosh",
|
|
155
|
+
"atanh",
|
|
156
|
+
"atan2",
|
|
157
|
+
"degrees",
|
|
158
|
+
"radians",
|
|
159
|
+
"cot",
|
|
160
|
+
"csc",
|
|
161
|
+
"sec",
|
|
162
|
+
"hypot",
|
|
163
|
+
"pow",
|
|
164
|
+
"power",
|
|
165
|
+
"rand",
|
|
166
|
+
"random",
|
|
167
|
+
"randn",
|
|
168
|
+
"pi",
|
|
169
|
+
"e",
|
|
170
|
+
"rint",
|
|
171
|
+
"nanvl",
|
|
172
|
+
"stddev",
|
|
173
|
+
"std",
|
|
174
|
+
"stddev_pop",
|
|
175
|
+
"stddev_samp",
|
|
176
|
+
"variance",
|
|
177
|
+
"var_samp",
|
|
178
|
+
"var_pop",
|
|
179
|
+
"corr",
|
|
180
|
+
"covar_pop",
|
|
181
|
+
"covar_samp",
|
|
182
|
+
"kurtosis",
|
|
183
|
+
"skewness",
|
|
184
|
+
"percentile",
|
|
185
|
+
"percentile_cont",
|
|
186
|
+
"approx_percentile",
|
|
187
|
+
"median",
|
|
188
|
+
"months_between",
|
|
189
|
+
"double",
|
|
190
|
+
]),
|
|
191
|
+
...group(fixed(B), [
|
|
192
|
+
"startswith",
|
|
193
|
+
"endswith",
|
|
194
|
+
"contains",
|
|
195
|
+
"isnan",
|
|
196
|
+
"isnull",
|
|
197
|
+
"isnotnull",
|
|
198
|
+
"array_contains",
|
|
199
|
+
"arrays_overlap",
|
|
200
|
+
"map_contains_key",
|
|
201
|
+
"exists",
|
|
202
|
+
"forall",
|
|
203
|
+
"any",
|
|
204
|
+
"bool_or",
|
|
205
|
+
"bool_and",
|
|
206
|
+
"every",
|
|
207
|
+
"like",
|
|
208
|
+
"rlike",
|
|
209
|
+
"ilike",
|
|
210
|
+
"boolean",
|
|
211
|
+
]),
|
|
212
|
+
...group(fixed(DATE), [
|
|
213
|
+
"current_date",
|
|
214
|
+
"curdate",
|
|
215
|
+
"to_date",
|
|
216
|
+
"date",
|
|
217
|
+
"date_from_unix_date",
|
|
218
|
+
"make_date",
|
|
219
|
+
"next_day",
|
|
220
|
+
"last_day",
|
|
221
|
+
]),
|
|
222
|
+
...group(fixed(TS), [
|
|
223
|
+
"current_timestamp",
|
|
224
|
+
"now",
|
|
225
|
+
"to_timestamp",
|
|
226
|
+
"to_timestamp_ltz",
|
|
227
|
+
"to_timestamp_ntz",
|
|
228
|
+
"make_timestamp",
|
|
229
|
+
"make_timestamp_ltz",
|
|
230
|
+
"make_timestamp_ntz",
|
|
231
|
+
"timestamp_millis",
|
|
232
|
+
"timestamp_micros",
|
|
233
|
+
"timestamp_seconds",
|
|
234
|
+
"from_utc_timestamp",
|
|
235
|
+
"to_utc_timestamp",
|
|
236
|
+
"convert_timezone",
|
|
237
|
+
"localtimestamp",
|
|
238
|
+
"date_trunc",
|
|
239
|
+
"timestamp",
|
|
240
|
+
]),
|
|
241
|
+
...group(fixed(BIN), ["unhex", "unbase64", "encode", "to_binary", "binary"]),
|
|
242
|
+
...group(fixed(INTERVAL), ["make_interval", "make_ym_interval", "make_dt_interval"]),
|
|
243
|
+
float: fixed(scalar("float")),
|
|
244
|
+
decimal: fixed(scalar("decimal")),
|
|
245
|
+
// same type as input (numeric ops, ordering aggregates, array → array transforms)
|
|
246
|
+
...group(firstArg, [
|
|
247
|
+
"abs",
|
|
248
|
+
"negative",
|
|
249
|
+
"positive",
|
|
250
|
+
"ceil",
|
|
251
|
+
"ceiling",
|
|
252
|
+
"floor",
|
|
253
|
+
"round",
|
|
254
|
+
"bround",
|
|
255
|
+
"trunc",
|
|
256
|
+
"mod",
|
|
257
|
+
"pmod",
|
|
258
|
+
"shiftleft",
|
|
259
|
+
"shiftright",
|
|
260
|
+
"min",
|
|
261
|
+
"max",
|
|
262
|
+
"first",
|
|
263
|
+
"first_value",
|
|
264
|
+
"last",
|
|
265
|
+
"last_value",
|
|
266
|
+
"nth_value",
|
|
267
|
+
"max_by",
|
|
268
|
+
"min_by",
|
|
269
|
+
"any_value",
|
|
270
|
+
"mode",
|
|
271
|
+
"percentile_disc",
|
|
272
|
+
"nullif",
|
|
273
|
+
"nullifzero",
|
|
274
|
+
"zeroifnull",
|
|
275
|
+
"reverse",
|
|
276
|
+
"array_distinct",
|
|
277
|
+
"array_union",
|
|
278
|
+
"array_intersect",
|
|
279
|
+
"array_except",
|
|
280
|
+
"array_remove",
|
|
281
|
+
"array_compact",
|
|
282
|
+
"array_sort",
|
|
283
|
+
"sort_array",
|
|
284
|
+
"shuffle",
|
|
285
|
+
"slice",
|
|
286
|
+
"array_append",
|
|
287
|
+
"array_prepend",
|
|
288
|
+
"array_insert",
|
|
289
|
+
"array_repeat",
|
|
290
|
+
"filter",
|
|
291
|
+
]),
|
|
292
|
+
...group(common, ["coalesce", "ifnull", "nvl", "greatest", "least"]),
|
|
293
|
+
...group(restCommon, ["if", "iff", "nvl2"]),
|
|
294
|
+
sum: (args) => widenSum(args[0] ?? UNKNOWN),
|
|
295
|
+
...group(arrayOfFirst, ["collect_list", "collect_set", "array_agg", "sequence", "range"]),
|
|
296
|
+
array: arrayOfCommon,
|
|
297
|
+
...group(fixed({ kind: "array", element: S }), ["split", "regexp_extract_all"]),
|
|
298
|
+
...group(elementOf, ["array_max", "array_min", "element_at", "explode", "explode_outer", "get"]),
|
|
299
|
+
map_keys: mapKeys,
|
|
300
|
+
map_values: mapValues,
|
|
301
|
+
concat: concatRule,
|
|
302
|
+
...group(dateArg, ["date_add", "dateadd", "date_sub", "timestampadd", "add_months"]),
|
|
303
|
+
// window/ranking — Spark's ranking functions return int (T-SQL's return bigint); the
|
|
304
|
+
// value-returning analytics keep their argument's type.
|
|
305
|
+
...group(fixed(I), ["row_number", "rank", "dense_rank", "ntile"]),
|
|
306
|
+
...group(fixed(D), ["percent_rank", "cume_dist"]),
|
|
307
|
+
...group(firstArg, ["lag", "lead"]),
|
|
308
|
+
// string-returning system / session functions
|
|
309
|
+
...group(fixed(S), [
|
|
310
|
+
"current_user",
|
|
311
|
+
"current_database",
|
|
312
|
+
"current_schema",
|
|
313
|
+
"current_catalog",
|
|
314
|
+
"collation",
|
|
315
|
+
"randstr",
|
|
316
|
+
"uuid",
|
|
317
|
+
]),
|
|
318
|
+
factorial: fixed(BIG),
|
|
319
|
+
bitmap_count: fixed(BIG),
|
|
320
|
+
// ------------------------------------------------------------------
|
|
321
|
+
// Entries below: return types fetched from the official Databricks
|
|
322
|
+
// reference 2026-06-10 (the H3 / ST geospatial / AI / IP family pages
|
|
323
|
+
// and per-function "Returns" sections). A function whose documented
|
|
324
|
+
// return type depends on an argument VALUE (ai_query, from_avro,
|
|
325
|
+
// extract, …) or whose page states no type stays absent → unknown.
|
|
326
|
+
// ------------------------------------------------------------------
|
|
327
|
+
// T-SQL-compat aliases Databricks documents
|
|
328
|
+
...group(fixed(S), ["left", "right", "mask"]),
|
|
329
|
+
len: fixed(I),
|
|
330
|
+
charindex: fixed(I), // synonym of position/locate — "An INTEGER"
|
|
331
|
+
getdate: fixed(TS), // synonym of current_timestamp
|
|
332
|
+
getbit: fixed(I),
|
|
333
|
+
// VARIANT family
|
|
334
|
+
...group(fixed(scalar("variant")), ["parse_json", "try_parse_json", "to_variant_object"]),
|
|
335
|
+
...group(fixed(S), ["schema_of_variant", "schema_of_variant_agg"]),
|
|
336
|
+
is_variant_null: fixed(B),
|
|
337
|
+
// variant_get(v, path) → VARIANT; the 3-arg form's type is named by a literal we
|
|
338
|
+
// don't evaluate, so unknown.
|
|
339
|
+
...group((args) => (args.length >= 3 ? UNKNOWN : scalar("variant")), ["variant_get", "try_variant_get"]),
|
|
340
|
+
// schema/conversion helpers
|
|
341
|
+
...group(fixed(S), ["schema_of_csv", "schema_of_json", "schema_of_json_agg", "schema_of_xml", "to_csv", "to_xml"]),
|
|
342
|
+
json_object_keys: fixed({ kind: "array", element: S }),
|
|
343
|
+
...group(fixed(scalar("decimal")), ["to_number", "try_to_number"]),
|
|
344
|
+
...group(fixed(TS), ["parse_timestamp", "try_parse_timestamp"]),
|
|
345
|
+
to_unix_timestamp: fixed(BIG),
|
|
346
|
+
...group(fixed(BIN), [
|
|
347
|
+
"aes_encrypt",
|
|
348
|
+
"aes_decrypt",
|
|
349
|
+
"try_aes_decrypt",
|
|
350
|
+
"zstd_compress",
|
|
351
|
+
"zstd_decompress",
|
|
352
|
+
"try_zstd_decompress",
|
|
353
|
+
"to_avro",
|
|
354
|
+
"try_to_binary",
|
|
355
|
+
]),
|
|
356
|
+
// TIME type family (sql-ref-datatypes TIME)
|
|
357
|
+
...group(fixed(scalar("time")), [
|
|
358
|
+
"to_time",
|
|
359
|
+
"try_to_time",
|
|
360
|
+
"make_time",
|
|
361
|
+
"current_time",
|
|
362
|
+
"time_trunc",
|
|
363
|
+
"time_from_micros",
|
|
364
|
+
"time_from_millis",
|
|
365
|
+
"time_from_seconds",
|
|
366
|
+
]),
|
|
367
|
+
...group(fixed(BIG), ["time_diff", "timediff", "time_to_micros", "time_to_millis"]),
|
|
368
|
+
time_to_seconds: fixed(scalar("decimal")),
|
|
369
|
+
// try_* arithmetic mirrors the base operators (NULL on error)
|
|
370
|
+
...group(common, ["try_add", "try_subtract", "try_multiply", "try_mod"]),
|
|
371
|
+
try_divide: (args) => (args[0]?.kind === "scalar" && args[0].name === "interval" ? args[0] : D),
|
|
372
|
+
try_sum: (args) => widenSum(args[0] ?? UNKNOWN),
|
|
373
|
+
try_avg: fixed(D),
|
|
374
|
+
try_element_at: elementOf,
|
|
375
|
+
// regression aggregates (regr_avgx/avgy: DECIMAL input stays decimal, else DOUBLE)
|
|
376
|
+
regr_count: fixed(BIG),
|
|
377
|
+
regr_avgx: (args) => (args[1]?.kind === "scalar" && args[1].name === "decimal" ? scalar("decimal") : D),
|
|
378
|
+
regr_avgy: (args) => (args[0]?.kind === "scalar" && args[0].name === "decimal" ? scalar("decimal") : D),
|
|
379
|
+
...group(fixed(D), ["regr_slope", "regr_intercept", "regr_r2", "regr_sxx", "regr_sxy", "regr_syy"]),
|
|
380
|
+
// maps
|
|
381
|
+
map_entries: (args) => args[0]?.kind === "map"
|
|
382
|
+
? {
|
|
383
|
+
kind: "array",
|
|
384
|
+
element: {
|
|
385
|
+
kind: "struct",
|
|
386
|
+
fields: [
|
|
387
|
+
{ name: "key", type: args[0].key },
|
|
388
|
+
{ name: "value", type: args[0].value },
|
|
389
|
+
],
|
|
390
|
+
},
|
|
391
|
+
}
|
|
392
|
+
: UNKNOWN,
|
|
393
|
+
map_from_arrays: (args) => ({
|
|
394
|
+
kind: "map",
|
|
395
|
+
key: args[0]?.kind === "array" ? args[0].element : UNKNOWN,
|
|
396
|
+
value: args[1]?.kind === "array" ? args[1].element : UNKNOWN,
|
|
397
|
+
}),
|
|
398
|
+
map_from_entries: (args) => {
|
|
399
|
+
const e = args[0]?.kind === "array" ? args[0].element : UNKNOWN;
|
|
400
|
+
return e.kind === "struct" && e.fields.length >= 2
|
|
401
|
+
? { kind: "map", key: e.fields[0].type, value: e.fields[1].type }
|
|
402
|
+
: UNKNOWN;
|
|
403
|
+
},
|
|
404
|
+
map_concat: common,
|
|
405
|
+
map_filter: firstArg,
|
|
406
|
+
str_to_map: fixed({ kind: "map", key: S, value: S }),
|
|
407
|
+
// misc scalars
|
|
408
|
+
...group(fixed(S), [
|
|
409
|
+
"typeof",
|
|
410
|
+
"parse_url",
|
|
411
|
+
"make_valid_utf8",
|
|
412
|
+
"validate_utf8",
|
|
413
|
+
"try_validate_utf8",
|
|
414
|
+
"version",
|
|
415
|
+
"current_metastore",
|
|
416
|
+
"current_timezone",
|
|
417
|
+
"java_method",
|
|
418
|
+
"reflect",
|
|
419
|
+
"try_reflect",
|
|
420
|
+
"array_join",
|
|
421
|
+
]),
|
|
422
|
+
...group(fixed(B), ["luhn_check", "equal_null", "is_valid_utf8", "is_account_group_member", "is_member", "some"]),
|
|
423
|
+
flatten: (args) => (args[0]?.kind === "array" && args[0].element.kind === "array" ? args[0].element : UNKNOWN),
|
|
424
|
+
uniform: (args) => commonType(args.slice(0, 2)),
|
|
425
|
+
// decode(expr, search1, result1, …[, default]) → least common type of the results
|
|
426
|
+
decode: (args) => {
|
|
427
|
+
if (args.length === 2)
|
|
428
|
+
return S; // decode(binary, charset) overload
|
|
429
|
+
const results = [];
|
|
430
|
+
for (let i = 2; i < args.length; i += 2)
|
|
431
|
+
results.push(args[i]);
|
|
432
|
+
if (args.length > 3 && (args.length - 1) % 2 === 1)
|
|
433
|
+
results.push(args[args.length - 1]);
|
|
434
|
+
return commonType(results);
|
|
435
|
+
},
|
|
436
|
+
elt: restCommon,
|
|
437
|
+
percentile_approx: (args) => args[1]?.kind === "array" ? { kind: "array", element: args[0] ?? UNKNOWN } : (args[0] ?? UNKNOWN),
|
|
438
|
+
histogram_numeric: (args) => ({
|
|
439
|
+
kind: "array",
|
|
440
|
+
element: {
|
|
441
|
+
kind: "struct",
|
|
442
|
+
fields: [
|
|
443
|
+
{ name: "x", type: args[0] ?? UNKNOWN },
|
|
444
|
+
{ name: "y", type: D },
|
|
445
|
+
],
|
|
446
|
+
},
|
|
447
|
+
}),
|
|
448
|
+
...group(fixed({
|
|
449
|
+
kind: "struct",
|
|
450
|
+
fields: [
|
|
451
|
+
{ name: "start", type: TS },
|
|
452
|
+
{ name: "end", type: TS },
|
|
453
|
+
],
|
|
454
|
+
}), ["window", "session_window"]),
|
|
455
|
+
window_time: fixed(TS),
|
|
456
|
+
http_request: fixed({
|
|
457
|
+
kind: "struct",
|
|
458
|
+
fields: [
|
|
459
|
+
{ name: "status_code", type: I },
|
|
460
|
+
{ name: "text", type: S },
|
|
461
|
+
],
|
|
462
|
+
}),
|
|
463
|
+
...group(fixed(BIG), ["monotonically_increasing_id", "input_file_block_length", "input_file_block_start"]),
|
|
464
|
+
input_file_name: fixed(S),
|
|
465
|
+
// bitmaps
|
|
466
|
+
...group(fixed(BIG), ["bitmap_bucket_number", "bitmap_bit_position"]),
|
|
467
|
+
...group(fixed(BIN), ["bitmap_construct_agg", "bitmap_or_agg", "bitmap_and_agg"]),
|
|
468
|
+
// H3 geospatial (sql-ref-h3-geospatial-functions)
|
|
469
|
+
...group(fixed(BIG), ["h3_longlatash3", "h3_pointash3", "h3_stringtoh3"]),
|
|
470
|
+
...group(fixed(S), [
|
|
471
|
+
"h3_longlatash3string",
|
|
472
|
+
"h3_pointash3string",
|
|
473
|
+
"h3_h3tostring",
|
|
474
|
+
"h3_boundaryasgeojson",
|
|
475
|
+
"h3_boundaryaswkt",
|
|
476
|
+
"h3_centerasgeojson",
|
|
477
|
+
"h3_centeraswkt",
|
|
478
|
+
]),
|
|
479
|
+
...group(fixed(BIN), ["h3_boundaryaswkb", "h3_centeraswkb"]),
|
|
480
|
+
...group(fixed(B), ["h3_ischildof", "h3_ispentagon", "h3_isvalid"]),
|
|
481
|
+
...group(fixed({ kind: "array", element: BIG }), [
|
|
482
|
+
"h3_coverash3",
|
|
483
|
+
"h3_polyfillash3",
|
|
484
|
+
"h3_try_coverash3",
|
|
485
|
+
"h3_try_polyfillash3",
|
|
486
|
+
]),
|
|
487
|
+
...group(fixed({ kind: "array", element: S }), [
|
|
488
|
+
"h3_coverash3string",
|
|
489
|
+
"h3_polyfillash3string",
|
|
490
|
+
"h3_try_coverash3string",
|
|
491
|
+
"h3_try_polyfillash3string",
|
|
492
|
+
]),
|
|
493
|
+
// cell-id in → same cell-id type out (the family's BIGINT/STRING pairing)
|
|
494
|
+
...group(firstArg, ["h3_validate", "h3_try_validate", "h3_compact", "h3_uncompact"]),
|
|
495
|
+
...group(arrayOfFirst, ["h3_kring", "h3_hexring", "h3_tochildren"]),
|
|
496
|
+
h3_kringdistances: (args) => ({
|
|
497
|
+
kind: "array",
|
|
498
|
+
element: {
|
|
499
|
+
kind: "struct",
|
|
500
|
+
fields: [
|
|
501
|
+
{ name: "cellid", type: args[0] ?? UNKNOWN },
|
|
502
|
+
{ name: "distance", type: I },
|
|
503
|
+
],
|
|
504
|
+
},
|
|
505
|
+
}),
|
|
506
|
+
// ST geospatial (sql-ref-st-geospatial-functions)
|
|
507
|
+
...group(fixed(scalar("geography")), [
|
|
508
|
+
"st_geogfromewkt",
|
|
509
|
+
"st_geogfromgeojson",
|
|
510
|
+
"st_geogfromtext",
|
|
511
|
+
"st_geogfromwkb",
|
|
512
|
+
"st_geogfromwkt",
|
|
513
|
+
"to_geography",
|
|
514
|
+
"try_to_geography",
|
|
515
|
+
]),
|
|
516
|
+
...group(fixed(scalar("geometry")), [
|
|
517
|
+
"st_geomfromewkb",
|
|
518
|
+
"st_geomfromewkt",
|
|
519
|
+
"st_geomfromgeohash",
|
|
520
|
+
"st_geomfromgeojson",
|
|
521
|
+
"st_geomfromtext",
|
|
522
|
+
"st_geomfromwkb",
|
|
523
|
+
"st_geomfromwkt",
|
|
524
|
+
"st_pointfromgeohash",
|
|
525
|
+
"to_geometry",
|
|
526
|
+
"try_to_geometry",
|
|
527
|
+
"st_makeenvelope",
|
|
528
|
+
"st_makeline",
|
|
529
|
+
"st_makepoint",
|
|
530
|
+
"st_makepolygon",
|
|
531
|
+
"st_point",
|
|
532
|
+
"st_envelope",
|
|
533
|
+
"st_envelope_agg",
|
|
534
|
+
"st_geometryn",
|
|
535
|
+
"st_setsrid",
|
|
536
|
+
"st_transform",
|
|
537
|
+
"st_rotate",
|
|
538
|
+
"st_scale",
|
|
539
|
+
"st_translate",
|
|
540
|
+
"st_flipcoordinates",
|
|
541
|
+
"st_boundary",
|
|
542
|
+
"st_buffer",
|
|
543
|
+
"st_centroid",
|
|
544
|
+
"st_closestpoint",
|
|
545
|
+
"st_concavehull",
|
|
546
|
+
"st_convexhull",
|
|
547
|
+
"st_pointonsurface",
|
|
548
|
+
"st_simplify",
|
|
549
|
+
"st_difference",
|
|
550
|
+
"st_intersection",
|
|
551
|
+
"st_union",
|
|
552
|
+
"st_union_agg",
|
|
553
|
+
]),
|
|
554
|
+
...group(fixed(BIN), ["st_asbinary", "st_asewkb", "st_aswkb"]),
|
|
555
|
+
...group(fixed(S), ["st_asgeojson", "st_asewkt", "st_astext", "st_aswkt", "st_geohash", "st_geometrytype"]),
|
|
556
|
+
...group(fixed(B), [
|
|
557
|
+
"st_isempty",
|
|
558
|
+
"st_isvalid",
|
|
559
|
+
"st_dwithin",
|
|
560
|
+
"st_contains",
|
|
561
|
+
"st_covers",
|
|
562
|
+
"st_disjoint",
|
|
563
|
+
"st_equals",
|
|
564
|
+
"st_intersects",
|
|
565
|
+
"st_touches",
|
|
566
|
+
"st_within",
|
|
567
|
+
]),
|
|
568
|
+
...group(fixed(I), ["st_npoints", "st_numpoints", "st_srid"]),
|
|
569
|
+
st_area: fixed(D),
|
|
570
|
+
st_collect: firstArg,
|
|
571
|
+
st_dump: arrayOfFirst,
|
|
572
|
+
// point/linestring accessors keep the input's GEOGRAPHY/GEOMETRY type
|
|
573
|
+
...group(firstArg, [
|
|
574
|
+
"st_endpoint",
|
|
575
|
+
"st_startpoint",
|
|
576
|
+
"st_pointn",
|
|
577
|
+
"st_exteriorring",
|
|
578
|
+
"st_interiorringn",
|
|
579
|
+
"st_addpoint",
|
|
580
|
+
"st_force2d",
|
|
581
|
+
"st_multi",
|
|
582
|
+
"st_removepoint",
|
|
583
|
+
"st_reverse",
|
|
584
|
+
"st_setpoint",
|
|
585
|
+
]),
|
|
586
|
+
// AI functions (ai-functions page); ai_classify/ai_extract/ai_query/ai_forecast are
|
|
587
|
+
// argument-value-dependent → absent
|
|
588
|
+
...group(fixed(S), [
|
|
589
|
+
"ai_analyze_sentiment",
|
|
590
|
+
"ai_fix_grammar",
|
|
591
|
+
"ai_gen",
|
|
592
|
+
"ai_generate_text",
|
|
593
|
+
"ai_mask",
|
|
594
|
+
"ai_summarize",
|
|
595
|
+
"ai_translate",
|
|
596
|
+
]),
|
|
597
|
+
ai_similarity: fixed(scalar("float")),
|
|
598
|
+
...group(fixed(scalar("variant")), ["ai_parse_document", "ai_prep_search"]),
|
|
599
|
+
// IP functions (sql-ref-ip-functions)
|
|
600
|
+
...group(fixed(BIN), ["ip_as_binary", "try_ip_as_binary"]),
|
|
601
|
+
...group(fixed(S), ["ip_as_string", "try_ip_as_string"]),
|
|
602
|
+
ip_cidr_contains: fixed(B),
|
|
603
|
+
...group(fixed(I), ["ip_prefix_length", "ip_version"]),
|
|
604
|
+
...group(firstArg, [
|
|
605
|
+
"ip_cidr",
|
|
606
|
+
"ip_host",
|
|
607
|
+
"ip_network",
|
|
608
|
+
"ip_network_first",
|
|
609
|
+
"ip_network_last",
|
|
610
|
+
"try_ip_cidr",
|
|
611
|
+
"try_ip_host",
|
|
612
|
+
]),
|
|
613
|
+
};
|
|
614
|
+
const BOOLEAN = scalar("boolean");
|
|
615
|
+
/** Databricks/Spark literal forms. */
|
|
616
|
+
export function databricksLiteral(text) {
|
|
617
|
+
const t = text.trim();
|
|
618
|
+
if (/^['"]/.test(t))
|
|
619
|
+
return scalar("string");
|
|
620
|
+
if (/^(true|false)$/i.test(t))
|
|
621
|
+
return BOOLEAN;
|
|
622
|
+
if (/^null$/i.test(t))
|
|
623
|
+
return UNKNOWN;
|
|
624
|
+
if (/^date\s*'/i.test(t))
|
|
625
|
+
return scalar("date");
|
|
626
|
+
if (/^timestamp\s*'/i.test(t))
|
|
627
|
+
return scalar("timestamp");
|
|
628
|
+
if (/^interval\b/i.test(t))
|
|
629
|
+
return scalar("interval");
|
|
630
|
+
if (/^[+-]?\d+$/.test(t))
|
|
631
|
+
return scalar("int");
|
|
632
|
+
if (/^[+-]?(\d+\.\d*|\.\d+|\d+)([eed][+-]?\d+)?$/i.test(t) && /[.eed]/i.test(t))
|
|
633
|
+
return scalar("double");
|
|
634
|
+
return UNKNOWN;
|
|
635
|
+
}
|
|
636
|
+
export function databricksParseType(text) {
|
|
637
|
+
return parseType(text, undefined, fold);
|
|
638
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FnSignature } from "../signature/signatures.js";
|
|
2
|
+
/** The merged function-signature table for databricks: curated overrides folded over the harvested
|
|
3
|
+
* doc-derived long tail (overrides win by key, replacing the whole overload set), keyed by
|
|
4
|
+
* lowercased name. Each name maps to an ORDERED overload set - a name with one documented shape
|
|
5
|
+
* is a one-element array. `origin` says which layer produced the set. */
|
|
6
|
+
export declare const DATABRICKS_SIGNATURES: Record<string, FnSignature[]>;
|