sqlingo 0.15.0 → 0.15.2

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 (211) hide show
  1. package/CHANGELOG.md +17 -3
  2. package/README.md +46 -42
  3. package/README.npm.md +46 -42
  4. package/README.repo.md +46 -42
  5. package/dist/chunk-3AQZGJOE.js +2 -0
  6. package/dist/chunk-3AQZGJOE.js.map +1 -0
  7. package/dist/chunk-3QM5KG7E.cjs +2 -0
  8. package/dist/chunk-3QM5KG7E.cjs.map +1 -0
  9. package/dist/chunk-3QPO4PHG.cjs +2 -0
  10. package/dist/{chunk-HM2LPF3F.cjs.map → chunk-3QPO4PHG.cjs.map} +1 -1
  11. package/dist/chunk-3UWWG7AW.cjs +2 -0
  12. package/dist/{chunk-3OQRIAK6.cjs.map → chunk-3UWWG7AW.cjs.map} +1 -1
  13. package/dist/{chunk-UZQQGWEG.js → chunk-4GEW5JA6.js} +2 -2
  14. package/dist/chunk-4OWUZIBT.cjs +2 -0
  15. package/dist/chunk-4OWUZIBT.cjs.map +1 -0
  16. package/dist/chunk-57QCCXIJ.cjs +2 -0
  17. package/dist/{chunk-HOS6YPLH.cjs.map → chunk-57QCCXIJ.cjs.map} +1 -1
  18. package/dist/{chunk-T4CYUMP3.js → chunk-5UEGDJPA.js} +2 -2
  19. package/dist/{chunk-M7GQSFMU.js → chunk-6KKXEKNM.js} +2 -2
  20. package/dist/chunk-AHVZOF3N.cjs +2 -0
  21. package/dist/{chunk-OZSCBCO2.cjs.map → chunk-AHVZOF3N.cjs.map} +1 -1
  22. package/dist/{chunk-L5WMOHKN.js → chunk-AXLGFQDQ.js} +2 -2
  23. package/dist/chunk-BLUVFIA7.cjs +2 -0
  24. package/dist/chunk-BLUVFIA7.cjs.map +1 -0
  25. package/dist/chunk-DI2QZRFR.cjs +4 -0
  26. package/dist/{chunk-66JALKFB.cjs.map → chunk-DI2QZRFR.cjs.map} +1 -1
  27. package/dist/{chunk-AVPDMWUK.js → chunk-EZ7VKF2X.js} +2 -2
  28. package/dist/chunk-FERVZ62T.cjs +2 -0
  29. package/dist/{chunk-2S7D555U.cjs.map → chunk-FERVZ62T.cjs.map} +1 -1
  30. package/dist/chunk-GVRTGQV6.cjs +2 -0
  31. package/dist/chunk-GVRTGQV6.cjs.map +1 -0
  32. package/dist/chunk-HN5OT37U.js +2 -0
  33. package/dist/chunk-HN5OT37U.js.map +1 -0
  34. package/dist/{chunk-2RVEXDCA.js → chunk-I3W3TYLQ.js} +2 -2
  35. package/dist/{chunk-QRPJHVZJ.js → chunk-JLPP24SP.js} +2 -2
  36. package/dist/chunk-KCIBVGFH.cjs +2 -0
  37. package/dist/{chunk-LULCN2QF.cjs.map → chunk-KCIBVGFH.cjs.map} +1 -1
  38. package/dist/chunk-L3QLTSDN.cjs +2 -0
  39. package/dist/{chunk-NV4JJPNH.cjs.map → chunk-L3QLTSDN.cjs.map} +1 -1
  40. package/dist/{chunk-DA4ACCPJ.js → chunk-LXNDZZBH.js} +4 -4
  41. package/dist/chunk-LXNDZZBH.js.map +1 -0
  42. package/dist/chunk-MFCEAG7X.cjs +2 -0
  43. package/dist/{chunk-HMK6HRF2.cjs.map → chunk-MFCEAG7X.cjs.map} +1 -1
  44. package/dist/chunk-MVIZ3OGF.cjs +2 -0
  45. package/dist/{chunk-46KA45SQ.cjs.map → chunk-MVIZ3OGF.cjs.map} +1 -1
  46. package/dist/{chunk-2JB6PWW5.js → chunk-NJEMK7XN.js} +2 -2
  47. package/dist/chunk-OEILKTSQ.cjs +2 -0
  48. package/dist/chunk-OEILKTSQ.cjs.map +1 -0
  49. package/dist/{chunk-H23TMB7T.js → chunk-OY3TUTWZ.js} +2 -2
  50. package/dist/chunk-QBQHDSEC.js +3 -0
  51. package/dist/chunk-QBQHDSEC.js.map +1 -0
  52. package/dist/{chunk-U7IPR2BW.js → chunk-QZPWUNHV.js} +2 -2
  53. package/dist/chunk-RCVHOYS7.js +2 -0
  54. package/dist/chunk-RCVHOYS7.js.map +1 -0
  55. package/dist/chunk-SBCEJTHD.js +2 -0
  56. package/dist/chunk-SBCEJTHD.js.map +1 -0
  57. package/dist/chunk-T4W65P5Z.cjs +3 -0
  58. package/dist/chunk-T4W65P5Z.cjs.map +1 -0
  59. package/dist/chunk-U2DYJPRT.js +2 -0
  60. package/dist/chunk-U2DYJPRT.js.map +1 -0
  61. package/dist/chunk-UN6XWES6.js +2 -0
  62. package/dist/chunk-UN6XWES6.js.map +1 -0
  63. package/dist/chunk-WEST5GIF.cjs +2 -0
  64. package/dist/chunk-WEST5GIF.cjs.map +1 -0
  65. package/dist/{chunk-BHZRPLYB.js → chunk-XHLLQOF5.js} +2 -2
  66. package/dist/{chunk-PPEQJWF2.cjs → chunk-Y3TUKXK4.cjs} +4 -4
  67. package/dist/{chunk-PPEQJWF2.cjs.map → chunk-Y3TUKXK4.cjs.map} +1 -1
  68. package/dist/chunk-Z3MZONPC.cjs +2 -0
  69. package/dist/{chunk-EZ4BXKV6.cjs.map → chunk-Z3MZONPC.cjs.map} +1 -1
  70. package/dist/dialects/athena.cjs +1 -1
  71. package/dist/dialects/athena.js +1 -1
  72. package/dist/dialects/bigquery.cjs +2 -2
  73. package/dist/dialects/bigquery.cjs.map +1 -1
  74. package/dist/dialects/bigquery.js +2 -2
  75. package/dist/dialects/bigquery.js.map +1 -1
  76. package/dist/dialects/clickhouse.cjs +1 -1
  77. package/dist/dialects/clickhouse.cjs.map +1 -1
  78. package/dist/dialects/clickhouse.js +1 -1
  79. package/dist/dialects/clickhouse.js.map +1 -1
  80. package/dist/dialects/databricks.cjs +1 -1
  81. package/dist/dialects/databricks.cjs.map +1 -1
  82. package/dist/dialects/databricks.js +1 -1
  83. package/dist/dialects/databricks.js.map +1 -1
  84. package/dist/dialects/doris.cjs +1 -1
  85. package/dist/dialects/doris.cjs.map +1 -1
  86. package/dist/dialects/doris.js +1 -1
  87. package/dist/dialects/doris.js.map +1 -1
  88. package/dist/dialects/dremio.cjs +1 -1
  89. package/dist/dialects/dremio.cjs.map +1 -1
  90. package/dist/dialects/dremio.js +1 -1
  91. package/dist/dialects/dremio.js.map +1 -1
  92. package/dist/dialects/drill.cjs +1 -1
  93. package/dist/dialects/drill.cjs.map +1 -1
  94. package/dist/dialects/drill.js +1 -1
  95. package/dist/dialects/drill.js.map +1 -1
  96. package/dist/dialects/druid.cjs +1 -1
  97. package/dist/dialects/druid.js +1 -1
  98. package/dist/dialects/duckdb.cjs +13 -13
  99. package/dist/dialects/duckdb.cjs.map +1 -1
  100. package/dist/dialects/duckdb.js +4 -4
  101. package/dist/dialects/duckdb.js.map +1 -1
  102. package/dist/dialects/dune.cjs +1 -1
  103. package/dist/dialects/dune.js +1 -1
  104. package/dist/dialects/exasol.cjs +1 -1
  105. package/dist/dialects/exasol.cjs.map +1 -1
  106. package/dist/dialects/exasol.js +1 -1
  107. package/dist/dialects/exasol.js.map +1 -1
  108. package/dist/dialects/fabric.cjs +1 -1
  109. package/dist/dialects/fabric.js +1 -1
  110. package/dist/dialects/hive.cjs +1 -1
  111. package/dist/dialects/hive.js +1 -1
  112. package/dist/dialects/materialize.cjs +1 -1
  113. package/dist/dialects/materialize.js +1 -1
  114. package/dist/dialects/mysql.cjs +1 -1
  115. package/dist/dialects/mysql.js +1 -1
  116. package/dist/dialects/oracle.cjs +1 -1
  117. package/dist/dialects/oracle.cjs.map +1 -1
  118. package/dist/dialects/oracle.js +1 -1
  119. package/dist/dialects/oracle.js.map +1 -1
  120. package/dist/dialects/postgres.cjs +1 -1
  121. package/dist/dialects/postgres.js +1 -1
  122. package/dist/dialects/presto.cjs +1 -1
  123. package/dist/dialects/presto.js +1 -1
  124. package/dist/dialects/prql.cjs +1 -1
  125. package/dist/dialects/prql.js +1 -1
  126. package/dist/dialects/redshift.cjs +1 -1
  127. package/dist/dialects/redshift.js +1 -1
  128. package/dist/dialects/risingwave.cjs +1 -1
  129. package/dist/dialects/risingwave.js +1 -1
  130. package/dist/dialects/singlestore.cjs +1 -1
  131. package/dist/dialects/singlestore.cjs.map +1 -1
  132. package/dist/dialects/singlestore.js +1 -1
  133. package/dist/dialects/singlestore.js.map +1 -1
  134. package/dist/dialects/snowflake.cjs +2 -2
  135. package/dist/dialects/snowflake.cjs.map +1 -1
  136. package/dist/dialects/snowflake.js +2 -2
  137. package/dist/dialects/snowflake.js.map +1 -1
  138. package/dist/dialects/solr.cjs +1 -1
  139. package/dist/dialects/solr.js +1 -1
  140. package/dist/dialects/spark.cjs +1 -1
  141. package/dist/dialects/spark.js +1 -1
  142. package/dist/dialects/spark2.cjs +1 -1
  143. package/dist/dialects/spark2.js +1 -1
  144. package/dist/dialects/sqlite.cjs +1 -1
  145. package/dist/dialects/sqlite.js +1 -1
  146. package/dist/dialects/starrocks.cjs +1 -1
  147. package/dist/dialects/starrocks.js +1 -1
  148. package/dist/dialects/tableau.cjs +1 -1
  149. package/dist/dialects/tableau.js +1 -1
  150. package/dist/dialects/teradata.cjs +1 -1
  151. package/dist/dialects/teradata.js +1 -1
  152. package/dist/dialects/trino.cjs +1 -1
  153. package/dist/dialects/trino.js +1 -1
  154. package/dist/dialects/tsql.cjs +1 -1
  155. package/dist/dialects/tsql.js +1 -1
  156. package/dist/index.cjs +5 -5
  157. package/dist/index.cjs.map +1 -1
  158. package/dist/index.js +1 -1
  159. package/dist/index.js.map +1 -1
  160. package/package.json +2 -2
  161. package/dist/chunk-2FE3OGCV.js +0 -2
  162. package/dist/chunk-2FE3OGCV.js.map +0 -1
  163. package/dist/chunk-2S7D555U.cjs +0 -2
  164. package/dist/chunk-3OQRIAK6.cjs +0 -2
  165. package/dist/chunk-46KA45SQ.cjs +0 -2
  166. package/dist/chunk-66JALKFB.cjs +0 -4
  167. package/dist/chunk-77XUJKMQ.cjs +0 -2
  168. package/dist/chunk-77XUJKMQ.cjs.map +0 -1
  169. package/dist/chunk-BHISYWYZ.cjs +0 -2
  170. package/dist/chunk-BHISYWYZ.cjs.map +0 -1
  171. package/dist/chunk-CLLF2IN3.cjs +0 -2
  172. package/dist/chunk-CLLF2IN3.cjs.map +0 -1
  173. package/dist/chunk-D7NVJBEB.js +0 -2
  174. package/dist/chunk-D7NVJBEB.js.map +0 -1
  175. package/dist/chunk-DA4ACCPJ.js.map +0 -1
  176. package/dist/chunk-DDF3BPGK.js +0 -2
  177. package/dist/chunk-DDF3BPGK.js.map +0 -1
  178. package/dist/chunk-EZ4BXKV6.cjs +0 -2
  179. package/dist/chunk-HM2LPF3F.cjs +0 -2
  180. package/dist/chunk-HMK6HRF2.cjs +0 -2
  181. package/dist/chunk-HOS6YPLH.cjs +0 -2
  182. package/dist/chunk-IESGDKWQ.js +0 -2
  183. package/dist/chunk-IESGDKWQ.js.map +0 -1
  184. package/dist/chunk-LULCN2QF.cjs +0 -2
  185. package/dist/chunk-M7AD2I25.js +0 -3
  186. package/dist/chunk-M7AD2I25.js.map +0 -1
  187. package/dist/chunk-MFTYEAPA.cjs +0 -2
  188. package/dist/chunk-MFTYEAPA.cjs.map +0 -1
  189. package/dist/chunk-NV4JJPNH.cjs +0 -2
  190. package/dist/chunk-OSSS3YFP.cjs +0 -2
  191. package/dist/chunk-OSSS3YFP.cjs.map +0 -1
  192. package/dist/chunk-OZSCBCO2.cjs +0 -2
  193. package/dist/chunk-PDRVLDIW.cjs +0 -3
  194. package/dist/chunk-PDRVLDIW.cjs.map +0 -1
  195. package/dist/chunk-S7RAXCVR.cjs +0 -2
  196. package/dist/chunk-S7RAXCVR.cjs.map +0 -1
  197. package/dist/chunk-VKYVJYC4.js +0 -2
  198. package/dist/chunk-VKYVJYC4.js.map +0 -1
  199. package/dist/chunk-XWPR4ZK3.js +0 -2
  200. package/dist/chunk-XWPR4ZK3.js.map +0 -1
  201. /package/dist/{chunk-UZQQGWEG.js.map → chunk-4GEW5JA6.js.map} +0 -0
  202. /package/dist/{chunk-T4CYUMP3.js.map → chunk-5UEGDJPA.js.map} +0 -0
  203. /package/dist/{chunk-M7GQSFMU.js.map → chunk-6KKXEKNM.js.map} +0 -0
  204. /package/dist/{chunk-L5WMOHKN.js.map → chunk-AXLGFQDQ.js.map} +0 -0
  205. /package/dist/{chunk-AVPDMWUK.js.map → chunk-EZ7VKF2X.js.map} +0 -0
  206. /package/dist/{chunk-2RVEXDCA.js.map → chunk-I3W3TYLQ.js.map} +0 -0
  207. /package/dist/{chunk-QRPJHVZJ.js.map → chunk-JLPP24SP.js.map} +0 -0
  208. /package/dist/{chunk-2JB6PWW5.js.map → chunk-NJEMK7XN.js.map} +0 -0
  209. /package/dist/{chunk-H23TMB7T.js.map → chunk-OY3TUTWZ.js.map} +0 -0
  210. /package/dist/{chunk-U7IPR2BW.js.map → chunk-QZPWUNHV.js.map} +0 -0
  211. /package/dist/{chunk-BHZRPLYB.js.map → chunk-XHLLQOF5.js.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # sqlingo
2
2
 
3
+ ## 0.15.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 9e66f11: Fix issue #58
8
+
9
+ ## 0.15.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 15c6a06: Fix issue #51
14
+
15
+ - Use stable class identifier internally when specifying dialects
16
+ - Fix MySQL UNIQUE (col) transpiling to UNIQUE (col NULLS FIRST)
17
+
3
18
  ## 0.15.0
4
19
 
5
20
  ### Minor Changes
@@ -46,9 +61,8 @@
46
61
  - 4321928: Sync upstream sqlglot v30.5.0 tests and fix bugs
47
62
 
48
63
  - Port all missing v30.5.0 test cases across all dialect files
49
- - Close validate call gaps: duckdb (+97), clickhouse (+36), snowflake (+27), dialect (+84), spark (+14), exasol (+11), hive (+4), oracle (+3), tsql (+7), databricks (+4), duckdb minor (+5), presto (+1)
50
- - Fix generator EXCLUDE bug: pass `undefined` as first arg to `this.expressions()` instead of object
51
- - Fix `renameindexSql` → `alterRenameIndexSql` method name mismatch
64
+ - Fix generator `EXCLUDE` bug: pass `undefined` as first arg to `this.expressions()` instead of object
65
+ - Fix `renameindexSql` -> `alterRenameIndexSql` method name mismatch
52
66
  - Fix `InvisibleColumnConstraintExpr` missing empty `requiredArgs` override
53
67
  - Fix `unnestGenerateDateArrayUsingRecursiveCte` to use `DateAddExpr` instead of `AnonymousExpr`
54
68
  - Add `ALL` to `JoinExprKind` enum for ClickHouse ALL JOIN support
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/sqlingo)](https://www.npmjs.com/package/sqlingo)
4
4
  [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/huydo862003/sqlingo/blob/master/LICENSE)
5
- ![SQLGlot](https://img.shields.io/badge/SQLGlot-v30.1.0-blue)
5
+ ![SQLGlot](https://img.shields.io/badge/SQLGlot-v30.5.0-blue)
6
6
  <a href="https://github.com/huydo862003/Fck-AI-Slop#plan"><img src="https://img.shields.io/badge/human%20slop-90EE90"></a>
7
7
 
8
8
  A JavaScript/TypeScript port of [SQLGlot](https://github.com/tobymao/sqlglot) which is compatible with browser and Node runtimes.
@@ -29,37 +29,34 @@ NOTICE: AI is not the decision maker, designer or maintainer for this project. I
29
29
  ## Installation
30
30
 
31
31
  ```bash
32
- npm install sqlingo
33
- # or
34
- pnpm add sqlingo
32
+ npm install sqlingo luxon
35
33
  ```
36
34
 
37
35
  Peer dependency: [`luxon`](https://www.npmjs.com/package/luxon) (^3.7.2) is required for date/time operations.
38
36
 
39
37
  ## Quick Start
40
38
 
41
- This example demonstrates transpiling a query from Spark to Postgres and then optimizing it.
42
-
43
39
  ```ts
44
40
  import { transpile, parseOne, optimize, MappingSchema } from "sqlingo";
41
+ import { MySQL } from "sqlingo/mysql";
45
42
  import { Postgres } from "sqlingo/postgres";
46
- import { Spark } from "sqlingo/spark";
47
43
 
48
44
  // Transpile between dialects
49
- const [pgSql] = transpile("SELECT APPROX_COUNT_DISTINCT(x) FROM table", {
50
- read: Spark,
45
+ const [pgSql] = transpile("SELECT DATE_SUB(d, INTERVAL 1 DAY) FROM t", {
46
+ read: MySQL,
51
47
  write: Postgres,
52
48
  });
53
49
  console.log(pgSql);
54
- // Output: SELECT COUNT(DISTINCT x) FROM "table"
50
+ // SELECT d - INTERVAL '1 DAY' FROM t
55
51
 
56
- // Optimize an expression
57
- const sql = "SELECT a, b FROM t WHERE a + 1 = 2";
52
+ // Optimize a query with schema information
58
53
  const schema = new MappingSchema({ t: { a: "int", b: "int" } });
59
-
60
- const optimized = optimize(parseOne(sql), { schema });
54
+ const optimized = optimize(
55
+ parseOne("SELECT * FROM t WHERE 1 = 1 AND a > 2"),
56
+ { schema },
57
+ );
61
58
  console.log(optimized.sql());
62
- // Output: SELECT t.a AS a, t.b AS b FROM t AS t WHERE t.a = 1
59
+ // SELECT "t"."a" AS "a", "t"."b" AS "b" FROM "t" AS "t" WHERE "t"."a" > 2
63
60
  ```
64
61
 
65
62
  ## Core Usage
@@ -75,7 +72,7 @@ import { parse, parseOne } from "sqlingo";
75
72
  const expressions = parse("SELECT 1; SELECT 2");
76
73
 
77
74
  // Parse a single statement
78
- const expr = parseOne("SELECT a, b FROM t WHERE a > 1");
75
+ const ast = parseOne("SELECT a, b FROM t WHERE a > 1");
79
76
  ```
80
77
 
81
78
  ### Transpiling
@@ -91,7 +88,8 @@ const [result] = transpile("SELECT EPOCH_MS(1618088028295)", {
91
88
  read: DuckDB,
92
89
  write: Hive,
93
90
  });
94
- // Output: "SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))"
91
+ console.log(result);
92
+ // SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))
95
93
  ```
96
94
 
97
95
  ### Tokenizing
@@ -102,9 +100,7 @@ Extract tokens from a SQL string for lower-level analysis.
102
100
  import { tokenize } from "sqlingo";
103
101
  import { Postgres } from "sqlingo/postgres";
104
102
 
105
- const tokens = tokenize("SELECT 1", {
106
- dialect: Postgres,
107
- });
103
+ const tokens = tokenize("SELECT 1", Postgres);
108
104
  ```
109
105
 
110
106
  ## SQL Builder
@@ -115,14 +111,10 @@ Build queries programmatically using a fluent API.
115
111
  import { select, condition } from "sqlingo";
116
112
  import { MySQL } from "sqlingo/mysql";
117
113
 
118
- const query = select("a", "b").from("t").where(condition("a > 1")).limit(10);
114
+ const query = select(["a", "b"]).from("t").where(condition("a > 1")).limit(10);
119
115
 
120
- console.log(
121
- query.sql({
122
- dialect: MySQL,
123
- }),
124
- );
125
- // Output: SELECT a, b FROM t WHERE a > 1 LIMIT 10
116
+ console.log(query.sql({ dialect: MySQL }));
117
+ // SELECT a, b FROM t WHERE a > 1 LIMIT 10
126
118
  ```
127
119
 
128
120
  ## Optimization & Analysis
@@ -132,13 +124,13 @@ console.log(
132
124
  Simplify and normalize queries based on schema information.
133
125
 
134
126
  ```ts
135
- import { optimize, MappingSchema } from "sqlingo";
136
-
137
- const schema = new MappingSchema({
138
- // define your schema
139
- });
127
+ import { optimize, parseOne, MappingSchema } from "sqlingo";
140
128
 
129
+ const schema = new MappingSchema({ t: { a: "int" } });
141
130
  const optimized = optimize(parseOne("SELECT * FROM t"), { schema });
131
+
132
+ console.log(optimized.sql());
133
+ // SELECT "t"."a" AS "a" FROM "t" AS "t"
142
134
  ```
143
135
 
144
136
  ### Column Lineage
@@ -149,8 +141,10 @@ Trace the origin of columns through subqueries and joins.
149
141
  import { lineage } from "sqlingo";
150
142
 
151
143
  const node = lineage("b", "SELECT a AS b FROM (SELECT x AS a FROM y)");
152
- console.log(node.source.name);
153
- // Output: "y"
144
+ console.log(node.name);
145
+ // "b"
146
+ console.log(node.downstream[0].name);
147
+ // "_0.a"
154
148
  ```
155
149
 
156
150
  ## Registering a Custom Dialect
@@ -158,20 +152,30 @@ console.log(node.source.name);
158
152
  You can extend the library by registering custom dialects or overriding existing behavior.
159
153
 
160
154
  ```ts
161
- import { Dialect, Generator, transpile } from "sqlingo";
155
+ import { Dialect, Generator, ArrayAggExpr, transpile } from "sqlingo";
156
+
157
+ class MyGenerator extends Generator {
158
+ static get ORIGINAL_TRANSFORMS() {
159
+ return new Map([
160
+ ...Generator.TRANSFORMS,
161
+ // Rewrite ARRAY_AGG as GROUP_CONCAT in this dialect
162
+ [ArrayAggExpr, function (this: Generator, e: ArrayAggExpr) {
163
+ return `GROUP_CONCAT(${this.sql(e, "this")})`;
164
+ }],
165
+ ]);
166
+ }
167
+ }
162
168
 
163
169
  class MyDialect extends Dialect {
164
170
  static DIALECT_NAME = "my_dialect";
165
-
166
- static Generator = class extends Generator {
167
- // Override how specific expressions are generated
168
- };
171
+ static Generator = MyGenerator;
169
172
  }
170
173
 
171
- // Register for string-based lookup
172
174
  Dialect.register(MyDialect);
173
175
 
174
- const [result] = transpile("SELECT 1", { write: MyDialect });
176
+ const [result] = transpile("SELECT ARRAY_AGG(x) FROM t", { write: MyDialect });
177
+ console.log(result);
178
+ // SELECT GROUP_CONCAT(x) FROM t
175
179
  ```
176
180
 
177
181
  ## Supported Dialects
@@ -180,7 +184,7 @@ Athena, BigQuery, ClickHouse, Databricks, Doris, Dremio, Drill, Druid, DuckDB, D
180
184
 
181
185
  ## SQLGlot Compatibility
182
186
 
183
- This package tracks [SQLGlot](https://github.com/tobymao/sqlglot) v30.1.0 (commit `8726250`). The API surface mirrors SQLGlot's Python API, adapted to TypeScript conventions. See [CONVENTION.md](https://github.com/huydo862003/sqlingo/blob/master/packages/sqlingo/CONVENTION.md) for details.
187
+ This package tracks [SQLGlot](https://github.com/tobymao/sqlglot) v30.5.0 (commit `64d385f`). The API surface mirrors SQLGlot's Python API, adapted to TypeScript conventions. See [CONVENTION.md](https://github.com/huydo862003/sqlingo/blob/master/packages/sqlingo/CONVENTION.md) for details.
184
188
 
185
189
  ## License
186
190
 
package/README.npm.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/sqlingo)](https://www.npmjs.com/package/sqlingo)
4
4
  [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/huydo862003/sqlingo/blob/master/LICENSE)
5
- ![SQLGlot](https://img.shields.io/badge/SQLGlot-v30.1.0-blue)
5
+ ![SQLGlot](https://img.shields.io/badge/SQLGlot-v30.5.0-blue)
6
6
  <a href="https://github.com/huydo862003/Fck-AI-Slop#plan"><img src="https://img.shields.io/badge/human%20slop-90EE90"></a>
7
7
 
8
8
  A JavaScript/TypeScript port of [SQLGlot](https://github.com/tobymao/sqlglot) which is compatible with browser and Node runtimes.
@@ -29,37 +29,34 @@ NOTICE: AI is not the decision maker, designer or maintainer for this project. I
29
29
  ## Installation
30
30
 
31
31
  ```bash
32
- npm install sqlingo
33
- # or
34
- pnpm add sqlingo
32
+ npm install sqlingo luxon
35
33
  ```
36
34
 
37
35
  Peer dependency: [`luxon`](https://www.npmjs.com/package/luxon) (^3.7.2) is required for date/time operations.
38
36
 
39
37
  ## Quick Start
40
38
 
41
- This example demonstrates transpiling a query from Spark to Postgres and then optimizing it.
42
-
43
39
  ```ts
44
40
  import { transpile, parseOne, optimize, MappingSchema } from "sqlingo";
41
+ import { MySQL } from "sqlingo/mysql";
45
42
  import { Postgres } from "sqlingo/postgres";
46
- import { Spark } from "sqlingo/spark";
47
43
 
48
44
  // Transpile between dialects
49
- const [pgSql] = transpile("SELECT APPROX_COUNT_DISTINCT(x) FROM table", {
50
- read: Spark,
45
+ const [pgSql] = transpile("SELECT DATE_SUB(d, INTERVAL 1 DAY) FROM t", {
46
+ read: MySQL,
51
47
  write: Postgres,
52
48
  });
53
49
  console.log(pgSql);
54
- // Output: SELECT COUNT(DISTINCT x) FROM "table"
50
+ // SELECT d - INTERVAL '1 DAY' FROM t
55
51
 
56
- // Optimize an expression
57
- const sql = "SELECT a, b FROM t WHERE a + 1 = 2";
52
+ // Optimize a query with schema information
58
53
  const schema = new MappingSchema({ t: { a: "int", b: "int" } });
59
-
60
- const optimized = optimize(parseOne(sql), { schema });
54
+ const optimized = optimize(
55
+ parseOne("SELECT * FROM t WHERE 1 = 1 AND a > 2"),
56
+ { schema },
57
+ );
61
58
  console.log(optimized.sql());
62
- // Output: SELECT t.a AS a, t.b AS b FROM t AS t WHERE t.a = 1
59
+ // SELECT "t"."a" AS "a", "t"."b" AS "b" FROM "t" AS "t" WHERE "t"."a" > 2
63
60
  ```
64
61
 
65
62
  ## Core Usage
@@ -75,7 +72,7 @@ import { parse, parseOne } from "sqlingo";
75
72
  const expressions = parse("SELECT 1; SELECT 2");
76
73
 
77
74
  // Parse a single statement
78
- const expr = parseOne("SELECT a, b FROM t WHERE a > 1");
75
+ const ast = parseOne("SELECT a, b FROM t WHERE a > 1");
79
76
  ```
80
77
 
81
78
  ### Transpiling
@@ -91,7 +88,8 @@ const [result] = transpile("SELECT EPOCH_MS(1618088028295)", {
91
88
  read: DuckDB,
92
89
  write: Hive,
93
90
  });
94
- // Output: "SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))"
91
+ console.log(result);
92
+ // SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))
95
93
  ```
96
94
 
97
95
  ### Tokenizing
@@ -102,9 +100,7 @@ Extract tokens from a SQL string for lower-level analysis.
102
100
  import { tokenize } from "sqlingo";
103
101
  import { Postgres } from "sqlingo/postgres";
104
102
 
105
- const tokens = tokenize("SELECT 1", {
106
- dialect: Postgres,
107
- });
103
+ const tokens = tokenize("SELECT 1", Postgres);
108
104
  ```
109
105
 
110
106
  ## SQL Builder
@@ -115,14 +111,10 @@ Build queries programmatically using a fluent API.
115
111
  import { select, condition } from "sqlingo";
116
112
  import { MySQL } from "sqlingo/mysql";
117
113
 
118
- const query = select("a", "b").from("t").where(condition("a > 1")).limit(10);
114
+ const query = select(["a", "b"]).from("t").where(condition("a > 1")).limit(10);
119
115
 
120
- console.log(
121
- query.sql({
122
- dialect: MySQL,
123
- }),
124
- );
125
- // Output: SELECT a, b FROM t WHERE a > 1 LIMIT 10
116
+ console.log(query.sql({ dialect: MySQL }));
117
+ // SELECT a, b FROM t WHERE a > 1 LIMIT 10
126
118
  ```
127
119
 
128
120
  ## Optimization & Analysis
@@ -132,13 +124,13 @@ console.log(
132
124
  Simplify and normalize queries based on schema information.
133
125
 
134
126
  ```ts
135
- import { optimize, MappingSchema } from "sqlingo";
136
-
137
- const schema = new MappingSchema({
138
- // define your schema
139
- });
127
+ import { optimize, parseOne, MappingSchema } from "sqlingo";
140
128
 
129
+ const schema = new MappingSchema({ t: { a: "int" } });
141
130
  const optimized = optimize(parseOne("SELECT * FROM t"), { schema });
131
+
132
+ console.log(optimized.sql());
133
+ // SELECT "t"."a" AS "a" FROM "t" AS "t"
142
134
  ```
143
135
 
144
136
  ### Column Lineage
@@ -149,8 +141,10 @@ Trace the origin of columns through subqueries and joins.
149
141
  import { lineage } from "sqlingo";
150
142
 
151
143
  const node = lineage("b", "SELECT a AS b FROM (SELECT x AS a FROM y)");
152
- console.log(node.source.name);
153
- // Output: "y"
144
+ console.log(node.name);
145
+ // "b"
146
+ console.log(node.downstream[0].name);
147
+ // "_0.a"
154
148
  ```
155
149
 
156
150
  ## Registering a Custom Dialect
@@ -158,20 +152,30 @@ console.log(node.source.name);
158
152
  You can extend the library by registering custom dialects or overriding existing behavior.
159
153
 
160
154
  ```ts
161
- import { Dialect, Generator, transpile } from "sqlingo";
155
+ import { Dialect, Generator, ArrayAggExpr, transpile } from "sqlingo";
156
+
157
+ class MyGenerator extends Generator {
158
+ static get ORIGINAL_TRANSFORMS() {
159
+ return new Map([
160
+ ...Generator.TRANSFORMS,
161
+ // Rewrite ARRAY_AGG as GROUP_CONCAT in this dialect
162
+ [ArrayAggExpr, function (this: Generator, e: ArrayAggExpr) {
163
+ return `GROUP_CONCAT(${this.sql(e, "this")})`;
164
+ }],
165
+ ]);
166
+ }
167
+ }
162
168
 
163
169
  class MyDialect extends Dialect {
164
170
  static DIALECT_NAME = "my_dialect";
165
-
166
- static Generator = class extends Generator {
167
- // Override how specific expressions are generated
168
- };
171
+ static Generator = MyGenerator;
169
172
  }
170
173
 
171
- // Register for string-based lookup
172
174
  Dialect.register(MyDialect);
173
175
 
174
- const [result] = transpile("SELECT 1", { write: MyDialect });
176
+ const [result] = transpile("SELECT ARRAY_AGG(x) FROM t", { write: MyDialect });
177
+ console.log(result);
178
+ // SELECT GROUP_CONCAT(x) FROM t
175
179
  ```
176
180
 
177
181
  ## Supported Dialects
@@ -180,7 +184,7 @@ Athena, BigQuery, ClickHouse, Databricks, Doris, Dremio, Drill, Druid, DuckDB, D
180
184
 
181
185
  ## SQLGlot Compatibility
182
186
 
183
- This package tracks [SQLGlot](https://github.com/tobymao/sqlglot) v30.1.0 (commit `8726250`). The API surface mirrors SQLGlot's Python API, adapted to TypeScript conventions. See [CONVENTION.md](https://github.com/huydo862003/sqlingo/blob/master/packages/sqlingo/CONVENTION.md) for details.
187
+ This package tracks [SQLGlot](https://github.com/tobymao/sqlglot) v30.5.0 (commit `64d385f`). The API surface mirrors SQLGlot's Python API, adapted to TypeScript conventions. See [CONVENTION.md](https://github.com/huydo862003/sqlingo/blob/master/packages/sqlingo/CONVENTION.md) for details.
184
188
 
185
189
  ## License
186
190
 
package/README.repo.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/sqlingo)](https://www.npmjs.com/package/sqlingo)
4
4
  [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/huydo862003/sqlingo/blob/master/LICENSE)
5
- ![SQLGlot](https://img.shields.io/badge/SQLGlot-v30.1.0-blue)
5
+ ![SQLGlot](https://img.shields.io/badge/SQLGlot-v30.5.0-blue)
6
6
  <a href="https://github.com/huydo862003/Fck-AI-Slop#plan"><img src="https://img.shields.io/badge/human%20slop-90EE90"></a>
7
7
 
8
8
  A JavaScript/TypeScript port of [SQLGlot](https://github.com/tobymao/sqlglot) which is compatible with browser and Node runtimes.
@@ -29,37 +29,34 @@ NOTICE: AI is not the decision maker, designer or maintainer for this project. I
29
29
  ## Installation
30
30
 
31
31
  ```bash
32
- npm install sqlingo
33
- # or
34
- pnpm add sqlingo
32
+ npm install sqlingo luxon
35
33
  ```
36
34
 
37
35
  Peer dependency: [`luxon`](https://www.npmjs.com/package/luxon) (^3.7.2) is required for date/time operations.
38
36
 
39
37
  ## Quick Start
40
38
 
41
- This example demonstrates transpiling a query from Spark to Postgres and then optimizing it.
42
-
43
39
  ```ts
44
40
  import { transpile, parseOne, optimize, MappingSchema } from "sqlingo";
41
+ import { MySQL } from "sqlingo/mysql";
45
42
  import { Postgres } from "sqlingo/postgres";
46
- import { Spark } from "sqlingo/spark";
47
43
 
48
44
  // Transpile between dialects
49
- const [pgSql] = transpile("SELECT APPROX_COUNT_DISTINCT(x) FROM table", {
50
- read: Spark,
45
+ const [pgSql] = transpile("SELECT DATE_SUB(d, INTERVAL 1 DAY) FROM t", {
46
+ read: MySQL,
51
47
  write: Postgres,
52
48
  });
53
49
  console.log(pgSql);
54
- // Output: SELECT COUNT(DISTINCT x) FROM "table"
50
+ // SELECT d - INTERVAL '1 DAY' FROM t
55
51
 
56
- // Optimize an expression
57
- const sql = "SELECT a, b FROM t WHERE a + 1 = 2";
52
+ // Optimize a query with schema information
58
53
  const schema = new MappingSchema({ t: { a: "int", b: "int" } });
59
-
60
- const optimized = optimize(parseOne(sql), { schema });
54
+ const optimized = optimize(
55
+ parseOne("SELECT * FROM t WHERE 1 = 1 AND a > 2"),
56
+ { schema },
57
+ );
61
58
  console.log(optimized.sql());
62
- // Output: SELECT t.a AS a, t.b AS b FROM t AS t WHERE t.a = 1
59
+ // SELECT "t"."a" AS "a", "t"."b" AS "b" FROM "t" AS "t" WHERE "t"."a" > 2
63
60
  ```
64
61
 
65
62
  ## Core Usage
@@ -75,7 +72,7 @@ import { parse, parseOne } from "sqlingo";
75
72
  const expressions = parse("SELECT 1; SELECT 2");
76
73
 
77
74
  // Parse a single statement
78
- const expr = parseOne("SELECT a, b FROM t WHERE a > 1");
75
+ const ast = parseOne("SELECT a, b FROM t WHERE a > 1");
79
76
  ```
80
77
 
81
78
  ### Transpiling
@@ -91,7 +88,8 @@ const [result] = transpile("SELECT EPOCH_MS(1618088028295)", {
91
88
  read: DuckDB,
92
89
  write: Hive,
93
90
  });
94
- // Output: "SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))"
91
+ console.log(result);
92
+ // SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))
95
93
  ```
96
94
 
97
95
  ### Tokenizing
@@ -102,9 +100,7 @@ Extract tokens from a SQL string for lower-level analysis.
102
100
  import { tokenize } from "sqlingo";
103
101
  import { Postgres } from "sqlingo/postgres";
104
102
 
105
- const tokens = tokenize("SELECT 1", {
106
- dialect: Postgres,
107
- });
103
+ const tokens = tokenize("SELECT 1", Postgres);
108
104
  ```
109
105
 
110
106
  ## SQL Builder
@@ -115,14 +111,10 @@ Build queries programmatically using a fluent API.
115
111
  import { select, condition } from "sqlingo";
116
112
  import { MySQL } from "sqlingo/mysql";
117
113
 
118
- const query = select("a", "b").from("t").where(condition("a > 1")).limit(10);
114
+ const query = select(["a", "b"]).from("t").where(condition("a > 1")).limit(10);
119
115
 
120
- console.log(
121
- query.sql({
122
- dialect: MySQL,
123
- }),
124
- );
125
- // Output: SELECT a, b FROM t WHERE a > 1 LIMIT 10
116
+ console.log(query.sql({ dialect: MySQL }));
117
+ // SELECT a, b FROM t WHERE a > 1 LIMIT 10
126
118
  ```
127
119
 
128
120
  ## Optimization & Analysis
@@ -132,13 +124,13 @@ console.log(
132
124
  Simplify and normalize queries based on schema information.
133
125
 
134
126
  ```ts
135
- import { optimize, MappingSchema } from "sqlingo";
136
-
137
- const schema = new MappingSchema({
138
- // define your schema
139
- });
127
+ import { optimize, parseOne, MappingSchema } from "sqlingo";
140
128
 
129
+ const schema = new MappingSchema({ t: { a: "int" } });
141
130
  const optimized = optimize(parseOne("SELECT * FROM t"), { schema });
131
+
132
+ console.log(optimized.sql());
133
+ // SELECT "t"."a" AS "a" FROM "t" AS "t"
142
134
  ```
143
135
 
144
136
  ### Column Lineage
@@ -149,8 +141,10 @@ Trace the origin of columns through subqueries and joins.
149
141
  import { lineage } from "sqlingo";
150
142
 
151
143
  const node = lineage("b", "SELECT a AS b FROM (SELECT x AS a FROM y)");
152
- console.log(node.source.name);
153
- // Output: "y"
144
+ console.log(node.name);
145
+ // "b"
146
+ console.log(node.downstream[0].name);
147
+ // "_0.a"
154
148
  ```
155
149
 
156
150
  ## Registering a Custom Dialect
@@ -158,20 +152,30 @@ console.log(node.source.name);
158
152
  You can extend the library by registering custom dialects or overriding existing behavior.
159
153
 
160
154
  ```ts
161
- import { Dialect, Generator, transpile } from "sqlingo";
155
+ import { Dialect, Generator, ArrayAggExpr, transpile } from "sqlingo";
156
+
157
+ class MyGenerator extends Generator {
158
+ static get ORIGINAL_TRANSFORMS() {
159
+ return new Map([
160
+ ...Generator.TRANSFORMS,
161
+ // Rewrite ARRAY_AGG as GROUP_CONCAT in this dialect
162
+ [ArrayAggExpr, function (this: Generator, e: ArrayAggExpr) {
163
+ return `GROUP_CONCAT(${this.sql(e, "this")})`;
164
+ }],
165
+ ]);
166
+ }
167
+ }
162
168
 
163
169
  class MyDialect extends Dialect {
164
170
  static DIALECT_NAME = "my_dialect";
165
-
166
- static Generator = class extends Generator {
167
- // Override how specific expressions are generated
168
- };
171
+ static Generator = MyGenerator;
169
172
  }
170
173
 
171
- // Register for string-based lookup
172
174
  Dialect.register(MyDialect);
173
175
 
174
- const [result] = transpile("SELECT 1", { write: MyDialect });
176
+ const [result] = transpile("SELECT ARRAY_AGG(x) FROM t", { write: MyDialect });
177
+ console.log(result);
178
+ // SELECT GROUP_CONCAT(x) FROM t
175
179
  ```
176
180
 
177
181
  ## Supported Dialects
@@ -180,7 +184,7 @@ Athena, BigQuery, ClickHouse, Databricks, Doris, Dremio, Drill, Druid, DuckDB, D
180
184
 
181
185
  ## SQLGlot Compatibility
182
186
 
183
- This package tracks [SQLGlot](https://github.com/tobymao/sqlglot) v30.0.0 (commit `a3929be`). The API surface mirrors SQLGlot's Python API, adapted to TypeScript conventions. See [CONVENTION.md](https://github.com/huydo862003/sqlingo/blob/master/packages/sqlingo/CONVENTION.md) for details.
187
+ This package tracks [SQLGlot](https://github.com/tobymao/sqlglot) v30.5.0 (commit `64d385f`). The API surface mirrors SQLGlot's Python API, adapted to TypeScript conventions. See [CONVENTION.md](https://github.com/huydo862003/sqlingo/blob/master/packages/sqlingo/CONVENTION.md) for details.
184
188
 
185
189
  ## License
186
190
 
@@ -0,0 +1,2 @@
1
+ import{$k as Z,$q as Jt,$t as op,$v as Ap,Ak as b,Am as Cr,Ap as dt,Ar as ie,Bl as pr,Bm as Mr,Bp as ht,Bq as Kt,Br as xe,Ck as U,Cl as nr,Cm as Dr,Cq as wt,Dd as A,Dk as F,Dl as ar,Dm as Rr,Dq as Wt,Dr as ce,Ds as Me,Ek as v,El as or,Em as fr,Eo as it,Eq as zt,Es as De,Fk as K,Fo as xt,Fp as gt,Fs as Re,Gd as M,Gk as w,Gm as Sr,Gp as mt,Gq as Gt,Gs as fe,Hf as D,Hm as Br,Ho as ct,Hp as Ct,Hs as Se,Ik as W,Io as Tt,Is as Be,Jk as z,Jo as ut,Jp as Mt,Jt as Ye,Kk as G,Kn as Hr,Ko as At,Ks as Oe,Kt as Ze,Lk as H,Ll as Er,Ln as Vr,Lo as yt,Lr as Te,Ls as Pe,Mk as V,Mm as Or,Mn as _r,Mp as Dt,Mq as Ht,Mr as ue,Ms as Ne,Nk as _,Np as Rt,Nq as Vt,Ns as Ie,Nt as $e,Ok as q,Om as Pr,Oq as _t,Os as Le,Ot as ke,Qk as X,Rm as Nr,Rn as qr,Rs as be,Rt as Je,Sk as Y,Sp as ft,Sq as qt,Ss as Ue,To as lt,Tp as St,Ts as Fe,Tt as Qe,Up as Bt,Uq as Xt,Us as ve,Ut as je,Vm as Ir,Vp as Ot,Vq as Yt,Vs as Ke,Vt as rp,Wm as Lr,Wp as Pt,Wq as Zt,Ws as we,Wt as tp,Xm as br,Xp as Nt,Xq as $t,Xt as ep,Ym as Ur,Yn as Xr,Yp as It,Yq as kt,Ys as We,Yt as pp,Zl as sr,Zn as Yr,Zt as np,_n as Zr,_r as Ae,_t as ap,a,ar as Qt,at as ze,au as Ep,b as l,bn as Fr,bo as $r,bq as Lt,br as jt,bs as ye,bt as Ge,bu as sp,c as d,cl as $,cm as ir,co as kr,cq as bt,cr as re,ct as He,d as h,do as Jr,dq as Ut,dt as Ve,e as g,eo as Qr,fl as k,fn as vr,fo as jr,ft as _e,gq as Ft,hc as C,hu as ip,ik as R,il as J,iu as xp,jo as rt,jq as vt,ju as cp,kk as f,kl as Q,km as xr,ll as j,lm as cr,lr as te,ls as le,lu as Tp,mk as S,ml as rr,mm as Tr,mn as Kr,mr as ee,mu as up,nm as ur,ns as de,o,ok as B,om as Ar,on as wr,oo as tt,pk as O,pn as Wr,po as et,pr as pe,pt as qe,qe as E,qo as pt,qr as ne,r as u,rk as P,rl as tr,ro as nt,rr as ae,s as m,so as at,sr as oe,ss as he,st as Xe,to as ot,tr as Ee,um as yr,uo as Et,ur as se,us as ge,vl as er,vm as lr,vn as zr,vo as st,wk as N,wm as dr,ws as me,xb as i,xm as hr,yk as I,ym as gr,yn as Gr,zk as L,zm as mr,zs as Ce}from"./chunk-LXNDZZBH.js";var Cp=new Set(["DAY","WEEK","MONTH","QUARTER","YEAR"]),c=38,Mp=37;function Dp(r){return this.annotateByArgs(r,["this"]),r.isType("null")&&this.setType(r,"varchar"),r}a(Dp,"annotateReverse");function Rp(r){return r.args.zone?this.setType(r,"timestamptz"):this.setType(r,"timestamp"),r}a(Rp,"annotateTimestampFromParts");function yp(r){let p=r.args.this;return o(p,i)&&p.isType("date")&&!Cp.has(r.text("unit").toUpperCase())?this.setType(r,"timestampntz"):this.annotateByArgs(r,["this"]),r}a(yp,"annotateDateOrTimeAdd");function fp(r){let p=r.args.expressions??[],n=[];for(let e=2;e<p.length;e+=2)n.push(p[e].type);p.length%2===0&&n.push(p[p.length-1].type);let t;for(let e of n){let s=o(e,E)?e:void 0;t=this.maybeCoerce(t||s,s)}return this.setType(r,t),r}a(fp,"annotateDecodeCase");function lp(r){let p=r.args.this,n=o(p,i)?p.type:void 0;return this.setType(r,r.args.count?"array":o(n,E)?n:void 0),r}a(lp,"annotateArgMaxMin");function Sp(r){let p=r.args.this,n=r.args.expression,t=o(n,A)?n.args.expressions??[]:[];if((o(p,ke)||o(p,$e))&&o(n,A)&&t.length===1&&o(t[0],M)){let e=t[0].args.this,s=o(e,i)?e.type:void 0;this.setType(r,o(s,E)?s:void 0)}else this.setType(r,o(p,i)?p.type:void 0);return r}a(Sp,"annotateWithinGroup");function Bp(r){this.annotateByArgs(r,["this"]);let p=r.args.this,n=o(p,i)?p.type:void 0;if(!o(n,E))return r;if(n.isType("double"))this.setType(r,"double");else{let t=u(n.args.expressions??[],i),e=t[0]?Number(t[0].text("this")):c,s=t[1]?Number(t[1].text("this")):0,T=Math.min(e+3,c),gp=Math.min(s+3,Mp),mp=E.build(`NUMBER(${T}, ${gp})`,{dialect:this.dialect._constructor});this.setType(r,mp)}return r}a(Bp,"annotateMedian");function Op(r){this.annotateByArgs(r,["this"]);let p=r.args.this,n=o(p,i)?p.type:void 0;if(!o(n,E))return r;if(n.isType("decfloat"))this.setType(r,E.build("DECFLOAT",{dialect:this.dialect._constructor}));else if(n.isType(["float","double"]))this.setType(r,"double");else{let t=u(n.args.expressions??[],i),e=t[1]?Number(t[1].text("this")):0,s=e===0?6:Math.max(12,e),T=E.build(`NUMBER(${c}, ${s})`,{dialect:this.dialect._constructor});this.setType(r,T)}return r}a(Op,"annotateVariance");function Pp(r){this.annotateByArgs(r,["this"]);let p=r.args.this,n=o(p,i)?p.type:void 0;return o(n,E)?(n.isType("decfloat")?this.setType(r,E.build("DECFLOAT",{dialect:this.dialect._constructor})):n.isType(["float","double"])?this.setType(r,"double"):this.setType(r,E.build(`NUMBER(${c}, 12)`,{dialect:this.dialect._constructor})),r):(this.setType(r,E.build(`NUMBER(${c}, 12)`,{dialect:this.dialect._constructor})),r)}a(Pp,"annotateKurtosis");function Np(r){this.annotateByArgs(r,["this"]);let p=r.args.this;if(o(p,i)&&p.isType("decfloat")){let n=p.type;this.setType(r,o(n,E)?n:void 0)}else this.setType(r,"double");return r}a(Np,"annotateMathWithFloatDecfloat");function Ip(r){let p=r.args.targetType,n=o(p,E)?p:"timestamp";return this.setType(r,n),r}a(Ip,"annotateStrToTime");var hp,y;hp=[m];var x=class x{static get EXPRESSION_METADATA(){let p=new Map(Ap.EXPRESSION_METADATA),n=a((t,e)=>{for(let s of t)p.set(s,e)},"extend");return n([Ft,Ar,vr,rt,gt,Ze,k,mt,kt,Te,se,Vr,Hr],{annotator:a((t,e)=>t.annotateByArgs(e,["this"]),"annotator")}),n([Ne,Y,Z,ze,pr,or,ar,Er,nr,X,ir,Ge,_e,Pt,Vt,ae,sr],{returns:"array"}),n([G,W,z,jr,we,bt,Ut,zt,re,Ce],{returns:"bigint"}),n([et,Se,Be,ut,At,Yr,Zr,$r,kr,D,Lt,te,ee,tt,at,Et,ye],{returns:"binary"}),n([_,V,q,fe,Jr,lt,St,ie,xe,$],{returns:"boolean"}),n([ge,Gr],{returns:"date"}),n([Me,De,Re,Xt,qt,J],{annotator:a((t,e)=>t.setType(e,E.build("NUMBER",{dialect:t.dialect._constructor})),"annotator")}),n([wt,ve,U,up,Tp,F,v,K,zr,vt],{returns:"double"}),n([Q,j],{returns:"decfloat"}),n([R,f,S,B,yr,P,O,b,Qr,Dt,Rt,Kt,$t,tp,rp,ep,pp,np,sp,ap,op,Ep,Qe,je,N,ue,I,L],{annotator:a((t,e)=>Np.call(t,e),"annotator")}),n([H,Ke,w,It,ct,Mt,Tt,Jt,Qt,jt,he],{returns:"int"}),n([Je,be,Ie,Le,qe,ht,dt,me],{returns:"object"}),n([ft,Bt,Ot,Nt],{returns:"map"}),p.set(rr,{returns:"file"}),n([qr,Ae],{returns:"time"}),n([Pr,Or],{returns:"timestampltz"}),n([wr,Kr,Wr,Wt],{returns:"tinyint"}),n([He,er,Ve,pt,nt,xr,cr,Tr,ur,lr,dr,hr,gr,Cr,mr,Mr,Dr,Rr,fr,Sr,Br,Ur,Ir,Lr,br,Nr,yt,it,xt,Gt,Ht,_t,Yt,Zt,pe,ne,oe,Ee,ot,st,le],{returns:"varchar"}),n([Ue,Fe],{returns:"variant"}),n([ip,xp],{annotator:a((t,e)=>Op.call(t,e),"annotator")}),p.set(Oe,{annotator:a((t,e)=>lp.call(t,e),"annotator")}),p.set(Pe,{annotator:a((t,e)=>lp.call(t,e),"annotator")}),p.set(Xe,{annotator:a((t,e)=>t.annotateByArgs(e,["expressions"]),"annotator")}),p.set(tr,{annotator:a((t,e)=>t.setType(e,e.args.sourceTz?"timestampntz":"timestamptz"),"annotator")}),p.set(Fr,{annotator:a((t,e)=>yp.call(t,e),"annotator")}),p.set(Xr,{annotator:a((t,e)=>fp.call(t,e),"annotator")}),p.set(We,{annotator:a((t,e)=>t.setType(e,E.build("NUMBER(19, 0)",{dialect:t.dialect._constructor})),"annotator")}),p.set(cp,{annotator:a((t,e)=>Pp.call(t,e),"annotator")}),p.set(Ye,{annotator:a((t,e)=>Bp.call(t,e),"annotator")}),p.set(Ct,{annotator:a((t,e)=>Dp.call(t,e),"annotator")}),p.set(ce,{annotator:a((t,e)=>Ip.call(t,e),"annotator")}),p.set(_r,{annotator:a((t,e)=>yp.call(t,e),"annotator")}),p.set(de,{annotator:a((t,e)=>Rp.call(t,e),"annotator")}),p.set(C,{annotator:a((t,e)=>Sp.call(t,e),"annotator")}),p}};y=l(null),g(y,10,"EXPRESSION_METADATA",hp,x),d(y,x),h(y,3,x),a(x,"SnowflakeTyping");var dp=x;export{dp as a};
2
+ //# sourceMappingURL=chunk-3AQZGJOE.js.map