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.
Files changed (244) hide show
  1. package/LICENSE +0 -10
  2. package/README.md +95 -85
  3. package/THIRD-PARTY-NOTICES.md +70 -5
  4. package/dist/api.d.ts +5 -3
  5. package/dist/api.js +17 -4
  6. package/dist/bigquery/behavior.d.ts +2 -0
  7. package/dist/bigquery/behavior.js +20 -0
  8. package/dist/bigquery/dot-path.d.ts +0 -2
  9. package/dist/bigquery/dot-path.js +0 -1
  10. package/dist/bigquery/fold.d.ts +8 -0
  11. package/dist/bigquery/fold.js +39 -0
  12. package/dist/bigquery/index.d.ts +7 -0
  13. package/dist/bigquery/index.js +10 -0
  14. package/dist/{infer/bigquery.d.ts → bigquery/infer.d.ts} +2 -2
  15. package/dist/{infer/bigquery.js → bigquery/infer.js} +4 -3
  16. package/dist/bigquery/lower.js +35 -12
  17. package/dist/bigquery/signatures.generated.d.ts +6 -0
  18. package/dist/bigquery/signatures.generated.js +1068 -0
  19. package/dist/completion/atn-walk.d.ts +13 -2
  20. package/dist/completion/atn-walk.js +13 -10
  21. package/dist/completion/complete.d.ts +4 -3
  22. package/dist/completion/complete.js +101 -45
  23. package/dist/completion/config.js +66 -0
  24. package/dist/completion/jinja-slot.d.ts +24 -0
  25. package/dist/completion/jinja-slot.js +126 -0
  26. package/dist/completion/parser-factory.d.ts +13 -1
  27. package/dist/completion/parser-factory.js +48 -0
  28. package/dist/databricks/behavior.d.ts +2 -0
  29. package/dist/databricks/behavior.js +19 -0
  30. package/dist/databricks/fold.d.ts +8 -0
  31. package/dist/databricks/fold.js +27 -0
  32. package/dist/databricks/index.d.ts +7 -0
  33. package/dist/databricks/index.js +10 -0
  34. package/dist/databricks/infer.d.ts +6 -0
  35. package/dist/databricks/infer.js +638 -0
  36. package/dist/databricks/signatures.generated.d.ts +6 -0
  37. package/dist/databricks/signatures.generated.js +1745 -0
  38. package/dist/derived-dialects.js +19 -1
  39. package/dist/dialect-behavior/behavior.d.ts +26 -0
  40. package/dist/dialect-behavior/behavior.js +1 -0
  41. package/dist/dialect-behavior/carrier.d.ts +5 -0
  42. package/dist/dialect-behavior/carrier.js +5 -0
  43. package/dist/dialect-behavior/coerce-rules.d.ts +7 -0
  44. package/dist/dialect-behavior/coerce-rules.js +69 -0
  45. package/dist/dialect-behavior/public-fold.d.ts +6 -0
  46. package/dist/dialect-behavior/public-fold.js +9 -0
  47. package/dist/dialect-behavior/registry.d.ts +6 -0
  48. package/dist/dialect-behavior/registry.js +34 -0
  49. package/dist/dialect-symbols.js +22 -17
  50. package/dist/dialect.d.ts +2 -2
  51. package/dist/document/document.d.ts +1 -1
  52. package/dist/document/document.js +8 -7
  53. package/dist/duckdb/behavior.d.ts +2 -0
  54. package/dist/duckdb/behavior.js +21 -0
  55. package/dist/duckdb/fold.d.ts +8 -0
  56. package/dist/duckdb/fold.js +29 -0
  57. package/dist/duckdb/index.d.ts +7 -0
  58. package/dist/duckdb/index.js +10 -0
  59. package/dist/{infer/duckdb.d.ts → duckdb/infer.d.ts} +2 -2
  60. package/dist/{infer/duckdb.js → duckdb/infer.js} +4 -3
  61. package/dist/duckdb/lower.js +47 -15
  62. package/dist/duckdb/signatures.generated.d.ts +6 -0
  63. package/dist/duckdb/signatures.generated.js +1072 -0
  64. package/dist/generated/bigquery/GoogleSQLParser.js +0 -7060
  65. package/dist/generated/databricks/DatabricksParser.js +0 -4800
  66. package/dist/generated/duckdb/DuckdbParser.js +0 -9100
  67. package/dist/generated/minijinja/MinijinjaParser.js +0 -380
  68. package/dist/generated/mysql/MysqlLexer.js +7357 -0
  69. package/dist/generated/mysql/MysqlParser.js +78520 -0
  70. package/dist/generated/postgres/PostgresParser.js +0 -8530
  71. package/dist/generated/redshift/RedshiftParser.js +0 -10970
  72. package/dist/generated/snowflake/SnowflakeParser.js +0 -7320
  73. package/dist/generated/sqlite/SqliteLexer.js +945 -0
  74. package/dist/generated/sqlite/SqliteParser.js +14682 -0
  75. package/dist/generated/trino/TrinoParser.js +0 -3770
  76. package/dist/generated/tsql/TSqlParser.js +0 -8420
  77. package/dist/ident/fold.d.ts +24 -15
  78. package/dist/ident/fold.js +12 -145
  79. package/dist/index.d.ts +6 -2
  80. package/dist/index.js +14 -8
  81. package/dist/infer/functions.d.ts +22 -11
  82. package/dist/infer/functions.js +26 -888
  83. package/dist/infer/infer.js +16 -14
  84. package/dist/infer/nullability.js +3 -4
  85. package/dist/infer/types.d.ts +1 -1
  86. package/dist/infer/types.js +7 -7
  87. package/dist/ir/ir.d.ts +26 -17
  88. package/dist/ir/part-span.d.ts +16 -1
  89. package/dist/ir/part-span.js +38 -10
  90. package/dist/ir/span.js +0 -2
  91. package/dist/ir/walk.js +3 -3
  92. package/dist/lineage/hops.js +13 -10
  93. package/dist/lineage/lineage.js +10 -7
  94. package/dist/minijinja/apply-tags.d.ts +14 -7
  95. package/dist/minijinja/apply-tags.js +66 -121
  96. package/dist/minijinja/parse.js +6 -6
  97. package/dist/minijinja/tag-ast.d.ts +29 -36
  98. package/dist/minijinja/tag-ast.js +210 -90
  99. package/dist/mysql/behavior.d.ts +2 -0
  100. package/dist/mysql/behavior.js +21 -0
  101. package/dist/mysql/fold.d.ts +8 -0
  102. package/dist/mysql/fold.js +49 -0
  103. package/dist/mysql/index.d.ts +7 -0
  104. package/dist/mysql/index.js +10 -0
  105. package/dist/mysql/infer.d.ts +20 -0
  106. package/dist/mysql/infer.js +156 -0
  107. package/dist/mysql/lower.d.ts +13 -0
  108. package/dist/mysql/lower.js +1443 -0
  109. package/dist/mysql/parse.d.ts +10 -0
  110. package/dist/mysql/parse.js +70 -0
  111. package/dist/mysql/signatures.generated.d.ts +6 -0
  112. package/dist/mysql/signatures.generated.js +508 -0
  113. package/dist/postgres/behavior.d.ts +2 -0
  114. package/dist/postgres/behavior.js +19 -0
  115. package/dist/postgres/fold.d.ts +8 -0
  116. package/dist/postgres/fold.js +30 -0
  117. package/dist/postgres/index.d.ts +7 -0
  118. package/dist/postgres/index.js +10 -0
  119. package/dist/{infer/postgres.d.ts → postgres/infer.d.ts} +2 -2
  120. package/dist/{infer/postgres.js → postgres/infer.js} +4 -3
  121. package/dist/postgres/lower.js +2 -2
  122. package/dist/postgres/signatures.generated.d.ts +6 -0
  123. package/dist/postgres/signatures.generated.js +2973 -0
  124. package/dist/qualify/check-calls.js +80 -134
  125. package/dist/qualify/qualify.js +16 -14
  126. package/dist/qualify/schema-provider.js +2 -2
  127. package/dist/qualify/schema.js +3 -3
  128. package/dist/qualify/template-provider.d.ts +45 -12
  129. package/dist/qualify/template-provider.js +69 -38
  130. package/dist/redshift/behavior.d.ts +2 -0
  131. package/dist/redshift/behavior.js +19 -0
  132. package/dist/redshift/fold.d.ts +8 -0
  133. package/dist/redshift/fold.js +31 -0
  134. package/dist/redshift/index.d.ts +7 -0
  135. package/dist/redshift/index.js +10 -0
  136. package/dist/{infer/redshift.d.ts → redshift/infer.d.ts} +2 -2
  137. package/dist/{infer/redshift.js → redshift/infer.js} +4 -3
  138. package/dist/redshift/lower.js +2 -2
  139. package/dist/redshift/signatures.generated.d.ts +6 -0
  140. package/dist/redshift/signatures.generated.js +757 -0
  141. package/dist/references/references.js +17 -12
  142. package/dist/scope/like-pattern.d.ts +2 -0
  143. package/dist/scope/like-pattern.js +15 -0
  144. package/dist/scope/scope.d.ts +5 -5
  145. package/dist/scope/scope.js +48 -42
  146. package/dist/sema/resolve.js +17 -12
  147. package/dist/session.d.ts +2 -2
  148. package/dist/signature/signature.d.ts +14 -6
  149. package/dist/signature/signature.js +30 -22
  150. package/dist/signature/signatures.d.ts +14 -12
  151. package/dist/signature/signatures.js +42 -582
  152. package/dist/snowflake/behavior.d.ts +2 -0
  153. package/dist/snowflake/behavior.js +22 -0
  154. package/dist/snowflake/fold.d.ts +8 -0
  155. package/dist/snowflake/fold.js +25 -0
  156. package/dist/snowflake/index.d.ts +7 -0
  157. package/dist/snowflake/index.js +10 -0
  158. package/dist/{infer/snowflake.d.ts → snowflake/infer.d.ts} +2 -2
  159. package/dist/{infer/snowflake.js → snowflake/infer.js} +4 -3
  160. package/dist/snowflake/lower.js +59 -19
  161. package/dist/snowflake/signatures.generated.d.ts +6 -0
  162. package/dist/snowflake/signatures.generated.js +2080 -0
  163. package/dist/sqlite/behavior.d.ts +2 -0
  164. package/dist/sqlite/behavior.js +19 -0
  165. package/dist/sqlite/fold.d.ts +8 -0
  166. package/dist/sqlite/fold.js +41 -0
  167. package/dist/sqlite/index.d.ts +7 -0
  168. package/dist/sqlite/index.js +10 -0
  169. package/dist/sqlite/infer.d.ts +12 -0
  170. package/dist/sqlite/infer.js +122 -0
  171. package/dist/sqlite/lower.d.ts +11 -0
  172. package/dist/sqlite/lower.js +1093 -0
  173. package/dist/sqlite/parse.d.ts +10 -0
  174. package/dist/sqlite/parse.js +70 -0
  175. package/dist/sqlite/signatures.generated.d.ts +6 -0
  176. package/dist/sqlite/signatures.generated.js +277 -0
  177. package/dist/symbols/symbols.js +14 -12
  178. package/dist/token/classify.js +31 -0
  179. package/dist/token/tokenize.js +4 -0
  180. package/dist/trino/behavior.d.ts +2 -0
  181. package/dist/trino/behavior.js +21 -0
  182. package/dist/trino/fold.d.ts +8 -0
  183. package/dist/trino/fold.js +39 -0
  184. package/dist/trino/index.d.ts +7 -0
  185. package/dist/trino/index.js +10 -0
  186. package/dist/{infer/trino.d.ts → trino/infer.d.ts} +2 -2
  187. package/dist/{infer/trino.js → trino/infer.js} +4 -3
  188. package/dist/trino/lower.js +5 -5
  189. package/dist/trino/signatures.generated.d.ts +6 -0
  190. package/dist/trino/signatures.generated.js +968 -0
  191. package/dist/tsql/behavior.d.ts +2 -0
  192. package/dist/tsql/behavior.js +20 -0
  193. package/dist/tsql/fold.d.ts +8 -0
  194. package/dist/tsql/fold.js +34 -0
  195. package/dist/tsql/index.d.ts +7 -0
  196. package/dist/tsql/index.js +10 -0
  197. package/dist/tsql/infer.d.ts +16 -0
  198. package/dist/tsql/infer.js +289 -0
  199. package/dist/tsql/lower.js +4 -4
  200. package/dist/tsql/signatures.generated.d.ts +6 -0
  201. package/dist/tsql/signatures.generated.js +640 -0
  202. package/package.json +15 -11
  203. package/dist/generated/bigquery/GoogleSQLLexer.d.ts +0 -407
  204. package/dist/generated/bigquery/GoogleSQLParser.d.ts +0 -9558
  205. package/dist/generated/bigquery/GoogleSQLParserListener.d.ts +0 -7777
  206. package/dist/generated/bigquery/GoogleSQLParserListener.js +0 -7070
  207. package/dist/generated/databricks/DatabricksLexer.d.ts +0 -566
  208. package/dist/generated/databricks/DatabricksParser.d.ts +0 -7771
  209. package/dist/generated/databricks/DatabricksParserListener.d.ts +0 -5737
  210. package/dist/generated/databricks/DatabricksParserListener.js +0 -5256
  211. package/dist/generated/duckdb/DuckdbLexer.d.ts +0 -691
  212. package/dist/generated/duckdb/DuckdbParser.d.ts +0 -13932
  213. package/dist/generated/duckdb/DuckdbParserListener.d.ts +0 -10049
  214. package/dist/generated/duckdb/DuckdbParserListener.js +0 -9138
  215. package/dist/generated/minijinja/MinijinjaLexer.d.ts +0 -108
  216. package/dist/generated/minijinja/MinijinjaParser.d.ts +0 -604
  217. package/dist/generated/minijinja/MinijinjaParserListener.d.ts +0 -449
  218. package/dist/generated/minijinja/MinijinjaParserListener.js +0 -410
  219. package/dist/generated/postgres/PostgresLexer.d.ts +0 -663
  220. package/dist/generated/postgres/PostgresParser.d.ts +0 -12963
  221. package/dist/generated/postgres/PostgresParserListener.d.ts +0 -9408
  222. package/dist/generated/postgres/PostgresParserListener.js +0 -8554
  223. package/dist/generated/redshift/RedshiftLexer.d.ts +0 -954
  224. package/dist/generated/redshift/RedshiftParser.d.ts +0 -16939
  225. package/dist/generated/redshift/RedshiftParserListener.d.ts +0 -12092
  226. package/dist/generated/redshift/RedshiftParserListener.js +0 -10994
  227. package/dist/generated/snowflake/SnowflakeLexer.d.ts +0 -1046
  228. package/dist/generated/snowflake/SnowflakeParser.d.ts +0 -14196
  229. package/dist/generated/snowflake/SnowflakeParserListener.d.ts +0 -8063
  230. package/dist/generated/snowflake/SnowflakeParserListener.js +0 -7330
  231. package/dist/generated/trino/TrinoLexer.d.ts +0 -381
  232. package/dist/generated/trino/TrinoParser.d.ts +0 -5340
  233. package/dist/generated/trino/TrinoParserListener.d.ts +0 -4704
  234. package/dist/generated/trino/TrinoParserListener.js +0 -4326
  235. package/dist/generated/tsql/TSqlLexer.d.ts +0 -1278
  236. package/dist/generated/tsql/TSqlParser.d.ts +0 -17267
  237. package/dist/generated/tsql/TSqlParserListener.d.ts +0 -9697
  238. package/dist/generated/tsql/TSqlParserListener.js +0 -8854
  239. package/dist/infer/dialect.d.ts +0 -21
  240. package/dist/infer/dialect.js +0 -74
  241. package/dist/infer/literals.d.ts +0 -6
  242. package/dist/infer/literals.js +0 -44
  243. package/dist/signature/generated/tsql.d.ts +0 -3
  244. package/dist/signature/generated/tsql.js +0 -260
@@ -18,15 +18,16 @@
18
18
  // overrides only the parts it knows (manifest lookups, var values, shape
19
19
  // classification) and inherits the conservative default for the rest.
20
20
  //
21
- // The default provider also carries the DBT-BUILTIN knowledge that used to be
22
- // hardcoded inside the segmenter (NO_OUTPUT_BUILTINS / SHAPE_EXCLUDED string
23
- // sets): `config`/`docs`/`print`/`log`/`return`/`exceptions` produce nothing;
24
- // `ref`/`source` produce a relation logically named by their literal args;
25
- // `env_var` produces a string. Domain knowledge lives in the provider; the
26
- // ENGINE keeps only the positional machinery (length-/newline-preserving
27
- // fills, slot guards, statement-slot handling) — non-overridable on purpose: a
28
- // provider states WHAT a call produces, never how it is spliced, so a buggy
29
- // provider can make meanings unknown but can never corrupt a parse.
21
+ // The DBT-BUILTIN knowledge (config/docs/print/log/return/exceptions produce
22
+ // nothing; ref/source produce a relation logically named by their literal args;
23
+ // env_var produces a string) is NOT minijinja knowledge and does NOT live in the
24
+ // neutral default: it lives in `DbtTemplateProvider` (below), the shipped dbt
25
+ // overlay a consumer extends. The neutral `DefaultTemplateProvider` knows no
26
+ // macro vocabulary at all. Domain knowledge lives in the provider; the ENGINE
27
+ // keeps only the positional machinery (length-/newline-preserving fills, slot
28
+ // guards, statement-slot handling) — non-overridable on purpose: a provider
29
+ // states WHAT a call produces, never how it is spliced, so a buggy provider can
30
+ // make meanings unknown but can never corrupt a parse.
30
31
  //
31
32
  // Contract points (agreed on the channel):
32
33
  // - SYNC-ONLY: every method answers from a warm cache; misses are recorded
@@ -106,39 +107,21 @@ export class DefaultTemplateProvider {
106
107
  return this._version;
107
108
  }
108
109
  // --- Granular expansion knowledge (the C#-style virtuals — override the parts you know). ---
109
- /** The relation a call produces. Default knowledge: `ref(...)` → the dbt-LOGICAL model name,
110
- * `source(a,b)` → the logical [source, table] — literal args only, never fabricated. An
111
- * overriding provider answers the PHYSICAL relation (+columns) from its manifest/describe. */
112
- relationOf(call) {
113
- if (call.packageParts !== undefined)
114
- return undefined;
115
- if (call.name === "ref") {
116
- const model = refModel(call);
117
- return typeof model === "string" ? { nameParts: [model] } : undefined;
118
- }
119
- if (call.name === "source") {
120
- const parts = sourceParts(call);
121
- if (parts && typeof parts[0] === "string" && typeof parts[1] === "string") {
122
- return { nameParts: [parts[0], parts[1]] };
123
- }
124
- }
110
+ /** The relation a call produces. The NEUTRAL floor knows no macro vocabulary, so it answers
111
+ * undefined for everything: `ref`/`source` are dbt macros, not minijinja knowledge, and live in
112
+ * `DbtTemplateProvider`. An overriding provider answers the relation (+columns) it knows. */
113
+ relationOf(_call) {
125
114
  return undefined;
126
115
  }
127
- /** The scalar value a call yields. Default knowledge: `env_var` returns a string (dbt docs);
128
- * `var` and user macros are unknown. */
129
- valueOf(call) {
130
- if (call.packageParts === undefined && call.name === "env_var")
131
- return { type: "string" };
116
+ /** The scalar value a call yields. Neutral floor: unknown (no macro vocabulary). `env_var` is a
117
+ * dbt builtin known by `DbtTemplateProvider`. */
118
+ valueOf(_call) {
132
119
  return undefined;
133
120
  }
134
- /** The rendered-output shape of a call. Default knowledge: the no-output builtins → "nothing".
135
- * Everything else unknown (the engine derives a shape from stronger fields, or falls back to
136
- * its positional fill). */
137
- shapeOf(call) {
138
- if (call.packageParts === undefined && NO_OUTPUT_BUILTINS.has(call.name))
139
- return "nothing";
140
- if (call.packageParts !== undefined && NO_OUTPUT_BUILTINS.has(call.packageParts[0] ?? ""))
141
- return "nothing";
121
+ /** The rendered-output shape of a call. Neutral floor: unknown (the engine derives a shape from
122
+ * stronger fields, or falls back to its positional fill). The dbt no-output builtins → "nothing"
123
+ * is `DbtTemplateProvider` knowledge. */
124
+ shapeOf(_call) {
142
125
  return undefined;
143
126
  }
144
127
  /** The columns a column-list-producing macro emits. Default: unknown. */
@@ -149,6 +132,15 @@ export class DefaultTemplateProvider {
149
132
  collectionOf(_call) {
150
133
  return undefined;
151
134
  }
135
+ /** Completion candidates for a template call slot: the caret sits in `callee`'s positional argument
136
+ * `argIndex` (a dbt ref's arg 0 answers the model names, a source's arg 0 the source names, arg 1
137
+ * the table names). `argIndex` is -1 when the caret is still in the callee name itself, so a host
138
+ * can answer the macro/callee names it knows. `packageName` is the dotted package (`dbt_utils` in
139
+ * `dbt_utils.star(...)`). The NEUTRAL provider knows no vocabulary and offers none; a host answers
140
+ * from its catalog. `completeAt` reads this when the caret is inside a jinja tag. */
141
+ templateCandidates(_callee, _argIndex, _packageName) {
142
+ return [];
143
+ }
152
144
  // --- The composed entry the ENGINE consults (rarely overridden wholesale). ---
153
145
  /**
154
146
  * Everything known about `call`, composed from the granular methods. Field precedence for the
@@ -257,6 +249,45 @@ export class DefaultTemplateProvider {
257
249
  return anyNew;
258
250
  }
259
251
  }
252
+ /**
253
+ * The shipped dbt overlay: a `DefaultTemplateProvider` that knows dbt's built-in macros and nothing
254
+ * more. `ref(...)` resolves to the dbt-LOGICAL model name, `source(a,b)` to the logical
255
+ * [source, table], `env_var` to a string, and the no-output builtins
256
+ * (config/docs/print/log/return/exceptions) render nothing. Static famous-macro knowledge ONLY: no
257
+ * manifest, no warehouse, no project config, no runtime. A dbt consumer with runtime knowledge
258
+ * extends THIS (not the neutral `DefaultTemplateProvider`) and overrides the granular methods with
259
+ * what its manifest / describe cache resolve to. This class is where the dbt vocabulary lives so the
260
+ * neutral core and default do not carry it.
261
+ */
262
+ export class DbtTemplateProvider extends DefaultTemplateProvider {
263
+ relationOf(call) {
264
+ if (call.packageParts !== undefined)
265
+ return undefined;
266
+ if (call.name === "ref") {
267
+ const model = refModel(call);
268
+ return typeof model === "string" ? { nameParts: [model] } : undefined;
269
+ }
270
+ if (call.name === "source") {
271
+ const parts = sourceParts(call);
272
+ if (parts && typeof parts[0] === "string" && typeof parts[1] === "string") {
273
+ return { nameParts: [parts[0], parts[1]] };
274
+ }
275
+ }
276
+ return undefined;
277
+ }
278
+ valueOf(call) {
279
+ if (call.packageParts === undefined && call.name === "env_var")
280
+ return { type: "string" };
281
+ return undefined;
282
+ }
283
+ shapeOf(call) {
284
+ if (call.packageParts === undefined && NO_OUTPUT_BUILTINS.has(call.name))
285
+ return "nothing";
286
+ if (call.packageParts !== undefined && NO_OUTPUT_BUILTINS.has(call.packageParts[0] ?? ""))
287
+ return "nothing";
288
+ return undefined;
289
+ }
290
+ }
260
291
  /**
261
292
  * The ONE shared no-configuration default — an OPEN world that answers nothing and diagnoses
262
293
  * nothing. Sharing a single instance across documents/calls is safe ONLY because the bare base
@@ -0,0 +1,2 @@
1
+ import type { DialectBehavior } from "../dialect-behavior/behavior.js";
2
+ export declare const redshiftBehavior: DialectBehavior;
@@ -0,0 +1,19 @@
1
+ import { acceptsFor } from "../dialect-behavior/coerce-rules.js";
2
+ import { likePatternToRegExp } from "../scope/like-pattern.js";
3
+ import { SIGNATURES } from "../signature/signatures.js";
4
+ import { displayName, fold, foldTableName, matchesSourceKey } from "./fold.js";
5
+ import { redshiftLiteral, redshiftParseType, REDSHIFT_FUNCTION_RETURNS } from "./infer.js";
6
+ export const redshiftBehavior = {
7
+ fold,
8
+ displayName,
9
+ foldTableName,
10
+ matchesSourceKey,
11
+ likeMatch: (pattern, value) => likePatternToRegExp(pattern).test(value),
12
+ literal: redshiftLiteral,
13
+ parseType: redshiftParseType,
14
+ functions: REDSHIFT_FUNCTION_RETURNS,
15
+ division: "integer",
16
+ signatures: SIGNATURES.redshift,
17
+ // Redshift implicit coercion: VARCHAR containing a number coerces to numeric (STR_TO_NUM=true), no bool<->num (BOOL_NUM=false).
18
+ accepts: (argType, paramText) => acceptsFor(redshiftParseType, true, false, argType, paramText),
19
+ };
@@ -0,0 +1,8 @@
1
+ import { type FoldRule, type IdentKind } from "../ident/fold.js";
2
+ export declare const REDSHIFT_FOLD_RULE: FoldRule;
3
+ /** Fold an identifier to its Redshift identity key. */
4
+ export declare function fold(raw: string, kind?: IdentKind): string;
5
+ /** Presentation twin: strip delimiters, no case change. */
6
+ export declare function displayName(raw: string): string;
7
+ export declare function foldTableName(parts: string[]): string[];
8
+ export declare function matchesSourceKey(key: string, rawPart: string): boolean;
@@ -0,0 +1,31 @@
1
+ // Redshift identifier folding. The FoldRule plus its bound engine, colocated here because BOTH the
2
+ // upstream lower() and the downstream DialectBehavior need it (the fold rule is the one dialect concern
3
+ // used at two stages). Redshift folds both unquoted and quoted identifiers to lowercase; double-quote
4
+ // is the delimiter, doubled to escape.
5
+ import { displayWith, foldWith } from "../ident/fold.js";
6
+ const DOUBLE_QUOTE = ['"', '"'];
7
+ // docs.aws.amazon.com/redshift/latest/dg/r_names.html — verified live: "ASCII letters in
8
+ // standard and delimited identifiers are case-insensitive and are folded to lowercase in the
9
+ // database" — explicitly covers BOTH unquoted and quoted by default (the
10
+ // enable_case_sensitive_identifier parameter can flip quoted identifiers case-sensitive; this
11
+ // module encodes the default). Doubled-quote escape: "To use a double quotation mark in a
12
+ // string, you must precede it with another double quotation mark character."
13
+ export const REDSHIFT_FOLD_RULE = {
14
+ delimiters: [DOUBLE_QUOTE],
15
+ unquoted: "lower",
16
+ quoted: "lower",
17
+ };
18
+ /** Fold an identifier to its Redshift identity key. */
19
+ export function fold(raw, kind = "other") {
20
+ return foldWith(REDSHIFT_FOLD_RULE, raw, kind);
21
+ }
22
+ /** Presentation twin: strip delimiters, no case change. */
23
+ export function displayName(raw) {
24
+ return displayWith(REDSHIFT_FOLD_RULE, raw);
25
+ }
26
+ export function foldTableName(parts) {
27
+ return parts.map((p) => fold(p, "table"));
28
+ }
29
+ export function matchesSourceKey(key, rawPart) {
30
+ return key === fold(rawPart) || key === fold(rawPart, "table");
31
+ }
@@ -0,0 +1,7 @@
1
+ import { lower } from "./lower.js";
2
+ import { parseRedshift } from "./parse.js";
3
+ export declare const redshift: {
4
+ parse: typeof parseRedshift;
5
+ lower: typeof lower;
6
+ behavior: import("../dialect-behavior/behavior.js").DialectBehavior;
7
+ };
@@ -0,0 +1,10 @@
1
+ // The complete redshift dialect module: parse + lower (front end) and behavior (semantic knowledge).
2
+ // The registry wires this; to understand everything sqllens does for redshift, read this folder.
3
+ import { redshiftBehavior } from "./behavior.js";
4
+ import { lower } from "./lower.js";
5
+ import { parseRedshift } from "./parse.js";
6
+ export const redshift = {
7
+ parse: parseRedshift,
8
+ lower,
9
+ behavior: redshiftBehavior,
10
+ };
@@ -1,5 +1,5 @@
1
- import { type Type } from "./types.js";
2
- import type { FnRule } from "./functions.js";
1
+ import { type Type } from "../infer/types.js";
2
+ import type { FnRule } from "../infer/functions.js";
3
3
  export declare const REDSHIFT_ALIASES: Record<string, string>;
4
4
  export declare function redshiftParseType(text: string): Type;
5
5
  /** Redshift literal forms. Numeric rules per the AWS SQL reference "Numeric literals"
@@ -1,5 +1,6 @@
1
- import { parseType, scalar, UNKNOWN } from "./types.js";
2
- import { commonType, widenSum } from "./coerce.js";
1
+ import { parseType, scalar, UNKNOWN } from "../infer/types.js";
2
+ import { commonType, widenSum } from "../infer/coerce.js";
3
+ import { fold } from "./fold.js";
3
4
  // ---------------------------------------------------------------------------
4
5
  // Redshift (Postgres-derived) inference knowledge. Scalar-name aliases map the
5
6
  // Postgres/Redshift type vocabulary onto the shared canonical names; division
@@ -36,7 +37,7 @@ export const REDSHIFT_ALIASES = {
36
37
  varbinary: "binary",
37
38
  };
38
39
  export function redshiftParseType(text) {
39
- return parseType(text, REDSHIFT_ALIASES, "redshift");
40
+ return parseType(text, REDSHIFT_ALIASES, fold);
40
41
  }
41
42
  const BOOLEAN = scalar("boolean");
42
43
  /** Redshift literal forms. Numeric rules per the AWS SQL reference "Numeric literals"
@@ -3,7 +3,7 @@ import { RedshiftParser as P } from "../generated/redshift/RedshiftParser.js";
3
3
  import { keywordCategory, swallowedCategories, swallowedStatements } from "../ir/statement.js";
4
4
  import { partSpansOf } from "../ir/part-span.js";
5
5
  import { freezeIR } from "../ir/freeze.js";
6
- import { displayName } from "../ident/fold.js";
6
+ import { displayName } from "./fold.js";
7
7
  // ---------------------------------------------------------------------------
8
8
  // Lowering — Amazon Redshift (bytebase/parser fork, a PostgreSQL-grammar fork)
9
9
  // CST -> the shared dialect-neutral IR (src/ir/ir.ts). The semantic layer runs
@@ -1321,7 +1321,7 @@ function lowerFuncExpr(node) {
1321
1321
  if (!app)
1322
1322
  return otherExpr(node);
1323
1323
  const fname = firstShallow(app, P.RULE_func_name);
1324
- const name = (fname ? displayName(lastName(fname), "redshift") : (leftmostToken(app) ?? "")).toLowerCase();
1324
+ const name = (fname ? displayName(lastName(fname)) : (leftmostToken(app) ?? "")).toLowerCase();
1325
1325
  const args = funcArgs(app);
1326
1326
  // WITHIN GROUP (ORDER BY …) keys feed the aggregate — include as args.
1327
1327
  const within = directChildrenOfRule(node, P.RULE_within_group_clause)[0];
@@ -0,0 +1,6 @@
1
+ import type { FnSignature } from "../signature/signatures.js";
2
+ /** The merged function-signature table for redshift: 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 REDSHIFT_SIGNATURES: Record<string, FnSignature[]>;