@hdnax/sqlingo.js 0.0.4 → 0.1.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 (245) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +8 -14
  3. package/README.npm.md +8 -14
  4. package/README.repo.md +1 -2
  5. package/dist/chunk-2YNOERAO.cjs +2 -0
  6. package/dist/chunk-2YNOERAO.cjs.map +1 -0
  7. package/dist/chunk-2Z3O2CFM.cjs +19 -0
  8. package/dist/chunk-2Z3O2CFM.cjs.map +1 -0
  9. package/dist/chunk-4ZMKB6PV.cjs +2 -0
  10. package/dist/chunk-4ZMKB6PV.cjs.map +1 -0
  11. package/dist/chunk-53OWF4GG.js +2 -0
  12. package/dist/chunk-53OWF4GG.js.map +1 -0
  13. package/dist/chunk-C4CLTVOW.cjs +2 -0
  14. package/dist/chunk-C4CLTVOW.cjs.map +1 -0
  15. package/dist/chunk-DOKMTZYO.cjs +4 -0
  16. package/dist/chunk-DOKMTZYO.cjs.map +1 -0
  17. package/dist/chunk-FCGUTI7Y.js +2 -0
  18. package/dist/chunk-FCGUTI7Y.js.map +1 -0
  19. package/dist/chunk-IPCIXWCY.js +2 -0
  20. package/dist/chunk-IPCIXWCY.js.map +1 -0
  21. package/dist/chunk-KCNOE4DZ.js +19 -0
  22. package/dist/chunk-KCNOE4DZ.js.map +1 -0
  23. package/dist/chunk-NRJHX2GZ.js +2 -0
  24. package/dist/chunk-NRJHX2GZ.js.map +1 -0
  25. package/dist/chunk-O2J5RKBN.js +2 -0
  26. package/dist/chunk-O2J5RKBN.js.map +1 -0
  27. package/dist/chunk-PXUASP5I.js +2 -0
  28. package/dist/chunk-PXUASP5I.js.map +1 -0
  29. package/dist/chunk-R7C3ZHVK.cjs +2 -0
  30. package/dist/chunk-R7C3ZHVK.cjs.map +1 -0
  31. package/dist/chunk-UHWHUDLE.cjs +2 -0
  32. package/dist/chunk-UHWHUDLE.cjs.map +1 -0
  33. package/dist/chunk-WRNYJ54A.cjs +2 -0
  34. package/dist/chunk-WRNYJ54A.cjs.map +1 -0
  35. package/dist/chunk-XZQFOICX.cjs +3 -0
  36. package/dist/chunk-XZQFOICX.cjs.map +1 -0
  37. package/dist/chunk-YLOQRUXC.js +2 -0
  38. package/dist/chunk-YLOQRUXC.js.map +1 -0
  39. package/dist/chunk-YSS2WVCM.cjs +2 -0
  40. package/dist/chunk-YSS2WVCM.cjs.map +1 -0
  41. package/dist/chunk-Z5V6VOIN.js +3 -0
  42. package/dist/chunk-Z5V6VOIN.js.map +1 -0
  43. package/dist/chunk-ZBFGQPJR.js +4 -0
  44. package/dist/chunk-ZBFGQPJR.js.map +1 -0
  45. package/dist/dialects/athena.cjs +2 -0
  46. package/dist/dialects/athena.cjs.map +1 -0
  47. package/dist/dialects/athena.d.cts +66 -0
  48. package/dist/dialects/athena.d.ts +66 -0
  49. package/dist/dialects/athena.js +2 -0
  50. package/dist/dialects/athena.js.map +1 -0
  51. package/dist/dialects/bigquery.cjs +3 -0
  52. package/dist/dialects/bigquery.cjs.map +1 -0
  53. package/dist/dialects/bigquery.d.cts +651 -0
  54. package/dist/dialects/bigquery.d.ts +651 -0
  55. package/dist/dialects/bigquery.js +3 -0
  56. package/dist/dialects/bigquery.js.map +1 -0
  57. package/dist/dialects/clickhouse.cjs +2 -0
  58. package/dist/dialects/clickhouse.cjs.map +1 -0
  59. package/dist/dialects/clickhouse.d.cts +634 -0
  60. package/dist/dialects/clickhouse.d.ts +634 -0
  61. package/dist/dialects/clickhouse.js +2 -0
  62. package/dist/dialects/clickhouse.js.map +1 -0
  63. package/dist/dialects/databricks.cjs +2 -0
  64. package/dist/dialects/databricks.cjs.map +1 -0
  65. package/dist/dialects/databricks.d.cts +484 -0
  66. package/dist/dialects/databricks.d.ts +484 -0
  67. package/dist/dialects/databricks.js +2 -0
  68. package/dist/dialects/databricks.js.map +1 -0
  69. package/dist/dialects/doris.cjs +2 -0
  70. package/dist/dialects/doris.cjs.map +1 -0
  71. package/dist/dialects/doris.d.cts +484 -0
  72. package/dist/dialects/doris.d.ts +484 -0
  73. package/dist/dialects/doris.js +2 -0
  74. package/dist/dialects/doris.js.map +1 -0
  75. package/dist/dialects/dremio.cjs +2 -0
  76. package/dist/dialects/dremio.cjs.map +1 -0
  77. package/dist/dialects/dremio.d.cts +522 -0
  78. package/dist/dialects/dremio.d.ts +522 -0
  79. package/dist/dialects/dremio.js +2 -0
  80. package/dist/dialects/dremio.js.map +1 -0
  81. package/dist/dialects/drill.cjs +2 -0
  82. package/dist/dialects/drill.cjs.map +1 -0
  83. package/dist/dialects/drill.d.cts +512 -0
  84. package/dist/dialects/drill.d.ts +512 -0
  85. package/dist/dialects/drill.js +2 -0
  86. package/dist/dialects/drill.js.map +1 -0
  87. package/dist/dialects/druid.cjs +2 -0
  88. package/dist/dialects/druid.cjs.map +1 -0
  89. package/dist/dialects/druid.d.cts +17 -0
  90. package/dist/dialects/druid.d.ts +17 -0
  91. package/dist/dialects/druid.js +2 -0
  92. package/dist/dialects/druid.js.map +1 -0
  93. package/dist/dialects/duckdb.cjs +86 -0
  94. package/dist/dialects/duckdb.cjs.map +1 -0
  95. package/dist/dialects/duckdb.d.cts +756 -0
  96. package/dist/dialects/duckdb.d.ts +756 -0
  97. package/dist/dialects/duckdb.js +86 -0
  98. package/dist/dialects/duckdb.js.map +1 -0
  99. package/dist/dialects/dune.cjs +2 -0
  100. package/dist/dialects/dune.cjs.map +1 -0
  101. package/dist/dialects/dune.d.cts +21 -0
  102. package/dist/dialects/dune.d.ts +21 -0
  103. package/dist/dialects/dune.js +2 -0
  104. package/dist/dialects/dune.js.map +1 -0
  105. package/dist/dialects/exasol.cjs +2 -0
  106. package/dist/dialects/exasol.cjs.map +1 -0
  107. package/dist/dialects/exasol.d.cts +507 -0
  108. package/dist/dialects/exasol.d.ts +507 -0
  109. package/dist/dialects/exasol.js +2 -0
  110. package/dist/dialects/exasol.js.map +1 -0
  111. package/dist/dialects/fabric.cjs +2 -0
  112. package/dist/dialects/fabric.cjs.map +1 -0
  113. package/dist/dialects/fabric.d.cts +463 -0
  114. package/dist/dialects/fabric.d.ts +463 -0
  115. package/dist/dialects/fabric.js +2 -0
  116. package/dist/dialects/fabric.js.map +1 -0
  117. package/dist/dialects/hive.cjs +2 -0
  118. package/dist/dialects/hive.cjs.map +1 -0
  119. package/dist/dialects/hive.d.cts +585 -0
  120. package/dist/dialects/hive.d.ts +585 -0
  121. package/dist/dialects/hive.js +2 -0
  122. package/dist/dialects/hive.js.map +1 -0
  123. package/dist/dialects/materialize.cjs +2 -0
  124. package/dist/dialects/materialize.cjs.map +1 -0
  125. package/dist/dialects/materialize.d.cts +890 -0
  126. package/dist/dialects/materialize.d.ts +890 -0
  127. package/dist/dialects/materialize.js +2 -0
  128. package/dist/dialects/materialize.js.map +1 -0
  129. package/dist/dialects/mysql.cjs +2 -0
  130. package/dist/dialects/mysql.cjs.map +1 -0
  131. package/dist/dialects/mysql.d.cts +292 -0
  132. package/dist/dialects/mysql.d.ts +292 -0
  133. package/dist/dialects/mysql.js +2 -0
  134. package/dist/dialects/mysql.js.map +1 -0
  135. package/dist/dialects/oracle.cjs +2 -0
  136. package/dist/dialects/oracle.cjs.map +1 -0
  137. package/dist/dialects/oracle.d.cts +539 -0
  138. package/dist/dialects/oracle.d.ts +539 -0
  139. package/dist/dialects/oracle.js +2 -0
  140. package/dist/dialects/oracle.js.map +1 -0
  141. package/dist/dialects/postgres.cjs +2 -0
  142. package/dist/dialects/postgres.cjs.map +1 -0
  143. package/dist/dialects/postgres.d.cts +587 -0
  144. package/dist/dialects/postgres.d.ts +587 -0
  145. package/dist/dialects/postgres.js +2 -0
  146. package/dist/dialects/postgres.js.map +1 -0
  147. package/dist/dialects/presto.cjs +2 -0
  148. package/dist/dialects/presto.cjs.map +1 -0
  149. package/dist/dialects/presto.d.cts +173 -0
  150. package/dist/dialects/presto.d.ts +173 -0
  151. package/dist/dialects/presto.js +2 -0
  152. package/dist/dialects/presto.js.map +1 -0
  153. package/dist/dialects/prql.cjs +2 -0
  154. package/dist/dialects/prql.cjs.map +1 -0
  155. package/dist/dialects/prql.d.cts +496 -0
  156. package/dist/dialects/prql.d.ts +496 -0
  157. package/dist/dialects/prql.js +2 -0
  158. package/dist/dialects/prql.js.map +1 -0
  159. package/dist/dialects/redshift.cjs +2 -0
  160. package/dist/dialects/redshift.cjs.map +1 -0
  161. package/dist/dialects/redshift.d.cts +132 -0
  162. package/dist/dialects/redshift.d.ts +132 -0
  163. package/dist/dialects/redshift.js +2 -0
  164. package/dist/dialects/redshift.js.map +1 -0
  165. package/dist/dialects/risingwave.cjs +2 -0
  166. package/dist/dialects/risingwave.cjs.map +1 -0
  167. package/dist/dialects/risingwave.d.cts +478 -0
  168. package/dist/dialects/risingwave.d.ts +478 -0
  169. package/dist/dialects/risingwave.js +2 -0
  170. package/dist/dialects/risingwave.js.map +1 -0
  171. package/dist/dialects/singlestore.cjs +2 -0
  172. package/dist/dialects/singlestore.cjs.map +1 -0
  173. package/dist/dialects/singlestore.d.cts +73 -0
  174. package/dist/dialects/singlestore.d.ts +73 -0
  175. package/dist/dialects/singlestore.js +2 -0
  176. package/dist/dialects/singlestore.js.map +1 -0
  177. package/dist/dialects/snowflake.cjs +3 -0
  178. package/dist/dialects/snowflake.cjs.map +1 -0
  179. package/dist/dialects/snowflake.d.cts +320 -0
  180. package/dist/dialects/snowflake.d.ts +320 -0
  181. package/dist/dialects/snowflake.js +3 -0
  182. package/dist/dialects/snowflake.js.map +1 -0
  183. package/dist/dialects/solr.cjs +2 -0
  184. package/dist/dialects/solr.cjs.map +1 -0
  185. package/dist/dialects/solr.d.cts +458 -0
  186. package/dist/dialects/solr.d.ts +458 -0
  187. package/dist/dialects/solr.js +2 -0
  188. package/dist/dialects/solr.js.map +1 -0
  189. package/dist/dialects/spark.cjs +2 -0
  190. package/dist/dialects/spark.cjs.map +1 -0
  191. package/dist/dialects/spark.d.cts +484 -0
  192. package/dist/dialects/spark.d.ts +484 -0
  193. package/dist/dialects/spark.js +2 -0
  194. package/dist/dialects/spark.js.map +1 -0
  195. package/dist/dialects/spark2.cjs +2 -0
  196. package/dist/dialects/spark2.cjs.map +1 -0
  197. package/dist/dialects/spark2.d.cts +486 -0
  198. package/dist/dialects/spark2.d.ts +486 -0
  199. package/dist/dialects/spark2.js +2 -0
  200. package/dist/dialects/spark2.js.map +1 -0
  201. package/dist/dialects/sqlite.cjs +2 -0
  202. package/dist/dialects/sqlite.cjs.map +1 -0
  203. package/dist/dialects/sqlite.d.cts +510 -0
  204. package/dist/dialects/sqlite.d.ts +510 -0
  205. package/dist/dialects/sqlite.js +2 -0
  206. package/dist/dialects/sqlite.js.map +1 -0
  207. package/dist/dialects/starrocks.cjs +2 -0
  208. package/dist/dialects/starrocks.cjs.map +1 -0
  209. package/dist/dialects/starrocks.d.cts +518 -0
  210. package/dist/dialects/starrocks.d.ts +518 -0
  211. package/dist/dialects/starrocks.js +2 -0
  212. package/dist/dialects/starrocks.js.map +1 -0
  213. package/dist/dialects/tableau.cjs +2 -0
  214. package/dist/dialects/tableau.cjs.map +1 -0
  215. package/dist/dialects/tableau.d.cts +466 -0
  216. package/dist/dialects/tableau.d.ts +466 -0
  217. package/dist/dialects/tableau.js +2 -0
  218. package/dist/dialects/tableau.js.map +1 -0
  219. package/dist/dialects/teradata.cjs +2 -0
  220. package/dist/dialects/teradata.cjs.map +1 -0
  221. package/dist/dialects/teradata.d.cts +539 -0
  222. package/dist/dialects/teradata.d.ts +539 -0
  223. package/dist/dialects/teradata.js +2 -0
  224. package/dist/dialects/teradata.js.map +1 -0
  225. package/dist/dialects/trino.cjs +2 -0
  226. package/dist/dialects/trino.cjs.map +1 -0
  227. package/dist/dialects/trino.d.cts +465 -0
  228. package/dist/dialects/trino.d.ts +465 -0
  229. package/dist/dialects/trino.js +2 -0
  230. package/dist/dialects/trino.js.map +1 -0
  231. package/dist/dialects/tsql.cjs +2 -0
  232. package/dist/dialects/tsql.cjs.map +1 -0
  233. package/dist/dialects/tsql.d.cts +703 -0
  234. package/dist/dialects/tsql.d.ts +703 -0
  235. package/dist/dialects/tsql.js +2 -0
  236. package/dist/dialects/tsql.js.map +1 -0
  237. package/dist/index.cjs +5 -25
  238. package/dist/index.cjs.map +1 -1
  239. package/dist/index.d.cts +3 -14178
  240. package/dist/index.d.ts +3 -14178
  241. package/dist/index.js +5 -25
  242. package/dist/index.js.map +1 -1
  243. package/dist/tokens-VcMD09XM.d.cts +15805 -0
  244. package/dist/tokens-VcMD09XM.d.ts +15805 -0
  245. package/package.json +171 -5
@@ -0,0 +1,173 @@
1
+ import { c as Dialect, d as Dialects, aH as NullOrdering, E as Expression, bo as TypeAnnotator, $ as DataTypeExprKind, a0 as NormalizationStrategy, m as Tokenizer, _ as TokenPair, l as TokenType, i as Parser, G as Generator, aj as PropertiesLocation, aL as ExtractExpr, ec as JsonFormatExpr, aF as Md5Expr, ed as StrToUnixExpr, aq as BracketExpr, dw as StructExpr, cM as IntervalExpr, dW as TransactionExpr, b8 as CreateExpr, ee as DeleteExpr, dy as JsonExtractExpr, dV as GroupConcatExpr, co as ApproxQuantileExpr, bd as UnixToTimeExpr, am as TimeToStrExpr, ef as DateAddOrSub, c$ as LateralExpr, aS as FuncExpr, eg as InitcapExpr, eh as SortArrayExpr, aT as QuantileExpr, dO as SchemaExpr, b0 as StrToDateExpr, aC as StrToTimeExpr, e5 as TsOrDsToDateExpr, ei as TsOrDsAddExpr, ej as TsOrDsDiffExpr } from '../tokens-VcMD09XM.cjs';
2
+
3
+ /**
4
+ * Presto doesn't have a native INITCAP. We simulate it using REGEXP_REPLACE with a lambda.
5
+ * It transforms 'hello world' into 'Hello World'.
6
+ */
7
+ declare function initcapSql(this: Generator, expression: InitcapExpr): string;
8
+ /**
9
+ * Presto uses ARRAY_SORT. If descending is requested, we provide a custom comparator lambda.
10
+ */
11
+ declare function noSortArray(this: Generator, expression: SortArrayExpr): string;
12
+ /**
13
+ * Handles schema generation, with special logic for PARTITIONED BY properties
14
+ * where column names must be rendered as string literals within an array.
15
+ */
16
+ declare function schemaSql(this: Generator, expression: SchemaExpr): string;
17
+ /**
18
+ * Presto lacks exact quantiles, so we pivot to the approximate version.
19
+ */
20
+ declare function quantileSql(this: Generator, expression: QuantileExpr): string;
21
+ /**
22
+ * Maps StrToDate/Time to Presto's DATE_PARSE function.
23
+ */
24
+ declare function strToTimeSql(this: Generator, expression: StrToDateExpr | StrToTimeExpr | TsOrDsToDateExpr): string;
25
+ /**
26
+ * Handles converting a Timestamp or DateString to a Date.
27
+ * If a custom format is provided, it uses DATE_PARSE; otherwise, it performs a nested cast.
28
+ */
29
+ declare function tsOrDsToDateSql(this: Generator, expression: TsOrDsToDateExpr): string;
30
+ declare function tsOrDsAddSql(this: Generator, expression: TsOrDsAddExpr): string;
31
+ declare function tsOrDsDiffSql(this: Generator, expression: TsOrDsDiffExpr): string;
32
+ /**
33
+ * Builder for approximate percentiles which maps to ApproxQuantile AST nodes.
34
+ */
35
+ declare function buildApproxPercentile(args: Expression[]): ApproxQuantileExpr;
36
+ /**
37
+ * Builder for FROM_UNIXTIME, supporting timezone and offset arguments.
38
+ */
39
+ declare function buildFromUnixtime(args: Expression[]): UnixToTimeExpr;
40
+ /**
41
+ * In Trino, FIRST/LAST are navigation functions within MATCH_RECOGNIZE.
42
+ * Everywhere else, they are treated as ARBITRARY.
43
+ */
44
+ declare function firstLastSql(this: Generator, expression: FuncExpr): string;
45
+ /**
46
+ * Handles UNIX timestamp conversion, potentially scaling for milliseconds/microseconds.
47
+ */
48
+ declare function unixToTimeSql(this: Generator, expression: UnixToTimeExpr): string;
49
+ /**
50
+ * Presto's TO_CHAR implementation actually follows Teradata's format conventions.
51
+ */
52
+ declare function buildToChar(args: Expression[]): TimeToStrExpr;
53
+ /**
54
+ * Higher-order function to create SQL for date addition or subtraction.
55
+ */
56
+ declare function dateDeltaSql(name: string, options?: {
57
+ negateInterval?: boolean;
58
+ }): (this: Generator, expression: DateAddOrSub) => string;
59
+ /**
60
+ * Converts Spark/Hive style EXPLODE into Presto UNNEST, with special handling for
61
+ * Arrays of Structs which Presto flattens into multiple columns.
62
+ */
63
+ declare function explodeToUnnestSqlPresto(this: Generator, expression: LateralExpr): string;
64
+ /**
65
+ * Fixes column qualifications in a SELECT scope after an EXPLODE -> UNNEST transformation.
66
+ * Useful when transpiling from Spark where fields might be qualified with the struct name.
67
+ */
68
+ declare function amendExplodedColumnTable(expression: Expression): Expression;
69
+ declare class PrestoTokenizer extends Tokenizer {
70
+ static get HEX_STRINGS(): TokenPair[];
71
+ static get UNICODE_STRINGS(): TokenPair[];
72
+ static NESTED_COMMENTS: boolean;
73
+ static get ORIGINAL_KEYWORDS(): Record<string, TokenType>;
74
+ }
75
+ declare class PrestoParser extends Parser {
76
+ static get ID_VAR_TOKENS(): Set<TokenType>;
77
+ static VALUES_FOLLOWED_BY_PAREN: boolean;
78
+ static ZONE_AWARE_TIMESTAMP_CONSTRUCTOR: boolean;
79
+ static get FUNCTIONS(): Record<string, (args: Expression[], options: {
80
+ dialect: Dialect;
81
+ }) => Expression>;
82
+ static get FUNCTION_PARSERS(): Partial<Record<string, (this: Parser) => Expression | undefined>>;
83
+ static get TABLE_ALIAS_TOKENS(): Set<TokenType>;
84
+ }
85
+ declare class PrestoGenerator extends Generator {
86
+ static get AFTER_HAVING_MODIFIER_TRANSFORMS(): Map<string, (this: Generator, e: Expression) => string>;
87
+ static SUPPORTS_DECODE_CASE: boolean;
88
+ static readonly SELECT_KINDS: string[];
89
+ static INTERVAL_ALLOWS_PLURAL_FORM: boolean;
90
+ static JOIN_HINTS: boolean;
91
+ static TABLE_HINTS: boolean;
92
+ static QUERY_HINTS: boolean;
93
+ static IS_BOOL_ALLOWED: boolean;
94
+ static TZ_TO_WITH_TIME_ZONE: boolean;
95
+ static NVL2_SUPPORTED: boolean;
96
+ static get STRUCT_DELIMITER(): [string, string];
97
+ static LIMIT_ONLY_LITERALS: boolean;
98
+ static SUPPORTS_SINGLE_ARG_CONCAT: boolean;
99
+ static LIKE_PROPERTY_INSIDE_SCHEMA: boolean;
100
+ static MULTI_ARG_DISTINCT: boolean;
101
+ static SUPPORTS_TO_NUMBER: boolean;
102
+ static HEX_FUNC: string;
103
+ static PARSE_JSON_NAME: string;
104
+ static PAD_FILL_PATTERN_IS_REQUIRED: boolean;
105
+ static EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE: boolean;
106
+ static SUPPORTS_MEDIAN: boolean;
107
+ static ARRAY_SIZE_NAME: string;
108
+ static get PROPERTIES_LOCATION(): Map<typeof Expression, PropertiesLocation>;
109
+ static get TYPE_MAPPING(): Map<string, string>;
110
+ static get ORIGINAL_TRANSFORMS(): Map<typeof Expression, (this: Generator, e: any) => string>;
111
+ static get RESERVED_KEYWORDS(): Set<string>;
112
+ /**
113
+ * Handles Presto's specific EXTRACT logic for high-precision EPOCHs.
114
+ * Converts EPOCH_MILLISECOND, etc., into Unix time math.
115
+ */
116
+ extractSql(expression: ExtractExpr): string;
117
+ /**
118
+ * Presto requires the input to JSON_FORMAT to be of type JSON.
119
+ */
120
+ jsonFormatSql(expression: JsonFormatExpr): string;
121
+ /**
122
+ * Presto's MD5 returns VARBINARY, so it needs to be hexed and lowercased
123
+ * for standard string representation.
124
+ */
125
+ md5Sql(expression: Md5Expr): string;
126
+ /**
127
+ * Converts a string to a Unix timestamp.
128
+ * Uses a COALESCE(TRY(DATE_PARSE), PARSE_DATETIME) pattern to handle
129
+ * standard formats and those containing timezones (Hive style).
130
+ */
131
+ strToUnixSql(expression: StrToUnixExpr): string;
132
+ bracketSql(expression: BracketExpr): string;
133
+ /**
134
+ * Presto uses ROW(...) for structs. If types are known, it casts the row
135
+ * to a specific ROW schema to maintain field naming.
136
+ */
137
+ structSql(expression: StructExpr): string;
138
+ intervalSql(expression: IntervalExpr): string;
139
+ transactionSql(expression: TransactionExpr): string;
140
+ createSql(expression: CreateExpr): string;
141
+ /**
142
+ * Presto DELETE is restrictive (no aliases, single table).
143
+ */
144
+ deleteSql(expression: DeleteExpr): string;
145
+ jsonExtractSql(expression: JsonExtractExpr): string;
146
+ groupConcatSql(expression: GroupConcatExpr): string;
147
+ }
148
+ declare class Presto extends Dialect {
149
+ static DIALECT_NAME: Dialects;
150
+ static UNNEST_REQUIRES_CROSS_JOIN: boolean;
151
+ static INDEX_OFFSET: number;
152
+ static get NULL_ORDERING(): NullOrdering;
153
+ static get EXPRESSION_METADATA(): Map<typeof Expression, {
154
+ annotator?: (annotator: TypeAnnotator, expression: any) => void;
155
+ returns?: DataTypeExprKind | string;
156
+ }>;
157
+ static get TIME_FORMAT(): string;
158
+ static STRICT_STRING_CONCAT: boolean;
159
+ static SUPPORTS_SEMI_ANTI_JOIN: boolean;
160
+ static TYPED_DIVISION: boolean;
161
+ static TABLESAMPLE_SIZE_IS_PERCENT: boolean;
162
+ static LOG_BASE_FIRST: boolean | undefined;
163
+ static SUPPORTS_VALUES_DEFAULT: boolean;
164
+ static LEAST_GREATEST_IGNORES_NULLS: boolean;
165
+ static get TIME_MAPPING(): Record<string, string>;
166
+ static get NORMALIZATION_STRATEGY(): NormalizationStrategy;
167
+ static get SUPPORTED_SETTINGS(): Set<string>;
168
+ static Tokenizer: typeof PrestoTokenizer;
169
+ static Parser: typeof PrestoParser;
170
+ static Generator: typeof PrestoGenerator;
171
+ }
172
+
173
+ export { Presto, amendExplodedColumnTable, buildApproxPercentile, buildFromUnixtime, buildToChar, dateDeltaSql, explodeToUnnestSqlPresto, firstLastSql, initcapSql, noSortArray, quantileSql, schemaSql, strToTimeSql, tsOrDsAddSql, tsOrDsDiffSql, tsOrDsToDateSql, unixToTimeSql };
@@ -0,0 +1,173 @@
1
+ import { c as Dialect, d as Dialects, aH as NullOrdering, E as Expression, bo as TypeAnnotator, $ as DataTypeExprKind, a0 as NormalizationStrategy, m as Tokenizer, _ as TokenPair, l as TokenType, i as Parser, G as Generator, aj as PropertiesLocation, aL as ExtractExpr, ec as JsonFormatExpr, aF as Md5Expr, ed as StrToUnixExpr, aq as BracketExpr, dw as StructExpr, cM as IntervalExpr, dW as TransactionExpr, b8 as CreateExpr, ee as DeleteExpr, dy as JsonExtractExpr, dV as GroupConcatExpr, co as ApproxQuantileExpr, bd as UnixToTimeExpr, am as TimeToStrExpr, ef as DateAddOrSub, c$ as LateralExpr, aS as FuncExpr, eg as InitcapExpr, eh as SortArrayExpr, aT as QuantileExpr, dO as SchemaExpr, b0 as StrToDateExpr, aC as StrToTimeExpr, e5 as TsOrDsToDateExpr, ei as TsOrDsAddExpr, ej as TsOrDsDiffExpr } from '../tokens-VcMD09XM.js';
2
+
3
+ /**
4
+ * Presto doesn't have a native INITCAP. We simulate it using REGEXP_REPLACE with a lambda.
5
+ * It transforms 'hello world' into 'Hello World'.
6
+ */
7
+ declare function initcapSql(this: Generator, expression: InitcapExpr): string;
8
+ /**
9
+ * Presto uses ARRAY_SORT. If descending is requested, we provide a custom comparator lambda.
10
+ */
11
+ declare function noSortArray(this: Generator, expression: SortArrayExpr): string;
12
+ /**
13
+ * Handles schema generation, with special logic for PARTITIONED BY properties
14
+ * where column names must be rendered as string literals within an array.
15
+ */
16
+ declare function schemaSql(this: Generator, expression: SchemaExpr): string;
17
+ /**
18
+ * Presto lacks exact quantiles, so we pivot to the approximate version.
19
+ */
20
+ declare function quantileSql(this: Generator, expression: QuantileExpr): string;
21
+ /**
22
+ * Maps StrToDate/Time to Presto's DATE_PARSE function.
23
+ */
24
+ declare function strToTimeSql(this: Generator, expression: StrToDateExpr | StrToTimeExpr | TsOrDsToDateExpr): string;
25
+ /**
26
+ * Handles converting a Timestamp or DateString to a Date.
27
+ * If a custom format is provided, it uses DATE_PARSE; otherwise, it performs a nested cast.
28
+ */
29
+ declare function tsOrDsToDateSql(this: Generator, expression: TsOrDsToDateExpr): string;
30
+ declare function tsOrDsAddSql(this: Generator, expression: TsOrDsAddExpr): string;
31
+ declare function tsOrDsDiffSql(this: Generator, expression: TsOrDsDiffExpr): string;
32
+ /**
33
+ * Builder for approximate percentiles which maps to ApproxQuantile AST nodes.
34
+ */
35
+ declare function buildApproxPercentile(args: Expression[]): ApproxQuantileExpr;
36
+ /**
37
+ * Builder for FROM_UNIXTIME, supporting timezone and offset arguments.
38
+ */
39
+ declare function buildFromUnixtime(args: Expression[]): UnixToTimeExpr;
40
+ /**
41
+ * In Trino, FIRST/LAST are navigation functions within MATCH_RECOGNIZE.
42
+ * Everywhere else, they are treated as ARBITRARY.
43
+ */
44
+ declare function firstLastSql(this: Generator, expression: FuncExpr): string;
45
+ /**
46
+ * Handles UNIX timestamp conversion, potentially scaling for milliseconds/microseconds.
47
+ */
48
+ declare function unixToTimeSql(this: Generator, expression: UnixToTimeExpr): string;
49
+ /**
50
+ * Presto's TO_CHAR implementation actually follows Teradata's format conventions.
51
+ */
52
+ declare function buildToChar(args: Expression[]): TimeToStrExpr;
53
+ /**
54
+ * Higher-order function to create SQL for date addition or subtraction.
55
+ */
56
+ declare function dateDeltaSql(name: string, options?: {
57
+ negateInterval?: boolean;
58
+ }): (this: Generator, expression: DateAddOrSub) => string;
59
+ /**
60
+ * Converts Spark/Hive style EXPLODE into Presto UNNEST, with special handling for
61
+ * Arrays of Structs which Presto flattens into multiple columns.
62
+ */
63
+ declare function explodeToUnnestSqlPresto(this: Generator, expression: LateralExpr): string;
64
+ /**
65
+ * Fixes column qualifications in a SELECT scope after an EXPLODE -> UNNEST transformation.
66
+ * Useful when transpiling from Spark where fields might be qualified with the struct name.
67
+ */
68
+ declare function amendExplodedColumnTable(expression: Expression): Expression;
69
+ declare class PrestoTokenizer extends Tokenizer {
70
+ static get HEX_STRINGS(): TokenPair[];
71
+ static get UNICODE_STRINGS(): TokenPair[];
72
+ static NESTED_COMMENTS: boolean;
73
+ static get ORIGINAL_KEYWORDS(): Record<string, TokenType>;
74
+ }
75
+ declare class PrestoParser extends Parser {
76
+ static get ID_VAR_TOKENS(): Set<TokenType>;
77
+ static VALUES_FOLLOWED_BY_PAREN: boolean;
78
+ static ZONE_AWARE_TIMESTAMP_CONSTRUCTOR: boolean;
79
+ static get FUNCTIONS(): Record<string, (args: Expression[], options: {
80
+ dialect: Dialect;
81
+ }) => Expression>;
82
+ static get FUNCTION_PARSERS(): Partial<Record<string, (this: Parser) => Expression | undefined>>;
83
+ static get TABLE_ALIAS_TOKENS(): Set<TokenType>;
84
+ }
85
+ declare class PrestoGenerator extends Generator {
86
+ static get AFTER_HAVING_MODIFIER_TRANSFORMS(): Map<string, (this: Generator, e: Expression) => string>;
87
+ static SUPPORTS_DECODE_CASE: boolean;
88
+ static readonly SELECT_KINDS: string[];
89
+ static INTERVAL_ALLOWS_PLURAL_FORM: boolean;
90
+ static JOIN_HINTS: boolean;
91
+ static TABLE_HINTS: boolean;
92
+ static QUERY_HINTS: boolean;
93
+ static IS_BOOL_ALLOWED: boolean;
94
+ static TZ_TO_WITH_TIME_ZONE: boolean;
95
+ static NVL2_SUPPORTED: boolean;
96
+ static get STRUCT_DELIMITER(): [string, string];
97
+ static LIMIT_ONLY_LITERALS: boolean;
98
+ static SUPPORTS_SINGLE_ARG_CONCAT: boolean;
99
+ static LIKE_PROPERTY_INSIDE_SCHEMA: boolean;
100
+ static MULTI_ARG_DISTINCT: boolean;
101
+ static SUPPORTS_TO_NUMBER: boolean;
102
+ static HEX_FUNC: string;
103
+ static PARSE_JSON_NAME: string;
104
+ static PAD_FILL_PATTERN_IS_REQUIRED: boolean;
105
+ static EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE: boolean;
106
+ static SUPPORTS_MEDIAN: boolean;
107
+ static ARRAY_SIZE_NAME: string;
108
+ static get PROPERTIES_LOCATION(): Map<typeof Expression, PropertiesLocation>;
109
+ static get TYPE_MAPPING(): Map<string, string>;
110
+ static get ORIGINAL_TRANSFORMS(): Map<typeof Expression, (this: Generator, e: any) => string>;
111
+ static get RESERVED_KEYWORDS(): Set<string>;
112
+ /**
113
+ * Handles Presto's specific EXTRACT logic for high-precision EPOCHs.
114
+ * Converts EPOCH_MILLISECOND, etc., into Unix time math.
115
+ */
116
+ extractSql(expression: ExtractExpr): string;
117
+ /**
118
+ * Presto requires the input to JSON_FORMAT to be of type JSON.
119
+ */
120
+ jsonFormatSql(expression: JsonFormatExpr): string;
121
+ /**
122
+ * Presto's MD5 returns VARBINARY, so it needs to be hexed and lowercased
123
+ * for standard string representation.
124
+ */
125
+ md5Sql(expression: Md5Expr): string;
126
+ /**
127
+ * Converts a string to a Unix timestamp.
128
+ * Uses a COALESCE(TRY(DATE_PARSE), PARSE_DATETIME) pattern to handle
129
+ * standard formats and those containing timezones (Hive style).
130
+ */
131
+ strToUnixSql(expression: StrToUnixExpr): string;
132
+ bracketSql(expression: BracketExpr): string;
133
+ /**
134
+ * Presto uses ROW(...) for structs. If types are known, it casts the row
135
+ * to a specific ROW schema to maintain field naming.
136
+ */
137
+ structSql(expression: StructExpr): string;
138
+ intervalSql(expression: IntervalExpr): string;
139
+ transactionSql(expression: TransactionExpr): string;
140
+ createSql(expression: CreateExpr): string;
141
+ /**
142
+ * Presto DELETE is restrictive (no aliases, single table).
143
+ */
144
+ deleteSql(expression: DeleteExpr): string;
145
+ jsonExtractSql(expression: JsonExtractExpr): string;
146
+ groupConcatSql(expression: GroupConcatExpr): string;
147
+ }
148
+ declare class Presto extends Dialect {
149
+ static DIALECT_NAME: Dialects;
150
+ static UNNEST_REQUIRES_CROSS_JOIN: boolean;
151
+ static INDEX_OFFSET: number;
152
+ static get NULL_ORDERING(): NullOrdering;
153
+ static get EXPRESSION_METADATA(): Map<typeof Expression, {
154
+ annotator?: (annotator: TypeAnnotator, expression: any) => void;
155
+ returns?: DataTypeExprKind | string;
156
+ }>;
157
+ static get TIME_FORMAT(): string;
158
+ static STRICT_STRING_CONCAT: boolean;
159
+ static SUPPORTS_SEMI_ANTI_JOIN: boolean;
160
+ static TYPED_DIVISION: boolean;
161
+ static TABLESAMPLE_SIZE_IS_PERCENT: boolean;
162
+ static LOG_BASE_FIRST: boolean | undefined;
163
+ static SUPPORTS_VALUES_DEFAULT: boolean;
164
+ static LEAST_GREATEST_IGNORES_NULLS: boolean;
165
+ static get TIME_MAPPING(): Record<string, string>;
166
+ static get NORMALIZATION_STRATEGY(): NormalizationStrategy;
167
+ static get SUPPORTED_SETTINGS(): Set<string>;
168
+ static Tokenizer: typeof PrestoTokenizer;
169
+ static Parser: typeof PrestoParser;
170
+ static Generator: typeof PrestoGenerator;
171
+ }
172
+
173
+ export { Presto, amendExplodedColumnTable, buildApproxPercentile, buildFromUnixtime, buildToChar, dateDeltaSql, explodeToUnnestSqlPresto, firstLastSql, initcapSql, noSortArray, quantileSql, schemaSql, strToTimeSql, tsOrDsAddSql, tsOrDsDiffSql, tsOrDsToDateSql, unixToTimeSql };
@@ -0,0 +1,2 @@
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q}from"../chunk-PXUASP5I.js";import"../chunk-Z5V6VOIN.js";import"../chunk-ZBFGQPJR.js";import"../chunk-O2J5RKBN.js";import"../chunk-KCNOE4DZ.js";export{q as Presto,p as amendExplodedColumnTable,i as buildApproxPercentile,j as buildFromUnixtime,m as buildToChar,n as dateDeltaSql,o as explodeToUnnestSqlPresto,k as firstLastSql,a as initcapSql,b as noSortArray,d as quantileSql,c as schemaSql,e as strToTimeSql,g as tsOrDsAddSql,h as tsOrDsDiffSql,f as tsOrDsToDateSql,l as unixToTimeSql};
2
+ //# sourceMappingURL=presto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk2Z3O2CFMcjs = require('../chunk-2Z3O2CFM.cjs');function D(d){return d?_chunk2Z3O2CFMcjs.jo.call(void 0, "*").from(d,{copy:!1}):void 0}var j,v,J,H,Y,l,E=class extends(Y=_chunk2Z3O2CFMcjs.Xq,H=[_chunk2Z3O2CFMcjs.r],J=[_chunk2Z3O2CFMcjs.r],v=[_chunk2Z3O2CFMcjs.r],j=[_chunk2Z3O2CFMcjs.r],Y){static get IDENTIFIERS(){return["`"]}static get QUOTES(){return["'",'"']}static get SINGLE_TOKENS(){return{..._chunk2Z3O2CFMcjs.Xq.SINGLE_TOKENS,"=":"alias","'":"quote",'"':"quote","`":"identifier","#":"comment"}}static get ORIGINAL_KEYWORDS(){return{..._chunk2Z3O2CFMcjs.Xq.KEYWORDS}}};l=_chunk2Z3O2CFMcjs.a.call(void 0, Y),_chunk2Z3O2CFMcjs.d.call(void 0, l,10,"IDENTIFIERS",H,E),_chunk2Z3O2CFMcjs.d.call(void 0, l,10,"QUOTES",J,E),_chunk2Z3O2CFMcjs.d.call(void 0, l,10,"SINGLE_TOKENS",v,E),_chunk2Z3O2CFMcjs.d.call(void 0, l,10,"ORIGINAL_KEYWORDS",j,E),_chunk2Z3O2CFMcjs.b.call(void 0, l,E),_chunk2Z3O2CFMcjs.c.call(void 0, l,3,E);var W,$,X,Z,Q,z,ee,se,c,o=class extends(se=_chunk2Z3O2CFMcjs.za,ee=[_chunk2Z3O2CFMcjs.r],z=[_chunk2Z3O2CFMcjs.r],Q=[_chunk2Z3O2CFMcjs.r],Z=[_chunk2Z3O2CFMcjs.r],X=[_chunk2Z3O2CFMcjs.r],$=[_chunk2Z3O2CFMcjs.r],W=[_chunk2Z3O2CFMcjs.r],se){static get ID_VAR_TOKENS(){return new Set([..._chunk2Z3O2CFMcjs.za.ID_VAR_TOKENS,"sessionUser","currentCatalog","straightJoin"])}static get NO_PAREN_FUNCTIONS(){let e={..._chunk2Z3O2CFMcjs.za.NO_PAREN_FUNCTIONS};return delete e.localtime,delete e.localtimestamp,e}static get CONJUNCTION(){return{..._chunk2Z3O2CFMcjs.za.CONJUNCTION,damp:_chunk2Z3O2CFMcjs.kn}}static get DISJUNCTION(){return{..._chunk2Z3O2CFMcjs.za.DISJUNCTION,dpipe:_chunk2Z3O2CFMcjs.ln}}static get TRANSFORM_PARSERS(){return{DERIVE:function(e){return this.parseSelection(e)},SELECT:function(e){return this.parseSelection(e,{append:!1})},TAKE:function(e){return this.parseTake(e)},FILTER:function(e){return e.where(this.parseDisjunction())},APPEND:function(e){return e.union(D(this.parseTable()),{distinct:!1,copy:!1})},REMOVE:function(e){return e.except(D(this.parseTable()),{distinct:!1,copy:!1})},INTERSECT:function(e){return e.intersect(D(this.parseTable()),{distinct:!1,copy:!1})},SORT:function(e){return this.parseOrderBy(e)},AGGREGATE:function(e){return this.parseSelection(e,{parseMethod:this.parseAggregate,append:!1})}}}static get FUNCTIONS(){return{..._chunk2Z3O2CFMcjs.za.FUNCTIONS,AVERAGE:e=>_chunk2Z3O2CFMcjs.Tm.fromArgList(e),SUM:e=>_chunk2Z3O2CFMcjs.no.call(void 0, "COALESCE",new (0, _chunk2Z3O2CFMcjs.On)({this:_chunk2Z3O2CFMcjs.ca.call(void 0, e,0),expression:0}))}}parseEquality(){let e=this.parseTokens(()=>this.parseComparison(),this._constructor.EQUALITY);if(!(e instanceof _chunk2Z3O2CFMcjs.Ce||e instanceof _chunk2Z3O2CFMcjs.Re))return e;if(e.args.expression instanceof _chunk2Z3O2CFMcjs.$d){let s=new (0, _chunk2Z3O2CFMcjs.Ke)({this:e.args.this,expression:e.args.expression});return e instanceof _chunk2Z3O2CFMcjs.Ce?s:new (0, _chunk2Z3O2CFMcjs.Ue)({this:s})}if(e.args.this instanceof _chunk2Z3O2CFMcjs.$d){let s=new (0, _chunk2Z3O2CFMcjs.Ke)({this:e.args.expression,expression:e.args.this});return e instanceof _chunk2Z3O2CFMcjs.Ce?s:new (0, _chunk2Z3O2CFMcjs.Ue)({this:s})}return e}parseStatement(){let e=this.parseExpression();return e||this.parseQuery()}parseQuery(){let e=this.parseFrom();if(!e)return;let s=_chunk2Z3O2CFMcjs.jo.call(void 0, "*").from(e,{copy:!1});for(;this.matchTexts(Object.keys(this._constructor.TRANSFORM_PARSERS));){let r=this._constructor.TRANSFORM_PARSERS[_nullishCoalesce(_optionalChain([this, 'access', _2 => _2.prev, 'optionalAccess', _3 => _3.text, 'access', _4 => _4.toUpperCase, 'call', _5 => _5()]), () => (""))].call(this,s);r&&(s=r)}return s}parseSelection(e,s={}){let{parseMethod:i=()=>this.parseExpression(),append:r=!0}=s,h;if(this.match("lBrace"))h=this.parseCsv(i),this.match("rBrace")||this.raiseError("Expecting }");else{let a=i();h=a?[a]:[]}let y={};_optionalChain([e, 'access', _6 => _6.args, 'access', _7 => _7.expressions, 'optionalAccess', _8 => _8.forEach, 'call', _9 => _9(a=>{y[a.aliasOrName]=a instanceof _chunk2Z3O2CFMcjs.hc?_nullishCoalesce(a.args.this, () => (a)):a})]);let ne=h.map(a=>a&&a.transform(x=>x instanceof _chunk2Z3O2CFMcjs.Ic&&y[x.name]?y[x.name].copy():x,{copy:!1}));return _chunk2Z3O2CFMcjs.jo.call(void 0, ...ne,{append:r,copy:!1})}static get TABLE_ALIAS_TOKENS(){return new Set([..._chunk2Z3O2CFMcjs.za.TABLE_ALIAS_TOKENS,"straightJoin"])}parseTake(e){let s=this.parseNumber();return s?e.limit(s):void 0}parseOrdered(e){let s=this.match("plus"),i=this.match("dash")||s&&!1,r=super.parseOrdered(e);return r&&i&&(r.setArgKey("desc",!0),r.setArgKey("nullsFirst",!1)),r}parseOrderBy(e){let s=this.match("lBrace"),i=this.parseCsv(()=>this.parseOrdered());return s&&!this.match("rBrace")&&this.raiseError("Expecting }"),e.orderBy(new (0, _chunk2Z3O2CFMcjs.Fb)({expressions:i.filter(Boolean)}),{copy:!1})}parseAggregate(){let e;this.next&&this.next.tokenType==="alias"&&(e=_optionalChain([this, 'access', _10 => _10.parseIdVar, 'call', _11 => _11({anyToken:!0}), 'optionalAccess', _12 => _12.name]),this.match("alias"));let s=_nullishCoalesce(_optionalChain([this, 'access', _13 => _13.curr, 'optionalAccess', _14 => _14.text, 'access', _15 => _15.toUpperCase, 'call', _16 => _16()]), () => ("")),i=this._constructor.FUNCTIONS[s],r;if(i){this.advance();let h=this.parseColumn();r=i(h?[h]:[],{dialect:this.dialect})}else{this.raiseError(`Unsupported aggregation function ${s}`);return}return e?new (0, _chunk2Z3O2CFMcjs.hc)({this:r,alias:e}):r}parseExpression(){if(this.next&&this.next.tokenType==="alias"){let e=_optionalChain([this, 'access', _17 => _17.parseIdVar, 'call', _18 => _18({anyToken:!0}), 'optionalAccess', _19 => _19.name]);this.match("alias");let s=this.parseAssignment();return s?new (0, _chunk2Z3O2CFMcjs.hc)({this:s,alias:e}):void 0}return this.parseAssignment()}parseTable(e={}){return this.parseTableParts()}parseFrom(e={}){let{joins:s=!1,skipFromToken:i=!1}=e;if(!(!i&&!this.match("from")))return this.expression(_chunk2Z3O2CFMcjs.pb,{comments:this.prevComments,this:this.parseTable({joins:s})})}};c=_chunk2Z3O2CFMcjs.a.call(void 0, se),_chunk2Z3O2CFMcjs.d.call(void 0, c,10,"ID_VAR_TOKENS",ee,o),_chunk2Z3O2CFMcjs.d.call(void 0, c,10,"NO_PAREN_FUNCTIONS",z,o),_chunk2Z3O2CFMcjs.d.call(void 0, c,10,"CONJUNCTION",Q,o),_chunk2Z3O2CFMcjs.d.call(void 0, c,10,"DISJUNCTION",Z,o),_chunk2Z3O2CFMcjs.d.call(void 0, c,10,"TRANSFORM_PARSERS",X,o),_chunk2Z3O2CFMcjs.d.call(void 0, c,10,"FUNCTIONS",$,o),_chunk2Z3O2CFMcjs.d.call(void 0, c,10,"TABLE_ALIAS_TOKENS",W,o),_chunk2Z3O2CFMcjs.b.call(void 0, c,o),_chunk2Z3O2CFMcjs.c.call(void 0, c,3,o);var re,te,F,p= exports.PRQLGenerator =class extends(te=_chunk2Z3O2CFMcjs.lp,re=[_chunk2Z3O2CFMcjs.r],te){static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let e=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(s=>e.delete(s)),e}};F=_chunk2Z3O2CFMcjs.a.call(void 0, te),_chunk2Z3O2CFMcjs.d.call(void 0, F,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",re,p),_chunk2Z3O2CFMcjs.b.call(void 0, F,p),_chunk2Z3O2CFMcjs.c.call(void 0, F,3,p),p.SUPPORTS_DECODE_CASE=!1,p.SELECT_KINDS=[],p.TRY_SUPPORTED=!1,p.SUPPORTS_UESCAPE=!1;var f=class extends _chunk2Z3O2CFMcjs.op{};f.DIALECT_NAME="prql",f.DPIPE_IS_STRING_CONCAT=!1,f.Tokenizer=E,f.Parser=o,f.Generator=p;_chunk2Z3O2CFMcjs.op.register("prql",f);exports.PRQL = f; exports.PRQLGenerator = p;
2
+ //# sourceMappingURL=prql.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/huydna/projects/sqlingo.js/dist/dialects/prql.cjs","../../src/dialects/prql.ts"],"names":["selectAll","table","select","_ORIGINAL_KEYWORDS_dec","_SINGLE_TOKENS_dec","_QUOTES_dec","_IDENTIFIERS_dec","_a","_init","PRQLTokenizer","Tokenizer","cache","__decoratorStart","__decorateElement","__decoratorMetadata","__runInitializers","_TABLE_ALIAS_TOKENS_dec","_FUNCTIONS_dec","_TRANSFORM_PARSERS_dec","_DISJUNCTION_dec","_CONJUNCTION_dec","_NO_PAREN_FUNCTIONS_dec","_ID_VAR_TOKENS_dec","PRQLParser","Parser","noParenFunctions","AndExpr","OrExpr","query","args","AvgExpr","func","SumExpr","seqGet","eq","EqExpr","NeqExpr","NullExpr","isExp","IsExpr","NotExpr","expression","from","result","options","parseMethod","append","selects","projections","AliasExpr","transformedSelects","s","ColumnExpr","num","asc","desc","term","lBr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A,CAAO,OAAO,CACzC,CAAC,CAAA,CAAG,CACF,IAAA,CAAM,CAAA,CACR,CAAC,CACH,CAEA,cAAA,CAAA,CAA0C,CACxC,IAAIE,CAAAA,CACA,IAAA,CAAK,IAAA,EAAQ,IAAA,CAAK,IAAA,CAAK,SAAA,GAAc,OAAA,EAAA,CACvCA,CAAAA,iBAAQ,IAAA,uBAAK,UAAA,qBAAW,CACtB,QAAA,CAAU,CAAA,CACZ,CAAC,CAAA,+BAAG,MAAA,CACJ,IAAA,CAAK,KAAA,CAAA,OAAqB,CAAA,CAAA,CAG5B,IAAMC,CAAAA,kCAAO,IAAA,uBAAK,IAAA,+BAAM,IAAA,uBAAK,WAAA,qBAAY,GAAA,SAAK,IAAA,CACxCC,CAAAA,CAAc,IAAA,CAAK,YAAA,CAAa,SAAA,CAAUD,CAAI,CAAA,CAChD9B,CAAAA,CAEJ,EAAA,CAAI+B,CAAAA,CAAa,CACf,IAAA,CAAK,OAAA,CAAQ,CAAA,CACb,IAAMjC,CAAAA,CAAO,IAAA,CAAK,WAAA,CAAY,CAAA,CAC9BE,CAAAA,CAAO+B,CAAAA,CAAYjC,CAAAA,CACf,CACAA,CACF,CAAA,CACE,CACF,CAAA,CAAG,CACH,OAAA,CAAS,IAAA,CAAK,OAChB,CAAC,CACH,CAAA,IAAO,CACL,IAAA,CAAK,UAAA,CAAW,CAAA,iCAAA,EAAoCgC,CAAI,CAAA,CAAA","file":"/home/huydna/projects/sqlingo.js/dist/dialects/prql.cjs","sourcesContent":[null,"import {\n cache,\n} from '../port_internals';\nimport type {\n Expression, OrderedExpr, QueryExpr, SelectExpr,\n} from '../expressions';\nimport {\n AliasExpr,\n AndExpr, AvgExpr, ColumnExpr, EqExpr, FromExpr, func, IsExpr, NeqExpr, NotExpr, NullExpr, OrderExpr, OrExpr, select, SumExpr,\n} from '../expressions';\nimport {\n seqGet,\n} from '../helper';\nimport {\n Parser,\n} from '../parser';\nimport {\n Tokenizer, TokenType,\n} from '../tokens';\nimport {\n Generator,\n} from '../generator';\nimport {\n Dialect, Dialects,\n} from './dialect';\n\nfunction selectAll (table: Expression | undefined): SelectExpr | undefined {\n return table\n ? select('*').from(table, {\n copy: false,\n })\n : undefined;\n}\n\nclass PRQLTokenizer extends Tokenizer {\n @cache\n static get IDENTIFIERS () {\n return [\n '`',\n ];\n }\n\n @cache\n static get QUOTES () {\n return [\n '\\'',\n '\"',\n ];\n }\n\n @cache\n static get SINGLE_TOKENS () {\n return {\n ...Tokenizer.SINGLE_TOKENS,\n '=': TokenType.ALIAS,\n '\\'': TokenType.QUOTE,\n '\"': TokenType.QUOTE,\n '`': TokenType.IDENTIFIER,\n '#': TokenType.COMMENT,\n };\n }\n\n @cache\n static get ORIGINAL_KEYWORDS () {\n return {\n ...Tokenizer.KEYWORDS,\n };\n }\n}\n\nclass PRQLParser extends Parser {\n @cache\n static get ID_VAR_TOKENS (): Set<TokenType> {\n return new Set([\n ...Parser.ID_VAR_TOKENS,\n TokenType.SESSION_USER,\n TokenType.CURRENT_CATALOG,\n TokenType.STRAIGHT_JOIN,\n ]);\n }\n\n // port from _Dialect metaclass logic\n @cache\n static get NO_PAREN_FUNCTIONS () {\n const noParenFunctions = {\n ...Parser.NO_PAREN_FUNCTIONS,\n };\n delete noParenFunctions[TokenType.LOCALTIME];\n delete noParenFunctions[TokenType.LOCALTIMESTAMP];\n return noParenFunctions;\n }\n\n @cache\n static get CONJUNCTION (): Partial<Record<TokenType, typeof Expression>> {\n return {\n ...Parser.CONJUNCTION,\n [TokenType.DAMP]: AndExpr,\n };\n }\n\n @cache\n static get DISJUNCTION (): Partial<Record<TokenType, typeof Expression>> {\n return {\n ...Parser.DISJUNCTION,\n [TokenType.DPIPE]: OrExpr,\n };\n }\n\n @cache\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static get TRANSFORM_PARSERS (): Record<string, (this: Parser, query: any) => QueryExpr | undefined> {\n return {\n DERIVE: function (this: Parser, query) {\n return (this as PRQLParser).parseSelection(query);\n },\n SELECT: function (this: Parser, query) {\n return (this as PRQLParser).parseSelection(query, {\n append: false,\n });\n },\n TAKE: function (this: Parser, query) {\n return (this as PRQLParser).parseTake(query);\n },\n FILTER: function (this: Parser, query) {\n return query.where((this as PRQLParser).parseDisjunction());\n },\n APPEND: function (this: Parser, query) {\n return query.union(selectAll((this as PRQLParser).parseTable()), {\n distinct: false,\n copy: false,\n });\n },\n REMOVE: function (this: Parser, query) {\n return query.except(selectAll((this as PRQLParser).parseTable()), {\n distinct: false,\n copy: false,\n });\n },\n INTERSECT: function (this: Parser, query) {\n return query.intersect(selectAll((this as PRQLParser).parseTable()), {\n distinct: false,\n copy: false,\n });\n },\n SORT: function (this: Parser, query) {\n return (this as PRQLParser).parseOrderBy(query);\n },\n AGGREGATE: function (this: Parser, query) {\n return (this as PRQLParser).parseSelection(query, {\n parseMethod: (this as PRQLParser).parseAggregate,\n append: false,\n });\n },\n };\n }\n\n @cache\n static get FUNCTIONS (): Record<string, (args: Expression[], options: {dialect: Dialect}) => Expression> {\n return {\n ...Parser.FUNCTIONS,\n AVERAGE: (args: unknown[]) => AvgExpr.fromArgList(args),\n SUM: (args: Expression[]) => func('COALESCE', new SumExpr({\n this: seqGet(args, 0),\n expression: 0,\n })),\n };\n }\n\n parseEquality (): Expression | undefined {\n const eq = this.parseTokens(() => this.parseComparison(), (this._constructor as typeof PRQLParser).EQUALITY);\n if (!(eq instanceof EqExpr || eq instanceof NeqExpr)) {\n return eq;\n }\n\n if (eq.args.expression instanceof NullExpr) {\n const isExp = new IsExpr({\n this: eq.args.this,\n expression: eq.args.expression,\n });\n return eq instanceof EqExpr\n ? isExp\n : new NotExpr({\n this: isExp,\n });\n }\n if (eq.args.this instanceof NullExpr) {\n const isExp = new IsExpr({\n this: eq.args.expression,\n expression: eq.args.this,\n });\n return eq instanceof EqExpr\n ? isExp\n : new NotExpr({\n this: isExp,\n });\n }\n return eq;\n }\n\n parseStatement (): Expression | undefined {\n const expression = this.parseExpression();\n return expression ? expression : this.parseQuery();\n }\n\n parseQuery (): QueryExpr | undefined {\n const from = this.parseFrom();\n\n if (!from) {\n return undefined;\n }\n\n let query: QueryExpr = select('*').from(from, {\n copy: false,\n });\n\n while (this.matchTexts(Object.keys((this._constructor as typeof PRQLParser).TRANSFORM_PARSERS))) {\n const transform = (this._constructor as typeof PRQLParser).TRANSFORM_PARSERS[this.prev?.text.toUpperCase() ?? ''];\n const result = transform.call(this, query);\n if (result) {\n query = result;\n }\n }\n\n return query;\n }\n\n parseSelection (\n query: QueryExpr,\n options: {\n parseMethod?: () => Expression | undefined;\n append?: boolean;\n } = {},\n ): QueryExpr {\n const {\n parseMethod = () => this.parseExpression(), append = true,\n } = options;\n let selects: (Expression | undefined)[];\n\n if (this.match(TokenType.L_BRACE)) {\n selects = this.parseCsv(parseMethod);\n\n if (!this.match(TokenType.R_BRACE)) {\n this.raiseError('Expecting }');\n }\n } else {\n const expression = parseMethod();\n selects = expression\n ? [\n expression,\n ]\n : [\n ];\n }\n\n const projections: Record<string, Expression> = {};\n (query as SelectExpr).args.expressions?.forEach((select) => {\n projections[select.aliasOrName] = select instanceof AliasExpr ? (select.args.this ?? select) : select;\n });\n\n const transformedSelects = selects.map((select) => {\n if (!select) return select;\n return select.transform((s) => {\n if (s instanceof ColumnExpr && projections[s.name]) {\n return projections[s.name].copy();\n }\n return s;\n }, {\n copy: false,\n });\n }) as Expression[];\n\n return select(...transformedSelects, {\n append,\n copy: false,\n });\n }\n\n // port from _Dialect metaclass logic\n @cache\n static get TABLE_ALIAS_TOKENS (): Set<TokenType> {\n return new Set([\n ...Parser.TABLE_ALIAS_TOKENS,\n TokenType.STRAIGHT_JOIN,\n ]);\n }\n\n parseTake (query: QueryExpr): QueryExpr | undefined {\n const num = this.parseNumber();\n return num ? query.limit(num) : undefined;\n }\n\n parseOrdered (parseMethod?: () => Expression | undefined): OrderedExpr | undefined {\n const asc = this.match(TokenType.PLUS);\n const desc = this.match(TokenType.DASH) || (asc && false);\n const term = super.parseOrdered(parseMethod);\n if (term && desc) {\n term.setArgKey('desc', true);\n term.setArgKey('nullsFirst', false);\n }\n return term;\n }\n\n parseOrderBy (query: SelectExpr): QueryExpr {\n const lBrace = this.match(TokenType.L_BRACE);\n const expressions = this.parseCsv(() => this.parseOrdered());\n if (lBrace && !this.match(TokenType.R_BRACE)) {\n this.raiseError('Expecting }');\n }\n return query.orderBy(new OrderExpr({\n expressions: expressions.filter(Boolean),\n }), {\n copy: false,\n });\n }\n\n parseAggregate (): Expression | undefined {\n let alias: string | undefined = undefined;\n if (this.next && this.next.tokenType === TokenType.ALIAS) {\n alias = this.parseIdVar({\n anyToken: true,\n })?.name;\n this.match(TokenType.ALIAS);\n }\n\n const name = this.curr?.text.toUpperCase() ?? '';\n const funcBuilder = this._constructor.FUNCTIONS[name];\n let func: Expression;\n\n if (funcBuilder) {\n this.advance();\n const args = this.parseColumn();\n func = funcBuilder(args\n ? [\n args,\n ]\n : [\n ], {\n dialect: this.dialect,\n });\n } else {\n this.raiseError(`Unsupported aggregation function ${name}`);\n return undefined;\n }\n\n if (alias) {\n return new AliasExpr({\n this: func,\n alias,\n });\n }\n return func;\n }\n\n parseExpression (): Expression | undefined {\n if (this.next && this.next.tokenType === TokenType.ALIAS) {\n const alias = this.parseIdVar({\n anyToken: true,\n })?.name;\n this.match(TokenType.ALIAS);\n const parsedExpr = this.parseAssignment();\n if (!parsedExpr) return undefined;\n return new AliasExpr({\n this: parsedExpr,\n alias,\n });\n }\n return this.parseAssignment();\n }\n\n parseTable (_options: {\n schema?: boolean;\n joins?: boolean;\n aliasTokens?: Set<TokenType>;\n parseBracket?: boolean;\n isDbReference?: boolean;\n parsePartition?: boolean;\n consumePipe?: boolean;\n } = {}): Expression | undefined {\n return this.parseTableParts();\n }\n\n parseFrom (options: {\n joins?: boolean;\n skipFromToken?: boolean;\n } = {}): FromExpr | undefined {\n const {\n joins = false, skipFromToken = false,\n } = options;\n if (!skipFromToken && !this.match(TokenType.FROM)) {\n return undefined;\n }\n\n return this.expression(FromExpr, {\n comments: this.prevComments,\n this: this.parseTable({\n joins,\n }),\n });\n }\n};\n\nexport class PRQLGenerator extends Generator {\n // port from _Dialect metaclass logic\n @cache\n static get AFTER_HAVING_MODIFIER_TRANSFORMS () {\n const modifiers = new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);\n [\n 'cluster',\n 'distribute',\n 'sort',\n ].forEach((m) => modifiers.delete(m));\n return modifiers;\n }\n\n // port from _Dialect metaclass logic\n static SUPPORTS_DECODE_CASE = false;\n // port from _Dialect metaclass logic\n static readonly SELECT_KINDS: string[] = [\n ];\n // port from _Dialect metaclass logic\n static TRY_SUPPORTED = false;\n // port from _Dialect metaclass logic\n static SUPPORTS_UESCAPE = false;\n}\n\nexport class PRQL extends Dialect {\n static DIALECT_NAME = Dialects.PRQL;\n static DPIPE_IS_STRING_CONCAT = false;\n\n static Tokenizer = PRQLTokenizer;\n\n static Parser = PRQLParser;\n\n static Generator = PRQLGenerator;\n}\n\nDialect.register(Dialects.PRQL, PRQL);\n"]}