sqlingo 0.12.3 → 0.12.4

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 (237) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{chunk-YOTDZ46J.js → chunk-3FYGRTYM.js} +2 -2
  3. package/dist/{chunk-P6YCSUUX.js → chunk-3L4IL5ZG.js} +2 -2
  4. package/dist/chunk-55NVAUC3.cjs +2 -0
  5. package/dist/{chunk-OE3QVFQR.cjs.map → chunk-55NVAUC3.cjs.map} +1 -1
  6. package/dist/chunk-5DOLMG5W.cjs +4 -0
  7. package/dist/{chunk-ARZB6LLO.cjs.map → chunk-5DOLMG5W.cjs.map} +1 -1
  8. package/dist/{chunk-GEM5ED3Q.js → chunk-5NIOI7IT.js} +2 -2
  9. package/dist/{chunk-NNPDC7K7.js → chunk-5TO2OPOM.js} +3 -3
  10. package/dist/{chunk-NNPDC7K7.js.map → chunk-5TO2OPOM.js.map} +1 -1
  11. package/dist/{chunk-FZMXAQA2.js → chunk-6KLCCQGX.js} +2 -2
  12. package/dist/{chunk-SR5T64DP.js → chunk-7D3RXRLA.js} +2 -2
  13. package/dist/{chunk-MBDFVUXG.js → chunk-7P5S7LVR.js} +2 -2
  14. package/dist/{chunk-ZZAKTBZ2.js → chunk-CKAH73SV.js} +2 -2
  15. package/dist/{chunk-C72OQ3YO.cjs → chunk-D5KSTAKN.cjs} +3 -3
  16. package/dist/chunk-D5KSTAKN.cjs.map +1 -0
  17. package/dist/chunk-DBWRBDNP.cjs +2 -0
  18. package/dist/{chunk-7SURY7NK.cjs.map → chunk-DBWRBDNP.cjs.map} +1 -1
  19. package/dist/chunk-DYRCRBW4.cjs +2 -0
  20. package/dist/{chunk-IBAFRN67.cjs.map → chunk-DYRCRBW4.cjs.map} +1 -1
  21. package/dist/chunk-ERBTCAP6.cjs +2 -0
  22. package/dist/{chunk-J73GN7VK.cjs.map → chunk-ERBTCAP6.cjs.map} +1 -1
  23. package/dist/{chunk-XV77F2MB.js → chunk-F3FPFYG6.js} +2 -2
  24. package/dist/chunk-FSGXA7Q2.cjs +2 -0
  25. package/dist/{chunk-O2VXK4BJ.cjs.map → chunk-FSGXA7Q2.cjs.map} +1 -1
  26. package/dist/chunk-G2RXM7F6.cjs +2 -0
  27. package/dist/{chunk-KKH43SVW.cjs.map → chunk-G2RXM7F6.cjs.map} +1 -1
  28. package/dist/chunk-HAN3ZQBX.cjs +2 -0
  29. package/dist/{chunk-2IDNLTQG.cjs.map → chunk-HAN3ZQBX.cjs.map} +1 -1
  30. package/dist/chunk-IUTLID33.cjs +2 -0
  31. package/dist/{chunk-F4H5GNAS.cjs.map → chunk-IUTLID33.cjs.map} +1 -1
  32. package/dist/chunk-JU23J75C.cjs +3 -0
  33. package/dist/{chunk-D62XDRDA.cjs.map → chunk-JU23J75C.cjs.map} +1 -1
  34. package/dist/{chunk-PIPS5SYM.js → chunk-K3RTO54N.js} +2 -2
  35. package/dist/{chunk-CELHDVUC.js → chunk-KI4YDHIS.js} +2 -2
  36. package/dist/{chunk-T3LZIXXV.js → chunk-LZYWZJB7.js} +2 -2
  37. package/dist/chunk-MWHDVWOK.cjs +2 -0
  38. package/dist/{chunk-HMVTAVD4.cjs.map → chunk-MWHDVWOK.cjs.map} +1 -1
  39. package/dist/chunk-NFGBKQVV.cjs +2 -0
  40. package/dist/{chunk-LD7YHVMH.cjs.map → chunk-NFGBKQVV.cjs.map} +1 -1
  41. package/dist/{chunk-ABH3VZG7.cjs → chunk-PQASBFLD.cjs} +2 -2
  42. package/dist/{chunk-ABH3VZG7.cjs.map → chunk-PQASBFLD.cjs.map} +1 -1
  43. package/dist/chunk-REACQUZR.cjs +2 -0
  44. package/dist/{chunk-YODZ2FBS.cjs.map → chunk-REACQUZR.cjs.map} +1 -1
  45. package/dist/chunk-SEC5YUNS.cjs +2 -0
  46. package/dist/{chunk-AOD6F6HV.cjs.map → chunk-SEC5YUNS.cjs.map} +1 -1
  47. package/dist/chunk-SSQRBTMM.cjs +2 -0
  48. package/dist/{chunk-5YRYCTSB.cjs.map → chunk-SSQRBTMM.cjs.map} +1 -1
  49. package/dist/{chunk-4UJWN7AG.js → chunk-TLKLTUJ3.js} +2 -2
  50. package/dist/{chunk-AZNXXBMF.js → chunk-UADXIAM3.js} +2 -2
  51. package/dist/chunk-V442VXAE.js +2 -0
  52. package/dist/chunk-V442VXAE.js.map +1 -0
  53. package/dist/chunk-X22HA2A6.cjs +2 -0
  54. package/dist/chunk-X22HA2A6.cjs.map +1 -0
  55. package/dist/{chunk-GXH2FNJU.js → chunk-XETIUHVU.js} +2 -2
  56. package/dist/chunk-YFLI34KL.cjs +2 -0
  57. package/dist/{chunk-UJEHXXRU.cjs.map → chunk-YFLI34KL.cjs.map} +1 -1
  58. package/dist/{chunk-PKVBRYCO.js → chunk-YP37LWGH.js} +2 -2
  59. package/dist/{chunk-YIVRRRRB.js → chunk-ZGS6MWL2.js} +2 -2
  60. package/dist/chunk-ZUODNLZM.js +2 -0
  61. package/dist/chunk-ZUODNLZM.js.map +1 -0
  62. package/dist/dialects/athena.cjs +1 -1
  63. package/dist/dialects/athena.d.cts +1 -1
  64. package/dist/dialects/athena.d.ts +1 -1
  65. package/dist/dialects/athena.js +1 -1
  66. package/dist/dialects/bigquery.cjs +1 -1
  67. package/dist/dialects/bigquery.d.cts +1 -1
  68. package/dist/dialects/bigquery.d.ts +1 -1
  69. package/dist/dialects/bigquery.js +1 -1
  70. package/dist/dialects/clickhouse.cjs +1 -1
  71. package/dist/dialects/clickhouse.d.cts +1 -1
  72. package/dist/dialects/clickhouse.d.ts +1 -1
  73. package/dist/dialects/clickhouse.js +1 -1
  74. package/dist/dialects/databricks.cjs +1 -1
  75. package/dist/dialects/databricks.d.cts +1 -1
  76. package/dist/dialects/databricks.d.ts +1 -1
  77. package/dist/dialects/databricks.js +1 -1
  78. package/dist/dialects/doris.cjs +1 -1
  79. package/dist/dialects/doris.d.cts +1 -1
  80. package/dist/dialects/doris.d.ts +1 -1
  81. package/dist/dialects/doris.js +1 -1
  82. package/dist/dialects/dremio.cjs +1 -1
  83. package/dist/dialects/dremio.d.cts +1 -1
  84. package/dist/dialects/dremio.d.ts +1 -1
  85. package/dist/dialects/dremio.js +1 -1
  86. package/dist/dialects/drill.cjs +1 -1
  87. package/dist/dialects/drill.d.cts +1 -1
  88. package/dist/dialects/drill.d.ts +1 -1
  89. package/dist/dialects/drill.js +1 -1
  90. package/dist/dialects/druid.cjs +1 -1
  91. package/dist/dialects/druid.d.cts +1 -1
  92. package/dist/dialects/druid.d.ts +1 -1
  93. package/dist/dialects/druid.js +1 -1
  94. package/dist/dialects/duckdb.cjs +13 -13
  95. package/dist/dialects/duckdb.d.cts +1 -1
  96. package/dist/dialects/duckdb.d.ts +1 -1
  97. package/dist/dialects/duckdb.js +1 -1
  98. package/dist/dialects/dune.cjs +1 -1
  99. package/dist/dialects/dune.d.cts +1 -1
  100. package/dist/dialects/dune.d.ts +1 -1
  101. package/dist/dialects/dune.js +1 -1
  102. package/dist/dialects/exasol.cjs +1 -1
  103. package/dist/dialects/exasol.d.cts +1 -1
  104. package/dist/dialects/exasol.d.ts +1 -1
  105. package/dist/dialects/exasol.js +1 -1
  106. package/dist/dialects/fabric.cjs +1 -1
  107. package/dist/dialects/fabric.d.cts +1 -1
  108. package/dist/dialects/fabric.d.ts +1 -1
  109. package/dist/dialects/fabric.js +1 -1
  110. package/dist/dialects/hive.cjs +1 -1
  111. package/dist/dialects/hive.d.cts +1 -1
  112. package/dist/dialects/hive.d.ts +1 -1
  113. package/dist/dialects/hive.js +1 -1
  114. package/dist/dialects/materialize.cjs +1 -1
  115. package/dist/dialects/materialize.d.cts +1 -1
  116. package/dist/dialects/materialize.d.ts +1 -1
  117. package/dist/dialects/materialize.js +1 -1
  118. package/dist/dialects/mysql.cjs +1 -1
  119. package/dist/dialects/mysql.d.cts +1 -1
  120. package/dist/dialects/mysql.d.ts +1 -1
  121. package/dist/dialects/mysql.js +1 -1
  122. package/dist/dialects/oracle.cjs +1 -1
  123. package/dist/dialects/oracle.d.cts +1 -1
  124. package/dist/dialects/oracle.d.ts +1 -1
  125. package/dist/dialects/oracle.js +1 -1
  126. package/dist/dialects/postgres.cjs +1 -1
  127. package/dist/dialects/postgres.d.cts +2 -1
  128. package/dist/dialects/postgres.d.ts +2 -1
  129. package/dist/dialects/postgres.js +1 -1
  130. package/dist/dialects/presto.cjs +1 -1
  131. package/dist/dialects/presto.d.cts +1 -1
  132. package/dist/dialects/presto.d.ts +1 -1
  133. package/dist/dialects/presto.js +1 -1
  134. package/dist/dialects/prql.cjs +1 -1
  135. package/dist/dialects/prql.d.cts +1 -1
  136. package/dist/dialects/prql.d.ts +1 -1
  137. package/dist/dialects/prql.js +1 -1
  138. package/dist/dialects/redshift.cjs +1 -1
  139. package/dist/dialects/redshift.d.cts +1 -1
  140. package/dist/dialects/redshift.d.ts +1 -1
  141. package/dist/dialects/redshift.js +1 -1
  142. package/dist/dialects/risingwave.cjs +1 -1
  143. package/dist/dialects/risingwave.d.cts +1 -1
  144. package/dist/dialects/risingwave.d.ts +1 -1
  145. package/dist/dialects/risingwave.js +1 -1
  146. package/dist/dialects/singlestore.cjs +1 -1
  147. package/dist/dialects/singlestore.d.cts +1 -1
  148. package/dist/dialects/singlestore.d.ts +1 -1
  149. package/dist/dialects/singlestore.js +1 -1
  150. package/dist/dialects/snowflake.cjs +1 -1
  151. package/dist/dialects/snowflake.d.cts +1 -1
  152. package/dist/dialects/snowflake.d.ts +1 -1
  153. package/dist/dialects/snowflake.js +1 -1
  154. package/dist/dialects/solr.cjs +1 -1
  155. package/dist/dialects/solr.d.cts +1 -1
  156. package/dist/dialects/solr.d.ts +1 -1
  157. package/dist/dialects/solr.js +1 -1
  158. package/dist/dialects/spark.cjs +1 -1
  159. package/dist/dialects/spark.d.cts +1 -1
  160. package/dist/dialects/spark.d.ts +1 -1
  161. package/dist/dialects/spark.js +1 -1
  162. package/dist/dialects/spark2.cjs +1 -1
  163. package/dist/dialects/spark2.d.cts +1 -1
  164. package/dist/dialects/spark2.d.ts +1 -1
  165. package/dist/dialects/spark2.js +1 -1
  166. package/dist/dialects/sqlite.cjs +1 -1
  167. package/dist/dialects/sqlite.d.cts +1 -1
  168. package/dist/dialects/sqlite.d.ts +1 -1
  169. package/dist/dialects/sqlite.js +1 -1
  170. package/dist/dialects/starrocks.cjs +1 -1
  171. package/dist/dialects/starrocks.d.cts +1 -1
  172. package/dist/dialects/starrocks.d.ts +1 -1
  173. package/dist/dialects/starrocks.js +1 -1
  174. package/dist/dialects/tableau.cjs +1 -1
  175. package/dist/dialects/tableau.d.cts +1 -1
  176. package/dist/dialects/tableau.d.ts +1 -1
  177. package/dist/dialects/tableau.js +1 -1
  178. package/dist/dialects/teradata.cjs +1 -1
  179. package/dist/dialects/teradata.d.cts +1 -1
  180. package/dist/dialects/teradata.d.ts +1 -1
  181. package/dist/dialects/teradata.js +1 -1
  182. package/dist/dialects/trino.cjs +1 -1
  183. package/dist/dialects/trino.d.cts +1 -1
  184. package/dist/dialects/trino.d.ts +1 -1
  185. package/dist/dialects/trino.js +1 -1
  186. package/dist/dialects/tsql.cjs +1 -1
  187. package/dist/dialects/tsql.d.cts +5 -1
  188. package/dist/dialects/tsql.d.ts +5 -1
  189. package/dist/dialects/tsql.js +1 -1
  190. package/dist/index.cjs +5 -5
  191. package/dist/index.cjs.map +1 -1
  192. package/dist/index.d.cts +2 -2
  193. package/dist/index.d.ts +2 -2
  194. package/dist/index.js +1 -1
  195. package/dist/index.js.map +1 -1
  196. package/dist/{tokens-DQmh7u9L.d.ts → tokens-DL_c9vq7.d.cts} +1 -1
  197. package/dist/{tokens-DQmh7u9L.d.cts → tokens-DL_c9vq7.d.ts} +1 -1
  198. package/package.json +1 -1
  199. package/dist/chunk-2IDNLTQG.cjs +0 -2
  200. package/dist/chunk-5YRYCTSB.cjs +0 -2
  201. package/dist/chunk-7SURY7NK.cjs +0 -2
  202. package/dist/chunk-AOD6F6HV.cjs +0 -2
  203. package/dist/chunk-ARZB6LLO.cjs +0 -4
  204. package/dist/chunk-C72OQ3YO.cjs.map +0 -1
  205. package/dist/chunk-D62XDRDA.cjs +0 -3
  206. package/dist/chunk-F4H5GNAS.cjs +0 -2
  207. package/dist/chunk-FHZLNMGS.js +0 -2
  208. package/dist/chunk-FHZLNMGS.js.map +0 -1
  209. package/dist/chunk-HMVTAVD4.cjs +0 -2
  210. package/dist/chunk-IBAFRN67.cjs +0 -2
  211. package/dist/chunk-J73GN7VK.cjs +0 -2
  212. package/dist/chunk-KKH43SVW.cjs +0 -2
  213. package/dist/chunk-LD7YHVMH.cjs +0 -2
  214. package/dist/chunk-O2VXK4BJ.cjs +0 -2
  215. package/dist/chunk-OE3QVFQR.cjs +0 -2
  216. package/dist/chunk-UJEHXXRU.cjs +0 -2
  217. package/dist/chunk-UXK7PGJ3.cjs +0 -2
  218. package/dist/chunk-UXK7PGJ3.cjs.map +0 -1
  219. package/dist/chunk-YODZ2FBS.cjs +0 -2
  220. package/dist/chunk-YQ22ZDIZ.js +0 -2
  221. package/dist/chunk-YQ22ZDIZ.js.map +0 -1
  222. /package/dist/{chunk-YOTDZ46J.js.map → chunk-3FYGRTYM.js.map} +0 -0
  223. /package/dist/{chunk-P6YCSUUX.js.map → chunk-3L4IL5ZG.js.map} +0 -0
  224. /package/dist/{chunk-GEM5ED3Q.js.map → chunk-5NIOI7IT.js.map} +0 -0
  225. /package/dist/{chunk-FZMXAQA2.js.map → chunk-6KLCCQGX.js.map} +0 -0
  226. /package/dist/{chunk-SR5T64DP.js.map → chunk-7D3RXRLA.js.map} +0 -0
  227. /package/dist/{chunk-MBDFVUXG.js.map → chunk-7P5S7LVR.js.map} +0 -0
  228. /package/dist/{chunk-ZZAKTBZ2.js.map → chunk-CKAH73SV.js.map} +0 -0
  229. /package/dist/{chunk-XV77F2MB.js.map → chunk-F3FPFYG6.js.map} +0 -0
  230. /package/dist/{chunk-PIPS5SYM.js.map → chunk-K3RTO54N.js.map} +0 -0
  231. /package/dist/{chunk-CELHDVUC.js.map → chunk-KI4YDHIS.js.map} +0 -0
  232. /package/dist/{chunk-T3LZIXXV.js.map → chunk-LZYWZJB7.js.map} +0 -0
  233. /package/dist/{chunk-4UJWN7AG.js.map → chunk-TLKLTUJ3.js.map} +0 -0
  234. /package/dist/{chunk-AZNXXBMF.js.map → chunk-UADXIAM3.js.map} +0 -0
  235. /package/dist/{chunk-GXH2FNJU.js.map → chunk-XETIUHVU.js.map} +0 -0
  236. /package/dist/{chunk-PKVBRYCO.js.map → chunk-YP37LWGH.js.map} +0 -0
  237. /package/dist/{chunk-YIVRRRRB.js.map → chunk-ZGS6MWL2.js.map} +0 -0
@@ -1,2 +1,2 @@
1
- import{a as Nr}from"./chunk-MBDFVUXG.js";import{$v as pr,Ac as C,Aj as Ae,Am as St,An as De,Av as rr,Aw as Ir,Bh as V,Bn as k,Bv as sr,Ci as Se,Ck as Tt,Cm as de,Cw as hr,Dh as K,Dr as Be,Er as Fe,Fr as Ge,Gr as we,Hj as Ie,Hr as ye,Jb as Ht,Jn as Ot,Jr as O,Jv as ir,Kf as te,Km as ut,Kn as Ue,Kq as Me,Kv as G,Md as Zt,Mr as gt,Nf as ee,Ns as Ve,Nv as W,On as Nt,Ph as Ee,Pr as Ye,Pw as Rr,Qv as h,Rm as xe,Sa as c,Si as ot,Tc as Xt,Tm as Ce,Tr as $,Tv as nr,Uk as Re,Um as me,Vm as H,Wv as ar,Ww as Bt,Xh as oe,Xm as lt,Xp as dt,Xv as Er,Yl as Ne,Ym as ct,Zj as he,Zm as Pe,Zv as or,_v as Tr,a as s,ac as st,ag as re,ar as xt,b,bt as Ke,c as q,cc as kt,ce as P,cg as se,d as B,dw as Sr,e as E,ee as jt,en as At,es as Dt,ge as zt,gn as It,hn as ht,hp as _e,ie as Qt,im as fe,js as Ut,jt as He,kd as it,kn as Rt,kr as be,kw as ur,lc as vt,ld as Jt,lg as at,lt as ke,mi as Te,ml as Oe,mp as Le,mt as ve,mv as ze,mw as bt,nc as $t,nr as Ct,nt as $e,nv as Qe,nw as X,oc as Wt,or as mt,os as _t,ox as Or,pb as I,pe as nt,pg as Et,ps as Lt,pv as tr,pw as qt,qh as ne,qi as pe,qs as Mt,qv as er,rr as Pt,rt as We,s as o,sj as ue,st as Xe,tg as F,tt as Je,wr as qe,wt as Ze,ww as lr,wx as J,xb as Kt,xm as pt,xu as je,xw as cr,yg as ie,yh as ae,yj as le,zj as ce,zn as ge,zp as ft,zr as v,zw as Ar}from"./chunk-NNPDC7K7.js";function i(S,a={}){return function(){return this.parseShowMysql(S,a)}}s(i,"showParser");function Ts(S){let a=this.sql(S,"this"),t=S.text("unit").toUpperCase(),e,r;if(t==="WEEK")e=`CONCAT(YEAR(${a}), ' ', WEEK(${a}, 1), ' 1')`,r="%Y %u %w";else if(t==="MONTH")e=`CONCAT(YEAR(${a}), ' ', MONTH(${a}), ' 1')`,r="%Y %c %e";else if(t==="QUARTER")e=`CONCAT(YEAR(${a}), ' ', QUARTER(${a}) * 3 - 2, ' 1')`,r="%Y %c %e";else if(t==="YEAR")e=`CONCAT(YEAR(${a}), ' 1 1')`,r="%Y %c %e";else return t!=="DAY"&&this.unsupported(`Unexpected interval unit: ${t}`),this.func("DATE",[a]);return this.func("STR_TO_DATE",[e,`'${r}'`])}s(Ts,"dateTruncSql");var ps=new Set(["f","H","h","I","i","k","l","p","r","S","s","T"]);function Ss(S){let a=0,t=S.length;for(;a<t;){if(S[a]==="%"&&(a+=1,a<t&&ps.has(S[a])))return!0;a+=1}return!1}s(Ss,"hasTimeSpecifier");function us(S){let a=c(S,1),t=Vt.formatTime(a),e=c(S,0);return a&&Ss(a instanceof Kt?a.name:a)?new mt({this:e,format:t||""}):new Ct({this:e,format:t})}s(us,"buildStrToDate");function Gt(S){return this.func("STR_TO_DATE",[S.args.this,this.formatTime(S)])}s(Gt,"strToDateSql");function ls(S){let a=S.args.scale,t=S.args.this;return a===void 0||a.toValue()===$.SECONDS.toValue()?this.func("FROM_UNIXTIME",[t,this.formatTime(S)]):this.func("FROM_UNIXTIME",[new ue({this:t,expression:je("POW","10",a.toString())}),this.formatTime(S)])}s(ls,"unixToTimeSql");function Ft(S){return function(a){return this.func(`DATE_${S}`,[a.args.this,new ot({this:a.args.expression,unit:Bt(a)})])}}s(Ft,"dateAddSql");function cs(S){return S.args.format?Gt.call(this,S):this.func("DATE",[S.args.this])}s(cs,"tsOrDsToDateSql");function d(S,a=["this"]){return function(t){for(let e of a){let r=t.getArgKey(e);(r instanceof O||r instanceof gt)&&!r.getArgKey("format")&&t.setArgKey(e,r.args.this)}return S?S.call(this,t):this.functionFallbackSql(t)}}s(d,"removeTsOrDsToDate");var fr,dr,xr,Z,f=class f extends(xr=J,dr=[o],fr=[o],xr){constructor(){super(...arguments);this.NESTED_COMMENTS=!1}static get ORIGINAL_KEYWORDS(){return{...J.KEYWORDS,BLOB:"blob",CHARSET:"characterSet",DISTINCTROW:"distinct",EXPLAIN:"describe",FORCE:"force",IGNORE:"ignore",KEY:"key","LOCK TABLES":"command",LONGBLOB:"longblob",LONGTEXT:"longtext",MEDIUMBLOB:"mediumblob",MEDIUMINT:"mediumint",MEDIUMTEXT:"mediumtext","MEMBER OF":"memberOf",MOD:"mod",SEPARATOR:"separator",SERIAL:"serial",SIGNED:"bigint","SIGNED INTEGER":"bigint","SOUNDS LIKE":"soundsLike",START:"begin",TIMESTAMP:"timestamptz",TINYBLOB:"tinyblob",TINYTEXT:"tinytext",TYPE:"type","UNLOCK TABLES":"command",UNSIGNED:"ubigint","UNSIGNED INTEGER":"ubigint",YEAR:"year",_ARMSCII8:"introducer",_ASCII:"introducer",_BIG5:"introducer",_BINARY:"introducer",_CP1250:"introducer",_CP1251:"introducer",_CP1256:"introducer",_CP1257:"introducer",_CP850:"introducer",_CP852:"introducer",_CP866:"introducer",_CP932:"introducer",_DEC8:"introducer",_EUCJPMS:"introducer",_EUCKR:"introducer",_GB18030:"introducer",_GB2312:"introducer",_GBK:"introducer",_GEOSTD8:"introducer",_GREEK:"introducer",_HEBREW:"introducer",_HP8:"introducer",_KEYBCS2:"introducer",_KOI8R:"introducer",_KOI8U:"introducer",_LATIN1:"introducer",_LATIN2:"introducer",_LATIN5:"introducer",_LATIN7:"introducer",_MACCE:"introducer",_MACROMAN:"introducer",_SJIS:"introducer",_SWE7:"introducer",_TIS620:"introducer",_UCS2:"introducer",_UJIS:"introducer",_UTF8:"introducer",_UTF16:"introducer",_UTF16LE:"introducer",_UTF32:"introducer",_UTF8MB3:"introducer",_UTF8MB4:"introducer","@@":"sessionParameter"}}static get COMMANDS(){let t=new Set([...J.COMMANDS,"replace"]);return t.delete("show"),t}};Z=b(xr),E(Z,10,"ORIGINAL_KEYWORDS",dr,f),E(Z,10,"COMMANDS",fr,f),q(Z,f),B(Z,3,f),s(f,"MySQLTokenizer"),f.QUOTES=["'",'"'],f.COMMENTS=["--","#",["/*","*/"]],f.IDENTIFIERS=["`"],f.STRING_ESCAPES=["'",'"',"\\"],f.BIT_STRINGS=[["b'","'"],["B'","'"],["0b",""]],f.HEX_STRINGS=[["x'","'"],["X'","'"],["0x",""]],f.ESCAPE_FOLLOW_CHARS=["0","b","n","r","t","Z","%","_"];var wt=f,Cr,mr,Pr,gr,Dr,Ur,_r,Lr,Mr,br,qr,Br,Fr,Gr,wr,yr,Yr,Vr,Kr,Hr,A,T=class T extends(Hr=I,Kr=[o],Vr=[o],Yr=[o],yr=[o],wr=[o],Gr=[o],Fr=[o],Br=[o],qr=[o],br=[o],Mr=[o],Lr=[o],_r=[o],Ur=[o],Dr=[o],gr=[o],Pr=[o],mr=[o],Cr=[o],Hr){static get ID_VAR_TOKENS(){return new Set([...I.ID_VAR_TOKENS,"currentCatalog"])}static get FUNC_TOKENS(){return new Set([...I.FUNC_TOKENS,"database","mod","schema","values","characterSet"])}static get CONJUNCTION(){return{...I.CONJUNCTION,damp:ke,xor:$e}}static get DISJUNCTION(){return{...I.DISJUNCTION,dpipe:ve}}static get TABLE_ALIAS_TOKENS(){return(()=>{let t=new Set(I.TABLE_ALIAS_TOKENS);for(let e of I.TABLE_INDEX_HINT_TOKENS)t.delete(e);return t})()}static get RANGE_PARSERS(){return{...I.RANGE_PARSERS,soundsLike:function(t){return this.expression(le,{this:this.expression(xt,{this:t}),expression:this.expression(xt,{this:this.parseTerm()})})},memberOf:function(t){return this.expression(Le,{this:t,expression:this.parseWrapped(this.parseExpression.bind(this))})}}}static get FUNCTIONS(){return{...I.FUNCTIONS,BIT_AND:s(t=>_t.fromArgList(t),"BIT_AND"),BIT_OR:s(t=>Lt.fromArgList(t),"BIT_OR"),BIT_XOR:s(t=>Mt.fromArgList(t),"BIT_XOR"),BIT_COUNT:s(t=>Tt.fromArgList(t),"BIT_COUNT"),CONVERT_TZ:s(t=>new Oe({sourceTz:c(t,1),targetTz:c(t,2),timestamp:c(t,0)}),"CONVERT_TZ"),CURDATE:s(t=>St.fromArgList(t),"CURDATE"),CURTIME:s(t=>de.fromArgList(t),"CURTIME"),DATE:s(t=>new O({this:c(t,0)}),"DATE"),DATE_ADD:s(t=>X(H)(t),"DATE_ADD"),DATE_FORMAT:s(t=>new v({this:new gt({this:c(t,0)}),format:W.getOrRaise("mysql")._constructor.formatTime(c(t,1))}),"DATE_FORMAT"),DATE_SUB:s(t=>X(lt)(t),"DATE_SUB"),DAY:s(t=>new Nt({this:new O({this:c(t,0)})}),"DAY"),DAYOFMONTH:s(t=>new It({this:new O({this:c(t,0)})}),"DAYOFMONTH"),DAYOFWEEK:s(t=>new At({this:new O({this:c(t,0)})}),"DAYOFWEEK"),DAYOFYEAR:s(t=>new ht({this:new O({this:c(t,0)})}),"DAYOFYEAR"),FORMAT:s(t=>Pt.fromArgList(t),"FORMAT"),FROM_UNIXTIME:ur($,{dialect:"mysql"}),ISNULL:Rr,LENGTH:s(t=>new ft({this:c(t,0),binary:!0}),"LENGTH"),MAKETIME:s(t=>Ot.fromArgList(t),"MAKETIME"),MONTH:s(t=>new dt({this:new O({this:c(t,0)})}),"MONTH"),MONTHNAME:s(t=>new v({this:new O({this:c(t,0)}),format:new F({this:"%B",isString:!0})}),"MONTHNAME"),SCHEMA:s(t=>ut.fromArgList(t),"SCHEMA"),DATABASE:s(t=>ut.fromArgList(t),"DATABASE"),STR_TO_DATE:us,TIMESTAMPDIFF:bt(k,void 0,{defaultUnit:"DAY"}),TO_DAYS:s(t=>{let e=new ct({this:new O({this:c(t,0)}),expression:new O({this:new F({this:"0000-01-01",isString:!0})}),unit:new P({this:"DAY"})});return new he({this:e.add(1)})},"TO_DAYS"),VERSION:s(t=>pt.fromArgList(t),"VERSION"),WEEK:s(t=>new Dt({this:new O({this:c(t,0)}),mode:c(t,1)}),"WEEK"),WEEKOFYEAR:s(t=>new Rt({this:new O({this:c(t,0)})}),"WEEKOFYEAR"),YEAR:s(t=>new Ut({this:new O({this:c(t,0)})}),"YEAR")}}static get FUNCTION_PARSERS(){return{...I.FUNCTION_PARSERS,GROUP_CONCAT:s(function(){return this.parseGroupConcat()},"GROUP_CONCAT"),VALUES:s(function(){return this.expression(Re,{this:"VALUES",expressions:[this.parseIdVar()]})},"VALUES"),JSON_VALUE:s(function(){return this.parseJsonValue()},"JSON_VALUE"),SUBSTR:s(function(){return this.parseSubstring()},"SUBSTR")}}static get STATEMENT_PARSERS(){return{...I.STATEMENT_PARSERS,show:function(){return this.parseShow()}}}static get PROPERTY_PARSERS(){return{...I.PROPERTY_PARSERS,LOCK:s(function(){return this.parsePropertyAssignment(ne)},"LOCK"),"PARTITION BY":s(function(){return this.parsePartitionProperty()},"PARTITION BY")}}static get SET_PARSERS(){return{...I.SET_PARSERS,PERSIST:s(function(){return this.parseSetItemAssignment({kind:"persist"})},"PERSIST"),PERSIST_ONLY:s(function(){return this.parseSetItemAssignment({kind:"PERSIST_ONLY"})},"PERSIST_ONLY"),"CHARACTER SET":s(function(){return this.parseSetItemCharset("CHARACTER SET")},"CHARACTER SET"),CHARSET:s(function(){return this.parseSetItemCharset("CHARACTER SET")},"CHARSET"),NAMES:s(function(){return this.parseSetItemNames()},"NAMES")}}static get CONSTRAINT_PARSERS(){return{...I.CONSTRAINT_PARSERS,FULLTEXT:s(function(){return this.parseIndexConstraint("FULLTEXT")},"FULLTEXT"),INDEX:s(function(){return this.parseIndexConstraint()},"INDEX"),KEY:s(function(){return this.parseIndexConstraint()},"KEY"),SPATIAL:s(function(){return this.parseIndexConstraint("SPATIAL")},"SPATIAL"),ZEROFILL:s(function(){return this.expression(ee)},"ZEROFILL"),COLUMN_FORMAT:s(function(){return this.parseIdVar(),this.expression(P,{this:"COLUMN_FORMAT"})},"COLUMN_FORMAT"),STORAGE:s(function(){return this.parseIdVar(),this.expression(P,{this:"STORAGE"})},"STORAGE"),INVISIBLE:s(function(){return this.expression(P,{this:"INVISIBLE"})},"INVISIBLE"),VISIBLE:s(function(){return this.expression(P,{this:"VISIBLE"})},"VISIBLE")}}static get ALTER_PARSERS(){return{...I.ALTER_PARSERS,MODIFY:s(function(){return this.parseAlterTableModify()},"MODIFY"),AUTO_INCREMENT:s(function(){return this.parsePropertyAssignment(ie)},"AUTO_INCREMENT"),COMMENT:s(function(){return this.parsePropertyAssignment(Ee)},"COMMENT")}}static get ALTER_ALTER_PARSERS(){return{...I.ALTER_ALTER_PARSERS,INDEX:s(function(){return this.parseAlterTableAlterIndex()},"INDEX")}}static get SCHEMA_UNNAMED_CONSTRAINTS(){return new Set([...I.SCHEMA_UNNAMED_CONSTRAINTS,"FULLTEXT","INDEX","KEY","SPATIAL"])}static get PROFILE_TYPES(){return{ALL:[],CPU:[],IPC:[],MEMORY:[],SOURCE:[],SWAPS:[],BLOCK:["IO"],CONTEXT:["SWITCHES"],PAGE:["FAULTS"]}}static get TYPE_TOKENS(){return new Set([...I.TYPE_TOKENS,"set"])}static get ENUM_TYPE_TOKENS(){return new Set([...I.ENUM_TYPE_TOKENS,"set"])}static get OPERATION_MODIFIERS(){return new Set(["HIGH_PRIORITY","STRAIGHT_JOIN","SQL_SMALL_RESULT","SQL_BIG_RESULT","SQL_BUFFER_RESULT","SQL_NO_CACHE","SQL_CALC_FOUND_ROWS"])}parseGeneratedAsIdentity(){let t=super.parseGeneratedAsIdentity();if(this.matchTexts(["STORED","VIRTUAL"])){let e=this.prev?.text.toUpperCase()==="STORED";t instanceof Et?t.setArgKey("persisted",e):t instanceof re&&(t=this.expression(Et,{this:t.args.expression,persisted:e}))}return t}parsePrimaryKeyPart(){let t=this.parseIdVar();if(!this.match("lParen"))return t;let e=this.parseNumber();return this.matchRParen(),this.expression(Xt,{this:t,expression:e})}parseUnique(){this.matchTexts(["KEY","INDEX"]);let t=this.parseUniqueKey(),e=(this.match("using")||void 0)&&this.advanceAny()&&this.prev?.text;if(!this.match("lParen",{advance:!1}))return this.expression(at,{this:t,indexType:e});let r=this.parseWrappedCsv(this.parseOrdered.bind(this));return this.expression(at,{this:this.expression(jt,{this:t,expressions:r}),indexType:e||(this.match("using")||void 0)&&this.advanceAny()&&this.prev?.text,options:this.parseKeyConstraintOptions()})}parseIndexConstraint(t){t&&this.matchTexts(["INDEX","KEY"]);let e=this.parseIdVar({anyToken:!1}),r=this.match("using")&&this.advanceAny()&&this.prev?.text,u=this.parseWrappedCsv(this.parseOrdered.bind(this)),p=[];for(;;){let R;if(this.matchTextSeq(["KEY_BLOCK_SIZE"])?(this.match("eq"),R=new C({keyBlockSize:this.parseNumber()})):this.match("using")?R=new C({using:this.advanceAny()&&this.prev?.text}):this.matchTextSeq(["WITH","PARSER"])?R=new C({parser:this.parseVar({anyToken:!0})}):this.match("comment")?R=new C({comment:this.parseString()}):this.matchTextSeq(["VISIBLE"])?R=new C({visible:!0}):this.matchTextSeq(["INVISIBLE"])?R=new C({visible:!1}):this.matchTextSeq(["ENGINE_ATTRIBUTE"])?(this.match("eq"),R=new C({engineAttr:this.parseString()})):this.matchTextSeq(["SECONDARY_ENGINE_ATTRIBUTE"])&&(this.match("eq"),R=new C({secondaryEngineAttr:this.parseString()})),!R)break;p.push(R)}return this.expression(se,{this:e,expressions:u,kind:t,indexType:r,options:p})}parseShowMysql(t,e={}){let{target:r=!1,full:u,global:p}=e,R=this.matchTextSeq(["JSON"]),x;r&&(typeof r=="string"&&this.matchTextSeq(r.split(" ")),x=this.parseIdVar());let j=this.matchTextSeq(["IN"])?this.parseString():void 0,m,U;t==="BINLOG EVENTS"||t==="RELAYLOG EVENTS"?m=this.matchTextSeq(["FROM"])?this.parseNumber():void 0:this.match("from")?U=this.parseIdVar():this.match("dot")&&(U=x,x=this.parseIdVar());let w=this.matchTextSeq(["FOR","CHANNEL"])?this.parseIdVar():void 0,_=this.matchTextSeq(["LIKE"])?this.parseString():void 0,z=this.parseWhere(),y,Y,g,L;t==="PROFILE"?(y=this.parseCsv(()=>this.parseVarFromOptions(T.PROFILE_TYPES)),Y=this.matchTextSeq(["FOR","QUERY"])?this.parseNumber():void 0,g=this.matchTextSeq(["OFFSET"])?this.parseNumber():void 0,L=this.matchTextSeq(["LIMIT"])?this.parseNumber():void 0):[g,L]=this.parseOldstyleLimit();let M;this.matchTextSeq(["MUTEX"])&&(M=!0),this.matchTextSeq(["STATUS"])&&(M=!1);let Q=this.matchTextSeq(["FOR","TABLE"])?this.parseIdVar():void 0,tt=this.matchTextSeq(["FOR","GROUP"])?this.parseString():void 0,et=this.matchTextSeq(["FOR","USER"])?this.parseString():void 0,rt=this.matchTextSeq(["FOR","ROLE"])?this.parseString():void 0,os=this.matchTextSeq(["INTO","OUTFILE"])?this.parseString():void 0;return this.expression(kt,{this:t,target:x,full:u,log:j,position:m,db:U,channel:w,like:_,where:z,types:y,query:Y,offset:g,limit:L,mutex:M,forTable:Q,forGroup:tt,forUser:et,forRole:rt,intoOutfile:os,json:R,global:p})}parseOldstyleLimit(){let t,e;if(this.matchTextSeq(["LIMIT"])){let r=this.parseCsv(this.parseNumber.bind(this));r.length===1?t=r[0]:r.length===2&&(t=r[1],e=r[0])}return[e,t]}parseSetItemCharset(t){let e=this.parseString()||this.parseUnquotedField();return this.expression(st,{this:e,kind:t})}parseSetItemNames(){let t=this.parseString()||this.parseUnquotedField(),e;return this.matchTextSeq(["COLLATE"])&&(e=this.parseString()||this.parseUnquotedField()),this.expression(st,{this:t,collate:e,kind:"NAMES"})}parseType(t={}){let{parseInterval:e=!0,fallbackToIdentifier:r=!1}=t;if(this.match("binary",{advance:!1})){let u=this.parseTypes({checkFunc:!0,allowIdentifiers:!1});if(u instanceof nt)return this.expression(Ne,{this:this.parseColumn(),to:u})}return super.parseType({parseInterval:e,fallbackToIdentifier:r})}parseAlterTableAlterIndex(){let t=this.parseField({anyToken:!0}),e;return this.matchTextSeq(["VISIBLE"])?e=!0:this.matchTextSeq(["INVISIBLE"])&&(e=!1),this.expression(Wt,{this:t,visible:e})}parseAlterTableModify(){this.match("column");let t=this.parseField({anyToken:!0});if(!t)return;let e=this.parseColumnDef(t);if(e instanceof vt)return this.expression($t,{this:e})}parsePartitionProperty(){let t,e;if(this.matchTextSeq(["RANGE"])?(t=V,e=this.parsePartitionRangeValue.bind(this)):this.matchTextSeq(["LIST"])&&(t=K,e=this.parsePartitionListValue.bind(this)),!t||!e)return;let r=this.parseWrappedCsv(this.parseAssignment.bind(this));if(!this.matchTextSeq(["(","PARTITION"],{advance:!1}))return r;let u=this.parseWrappedCsv(e);return this.expression(t,{partitionExpressions:r,createExpressions:u})}parsePartitionRangeValue(){this.matchTextSeq(["PARTITION"]);let t=this.parseIdVar();if(!this.matchTextSeq(["VALUES","LESS","THAN"]))return t;let e=this.parseWrappedCsv(this.parseExpression.bind(this));e.length===1&&e[0]instanceof te&&e[0].name.toUpperCase()==="MAXVALUE"&&(e=[new P({this:"MAXVALUE"})]);let r=this.expression(Jt,{this:t,expressions:e});return this.expression(it,{expressions:[r]})}parsePartitionListValue(){this.matchTextSeq(["PARTITION"]);let t=this.parseIdVar();this.matchTextSeq(["VALUES","IN"]);let e=this.parseWrappedCsv(this.parseExpression.bind(this)),r=this.expression(Zt,{this:t,expressions:e});return this.expression(it,{expressions:[r]})}parsePrimaryKey(t={}){let{wrappedOptional:e=!1,inProps:r=!1}=t;return super.parsePrimaryKey({wrappedOptional:e,inProps:r,namedPrimaryKey:!0})}};A=b(Hr),E(A,10,"ID_VAR_TOKENS",Kr,T),E(A,10,"FUNC_TOKENS",Vr,T),E(A,10,"CONJUNCTION",Yr,T),E(A,10,"DISJUNCTION",yr,T),E(A,10,"TABLE_ALIAS_TOKENS",wr,T),E(A,10,"RANGE_PARSERS",Gr,T),E(A,10,"FUNCTIONS",Fr,T),E(A,10,"FUNCTION_PARSERS",Br,T),E(A,10,"STATEMENT_PARSERS",qr,T),E(A,10,"PROPERTY_PARSERS",br,T),E(A,10,"SET_PARSERS",Mr,T),E(A,10,"CONSTRAINT_PARSERS",Lr,T),E(A,10,"ALTER_PARSERS",_r,T),E(A,10,"ALTER_ALTER_PARSERS",Ur,T),E(A,10,"SCHEMA_UNNAMED_CONSTRAINTS",Dr,T),E(A,10,"PROFILE_TYPES",gr,T),E(A,10,"TYPE_TOKENS",Pr,T),E(A,10,"ENUM_TYPE_TOKENS",mr,T),E(A,10,"OPERATION_MODIFIERS",Cr,T),q(A,T),B(A,3,T),s(T,"MySQLParser"),T.SHOW_PARSERS={"BINARY LOGS":i("BINARY LOGS"),"MASTER LOGS":i("BINARY LOGS"),"BINLOG EVENTS":i("BINLOG EVENTS"),"CHARACTER SET":i("CHARACTER SET"),CHARSET:i("CHARACTER SET"),COLLATION:i("COLLATION"),"FULL COLUMNS":i("COLUMNS",{target:"FROM",full:!0}),COLUMNS:i("COLUMNS",{target:"FROM"}),"CREATE DATABASE":i("CREATE DATABASE",{target:!0}),"CREATE EVENT":i("CREATE EVENT",{target:!0}),"CREATE FUNCTION":i("CREATE FUNCTION",{target:!0}),"CREATE PROCEDURE":i("CREATE PROCEDURE",{target:!0}),"CREATE TABLE":i("CREATE TABLE",{target:!0}),"CREATE TRIGGER":i("CREATE TRIGGER",{target:!0}),"CREATE VIEW":i("CREATE VIEW",{target:!0}),DATABASES:i("DATABASES"),SCHEMAS:i("DATABASES"),ENGINE:i("ENGINE",{target:!0}),"STORAGE ENGINES":i("ENGINES"),ENGINES:i("ENGINES"),ERRORS:i("ERRORS"),EVENTS:i("EVENTS"),"FUNCTION CODE":i("FUNCTION CODE",{target:!0}),"FUNCTION STATUS":i("FUNCTION STATUS"),GRANTS:i("GRANTS",{target:"FOR"}),INDEX:i("INDEX",{target:"FROM"}),"MASTER STATUS":i("MASTER STATUS"),"OPEN TABLES":i("OPEN TABLES"),PLUGINS:i("PLUGINS"),"PROCEDURE CODE":i("PROCEDURE CODE",{target:!0}),"PROCEDURE STATUS":i("PROCEDURE STATUS"),PRIVILEGES:i("PRIVILEGES"),"FULL PROCESSLIST":i("PROCESSLIST",{full:!0}),PROCESSLIST:i("PROCESSLIST"),PROFILE:i("PROFILE"),PROFILES:i("PROFILES"),"RELAYLOG EVENTS":i("RELAYLOG EVENTS"),REPLICAS:i("REPLICAS"),"SLAVE HOSTS":i("REPLICAS"),"REPLICA STATUS":i("REPLICA STATUS"),"SLAVE STATUS":i("REPLICA STATUS"),"GLOBAL STATUS":i("STATUS",{global:!0}),"SESSION STATUS":i("STATUS"),STATUS:i("STATUS"),"TABLE STATUS":i("TABLE STATUS"),"FULL TABLES":i("TABLES",{full:!0}),TABLES:i("TABLES"),TRIGGERS:i("TRIGGERS"),"GLOBAL VARIABLES":i("VARIABLES",{global:!0}),"SESSION VARIABLES":i("VARIABLES"),VARIABLES:i("VARIABLES"),WARNINGS:i("WARNINGS")},T.LOG_DEFAULTS_TO_LN=!0,T.STRING_ALIASES=!0,T.VALUES_FOLLOWED_BY_PAREN=!1,T.SUPPORTS_PARTITION_SELECTION=!0;var yt=T,kr,vr,$r,Wr,Xr,Jr,Zr,jr,zr,Qr,ts,es,rs,N,n=class n extends(rs=G,es=[o],ts=[o],Qr=[o],zr=[o],jr=[o],Zr=[o],Jr=[o],Xr=[o],Wr=[o],$r=[o],vr=[o],kr=[o],rs){static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let t=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(e=>t.delete(e)),t}static get NULL_ORDERING_SUPPORTED(){return"unsupported"}static get ORIGINAL_TRANSFORMS(){return new Map([...G.TRANSFORMS,[Ve,h("GROUP_CONCAT")],[_t,h("BIT_AND")],[Lt,h("BIT_OR")],[Mt,h("BIT_XOR")],[Tt,h("BIT_COUNT")],[fe,function(t){return this.chrSql(t,{name:"CHAR"})}],[St,Er],[pt,h("VERSION")],[ct,d(function(t){return this.func("DATEDIFF",[t.args.this,t.args.expression])},["this","expression"])],[H,d(Ft("ADD"))],[Ue,cr],[lt,d(Ft("SUB"))],[Pe,Ts],[Nt,d()],[It,d(h("DAYOFMONTH"))],[At,d(h("DAYOFWEEK"))],[ht,d(h("DAYOFYEAR"))],[He,function(t){return`GROUP_CONCAT(${this.sql(t,"this")} SEPARATOR ${this.sql(t,"separator")||"','"})`}],[Ie,ar],[_e,nr],[ft,Or],[We,h("MAX")],[Xe,h("MIN")],[Je,Ir],[Ze,Ar],[dt,d()],[ce,function(t){return this.binary(t,"<=>")}],[Ae,function(t){return`NOT ${this.binary(t,"<=>")}`}],[Pt,h("FORMAT")],[Qt,Tr],[Se,ze([tr,rr,er,sr,Qe])],[be,function(t){return Sr.call(this,t,{funcName:"LOCATE",supportsPosition:!0})}],[Ct,Gt],[mt,Gt],[qe,h("INSERT")],[xe,()=>"SESSION_USER()"],[zt,or],[Ot,h("MAKETIME")],[ge,qt("DATE","ADD")],[k,function(t){return this.func("TIMESTAMPDIFF",[Bt(t),t.args.expression,t.args.this])}],[De,qt("DATE","SUB")],[Fe,h("UNIX_TIMESTAMP")],[Be,function(t){return lr.call(this,t,{includePrecision:!t.args.zone})}],[v,d(function(t){return this.func("DATE_FORMAT",[t.args.this,this.formatTime(t)])})],[Ge,hr],[Me,h("TRUNCATE")],[Ke,pr],[we,Ft("ADD")],[ye,function(t){return this.func("DATEDIFF",[t.args.this,t.args.expression])}],[O,cs],[Ye,function(t){return`ORD(CONVERT(${this.sql(t.args.this)} USING utf32))`}],[$,ls],[Dt,d()],[Rt,d(h("WEEKOFYEAR"))],[Ut,d()],[me,h("UTC_TIMESTAMP")],[Ce,h("UTC_TIME")]])}static get UNSIGNED_TYPE_MAPPING(){return new Map([["ubigint","BIGINT"],["uint","INT"],["umediumint","MEDIUMINT"],["usmallint","SMALLINT"],["utinyint","TINYINT"],["udecimal","DECIMAL"],["udouble","DOUBLE"]])}static get TIMESTAMP_TYPE_MAPPING(){return new Map([["datetime2","DATETIME"],["smalldatetime","DATETIME"],["timestamp","DATETIME"],["timestampntz","DATETIME"],["timestamptz","TIMESTAMP"],["timestampltz","TIMESTAMP"]])}static get TYPE_MAPPING(){let t=new Map(G.TYPE_MAPPING);for(let[e,r]of n.UNSIGNED_TYPE_MAPPING)t.set(e,r);for(let[e,r]of n.TIMESTAMP_TYPE_MAPPING)t.set(e,r);return t.delete("mediumtext"),t.delete("longtext"),t.delete("tinytext"),t.delete("blob"),t.delete("mediumblob"),t.delete("longblob"),t.delete("tinyblob"),t}static get PROPERTIES_LOCATION(){let t=new Map(G.PROPERTIES_LOCATION);return t.set(Te,"unsupported"),t.set(pe,"unsupported"),t.set(ae,"unsupported"),t.set(V,"postSchema"),t.set(K,"postSchema"),t}static get CHAR_CAST_MAPPING(){return["longtext","longblob","mediumblob","mediumtext","text","tinyblob","tinytext","varchar"].reduce((t,e)=>({...t,[e]:"CHAR"}),{})}static get SIGNED_CAST_MAPPING(){return["bigint","boolean","int","smallint","tinyint","mediumint"].reduce((t,e)=>({...t,[e]:"SIGNED"}),{})}static get CAST_MAPPING(){return{...n.CHAR_CAST_MAPPING,...n.SIGNED_CAST_MAPPING,ubigint:"UNSIGNED"}}static get TIMESTAMP_FUNC_TYPES(){return new Set(["timestamptz","timestampltz"])}static get RESERVED_KEYWORDS(){return new Set(["accessible","add","all","alter","analyze","and","as","asc","asensitive","before","between","bigint","binary","blob","both","by","call","cascade","case","change","char","character","check","collate","column","condition","constraint","continue","convert","create","cross","cube","cume_dist","current_date","current_time","current_timestamp","current_user","cursor","database","databases","day_hour","day_microsecond","day_minute","day_second","dec","decimal","declare","default","delayed","delete","dense_rank","desc","describe","deterministic","distinct","distinctrow","div","double","drop","dual","each","else","elseif","empty","enclosed","escaped","except","exists","exit","explain","false","fetch","first_value","float","float4","float8","for","force","foreign","from","fulltext","function","generated","get","grant","group","grouping","groups","having","high_priority","hour_microsecond","hour_minute","hour_second","if","ignore","in","index","infile","inner","inout","insensitive","insert","int","int1","int2","int3","int4","int8","integer","intersect","interval","into","io_after_gtids","io_before_gtids","is","iterate","join","json_table","key","keys","kill","lag","last_value","lateral","lead","leading","leave","left","like","limit","linear","lines","load","localtime","localtimestamp","lock","long","longblob","longtext","loop","low_priority","master_bind","master_ssl_verify_server_cert","match","maxvalue","mediumblob","mediumint","mediumtext","middleint","minute_microsecond","minute_second","mod","modifies","natural","not","no_write_to_binlog","nth_value","ntile","undefined","numeric","of","on","optimize","optimizer_costs","option","optionally","or","order","out","outer","outfile","over","partition","percent_rank","precision","primary","procedure","purge","range","rank","read","reads","read_write","real","recursive","references","regexp","release","rename","repeat","replace","require","resignal","restrict","return","revoke","right","rlike","row","rows","row_number","schema","schemas","second_microsecond","select","sensitive","separator","set","show","signal","smallint","spatial","specific","sql","sqlexception","sqlstate","sqlwarning","sql_big_result","sql_calc_found_rows","sql_small_result","ssl","starting","stored","straight_join","system","table","terminated","then","tinyblob","tinyint","tinytext","to","trailing","trigger","true","undo","union","unique","unlock","unsigned","update","usage","use","using","utc_date","utc_time","utc_timestamp","values","varbinary","varchar","varcharacter","varying","virtual","when","where","while","window","with","write","xor","year_month","zerofill"])}locateProperties(t){let e=super.locateProperties(t),r=t.parent;if(r instanceof Ht&&r.args.kind?.toUpperCase()==="VIEW"){let u=e.get("postSchema");if(u){for(let p=0;p<u.length;p++)if(u[p]instanceof oe){let[R]=u.splice(p,1),x=this._constructor.SQL_SECURITY_VIEW_LOCATION;e.has(x)||e.set(x,[]),e.get(x).push(R);break}}}return e}computedColumnConstraintSql(t){let e=t.args.persisted?"STORED":"VIRTUAL";return`GENERATED ALWAYS AS (${this.sql(t.args.this?.unnest())}) ${e}`}arraySql(t){return this.unsupported("Arrays are not supported by MySQL"),this.functionFallbackSql(t)}arrayContainsAllSql(t){return this.unsupported("Array operations are not supported by MySQL"),this.functionFallbackSql(t)}dPipeSql(t){return this.func("CONCAT",[...t.flatten()])}extractSql(t){let e=t.name;return e&&e.toLowerCase()==="epoch"?this.func("UNIX_TIMESTAMP",[t.args.expression]):super.extractSql(t)}dataTypeSql(t){if(this.constructor.VARCHAR_REQUIRES_SIZE&&t.isType("varchar")&&!t.args.expressions?.length)return"TEXT";let e=super.dataTypeSql(t);return n.UNSIGNED_TYPE_MAPPING.has(t.args.this)&&(e=`${e} UNSIGNED`),e}jsonArrayContainsSql(t){return`${this.sql(t,"this")} MEMBER OF(${this.sql(t,"expression")})`}castSql(t,e={}){let r=t.args.to;if(r instanceof nt){let u=r.args.this;if(this._constructor.TIMESTAMP_FUNC_TYPES.has(u))return this.func("TIMESTAMP",[t.args.this]);let p=this._constructor.CAST_MAPPING[u];p&&r.setArgKey("this",p)}return super.castSql(t)}showSql(t){let e=` ${t.name}`,r=t.args.full?" FULL":"",u=t.args.global?" GLOBAL":"",p=this.sql(t,"target");p=p?` ${p}`:"",["COLUMNS","INDEX"].includes(t.name)?p=` FROM${p}`:t.name==="GRANTS"?p=` FOR${p}`:["LINKS","PARTITIONS"].includes(t.name)?p=p?` ON${p}`:"":t.name==="PROJECTIONS"&&(p=p?` ON TABLE${p}`:"");let R=this.prefixedSql("FROM",t,"db"),x=this.prefixedSql("LIKE",t,"like"),j=this.sql(t,"where"),m=this.expressions(t,{key:"types"});m=m&&` ${m}`;let U=this.prefixedSql("FOR QUERY",t,"query"),w="",_="";t.name==="PROFILE"?(w=this.prefixedSql("OFFSET",t,"offset"),_=this.prefixedSql("LIMIT",t,"limit")):_=this.oldStyleLimitSql(t);let z=this.prefixedSql("IN",t,"log"),y=this.prefixedSql("FROM",t,"position"),Y=this.prefixedSql("FOR CHANNEL",t,"channel"),g="";t.name==="ENGINE"&&(g=t.args.mutex?" MUTEX":" STATUS");let L=this.prefixedSql("FOR TABLE",t,"forTable"),M=this.prefixedSql("FOR GROUP",t,"forGroup"),Q=this.prefixedSql("FOR USER",t,"forUser"),tt=this.prefixedSql("FOR ROLE",t,"forRole"),et=this.prefixedSql("INTO OUTFILE",t,"intoOutfile"),rt=t.args.json?" JSON":"";return`SHOW${r}${u}${e}${rt}${p}${L}${m}${R}${U}${z}${y}${Y}${g}${x}${j}${w}${_}${M}${Q}${tt}${et}`}alterRenameSql(t,e={}){return super.alterRenameSql(t,{includeTo:!1})}alterColumnSql(t){let e=this.sql(t,"dtype");return e?`MODIFY COLUMN ${this.sql(t,"this")} ${e}`:super.alterColumnSql(t)}prefixedSql(t,e,r){let u=this.sql(e,r);return u?` ${t} ${u}`:""}oldStyleLimitSql(t){let e=this.sql(t,"limit"),r=this.sql(t,"offset");return e?` LIMIT ${r?`${r}, ${e}`:e}`:""}timestampTruncSql(t){let e=t.args.unit,r="0000-01-01 00:00:00",u=bt(k)([e,new F({this:r,isString:!0}),t.args.this]),p=new ot({this:u,unit:e}),R=X(H)([new F({this:r,isString:!0}),p]);return this.sql(R)}convertTimezoneSql(t){let e=t.args.sourceTz,r=t.args.targetTz,u=t.args.timestamp;return this.func("CONVERT_TZ",[u,e,r])}atTimeZoneSql(t){return this.unsupported("AT TIME ZONE is not supported by MySQL"),this.sql(t.args.this)}isAsciiSql(t){return`REGEXP_LIKE(${this.sql(t.args.this)}, '^[[:ascii:]]*$')`}ignoreNullsSql(t){return this.unsupported("MySQL does not support IGNORE NULLS."),this.sql(t.args.this)}currentSchemaSql(t){return ir.call(this,t,"this"),this.func("SCHEMA",[])}partitionSql(t){let e=t.parent;return e instanceof V||e instanceof K?this.expressions(t,{flat:!0}):super.partitionSql(t)}partitionByRangeOrListSql(t,e){let r=this.expressions(t,{key:"partitionExpressions",flat:!0}),u=this.expressions(t,{key:"createExpressions",flat:!0});return`PARTITION BY ${e} (${r}) (${u})`}partitionByRangePropertySql(t){return this.partitionByRangeOrListSql(t,"RANGE")}partitionByListPropertySql(t){return this.partitionByRangeOrListSql(t,"LIST")}partitionListSql(t){let e=this.sql(t,"this"),r=this.expressions(t,{flat:!0});return`PARTITION ${e} VALUES IN (${r})`}partitionRangeSql(t){let e=this.sql(t,"this"),r=this.expressions(t,{flat:!0});return`PARTITION ${e} VALUES LESS THAN (${r})`}};N=b(rs),E(N,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",es,n),E(N,10,"NULL_ORDERING_SUPPORTED",ts,n),E(N,10,"ORIGINAL_TRANSFORMS",Qr,n),E(N,10,"UNSIGNED_TYPE_MAPPING",zr,n),E(N,10,"TIMESTAMP_TYPE_MAPPING",jr,n),E(N,10,"TYPE_MAPPING",Zr,n),E(N,10,"PROPERTIES_LOCATION",Jr,n),E(N,10,"CHAR_CAST_MAPPING",Xr,n),E(N,10,"SIGNED_CAST_MAPPING",Wr,n),E(N,10,"CAST_MAPPING",$r,n),E(N,10,"TIMESTAMP_FUNC_TYPES",vr,n),E(N,10,"RESERVED_KEYWORDS",kr,n),q(N,n),B(N,3,n),s(n,"MySQLGenerator"),n.SUPPORTS_DECODE_CASE=!1,n.SELECT_KINDS=[],n.TRY_SUPPORTED=!1,n.SUPPORTS_UESCAPE=!1,n.INTERVAL_ALLOWS_PLURAL_FORM=!1,n.LOCKING_READS_SUPPORTED=!0,n.SUPPORTS_MODIFY_COLUMN=!0,n.JOIN_HINTS=!1,n.TABLE_HINTS=!0,n.DUPLICATE_KEY_UPDATE_WITH_SET=!1,n.QUERY_HINT_SEP=" ",n.VALUES_AS_TABLE=!1,n.NVL2_SUPPORTED=!1,n.LAST_DAY_SUPPORTS_DATE_PART=!1,n.JSON_TYPE_REQUIRED_FOR_EXTRACTION=!0,n.JSON_PATH_BRACKETED_KEY_SUPPORTED=!1,n.JSON_KEY_VALUE_PAIR_SEP=",",n.SUPPORTS_TO_NUMBER=!1,n.PARSE_JSON_NAME=void 0,n.PAD_FILL_PATTERN_IS_REQUIRED=!0,n.WRAP_DERIVED_VALUES=!1,n.VARCHAR_REQUIRES_SIZE=!0,n.SUPPORTS_MEDIAN=!1,n.UPDATE_STATEMENT_SUPPORTS_FROM=!1,n.SUPPORTS_CONVERT_TIMEZONE=!0,n.SQL_SECURITY_VIEW_LOCATION="postCreate",n.LIMIT_FETCH="LIMIT",n.LIMIT_ONLY_LITERALS=!0;var Yt=n,ss,is,ns,as,Es,D,l=class l extends(Es=W,as=[o],ns=[o],is=[o],ss=[o],Es){static get NORMALIZATION_STRATEGY(){return"caseSensitive"}static get EXPRESSION_METADATA(){return new Map(Nr.EXPRESSION_METADATA)}static get TIME_MAPPING(){return{"%M":"%B","%c":"%-m","%e":"%-d","%h":"%I","%i":"%M","%s":"%S","%u":"%W","%k":"%-H","%l":"%-I","%T":"%H:%M:%S","%W":"%A"}}static get VALID_INTERVAL_UNITS(){return new Set([...W.VALID_INTERVAL_UNITS,"SECOND_MICROSECOND","MINUTE_MICROSECOND","MINUTE_SECOND","HOUR_MICROSECOND","HOUR_SECOND","HOUR_MINUTE","DAY_MICROSECOND","DAY_SECOND","DAY_MINUTE","DAY_HOUR","YEAR_MONTH"])}};D=b(Es),E(D,10,"NORMALIZATION_STRATEGY",as,l),E(D,10,"EXPRESSION_METADATA",ns,l),E(D,10,"TIME_MAPPING",is,l),E(D,10,"VALID_INTERVAL_UNITS",ss,l),q(D,l),B(D,3,l),s(l,"MySQL"),l.DIALECT_NAME="mysql",l.PROMOTE_TO_INFERRED_DATETIME_TYPE=!0,l.IDENTIFIERS_CAN_START_WITH_DIGIT=!0,l.TIME_FORMAT="'%Y-%m-%d %T'",l.DPIPE_IS_STRING_CONCAT=!1,l.SUPPORTS_USER_DEFINED_TYPES=!1,l.SUPPORTS_SEMI_ANTI_JOIN=!1,l.SAFE_DIVISION=!0,l.SAFE_TO_ELIMINATE_DOUBLE_NEGATION=!1,l.LEAST_GREATEST_IGNORES_NULLS=!1,l.Tokenizer=wt,l.Parser=yt,l.Generator=Yt;var Vt=l;export{i as a,Ts as b,ps as c,us as d,Gt as e,ls as f,Ft as g,cs as h,d as i,Vt as j};
2
- //# sourceMappingURL=chunk-FZMXAQA2.js.map
1
+ import{a as Nr}from"./chunk-7P5S7LVR.js";import{$v as pr,Ac as C,Aj as Ae,Am as St,An as De,Av as rr,Aw as Ir,Bh as V,Bn as k,Bv as sr,Ci as Se,Ck as Tt,Cm as de,Cw as hr,Dh as K,Dr as Be,Er as Fe,Fr as Ge,Gr as we,Hj as Ie,Hr as ye,Jb as Ht,Jn as Ot,Jr as O,Jv as ir,Kf as te,Km as ut,Kn as Ue,Kq as Me,Kv as G,Md as Zt,Mr as gt,Nf as ee,Ns as Ve,Nv as W,On as Nt,Ph as Ee,Pr as Ye,Pw as Rr,Qv as h,Rm as xe,Sa as c,Si as ot,Tc as Xt,Tm as Ce,Tr as $,Tv as nr,Uk as Re,Um as me,Vm as H,Wv as ar,Ww as Bt,Xh as oe,Xm as lt,Xp as dt,Xv as Er,Yl as Ne,Ym as ct,Zj as he,Zm as Pe,Zv as or,_v as Tr,a as s,ac as st,ag as re,ar as xt,b,bt as Ke,c as q,cc as kt,ce as P,cg as se,d as B,dw as Sr,e as E,ee as jt,en as At,es as Dt,ge as zt,gn as It,hn as ht,hp as _e,ie as Qt,im as fe,js as Ut,jt as He,kd as it,kn as Rt,kr as be,kw as ur,lc as vt,ld as Jt,lg as at,lt as ke,mi as Te,ml as Oe,mp as Le,mt as ve,mv as ze,mw as bt,nc as $t,nr as Ct,nt as $e,nv as Qe,nw as X,oc as Wt,or as mt,os as _t,ox as Or,pb as I,pe as nt,pg as Et,ps as Lt,pv as tr,pw as qt,qh as ne,qi as pe,qs as Mt,qv as er,rr as Pt,rt as We,s as o,sj as ue,st as Xe,tg as F,tt as Je,wr as qe,wt as Ze,ww as lr,wx as J,xb as Kt,xm as pt,xu as je,xw as cr,yg as ie,yh as ae,yj as le,zj as ce,zn as ge,zp as ft,zr as v,zw as Ar}from"./chunk-5TO2OPOM.js";function i(S,a={}){return function(){return this.parseShowMysql(S,a)}}s(i,"showParser");function Ts(S){let a=this.sql(S,"this"),t=S.text("unit").toUpperCase(),e,r;if(t==="WEEK")e=`CONCAT(YEAR(${a}), ' ', WEEK(${a}, 1), ' 1')`,r="%Y %u %w";else if(t==="MONTH")e=`CONCAT(YEAR(${a}), ' ', MONTH(${a}), ' 1')`,r="%Y %c %e";else if(t==="QUARTER")e=`CONCAT(YEAR(${a}), ' ', QUARTER(${a}) * 3 - 2, ' 1')`,r="%Y %c %e";else if(t==="YEAR")e=`CONCAT(YEAR(${a}), ' 1 1')`,r="%Y %c %e";else return t!=="DAY"&&this.unsupported(`Unexpected interval unit: ${t}`),this.func("DATE",[a]);return this.func("STR_TO_DATE",[e,`'${r}'`])}s(Ts,"dateTruncSql");var ps=new Set(["f","H","h","I","i","k","l","p","r","S","s","T"]);function Ss(S){let a=0,t=S.length;for(;a<t;){if(S[a]==="%"&&(a+=1,a<t&&ps.has(S[a])))return!0;a+=1}return!1}s(Ss,"hasTimeSpecifier");function us(S){let a=c(S,1),t=Vt.formatTime(a),e=c(S,0);return a&&Ss(a instanceof Kt?a.name:a)?new mt({this:e,format:t||""}):new Ct({this:e,format:t})}s(us,"buildStrToDate");function Gt(S){return this.func("STR_TO_DATE",[S.args.this,this.formatTime(S)])}s(Gt,"strToDateSql");function ls(S){let a=S.args.scale,t=S.args.this;return a===void 0||a.toValue()===$.SECONDS.toValue()?this.func("FROM_UNIXTIME",[t,this.formatTime(S)]):this.func("FROM_UNIXTIME",[new ue({this:t,expression:je("POW","10",a.toString())}),this.formatTime(S)])}s(ls,"unixToTimeSql");function Ft(S){return function(a){return this.func(`DATE_${S}`,[a.args.this,new ot({this:a.args.expression,unit:Bt(a)})])}}s(Ft,"dateAddSql");function cs(S){return S.args.format?Gt.call(this,S):this.func("DATE",[S.args.this])}s(cs,"tsOrDsToDateSql");function d(S,a=["this"]){return function(t){for(let e of a){let r=t.getArgKey(e);(r instanceof O||r instanceof gt)&&!r.getArgKey("format")&&t.setArgKey(e,r.args.this)}return S?S.call(this,t):this.functionFallbackSql(t)}}s(d,"removeTsOrDsToDate");var fr,dr,xr,Z,f=class f extends(xr=J,dr=[o],fr=[o],xr){constructor(){super(...arguments);this.NESTED_COMMENTS=!1}static get ORIGINAL_KEYWORDS(){return{...J.KEYWORDS,BLOB:"blob",CHARSET:"characterSet",DISTINCTROW:"distinct",EXPLAIN:"describe",FORCE:"force",IGNORE:"ignore",KEY:"key","LOCK TABLES":"command",LONGBLOB:"longblob",LONGTEXT:"longtext",MEDIUMBLOB:"mediumblob",MEDIUMINT:"mediumint",MEDIUMTEXT:"mediumtext","MEMBER OF":"memberOf",MOD:"mod",SEPARATOR:"separator",SERIAL:"serial",SIGNED:"bigint","SIGNED INTEGER":"bigint","SOUNDS LIKE":"soundsLike",START:"begin",TIMESTAMP:"timestamptz",TINYBLOB:"tinyblob",TINYTEXT:"tinytext",TYPE:"type","UNLOCK TABLES":"command",UNSIGNED:"ubigint","UNSIGNED INTEGER":"ubigint",YEAR:"year",_ARMSCII8:"introducer",_ASCII:"introducer",_BIG5:"introducer",_BINARY:"introducer",_CP1250:"introducer",_CP1251:"introducer",_CP1256:"introducer",_CP1257:"introducer",_CP850:"introducer",_CP852:"introducer",_CP866:"introducer",_CP932:"introducer",_DEC8:"introducer",_EUCJPMS:"introducer",_EUCKR:"introducer",_GB18030:"introducer",_GB2312:"introducer",_GBK:"introducer",_GEOSTD8:"introducer",_GREEK:"introducer",_HEBREW:"introducer",_HP8:"introducer",_KEYBCS2:"introducer",_KOI8R:"introducer",_KOI8U:"introducer",_LATIN1:"introducer",_LATIN2:"introducer",_LATIN5:"introducer",_LATIN7:"introducer",_MACCE:"introducer",_MACROMAN:"introducer",_SJIS:"introducer",_SWE7:"introducer",_TIS620:"introducer",_UCS2:"introducer",_UJIS:"introducer",_UTF8:"introducer",_UTF16:"introducer",_UTF16LE:"introducer",_UTF32:"introducer",_UTF8MB3:"introducer",_UTF8MB4:"introducer","@@":"sessionParameter"}}static get COMMANDS(){let t=new Set([...J.COMMANDS,"replace"]);return t.delete("show"),t}};Z=b(xr),E(Z,10,"ORIGINAL_KEYWORDS",dr,f),E(Z,10,"COMMANDS",fr,f),q(Z,f),B(Z,3,f),s(f,"MySQLTokenizer"),f.QUOTES=["'",'"'],f.COMMENTS=["--","#",["/*","*/"]],f.IDENTIFIERS=["`"],f.STRING_ESCAPES=["'",'"',"\\"],f.BIT_STRINGS=[["b'","'"],["B'","'"],["0b",""]],f.HEX_STRINGS=[["x'","'"],["X'","'"],["0x",""]],f.ESCAPE_FOLLOW_CHARS=["0","b","n","r","t","Z","%","_"];var wt=f,Cr,mr,Pr,gr,Dr,Ur,_r,Lr,Mr,br,qr,Br,Fr,Gr,wr,yr,Yr,Vr,Kr,Hr,A,T=class T extends(Hr=I,Kr=[o],Vr=[o],Yr=[o],yr=[o],wr=[o],Gr=[o],Fr=[o],Br=[o],qr=[o],br=[o],Mr=[o],Lr=[o],_r=[o],Ur=[o],Dr=[o],gr=[o],Pr=[o],mr=[o],Cr=[o],Hr){static get ID_VAR_TOKENS(){return new Set([...I.ID_VAR_TOKENS,"currentCatalog"])}static get FUNC_TOKENS(){return new Set([...I.FUNC_TOKENS,"database","mod","schema","values","characterSet"])}static get CONJUNCTION(){return{...I.CONJUNCTION,damp:ke,xor:$e}}static get DISJUNCTION(){return{...I.DISJUNCTION,dpipe:ve}}static get TABLE_ALIAS_TOKENS(){return(()=>{let t=new Set(I.TABLE_ALIAS_TOKENS);for(let e of I.TABLE_INDEX_HINT_TOKENS)t.delete(e);return t})()}static get RANGE_PARSERS(){return{...I.RANGE_PARSERS,soundsLike:function(t){return this.expression(le,{this:this.expression(xt,{this:t}),expression:this.expression(xt,{this:this.parseTerm()})})},memberOf:function(t){return this.expression(Le,{this:t,expression:this.parseWrapped(this.parseExpression.bind(this))})}}}static get FUNCTIONS(){return{...I.FUNCTIONS,BIT_AND:s(t=>_t.fromArgList(t),"BIT_AND"),BIT_OR:s(t=>Lt.fromArgList(t),"BIT_OR"),BIT_XOR:s(t=>Mt.fromArgList(t),"BIT_XOR"),BIT_COUNT:s(t=>Tt.fromArgList(t),"BIT_COUNT"),CONVERT_TZ:s(t=>new Oe({sourceTz:c(t,1),targetTz:c(t,2),timestamp:c(t,0)}),"CONVERT_TZ"),CURDATE:s(t=>St.fromArgList(t),"CURDATE"),CURTIME:s(t=>de.fromArgList(t),"CURTIME"),DATE:s(t=>new O({this:c(t,0)}),"DATE"),DATE_ADD:s(t=>X(H)(t),"DATE_ADD"),DATE_FORMAT:s(t=>new v({this:new gt({this:c(t,0)}),format:W.getOrRaise("mysql")._constructor.formatTime(c(t,1))}),"DATE_FORMAT"),DATE_SUB:s(t=>X(lt)(t),"DATE_SUB"),DAY:s(t=>new Nt({this:new O({this:c(t,0)})}),"DAY"),DAYOFMONTH:s(t=>new It({this:new O({this:c(t,0)})}),"DAYOFMONTH"),DAYOFWEEK:s(t=>new At({this:new O({this:c(t,0)})}),"DAYOFWEEK"),DAYOFYEAR:s(t=>new ht({this:new O({this:c(t,0)})}),"DAYOFYEAR"),FORMAT:s(t=>Pt.fromArgList(t),"FORMAT"),FROM_UNIXTIME:ur($,{dialect:"mysql"}),ISNULL:Rr,LENGTH:s(t=>new ft({this:c(t,0),binary:!0}),"LENGTH"),MAKETIME:s(t=>Ot.fromArgList(t),"MAKETIME"),MONTH:s(t=>new dt({this:new O({this:c(t,0)})}),"MONTH"),MONTHNAME:s(t=>new v({this:new O({this:c(t,0)}),format:new F({this:"%B",isString:!0})}),"MONTHNAME"),SCHEMA:s(t=>ut.fromArgList(t),"SCHEMA"),DATABASE:s(t=>ut.fromArgList(t),"DATABASE"),STR_TO_DATE:us,TIMESTAMPDIFF:bt(k,void 0,{defaultUnit:"DAY"}),TO_DAYS:s(t=>{let e=new ct({this:new O({this:c(t,0)}),expression:new O({this:new F({this:"0000-01-01",isString:!0})}),unit:new P({this:"DAY"})});return new he({this:e.add(1)})},"TO_DAYS"),VERSION:s(t=>pt.fromArgList(t),"VERSION"),WEEK:s(t=>new Dt({this:new O({this:c(t,0)}),mode:c(t,1)}),"WEEK"),WEEKOFYEAR:s(t=>new Rt({this:new O({this:c(t,0)})}),"WEEKOFYEAR"),YEAR:s(t=>new Ut({this:new O({this:c(t,0)})}),"YEAR")}}static get FUNCTION_PARSERS(){return{...I.FUNCTION_PARSERS,GROUP_CONCAT:s(function(){return this.parseGroupConcat()},"GROUP_CONCAT"),VALUES:s(function(){return this.expression(Re,{this:"VALUES",expressions:[this.parseIdVar()]})},"VALUES"),JSON_VALUE:s(function(){return this.parseJsonValue()},"JSON_VALUE"),SUBSTR:s(function(){return this.parseSubstring()},"SUBSTR")}}static get STATEMENT_PARSERS(){return{...I.STATEMENT_PARSERS,show:function(){return this.parseShow()}}}static get PROPERTY_PARSERS(){return{...I.PROPERTY_PARSERS,LOCK:s(function(){return this.parsePropertyAssignment(ne)},"LOCK"),"PARTITION BY":s(function(){return this.parsePartitionProperty()},"PARTITION BY")}}static get SET_PARSERS(){return{...I.SET_PARSERS,PERSIST:s(function(){return this.parseSetItemAssignment({kind:"persist"})},"PERSIST"),PERSIST_ONLY:s(function(){return this.parseSetItemAssignment({kind:"PERSIST_ONLY"})},"PERSIST_ONLY"),"CHARACTER SET":s(function(){return this.parseSetItemCharset("CHARACTER SET")},"CHARACTER SET"),CHARSET:s(function(){return this.parseSetItemCharset("CHARACTER SET")},"CHARSET"),NAMES:s(function(){return this.parseSetItemNames()},"NAMES")}}static get CONSTRAINT_PARSERS(){return{...I.CONSTRAINT_PARSERS,FULLTEXT:s(function(){return this.parseIndexConstraint("FULLTEXT")},"FULLTEXT"),INDEX:s(function(){return this.parseIndexConstraint()},"INDEX"),KEY:s(function(){return this.parseIndexConstraint()},"KEY"),SPATIAL:s(function(){return this.parseIndexConstraint("SPATIAL")},"SPATIAL"),ZEROFILL:s(function(){return this.expression(ee)},"ZEROFILL"),COLUMN_FORMAT:s(function(){return this.parseIdVar(),this.expression(P,{this:"COLUMN_FORMAT"})},"COLUMN_FORMAT"),STORAGE:s(function(){return this.parseIdVar(),this.expression(P,{this:"STORAGE"})},"STORAGE"),INVISIBLE:s(function(){return this.expression(P,{this:"INVISIBLE"})},"INVISIBLE"),VISIBLE:s(function(){return this.expression(P,{this:"VISIBLE"})},"VISIBLE")}}static get ALTER_PARSERS(){return{...I.ALTER_PARSERS,MODIFY:s(function(){return this.parseAlterTableModify()},"MODIFY"),AUTO_INCREMENT:s(function(){return this.parsePropertyAssignment(ie)},"AUTO_INCREMENT"),COMMENT:s(function(){return this.parsePropertyAssignment(Ee)},"COMMENT")}}static get ALTER_ALTER_PARSERS(){return{...I.ALTER_ALTER_PARSERS,INDEX:s(function(){return this.parseAlterTableAlterIndex()},"INDEX")}}static get SCHEMA_UNNAMED_CONSTRAINTS(){return new Set([...I.SCHEMA_UNNAMED_CONSTRAINTS,"FULLTEXT","INDEX","KEY","SPATIAL"])}static get PROFILE_TYPES(){return{ALL:[],CPU:[],IPC:[],MEMORY:[],SOURCE:[],SWAPS:[],BLOCK:["IO"],CONTEXT:["SWITCHES"],PAGE:["FAULTS"]}}static get TYPE_TOKENS(){return new Set([...I.TYPE_TOKENS,"set"])}static get ENUM_TYPE_TOKENS(){return new Set([...I.ENUM_TYPE_TOKENS,"set"])}static get OPERATION_MODIFIERS(){return new Set(["HIGH_PRIORITY","STRAIGHT_JOIN","SQL_SMALL_RESULT","SQL_BIG_RESULT","SQL_BUFFER_RESULT","SQL_NO_CACHE","SQL_CALC_FOUND_ROWS"])}parseGeneratedAsIdentity(){let t=super.parseGeneratedAsIdentity();if(this.matchTexts(["STORED","VIRTUAL"])){let e=this.prev?.text.toUpperCase()==="STORED";t instanceof Et?t.setArgKey("persisted",e):t instanceof re&&(t=this.expression(Et,{this:t.args.expression,persisted:e}))}return t}parsePrimaryKeyPart(){let t=this.parseIdVar();if(!this.match("lParen"))return t;let e=this.parseNumber();return this.matchRParen(),this.expression(Xt,{this:t,expression:e})}parseUnique(){this.matchTexts(["KEY","INDEX"]);let t=this.parseUniqueKey(),e=(this.match("using")||void 0)&&this.advanceAny()&&this.prev?.text;if(!this.match("lParen",{advance:!1}))return this.expression(at,{this:t,indexType:e});let r=this.parseWrappedCsv(this.parseOrdered.bind(this));return this.expression(at,{this:this.expression(jt,{this:t,expressions:r}),indexType:e||(this.match("using")||void 0)&&this.advanceAny()&&this.prev?.text,options:this.parseKeyConstraintOptions()})}parseIndexConstraint(t){t&&this.matchTexts(["INDEX","KEY"]);let e=this.parseIdVar({anyToken:!1}),r=this.match("using")&&this.advanceAny()&&this.prev?.text,u=this.parseWrappedCsv(this.parseOrdered.bind(this)),p=[];for(;;){let R;if(this.matchTextSeq(["KEY_BLOCK_SIZE"])?(this.match("eq"),R=new C({keyBlockSize:this.parseNumber()})):this.match("using")?R=new C({using:this.advanceAny()&&this.prev?.text}):this.matchTextSeq(["WITH","PARSER"])?R=new C({parser:this.parseVar({anyToken:!0})}):this.match("comment")?R=new C({comment:this.parseString()}):this.matchTextSeq(["VISIBLE"])?R=new C({visible:!0}):this.matchTextSeq(["INVISIBLE"])?R=new C({visible:!1}):this.matchTextSeq(["ENGINE_ATTRIBUTE"])?(this.match("eq"),R=new C({engineAttr:this.parseString()})):this.matchTextSeq(["SECONDARY_ENGINE_ATTRIBUTE"])&&(this.match("eq"),R=new C({secondaryEngineAttr:this.parseString()})),!R)break;p.push(R)}return this.expression(se,{this:e,expressions:u,kind:t,indexType:r,options:p})}parseShowMysql(t,e={}){let{target:r=!1,full:u,global:p}=e,R=this.matchTextSeq(["JSON"]),x;r&&(typeof r=="string"&&this.matchTextSeq(r.split(" ")),x=this.parseIdVar());let j=this.matchTextSeq(["IN"])?this.parseString():void 0,m,U;t==="BINLOG EVENTS"||t==="RELAYLOG EVENTS"?m=this.matchTextSeq(["FROM"])?this.parseNumber():void 0:this.match("from")?U=this.parseIdVar():this.match("dot")&&(U=x,x=this.parseIdVar());let w=this.matchTextSeq(["FOR","CHANNEL"])?this.parseIdVar():void 0,_=this.matchTextSeq(["LIKE"])?this.parseString():void 0,z=this.parseWhere(),y,Y,g,L;t==="PROFILE"?(y=this.parseCsv(()=>this.parseVarFromOptions(T.PROFILE_TYPES)),Y=this.matchTextSeq(["FOR","QUERY"])?this.parseNumber():void 0,g=this.matchTextSeq(["OFFSET"])?this.parseNumber():void 0,L=this.matchTextSeq(["LIMIT"])?this.parseNumber():void 0):[g,L]=this.parseOldstyleLimit();let M;this.matchTextSeq(["MUTEX"])&&(M=!0),this.matchTextSeq(["STATUS"])&&(M=!1);let Q=this.matchTextSeq(["FOR","TABLE"])?this.parseIdVar():void 0,tt=this.matchTextSeq(["FOR","GROUP"])?this.parseString():void 0,et=this.matchTextSeq(["FOR","USER"])?this.parseString():void 0,rt=this.matchTextSeq(["FOR","ROLE"])?this.parseString():void 0,os=this.matchTextSeq(["INTO","OUTFILE"])?this.parseString():void 0;return this.expression(kt,{this:t,target:x,full:u,log:j,position:m,db:U,channel:w,like:_,where:z,types:y,query:Y,offset:g,limit:L,mutex:M,forTable:Q,forGroup:tt,forUser:et,forRole:rt,intoOutfile:os,json:R,global:p})}parseOldstyleLimit(){let t,e;if(this.matchTextSeq(["LIMIT"])){let r=this.parseCsv(this.parseNumber.bind(this));r.length===1?t=r[0]:r.length===2&&(t=r[1],e=r[0])}return[e,t]}parseSetItemCharset(t){let e=this.parseString()||this.parseUnquotedField();return this.expression(st,{this:e,kind:t})}parseSetItemNames(){let t=this.parseString()||this.parseUnquotedField(),e;return this.matchTextSeq(["COLLATE"])&&(e=this.parseString()||this.parseUnquotedField()),this.expression(st,{this:t,collate:e,kind:"NAMES"})}parseType(t={}){let{parseInterval:e=!0,fallbackToIdentifier:r=!1}=t;if(this.match("binary",{advance:!1})){let u=this.parseTypes({checkFunc:!0,allowIdentifiers:!1});if(u instanceof nt)return this.expression(Ne,{this:this.parseColumn(),to:u})}return super.parseType({parseInterval:e,fallbackToIdentifier:r})}parseAlterTableAlterIndex(){let t=this.parseField({anyToken:!0}),e;return this.matchTextSeq(["VISIBLE"])?e=!0:this.matchTextSeq(["INVISIBLE"])&&(e=!1),this.expression(Wt,{this:t,visible:e})}parseAlterTableModify(){this.match("column");let t=this.parseField({anyToken:!0});if(!t)return;let e=this.parseColumnDef(t);if(e instanceof vt)return this.expression($t,{this:e})}parsePartitionProperty(){let t,e;if(this.matchTextSeq(["RANGE"])?(t=V,e=this.parsePartitionRangeValue.bind(this)):this.matchTextSeq(["LIST"])&&(t=K,e=this.parsePartitionListValue.bind(this)),!t||!e)return;let r=this.parseWrappedCsv(this.parseAssignment.bind(this));if(!this.matchTextSeq(["(","PARTITION"],{advance:!1}))return r;let u=this.parseWrappedCsv(e);return this.expression(t,{partitionExpressions:r,createExpressions:u})}parsePartitionRangeValue(){this.matchTextSeq(["PARTITION"]);let t=this.parseIdVar();if(!this.matchTextSeq(["VALUES","LESS","THAN"]))return t;let e=this.parseWrappedCsv(this.parseExpression.bind(this));e.length===1&&e[0]instanceof te&&e[0].name.toUpperCase()==="MAXVALUE"&&(e=[new P({this:"MAXVALUE"})]);let r=this.expression(Jt,{this:t,expressions:e});return this.expression(it,{expressions:[r]})}parsePartitionListValue(){this.matchTextSeq(["PARTITION"]);let t=this.parseIdVar();this.matchTextSeq(["VALUES","IN"]);let e=this.parseWrappedCsv(this.parseExpression.bind(this)),r=this.expression(Zt,{this:t,expressions:e});return this.expression(it,{expressions:[r]})}parsePrimaryKey(t={}){let{wrappedOptional:e=!1,inProps:r=!1}=t;return super.parsePrimaryKey({wrappedOptional:e,inProps:r,namedPrimaryKey:!0})}};A=b(Hr),E(A,10,"ID_VAR_TOKENS",Kr,T),E(A,10,"FUNC_TOKENS",Vr,T),E(A,10,"CONJUNCTION",Yr,T),E(A,10,"DISJUNCTION",yr,T),E(A,10,"TABLE_ALIAS_TOKENS",wr,T),E(A,10,"RANGE_PARSERS",Gr,T),E(A,10,"FUNCTIONS",Fr,T),E(A,10,"FUNCTION_PARSERS",Br,T),E(A,10,"STATEMENT_PARSERS",qr,T),E(A,10,"PROPERTY_PARSERS",br,T),E(A,10,"SET_PARSERS",Mr,T),E(A,10,"CONSTRAINT_PARSERS",Lr,T),E(A,10,"ALTER_PARSERS",_r,T),E(A,10,"ALTER_ALTER_PARSERS",Ur,T),E(A,10,"SCHEMA_UNNAMED_CONSTRAINTS",Dr,T),E(A,10,"PROFILE_TYPES",gr,T),E(A,10,"TYPE_TOKENS",Pr,T),E(A,10,"ENUM_TYPE_TOKENS",mr,T),E(A,10,"OPERATION_MODIFIERS",Cr,T),q(A,T),B(A,3,T),s(T,"MySQLParser"),T.SHOW_PARSERS={"BINARY LOGS":i("BINARY LOGS"),"MASTER LOGS":i("BINARY LOGS"),"BINLOG EVENTS":i("BINLOG EVENTS"),"CHARACTER SET":i("CHARACTER SET"),CHARSET:i("CHARACTER SET"),COLLATION:i("COLLATION"),"FULL COLUMNS":i("COLUMNS",{target:"FROM",full:!0}),COLUMNS:i("COLUMNS",{target:"FROM"}),"CREATE DATABASE":i("CREATE DATABASE",{target:!0}),"CREATE EVENT":i("CREATE EVENT",{target:!0}),"CREATE FUNCTION":i("CREATE FUNCTION",{target:!0}),"CREATE PROCEDURE":i("CREATE PROCEDURE",{target:!0}),"CREATE TABLE":i("CREATE TABLE",{target:!0}),"CREATE TRIGGER":i("CREATE TRIGGER",{target:!0}),"CREATE VIEW":i("CREATE VIEW",{target:!0}),DATABASES:i("DATABASES"),SCHEMAS:i("DATABASES"),ENGINE:i("ENGINE",{target:!0}),"STORAGE ENGINES":i("ENGINES"),ENGINES:i("ENGINES"),ERRORS:i("ERRORS"),EVENTS:i("EVENTS"),"FUNCTION CODE":i("FUNCTION CODE",{target:!0}),"FUNCTION STATUS":i("FUNCTION STATUS"),GRANTS:i("GRANTS",{target:"FOR"}),INDEX:i("INDEX",{target:"FROM"}),"MASTER STATUS":i("MASTER STATUS"),"OPEN TABLES":i("OPEN TABLES"),PLUGINS:i("PLUGINS"),"PROCEDURE CODE":i("PROCEDURE CODE",{target:!0}),"PROCEDURE STATUS":i("PROCEDURE STATUS"),PRIVILEGES:i("PRIVILEGES"),"FULL PROCESSLIST":i("PROCESSLIST",{full:!0}),PROCESSLIST:i("PROCESSLIST"),PROFILE:i("PROFILE"),PROFILES:i("PROFILES"),"RELAYLOG EVENTS":i("RELAYLOG EVENTS"),REPLICAS:i("REPLICAS"),"SLAVE HOSTS":i("REPLICAS"),"REPLICA STATUS":i("REPLICA STATUS"),"SLAVE STATUS":i("REPLICA STATUS"),"GLOBAL STATUS":i("STATUS",{global:!0}),"SESSION STATUS":i("STATUS"),STATUS:i("STATUS"),"TABLE STATUS":i("TABLE STATUS"),"FULL TABLES":i("TABLES",{full:!0}),TABLES:i("TABLES"),TRIGGERS:i("TRIGGERS"),"GLOBAL VARIABLES":i("VARIABLES",{global:!0}),"SESSION VARIABLES":i("VARIABLES"),VARIABLES:i("VARIABLES"),WARNINGS:i("WARNINGS")},T.LOG_DEFAULTS_TO_LN=!0,T.STRING_ALIASES=!0,T.VALUES_FOLLOWED_BY_PAREN=!1,T.SUPPORTS_PARTITION_SELECTION=!0;var yt=T,kr,vr,$r,Wr,Xr,Jr,Zr,jr,zr,Qr,ts,es,rs,N,n=class n extends(rs=G,es=[o],ts=[o],Qr=[o],zr=[o],jr=[o],Zr=[o],Jr=[o],Xr=[o],Wr=[o],$r=[o],vr=[o],kr=[o],rs){static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let t=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(e=>t.delete(e)),t}static get NULL_ORDERING_SUPPORTED(){return"unsupported"}static get ORIGINAL_TRANSFORMS(){return new Map([...G.TRANSFORMS,[Ve,h("GROUP_CONCAT")],[_t,h("BIT_AND")],[Lt,h("BIT_OR")],[Mt,h("BIT_XOR")],[Tt,h("BIT_COUNT")],[fe,function(t){return this.chrSql(t,{name:"CHAR"})}],[St,Er],[pt,h("VERSION")],[ct,d(function(t){return this.func("DATEDIFF",[t.args.this,t.args.expression])},["this","expression"])],[H,d(Ft("ADD"))],[Ue,cr],[lt,d(Ft("SUB"))],[Pe,Ts],[Nt,d()],[It,d(h("DAYOFMONTH"))],[At,d(h("DAYOFWEEK"))],[ht,d(h("DAYOFYEAR"))],[He,function(t){return`GROUP_CONCAT(${this.sql(t,"this")} SEPARATOR ${this.sql(t,"separator")||"','"})`}],[Ie,ar],[_e,nr],[ft,Or],[We,h("MAX")],[Xe,h("MIN")],[Je,Ir],[Ze,Ar],[dt,d()],[ce,function(t){return this.binary(t,"<=>")}],[Ae,function(t){return`NOT ${this.binary(t,"<=>")}`}],[Pt,h("FORMAT")],[Qt,Tr],[Se,ze([tr,rr,er,sr,Qe])],[be,function(t){return Sr.call(this,t,{funcName:"LOCATE",supportsPosition:!0})}],[Ct,Gt],[mt,Gt],[qe,h("INSERT")],[xe,()=>"SESSION_USER()"],[zt,or],[Ot,h("MAKETIME")],[ge,qt("DATE","ADD")],[k,function(t){return this.func("TIMESTAMPDIFF",[Bt(t),t.args.expression,t.args.this])}],[De,qt("DATE","SUB")],[Fe,h("UNIX_TIMESTAMP")],[Be,function(t){return lr.call(this,t,{includePrecision:!t.args.zone})}],[v,d(function(t){return this.func("DATE_FORMAT",[t.args.this,this.formatTime(t)])})],[Ge,hr],[Me,h("TRUNCATE")],[Ke,pr],[we,Ft("ADD")],[ye,function(t){return this.func("DATEDIFF",[t.args.this,t.args.expression])}],[O,cs],[Ye,function(t){return`ORD(CONVERT(${this.sql(t.args.this)} USING utf32))`}],[$,ls],[Dt,d()],[Rt,d(h("WEEKOFYEAR"))],[Ut,d()],[me,h("UTC_TIMESTAMP")],[Ce,h("UTC_TIME")]])}static get UNSIGNED_TYPE_MAPPING(){return new Map([["ubigint","BIGINT"],["uint","INT"],["umediumint","MEDIUMINT"],["usmallint","SMALLINT"],["utinyint","TINYINT"],["udecimal","DECIMAL"],["udouble","DOUBLE"]])}static get TIMESTAMP_TYPE_MAPPING(){return new Map([["datetime2","DATETIME"],["smalldatetime","DATETIME"],["timestamp","DATETIME"],["timestampntz","DATETIME"],["timestamptz","TIMESTAMP"],["timestampltz","TIMESTAMP"]])}static get TYPE_MAPPING(){let t=new Map(G.TYPE_MAPPING);for(let[e,r]of n.UNSIGNED_TYPE_MAPPING)t.set(e,r);for(let[e,r]of n.TIMESTAMP_TYPE_MAPPING)t.set(e,r);return t.delete("mediumtext"),t.delete("longtext"),t.delete("tinytext"),t.delete("blob"),t.delete("mediumblob"),t.delete("longblob"),t.delete("tinyblob"),t}static get PROPERTIES_LOCATION(){let t=new Map(G.PROPERTIES_LOCATION);return t.set(Te,"unsupported"),t.set(pe,"unsupported"),t.set(ae,"unsupported"),t.set(V,"postSchema"),t.set(K,"postSchema"),t}static get CHAR_CAST_MAPPING(){return["longtext","longblob","mediumblob","mediumtext","text","tinyblob","tinytext","varchar"].reduce((t,e)=>({...t,[e]:"CHAR"}),{})}static get SIGNED_CAST_MAPPING(){return["bigint","boolean","int","smallint","tinyint","mediumint"].reduce((t,e)=>({...t,[e]:"SIGNED"}),{})}static get CAST_MAPPING(){return{...n.CHAR_CAST_MAPPING,...n.SIGNED_CAST_MAPPING,ubigint:"UNSIGNED"}}static get TIMESTAMP_FUNC_TYPES(){return new Set(["timestamptz","timestampltz"])}static get RESERVED_KEYWORDS(){return new Set(["accessible","add","all","alter","analyze","and","as","asc","asensitive","before","between","bigint","binary","blob","both","by","call","cascade","case","change","char","character","check","collate","column","condition","constraint","continue","convert","create","cross","cube","cume_dist","current_date","current_time","current_timestamp","current_user","cursor","database","databases","day_hour","day_microsecond","day_minute","day_second","dec","decimal","declare","default","delayed","delete","dense_rank","desc","describe","deterministic","distinct","distinctrow","div","double","drop","dual","each","else","elseif","empty","enclosed","escaped","except","exists","exit","explain","false","fetch","first_value","float","float4","float8","for","force","foreign","from","fulltext","function","generated","get","grant","group","grouping","groups","having","high_priority","hour_microsecond","hour_minute","hour_second","if","ignore","in","index","infile","inner","inout","insensitive","insert","int","int1","int2","int3","int4","int8","integer","intersect","interval","into","io_after_gtids","io_before_gtids","is","iterate","join","json_table","key","keys","kill","lag","last_value","lateral","lead","leading","leave","left","like","limit","linear","lines","load","localtime","localtimestamp","lock","long","longblob","longtext","loop","low_priority","master_bind","master_ssl_verify_server_cert","match","maxvalue","mediumblob","mediumint","mediumtext","middleint","minute_microsecond","minute_second","mod","modifies","natural","not","no_write_to_binlog","nth_value","ntile","undefined","numeric","of","on","optimize","optimizer_costs","option","optionally","or","order","out","outer","outfile","over","partition","percent_rank","precision","primary","procedure","purge","range","rank","read","reads","read_write","real","recursive","references","regexp","release","rename","repeat","replace","require","resignal","restrict","return","revoke","right","rlike","row","rows","row_number","schema","schemas","second_microsecond","select","sensitive","separator","set","show","signal","smallint","spatial","specific","sql","sqlexception","sqlstate","sqlwarning","sql_big_result","sql_calc_found_rows","sql_small_result","ssl","starting","stored","straight_join","system","table","terminated","then","tinyblob","tinyint","tinytext","to","trailing","trigger","true","undo","union","unique","unlock","unsigned","update","usage","use","using","utc_date","utc_time","utc_timestamp","values","varbinary","varchar","varcharacter","varying","virtual","when","where","while","window","with","write","xor","year_month","zerofill"])}locateProperties(t){let e=super.locateProperties(t),r=t.parent;if(r instanceof Ht&&r.args.kind?.toUpperCase()==="VIEW"){let u=e.get("postSchema");if(u){for(let p=0;p<u.length;p++)if(u[p]instanceof oe){let[R]=u.splice(p,1),x=this._constructor.SQL_SECURITY_VIEW_LOCATION;e.has(x)||e.set(x,[]),e.get(x).push(R);break}}}return e}computedColumnConstraintSql(t){let e=t.args.persisted?"STORED":"VIRTUAL";return`GENERATED ALWAYS AS (${this.sql(t.args.this?.unnest())}) ${e}`}arraySql(t){return this.unsupported("Arrays are not supported by MySQL"),this.functionFallbackSql(t)}arrayContainsAllSql(t){return this.unsupported("Array operations are not supported by MySQL"),this.functionFallbackSql(t)}dPipeSql(t){return this.func("CONCAT",[...t.flatten()])}extractSql(t){let e=t.name;return e&&e.toLowerCase()==="epoch"?this.func("UNIX_TIMESTAMP",[t.args.expression]):super.extractSql(t)}dataTypeSql(t){if(this.constructor.VARCHAR_REQUIRES_SIZE&&t.isType("varchar")&&!t.args.expressions?.length)return"TEXT";let e=super.dataTypeSql(t);return n.UNSIGNED_TYPE_MAPPING.has(t.args.this)&&(e=`${e} UNSIGNED`),e}jsonArrayContainsSql(t){return`${this.sql(t,"this")} MEMBER OF(${this.sql(t,"expression")})`}castSql(t,e={}){let r=t.args.to;if(r instanceof nt){let u=r.args.this;if(this._constructor.TIMESTAMP_FUNC_TYPES.has(u))return this.func("TIMESTAMP",[t.args.this]);let p=this._constructor.CAST_MAPPING[u];p&&r.setArgKey("this",p)}return super.castSql(t)}showSql(t){let e=` ${t.name}`,r=t.args.full?" FULL":"",u=t.args.global?" GLOBAL":"",p=this.sql(t,"target");p=p?` ${p}`:"",["COLUMNS","INDEX"].includes(t.name)?p=` FROM${p}`:t.name==="GRANTS"?p=` FOR${p}`:["LINKS","PARTITIONS"].includes(t.name)?p=p?` ON${p}`:"":t.name==="PROJECTIONS"&&(p=p?` ON TABLE${p}`:"");let R=this.prefixedSql("FROM",t,"db"),x=this.prefixedSql("LIKE",t,"like"),j=this.sql(t,"where"),m=this.expressions(t,{key:"types"});m=m&&` ${m}`;let U=this.prefixedSql("FOR QUERY",t,"query"),w="",_="";t.name==="PROFILE"?(w=this.prefixedSql("OFFSET",t,"offset"),_=this.prefixedSql("LIMIT",t,"limit")):_=this.oldStyleLimitSql(t);let z=this.prefixedSql("IN",t,"log"),y=this.prefixedSql("FROM",t,"position"),Y=this.prefixedSql("FOR CHANNEL",t,"channel"),g="";t.name==="ENGINE"&&(g=t.args.mutex?" MUTEX":" STATUS");let L=this.prefixedSql("FOR TABLE",t,"forTable"),M=this.prefixedSql("FOR GROUP",t,"forGroup"),Q=this.prefixedSql("FOR USER",t,"forUser"),tt=this.prefixedSql("FOR ROLE",t,"forRole"),et=this.prefixedSql("INTO OUTFILE",t,"intoOutfile"),rt=t.args.json?" JSON":"";return`SHOW${r}${u}${e}${rt}${p}${L}${m}${R}${U}${z}${y}${Y}${g}${x}${j}${w}${_}${M}${Q}${tt}${et}`}alterRenameSql(t,e={}){return super.alterRenameSql(t,{includeTo:!1})}alterColumnSql(t){let e=this.sql(t,"dtype");return e?`MODIFY COLUMN ${this.sql(t,"this")} ${e}`:super.alterColumnSql(t)}prefixedSql(t,e,r){let u=this.sql(e,r);return u?` ${t} ${u}`:""}oldStyleLimitSql(t){let e=this.sql(t,"limit"),r=this.sql(t,"offset");return e?` LIMIT ${r?`${r}, ${e}`:e}`:""}timestampTruncSql(t){let e=t.args.unit,r="0000-01-01 00:00:00",u=bt(k)([e,new F({this:r,isString:!0}),t.args.this]),p=new ot({this:u,unit:e}),R=X(H)([new F({this:r,isString:!0}),p]);return this.sql(R)}convertTimezoneSql(t){let e=t.args.sourceTz,r=t.args.targetTz,u=t.args.timestamp;return this.func("CONVERT_TZ",[u,e,r])}atTimeZoneSql(t){return this.unsupported("AT TIME ZONE is not supported by MySQL"),this.sql(t.args.this)}isAsciiSql(t){return`REGEXP_LIKE(${this.sql(t.args.this)}, '^[[:ascii:]]*$')`}ignoreNullsSql(t){return this.unsupported("MySQL does not support IGNORE NULLS."),this.sql(t.args.this)}currentSchemaSql(t){return ir.call(this,t,"this"),this.func("SCHEMA",[])}partitionSql(t){let e=t.parent;return e instanceof V||e instanceof K?this.expressions(t,{flat:!0}):super.partitionSql(t)}partitionByRangeOrListSql(t,e){let r=this.expressions(t,{key:"partitionExpressions",flat:!0}),u=this.expressions(t,{key:"createExpressions",flat:!0});return`PARTITION BY ${e} (${r}) (${u})`}partitionByRangePropertySql(t){return this.partitionByRangeOrListSql(t,"RANGE")}partitionByListPropertySql(t){return this.partitionByRangeOrListSql(t,"LIST")}partitionListSql(t){let e=this.sql(t,"this"),r=this.expressions(t,{flat:!0});return`PARTITION ${e} VALUES IN (${r})`}partitionRangeSql(t){let e=this.sql(t,"this"),r=this.expressions(t,{flat:!0});return`PARTITION ${e} VALUES LESS THAN (${r})`}};N=b(rs),E(N,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",es,n),E(N,10,"NULL_ORDERING_SUPPORTED",ts,n),E(N,10,"ORIGINAL_TRANSFORMS",Qr,n),E(N,10,"UNSIGNED_TYPE_MAPPING",zr,n),E(N,10,"TIMESTAMP_TYPE_MAPPING",jr,n),E(N,10,"TYPE_MAPPING",Zr,n),E(N,10,"PROPERTIES_LOCATION",Jr,n),E(N,10,"CHAR_CAST_MAPPING",Xr,n),E(N,10,"SIGNED_CAST_MAPPING",Wr,n),E(N,10,"CAST_MAPPING",$r,n),E(N,10,"TIMESTAMP_FUNC_TYPES",vr,n),E(N,10,"RESERVED_KEYWORDS",kr,n),q(N,n),B(N,3,n),s(n,"MySQLGenerator"),n.SUPPORTS_DECODE_CASE=!1,n.SELECT_KINDS=[],n.TRY_SUPPORTED=!1,n.SUPPORTS_UESCAPE=!1,n.INTERVAL_ALLOWS_PLURAL_FORM=!1,n.LOCKING_READS_SUPPORTED=!0,n.SUPPORTS_MODIFY_COLUMN=!0,n.JOIN_HINTS=!1,n.TABLE_HINTS=!0,n.DUPLICATE_KEY_UPDATE_WITH_SET=!1,n.QUERY_HINT_SEP=" ",n.VALUES_AS_TABLE=!1,n.NVL2_SUPPORTED=!1,n.LAST_DAY_SUPPORTS_DATE_PART=!1,n.JSON_TYPE_REQUIRED_FOR_EXTRACTION=!0,n.JSON_PATH_BRACKETED_KEY_SUPPORTED=!1,n.JSON_KEY_VALUE_PAIR_SEP=",",n.SUPPORTS_TO_NUMBER=!1,n.PARSE_JSON_NAME=void 0,n.PAD_FILL_PATTERN_IS_REQUIRED=!0,n.WRAP_DERIVED_VALUES=!1,n.VARCHAR_REQUIRES_SIZE=!0,n.SUPPORTS_MEDIAN=!1,n.UPDATE_STATEMENT_SUPPORTS_FROM=!1,n.SUPPORTS_CONVERT_TIMEZONE=!0,n.SQL_SECURITY_VIEW_LOCATION="postCreate",n.LIMIT_FETCH="LIMIT",n.LIMIT_ONLY_LITERALS=!0;var Yt=n,ss,is,ns,as,Es,D,l=class l extends(Es=W,as=[o],ns=[o],is=[o],ss=[o],Es){static get NORMALIZATION_STRATEGY(){return"caseSensitive"}static get EXPRESSION_METADATA(){return new Map(Nr.EXPRESSION_METADATA)}static get TIME_MAPPING(){return{"%M":"%B","%c":"%-m","%e":"%-d","%h":"%I","%i":"%M","%s":"%S","%u":"%W","%k":"%-H","%l":"%-I","%T":"%H:%M:%S","%W":"%A"}}static get VALID_INTERVAL_UNITS(){return new Set([...W.VALID_INTERVAL_UNITS,"SECOND_MICROSECOND","MINUTE_MICROSECOND","MINUTE_SECOND","HOUR_MICROSECOND","HOUR_SECOND","HOUR_MINUTE","DAY_MICROSECOND","DAY_SECOND","DAY_MINUTE","DAY_HOUR","YEAR_MONTH"])}};D=b(Es),E(D,10,"NORMALIZATION_STRATEGY",as,l),E(D,10,"EXPRESSION_METADATA",ns,l),E(D,10,"TIME_MAPPING",is,l),E(D,10,"VALID_INTERVAL_UNITS",ss,l),q(D,l),B(D,3,l),s(l,"MySQL"),l.DIALECT_NAME="mysql",l.PROMOTE_TO_INFERRED_DATETIME_TYPE=!0,l.IDENTIFIERS_CAN_START_WITH_DIGIT=!0,l.TIME_FORMAT="'%Y-%m-%d %T'",l.DPIPE_IS_STRING_CONCAT=!1,l.SUPPORTS_USER_DEFINED_TYPES=!1,l.SUPPORTS_SEMI_ANTI_JOIN=!1,l.SAFE_DIVISION=!0,l.SAFE_TO_ELIMINATE_DOUBLE_NEGATION=!1,l.LEAST_GREATEST_IGNORES_NULLS=!1,l.Tokenizer=wt,l.Parser=yt,l.Generator=Yt;var Vt=l;export{i as a,Ts as b,ps as c,us as d,Gt as e,ls as f,Ft as g,cs as h,d as i,Vt as j};
2
+ //# sourceMappingURL=chunk-6KLCCQGX.js.map
@@ -1,2 +1,2 @@
1
- import{a as U}from"./chunk-P6YCSUUX.js";import{Gl as N,Gr as w,No as x,Qe as R,Zp as I,a as n,al as M,b as T,bu as C,c as f,d as y,e as l,fr as K,fs as B,jk as h,jm as g,o as c,pe as D,qq as P,r as d,s as u,xb as m,xp as O}from"./chunk-NNPDC7K7.js";function X(E,r,a){let e=[];for(let i of r){let s=E.args[i];if(s){let F=Array.isArray(s)?s:[s];e.push(...d(F,m))}}let t,p=!1;for(let i of e)if(i.isType("unknown"))p=!0;else if(i.isType(a)){p=!1,t=a;break}else{let s=i.type;t=c(s,D)?s:void 0}return this.setType(E,p?"unknown":t),E}n(X,"annotateBySimilarArgs");var H,A;H=[u];var o=class o{static get EXPRESSION_METADATA(){let r=new Map(U.EXPRESSION_METADATA),a=n((e,t)=>{for(let p of e)r.set(p,t)},"extend");return a([h,P],{returns:"double"}),a([x,O],{returns:"varchar"}),r.set(I,{returns:"date"}),r.set(w,{returns:"date"}),r.set(C,{annotator:n((e,t)=>e.annotateByArgs(t,["this"],{array:t.args.quantile?.isType?.("array")??!1}),"annotator")}),r.set(R,{returns:"timestamp"}),r.set(g,{annotator:n((e,t)=>X.call(e,t,["expressions"],"text"),"annotator")}),r.set(x,{returns:"varchar"}),r.set(B,{returns:"date"}),r.set(M,{annotator:n((e,t)=>X.call(e,t,["this","fillPattern"],"text"),"annotator")}),a([N,K],{annotator:n((e,t)=>e.annotateByArgs(t,["this"]),"annotator")}),r}};A=T(null),l(A,10,"EXPRESSION_METADATA",H,o),f(A,o),y(A,3,o),n(o,"Spark2Typing");var b=o;export{b as a};
2
- //# sourceMappingURL=chunk-SR5T64DP.js.map
1
+ import{a as U}from"./chunk-3L4IL5ZG.js";import{Gl as N,Gr as w,No as x,Qe as R,Zp as I,a as n,al as M,b as T,bu as C,c as f,d as y,e as l,fr as K,fs as B,jk as h,jm as g,o as c,pe as D,qq as P,r as d,s as u,xb as m,xp as O}from"./chunk-5TO2OPOM.js";function X(E,r,a){let e=[];for(let i of r){let s=E.args[i];if(s){let F=Array.isArray(s)?s:[s];e.push(...d(F,m))}}let t,p=!1;for(let i of e)if(i.isType("unknown"))p=!0;else if(i.isType(a)){p=!1,t=a;break}else{let s=i.type;t=c(s,D)?s:void 0}return this.setType(E,p?"unknown":t),E}n(X,"annotateBySimilarArgs");var H,A;H=[u];var o=class o{static get EXPRESSION_METADATA(){let r=new Map(U.EXPRESSION_METADATA),a=n((e,t)=>{for(let p of e)r.set(p,t)},"extend");return a([h,P],{returns:"double"}),a([x,O],{returns:"varchar"}),r.set(I,{returns:"date"}),r.set(w,{returns:"date"}),r.set(C,{annotator:n((e,t)=>e.annotateByArgs(t,["this"],{array:t.args.quantile?.isType?.("array")??!1}),"annotator")}),r.set(R,{returns:"timestamp"}),r.set(g,{annotator:n((e,t)=>X.call(e,t,["expressions"],"text"),"annotator")}),r.set(x,{returns:"varchar"}),r.set(B,{returns:"date"}),r.set(M,{annotator:n((e,t)=>X.call(e,t,["this","fillPattern"],"text"),"annotator")}),a([N,K],{annotator:n((e,t)=>e.annotateByArgs(t,["this"]),"annotator")}),r}};A=T(null),l(A,10,"EXPRESSION_METADATA",H,o),f(A,o),y(A,3,o),n(o,"Spark2Typing");var b=o;export{b as a};
2
+ //# sourceMappingURL=chunk-7D3RXRLA.js.map
@@ -1,2 +1,2 @@
1
- import{Ao as d,Dm as c,Gm as A,Mv as l,Xp as u,a as e,b as p,c as n,d as E,e as a,es as D,jk as i,s as x,xm as m,xn as f}from"./chunk-NNPDC7K7.js";var T,o;T=[x];var r=class r{static get EXPRESSION_METADATA(){let s=new Map(l.EXPRESSION_METADATA),t=e((I,C)=>{for(let M of I)s.set(M,C)},"extend");return t([i],{returns:"double"}),t([A,c],{returns:"datetime"}),t([m,f],{returns:"varchar"}),t([u,d,D],{returns:"int"}),s}};o=p(null),a(o,10,"EXPRESSION_METADATA",T,r),n(o,r),E(o,3,r),e(r,"MySQLTyping");var R=r;export{R as a};
2
- //# sourceMappingURL=chunk-MBDFVUXG.js.map
1
+ import{Ao as d,Dm as c,Gm as A,Mv as l,Xp as u,a as e,b as p,c as n,d as E,e as a,es as D,jk as i,s as x,xm as m,xn as f}from"./chunk-5TO2OPOM.js";var T,o;T=[x];var r=class r{static get EXPRESSION_METADATA(){let s=new Map(l.EXPRESSION_METADATA),t=e((I,C)=>{for(let M of I)s.set(M,C)},"extend");return t([i],{returns:"double"}),t([A,c],{returns:"datetime"}),t([m,f],{returns:"varchar"}),t([u,d,D],{returns:"int"}),s}};o=p(null),a(o,10,"EXPRESSION_METADATA",T,r),n(o,r),E(o,3,r),e(r,"MySQLTyping");var R=r;export{R as a};
2
+ //# sourceMappingURL=chunk-7P5S7LVR.js.map
@@ -1,4 +1,4 @@
1
- import{$a as gs,Ai as ne,Bb as Ae,Bd as Xe,Bj as ws,Cd as hs,Ci as w,Di as P,Ef as es,Ei as le,Fa as H,Fu as qs,Ga as q,Gb as Es,Gu as Rs,Ha as D,Ia as V,Ja as Qe,Kf as O,La as re,Lf as As,Ma as Ge,Me as Z,Mi as ee,Na as He,Ni as Cs,Ns as vs,Nv as $,Oa as ms,Od as se,Oe as Ss,Ou as Je,Pa as de,Pu as B,Qa as Re,Ra as ds,Rj as Ns,Sa as L,Ta as Ye,Te as ys,Ti as ge,Ui as M,Va as be,Wc as z,Xa as _e,Xc as ae,Xu as oe,Zj as Ne,_c as Q,_n as Ue,a as h,ak as pe,ao as te,be as U,cb as ie,cu as R,ej as Ts,et as ss,eu as ns,fu as Fe,gc as Y,gu as Is,gv as _s,hm as xe,ie as we,iv as Ks,jc as F,jj as Me,ju as ke,k as J,kv as js,lc as Ke,lt as Pe,lu as _,lv as Ms,m as Be,me as X,ms as De,mt as Le,mu as ts,n as fs,ne as Ze,ns as he,o as j,p as me,pe as je,q as ps,qd as Ce,qu as I,r as qe,s as us,su as ue,tg as ce,tt as Oe,ur as Os,vd as Te,vf as bs,wj as fe,wn as Ee,xb as T,xd as N,yb as xs,yj as W,zb as Ve}from"./chunk-NNPDC7K7.js";function Us(e){let t=V(e);if(t){let a=t.refCount(),s=[];for(let o of t.traverse())s.push(o);for(let o=s.length-1;0<=o;o--){let r=s[o];if(r.isCte){let c=r;if((a.get(c)||0)<=0){let n=r.expression.parent;if(!n)continue;let l=n.parent;if(n.pop(),l){let f=l.args.expressions;(!f||f.length===0)&&l.pop()}for(let[,f]of Object.entries(r.selectedSources)){let[,p]=f;if(p instanceof q){let m=a.get(p)||0;a.set(p,m-1)}}}}}}return e}h(Us,"eliminateCtes");function os(e){for(let t of D(e)){if(0<t.unqualifiedColumns.length)continue;let a=t.expression.args.joins;if(a)for(let s=a.length-1;0<=s;s--){let o=a[s];if(me(o,N),o.isSemiOrAntiJoin)continue;let r=o.aliasOrName;r&&hn(t,o,r)&&(o.pop(),t.removeSource(r))}}return e}h(os,"eliminateJoins");function hn(e,t,a){let s=e.sources.get(a);if(!(s instanceof q)||Sn(e,t,a))return!1;let o=t.args.side,r=t.args.on;return o==="left"&&yn(s,t)||!r&&Ps(s)}h(hn,"shouldEliminateJoin");function Sn(e,t,a){let s=t.args.on,o=new Set;if(s)for(let c of s.findAll(O))o.add(c);return e.sourceColumns(a).some(c=>!o.has(c))}h(Sn,"joinIsUsed");function yn(e,t){let a=bn(e);if(!a||a.size===0)return!1;let{joinKeys:s}=Ls(t),o=new Set(s.map(r=>r.name));for(let r of a)if(!o.has(r))return!1;return!0}h(yn,"isJoinedOnAllUniqueOutputs");function bn(e){let t=e.expression;if(!(t instanceof w))return;let a=t;if(a.args.distinct)return new Set(a.namedSelects);let s=a.args.group;if(s){let o=new Set((s.args.expressions??[]).filter(n=>n instanceof T).map(n=>n.sql())),r=new Set,c=new Set;for(let n of a.selects){if(!(n instanceof T))continue;let l=n.unalias().sql();o.has(l)&&(r.add(l),c.add(n.aliasOrName))}return[...o].every(n=>r.has(n))?c:new Set}return Ps(e)?new Set(a.namedSelects):new Set}h(bn,"uniqueOutputs");function Ps(e){let t=e.expression;if(!(t instanceof w))return!1;let a=t;return!!(!a.args.from||a.selects.every(o=>o instanceof T?o.unalias()instanceof M:!1)||An(e))}h(Ps,"hasSingleOutputRow");function An(e){let t=e.expression.getArgKey("limit");return t instanceof Te?t.args.expression?.args.this==="1":!1}h(An,"isLimit1");function Ls(e){let t=e.aliasOrName,s=(e.args.on||B()).copy(),o=[],r=[];function c(i){let[n,l]=i.unnestOperands();if(!n||!l)return;let f=Ds(n),p=Ds(l);t&&f.has(t)&&!p.has(t)?(r.push(n),o.push(l),i.replace(B())):t&&p.has(t)&&!f.has(t)&&(r.push(l),o.push(n),i.replace(B()))}if(h(c,"extractCondition"),de(s)){let i=s instanceof Pe?s:Fe([s,B()],{copy:!1});for(let n of i.flatten())n instanceof W&&c(n)}else if(de(s,{dnf:!0})){let i;for(let n of s.flatten()){let l=Array.from(n.flatten()).filter(f=>f instanceof W);if(i===void 0)i=l;else{let f=[];for(let p of l){let m=i.filter(d=>p.sql()===d.sql());0<m.length&&(f.push(p),f.push(...m))}i=f}}if(i)for(let n of i)c(n)}return{sourceKeys:o,joinKeys:r,on:s}}h(Ls,"joinCondition");function Ds(e){let t=new Set;for(let a of e.findAll(O))a.table&&t.add(a.table);return t}h(Ds,"columnTableNames");function rs(e){if(e instanceof P&&e.args.this)return rs(e.args.this),e;let t=V(e);if(!t)return e;let a=new Map;for(let n of t.cteScopes){let l=n.expression.parent;l&&a.set(l.alias,n)}for(let n of t.traverse())for(let[,l]of n.sources)l instanceof U&&a.set(l.name,l);let s=new Map,o=t.expression.args.with,r=!1;if(o){me(o,Y),r=!!o.args.recursive;for(let n of o.args.expressions??[])j(n,es)&&n.args.this&&n.args.this&&s.set(n.args.this.sqlKey,n.alias)}let c=[];for(let n of t.cteScopes){for(let f of n.traverse()){if(f===n)continue;let p=Fs(f,s,a);p&&c.push(p)}let l=n.expression.parent;l&&c.push(l)}let i=[...t.unionScopes,...t.subqueryScopes,...t.tableScopes];for(let n of i)for(let l of n.traverse()){let f=Fs(l,s,a);f&&c.push(f)}return 0<c.length&&(e instanceof Es?e.args.expression:e)?.setArgKey("with",new Y({expressions:c,recursive:r})),e}h(rs,"eliminateSubqueries");function Fs(e,t,a){if(e.isDerivedTable)return Cn(e,t,a);if(e.isCte)return Tn(e,t,a)}h(Fs,"eliminate");function Cn(e,t,a){if(e.parent&&(0<e.parent.pivots.length||e.parent.expression instanceof Ts))return;let s=e.expression.parent;if(!s)return;s instanceof P&&(s=s.unwrap());let[o,r]=ks(e,t,a),c=I(ns(o),s.alias||o,{copy:!1}),n=s.args.joins;return n&&Array.isArray(n)&&c.setArgKey("joins",n),s.replace(c),r}h(Cn,"eliminateDerivedTable");function Tn(e,t,a){let s=e.expression.parent;if(!s)return;let[o,r]=ks(e,t,a),c=s.parent;if(s.pop(),c){let i=c.args.expressions;(!i||i.length===0)&&c.pop()}if(e.parent)for(let i of e.parent.traverse())for(let[,n]of Object.entries(i.selectedSources)){let[l,f]=n;if(f===e){let p=I(ns(o),l.aliasOrName,{copy:!1});l.replace(p)}}return r}h(Tn,"eliminateCte");function ks(e,t,a){let s=t.get(e.expression.sqlKey),r=e.expression.parent?.alias||"";r||(r=be(Array.from(a.keys()),"cte")),s?r=s:a.has(r)&&(r=be(Array.from(a.keys()),r)),a.set(r,e);let c;return s||(t.set(e.expression.sqlKey,r),c=new es({this:e.expression,alias:new F({this:_(r)})})),[r,c]}h(ks,"newCte");function Js(e,t={}){let{leaveTablesIsolated:a=!1}=t;return e=Nn(e,{leaveTablesIsolated:a}),e=On(e,{leaveTablesIsolated:a}),e}h(Js,"mergeSubqueries");var wn=us(()=>[O,W,ge,Ns,Ne]);function Nn(e,t){let{leaveTablesIsolated:a}=t,s=Array.from(D(e)),o=new Map;for(let c of s)for(let[,i]of Object.entries(c.selectedSources)){let[n,l]=i;if(l instanceof q&&l.isCte){let f=o.get(l);f||(f=[],o.set(l,f)),f.push([c,l,n])}}let r=[];for(let[,c]of o)c.length===1&&r.push(c[0]);for(let[c,i,n]of r){let l=n.findAncestor(z,N);if(l&&zs(c,i,{leaveTablesIsolated:a},l)){let f=n.aliasOrName;$s(c,i,f),Ws(c,i,n,f),Qs(c,i,f),Hs(c,i),Bs(c,i,l),Gs(c,i,l),Ys(c,i),vn(i),c.clearCache()}}return e}h(Nn,"mergeCtes");function On(e,t){let{leaveTablesIsolated:a}=t;for(let s of D(e))for(let o of s.derivedTables){let r=o.findAncestor(z,N),c=o.aliasOrName,i=s.sources.get(c);i instanceof q&&r&&zs(s,i,{leaveTablesIsolated:a},r)&&($s(s,i,c),Ws(s,i,o,c),Qs(s,i,c),Hs(s,i),Bs(s,i,r),Gs(s,i,r),Ys(s,i),s.clearCache())}return e}h(On,"mergeDerivedTables");function zs(e,t,a,s){let{leaveTablesIsolated:o}=a,r=t.expression.unnest();function c(){let u=new Set;if(!(r instanceof w))return!1;let g=r;for(let b of g.selects)b instanceof T&&b.find(le)&&u.add(b.aliasOrName);let A=s.aliasOrName,x=[];for(let b of e.columns)b.findAncestor(X,Ce,hs,N,ae,M)!==void 0&&x.push(b);return 0<x.filter(b=>b.table===A&&u.has(b.name)).length}h(c,"isWindowExpressionInUnmergableOperation");function i(){if(!(s instanceof N))return!1;let u=s.aliasOrName,g=s.args.on;if(!g)return!1;let A=Array.from(g.findAll(O)).filter(S=>S.table===u).map(S=>S.name),x=t.expression.getArgKey("from");if(!x)return!1;let E=x.aliasOrName;if(!(t.expression instanceof w))return!1;let b=t.expression,y=new Map;for(let S of b.selects)S instanceof T&&y.set(S.aliasOrName,S);return A.some(S=>{let C=y.get(S);return C?Array.from(C.findAll(O)).some(K=>K.table!==E):!1})}h(i,"outerSelectJoinsOnInnerSelectJoin");function n(){let u=t.expression.parent,g=e.expression.parent;for(;g;){if(g===u)return!0;g=g.parent}return!1}if(h(n,"isRecursive"),!(e.expression instanceof w))return!1;let l=e.expression;if(l.isStar||!(r instanceof w))return!1;let f=r;for(let u of $.UNMERGABLE_ARGS)if(f.getArgKey(u))return!1;if(!f.args.from||0<e.pivots.length)return!1;for(let u of f.args.expressions??[])if(u instanceof T&&(u.find(M)||u.find(w)||u.find(Ue)))return!1;if(o&&1<Object.keys(e.selectedSources).length||s instanceof N&&f.args.joins&&0<f.args.joins.length)return!1;let p=s instanceof N?s.args.side:void 0;if(s instanceof N&&f.args.where&&(p==="full"||p==="left"||p==="right"))return!1;let m=l.args.joins;return!(s instanceof z&&f.args.where&&m&&m.some(u=>j(u,N)&&(u.args.side==="full"||u.args.side==="right"))||i()||c()||n()||f.args.order&&e.isUnion||L(f.args.expressions??[],0)instanceof se)}h(zs,"mergeable");function $s(e,t,a){let s=new Set(Object.keys(t.selectedSources)),o=new Set(Object.keys(e.selectedSources)),r=new Set(Array.from(s).filter(i=>o.has(i)));r.delete(a);let c=new Set([...o,...s]);for(let i of r){let n=be(Array.from(c),i),l=t.selectedSources[i];if(!l)continue;let[f]=l,p=_(n);f instanceof U?f.alias?f.setArgKey("alias",p):f.replace(I(f,p,{copy:!1})):f?.parent instanceof P&&f.parent.setArgKey("alias",new F({this:p}));for(let m of t.sourceColumns(i))m.setArgKey("table",_(n));t.renameSource(i,n),c.add(n)}}h($s,"renameInnerSources");function Ws(e,t,a,s){let r=t.expression.getArgKey("from").args.this;r.setArgKey("joins",a.args.joins),a.replace(r);for(let i of e.joinHints){let n=Array.from(i.findAll(U));for(let l of n)l.aliasOrName===a.aliasOrName&&l.setArgKey("this",_(r.aliasOrName))}e.removeSource(s);let c=t.sources.get(r.aliasOrName);c!==void 0&&e.addSource(r.aliasOrName,c)}h(Ws,"mergeFrom");function Bs(e,t,a){let s=[],o=t.expression.getArgKey("joins");if(o)for(let r of o){s.push(r);let c=t.sources.get(r.aliasOrName);c&&e.addSource(r.aliasOrName,c)}if(0<s.length){let r=e.expression.getArgKey("joins")||[],c;a instanceof z?c=0:c=r.indexOf(a)+1,r.splice(c,0,...s),e.expression.setArgKey("joins",r)}}h(Bs,"mergeJoins");function Qs(e,t,a){let s=new Map;for(let r of e.columns)if(r.table===a){let c=r.name,i=s.get(c);i||(i=[],s.set(c,i)),i.push(r)}if(!(t.expression instanceof w))return;let o=t.expression;for(let r of o.args.expressions??[]){if(!(r instanceof T))continue;let c=r.aliasOrName;if(!c)continue;let i=s.get(c)||[],n=r.unalias(),l=!wn().some(p=>n instanceof p),f=n.isNumber;for(let p of i){let m=p.parent;if(f&&m instanceof Ce){p.replace(_(p.name));continue}let d=n;m&&(m instanceof Cs||m instanceof ee)&&l&&(d=ke(d,{copy:!1})),m instanceof w&&p.name!==d.name&&(d=I(d,p.name,{copy:!1})),p.replace(d.copy())}}}h(Qs,"mergeExpressions");function Gs(e,t,a){let s=t.expression.getArgKey("where");if(!s)return;let o=s.args.this;if(!(o instanceof T))return;let r=e.expression;if(a instanceof N){let c=r.args.from,i=new Set;c&&i.add(c.aliasOrName);let n=r.args.joins;if(n)for(let p of n){let m=p.aliasOrName;if(i.add(m),m===a.aliasOrName)break}let l=oe(o);if(Array.from(l).every(p=>i.has(p))){a.on(o,{copy:!1});return}}r.where(o,{copy:!1})}h(Gs,"mergeWhere");function Hs(e,t){let a=e.expression;a.args.group||a.args.distinct||a.args.having||a.args.order||Object.keys(e.selectedSources).length!==1||a.args.expressions?.some(o=>o instanceof T?o.find(M)!==void 0:!1)||a.setArgKey("order",t.expression.getArgKey("order"))}h(Hs,"mergeOrder");function Ys(e,t){let a=t.expression.getArgKey("hint");if(!a)return;let s=e.expression,o=s.args.hint;if(o){let r=a.args.expressions;for(let c of r??[])c instanceof T&&o.append("expressions",c)}else s.setArgKey("hint",a)}h(Ys,"mergeHints");function vn(e){let t=e.expression.parent;if(!t)return;let a=t.parent;if(!a)return;a.args.expressions?.length===1?a.pop():t.pop()}h(vn,"popCte");function Xs(e,t={}){let{dialect:a}=t,s=V(e),o=$.getOrRaise(a),r=o.constructor.UNNEST_REQUIRES_CROSS_JOIN;if(s){let c=s.refCount();for(let i of Array.from(s.traverse()).reverse()){let n=i.expression,l=n.getArgKey("where");if(l){let p=i.selectedSources,m=n.getArgKey("joins"),d=new Map;m&&m.forEach((g,A)=>{let x=g.aliasOrName;x&&d.set(x,A)});let u=!0;for(let[g,A]of Object.entries(p)){let[x]=A;if(!x)continue;let E=x.findAncestor(N,z);if(E instanceof N){if(E.args.side==="right"){p={[g]:A};break}if(x instanceof te&&r){u=!1;break}}}if(u){let g=l.args.this;g instanceof T&&Vs(g,p,c,o,d)}}let f=n.getArgKey("joins");if(f)for(let p of f){let m=p.aliasOrName;if(m&&m in i.selectedSources){let d=p.args.on;Vs(d,{[m]:i.selectedSources[m]},c,o)}}}}return e}h(Xs,"pushdownPredicates");function Vs(e,t,a,s,o){if(!e)return;let r=Re(e,{dialect:s});e=e.replace(r);let c=de(e)||!de(e,{dnf:!0}),i=(c?e instanceof Pe:e instanceof Le)?Array.from(e.flatten()):[e];c?In(i,t,a,o):qn(i,t,a,o)}h(Vs,"pushdown");function In(e,t,a,s){for(let o of e){let r=Zs(o,t,a);for(let[c,i]of Object.entries(r))if(i instanceof N){let n=oe(o,{exclude:c});if(s){let l=s.get(c)??-1;if(Array.from(n).every(p=>(s.get(p)??-1)<l)){o.replace(B()),i.on(o,{copy:!1});break}}}else if(i instanceof w){o.replace(B());let n=en(i,o);re(n,M)?i.having(n,{copy:!1}):i.where(n,{copy:!1})}}}h(In,"pushdownCnf");function qn(e,t,a,s){let o=new Set;for(let i of e){let n=oe(i);for(let l of e){let f=oe(l);n=new Set(Array.from(n).filter(p=>f.has(p)))}for(let l of n)o.add(l)}let r=new Map,c={};for(let i of Array.from(o).sort()){for(let n of e){if(c=Zs(n,t,a),!(i in c))continue;let l=r.get(i);r.set(i,l?Is([l,n]):n)}for(let[n,l]of Object.entries(c)){let f=r.get(n);if(f){if(l instanceof N){if(s){let p=s.get(n)??-1,m=oe(f,{exclude:n});if(!Array.from(m).every(d=>(s.get(d)??-1)<p))continue}l.on(f,{copy:!1})}else if(l instanceof w){let p=en(l,f);re(p,M)?l.having(p,{copy:!1}):l.where(p,{copy:!1})}}}}}h(qn,"pushdownDnf");function Zs(e,t,a){let s={},o=oe(e),r=e.findAncestor(N,X)instanceof X;for(let c of Array.from(o).sort()){let i=t[c];if(!i)continue;let n=i[0],[,l]=i;if(n&&r&&(n=n.findAncestor(N,z)),n instanceof z&&!(l instanceof U)){let f=ps((l instanceof q?l.parent:l.parent?.args)?.expression,T)?.getArgKey("with");if(f instanceof Y&&f?.recursive)return{};n=l instanceof q?l.expression:l.args.expression}if(n instanceof N){let f=n.side;if(f&&f!=="right")return{};s[c]=n}else if(n instanceof w&&o.size===1){let f=n.selects.some(d=>d instanceof T?d.find(le)!==void 0:!1),p=!!n.args.group,m=a.get(l)||0;!p&&m<2&&!f&&(s[c]=n)}}return s}h(Zs,"nodesForPredicate");function en(e,t){let a=new Map;for(let o of e.selects)if(o instanceof T)if(o instanceof Z){let r=o.args.this;r instanceof T&&a.set(o.alias,r)}else a.set(o.name,o);function s(o){if(o instanceof O){let r=a.get(o.name);if(r)return r.copy()}return o}return h(s,"replaceAlias"),t.transform(s)}h(en,"replaceAliases");var $e=class $e{constructor(t,a,s={}){let{inferSchema:o=!0}=s;this.scope=t,this.schema=a,this.dialect=a.dialect||new $,this.inferSchema=o,this.getSourceColumnsCache=new fs}getTable(t){let a=typeof t=="string"?t:t.name,s=this.getTableNameFromSources(a);if(!s&&typeof t!="string"){let i=this.getColumnJoinContext(t);if(i)try{let n=this.getAvailableSourceColumns(i);s=this.getTableNameFromSources(a,n)}catch(n){if(!(n instanceof J))throw n}}if(!s&&this.inferSchema){let i=this.getAllSourceColumns(),n=[];for(let[l,f]of i)(!f||f.length===0||f.includes("*"))&&n.push(l);n.length===1&&(s=n[0])}if(!s)return;let o=this.scope.selectedSources[s];if(!o)return _(s);let[r]=o,c=r;if(c instanceof Ae)for(;c&&c.alias!==s;)c=c.parent;if(c){let i=c.getArgKey("alias");if(i instanceof T&&(i.args.this instanceof Q||typeof i.args.this=="string"))return _(i.args.this)}return _(s)}get allColumns(){if(!this.allColumnsCache){this.allColumnsCache=new Set;for(let t of this.getAllSourceColumns().values())for(let a of t)this.allColumnsCache.add(a)}return this.allColumnsCache}getSourceColumnsFromSetOp(t){if(t instanceof w)return t.namedSelects;if(t instanceof P){let c=t.args.this;if(c instanceof ne)return this.getSourceColumnsFromSetOp(c)}if(!(t instanceof ne))throw new Error(`Unknown set operation: ${t}`);let a=t,s=a.args.on;if(s)return s.map(c=>c.name);let o=a.args.side,r=a.args.kind;if(o||r){let c=a.args.this,i=a.args.expression;if(!c||!i)return[];let n=this.getSourceColumnsFromSetOp(c),l=this.getSourceColumnsFromSetOp(i);if(o==="left")return n;if(o==="full"){let f=[...n,...l];return Array.from(new Set(f))}else if(r==="inner"){let f=new Set(n),p=new Set(l);return Array.from(f).filter(m=>p.has(m))}}return t.namedSelects}getSourceColumns(t,a={}){let{onlyVisible:s=!1}=a;if(this.getSourceColumnsCache.has(t,s))return this.getSourceColumnsCache.get(t,s)??[];let o=this.scope.sources.get(t);if(!o)throw new J(`Unknown table: ${t}`);let r=[];if(o instanceof U)r=this.schema.columnNames?.(o,{onlyVisible:s})||[];else if(o instanceof q){let n=o.expression;if(n instanceof Me||n instanceof te){if(r=n.namedSelects,this.dialect._constructor.UNNEST_COLUMN_ONLY&&n instanceof te){let l=n;if(!l.type||Ks(l.type,"unknown")){let f=l.args.expressions,p=L(f??[],0);if(p instanceof O&&this.scope.parent){let m=this.getUnnestColumnType(p);if(m?.isType("array")){let d=m.args.expressions;d&&0<d.length?l.type=d[0].copy():l.type=m.copy()}}}if(l.isType("struct"))for(let f of(l.type instanceof T?l.type.args.expressions:void 0)||[])j(f,T)&&r.push(f.name)}}else if(n instanceof ne)r=this.getSourceColumnsFromSetOp(n);else{let l=L(n.args.expressions??[],0);if(l instanceof se){let f=l.args.schema;r=f?f.args.expressions?.map(p=>p instanceof T?p.name:String(p))??[]:["key","value"]}else r=n.namedSelects}}let[c]=this.scope.selectedSources[t]||[void 0,void 0],i;if(c instanceof q?i=c.expression.aliasColumnNames:c instanceof T?i=c.aliasColumnNames:i=[],i.length){let n=[];for(let l=0;l<Math.max(r.length,i.length);l++){let f=L(i,l),p=L(r,l);n.push(f||p||"")}r=n}return this.getSourceColumnsCache.set(t,s,r),r}getAllSourceColumns(){if(!this.sourceColumns){this.sourceColumns=new Map;let t={...this.scope.selectedSources,...Object.fromEntries(this.scope.lateralSources.entries())};for(let a of Object.keys(t))this.sourceColumns.set(a,this.getSourceColumns(a))}return this.sourceColumns}getTableNameFromSources(t,a){let s;return a?s=this.getUnambiguousColumns(a):(this.unambiguousColumns||(this.unambiguousColumns=this.getUnambiguousColumns(this.getAllSourceColumns())),s=this.unambiguousColumns),s.get(t)}getColumnJoinContext(t){if(!this.scope.expression.args.joins||this.scope.expression.getArgKey("laterals")||this.scope.expression.getArgKey("pivots"))return;let s=t.findAncestor(N,w);if(s instanceof N&&Object.keys(this.scope.selectedSources).includes(s.aliasOrName))return s}getAvailableSourceColumns(t){let{from:a,joins:s}=this.scope.expression.args;if(!a||!s)return new Map;let o=new Map,r=a instanceof T?a.aliasOrName:a;r&&o.set(r,this.getSourceColumns(r));for(let c of s.slice(0,s.indexOf(t)+1)){let i=c.aliasOrName;i&&o.set(i,this.getSourceColumns(i))}return o}getUnambiguousColumns(t){if(t.size===0)return new Map;let a=Array.from(t.entries()),[s,o]=a[0];if(a.length===1)return new gs(o,s);let r=new Map;if(this.dialect._constructor.UNNEST_COLUMN_ONLY){for(let[n,l]of this.scope.sources)if(l instanceof q&&l.expression instanceof te){let f=l.expression.args.alias;j(f,F)&&f.columns.length&&r.set(f.columns[0].name,n)}}let c=new Map;for(let n of o)c.set(n,s);let i=new Set(o);for(let[n,l]of a.slice(1)){let f=new Set(l),p=new Set([...i].filter(m=>f.has(m)));for(let m of l)i.add(m);for(let m of p){let d=r.get(m);if(d!==void 0){c.set(m,d);continue}c.delete(m)}for(let m of f)p.has(m)||c.set(m,n)}return c}getUnnestColumnType(t){let a=this.scope.parent;if(!a)return;let s;if(t.table)s=t.table;else{let c=new $e(a,this.schema,{inferSchema:this.inferSchema}).getTable(t);if(!c)return;s=c.name}let o=a.sources.get(s);return o?this.getColumnTypeFromScope(o,t):void 0}getColumnTypeFromScope(t,a){if(t instanceof U){let s=this.schema.getColumnType?.(t,a);if(s&&(typeof s.args.this=="string"?s.args.this:"unknown")!=="unknown")return s}else if(t instanceof q)for(let[,s]of t.sources){let o=this.getColumnTypeFromScope(s,a);if(o&&(typeof o.args.this=="string"?o.args.this:"unknown")!=="unknown")return o}}};h($e,"Resolver");var Se=$e;var ve=Symbol("SELECT_ALL");function _n(e){let{isAgg:t}=e;return I(t?new Oe({this:ce.number(1)}):"1","_")}h(_n,"defaultSelection");function sn(e,t={}){let{schema:a,removeUnusedSelections:s=!0,dialect:o}=t,r=H(a,{dialect:o}),c=new Map,i=new Map,n=Array.from(D(e));for(let l=n.length-1;0<=l;l--){let f=n[l],p=i.get(f)||new Set([ve]),m=c.get(f)||0,d=f.expression;if(d.getArgKey("distinct")&&(p=new Set([ve])),d instanceof ne){let u=d.args.kind,g=d.args.side;if(!u&&!g){let[A,x]=f.unionScopes;if(A.expression.selects.length!==x.expression.selects.length)throw new Error(`Invalid set operation due to column mismatch: ${f.expression.sql({dialect:o})}.`);if(i.set(A,p),x.expression.selects.some(E=>E instanceof T&&E.isStar))i.set(x,p);else if(!A.expression.selects.some(E=>E instanceof T&&E.isStar))if(d.args.byName)i.set(x,i.get(A)||new Set);else{let E=new Set;i.set(x,E);for(let b=0;b<A.expression.selects.length;b++){let y=A.expression.selects[b];if(y instanceof T&&(p.has(ve)||p.has(y.aliasOrName))){let S=x.expression.selects[b];S instanceof T&&E.add(S.aliasOrName)}}}}}if(d instanceof w){if(s&&Kn(f,p,r,m),d.isStar)continue;let u=new Map;for(let g of f.columns){let A=g.table||"",x=g.name,E=u.get(A);E||(E=new Set,u.set(A,E)),E.add(x)}for(let[g,A]of Object.entries(f.selectedSources)){let[x,E]=A;if(E instanceof q){let y=L(E.expression.selects,0),S;0<f.pivots.length||y instanceof se?S=new Set([ve]):S=u.get(g)||new Set;let C=i.get(E);C||(C=new Set,i.set(E,C));for(let v of S)C.add(v)}let b=x.aliasColumnNames;b&&0<b.length&&c.set(E,b.length)}}}return e}h(sn,"pushdownProjections");function Kn(e,t,a,s){let r=e.expression.args.order,c=new Set;if(r)for(let u of r.findAll(O))u.table||c.add(u.name);let i=[],n=!1,l=!1,f=!1,p=s,m=t.has(ve),d=e.expression;for(let u of d.selects){if(typeof u=="string"||typeof u=="number"||typeof u=="boolean")continue;let g=u,A=g.aliasOrName;m||t.has(A)||c.has(A)||0<p?(i.push(g),p-=1):(g.isStar&&(l=!0),n=!0),!f&&g.find(M)&&(f=!0)}if(l){let u=new Se(e,a,{}),g=new Set(i.map(x=>x.aliasOrName)),A=Array.from(t).filter(x=>typeof x=="string").sort();for(let x of A)if(!g.has(x)){let E=u.getTable(x);i.push(I(R({col:x,table:E?.aliasOrName}),x,{copy:!1}))}}i.length===0&&i.push(_n({isAgg:f})),d.select(i,{append:!1,copy:!1}),n&&e.clearCache()}h(Kn,"removeUnusedSelections_");function nn(e,t={}){let{schema:a,dialect:s}=t,o=H(a,{dialect:s});for(let r of D(e))if(Object.keys(r.selectedSources).length!==1)for(let[,c]of Object.entries(r.selectedSources)){let[i,n]=c;if(!(n instanceof U))continue;let l=i;if(!l.parent)continue;let f=o.columnNames?.(n);if(!f||f.length===0||l.parent instanceof P||l.parent?.parent instanceof U)continue;if(!l.alias)throw new J("Tables require an alias. Run qualify_tables optimization.");let m=l.aliasOrName,d=ue("*").from(I(l,m,{table:!0}),{copy:!1}).subquery(m,{copy:!1});l.replace(d)}return e}h(nn,"isolateTableSelects");function ln(e,t={}){let{schema:a,expandAliasRefs:s=!0,expandStars:o=!0,inferSchema:r,allowPartialQualification:c=!1,dialect:i}=t,n=H(a,{dialect:i}),l=new He({schema:n}),f=r??!!n.empty,p=n.dialect||new $,m=p._constructor,d=m.PSEUDOCOLUMNS;for(let u of D(e)){m.PREFER_CTE_ALIAS_COLUMN&&$n(u);let A=u.expression instanceof w;jn(u,d);let x=new Se(u,n,{inferSchema:f});tn(u.ctes),tn(u.derivedTables);let E=Mn(u,x);(n.empty||m.FORCE_EARLY_ALIAS_REF_EXPANSION)&&s&&on(u,x,p,{expandOnlyGroupby:m.EXPAND_ONLY_GROUP_ALIAS_REF}),Un(u,x),Dn(u,x,{allowPartialQualification:c}),!n.empty&&s&&on(u,x,p,{expandOnlyGroupby:!1}),A&&(o&&Fn(u,x,E,d,l),kn(u)),Jn(u,p),zn(u,x),m.ANNOTATE_ALL_SCOPES&&l.annotateScope(u)}return e}h(ln,"qualifyColumns");function fn(e,t){let a=[];for(let s of D(e)){if(!(s.expression instanceof w))continue;let o=s.unqualifiedColumns;if(0<s.externalColumns.length&&!s.isCorrelatedSubquery&&s.pivots.length===0){let r=s.externalColumns[0],c=r.table?` for table: '${r.table}'`:"",i=r.args.this?.meta?.line,n=r.args.this?.meta?.col,l=r.args.this?.meta?.start,f=r.args.this?.meta?.end,p=`Column '${r.name}' could not be resolved${c}.`;if(i&&n&&(p+=` Line: ${i}, Col: ${n}`),t&&l!==void 0&&f!==void 0){let{formattedSql:m}=Be({sql:t,positions:[[l,f]]});p+=`
1
+ import{$a as gs,Ai as ne,Bb as Ae,Bd as Xe,Bj as ws,Cd as hs,Ci as w,Di as P,Ef as es,Ei as le,Fa as H,Fu as qs,Ga as q,Gb as Es,Gu as Rs,Ha as D,Ia as V,Ja as Qe,Kf as O,La as re,Lf as As,Ma as Ge,Me as Z,Mi as ee,Na as He,Ni as Cs,Ns as vs,Nv as $,Oa as ms,Od as se,Oe as Ss,Ou as Je,Pa as de,Pu as B,Qa as Re,Ra as ds,Rj as Ns,Sa as L,Ta as Ye,Te as ys,Ti as ge,Ui as M,Va as be,Wc as z,Xa as _e,Xc as ae,Xu as oe,Zj as Ne,_c as Q,_n as Ue,a as h,ak as pe,ao as te,be as U,cb as ie,cu as R,ej as Ts,et as ss,eu as ns,fu as Fe,gc as Y,gu as Is,gv as _s,hm as xe,ie as we,iv as Ks,jc as F,jj as Me,ju as ke,k as J,kv as js,lc as Ke,lt as Pe,lu as _,lv as Ms,m as Be,me as X,ms as De,mt as Le,mu as ts,n as fs,ne as Ze,ns as he,o as j,p as me,pe as je,q as ps,qd as Ce,qu as I,r as qe,s as us,su as ue,tg as ce,tt as Oe,ur as Os,vd as Te,vf as bs,wj as fe,wn as Ee,xb as T,xd as N,yb as xs,yj as W,zb as Ve}from"./chunk-5TO2OPOM.js";function Us(e){let t=V(e);if(t){let a=t.refCount(),s=[];for(let o of t.traverse())s.push(o);for(let o=s.length-1;0<=o;o--){let r=s[o];if(r.isCte){let c=r;if((a.get(c)||0)<=0){let n=r.expression.parent;if(!n)continue;let l=n.parent;if(n.pop(),l){let f=l.args.expressions;(!f||f.length===0)&&l.pop()}for(let[,f]of Object.entries(r.selectedSources)){let[,p]=f;if(p instanceof q){let m=a.get(p)||0;a.set(p,m-1)}}}}}}return e}h(Us,"eliminateCtes");function os(e){for(let t of D(e)){if(0<t.unqualifiedColumns.length)continue;let a=t.expression.args.joins;if(a)for(let s=a.length-1;0<=s;s--){let o=a[s];if(me(o,N),o.isSemiOrAntiJoin)continue;let r=o.aliasOrName;r&&hn(t,o,r)&&(o.pop(),t.removeSource(r))}}return e}h(os,"eliminateJoins");function hn(e,t,a){let s=e.sources.get(a);if(!(s instanceof q)||Sn(e,t,a))return!1;let o=t.args.side,r=t.args.on;return o==="left"&&yn(s,t)||!r&&Ps(s)}h(hn,"shouldEliminateJoin");function Sn(e,t,a){let s=t.args.on,o=new Set;if(s)for(let c of s.findAll(O))o.add(c);return e.sourceColumns(a).some(c=>!o.has(c))}h(Sn,"joinIsUsed");function yn(e,t){let a=bn(e);if(!a||a.size===0)return!1;let{joinKeys:s}=Ls(t),o=new Set(s.map(r=>r.name));for(let r of a)if(!o.has(r))return!1;return!0}h(yn,"isJoinedOnAllUniqueOutputs");function bn(e){let t=e.expression;if(!(t instanceof w))return;let a=t;if(a.args.distinct)return new Set(a.namedSelects);let s=a.args.group;if(s){let o=new Set((s.args.expressions??[]).filter(n=>n instanceof T).map(n=>n.sql())),r=new Set,c=new Set;for(let n of a.selects){if(!(n instanceof T))continue;let l=n.unalias().sql();o.has(l)&&(r.add(l),c.add(n.aliasOrName))}return[...o].every(n=>r.has(n))?c:new Set}return Ps(e)?new Set(a.namedSelects):new Set}h(bn,"uniqueOutputs");function Ps(e){let t=e.expression;if(!(t instanceof w))return!1;let a=t;return!!(!a.args.from||a.selects.every(o=>o instanceof T?o.unalias()instanceof M:!1)||An(e))}h(Ps,"hasSingleOutputRow");function An(e){let t=e.expression.getArgKey("limit");return t instanceof Te?t.args.expression?.args.this==="1":!1}h(An,"isLimit1");function Ls(e){let t=e.aliasOrName,s=(e.args.on||B()).copy(),o=[],r=[];function c(i){let[n,l]=i.unnestOperands();if(!n||!l)return;let f=Ds(n),p=Ds(l);t&&f.has(t)&&!p.has(t)?(r.push(n),o.push(l),i.replace(B())):t&&p.has(t)&&!f.has(t)&&(r.push(l),o.push(n),i.replace(B()))}if(h(c,"extractCondition"),de(s)){let i=s instanceof Pe?s:Fe([s,B()],{copy:!1});for(let n of i.flatten())n instanceof W&&c(n)}else if(de(s,{dnf:!0})){let i;for(let n of s.flatten()){let l=Array.from(n.flatten()).filter(f=>f instanceof W);if(i===void 0)i=l;else{let f=[];for(let p of l){let m=i.filter(d=>p.sql()===d.sql());0<m.length&&(f.push(p),f.push(...m))}i=f}}if(i)for(let n of i)c(n)}return{sourceKeys:o,joinKeys:r,on:s}}h(Ls,"joinCondition");function Ds(e){let t=new Set;for(let a of e.findAll(O))a.table&&t.add(a.table);return t}h(Ds,"columnTableNames");function rs(e){if(e instanceof P&&e.args.this)return rs(e.args.this),e;let t=V(e);if(!t)return e;let a=new Map;for(let n of t.cteScopes){let l=n.expression.parent;l&&a.set(l.alias,n)}for(let n of t.traverse())for(let[,l]of n.sources)l instanceof U&&a.set(l.name,l);let s=new Map,o=t.expression.args.with,r=!1;if(o){me(o,Y),r=!!o.args.recursive;for(let n of o.args.expressions??[])j(n,es)&&n.args.this&&n.args.this&&s.set(n.args.this.sqlKey,n.alias)}let c=[];for(let n of t.cteScopes){for(let f of n.traverse()){if(f===n)continue;let p=Fs(f,s,a);p&&c.push(p)}let l=n.expression.parent;l&&c.push(l)}let i=[...t.unionScopes,...t.subqueryScopes,...t.tableScopes];for(let n of i)for(let l of n.traverse()){let f=Fs(l,s,a);f&&c.push(f)}return 0<c.length&&(e instanceof Es?e.args.expression:e)?.setArgKey("with",new Y({expressions:c,recursive:r})),e}h(rs,"eliminateSubqueries");function Fs(e,t,a){if(e.isDerivedTable)return Cn(e,t,a);if(e.isCte)return Tn(e,t,a)}h(Fs,"eliminate");function Cn(e,t,a){if(e.parent&&(0<e.parent.pivots.length||e.parent.expression instanceof Ts))return;let s=e.expression.parent;if(!s)return;s instanceof P&&(s=s.unwrap());let[o,r]=ks(e,t,a),c=I(ns(o),s.alias||o,{copy:!1}),n=s.args.joins;return n&&Array.isArray(n)&&c.setArgKey("joins",n),s.replace(c),r}h(Cn,"eliminateDerivedTable");function Tn(e,t,a){let s=e.expression.parent;if(!s)return;let[o,r]=ks(e,t,a),c=s.parent;if(s.pop(),c){let i=c.args.expressions;(!i||i.length===0)&&c.pop()}if(e.parent)for(let i of e.parent.traverse())for(let[,n]of Object.entries(i.selectedSources)){let[l,f]=n;if(f===e){let p=I(ns(o),l.aliasOrName,{copy:!1});l.replace(p)}}return r}h(Tn,"eliminateCte");function ks(e,t,a){let s=t.get(e.expression.sqlKey),r=e.expression.parent?.alias||"";r||(r=be(Array.from(a.keys()),"cte")),s?r=s:a.has(r)&&(r=be(Array.from(a.keys()),r)),a.set(r,e);let c;return s||(t.set(e.expression.sqlKey,r),c=new es({this:e.expression,alias:new F({this:_(r)})})),[r,c]}h(ks,"newCte");function Js(e,t={}){let{leaveTablesIsolated:a=!1}=t;return e=Nn(e,{leaveTablesIsolated:a}),e=On(e,{leaveTablesIsolated:a}),e}h(Js,"mergeSubqueries");var wn=us(()=>[O,W,ge,Ns,Ne]);function Nn(e,t){let{leaveTablesIsolated:a}=t,s=Array.from(D(e)),o=new Map;for(let c of s)for(let[,i]of Object.entries(c.selectedSources)){let[n,l]=i;if(l instanceof q&&l.isCte){let f=o.get(l);f||(f=[],o.set(l,f)),f.push([c,l,n])}}let r=[];for(let[,c]of o)c.length===1&&r.push(c[0]);for(let[c,i,n]of r){let l=n.findAncestor(z,N);if(l&&zs(c,i,{leaveTablesIsolated:a},l)){let f=n.aliasOrName;$s(c,i,f),Ws(c,i,n,f),Qs(c,i,f),Hs(c,i),Bs(c,i,l),Gs(c,i,l),Ys(c,i),vn(i),c.clearCache()}}return e}h(Nn,"mergeCtes");function On(e,t){let{leaveTablesIsolated:a}=t;for(let s of D(e))for(let o of s.derivedTables){let r=o.findAncestor(z,N),c=o.aliasOrName,i=s.sources.get(c);i instanceof q&&r&&zs(s,i,{leaveTablesIsolated:a},r)&&($s(s,i,c),Ws(s,i,o,c),Qs(s,i,c),Hs(s,i),Bs(s,i,r),Gs(s,i,r),Ys(s,i),s.clearCache())}return e}h(On,"mergeDerivedTables");function zs(e,t,a,s){let{leaveTablesIsolated:o}=a,r=t.expression.unnest();function c(){let u=new Set;if(!(r instanceof w))return!1;let g=r;for(let b of g.selects)b instanceof T&&b.find(le)&&u.add(b.aliasOrName);let A=s.aliasOrName,x=[];for(let b of e.columns)b.findAncestor(X,Ce,hs,N,ae,M)!==void 0&&x.push(b);return 0<x.filter(b=>b.table===A&&u.has(b.name)).length}h(c,"isWindowExpressionInUnmergableOperation");function i(){if(!(s instanceof N))return!1;let u=s.aliasOrName,g=s.args.on;if(!g)return!1;let A=Array.from(g.findAll(O)).filter(S=>S.table===u).map(S=>S.name),x=t.expression.getArgKey("from");if(!x)return!1;let E=x.aliasOrName;if(!(t.expression instanceof w))return!1;let b=t.expression,y=new Map;for(let S of b.selects)S instanceof T&&y.set(S.aliasOrName,S);return A.some(S=>{let C=y.get(S);return C?Array.from(C.findAll(O)).some(K=>K.table!==E):!1})}h(i,"outerSelectJoinsOnInnerSelectJoin");function n(){let u=t.expression.parent,g=e.expression.parent;for(;g;){if(g===u)return!0;g=g.parent}return!1}if(h(n,"isRecursive"),!(e.expression instanceof w))return!1;let l=e.expression;if(l.isStar||!(r instanceof w))return!1;let f=r;for(let u of $.UNMERGABLE_ARGS)if(f.getArgKey(u))return!1;if(!f.args.from||0<e.pivots.length)return!1;for(let u of f.args.expressions??[])if(u instanceof T&&(u.find(M)||u.find(w)||u.find(Ue)))return!1;if(o&&1<Object.keys(e.selectedSources).length||s instanceof N&&f.args.joins&&0<f.args.joins.length)return!1;let p=s instanceof N?s.args.side:void 0;if(s instanceof N&&f.args.where&&(p==="full"||p==="left"||p==="right"))return!1;let m=l.args.joins;return!(s instanceof z&&f.args.where&&m&&m.some(u=>j(u,N)&&(u.args.side==="full"||u.args.side==="right"))||i()||c()||n()||f.args.order&&e.isUnion||L(f.args.expressions??[],0)instanceof se)}h(zs,"mergeable");function $s(e,t,a){let s=new Set(Object.keys(t.selectedSources)),o=new Set(Object.keys(e.selectedSources)),r=new Set(Array.from(s).filter(i=>o.has(i)));r.delete(a);let c=new Set([...o,...s]);for(let i of r){let n=be(Array.from(c),i),l=t.selectedSources[i];if(!l)continue;let[f]=l,p=_(n);f instanceof U?f.alias?f.setArgKey("alias",p):f.replace(I(f,p,{copy:!1})):f?.parent instanceof P&&f.parent.setArgKey("alias",new F({this:p}));for(let m of t.sourceColumns(i))m.setArgKey("table",_(n));t.renameSource(i,n),c.add(n)}}h($s,"renameInnerSources");function Ws(e,t,a,s){let r=t.expression.getArgKey("from").args.this;r.setArgKey("joins",a.args.joins),a.replace(r);for(let i of e.joinHints){let n=Array.from(i.findAll(U));for(let l of n)l.aliasOrName===a.aliasOrName&&l.setArgKey("this",_(r.aliasOrName))}e.removeSource(s);let c=t.sources.get(r.aliasOrName);c!==void 0&&e.addSource(r.aliasOrName,c)}h(Ws,"mergeFrom");function Bs(e,t,a){let s=[],o=t.expression.getArgKey("joins");if(o)for(let r of o){s.push(r);let c=t.sources.get(r.aliasOrName);c&&e.addSource(r.aliasOrName,c)}if(0<s.length){let r=e.expression.getArgKey("joins")||[],c;a instanceof z?c=0:c=r.indexOf(a)+1,r.splice(c,0,...s),e.expression.setArgKey("joins",r)}}h(Bs,"mergeJoins");function Qs(e,t,a){let s=new Map;for(let r of e.columns)if(r.table===a){let c=r.name,i=s.get(c);i||(i=[],s.set(c,i)),i.push(r)}if(!(t.expression instanceof w))return;let o=t.expression;for(let r of o.args.expressions??[]){if(!(r instanceof T))continue;let c=r.aliasOrName;if(!c)continue;let i=s.get(c)||[],n=r.unalias(),l=!wn().some(p=>n instanceof p),f=n.isNumber;for(let p of i){let m=p.parent;if(f&&m instanceof Ce){p.replace(_(p.name));continue}let d=n;m&&(m instanceof Cs||m instanceof ee)&&l&&(d=ke(d,{copy:!1})),m instanceof w&&p.name!==d.name&&(d=I(d,p.name,{copy:!1})),p.replace(d.copy())}}}h(Qs,"mergeExpressions");function Gs(e,t,a){let s=t.expression.getArgKey("where");if(!s)return;let o=s.args.this;if(!(o instanceof T))return;let r=e.expression;if(a instanceof N){let c=r.args.from,i=new Set;c&&i.add(c.aliasOrName);let n=r.args.joins;if(n)for(let p of n){let m=p.aliasOrName;if(i.add(m),m===a.aliasOrName)break}let l=oe(o);if(Array.from(l).every(p=>i.has(p))){a.on(o,{copy:!1});return}}r.where(o,{copy:!1})}h(Gs,"mergeWhere");function Hs(e,t){let a=e.expression;a.args.group||a.args.distinct||a.args.having||a.args.order||Object.keys(e.selectedSources).length!==1||a.args.expressions?.some(o=>o instanceof T?o.find(M)!==void 0:!1)||a.setArgKey("order",t.expression.getArgKey("order"))}h(Hs,"mergeOrder");function Ys(e,t){let a=t.expression.getArgKey("hint");if(!a)return;let s=e.expression,o=s.args.hint;if(o){let r=a.args.expressions;for(let c of r??[])c instanceof T&&o.append("expressions",c)}else s.setArgKey("hint",a)}h(Ys,"mergeHints");function vn(e){let t=e.expression.parent;if(!t)return;let a=t.parent;if(!a)return;a.args.expressions?.length===1?a.pop():t.pop()}h(vn,"popCte");function Xs(e,t={}){let{dialect:a}=t,s=V(e),o=$.getOrRaise(a),r=o.constructor.UNNEST_REQUIRES_CROSS_JOIN;if(s){let c=s.refCount();for(let i of Array.from(s.traverse()).reverse()){let n=i.expression,l=n.getArgKey("where");if(l){let p=i.selectedSources,m=n.getArgKey("joins"),d=new Map;m&&m.forEach((g,A)=>{let x=g.aliasOrName;x&&d.set(x,A)});let u=!0;for(let[g,A]of Object.entries(p)){let[x]=A;if(!x)continue;let E=x.findAncestor(N,z);if(E instanceof N){if(E.args.side==="right"){p={[g]:A};break}if(x instanceof te&&r){u=!1;break}}}if(u){let g=l.args.this;g instanceof T&&Vs(g,p,c,o,d)}}let f=n.getArgKey("joins");if(f)for(let p of f){let m=p.aliasOrName;if(m&&m in i.selectedSources){let d=p.args.on;Vs(d,{[m]:i.selectedSources[m]},c,o)}}}}return e}h(Xs,"pushdownPredicates");function Vs(e,t,a,s,o){if(!e)return;let r=Re(e,{dialect:s});e=e.replace(r);let c=de(e)||!de(e,{dnf:!0}),i=(c?e instanceof Pe:e instanceof Le)?Array.from(e.flatten()):[e];c?In(i,t,a,o):qn(i,t,a,o)}h(Vs,"pushdown");function In(e,t,a,s){for(let o of e){let r=Zs(o,t,a);for(let[c,i]of Object.entries(r))if(i instanceof N){let n=oe(o,{exclude:c});if(s){let l=s.get(c)??-1;if(Array.from(n).every(p=>(s.get(p)??-1)<l)){o.replace(B()),i.on(o,{copy:!1});break}}}else if(i instanceof w){o.replace(B());let n=en(i,o);re(n,M)?i.having(n,{copy:!1}):i.where(n,{copy:!1})}}}h(In,"pushdownCnf");function qn(e,t,a,s){let o=new Set;for(let i of e){let n=oe(i);for(let l of e){let f=oe(l);n=new Set(Array.from(n).filter(p=>f.has(p)))}for(let l of n)o.add(l)}let r=new Map,c={};for(let i of Array.from(o).sort()){for(let n of e){if(c=Zs(n,t,a),!(i in c))continue;let l=r.get(i);r.set(i,l?Is([l,n]):n)}for(let[n,l]of Object.entries(c)){let f=r.get(n);if(f){if(l instanceof N){if(s){let p=s.get(n)??-1,m=oe(f,{exclude:n});if(!Array.from(m).every(d=>(s.get(d)??-1)<p))continue}l.on(f,{copy:!1})}else if(l instanceof w){let p=en(l,f);re(p,M)?l.having(p,{copy:!1}):l.where(p,{copy:!1})}}}}}h(qn,"pushdownDnf");function Zs(e,t,a){let s={},o=oe(e),r=e.findAncestor(N,X)instanceof X;for(let c of Array.from(o).sort()){let i=t[c];if(!i)continue;let n=i[0],[,l]=i;if(n&&r&&(n=n.findAncestor(N,z)),n instanceof z&&!(l instanceof U)){let f=ps((l instanceof q?l.parent:l.parent?.args)?.expression,T)?.getArgKey("with");if(f instanceof Y&&f?.recursive)return{};n=l instanceof q?l.expression:l.args.expression}if(n instanceof N){let f=n.side;if(f&&f!=="right")return{};s[c]=n}else if(n instanceof w&&o.size===1){let f=n.selects.some(d=>d instanceof T?d.find(le)!==void 0:!1),p=!!n.args.group,m=a.get(l)||0;!p&&m<2&&!f&&(s[c]=n)}}return s}h(Zs,"nodesForPredicate");function en(e,t){let a=new Map;for(let o of e.selects)if(o instanceof T)if(o instanceof Z){let r=o.args.this;r instanceof T&&a.set(o.alias,r)}else a.set(o.name,o);function s(o){if(o instanceof O){let r=a.get(o.name);if(r)return r.copy()}return o}return h(s,"replaceAlias"),t.transform(s)}h(en,"replaceAliases");var $e=class $e{constructor(t,a,s={}){let{inferSchema:o=!0}=s;this.scope=t,this.schema=a,this.dialect=a.dialect||new $,this.inferSchema=o,this.getSourceColumnsCache=new fs}getTable(t){let a=typeof t=="string"?t:t.name,s=this.getTableNameFromSources(a);if(!s&&typeof t!="string"){let i=this.getColumnJoinContext(t);if(i)try{let n=this.getAvailableSourceColumns(i);s=this.getTableNameFromSources(a,n)}catch(n){if(!(n instanceof J))throw n}}if(!s&&this.inferSchema){let i=this.getAllSourceColumns(),n=[];for(let[l,f]of i)(!f||f.length===0||f.includes("*"))&&n.push(l);n.length===1&&(s=n[0])}if(!s)return;let o=this.scope.selectedSources[s];if(!o)return _(s);let[r]=o,c=r;if(c instanceof Ae)for(;c&&c.alias!==s;)c=c.parent;if(c){let i=c.getArgKey("alias");if(i instanceof T&&(i.args.this instanceof Q||typeof i.args.this=="string"))return _(i.args.this)}return _(s)}get allColumns(){if(!this.allColumnsCache){this.allColumnsCache=new Set;for(let t of this.getAllSourceColumns().values())for(let a of t)this.allColumnsCache.add(a)}return this.allColumnsCache}getSourceColumnsFromSetOp(t){if(t instanceof w)return t.namedSelects;if(t instanceof P){let c=t.args.this;if(c instanceof ne)return this.getSourceColumnsFromSetOp(c)}if(!(t instanceof ne))throw new Error(`Unknown set operation: ${t}`);let a=t,s=a.args.on;if(s)return s.map(c=>c.name);let o=a.args.side,r=a.args.kind;if(o||r){let c=a.args.this,i=a.args.expression;if(!c||!i)return[];let n=this.getSourceColumnsFromSetOp(c),l=this.getSourceColumnsFromSetOp(i);if(o==="left")return n;if(o==="full"){let f=[...n,...l];return Array.from(new Set(f))}else if(r==="inner"){let f=new Set(n),p=new Set(l);return Array.from(f).filter(m=>p.has(m))}}return t.namedSelects}getSourceColumns(t,a={}){let{onlyVisible:s=!1}=a;if(this.getSourceColumnsCache.has(t,s))return this.getSourceColumnsCache.get(t,s)??[];let o=this.scope.sources.get(t);if(!o)throw new J(`Unknown table: ${t}`);let r=[];if(o instanceof U)r=this.schema.columnNames?.(o,{onlyVisible:s})||[];else if(o instanceof q){let n=o.expression;if(n instanceof Me||n instanceof te){if(r=n.namedSelects,this.dialect._constructor.UNNEST_COLUMN_ONLY&&n instanceof te){let l=n;if(!l.type||Ks(l.type,"unknown")){let f=l.args.expressions,p=L(f??[],0);if(p instanceof O&&this.scope.parent){let m=this.getUnnestColumnType(p);if(m?.isType("array")){let d=m.args.expressions;d&&0<d.length?l.type=d[0].copy():l.type=m.copy()}}}if(l.isType("struct"))for(let f of(l.type instanceof T?l.type.args.expressions:void 0)||[])j(f,T)&&r.push(f.name)}}else if(n instanceof ne)r=this.getSourceColumnsFromSetOp(n);else{let l=L(n.args.expressions??[],0);if(l instanceof se){let f=l.args.schema;r=f?f.args.expressions?.map(p=>p instanceof T?p.name:String(p))??[]:["key","value"]}else r=n.namedSelects}}let[c]=this.scope.selectedSources[t]||[void 0,void 0],i;if(c instanceof q?i=c.expression.aliasColumnNames:c instanceof T?i=c.aliasColumnNames:i=[],i.length){let n=[];for(let l=0;l<Math.max(r.length,i.length);l++){let f=L(i,l),p=L(r,l);n.push(f||p||"")}r=n}return this.getSourceColumnsCache.set(t,s,r),r}getAllSourceColumns(){if(!this.sourceColumns){this.sourceColumns=new Map;let t={...this.scope.selectedSources,...Object.fromEntries(this.scope.lateralSources.entries())};for(let a of Object.keys(t))this.sourceColumns.set(a,this.getSourceColumns(a))}return this.sourceColumns}getTableNameFromSources(t,a){let s;return a?s=this.getUnambiguousColumns(a):(this.unambiguousColumns||(this.unambiguousColumns=this.getUnambiguousColumns(this.getAllSourceColumns())),s=this.unambiguousColumns),s.get(t)}getColumnJoinContext(t){if(!this.scope.expression.args.joins||this.scope.expression.getArgKey("laterals")||this.scope.expression.getArgKey("pivots"))return;let s=t.findAncestor(N,w);if(s instanceof N&&Object.keys(this.scope.selectedSources).includes(s.aliasOrName))return s}getAvailableSourceColumns(t){let{from:a,joins:s}=this.scope.expression.args;if(!a||!s)return new Map;let o=new Map,r=a instanceof T?a.aliasOrName:a;r&&o.set(r,this.getSourceColumns(r));for(let c of s.slice(0,s.indexOf(t)+1)){let i=c.aliasOrName;i&&o.set(i,this.getSourceColumns(i))}return o}getUnambiguousColumns(t){if(t.size===0)return new Map;let a=Array.from(t.entries()),[s,o]=a[0];if(a.length===1)return new gs(o,s);let r=new Map;if(this.dialect._constructor.UNNEST_COLUMN_ONLY){for(let[n,l]of this.scope.sources)if(l instanceof q&&l.expression instanceof te){let f=l.expression.args.alias;j(f,F)&&f.columns.length&&r.set(f.columns[0].name,n)}}let c=new Map;for(let n of o)c.set(n,s);let i=new Set(o);for(let[n,l]of a.slice(1)){let f=new Set(l),p=new Set([...i].filter(m=>f.has(m)));for(let m of l)i.add(m);for(let m of p){let d=r.get(m);if(d!==void 0){c.set(m,d);continue}c.delete(m)}for(let m of f)p.has(m)||c.set(m,n)}return c}getUnnestColumnType(t){let a=this.scope.parent;if(!a)return;let s;if(t.table)s=t.table;else{let c=new $e(a,this.schema,{inferSchema:this.inferSchema}).getTable(t);if(!c)return;s=c.name}let o=a.sources.get(s);return o?this.getColumnTypeFromScope(o,t):void 0}getColumnTypeFromScope(t,a){if(t instanceof U){let s=this.schema.getColumnType?.(t,a);if(s&&(typeof s.args.this=="string"?s.args.this:"unknown")!=="unknown")return s}else if(t instanceof q)for(let[,s]of t.sources){let o=this.getColumnTypeFromScope(s,a);if(o&&(typeof o.args.this=="string"?o.args.this:"unknown")!=="unknown")return o}}};h($e,"Resolver");var Se=$e;var ve=Symbol("SELECT_ALL");function _n(e){let{isAgg:t}=e;return I(t?new Oe({this:ce.number(1)}):"1","_")}h(_n,"defaultSelection");function sn(e,t={}){let{schema:a,removeUnusedSelections:s=!0,dialect:o}=t,r=H(a,{dialect:o}),c=new Map,i=new Map,n=Array.from(D(e));for(let l=n.length-1;0<=l;l--){let f=n[l],p=i.get(f)||new Set([ve]),m=c.get(f)||0,d=f.expression;if(d.getArgKey("distinct")&&(p=new Set([ve])),d instanceof ne){let u=d.args.kind,g=d.args.side;if(!u&&!g){let[A,x]=f.unionScopes;if(A.expression.selects.length!==x.expression.selects.length)throw new Error(`Invalid set operation due to column mismatch: ${f.expression.sql({dialect:o})}.`);if(i.set(A,p),x.expression.selects.some(E=>E instanceof T&&E.isStar))i.set(x,p);else if(!A.expression.selects.some(E=>E instanceof T&&E.isStar))if(d.args.byName)i.set(x,i.get(A)||new Set);else{let E=new Set;i.set(x,E);for(let b=0;b<A.expression.selects.length;b++){let y=A.expression.selects[b];if(y instanceof T&&(p.has(ve)||p.has(y.aliasOrName))){let S=x.expression.selects[b];S instanceof T&&E.add(S.aliasOrName)}}}}}if(d instanceof w){if(s&&Kn(f,p,r,m),d.isStar)continue;let u=new Map;for(let g of f.columns){let A=g.table||"",x=g.name,E=u.get(A);E||(E=new Set,u.set(A,E)),E.add(x)}for(let[g,A]of Object.entries(f.selectedSources)){let[x,E]=A;if(E instanceof q){let y=L(E.expression.selects,0),S;0<f.pivots.length||y instanceof se?S=new Set([ve]):S=u.get(g)||new Set;let C=i.get(E);C||(C=new Set,i.set(E,C));for(let v of S)C.add(v)}let b=x.aliasColumnNames;b&&0<b.length&&c.set(E,b.length)}}}return e}h(sn,"pushdownProjections");function Kn(e,t,a,s){let r=e.expression.args.order,c=new Set;if(r)for(let u of r.findAll(O))u.table||c.add(u.name);let i=[],n=!1,l=!1,f=!1,p=s,m=t.has(ve),d=e.expression;for(let u of d.selects){if(typeof u=="string"||typeof u=="number"||typeof u=="boolean")continue;let g=u,A=g.aliasOrName;m||t.has(A)||c.has(A)||0<p?(i.push(g),p-=1):(g.isStar&&(l=!0),n=!0),!f&&g.find(M)&&(f=!0)}if(l){let u=new Se(e,a,{}),g=new Set(i.map(x=>x.aliasOrName)),A=Array.from(t).filter(x=>typeof x=="string").sort();for(let x of A)if(!g.has(x)){let E=u.getTable(x);i.push(I(R({col:x,table:E?.aliasOrName}),x,{copy:!1}))}}i.length===0&&i.push(_n({isAgg:f})),d.select(i,{append:!1,copy:!1}),n&&e.clearCache()}h(Kn,"removeUnusedSelections_");function nn(e,t={}){let{schema:a,dialect:s}=t,o=H(a,{dialect:s});for(let r of D(e))if(Object.keys(r.selectedSources).length!==1)for(let[,c]of Object.entries(r.selectedSources)){let[i,n]=c;if(!(n instanceof U))continue;let l=i;if(!l.parent)continue;let f=o.columnNames?.(n);if(!f||f.length===0||l.parent instanceof P||l.parent?.parent instanceof U)continue;if(!l.alias)throw new J("Tables require an alias. Run qualify_tables optimization.");let m=l.aliasOrName,d=ue("*").from(I(l,m,{table:!0}),{copy:!1}).subquery(m,{copy:!1});l.replace(d)}return e}h(nn,"isolateTableSelects");function ln(e,t={}){let{schema:a,expandAliasRefs:s=!0,expandStars:o=!0,inferSchema:r,allowPartialQualification:c=!1,dialect:i}=t,n=H(a,{dialect:i}),l=new He({schema:n}),f=r??!!n.empty,p=n.dialect||new $,m=p._constructor,d=m.PSEUDOCOLUMNS;for(let u of D(e)){m.PREFER_CTE_ALIAS_COLUMN&&$n(u);let A=u.expression instanceof w;jn(u,d);let x=new Se(u,n,{inferSchema:f});tn(u.ctes),tn(u.derivedTables);let E=Mn(u,x);(n.empty||m.FORCE_EARLY_ALIAS_REF_EXPANSION)&&s&&on(u,x,p,{expandOnlyGroupby:m.EXPAND_ONLY_GROUP_ALIAS_REF}),Un(u,x),Dn(u,x,{allowPartialQualification:c}),!n.empty&&s&&on(u,x,p,{expandOnlyGroupby:!1}),A&&(o&&Fn(u,x,E,d,l),kn(u)),Jn(u,p),zn(u,x),m.ANNOTATE_ALL_SCOPES&&l.annotateScope(u)}return e}h(ln,"qualifyColumns");function fn(e,t){let a=[];for(let s of D(e)){if(!(s.expression instanceof w))continue;let o=s.unqualifiedColumns;if(0<s.externalColumns.length&&!s.isCorrelatedSubquery&&s.pivots.length===0){let r=s.externalColumns[0],c=r.table?` for table: '${r.table}'`:"",i=r.args.this?.meta?.line,n=r.args.this?.meta?.col,l=r.args.this?.meta?.start,f=r.args.this?.meta?.end,p=`Column '${r.name}' could not be resolved${c}.`;if(i&&n&&(p+=` Line: ${i}, Col: ${n}`),t&&l!==void 0&&f!==void 0){let{formattedSql:m}=Be({sql:t,positions:[[l,f]]});p+=`
2
2
  ${m}`}throw new J(p)}if(0<o.length&&0<s.pivots.length&&s.pivots[0].unpivot){let r=new Set(pn(s.pivots[0]));o=o.filter(c=>!r.has(c))}a.push(...o)}if(0<a.length){let s=a[0],o=s.args.this,r=j(o,T)?o.meta.line:void 0,c=j(o,T)?o.meta.col:void 0,i=j(o,T)?o.meta.start:void 0,n=j(o,T)?o.meta.end:void 0,l=`Ambiguous column '${s.name}'`;if(r&&c&&(l+=` (Line: ${r}, Col: ${c})`),t&&i!==void 0&&n!==void 0){let{formattedSql:f}=Be({sql:t,positions:[[i,n]]});l+=`
3
3
  ${f}`}throw new J(l)}return e}h(fn,"validateQualifyColumns");function jn(e,t){if(t.size===0)return;let a=!1,s=e.expression;for(let o of e.columns){let r=o.name.toUpperCase();t.has(r)&&(r!=="LEVEL"||s instanceof w&&s.args.connect)&&(o.replace(new As({...o.args})),a=!0)}a&&e.clearCache()}h(jn,"separatePseudocolumns");function pn(e){let a=(e.args.fields||[]).filter(o=>o instanceof pe&&o.args.this instanceof O).map(o=>o.args.this),s=[];for(let o of e.args.expressions)for(let r of o.findAll(O))s.push(r);return[...a,...s]}h(pn,"unpivotColumns");function tn(e){for(let t of e){if(t.parent instanceof Y&&t.parent.args.recursive)continue;let a=t.getArgKey("alias");a instanceof F&&a.setArgKey("columns",void 0)}}h(tn,"popTableColumnAliases");function Mn(e,t){let a=e.expression.args.joins||[];if(a.length===0)return new Map;let s=new Set(a.map(n=>n.aliasOrName)),o=Object.keys(e.selectedSources).filter(n=>!s.has(n));if(0<s.size&&o.length===0)throw new J(`Joins ${[...s].join(",")} missing source table ${e.expression}`);let r={},c=h(n=>{for(let l of t.getSourceColumns(n))l in r||(r[l]=n)},"updateSourceColumns");for(let n of o)c(n);let i=new Map;for(let n=0;n<a.length;n++){let l=a[n];me(l,N);let f=o[o.length-1];f&&c(f);let p=l.aliasOrName;o.push(p);let m=l.args.using;if(!m)continue;let d=t.getSourceColumns(p),u=[],g=m.length,A=l.isSemiOrAntiJoin;for(let x of m){let E=x.name,b=r[E];if((!b||!d.includes(E))&&0<Object.keys(r).length&&!("*"in r)&&0<d.length)throw new J(`Cannot automatically join: ${E}`);b=b||f;let y;if(n===0||g===1)y=R({col:E,table:b});else{let S=o.slice(0,-1).filter(C=>t.getSourceColumns(C).includes(E)).map(C=>R({col:E,table:C}));1<S.length?y=new xe({this:S[0],expressions:S.slice(1)}):y=R({col:E,table:b})}if(u.push(y.eq(R({col:E,table:p}))),!A){let S=i.get(E);S||(S=[],i.set(E,S)),S.includes(b)||S.push(b),S.includes(p)||S.push(p)}}l.setArgKey("using",void 0),l.setArgKey("on",Fe(u,{copy:!1}))}if(0<i.size)for(let n of e.columns){let l=n.table?void 0:i.get(n.name);if(l!==void 0){let f=l.map(m=>R({col:n.name,table:m})),p=new xe({this:f[0],expressions:f.slice(1)});n.parent instanceof w?p=I(p,n.name,{copy:!1}):n.parent instanceof Os&&(p=new ws({this:_(n.name),expression:p})),e.replace(n,p)}}return i}h(Mn,"expandUsing");function on(e,t,a,s){let{expandOnlyGroupby:o}=s,r=e.expression,c=a._constructor;if(!(r instanceof w)||c.DISABLES_ALIAS_REF_EXPANSION)return;let i=new Map,n=new Set(r.selects.map(d=>d.aliasOrName)),l=!1,f=h((d,u={})=>{let{resolveTable:g=!1,literalIndex:A=!1}=u,x=d instanceof Ce,E=d instanceof ae;if(!(!d||o&&!x))for(let b of Qe(d,{prune:h(y=>y.isStar,"prune")})){if(!(b instanceof O)||o&&x&&b.parent!==d)continue;let y=!1,S=g&&!b.table?t.getTable(b.name):void 0,C=i.get(b.name),v=C?C[0]:void 0,K=C?C[1]:1;if(v)y=!!(v.find(M)&&b.findAncestor(M)&&!(b.findAncestor(le,w)instanceof le)),E&&c.PROJECTION_ALIASES_SHADOW_SOURCE_NAMES&&(y=y||Array.from(v.findAll(O)).some(k=>n.has(k.parts[0]?.name||"")));else if(c.PROJECTION_ALIASES_SHADOW_SOURCE_NAMES&&(x||E)){let k=S?S.name:b.table;if(k&&n.has(k)){b.replace(_(b.name)),l=!0;continue}}if(S&&(!v||y))b.setArgKey("table",S);else if(!b.table&&v&&!y)if((v instanceof ce||v.isNumber)&&(A||g))A&&(b.replace(ce.number(K)),l=!0);else{l=!0;let k=b.replace(ke(v)),ye=ds(k,a);ye!==k&&k.replace(ye)}}},"replaceColumns");for(let d=0;d<r.selects.length;d++){let u=r.selects[d];f(u),u instanceof Z&&i.set(u.alias,[u.args.this,d+1])}let p=e,m=!1;for(;p&&!p.isCte;)p.isUnion&&p.parent&&(m=p.parent.expression.args.expression===p.expression),p=p.parent;if(p&&m){let d=p.expression.parent;if(d&&d.findAncestor(Y)?.args.recursive){let g=d.args.alias,A=g instanceof F?g.columns:[],x=0<A.length?A:d.args.this?.selects||[];for(let E of x)E instanceof T&&i.delete(E.outputName)}}if(f(r.args.where),f(r.args.group,{literalIndex:!0}),f(r.args.having,{resolveTable:!0}),f(r.args.qualify,{resolveTable:!0}),c.SUPPORTS_ALIAS_REFS_IN_JOIN_CONDITIONS)for(let d of r.args.joins||[])f(d);l&&e.clearCache()}h(on,"expandAliasRefs_");function Un(e,t){let a=!1,s=[...e.columns,...e.stars];for(let o of s){if(o instanceof fe)continue;let r=o.table,c=o.meta.dotParts||[];if(delete o.meta.dotParts,r&&!e.sources.has(r)&&(!e.parent||!e.parent.sources.has(r)||!e.isCorrelatedSubquery)){let i=o.parts;if(i.length<2)continue;let n=i[0],l=i.slice(1);if(!n)continue;let f,p,m,d;if(e.sources.has(n.name)){if(l.length===0)continue;m=n,f=l[0],p=l.slice(1),d=!0}else m=t.getTable(n.name),f=n,p=l,d=!1;if(m){a=!0;let u=R({col:f,table:m});0<c.length&&(u.meta.dotParts=c.slice(d?2:1)),0<p.length?o.replace(fe.build([u,...p])):o.replace(u)}}}a&&e.clearCache()}h(Un,"convertColumnsToDots");function Dn(e,t,a){let{allowPartialQualification:s}=a,o=t.dialect._constructor;for(let r of e.columns){let c=r.table,i=r.name;if(c&&e.sources.has(c)){let n=t.getSourceColumns(c);if(!s&&0<n.length&&!n.includes(i)&&!n.includes("*"))throw new J(`Unknown column: ${i}`)}if(!c){if(0<e.pivots.length&&!r.findAncestor(we)){r.setArgKey("table",_(e.pivots[0].alias));continue}let n=t.getTable(r);if(n){let l=e.sources.get(n.name);if(l instanceof q&&l.columnIndex.has(r))continue}if(n)r.setArgKey("table",n);else if(o.TABLES_REFERENCEABLE_AS_COLUMNS&&r.parts.length===1&&i in e.selectedSources){let l=r.args.this;e.replace(r,new bs({this:j(l,T)?l:void 0}))}}}for(let r of e.pivots)if(r instanceof we){for(let c of r.findAll(O))if(!c.table&&t.allColumns.has(c.name)){let i=t.getTable(c.name);i&&c.setArgKey("table",i)}}}h(Dn,"qualifyColumnsInScope");function rn(e,t,a){let s=e.getArgKey("except")??e.getArgKey("except");if(!s)return;let o=Array.isArray(s)?s:[s],r=new Set(o.filter(c=>c instanceof T).map(c=>c.name));for(let c of t)a.set(c,r)}h(rn,"addExceptColumns");function an(e,t,a){let s=e.getArgKey("rename");if(!s||s.length===0)return;let o={};for(let r of s)if(r instanceof T){let c=r.args.this;c instanceof T&&(o[c.name]=r.alias)}for(let r of t)a.set(r,o)}h(an,"addRenameColumns");function cn(e,t,a){let s=e.getArgKey("replace");if(!s||s.length===0)return;let o={};for(let r of s)r instanceof Z&&(o[r.alias]=r);for(let r of t)a.set(r,o)}h(cn,"addReplaceColumns");function Pn(e){let t=e.find(O);if(!(t instanceof O)||!t.isType("struct"))return[];let a=t.copy(),s=a.type,o=j(s,je)?s:void 0,r=e.parts.slice(1,-1);e:for(let n of r.slice(1)){let l=o?.args.expressions||[];for(let f of l){if(!(f.args.this instanceof Q))return[];if(!j(f,Ke))return[];let p=f.args.kind,m=j(p,je)?p:void 0;if(f.name===n.name&&m?.isType("struct")){o=m;break e}}return[]}let c=new Set,i=[];for(let n of o?.args.expressions||[]){let l=n.name,f=n.args.this;if(c.has(l)||!(f instanceof Q))return[];c.add(l);let p=f.copy(),m=[...r.map(A=>A.copy()),p],[d,...u]=m,g=R({col:d,table:a.args.table},{fields:u});i.push(I(g,p,{copy:!1}))}return i}h(Pn,"expandStructStarsNoParens");function Ln(e){if(!(e.args.this instanceof Ne))return[];let t=e.find(O);if(!(t instanceof O)||!t.isType("struct"))return[];let a=t.parent,s=t.type,o=j(s,je)?s:void 0;for(;a!==void 0;){if(a instanceof Ne){a=a.parent;continue}if(!(a instanceof fe))return[];let n=a.right;if(n instanceof Ze)break;if(!(n instanceof Q))return[];let l=!1,f=qe(o.args.expressions||[],Ke);for(let p of f)if(p.name===n.name){l=!0,o=p.args.kind;break}if(!l)return[];a=a.parent}let r=[],c=e.args.this,i=qe(o.args.expressions||[],Ke);for(let n of i){let l=n.args.this instanceof Q?n.args.this.copy():new Q({this:n.args.this?.toString()}),f=fe.build([c.copy(),l]),p=I(f,l,{copy:!1});r.push(p)}return r}h(Ln,"expandStructStarsWithParens");function Fn(e,t,a,s,o){let r=[],c=new Map,i=new Map,n=new Map,l=new Set,f=t.dialect._constructor,p,m=new Set,d=L(e.pivots,0);if(d instanceof we&&!d.aliasColumnNames.length)if(d.unpivot){p=pn(d).map(u=>u.outputName);for(let u of d.args.fields||[])if(u instanceof pe)for(let g of u.args.expressions)for(let A of g.findAll(O))m.add(A.outputName)}else{for(let g of d.findAll(O))m.add(g.outputName);p=(d.getArgKey("columns")||[]).map(g=>g.outputName),p.length||(p=d.args.expressions.map(g=>g.aliasOrName))}f.SUPPORTS_STRUCT_STAR_EXPANSION&&e.stars.some(u=>u instanceof fe)&&o.annotateScope(e);for(let u of e.expression.selects){let g=[];if(u instanceof Ze)g.push(...Object.keys(e.selectedSources)),rn(u,g,c),cn(u,g,i),an(u,g,n);else if(u.isStar)if(u instanceof fe){if(f.SUPPORTS_STRUCT_STAR_EXPANSION&&!f.REQUIRES_PARENTHESIZED_STRUCT_ACCESS){let A=Pn(u);if(0<A.length){r.push(...A);continue}}else if(f.REQUIRES_PARENTHESIZED_STRUCT_ACCESS){let A=Ln(u);if(0<A.length){r.push(...A);continue}}}else{let A=u instanceof O?u.table:"";A&&g.push(A);let x=u.args.this;x instanceof T&&(rn(x,g,c),cn(x,g,i),an(x,g,n))}if(g.length===0){r.push(u);continue}for(let A of g){if(!e.sources.has(A))throw new J(`Unknown table: ${A}`);let x=t.getSourceColumns(A,{onlyVisible:!0});if(x.length||(x=e.outerColumns),0<s.size&&f.EXCLUDES_PSEUDOCOLUMNS_FROM_STAR&&(x=x.filter(S=>!s.has(S.toUpperCase()))),!x.length||x.includes("*"))return;let E=c.get(A)||new Set,b=n.get(A)||{},y=i.get(A)||{};if(d instanceof we){let S;if(p&&0<m.size?(S=x.filter(C=>!m.has(C)),S.push(...p)):S=d.aliasColumnNames,0<S.length){for(let C of S)E.has(C)||r.push(I(R({col:C,table:d.alias}),C,{copy:!1}));continue}}for(let S of x){if(E.has(S)||l.has(S))continue;let C=a.get(S);if(C?.includes(A)){l.add(S);let v=C.map(K=>R({col:S,table:K}));r.push(I(new xe({this:v[0],expressions:v.slice(1)}),S,{copy:!1}))}else{let v=b[S]??S,K=y[S]||R({col:S,table:A});r.push(v!==S?I(K,v,{copy:!1}):K)}}}}0<r.length&&e.expression instanceof w&&e.expression.setArgKey("expressions",r)}h(Fn,"expandStars_");function kn(e){let t;if(e instanceof q)t=e;else{let c=V(e);if(!(c instanceof q))return;t=c}if(!(t.expression instanceof w))return;let a=t.expression.selects,s=t.outerColumns,o=[],r=Math.max(a.length,s.length);for(let c=0;c<r;c++){let i=a[c],n=s[c];if(!i||i instanceof se)break;i instanceof P?i.outputName||i.setArgKey("alias",new F({this:_(`_col_${c}`)})):!(i instanceof Z)&&!(i instanceof Ss)&&!i.isStar&&(i=I(i,i.outputName||`_col_${c}`,{copy:!1})),n&&i.setArgKey("alias",_(n)),o.push(i)}0<o.length&&t.expression instanceof w&&t.expression.setArgKey("expressions",o)}h(kn,"qualifyOutputs");function un(e,t){let a=Number(t.args.this)-1,s=e.expression.selects[a];if(!(s instanceof Z))throw new J(`Unknown output column: ${t.name}`);return s}h(un,"selectByPos");function mn(e,t,a,s={}){let{alias:o=!1}=s,r=a._constructor,c=[],i;for(let n of t)if(n.isInteger){let l=un(e,n);if(o){let f=l.alias;c.push(f?R({col:f}):n)}else{let f=l.args.this,p=!1;r.PROJECTION_ALIASES_SHADOW_SOURCE_NAMES&&(i===void 0&&(i=new Set(e.expression.selects.map(m=>m.aliasOrName).filter(m=>m in e.selectedSources))),p=Array.from(f.findAll(O)).some(m=>i?.has(m.parts[0]?.name||""))),_s.some(m=>f instanceof m)||f.isNumber||f.find(Ue)||f.find(te)||p?c.push(n):c.push(f.copy())}}else c.push(n);return c}h(mn,"expandPositionalReferences");function Jn(e,t){let a=e.expression.args.group;if(!a)return;let s=qe(a.args.expressions||[],T);a.setArgKey("expressions",mn(e,s,t)),e.expression.setArgKey("group",a)}h(Jn,"expandGroupBy");function zn(e,t){for(let a of["order","distinct"]){let s=e.expression.getArgKey(a);if(s instanceof ys&&(s=s.args.on),!(s instanceof T))continue;let o=s.args.expressions;a==="order"&&(o=o.map(c=>c.args.this));let r=mn(e,o,t.dialect,{alias:!0});for(let c=0;c<o.length;c++){let i=o[c],n=r[c];for(let l of i.findAll(M))for(let f of l.findAll(O))if(!f.table){let p=t.getTable(f.name);p&&f.setArgKey("table",p)}i.replace(n)}if(e.expression.getArgKey("group")){let c=new Map(e.expression.selects.filter(i=>i instanceof Z).map(i=>[i.args.this.sql(),R({col:i.aliasOrName})]));for(let i of o)if(i.isInteger)i.replace(_(un(e,i).alias));else{let n=c.get(i.sql());n&&i.replace(n)}}}}h(zn,"expandOrderByAndDistinctOn");function We(e,t={}){let{dialect:a,identify:s=!0}=t,o=$.getOrRaise(a);return e.transform(o.quoteIdentifier.bind(o),{identify:s,copy:!1})}h(We,"quoteIdentifiers");function $n(e){for(let t of e.ctes){let a=t.aliasColumnNames;if(0<a.length&&t.args.this instanceof w){let s=t.args.this,o=s.args.expressions||[],r=[];for(let c=0;c<a.length;c++){let i=a[c],n=o[c];if(!n)break;let l;n instanceof Z?(n.setArgKey("alias",_(i)),l=n):l=I(n,i),r.push(l)}s.setArgKey("expressions",r)}}}h($n,"pushdownCteAliasColumns");function dn(e,t={}){let{db:a,catalog:s,onQualify:o,dialect:r,canonicalizeTableAliases:c=!1}=t,i=$.getOrRaise(r),n=_e("_"),l;a&&(l=ts(a,{dialect:i}),l.meta.isTable=!0,l=ie(l,{dialect:i}));let f;s&&(f=ts(s,{dialect:i}),f.meta.isTable=!0,f=ie(f,{dialect:i}));let p=h(d=>{d.args.this instanceof Q&&(l&&!d.args.db&&d.setArgKey("db",l.copy()),f&&!d.args.catalog&&d.args.db&&d.setArgKey("catalog",f.copy()))},"qualify");if((l||f)&&!(e instanceof Ae)){let u=e.getArgKey("with")||new Y({expressions:[]}),g=new Set((u.args.expressions||[]).map(A=>A.aliasOrName));for(let A of e.walk({prune:h(x=>x instanceof Ae,"prune")}))A instanceof U&&(g.has(A.name)||p(A))}let m=h((d,u,g={})=>{let{targetAlias:A,scope:x,normalize:E=!1,columns:b}=g,y=d.getArgKey("alias");y||(y=new F({}));let S;if(c)S=n(),u.set(y.name||A||"",S);else if(!y.name)S=A||n(),E&&A&&(S=ie(S,{dialect:i}).name);else return;y.setArgKey("this",_(S)),b&&y.setArgKey("columns",b.map(C=>_(C))),d.setArgKey("alias",y),x&&x.renameSource("",S)},"setAlias");for(let d of D(e)){let u=d.localColumns,g=new Map;for(let x of d.subqueries){let E=x.parent;E&&E instanceof P&&E.unwrap().replace(E)}for(let x of d.derivedTables){let E=x.unnest();if(E instanceof U){let y=E.args.joins;E.setArgKey("joins",void 0);let S=x.args.this;if(S instanceof T){let C=ue("*").from(E.copy(),{copy:!1});S.replace(C),C.setArgKey("joins",y)}}m(x,g,{scope:d});let b=L(x.getArgKey("pivots")||[],0);b&&m(b,g)}let A=new Map;for(let[x,E]of d.sources)if(E instanceof U){let b=!!x,y=E.args.pivots,S=y?L(y,0):void 0,C=x;S&&(C=E.name);let v=E.args.this,K=E.args.alias,k=[];if(v&&v instanceof ge){let cs=v.constructor.name;if(K)K instanceof F&&K.args.columns?.length?k=K.columns:i._constructor.DEFAULT_FUNCTIONS_COLUMN_NAMES.has(cs)&&(k=Array.from(Ye(E.aliasOrName)),E.setArgKey("alias",void 0),C="");else{let ls=i._constructor.DEFAULT_FUNCTIONS_COLUMN_NAMES.get(cs);k=ls?Array.from(Ye(ls)):[]}}m(E,g,{targetAlias:C||E.name||void 0,normalize:!0,columns:k});let ye=E.parts?.map(Ie=>Ie.name).join("."),as=E.args.alias?.args.this,En=K&&K.name;if(as instanceof Q&&(!En||!A.has(ye))&&A.set(ye,as.copy()),S){let Ie=S.getArgKey("unpivot")?E.alias:void 0;if(m(S,g,{targetAlias:Ie,normalize:!0}),d.sources.get(E.aliasOrName)instanceof q)continue}b&&(p(E),o&&o(E))}else if(E instanceof q&&E.isUdtf){let b=E.expression;if(m(b,g),b instanceof Me){let y=b.getArgKey("alias");y instanceof F&&!y.args.columns?.length&&y.setArgKey("columns",i.generateValuesAliases(b).map(S=>ie(S,{dialect:i})))}}for(let x of d.tables)if(!x.alias&&x.parent){let E=x.parent;(E instanceof z||E instanceof N)&&m(x,g,{targetAlias:x.name})}for(let x of u){let E=x.table;if(x.args.db){let b=x.parts.slice(0,-1).map(S=>S.name).join("."),y=A.get(b);y&&(x.setArgKey("table",void 0),x.setArgKey("db",void 0),x.setArgKey("catalog",void 0),x.setArgKey("table",y.copy()))}else if(0<g.size&&E){let b=g.get(E);b&&b!==x.table&&x.setArgKey("table",_(b))}}}return e}h(dn,"qualifyTables");function gn(e,t={}){let{dialect:a,db:s,catalog:o,schema:r,expandAliasRefs:c=!0,expandStars:i=!0,inferSchema:n,isolateTables:l=!1,qualifyColumns:f=!0,allowPartialQualification:p=!1,validateQualifyColumns:m=!0,quoteIdentifiers:d=!0,identify:u=!0,canonicalizeTableAliases:g=!1,onQualify:A,sql:x}=t,E=H(r,{dialect:a}),b=$.getOrRaise(a);return e=ie(e,{dialect:b,storeOriginalColumnIdentifiers:!0}),e=dn(e,{db:s,catalog:o,dialect:b,onQualify:A,canonicalizeTableAliases:g}),l&&(e=nn(e,{schema:E,dialect:b})),f&&(e=ln(e,{schema:E,expandAliasRefs:c,expandStars:i,inferSchema:n,allowPartialQualification:p})),d&&(e=We(e,{dialect:b,identify:u})),m&&fn(e,x),e}h(gn,"qualify");function xn(e){let t=_e("_u_");for(let a of D(e)){let s=a.expression,o=s.parentSelect;if(!o||!j(o,w)||!j(s,w))continue;let r=s;0<a.externalColumns.length?Qn(r,o,a.externalColumns,t):a.scopeType==="subquery"&&Bn(r,o,t)}return e}h(xn,"unnestSubqueries");function Bn(e,t,a){if(1<e.selects.length)return;let s=e.findAncestor(xs);if(!s||s instanceof ge&&(s.parent instanceof U||s.parent instanceof z||s.parent instanceof N)||t!==s.parentSelect||!t.args.from)return;let o=e;e instanceof ne&&(o=ue(e.selects).from(e.subquery(a()),{copy:!1}));let r=a(),c=s.findAncestor(ae,X,N);if(!(s instanceof pe||s instanceof he)){let u=R({col:o.selects[0].aliasOrName,table:r}),g=c?.parentSelect;if(c instanceof ae&&g===t||(!c||g!==t)&&(t.args.group||t.selects.some(E=>re(E,M))))u=new Oe({this:u});else if(!(e.parent instanceof P))return;let A="cross",x;s instanceof Ee&&(u=u.is(Je()).not(),A="left",x=B()),G(e.parent,u),t.join(o,{on:x,joinType:A,joinAlias:r,copy:!1});return}if(o.find([Te,Xe]))return;let i=s;if(s instanceof he){let u=s.findAncestor(W);if(!u||t!==u.parentSelect)return;i=u}let n=is(i),l=o.selects[0],f=l.args.this;if(!(f instanceof T))return;let p=R({col:l.alias,table:r}),m=p.is(Je()).not();c instanceof N?(G(i,B()),t.where(m,{copy:!1})):G(i,m);let d=o.args.group;if(d){let u=new Set((d.args.expressions??[]).map(g=>g instanceof T?g.sql():String(g)));(u.size!==1||!u.has(l.args.this.sql()))&&(o=ue(I(R({col:l.alias,table:"_q"}),l.alias,{copy:!1})).from(o.subquery("_q",{copy:!1}),{copy:!1}).groupBy(R({col:l.alias,table:"_q"}),{copy:!1}))}else re(f,M)||(o=o.groupBy(f,{copy:!1}));n&&t.join(o,{on:n.eq(p),joinType:"left",joinAlias:r,copy:!1})}h(Bn,"unnest");function Qn(e,t,a,s){let o=e.args.where;if(!o||o.find(Le)||e.find([Te,Xe]))return;let r=s(),c=[];for(let y of a){if(y.findAncestor(X)!==o)return;let S=y.findAncestor(Ve);if(!S||S.findAncestor(X)!==o)return;let C;if(S instanceof ee)C=Array.from(S.left?.walk()||[]).some(v=>v===y)?S.right:S.left;else return;if(!C)return;c.push([C,y,S])}if(!c.some(([,,y])=>y instanceof W))return;let i=t.selects.map(y=>y.unalias()).some(y=>y instanceof P&&y===e.parent),n=e.selects[0],l=n.args.this;if(!(l instanceof T))return;let f=new Map,p=new Map,m=new Set,d=[],u=h(y=>m.has(y.sql()),"exprInGroupBy");for(let[y,,S]of c){let C=y.sql();C===l.sql()?(f.set(C,n.alias),p.set(C,y),m.has(C)||(m.add(C),d.push(y))):(f.has(C)||(f.set(C,s()),p.set(C,y)),S instanceof W&&!m.has(C)&&(m.add(C),d.push(y)))}let g=e.findAncestor(Ve);if(g===void 0&&!i)return;let A=i?Oe:vs;!n.find(M)&&!u(l)&&e.select(I(new A({this:l}),n.alias,{quoted:!1}),{append:!1,copy:!1}),g instanceof Ee&&e.setArgKey("expressions",[]);for(let[y,S]of f){let C=p.get(y);m.has(y)?(g instanceof Ee||y!==n.args.this.sql())&&e.select(`${C} AS ${S}`,{copy:!1}):e.select(I(new A({this:C.copy()}),S,{quoted:!1}),{copy:!1})}let x=R({col:n.alias,table:r}),E=is(g),b=g?.parent?._constructor;if(g instanceof Ee)x=R({col:Array.from(f.values())[0],table:r}),g=G(g,`NOT ${x} IS NULL`);else if(g instanceof De){if(!b||!(b.prototype instanceof ee||b===ee))return;let y=new b({this:E,expression:R({col:"_x"})});g.parent&&(g=G(g.parent,`ARRAY_ALL(${x}, _x -> ${y})`))}else if(g instanceof he){if(!b||!(b.prototype instanceof ee||b===ee))return;if(u(n.args.this)){let y=new b({this:E,expression:x});g.parent&&(g=G(g.parent,y))}else{let y=new b({this:E,expression:R({col:"_x"})});g=G(g,`ARRAY_ANY(${x}, _x -> ${y})`)}}else if(g instanceof pe)u(n.args.this)?g=G(g,`${E} = ${x}`):g=G(g,`ARRAY_ANY(${x}, _x -> _x = ${g.args.this})`);else{if(i&&e.parent?.alias&&(x=I(x,e.parent.alias,{copy:!1})),n.find(ss)){let y=h(S=>S instanceof ss?ce.number(0):S instanceof M?Je():S,"removeAggs");x=new xe({this:x,expressions:[n.args.this.transform(y)]})}e.parent?.replace(x)}for(let[y,S,C]of c){C.replace(B());let v=f.get(y.sql());if(!v)continue;let K=R({col:v,table:r});if(i){y.replace(K),C instanceof W||t.where(C,{copy:!1});continue}u(y)?y.replace(K):C instanceof W?g&&(g=G(g,`(${g} AND ARRAY_CONTAINS(${K}, ${S}))`)):(y.replace(_("_x")),g&&(g=G(g,`(${g} AND ARRAY_ANY(${K}, _x -> ${C}))`)))}t.join(e.groupBy(d,{copy:!1}),{on:c.filter(([,,y])=>y instanceof W).map(([,,y])=>y),joinType:"left",joinAlias:r,copy:!1})}h(Qn,"decorrelate");function G(e,t){return e.replace(qs(t))}h(G,"replace");function is(e){if(e instanceof pe)return e.args.this;if(e instanceof he||e instanceof De)return is(e.parent);if(e instanceof ee)return e.left instanceof P||e.left instanceof he||e.left instanceof Ee||e.left instanceof De?e.right:e.left}h(is,"otherOperand");var Gn=[gn,sn,ms,xn,Xs,Ms,rs,Js,os,Us,We,Ge,js,Re];function $o(e,t={}){let{schema:a,db:s,catalog:o,dialect:r,rules:c=Gn,sql:i,isolateTables:n=!0,quoteIdentifiers:l=!1,...f}=t,p=H(a,{dialect:r}),m={db:s,catalog:o,schema:p,dialect:r,sql:i,isolateTables:n,quoteIdentifiers:l,...f},d=Rs(e,{dialect:r,copy:!0});for(let u of c)d=u(d,m);return d}h($o,"optimize");export{gn as a,Ls as b,$o as c};
4
- //# sourceMappingURL=chunk-ZZAKTBZ2.js.map
4
+ //# sourceMappingURL=chunk-CKAH73SV.js.map