sqllens 1.1.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 (234) hide show
  1. package/README.md +2 -74
  2. package/THIRD-PARTY-NOTICES.md +50 -5
  3. package/dist/api.d.ts +5 -3
  4. package/dist/api.js +11 -4
  5. package/dist/bigquery/behavior.d.ts +2 -0
  6. package/dist/bigquery/behavior.js +20 -0
  7. package/dist/bigquery/dot-path.d.ts +0 -2
  8. package/dist/bigquery/dot-path.js +0 -1
  9. package/dist/bigquery/fold.d.ts +8 -0
  10. package/dist/bigquery/fold.js +39 -0
  11. package/dist/bigquery/index.d.ts +7 -0
  12. package/dist/bigquery/index.js +10 -0
  13. package/dist/{infer/bigquery.d.ts → bigquery/infer.d.ts} +2 -2
  14. package/dist/{infer/bigquery.js → bigquery/infer.js} +4 -3
  15. package/dist/bigquery/lower.js +35 -12
  16. package/dist/bigquery/signatures.generated.d.ts +6 -0
  17. package/dist/bigquery/signatures.generated.js +1068 -0
  18. package/dist/completion/atn-walk.d.ts +13 -2
  19. package/dist/completion/atn-walk.js +13 -10
  20. package/dist/completion/complete.d.ts +4 -3
  21. package/dist/completion/complete.js +101 -45
  22. package/dist/completion/jinja-slot.d.ts +24 -0
  23. package/dist/completion/jinja-slot.js +126 -0
  24. package/dist/completion/parser-factory.d.ts +13 -1
  25. package/dist/completion/parser-factory.js +12 -0
  26. package/dist/databricks/behavior.d.ts +2 -0
  27. package/dist/databricks/behavior.js +19 -0
  28. package/dist/databricks/fold.d.ts +8 -0
  29. package/dist/databricks/fold.js +27 -0
  30. package/dist/databricks/index.d.ts +7 -0
  31. package/dist/databricks/index.js +10 -0
  32. package/dist/databricks/infer.d.ts +6 -0
  33. package/dist/databricks/infer.js +638 -0
  34. package/dist/databricks/signatures.generated.d.ts +6 -0
  35. package/dist/databricks/signatures.generated.js +1745 -0
  36. package/dist/dialect-behavior/behavior.d.ts +26 -0
  37. package/dist/dialect-behavior/behavior.js +1 -0
  38. package/dist/dialect-behavior/carrier.d.ts +5 -0
  39. package/dist/dialect-behavior/carrier.js +5 -0
  40. package/dist/dialect-behavior/coerce-rules.d.ts +7 -0
  41. package/dist/dialect-behavior/coerce-rules.js +69 -0
  42. package/dist/dialect-behavior/public-fold.d.ts +6 -0
  43. package/dist/dialect-behavior/public-fold.js +9 -0
  44. package/dist/dialect-behavior/registry.d.ts +6 -0
  45. package/dist/dialect-behavior/registry.js +34 -0
  46. package/dist/dialect-symbols.js +16 -19
  47. package/dist/document/document.d.ts +1 -1
  48. package/dist/document/document.js +8 -7
  49. package/dist/duckdb/behavior.d.ts +2 -0
  50. package/dist/duckdb/behavior.js +21 -0
  51. package/dist/duckdb/fold.d.ts +8 -0
  52. package/dist/duckdb/fold.js +29 -0
  53. package/dist/duckdb/index.d.ts +7 -0
  54. package/dist/duckdb/index.js +10 -0
  55. package/dist/{infer/duckdb.d.ts → duckdb/infer.d.ts} +2 -2
  56. package/dist/{infer/duckdb.js → duckdb/infer.js} +4 -3
  57. package/dist/duckdb/lower.js +47 -15
  58. package/dist/duckdb/signatures.generated.d.ts +6 -0
  59. package/dist/duckdb/signatures.generated.js +1072 -0
  60. package/dist/generated/bigquery/GoogleSQLParser.js +0 -7060
  61. package/dist/generated/databricks/DatabricksParser.js +0 -4800
  62. package/dist/generated/duckdb/DuckdbParser.js +0 -9100
  63. package/dist/generated/minijinja/MinijinjaParser.js +0 -380
  64. package/dist/generated/mysql/MysqlParser.js +0 -6330
  65. package/dist/generated/postgres/PostgresParser.js +0 -8530
  66. package/dist/generated/redshift/RedshiftParser.js +0 -10970
  67. package/dist/generated/snowflake/SnowflakeParser.js +0 -7320
  68. package/dist/generated/sqlite/SqliteParser.js +0 -1150
  69. package/dist/generated/trino/TrinoParser.js +0 -3770
  70. package/dist/generated/tsql/TSqlParser.js +0 -8420
  71. package/dist/ident/fold.d.ts +24 -15
  72. package/dist/ident/fold.js +12 -194
  73. package/dist/index.d.ts +2 -2
  74. package/dist/index.js +10 -8
  75. package/dist/infer/functions.d.ts +22 -11
  76. package/dist/infer/functions.js +26 -888
  77. package/dist/infer/infer.js +16 -14
  78. package/dist/infer/nullability.js +3 -4
  79. package/dist/infer/types.d.ts +1 -1
  80. package/dist/infer/types.js +7 -7
  81. package/dist/ir/ir.d.ts +26 -17
  82. package/dist/ir/span.js +0 -2
  83. package/dist/ir/walk.js +3 -3
  84. package/dist/lineage/hops.js +13 -10
  85. package/dist/lineage/lineage.js +10 -7
  86. package/dist/minijinja/apply-tags.d.ts +14 -7
  87. package/dist/minijinja/apply-tags.js +66 -121
  88. package/dist/minijinja/parse.js +5 -5
  89. package/dist/minijinja/tag-ast.d.ts +29 -36
  90. package/dist/minijinja/tag-ast.js +210 -90
  91. package/dist/mysql/behavior.d.ts +2 -0
  92. package/dist/mysql/behavior.js +21 -0
  93. package/dist/mysql/fold.d.ts +8 -0
  94. package/dist/mysql/fold.js +49 -0
  95. package/dist/mysql/index.d.ts +7 -0
  96. package/dist/mysql/index.js +10 -0
  97. package/dist/{infer/mysql.d.ts → mysql/infer.d.ts} +2 -2
  98. package/dist/{infer/mysql.js → mysql/infer.js} +3 -2
  99. package/dist/mysql/signatures.generated.d.ts +6 -0
  100. package/dist/mysql/signatures.generated.js +508 -0
  101. package/dist/postgres/behavior.d.ts +2 -0
  102. package/dist/postgres/behavior.js +19 -0
  103. package/dist/postgres/fold.d.ts +8 -0
  104. package/dist/postgres/fold.js +30 -0
  105. package/dist/postgres/index.d.ts +7 -0
  106. package/dist/postgres/index.js +10 -0
  107. package/dist/{infer/postgres.d.ts → postgres/infer.d.ts} +2 -2
  108. package/dist/{infer/postgres.js → postgres/infer.js} +4 -3
  109. package/dist/postgres/lower.js +2 -2
  110. package/dist/postgres/signatures.generated.d.ts +6 -0
  111. package/dist/postgres/signatures.generated.js +2973 -0
  112. package/dist/qualify/check-calls.js +80 -161
  113. package/dist/qualify/qualify.js +16 -14
  114. package/dist/qualify/schema-provider.js +2 -2
  115. package/dist/qualify/schema.js +3 -3
  116. package/dist/qualify/template-provider.d.ts +45 -12
  117. package/dist/qualify/template-provider.js +69 -38
  118. package/dist/redshift/behavior.d.ts +2 -0
  119. package/dist/redshift/behavior.js +19 -0
  120. package/dist/redshift/fold.d.ts +8 -0
  121. package/dist/redshift/fold.js +31 -0
  122. package/dist/redshift/index.d.ts +7 -0
  123. package/dist/redshift/index.js +10 -0
  124. package/dist/{infer/redshift.d.ts → redshift/infer.d.ts} +2 -2
  125. package/dist/{infer/redshift.js → redshift/infer.js} +4 -3
  126. package/dist/redshift/lower.js +2 -2
  127. package/dist/redshift/signatures.generated.d.ts +6 -0
  128. package/dist/redshift/signatures.generated.js +757 -0
  129. package/dist/references/references.js +17 -12
  130. package/dist/scope/like-pattern.d.ts +2 -0
  131. package/dist/scope/like-pattern.js +15 -0
  132. package/dist/scope/scope.d.ts +5 -5
  133. package/dist/scope/scope.js +48 -42
  134. package/dist/sema/resolve.js +17 -12
  135. package/dist/session.d.ts +2 -2
  136. package/dist/signature/signature.d.ts +14 -6
  137. package/dist/signature/signature.js +30 -22
  138. package/dist/signature/signatures.d.ts +14 -12
  139. package/dist/signature/signatures.js +42 -721
  140. package/dist/snowflake/behavior.d.ts +2 -0
  141. package/dist/snowflake/behavior.js +22 -0
  142. package/dist/snowflake/fold.d.ts +8 -0
  143. package/dist/snowflake/fold.js +25 -0
  144. package/dist/snowflake/index.d.ts +7 -0
  145. package/dist/snowflake/index.js +10 -0
  146. package/dist/{infer/snowflake.d.ts → snowflake/infer.d.ts} +2 -2
  147. package/dist/{infer/snowflake.js → snowflake/infer.js} +4 -3
  148. package/dist/snowflake/lower.js +59 -19
  149. package/dist/snowflake/signatures.generated.d.ts +6 -0
  150. package/dist/snowflake/signatures.generated.js +2080 -0
  151. package/dist/sqlite/behavior.d.ts +2 -0
  152. package/dist/sqlite/behavior.js +19 -0
  153. package/dist/sqlite/fold.d.ts +8 -0
  154. package/dist/sqlite/fold.js +41 -0
  155. package/dist/sqlite/index.d.ts +7 -0
  156. package/dist/sqlite/index.js +10 -0
  157. package/dist/{infer/sqlite.d.ts → sqlite/infer.d.ts} +2 -2
  158. package/dist/{infer/sqlite.js → sqlite/infer.js} +4 -3
  159. package/dist/sqlite/signatures.generated.d.ts +6 -0
  160. package/dist/sqlite/signatures.generated.js +277 -0
  161. package/dist/symbols/symbols.js +14 -12
  162. package/dist/trino/behavior.d.ts +2 -0
  163. package/dist/trino/behavior.js +21 -0
  164. package/dist/trino/fold.d.ts +8 -0
  165. package/dist/trino/fold.js +39 -0
  166. package/dist/trino/index.d.ts +7 -0
  167. package/dist/trino/index.js +10 -0
  168. package/dist/{infer/trino.d.ts → trino/infer.d.ts} +2 -2
  169. package/dist/{infer/trino.js → trino/infer.js} +4 -3
  170. package/dist/trino/lower.js +5 -5
  171. package/dist/trino/signatures.generated.d.ts +6 -0
  172. package/dist/trino/signatures.generated.js +968 -0
  173. package/dist/tsql/behavior.d.ts +2 -0
  174. package/dist/tsql/behavior.js +20 -0
  175. package/dist/tsql/fold.d.ts +8 -0
  176. package/dist/tsql/fold.js +34 -0
  177. package/dist/tsql/index.d.ts +7 -0
  178. package/dist/tsql/index.js +10 -0
  179. package/dist/tsql/infer.d.ts +16 -0
  180. package/dist/tsql/infer.js +289 -0
  181. package/dist/tsql/lower.js +4 -4
  182. package/dist/tsql/signatures.generated.d.ts +6 -0
  183. package/dist/tsql/signatures.generated.js +640 -0
  184. package/package.json +5 -10
  185. package/dist/generated/bigquery/GoogleSQLLexer.d.ts +0 -407
  186. package/dist/generated/bigquery/GoogleSQLParser.d.ts +0 -9558
  187. package/dist/generated/bigquery/GoogleSQLParserListener.d.ts +0 -7777
  188. package/dist/generated/bigquery/GoogleSQLParserListener.js +0 -7070
  189. package/dist/generated/databricks/DatabricksLexer.d.ts +0 -566
  190. package/dist/generated/databricks/DatabricksParser.d.ts +0 -7771
  191. package/dist/generated/databricks/DatabricksParserListener.d.ts +0 -5737
  192. package/dist/generated/databricks/DatabricksParserListener.js +0 -5256
  193. package/dist/generated/duckdb/DuckdbLexer.d.ts +0 -691
  194. package/dist/generated/duckdb/DuckdbParser.d.ts +0 -13932
  195. package/dist/generated/duckdb/DuckdbParserListener.d.ts +0 -10049
  196. package/dist/generated/duckdb/DuckdbParserListener.js +0 -9138
  197. package/dist/generated/minijinja/MinijinjaLexer.d.ts +0 -108
  198. package/dist/generated/minijinja/MinijinjaParser.d.ts +0 -604
  199. package/dist/generated/minijinja/MinijinjaParserListener.d.ts +0 -449
  200. package/dist/generated/minijinja/MinijinjaParserListener.js +0 -410
  201. package/dist/generated/mysql/MysqlLexer.d.ts +0 -1198
  202. package/dist/generated/mysql/MysqlParser.d.ts +0 -10992
  203. package/dist/generated/mysql/MysqlParserListener.d.ts +0 -7592
  204. package/dist/generated/mysql/MysqlParserListener.js +0 -6958
  205. package/dist/generated/postgres/PostgresLexer.d.ts +0 -663
  206. package/dist/generated/postgres/PostgresParser.d.ts +0 -12963
  207. package/dist/generated/postgres/PostgresParserListener.d.ts +0 -9408
  208. package/dist/generated/postgres/PostgresParserListener.js +0 -8554
  209. package/dist/generated/redshift/RedshiftLexer.d.ts +0 -954
  210. package/dist/generated/redshift/RedshiftParser.d.ts +0 -16939
  211. package/dist/generated/redshift/RedshiftParserListener.d.ts +0 -12092
  212. package/dist/generated/redshift/RedshiftParserListener.js +0 -10994
  213. package/dist/generated/snowflake/SnowflakeLexer.d.ts +0 -1046
  214. package/dist/generated/snowflake/SnowflakeParser.d.ts +0 -14196
  215. package/dist/generated/snowflake/SnowflakeParserListener.d.ts +0 -8063
  216. package/dist/generated/snowflake/SnowflakeParserListener.js +0 -7330
  217. package/dist/generated/sqlite/SqliteLexer.d.ts +0 -210
  218. package/dist/generated/sqlite/SqliteParser.d.ts +0 -2115
  219. package/dist/generated/sqlite/SqliteParserListener.d.ts +0 -1276
  220. package/dist/generated/sqlite/SqliteParserListener.js +0 -1160
  221. package/dist/generated/trino/TrinoLexer.d.ts +0 -381
  222. package/dist/generated/trino/TrinoParser.d.ts +0 -5340
  223. package/dist/generated/trino/TrinoParserListener.d.ts +0 -4704
  224. package/dist/generated/trino/TrinoParserListener.js +0 -4326
  225. package/dist/generated/tsql/TSqlLexer.d.ts +0 -1278
  226. package/dist/generated/tsql/TSqlParser.d.ts +0 -17267
  227. package/dist/generated/tsql/TSqlParserListener.d.ts +0 -9697
  228. package/dist/generated/tsql/TSqlParserListener.js +0 -8854
  229. package/dist/infer/dialect.d.ts +0 -21
  230. package/dist/infer/dialect.js +0 -100
  231. package/dist/infer/literals.d.ts +0 -6
  232. package/dist/infer/literals.js +0 -44
  233. package/dist/signature/generated/tsql.d.ts +0 -3
  234. 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[]>;