sqlingo 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/chunk-253CRNX3.cjs +2 -0
  3. package/dist/chunk-253CRNX3.cjs.map +1 -0
  4. package/dist/chunk-3XSLMNQQ.js +19 -0
  5. package/dist/chunk-3XSLMNQQ.js.map +1 -0
  6. package/dist/chunk-45T22NWK.cjs +2 -0
  7. package/dist/{chunk-5NNVJ4H7.cjs.map → chunk-45T22NWK.cjs.map} +1 -1
  8. package/dist/chunk-5GVA4XPZ.cjs +2 -0
  9. package/dist/{chunk-6NDABX2K.cjs.map → chunk-5GVA4XPZ.cjs.map} +1 -1
  10. package/dist/{chunk-3AXRMSOM.js → chunk-6T7XKWKA.js} +2 -2
  11. package/dist/{chunk-H37TXOYX.js → chunk-7UEXD3RC.js} +2 -2
  12. package/dist/chunk-7XPPJ275.cjs +2 -0
  13. package/dist/{chunk-X6GBG5XG.cjs.map → chunk-7XPPJ275.cjs.map} +1 -1
  14. package/dist/chunk-CTSGJUVV.cjs +2 -0
  15. package/dist/{chunk-2NBCADTA.cjs.map → chunk-CTSGJUVV.cjs.map} +1 -1
  16. package/dist/{chunk-4GGZCF4M.js → chunk-DOCVJID4.js} +2 -2
  17. package/dist/{chunk-ZS3L5BUS.js → chunk-EBXKDF3U.js} +2 -2
  18. package/dist/chunk-EBXKDF3U.js.map +1 -0
  19. package/dist/{chunk-WDNJ5X7T.js → chunk-EO7P6GX2.js} +2 -2
  20. package/dist/{chunk-GOFHIRVB.js → chunk-FDZGJ5M3.js} +2 -2
  21. package/dist/chunk-GQS7NEWT.cjs +2 -0
  22. package/dist/{chunk-I3RBOQDO.cjs.map → chunk-GQS7NEWT.cjs.map} +1 -1
  23. package/dist/{chunk-UQR7VDWJ.js → chunk-GYC3WNMF.js} +2 -2
  24. package/dist/chunk-HF3BBINH.cjs +19 -0
  25. package/dist/chunk-HF3BBINH.cjs.map +1 -0
  26. package/dist/{chunk-UXKF3QRK.js → chunk-HN25JG4E.js} +2 -2
  27. package/dist/chunk-HVGOPPO6.cjs +2 -0
  28. package/dist/{chunk-SWPTLG2E.cjs.map → chunk-HVGOPPO6.cjs.map} +1 -1
  29. package/dist/{chunk-CFG73UXL.js → chunk-II6KO4YM.js} +2 -2
  30. package/dist/chunk-IZ6FO5XV.cjs +4 -0
  31. package/dist/{chunk-KKJ556AW.cjs.map → chunk-IZ6FO5XV.cjs.map} +1 -1
  32. package/dist/chunk-J3WE7VU2.cjs +2 -0
  33. package/dist/{chunk-XQG53TQM.cjs.map → chunk-J3WE7VU2.cjs.map} +1 -1
  34. package/dist/{chunk-GIZAGTDZ.js → chunk-NKTCFXES.js} +2 -2
  35. package/dist/chunk-NLMQEXP6.js +2 -0
  36. package/dist/chunk-NLMQEXP6.js.map +1 -0
  37. package/dist/chunk-OTPFZMI5.cjs +2 -0
  38. package/dist/{chunk-7T6422QK.cjs.map → chunk-OTPFZMI5.cjs.map} +1 -1
  39. package/dist/{chunk-2VXNMR6U.js → chunk-P4L2DZSO.js} +2 -2
  40. package/dist/chunk-P4L2DZSO.js.map +1 -0
  41. package/dist/{chunk-F4QS4D2O.js → chunk-Q6ZJFJGH.js} +2 -2
  42. package/dist/{chunk-F4QS4D2O.js.map → chunk-Q6ZJFJGH.js.map} +1 -1
  43. package/dist/{chunk-YGEJLTA7.js → chunk-QON2LPKU.js} +2 -2
  44. package/dist/chunk-SGMSSLF5.cjs +2 -0
  45. package/dist/{chunk-KOL64RQH.cjs.map → chunk-SGMSSLF5.cjs.map} +1 -1
  46. package/dist/{chunk-4SI6KRDO.js → chunk-TP2BCA77.js} +2 -2
  47. package/dist/{chunk-FSCGXYSR.js → chunk-TQ6CASZR.js} +2 -2
  48. package/dist/chunk-UZ6MAXLW.cjs +2 -0
  49. package/dist/{chunk-E3DG5GKS.cjs.map → chunk-UZ6MAXLW.cjs.map} +1 -1
  50. package/dist/{chunk-2CLRLOWZ.js → chunk-VNTZ5D4A.js} +2 -2
  51. package/dist/{chunk-2CLRLOWZ.js.map → chunk-VNTZ5D4A.js.map} +1 -1
  52. package/dist/chunk-VV4LMUMT.cjs +2 -0
  53. package/dist/{chunk-NDSBIRFZ.cjs.map → chunk-VV4LMUMT.cjs.map} +1 -1
  54. package/dist/chunk-WDQMMMTX.cjs +2 -0
  55. package/dist/{chunk-QIQQ2QJR.cjs.map → chunk-WDQMMMTX.cjs.map} +1 -1
  56. package/dist/{chunk-QFERDTPZ.cjs → chunk-YUVN3ZOA.cjs} +2 -2
  57. package/dist/{chunk-QFERDTPZ.cjs.map → chunk-YUVN3ZOA.cjs.map} +1 -1
  58. package/dist/{chunk-SLJIOLJ3.js → chunk-YXHFRUY4.js} +2 -2
  59. package/dist/chunk-Z6NSUNEB.cjs +2 -0
  60. package/dist/{chunk-VGJBK2L5.cjs.map → chunk-Z6NSUNEB.cjs.map} +1 -1
  61. package/dist/chunk-ZNCQ6OPU.cjs +3 -0
  62. package/dist/chunk-ZNCQ6OPU.cjs.map +1 -0
  63. package/dist/chunk-ZTQHO742.cjs +2 -0
  64. package/dist/{chunk-QS7IOBU6.cjs.map → chunk-ZTQHO742.cjs.map} +1 -1
  65. package/dist/dialects/athena.cjs +1 -1
  66. package/dist/dialects/athena.d.cts +1 -1
  67. package/dist/dialects/athena.d.ts +1 -1
  68. package/dist/dialects/athena.js +1 -1
  69. package/dist/dialects/bigquery.cjs +1 -1
  70. package/dist/dialects/bigquery.d.cts +1 -1
  71. package/dist/dialects/bigquery.d.ts +1 -1
  72. package/dist/dialects/bigquery.js +1 -1
  73. package/dist/dialects/clickhouse.cjs +1 -1
  74. package/dist/dialects/clickhouse.cjs.map +1 -1
  75. package/dist/dialects/clickhouse.d.cts +1 -1
  76. package/dist/dialects/clickhouse.d.ts +1 -1
  77. package/dist/dialects/clickhouse.js +1 -1
  78. package/dist/dialects/clickhouse.js.map +1 -1
  79. package/dist/dialects/databricks.cjs +1 -1
  80. package/dist/dialects/databricks.cjs.map +1 -1
  81. package/dist/dialects/databricks.d.cts +1 -1
  82. package/dist/dialects/databricks.d.ts +1 -1
  83. package/dist/dialects/databricks.js +1 -1
  84. package/dist/dialects/databricks.js.map +1 -1
  85. package/dist/dialects/doris.cjs +1 -1
  86. package/dist/dialects/doris.d.cts +1 -1
  87. package/dist/dialects/doris.d.ts +1 -1
  88. package/dist/dialects/doris.js +1 -1
  89. package/dist/dialects/dremio.cjs +1 -1
  90. package/dist/dialects/dremio.cjs.map +1 -1
  91. package/dist/dialects/dremio.d.cts +1 -1
  92. package/dist/dialects/dremio.d.ts +1 -1
  93. package/dist/dialects/dremio.js +1 -1
  94. package/dist/dialects/dremio.js.map +1 -1
  95. package/dist/dialects/drill.cjs +1 -1
  96. package/dist/dialects/drill.d.cts +1 -1
  97. package/dist/dialects/drill.d.ts +1 -1
  98. package/dist/dialects/drill.js +1 -1
  99. package/dist/dialects/druid.cjs +1 -1
  100. package/dist/dialects/druid.d.cts +1 -1
  101. package/dist/dialects/druid.d.ts +1 -1
  102. package/dist/dialects/druid.js +1 -1
  103. package/dist/dialects/duckdb.cjs +13 -13
  104. package/dist/dialects/duckdb.cjs.map +1 -1
  105. package/dist/dialects/duckdb.d.cts +5 -2
  106. package/dist/dialects/duckdb.d.ts +5 -2
  107. package/dist/dialects/duckdb.js +13 -13
  108. package/dist/dialects/duckdb.js.map +1 -1
  109. package/dist/dialects/dune.cjs +1 -1
  110. package/dist/dialects/dune.d.cts +1 -1
  111. package/dist/dialects/dune.d.ts +1 -1
  112. package/dist/dialects/dune.js +1 -1
  113. package/dist/dialects/exasol.cjs +1 -1
  114. package/dist/dialects/exasol.d.cts +1 -1
  115. package/dist/dialects/exasol.d.ts +1 -1
  116. package/dist/dialects/exasol.js +1 -1
  117. package/dist/dialects/fabric.cjs +1 -1
  118. package/dist/dialects/fabric.d.cts +1 -1
  119. package/dist/dialects/fabric.d.ts +1 -1
  120. package/dist/dialects/fabric.js +1 -1
  121. package/dist/dialects/hive.cjs +1 -1
  122. package/dist/dialects/hive.d.cts +2 -2
  123. package/dist/dialects/hive.d.ts +2 -2
  124. package/dist/dialects/hive.js +1 -1
  125. package/dist/dialects/materialize.cjs +1 -1
  126. package/dist/dialects/materialize.d.cts +1 -1
  127. package/dist/dialects/materialize.d.ts +1 -1
  128. package/dist/dialects/materialize.js +1 -1
  129. package/dist/dialects/mysql.cjs +1 -1
  130. package/dist/dialects/mysql.d.cts +2 -2
  131. package/dist/dialects/mysql.d.ts +2 -2
  132. package/dist/dialects/mysql.js +1 -1
  133. package/dist/dialects/oracle.cjs +1 -1
  134. package/dist/dialects/oracle.d.cts +1 -1
  135. package/dist/dialects/oracle.d.ts +1 -1
  136. package/dist/dialects/oracle.js +1 -1
  137. package/dist/dialects/postgres.cjs +1 -1
  138. package/dist/dialects/postgres.d.cts +1 -1
  139. package/dist/dialects/postgres.d.ts +1 -1
  140. package/dist/dialects/postgres.js +1 -1
  141. package/dist/dialects/presto.cjs +1 -1
  142. package/dist/dialects/presto.d.cts +1 -1
  143. package/dist/dialects/presto.d.ts +1 -1
  144. package/dist/dialects/presto.js +1 -1
  145. package/dist/dialects/prql.cjs +1 -1
  146. package/dist/dialects/prql.cjs.map +1 -1
  147. package/dist/dialects/prql.d.cts +1 -1
  148. package/dist/dialects/prql.d.ts +1 -1
  149. package/dist/dialects/prql.js +1 -1
  150. package/dist/dialects/prql.js.map +1 -1
  151. package/dist/dialects/redshift.cjs +1 -1
  152. package/dist/dialects/redshift.cjs.map +1 -1
  153. package/dist/dialects/redshift.d.cts +1 -1
  154. package/dist/dialects/redshift.d.ts +1 -1
  155. package/dist/dialects/redshift.js +1 -1
  156. package/dist/dialects/redshift.js.map +1 -1
  157. package/dist/dialects/risingwave.cjs +1 -1
  158. package/dist/dialects/risingwave.d.cts +1 -1
  159. package/dist/dialects/risingwave.d.ts +1 -1
  160. package/dist/dialects/risingwave.js +1 -1
  161. package/dist/dialects/singlestore.cjs +1 -1
  162. package/dist/dialects/singlestore.d.cts +1 -1
  163. package/dist/dialects/singlestore.d.ts +1 -1
  164. package/dist/dialects/singlestore.js +1 -1
  165. package/dist/dialects/snowflake.cjs +2 -2
  166. package/dist/dialects/snowflake.cjs.map +1 -1
  167. package/dist/dialects/snowflake.d.cts +15 -12
  168. package/dist/dialects/snowflake.d.ts +15 -12
  169. package/dist/dialects/snowflake.js +2 -2
  170. package/dist/dialects/snowflake.js.map +1 -1
  171. package/dist/dialects/solr.cjs +1 -1
  172. package/dist/dialects/solr.d.cts +1 -1
  173. package/dist/dialects/solr.d.ts +1 -1
  174. package/dist/dialects/solr.js +1 -1
  175. package/dist/dialects/spark.cjs +1 -1
  176. package/dist/dialects/spark.d.cts +1 -1
  177. package/dist/dialects/spark.d.ts +1 -1
  178. package/dist/dialects/spark.js +1 -1
  179. package/dist/dialects/spark2.cjs +1 -1
  180. package/dist/dialects/spark2.d.cts +1 -1
  181. package/dist/dialects/spark2.d.ts +1 -1
  182. package/dist/dialects/spark2.js +1 -1
  183. package/dist/dialects/sqlite.cjs +1 -1
  184. package/dist/dialects/sqlite.d.cts +1 -1
  185. package/dist/dialects/sqlite.d.ts +1 -1
  186. package/dist/dialects/sqlite.js +1 -1
  187. package/dist/dialects/starrocks.cjs +1 -1
  188. package/dist/dialects/starrocks.d.cts +1 -1
  189. package/dist/dialects/starrocks.d.ts +1 -1
  190. package/dist/dialects/starrocks.js +1 -1
  191. package/dist/dialects/tableau.cjs +1 -1
  192. package/dist/dialects/tableau.d.cts +1 -1
  193. package/dist/dialects/tableau.d.ts +1 -1
  194. package/dist/dialects/tableau.js +1 -1
  195. package/dist/dialects/teradata.cjs +1 -1
  196. package/dist/dialects/teradata.cjs.map +1 -1
  197. package/dist/dialects/teradata.d.cts +1 -4
  198. package/dist/dialects/teradata.d.ts +1 -4
  199. package/dist/dialects/teradata.js +1 -1
  200. package/dist/dialects/teradata.js.map +1 -1
  201. package/dist/dialects/trino.cjs +1 -1
  202. package/dist/dialects/trino.d.cts +1 -1
  203. package/dist/dialects/trino.d.ts +1 -1
  204. package/dist/dialects/trino.js +1 -1
  205. package/dist/dialects/tsql.cjs +1 -1
  206. package/dist/dialects/tsql.d.cts +2 -2
  207. package/dist/dialects/tsql.d.ts +2 -2
  208. package/dist/dialects/tsql.js +1 -1
  209. package/dist/index.cjs +5 -5
  210. package/dist/index.cjs.map +1 -1
  211. package/dist/index.d.cts +2 -2
  212. package/dist/index.d.ts +2 -2
  213. package/dist/index.js +2 -2
  214. package/dist/index.js.map +1 -1
  215. package/dist/{tokens-C2JqKsrn.d.ts → tokens-qxb1e_iq.d.cts} +27 -4
  216. package/dist/{tokens-C2JqKsrn.d.cts → tokens-qxb1e_iq.d.ts} +27 -4
  217. package/package.json +5 -3
  218. package/dist/chunk-2NBCADTA.cjs +0 -2
  219. package/dist/chunk-2VXNMR6U.js.map +0 -1
  220. package/dist/chunk-5NNVJ4H7.cjs +0 -2
  221. package/dist/chunk-6NDABX2K.cjs +0 -2
  222. package/dist/chunk-7T6422QK.cjs +0 -2
  223. package/dist/chunk-APZJ7NQO.js +0 -19
  224. package/dist/chunk-APZJ7NQO.js.map +0 -1
  225. package/dist/chunk-E3DG5GKS.cjs +0 -2
  226. package/dist/chunk-I3RBOQDO.cjs +0 -2
  227. package/dist/chunk-KKJ556AW.cjs +0 -4
  228. package/dist/chunk-KOL64RQH.cjs +0 -2
  229. package/dist/chunk-NDSBIRFZ.cjs +0 -2
  230. package/dist/chunk-QIQQ2QJR.cjs +0 -2
  231. package/dist/chunk-QS7IOBU6.cjs +0 -2
  232. package/dist/chunk-SWPTLG2E.cjs +0 -2
  233. package/dist/chunk-USQPYV24.cjs +0 -3
  234. package/dist/chunk-USQPYV24.cjs.map +0 -1
  235. package/dist/chunk-VGJBK2L5.cjs +0 -2
  236. package/dist/chunk-VWKXWLP5.cjs +0 -19
  237. package/dist/chunk-VWKXWLP5.cjs.map +0 -1
  238. package/dist/chunk-WKFDSPAW.js +0 -2
  239. package/dist/chunk-WKFDSPAW.js.map +0 -1
  240. package/dist/chunk-WT5MI6B6.cjs +0 -2
  241. package/dist/chunk-WT5MI6B6.cjs.map +0 -1
  242. package/dist/chunk-X6GBG5XG.cjs +0 -2
  243. package/dist/chunk-XQG53TQM.cjs +0 -2
  244. package/dist/chunk-ZS3L5BUS.js.map +0 -1
  245. /package/dist/{chunk-3AXRMSOM.js.map → chunk-6T7XKWKA.js.map} +0 -0
  246. /package/dist/{chunk-H37TXOYX.js.map → chunk-7UEXD3RC.js.map} +0 -0
  247. /package/dist/{chunk-4GGZCF4M.js.map → chunk-DOCVJID4.js.map} +0 -0
  248. /package/dist/{chunk-WDNJ5X7T.js.map → chunk-EO7P6GX2.js.map} +0 -0
  249. /package/dist/{chunk-GOFHIRVB.js.map → chunk-FDZGJ5M3.js.map} +0 -0
  250. /package/dist/{chunk-UQR7VDWJ.js.map → chunk-GYC3WNMF.js.map} +0 -0
  251. /package/dist/{chunk-UXKF3QRK.js.map → chunk-HN25JG4E.js.map} +0 -0
  252. /package/dist/{chunk-CFG73UXL.js.map → chunk-II6KO4YM.js.map} +0 -0
  253. /package/dist/{chunk-GIZAGTDZ.js.map → chunk-NKTCFXES.js.map} +0 -0
  254. /package/dist/{chunk-YGEJLTA7.js.map → chunk-QON2LPKU.js.map} +0 -0
  255. /package/dist/{chunk-4SI6KRDO.js.map → chunk-TP2BCA77.js.map} +0 -0
  256. /package/dist/{chunk-FSCGXYSR.js.map → chunk-TQ6CASZR.js.map} +0 -0
  257. /package/dist/{chunk-SLJIOLJ3.js.map → chunk-YXHFRUY4.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import{a as Ma}from"../chunk-WDNJ5X7T.js";import"../chunk-YGEJLTA7.js";import{$d as Ms,$i as Ir,$m as ln,$q as hs,$r as At,$w as Ia,Ad as wt,Al as Wr,Am as sn,Aq as ai,Ar as fi,Aw as Ra,Bi as Zt,Bl as ss,Bm as en,Bn as On,Bo as j,Bq as ls,Br as Ai,Bt as Me,Cj as Hs,Cn as Pn,Co as le,Cq as oi,Cr as xi,Ct as Qi,Dd as rr,Dj as yr,Dk as zt,Dl as es,Dm as se,Dn as Cn,Do as kn,Dp as ge,Dq as Re,Dr as Ri,Du as M,Ef as Sr,Ei as xr,Ek as Gr,Ep as fe,Eq as Ei,Er as di,Fi as ht,Fj as jt,Fk as Fr,Fn as ne,Fo as ue,Fv as na,Fw as da,Gh as Ds,Gi as Z,Gj as Tt,Gk as Ur,Gl as js,Gn as Mn,Gq as de,Gv as ds,Gw as ma,Hc as Jt,He as pr,Hj as Bs,Hn as yn,Ho as Vn,Hp as zn,Hv as Ct,If as bs,Ik as Hr,Io as Kn,Ir as mi,Is as qi,Jb as Je,Ji as _t,Jk as Ut,Jl as Qs,Jm as rn,Jn as qn,Jo as Wn,Jq as me,Ju as qe,Ke as ys,Kj as Ys,Kl as $r,Kn as bn,Kq as Ne,Kr as Ni,Ks as bi,Kv as be,Lj as qr,Lq as Ie,Lr as Ii,Ls as Di,Lu as f,Ma as Nt,Me as cr,Mi as q,Mj as St,Mn as as,Mq as we,Mu as ta,Mv as ia,Nj as gt,Nv as x,Oe as Et,Oj as Gt,Om as nn,Op as ti,Ov as aa,Pi as Y,Pk as Ht,Pl as rs,Pr as wi,Pu as sa,Ql as Bt,Qn as Dn,Qr as tt,Qu as ea,Qv as oa,Rb as Ze,Rd as nr,Re as qs,Ri as Rr,Rk as R,Rl as Jr,Rn as ie,Rp as si,Rr as _i,Rs as vt,Rw as Na,Sa as m,Sb as je,Sj as F,Sl as Zr,Sm as ns,So as he,Sr as Li,Ss as Gi,St as zi,Sv as Ea,Sw as Mt,Tb as Qe,Tf as gr,Ti as dr,Tk as W,Tm as ee,Tq as pi,Tr as Oi,Ts as Fi,Uc as Cs,Ue as lr,Ul as $,Um as an,Un as Gn,Uq as _e,Ur as Pi,Us as Ui,Vc as sr,Vi as mr,Vj as Ft,Vl as T,Vm as re,Vp as ei,Vq as ci,We as ur,Wj as w,Wk as Br,Wq as li,Ws as Hi,Xh as Ar,Xj as br,Xk as Yr,Xm as on,Xn as ae,Xr as Ci,Xs as Bi,Yc as It,Ye as hr,Ym as En,Yn as Fn,Yq as us,Ys as Yi,Zi as Nr,Zj as Qt,Zm as pn,Zn as os,Zv as pa,_a as Os,_m as cn,_n as oe,_r as Ts,_s as vi,_t as ye,_u as b,a as p,ab as We,ae as C,ao as Un,ap as $n,aw as ca,ax as wa,b as yt,bc as ze,bj as Gs,bn as un,c as qt,cc as tr,ce as ir,cj as wr,cn as hn,co as Hn,cp as Es,cr as Pt,cs as Pe,ct as Xi,cu as kt,cw as De,cx as _a,d as bt,dm as jr,dn as Tn,dp as Jn,du as xs,dw as la,e as S,em as Yt,en as Sn,eo as Bn,ep as Te,ew as ua,fm as Qr,fn as gn,fo as Yn,fr as ui,ft as ki,fv as X,ge as ar,gm as Ot,gt as Vi,gu as xt,gw as ha,hn as fn,hp as Zn,hw as Ge,hx as He,ib as $t,ic as Dt,ij as I,in as An,it as Ki,iu as H,ix as La,jb as Ps,jf as B,jn as xn,jq as ps,jt as Xt,jv as Rs,ke as or,kj as _r,kn as Rn,kt as Wi,kx as Oa,le as Er,lh as fr,lj as Fs,ll as Vs,ln as dn,lr as hi,ls as Ss,lt as $i,lw as Fe,mf as Tr,mj as Lr,ml as Ks,mn,mq as z,mr as Ti,ms as gs,mt as Ji,mx as Pa,nb as $e,ne as l,nj as Or,nn as Nn,no as Ee,np as jn,ns as Ce,ob as U,oj as Pr,oo as vn,os as Mi,ot as Zi,ow as Ta,pj as pt,pt as ji,pw as Sa,q as K,ql as Ws,qm as zr,qo as pe,qw as ga,qx as Ca,rg as a,rl as $s,ro as ce,rr as ft,ru as st,s as g,sd as rt,sl as vr,sn as is,so as Xn,sp as Qn,su as it,tj as Us,tl as ts,tw as fa,tx as Vt,uj as Cr,uk as vs,ul as Xr,um as zs,uq as ri,uu as d,uw as Aa,vd as er,vj as v,vl as kr,vn as In,vq as Ae,vr as Si,vt as fs,vw as Ue,wb as N,wj as Mr,wk as Xs,wl as Js,wn,wp as Q,wq as cs,wr as Le,wt as As,xl as Zs,xm as tn,xn as _n,xq as xe,yj as Lt,yk as ks,yl as Vr,yn as Ln,yq as ni,yr as Oe,ys as yi,yw as xa,zi as nt,zk as Dr,zl as Kr,zm as te,zp as Se,zq as ii,zr as gi,zv as ra}from"../chunk-APZJ7NQO.js";var eE=/:\d{2}.*?[+\-]\d{2}(?::\d{2})?/,ya={"\\":"\\\\","-":"\\-","^":"\\^","[":"\\[","]":"\\]"},rE="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",nE=123456,ms={"\v":11,"":28,"":29,"":30,"":31},ws={MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6,SUNDAY:7},iE=a.number(32768),aE=M("(ROW_NUMBER() OVER (ORDER BY 1) - 1)"),oE=new Map([[me,1],[Ne,2],[Ie,4],[we,8]]),EE=[or,sr,Rr,wt,nt];function Jo(n,o,s={}){let{reverse:t=!1}=s;if(o instanceof a&&o.isString){let r=o.args.this??"";for(let i=0;i<Math.min(3,r.length);i++){let E="+/="[i],c=r[i]??"";if(c!==E){let[u,A]=t?[c,E]:[E,c];n=new Ei({this:n,expression:a.string(u),replacement:a.string(A)})}}}return n}p(Jo,"applyBase64AlphabetReplacements");function qa(n,o){let{toString:s=!1}=o,t=n.args.this,e=n.args.alphabet;return t=Jo(t??f(),e,{reverse:!0}),t=new Un({this:t}),s&&(t=new as({this:t})),this.sql(t)}p(qa,"base64DecodeSql");function pE(n){let o=n.args.this,s=n.text("unit").toUpperCase();if(!s||s==="MONTH")return this.func("LAST_DAY",[o]);if(s==="YEAR"){let t=d("EXTRACT","YEAR",o),e=d("MAKE_DATE",t,a.number(12),a.number(31));return this.sql(e)}if(s==="QUARTER"){let t=d("EXTRACT","YEAR",o),e=d("EXTRACT","QUARTER",o),r=new gt({this:e,expression:a.number(3)}),i=d("MAKE_DATE",t,r,a.number(1)),E=d("LAST_DAY",i);return this.sql(E)}if(s==="WEEK"){let t=d("EXTRACT","DAYOFWEEK",o),e=new St({this:new w({this:new F({this:a.number(7),expression:t})}),expression:a.number(7)}),r=new Y({this:e,unit:new C({this:"DAY"})}),i=new I({this:o,expression:r});return this.sql(it(i,"date"))}return this.unsupported(`Unsupported date part '${s}' in LAST_DAY function`),this.functionFallbackSql(n)}p(pE,"lastDaySql");function Ke(n){return(n instanceof C||n instanceof a)&&n.name.toUpperCase()==="NANOSECOND"}p(Ke,"isNanosecondUnit");function Zo(n,o){let s=new T({this:n,to:new l({this:"timestampNs"})}),t=new T({this:o,to:new l({this:"timestampNs"})});return this.sql(new F({this:this.func("EPOCH_NS",[s]),expression:this.func("EPOCH_NS",[t])}))}p(Zo,"handleNanosecondDiff");function cE(n){let o=n.args.this,s=n.args.safe??!1,t=new $({}).when(new Ts({this:new T({this:o,to:new l({this:"varchar"})})}).eq(a.string("ON")),new Z({this:!0})).when(new Ts({this:new T({this:o,to:new l({this:"varchar"})})}).eq(a.string("OFF")),new Z({this:!1})),e;if(s)e=t.else(d("TRY_CAST",o,l.build("BOOLEAN")));else{let r=d("TRY_CAST",o,l.build("REAL")),i=new Xt({this:d("ISNAN",r),expression:d("ISINF",r)});e=t.when(i,d("ERROR",a.string("TO_BOOLEAN: Non-numeric values NaN and INF are not supported"))).else(new T({this:o,to:new l({this:"boolean"})}))}return this.sql(e)}p(cE,"toBooleanSql");function lE(n){let o=n.args.this,s=this.sql(n,"zone");if(s){o=new T({this:o,to:new l({this:"timestamp"})});let t=new Et({this:o,zone:a.string("UTC")});o=new Et({this:t,zone:s})}return this.sql(new T({this:o,to:new l({this:"date"})}))}p(lE,"dateSql");function uE(n){let o=n.args.unit;if(Ke(o))return Zo.call(this,n.args.expression??f(),n.args.this??f());let s=new T({this:n.args.this,to:new l({this:"time"})}),t=new T({this:n.args.expression,to:new l({this:"time"})});return this.func("DATE_DIFF",[Mt(n),t,s])}p(uE,"timeDiffSql");function at(n={}){let{cast:o=!0}=n,s=Na({cast:o});return function(t){let e=K(t.getArgKey("unit"),"string",N),r=t.args.expression;if(Ke(e instanceof N?e:void 0)){r instanceof Y&&(r=r.args.this);let i=new T({this:K(t.args.this,"string",N),to:new l({this:"timestampNs"})});return this.sql(this.func("MAKE_TIMESTAMP_NS",[new I({this:this.func("EPOCH_NS",[i]),expression:K(r,"string",N)})]))}return!r||r instanceof Y?s.call(this,t):(X(r,l.REAL_TYPES)&&t.setArgKey("expression",new T({this:this.func("ROUND",[r]),to:new l({this:"int"})})),s.call(this,t))}}p(at,"dateDeltaToBinaryIntervalOp");function hE(n){let o=n.args.this,s=n.args.position,t=n.args.expression,e=new W({expressions:[t??f()]}),r=n.args.offset??0;if(!s?.isNumber)return this.unsupported("ARRAY_INSERT can only be transpiled with a literal position"),this.func("ARRAY_INSERT",[o,s,t]);let i=s.toValue();0<i?i-=r:i<0&&(i+=r);let E;if(i===0)E=[e,o??f()];else if(0<i){let c=new q({this:o,expressions:[new B({this:a.number(1),expression:a.number(i)})]}),u=new q({this:o,expressions:[new B({this:a.number(i+1)})]});E=[c,e,u]}else{let c=new Q({this:o}),u=new I({this:c,expression:a.number(i)}),A=new I({this:u,expression:a.number(1)}),L=new q({this:o,expressions:[new B({this:a.number(1),expression:u})]}),O=new q({this:o,expressions:[new B({this:A})]});E=[L,e,O]}return this.sql(new j({this:new Tt({this:o,expression:f()}),true:f(),false:this.func("LIST_CONCAT",E)}))}p(hE,"arrayInsertSql");function TE(n){let o=n.args.this,s=n.args.position;if(!s?.isNumber)return this.unsupported("ARRAY_REMOVE_AT can only be transpiled with a literal position"),this.func("ARRAY_REMOVE_AT",[o,s]);let t=s.toValue(),e;if(t===0)e=new q({this:o,expressions:[new B({this:a.number(2)})]});else if(0<t){let r=new q({this:o,expressions:[new B({this:a.number(1),expression:a.number(t)})]}),i=new q({this:o,expressions:[new B({this:a.number(t+2)})]});e=this.func("LIST_CONCAT",[r,i])}else if(t===-1){let r=new Q({this:o}),i=new I({this:r,expression:a.number(-1)});e=new q({this:o,expressions:[new B({this:a.number(1),expression:i})]})}else{let r=new Q({this:o}),i=new I({this:r,expression:a.number(t)}),E=new I({this:i,expression:a.number(2)}),c=new q({this:o,expressions:[new B({this:a.number(1),expression:i})]}),u=new q({this:o,expressions:[new B({this:E})]});e=this.func("LIST_CONCAT",[c,u])}return this.sql(new j({this:new Tt({this:o,expression:f()}),true:f(),false:e}))}p(TE,"arrayRemoveAtSql");function SE(n){return n.args.expression&&this.unsupported("DuckDB's ARRAY_SORT does not support a comparator."),this.func("ARRAY_SORT",[n.args.this])}p(SE,"arraySortSql");function ba(n){return new us({this:m(n,0),asc:new Z({this:!1})})}p(ba,"buildSortArrayDesc");function Da(n){return new $s({this:m(n,1),expression:m(n,0)})}p(Da,"buildArrayPrepend");function Ga(n){return new re({this:m(n,2),expression:m(n,1),unit:m(n,0)})}p(Ga,"buildDateDiff");function Fa(n={}){let{endExclusive:o=!1}=n;return s=>{s.length===1&&s.unshift(a.number("0"));let t=Vs.fromArgList(s);return t.setArgKey("isEndExclusive",o),t}}p(Fa,"buildGenerateSeries");function gE(n){return n.length===1?new tt({this:m(n,0),scale:tt.MICROS}):new Ci({year:m(n,0),month:m(n,1),day:m(n,2),hour:m(n,3),min:m(n,4),sec:m(n,5)})}p(gE,"buildMakeTimestamp");function Ua(...n){return function(){return this.parseShowDuckdb(n[0])}}p(Ua,"showParser");function fE(n){let o=n.findAncestor(T,nt);if(o=o instanceof nt?void 0:o,(!n.args.expressions||n.args.expressions.length===0)&&o instanceof T&&X(o.args.to,"map"))return"MAP()";let s=[],t=!n.find(Lt)&&o instanceof T&&[...o.findAll(l)].some(r=>X(r,"struct"));n.args.expressions?.forEach((r,i)=>{let E=r instanceof Lt,c=r.args.this,u=E?r.args.expression:r;if(t)s.push(this.sql(u));else{let A;c instanceof It?A=this.sql(a.string(r.name)):E?A=this.sql(r.args.this):A=this.sql(a.string(`_${i}`)),s.push(`${A}: ${this.sql(u)}`)}});let e=s.join(", ");return t?`ROW(${e})`:`{${e}}`}p(fE,"structSql");function AE(n){if(X(n,"array")){let o=this.expressions(n,{flat:!0}),s=this.expressions(n,{key:"values",flat:!0});return`${o}[${s}]`}if(X(n,["time","timetz","timestamptz"])){let o=n.args.this;return o instanceof N?o.name:o?We(o):""}return Ct.prototype.dataTypeSql.call(this,n)}p(AE,"dataTypeSql");function xE(n){return`CAST(${this.func("TO_JSON",[n.args.this,n.args.options])} AS TEXT)`}p(xE,"jsonFormatSql");function jo(n,o,s){let t=o*8,e=a.number((2n**BigInt(t)).toString());if(s){let r=a.number((2n**BigInt(t-1)).toString());return b(Kt.SEQ_SIGNED.copy(),[],{base:n,maxVal:e,half:r})}return b(Kt.SEQ_UNSIGNED.copy(),[],{base:n,maxVal:e})}p(jo,"buildSeqExpression");function RE(n){if(!(n instanceof nt))return n;let o=n.args.from;return!o||!(o.args.this instanceof wr)||!(o.args.this.args.this instanceof Ks)?n:n.transform(s=>{let t=oE.get(s._constructor);return t!==void 0?jo(new bs({this:H("range")}),t,s.name==="1"):s},{copy:!1})}p(RE,"seqToRangeInGenerator");function Ns(n,o){let s=n.findAncestor(...EE);s&&(!(s instanceof wt||s instanceof nt)||s instanceof wt&&s.parent instanceof Zt)&&this.unsupported("SEQ in restricted context is not supported - use CTE or subquery");let t=jo(aE.copy(),o,n.name==="1");return this.sql(t)}p(Ns,"seqSql");function dE(n){let o=n.args.scale,s=o?.toValue(),t=n.args.this,e=n.args.targetType,r=X(e,["timestamp","timestampntz"]);if(s===tt.MILLIS.toValue())return this.func("EPOCH_MS",[t]);if(s===tt.MICROS.toValue())return this.func("MAKE_TIMESTAMP",[t]);s!==void 0&&s!==tt.SECONDS.toValue()&&(t=new pt({this:t,expression:d("POW",a.number(10),o)}));let i=new R({this:"TO_TIMESTAMP",expressions:[t??f()]});return r&&(i=new Et({this:i,zone:a.string("UTC")})),this.sql(i)}p(dE,"unixToTimeSql");var mE=[_t,q,Qt,Ft];function Ha(n){let o=oa.call(this,n);return!n.sameParent&&mE.some(s=>n.parent instanceof s)&&(o=this.wrap(o)),o}p(Ha,"arrowJsonExtractSqlDuckDB");function dt(n,o="date"){if(n instanceof a&&n.isString){let s=n.args.this??"",t=o;return o==="date"&&s.includes(":")&&(t=eE.test(s)?"timestamptz":"timestamp"),new T({this:n,to:new l({this:t})})}return n}p(dt,"implicitDatetimeCast");function Qo(n){if(n instanceof C&&"ISOWEEK".includes(n.name.toUpperCase()))return 1;if(n instanceof Tr)return ws[n.name.toUpperCase()]}p(Qo,"weekUnitToDow");function Ye(n,o,s={}){let{preserveStartDay:t=!1}=s,e=o===7?1:1-o,r=d("DATE_TRUNC",new C({this:"WEEK"}),n);if(e===0)return r;let i=new Y({this:a.string(e.toString()),unit:new C({this:"DAY"})}),E=new ns({this:n,expression:i});if(r.setArgKey("this",E),t){let c=new Y({this:a.string((-e).toString()),unit:new C({this:"DAY"})});return it(new ns({this:r,expression:c}),"date")}return r}p(Ye,"buildWeekTruncExpression");function Ba(n){let o=n.args.unit;if(Ke(o))return Zo.call(this,n.args.this??f(),n.args.expression??f());let s=dt(n.args.this),t=dt(n.args.expression),e=n.args.datePartBoundary,r=Qo(o);return e&&r!==void 0&&s&&t&&(n.setArgKey("unit",a.string("WEEK")),s=Ye(s,r),t=Ye(t,r)),this.func("DATE_DIFF",[Mt(n),t,s])}p(Ba,"dateDiffSql");function Ya(n){let o=n instanceof Ee,s=o?"date":"timestamp",t=dt(n.args.start,s),e=dt(n.args.end,s),r=new Vs({start:t,end:e,step:n.args.step});return o&&(r=new T({this:r,to:l.build("ARRAY<DATE>")})),this.sql(r)}p(Ya,"generateDatetimeArraySql");function va(n){let o=n.args.expression instanceof N?n.args.expression:void 0,s=new Es({this:n.args.this,expression:o}),t=n instanceof he?"ARRAY<STRING>":"ARRAY<JSON>";return this.sql(new T({this:s,to:l.build(t)}))}p(va,"jsonExtractValueArraySql");function et(n){if(n!==void 0)return n instanceof N&&n.type&&!X(n,[...l.TEXT_TYPES,"unknown"])?new T({this:n,to:new l({this:"varchar"})}):n instanceof N?n:a.string(n.toString())}p(et,"castToVarchar");function ve(n){return n&&!X(n,"boolean")?new T({this:n,to:new l({this:"boolean"})}):n}p(ve,"castToBoolean");function J(n){return X(n,["binary","varbinary","blob"])}p(J,"isBinary");function ct(n,o){if(J(n)){let s=l.build("BLOB",{dialect:"duckdb"});o=this.sql(new T({this:o,to:s}))}return o}p(ct,"genWithCastToBlob");function Xe(n){if(!J(n))return n;let o=n;return n instanceof Sr&&(o=new Ii({this:a.string(n.args.this)})),new T({this:o,to:new l({this:"bit"})})}p(Xe,"castToBit");function Xa(n){n.args.this instanceof N&&J(n.args.this)&&n.setArgKey("this",Xe(n.args.this)),n.args.expression instanceof N&&J(n.args.expression)&&n.setArgKey("expression",Xe(n.args.expression))}p(Xa,"prepareBinaryBitwiseArgs");function ka(n){let o=n.args.this,s=n.args.expression,t=d("ISODOW",o),e;if(s instanceof a){let i=(s.args.this??"").toUpperCase(),E=Object.keys(ws).find(c=>c.startsWith(i));if(E)e=a.number(ws[E]);else return this.functionFallbackSql(n)}else{let i=new Ts({this:s});e=new $({ifs:Object.entries(ws).map(([E,c])=>new j({this:this.func("STARTS_WITH",[i.copy(),a.string(E.substring(0,2))]),true:a.number(c)}))})}let r;if(n instanceof Pe){let i=xt(e.sub(t).add(6),{copy:!1}),E=new St({this:i,expression:a.number(7)}).add(1);r=new I({this:o,expression:new Y({this:E,unit:new C({this:"DAY"})})})}else{let i=xt(t.sub(e).add(6),{copy:!1}),E=new St({this:i,expression:a.number(7)}).add(1);r=new F({this:o,expression:new Y({this:E,unit:new C({this:"DAY"})})})}return this.sql(new T({this:r,to:new l({this:"date"})}))}p(ka,"dayNavigationSql");function NE(n){let o=n.args.this;if(o instanceof ur){let s=o.args.max?"ARG_MAX_NULL":"ARG_MIN_NULL";return this.func(s,[o.args.this,o.args.expression])}return this.functionFallbackSql(n)}p(NE,"anyValueSql");function Be(n){let o="BIT_XOR";n instanceof gs?o="BIT_OR":n instanceof Ss&&(o="BIT_AND");let s=n.args.this;return X(s,[...l.REAL_TYPES,...l.TEXT_TYPES])&&(X(s,l.FLOAT_TYPES)&&(s=this.func("ROUND",[s])),s=new T({this:s,to:new l({this:"int"})})),this.func(o,[s])}p(Be,"bitwiseAggSql");function IE(n){let o=n.split("");if(!o.some(i=>i in ms))return this.sql(a.string(n));let s=[],t=[],e=!1;for(let i of o){let E=i in ms;E!==e&&(0<t.length&&(e?t.forEach(c=>s.push(this.func("CHR",[a.number(ms[c])]))):s.push(this.sql(a.string(t.join(""))))),t=[],e=E),t.push(i)}0<t.length&&(e?t.forEach(i=>s.push(this.func("CHR",[a.number(ms[i])]))):s.push(this.sql(a.string(t.join("")))));let r=s.join(" || ");return s.length===1?r:`(${r})`}p(IE,"literalSqlWithWsChr");function wE(n,o){if(!n)return o;if(n instanceof a&&n.isString){let e=(n.args.this??"").split("").map(r=>ya[r]??r).join("");return IE.call(this,e)}let s=o;return Object.entries(ya).forEach(([t,e])=>{s=this.func("REPLACE",[s,this.sql(a.string(t)),this.sql(a.string(e))])}),s}p(wE,"escapeRegexMetachars");function _E(n,o){if(o==="''")return`UPPER(LEFT(${n}, 1)) || LOWER(SUBSTRING(${n}, 2))`;let s=`CONCAT('[', ${o}, ']')`,t=`CONCAT('([', ${o}, ']+|[^', ${o}, ']+)')`;return this.func("ARRAY_TO_STRING",[new $({}).when(`REGEXP_MATCHES(LEFT(${n}, 1), ${s})`,this.func("LIST_TRANSFORM",[this.func("REGEXP_EXTRACT_ALL",[n,t]),"(seg, idx) -> CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END"])).else(this.func("LIST_TRANSFORM",[this.func("REGEXP_EXTRACT_ALL",[n,t]),"(seg, idx) -> CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END"])),"''"])}p(_E,"buildCapitalizationSql");function LE(n){let o=this.sql(n,"this"),s=n.args.expression;s||(s=a.string(this.dialect._constructor.INITCAP_DEFAULT_DELIMITER_CHARS));let t=this.sql(s),e=wE.call(this,s,t);return _E.call(this,o,e)}p(LE,"initcapSql");function OE(n){return this.sql(new v({this:new Xi({this:ve(n.args.this)??n.args.this}),expression:a.number(1)}))}p(OE,"boolxorAggSql");function Va(n){let o=n instanceof Fs?"<<":">>",s=!1,t=n.args.this;t instanceof N&&J(t)?(s=!0,n.setArgKey("this",it(t,"bit"))):n.args.requiresInt128&&t instanceof N&&t.replace(it(t,"int128"));let e=this.binary(n,o);return n.parent instanceof _t&&(e=`(${e})`),s&&(e=this.sql(new T({this:e,to:l.build("BLOB",{dialect:"duckdb"})}))),e}p(Va,"bitshiftSql");function PE(n,o){let s=n.args.decimals;if(!s||n.args.to)return;let t=n.args.this;t instanceof _t&&(t=new w({this:t}));let e=s.isInteger||s.isType([...l.INTEGER_TYPES])?s:new T({this:s,to:new l({this:"int"})}),r=new ps({this:a.number("10"),expression:e}),i=new o({this:new gt({this:t,expression:r})}),E=new pt({this:i,expression:r.copy()});return this.roundSql(new de({this:E,decimals:s,castsNonIntegerDecimals:!0}))}p(PE,"scaleRoundingSql");function Ka(n){let o=PE.call(this,n,n._constructor);return o!==void 0?o:this.ceilFloor(n)}p(Ka,"ceilFloor");function Wa(n){let o=n.args.this??f(),s=n.args.expression??f(),t,e,r;n instanceof Me?(t=o,e=s,r="expression"):(t=s,e=o,r="this");let i=e.type;if(!i||typeof i=="string"||i.args.this==="unknown")try{let u=Nt(n.copy(),{dialect:this.dialect}).args[r];i=u instanceof N?u.type:void 0}catch{}(!i||typeof i=="string"||i.args.this==="unknown")&&(i=l.build("DOUBLE"));let E=new T({this:f(),to:i});return this.sql(new j({this:new Tt({this:t.copy(),expression:f()}),true:E,false:e.copy()}))}p(Wa,"regrValSql");function CE(n){let o=n;for(;o instanceof Zt||o instanceof Jt;)o=o.args.this??f();if(!(!(o instanceof At)||!o.args.nullOnZeroVariance))return o.setArgKey("nullOnZeroVariance",!1),n}p(CE,"maybeCorrNullToFalse");function ME(n){let o=n.args.year,s=n.args.month,t=n.args.day;if(n.args.allowOverflow){let e=new R({this:"MAKE_DATE",expressions:[o??f(),a.number(1),a.number(1)]});return s&&(e=new I({this:e,expression:new Y({this:new F({this:qe(s,_t),expression:a.number(1)}),unit:new C({this:"MONTH"})})})),t&&(e=new I({this:e,expression:new Y({this:new F({this:qe(t,_t),expression:a.number(1)}),unit:new C({this:"DAY"})})})),this.sql(new T({this:e,to:new l({this:"date"})}))}return this.func("MAKE_DATE",[o,s,t])}p(ME,"dateFromPartsSql");function mt(n,o){return o?new de({this:n,decimals:a.number(0)}):n}p(mt,"roundArg");function yE(n){let o=mt(n.args.this??f(),n.args.roundInput);return this.sql(new Ft({this:new w({this:o})}))}p(yE,"boolnotSql");function qE(n){let o=n.args.roundInput,s=mt(n.args.this??f(),o),t=mt(n.args.expression??f(),o);return this.sql(new w({this:new Ki({this:new w({this:s}),expression:new w({this:t})})}))}p(qE,"boolandSql");function bE(n){let o=n.args.roundInput,s=mt(n.args.this??f(),o),t=mt(n.args.expression??f(),o);return this.sql(new w({this:new Xt({this:new w({this:s}),expression:new w({this:t})})}))}p(bE,"boolorSql");function DE(n){let o=n.args.roundInput,s=n.args.this&&mt(n.args.this,o),t=n.args.expression&&mt(n.args.expression,o);return this.sql(xs([xt(kt([s?.copy(),xt(t.not())],{wrap:!1})),xt(kt([xt(s.not()),t?.copy()],{wrap:!1}))],{wrap:!1}))}p(DE,"xorSql");function Is(n,o,s={}){let{isBinary:t=!1}=s,e=n.args.this;o==="SHA256"&&(n.text("length")||"256")!=="256"&&this.unsupported("DuckDB only supports SHA256 hashing algorithm."),e instanceof N&&e.type&&(!(e.type instanceof N)||e.type.args.this!=="unknown")&&!e.isType(l.TEXT_TYPES)&&!J(e)&&(e=new T({this:e,to:new l({this:"varchar"})}));let r=this.func(o,[e]);return t?this.func("UNHEX",[r]):r}p(Is,"shaSql");var $a,Ja,Za,ja,Qa,za,to,lt,k=class k extends(to=Vt,za=[g],Qa=[g],ja=[g],Za=[g],Ja=[g],$a=[g],to){static get BYTE_STRINGS(){return[["e'","'"],["E'","'"]]}static get BYTE_STRING_ESCAPES(){return["'","\\"]}static get HEREDOC_STRINGS(){return["$"]}static get ORIGINAL_KEYWORDS(){let s={...Vt.KEYWORDS,"//":"div","**":"dstar","^@":"caretAt","@>":"atGt","<@":"ltAt",ATTACH:"attach",BINARY:"varbinary",BITSTRING:"bit",BPCHAR:"text",CHAR:"text",DATETIME:"timestampntz",DETACH:"detach",FORCE:"force",INSTALL:"install",INT8:"bigint",LOGICAL:"boolean",MACRO:"function",ONLY:"only",PIVOT_WIDER:"pivot",POSITIONAL:"positional",RESET:"command",ROW:"struct",SIGNED:"int",STRING:"text",SUMMARIZE:"summarize",TIMESTAMP:"timestampntz",TIMESTAMP_S:"timestampS",TIMESTAMP_MS:"timestampMs",TIMESTAMP_NS:"timestampNs",TIMESTAMP_US:"timestamp",UBIGINT:"ubigint",UINTEGER:"uint",USMALLINT:"usmallint",UTINYINT:"utinyint",VARCHAR:"text"};return delete s["/*+"],s}static get SINGLE_TOKENS(){return{...Vt.SINGLE_TOKENS,$:"parameter"}}static get COMMANDS(){let s=new Set(Vt.COMMANDS);return s.delete("show"),s}};lt=yt(to),S(lt,10,"BYTE_STRINGS",za,k),S(lt,10,"BYTE_STRING_ESCAPES",Qa,k),S(lt,10,"HEREDOC_STRINGS",ja,k),S(lt,10,"ORIGINAL_KEYWORDS",Za,k),S(lt,10,"SINGLE_TOKENS",Ja,k),S(lt,10,"COMMANDS",$a,k),qt(lt,k),bt(lt,3,k),p(k,"DuckDBTokenizer"),k.HEREDOC_TAG_IS_IDENTIFIER=!0,k.HEREDOC_STRING_ALTERNATIVE="parameter";var ke=k,so,eo,ro,no,io,ao,oo,Eo,po,co,lo,uo,ho,To,So,go,D,y=class y extends(go=U,So=[g],To=[g],ho=[g],uo=[g],lo=[g],co=[g],po=[g],Eo=[g],oo=[g],ao=[g],io=[g],no=[g],ro=[g],eo=[g],so=[g],go){static get NO_PAREN_FUNCTIONS(){let s={...U.NO_PAREN_FUNCTIONS};return s.sessionUser=nn,s.currentCatalog=rn,s}static get BITWISE(){return(()=>{let s={...U.BITWISE};return delete s.caret,s})()}static get RANGE_PARSERS(){return{...U.RANGE_PARSERS,damp:$t(rs),caretAt:$t(ui),tilde:$t(ii)}}static get EXPONENT(){return{...U.EXPONENT,caret:ps,dstar:ps}}static get FUNCTIONS_WITH_ALIASED_ARGS(){return new Set([...U.FUNCTIONS_WITH_ALIASED_ARGS,"STRUCT_PACK"])}static get SHOW_PARSERS(){return{TABLES:Ua("TABLES"),"ALL TABLES":Ua("ALL TABLES")}}static get FUNCTIONS(){return(()=>{let s={...U.FUNCTIONS,ANY_VALUE:p(t=>new lr({this:vt.fromArgList(t)}),"ANY_VALUE"),APPROX_QUANTILE:p(t=>ye.fromArgList(t),"APPROX_QUANTILE"),ARRAY_PREPEND:Da,ARRAY_INTERSECT:p(t=>new $r({expressions:t}),"ARRAY_INTERSECT"),ARRAY_REVERSE_SORT:ba,ARRAY_SORT:p(t=>us.fromArgList(t),"ARRAY_SORT"),BIT_AND:p(t=>Ss.fromArgList(t),"BIT_AND"),BIT_OR:p(t=>gs.fromArgList(t),"BIT_OR"),BIT_XOR:p(t=>Ce.fromArgList(t),"BIT_XOR"),DATEDIFF:Ga,DATE_DIFF:Ga,DATE_TRUNC:p(t=>Fe([m(t,0),m(t,1)]),"DATE_TRUNC"),DATETRUNC:p(t=>Fe([m(t,0),m(t,1)]),"DATETRUNC"),DECODE:p(t=>new as({this:m(t,0),charset:a.string("utf-8")}),"DECODE"),EDITDIST3:p(t=>Se.fromArgList(t),"EDITDIST3"),ENCODE:p(t=>new ie({this:m(t,0),charset:a.string("utf-8")}),"ENCODE"),EPOCH:p(t=>Oe.fromArgList(t),"EPOCH"),EPOCH_MS:p(t=>new tt({this:m(t,0),scale:tt.MILLIS}),"EPOCH_MS"),GENERATE_SERIES:Fa(),GET_CURRENT_TIME:p(t=>te.fromArgList(t),"GET_CURRENT_TIME"),GET_BIT:p(t=>new pe({this:m(t,0),expression:m(t,1),zeroIsMsb:!0}),"GET_BIT"),JARO_WINKLER_SIMILARITY:p(t=>ks.fromArgList(t),"JARO_WINKLER_SIMILARITY"),JSON:p(t=>jn.fromArgList(t),"JSON"),JSON_EXTRACT_PATH:Ps(Es),JSON_EXTRACT_STRING:Ps(Te),LIST_APPEND:p(t=>Ws.fromArgList(t),"LIST_APPEND"),LIST_CONCAT:$e,LIST_CONTAINS:p(t=>ss.fromArgList(t),"LIST_CONTAINS"),LIST_COSINE_DISTANCE:p(t=>vs.fromArgList(t),"LIST_COSINE_DISTANCE"),LIST_DISTANCE:p(t=>Xs.fromArgList(t),"LIST_DISTANCE"),LIST_FILTER:p(t=>es.fromArgList(t),"LIST_FILTER"),LIST_HAS:p(t=>ss.fromArgList(t),"LIST_HAS"),LIST_HAS_ANY:p(t=>rs.fromArgList(t),"LIST_HAS_ANY"),LIST_PREPEND:Da,LIST_REVERSE_SORT:ba,LIST_SORT:p(t=>us.fromArgList(t),"LIST_SORT"),LIST_TRANSFORM:p(t=>Ht.fromArgList(t),"LIST_TRANSFORM"),LIST_VALUE:p(t=>new W({expressions:t}),"LIST_VALUE"),MAKE_DATE:p(t=>ne.fromArgList(t),"MAKE_DATE"),MAKE_TIME:p(t=>Mn.fromArgList(t),"MAKE_TIME"),MAKE_TIMESTAMP:gE,QUANTILE_CONT:p(t=>fs.fromArgList(t),"QUANTILE_CONT"),QUANTILE_DISC:p(t=>As.fromArgList(t),"QUANTILE_DISC"),RANGE:Fa({endExclusive:!0}),REGEXP_EXTRACT:He(ri),REGEXP_EXTRACT_ALL:He(Ae),REGEXP_MATCHES:p(t=>xe.fromArgList(t),"REGEXP_MATCHES"),REGEXP_REPLACE:p(t=>new cs({this:m(t,0),expression:m(t,1),replacement:m(t,2),modifiers:m(t,3),singleReplace:!0}),"REGEXP_REPLACE"),SHA256:p(t=>new _e({this:m(t,0),length:a.number(256)}),"SHA256"),STRFTIME:Ge(Le,{dialect:"duckdb"}),STRING_SPLIT:p(t=>hs.fromArgList(t),"STRING_SPLIT"),STRING_SPLIT_REGEX:p(t=>ls.fromArgList(t),"STRING_SPLIT_REGEX"),STRING_TO_ARRAY:p(t=>hs.fromArgList(t),"STRING_TO_ARRAY"),STRPTIME:Ge(hi,{dialect:"duckdb"}),STRUCT_PACK:p(t=>ft.fromArgList(t),"STRUCT_PACK"),STR_SPLIT:p(t=>hs.fromArgList(t),"STR_SPLIT"),STR_SPLIT_REGEX:p(t=>ls.fromArgList(t),"STR_SPLIT_REGEX"),TIME_BUCKET:p(t=>ee.fromArgList(t),"TIME_BUCKET"),LIST_MAX:p(t=>Js.fromArgList(t),"LIST_MAX"),LIST_MIN:p(t=>Zs.fromArgList(t),"LIST_MIN"),CURRENT_LOCALTIMESTAMP:p(t=>en.fromArgList(t),"CURRENT_LOCALTIMESTAMP"),TODAY:p(t=>tn.fromArgList(t),"TODAY"),TO_TIMESTAMP:p(t=>tt.fromArgList(t),"TO_TIMESTAMP"),UNNEST:p(t=>ae.fromArgList(t),"UNNEST"),VERSION:p(t=>zs.fromArgList(t),"VERSION"),XOR:ma(Pr)};return delete s.DATE_SUB,delete s.GLOB,s})()}static get FUNCTION_PARSERS(){return(()=>{let s={...U.FUNCTION_PARSERS,...Object.fromEntries(["GROUP_CONCAT","LISTAGG","STRINGAGG"].map(t=>[t,function(){return this.parseStringAgg()}]))};return delete s.DECODE,s})()}static get NO_PAREN_FUNCTION_PARSERS(){return{...U.NO_PAREN_FUNCTION_PARSERS,MAP:p(function(){return this.parseMap()},"MAP"),"@":p(function(){return new Ut({this:this.parseBitwise()})},"@")}}static get ID_VAR_TOKENS(){return new Set([...U.ID_VAR_TOKENS,"straightJoin"])}static get TABLE_ALIAS_TOKENS(){return(()=>{let s=new Set(U.TABLE_ALIAS_TOKENS);return s.delete("semi"),s.delete("anti"),s.add("straightJoin"),s})()}static get PLACEHOLDER_PARSERS(){return{...U.PLACEHOLDER_PARSERS,parameter:function(){return this.match("number")||this.matchSet(this._constructor.ID_VAR_TOKENS)?this.expression(xr,{this:this.prev?.text}):void 0}}}static get TYPE_CONVERTERS(){return{decimal:_a(18,3),text:()=>l.build("TEXT")??new l({this:"text"})}}static get STATEMENT_PARSERS(){return{...U.STATEMENT_PARSERS,attach:function(){return this.parseAttachDetach()},detach:function(){return this.parseAttachDetach({isAttach:!1})},force:function(){return this.parseForce()},install:function(){return this.parseInstall()},show:function(){return this.parseShow()}}}static get SET_PARSERS(){return{...U.SET_PARSERS,VARIABLE:p(function(){return this.parseSetItemAssignment({kind:"VARIABLE"})},"VARIABLE")}}parseLambda(s={}){let t=this.index;if(!this.matchTextSeq("LAMBDA"))return super.parseLambda(s);let e=this.parseCsv(()=>this.parseLambdaArg());if(!this.match("colon")){this.retreat(t);return}let r=this.replaceLambda(this.parseAssignment(),e);return this.expression(rt,{this:r,expressions:e,colon:!0})}parseExpression(){if(this.next&&this.next.tokenType==="colon"){let s=this.parseIdVar({tokens:this._constructor.ALIAS_TOKENS});this.match("colon");let t=this.prevComments??[],e=this.parseAssignment();return e instanceof N&&(t=[...t,...e.popComments()??[]]),this.expression(ys,{comments:t,this:e,alias:s})}return super.parseExpression()}parseTable(s={}){let t,e=[];this.next&&this.next.tokenType==="colon"&&(t=this.parseTableAlias({aliasTokens:s.aliasTokens??this._constructor.TABLE_ALIAS_TOKENS}),this.match("colon"),e=this.prevComments??[]);let r=super.parseTable(s);return r instanceof N&&t instanceof Dt&&(e=[...e,...r.popComments()??[]],t.comments=[...t.popComments()??[],...e],r.setArgKey("alias",t)),r}parseTableSample(s={}){let t=super.parseTableSample(s);return t&&!t.args.method&&(t.args.size?t.setArgKey("method",new C({this:"RESERVOIR"})):t.setArgKey("method",new C({this:"SYSTEM"}))),t}parseBracket(s){let t=super.parseBracket(s);return this.dialect.version.major<=1&&this.dialect.version.minor<=2&&(this.dialect.version.major!==1||this.dialect.version.minor!==2)&&t instanceof q&&t.setArgKey("returnsListForMaps",!0),t}parseMap(){if(this.match("lBrace",{advance:!1}))return this.expression(fe,{this:this.parseBracket()});let s=this.parseWrappedCsv(()=>this.parseAssignment());return this.expression(ge,{keys:m(s,0),values:m(s,1)})}parseStructTypes(s={}){return this.parseFieldDef()}pivotColumnNames(s){return s.length===1?super.pivotColumnNames(s):da(s,{dialect:"duckdb"})}parseAttachDetach(s={}){let{isAttach:t=!0}=s,e=p(()=>this.expression(pr,{this:this.parseVar({anyToken:!0}),expression:this.parseField({anyToken:!0})}),"parseAttachOption");this.match("database");let r=this.parseExists({not:t}),i=this.parseAlias(this.parsePrimaryOrVar(),{explicit:!0}),E;return this.match("lParen",{advance:!1})&&(E=this.parseWrappedCsv(e)),t?this.expression(Ze,{this:i,exists:r,expressions:E}):this.expression(je,{this:i,exists:r})}parseShowDuckdb(s){return this.expression(ze,{this:s})}parseForce(){return this.match("install")?this.parseInstall({force:!0}):this.parseAsCommand(this.prev)}parseInstall(s={}){return this.expression(Qe,{this:this.parseIdVar(),from:this.match("from")?this.parseVarOrString():void 0,force:s.force??!1})}parsePrimary(){return this.matchPair("hash","number")?new hr({this:a.number(this.prev?.text||0)}):super.parsePrimary()}};D=yt(go),S(D,10,"NO_PAREN_FUNCTIONS",So,y),S(D,10,"BITWISE",To,y),S(D,10,"RANGE_PARSERS",ho,y),S(D,10,"EXPONENT",uo,y),S(D,10,"FUNCTIONS_WITH_ALIASED_ARGS",lo,y),S(D,10,"SHOW_PARSERS",co,y),S(D,10,"FUNCTIONS",po,y),S(D,10,"FUNCTION_PARSERS",Eo,y),S(D,10,"NO_PAREN_FUNCTION_PARSERS",oo,y),S(D,10,"ID_VAR_TOKENS",ao,y),S(D,10,"TABLE_ALIAS_TOKENS",io,y),S(D,10,"PLACEHOLDER_PARSERS",no,y),S(D,10,"TYPE_CONVERTERS",ro,y),S(D,10,"STATEMENT_PARSERS",eo,y),S(D,10,"SET_PARSERS",so,y),qt(D,y),bt(D,3,y),p(y,"DuckDBParser"),y.MAP_KEYS_ARE_ARBITRARY_EXPRESSIONS=!0;var Ve=y,fo,Ao,xo,Ro,mo,No,Io,wo,_o,Lo,Oo,Po,Co,Mo,yo,qo,bo,Do,Go,Fo,Uo,Ho,Bo,Yo,vo,_,h=class h extends(vo=Ct,Yo=[g],Bo=[g],Ho=[g],Uo=[g],Fo=[g],Go=[g],Do=[g],bo=[g],qo=[g],yo=[g],Mo=[g],Co=[g],Po=[g],Oo=[g],Lo=[g],_o=[g],wo=[g],Io=[g],No=[g],mo=[g],Ro=[g],xo=[g],Ao=[g],fo=[g],vo){static get STRTOK_TEMPLATE(){return M(`
1
+ import{a as ya}from"../chunk-EO7P6GX2.js";import"../chunk-QON2LPKU.js";import{$d as ys,$m as cn,$n as pe,$r as Ss,$s as Yi,$t as zi,$u as b,Ad as wt,Ai as nt,Ak as Dr,Al as Kr,Am as ee,Ap as fe,Aq as ii,Ar as gi,Av as ra,Bl as Wr,Bm as sn,Bq as ai,Br as fi,Bw as Ra,Ci as jt,Cl as es,Cm as en,Cn as On,Co as Q,Cq as us,Cr as Ai,Ct as qe,Dd as nr,Dj as Ys,Dn as Pn,Do as he,Dq as oi,Dr as xi,Dt as ji,Ef as Sr,Ej as Mr,Ek as ts,El as rs,Em as re,En as Cn,Eo as Xn,Ep as Ae,Eq as me,Er as Ri,Eu as y,Fi as xr,Fk as Gr,Fp as xe,Fq as Ei,Fr as di,Gi as it,Gj as Qt,Gk as Fr,Gn as ae,Go as Te,Gv as na,Gw as da,Hc as Gt,He as pr,Hh as Fs,Hi as j,Hj as at,Hk as Ur,Hl as zs,Hn as yn,Hq as Ne,Hv as ds,Hw as ma,If as Ds,Ij as vs,In as Mn,Io as Vn,Ip as zn,Iv as Ct,Jb as Ze,Jk as Hr,Jo as Kn,Jr as mi,Js as qi,Ke as qs,Ki as _t,Kk as Ut,Kl as te,Km as rn,Kn as qn,Ko as Wn,Kq as Ie,Ku as be,Lj as ks,Ll as $r,Ln as bn,Lq as we,Lr as Ni,Ls as bi,Lv as De,Ma as Nt,Me as cr,Mj as qr,Mq as _e,Mr as Ii,Mu as f,Ni as q,Nj as St,Nn as os,Nq as Le,Nu as ta,Nv as ia,Oe as ct,Oj as gt,Ov as R,Pj as Ft,Pm as nn,Pp as ti,Pv as aa,Qi as Y,Qk as Ht,Ql as ns,Qr as wi,Qu as sa,Rb as je,Rd as ir,Re as bs,Rl as Bt,Rn as Dn,Rr as st,Ru as ea,Rv as oa,Sa as m,Sb as Qe,Si as Rr,Sk as d,Sl as Jr,Sn as oe,Sp as si,Sr as _i,Ss as kt,Sw as Na,Tb as ze,Tf as gr,Tj as F,Tl as Zr,Tm as is,To as Se,Tr as Li,Ts as Di,Tt as Qi,Tv as Ea,Tw as yt,Uc as Cs,Ue as lr,Ui as dr,Uk as W,Um as ne,Uq as pi,Ur as Oi,Us as Gi,Vc as er,Vl as $,Vm as an,Vn as Gn,Vq as Oe,Vr as Pi,Vs as Fi,We as ur,Wi as mr,Wj as Ot,Wl as T,Wm as ie,Wp as ei,Wq as ci,Xj as L,Xk as Br,Xq as li,Xs as Ui,Yc as It,Ye as hr,Yh as Ar,Yj as br,Yk as Yr,Ym as on,Yn as Ee,Yr as Ci,Ys as Hi,Zg as Gs,Zm as En,Zn as Fn,Zq as hs,Zs as Bi,_a as Os,_i as Nr,_j as zt,_m as pn,_n as Es,_v as pa,a as p,ab as $e,ae as C,aj as Ir,an as ln,ar as Ts,as as At,ax as Ia,b as Mt,bc as tr,bo as Un,bp as $n,bw as ca,bx as wa,c as qt,cc as sr,ce as ar,cj as Us,cn as un,d as bt,dj as wr,dn as hn,do as Hn,dp as ps,dr as Pt,ds as ye,dt as vi,du as Vt,dw as Ge,dx as _a,e as S,em as jr,en as Tn,ep as Jn,eu as Kt,ew as la,fm as Yt,fn as Sn,fo as Bn,fp as ge,fw as ua,ge as or,gm as Qr,gn,go as Yn,gr as ui,gt as ki,gv as k,hm as vt,ht as Xi,hu as xt,hw as ha,ib as Zt,ic as Dt,in as fn,ip as Zn,iw as Fe,ix as Be,jb as Ps,jf as B,jj as I,jn as An,jt as Vi,ju as H,jx as La,ke as Ms,kn as xn,kq as cs,kt as Xt,kv as Rs,le as Er,lj as _r,ln as Rn,lt as Ki,lx as Oa,mf as Tr,mh as fr,mj as Hs,ml as Ws,mn as dn,mr as hi,ms as gs,mt as Wi,mw as Ue,nb as Je,ne as l,nj as Lr,nl as $s,nn as mn,nq as tt,nr as Ti,ns as fs,nt as $i,nx as Pa,ob as U,oj as Or,on as Nn,oo as ce,op as jn,os as Me,pj as Pr,po as vn,ps as yi,pt as Ji,pw as Ta,q as K,qj as lt,qt as Zi,qw as Sa,rg as a,rl as Js,rm as zr,ro as le,rw as ga,rx as Ca,s as g,sd as rt,sl as Zs,so as ue,sr as ft,su as J,tl as vr,tn as as,to as kn,tp as Qn,tu as ot,uj as Bs,ul as ss,uw as fa,ux as Wt,vd as rr,vj as Cr,vk as Xs,vl as kr,vm as se,vq as ri,vu as x,vw as Aa,wb as N,wj as v,wl as Xr,wn as In,wq as Re,wr as Si,wt as As,ww as He,xj as yr,xk as Vs,xl as js,xn as wn,xp as z,xq as ls,xr as Pe,xt as xs,yl as Qs,ym as tn,yn as _n,yq as de,zj as Lt,zk as Ks,zl as Vr,zn as Ln,zq as ni,zr as Ce,zs as Mi,zw as xa}from"../chunk-3XSLMNQQ.js";var eE=/:\d{2}.*?[+\-]\d{2}(?::\d{2})?/,Ma={"\\":"\\\\","-":"\\-","^":"\\^","[":"\\[","]":"\\]"},rE="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",nE=123456,ms={"\v":11,"":28,"":29,"":30,"":31},ws={MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6,SUNDAY:7},iE=a.number(32768),aE=y("(ROW_NUMBER() OVER (ORDER BY 1) - 1)"),oE=new Map([[Ie,1],[we,2],[_e,4],[Le,8]]),EE=[Ms,er,Rr,wt,nt];function Jo(n,o,s={}){let{reverse:t=!1}=s;if(o instanceof a&&o.isString){let r=o.args.this??"";for(let i=0;i<Math.min(3,r.length);i++){let E="+/="[i],c=r[i]??"";if(c!==E){let[u,A]=t?[c,E]:[E,c];n=new Ei({this:n,expression:a.string(u),replacement:a.string(A)})}}}return n}p(Jo,"applyBase64AlphabetReplacements");function qa(n,o){let{toString:s=!1}=o,t=n.args.this,e=n.args.alphabet;return t=Jo(t??f(),e,{reverse:!0}),t=new Un({this:t}),s&&(t=new os({this:t})),this.sql(t)}p(qa,"base64DecodeSql");function pE(n){let o=n.args.this,s=n.text("unit").toUpperCase();if(!s||s==="MONTH")return this.func("LAST_DAY",[o]);if(s==="YEAR"){let t=x("EXTRACT","YEAR",o),e=x("MAKE_DATE",t,a.number(12),a.number(31));return this.sql(e)}if(s==="QUARTER"){let t=x("EXTRACT","YEAR",o),e=x("EXTRACT","QUARTER",o),r=new gt({this:e,expression:a.number(3)}),i=x("MAKE_DATE",t,r,a.number(1)),E=x("LAST_DAY",i);return this.sql(E)}if(s==="WEEK"){let t=x("EXTRACT","DAYOFWEEK",o),e=new St({this:new L({this:new F({this:a.number(7),expression:t})}),expression:a.number(7)}),r=new Y({this:e,unit:new C({this:"DAY"})}),i=new I({this:o,expression:r});return this.sql(ot(i,"date"))}return this.unsupported(`Unsupported date part '${s}' in LAST_DAY function`),this.functionFallbackSql(n)}p(pE,"lastDaySql");function We(n){return(n instanceof C||n instanceof a)&&n.name.toUpperCase()==="NANOSECOND"}p(We,"isNanosecondUnit");function Zo(n,o){let s=new T({this:n,to:new l({this:"timestampNs"})}),t=new T({this:o,to:new l({this:"timestampNs"})});return this.sql(new F({this:this.func("EPOCH_NS",[s]),expression:this.func("EPOCH_NS",[t])}))}p(Zo,"handleNanosecondDiff");function cE(n){let o=n.args.this,s=n.args.safe??!1,t=new $({}).when(new Ss({this:new T({this:o,to:new l({this:"varchar"})})}).eq(a.string("ON")),new j({this:!0})).when(new Ss({this:new T({this:o,to:new l({this:"varchar"})})}).eq(a.string("OFF")),new j({this:!1})),e;if(s)e=t.else(x("TRY_CAST",o,l.build("boolean")));else{let r=x("TRY_CAST",o,l.build("float")),i=new Xt({this:x("ISNAN",r),expression:x("ISINF",r)});e=t.when(i,x("ERROR",a.string("TO_BOOLEAN: Non-numeric values NaN and INF are not supported"))).else(new T({this:o,to:new l({this:"boolean"})}))}return this.sql(e)}p(cE,"toBooleanSql");function lE(n){let o=n.args.this,s=this.sql(n,"zone");if(s){o=new T({this:o,to:new l({this:"timestamp"})});let t=new ct({this:o,zone:a.string("UTC")});o=new ct({this:t,zone:s})}return this.sql(new T({this:o,to:new l({this:"date"})}))}p(lE,"dateSql");function uE(n){let o=n.args.unit;if(We(o))return Zo.call(this,n.args.expression??f(),n.args.this??f());let s=new T({this:n.args.this,to:new l({this:"time"})}),t=new T({this:n.args.expression,to:new l({this:"time"})});return this.func("DATE_DIFF",[yt(n),t,s])}p(uE,"timeDiffSql");function Et(n={}){let{cast:o=!0}=n,s=Na({cast:o});return function(t){let e=K(t.getArgKey("unit"),"string",N),r=t.args.expression;if(We(e instanceof N?e:void 0)){r instanceof Y&&(r=r.args.this);let i=new T({this:K(t.args.this,"string",N),to:new l({this:"timestampNs"})});return this.sql(this.func("MAKE_TIMESTAMP_NS",[new I({this:this.func("EPOCH_NS",[i]),expression:K(r,"string",N)})]))}return!r||r instanceof Y?s.call(this,t):(k(r,l.REAL_TYPES)&&t.setArgKey("expression",new T({this:this.func("ROUND",[r]),to:new l({this:"int"})})),s.call(this,t))}}p(Et,"dateDeltaToBinaryIntervalOp");function hE(n){let o=n.args.this,s=n.args.position,t=n.args.expression,e=new W({expressions:[t??f()]}),r=n.args.offset??0;if(!s?.isNumber)return this.unsupported("ARRAY_INSERT can only be transpiled with a literal position"),this.func("ARRAY_INSERT",[o,s,t]);let i=s.toValue();0<i?i-=r:i<0&&(i+=r);let E;if(i===0)E=[e,o??f()];else if(0<i){let c=new q({this:o,expressions:[new B({this:a.number(1),expression:a.number(i)})]}),u=new q({this:o,expressions:[new B({this:a.number(i+1)})]});E=[c,e,u]}else{let c=new z({this:o}),u=new I({this:c,expression:a.number(i)}),A=new I({this:u,expression:a.number(1)}),_=new q({this:o,expressions:[new B({this:a.number(1),expression:u})]}),O=new q({this:o,expressions:[new B({this:A})]});E=[_,e,O]}return this.sql(new Q({this:new at({this:o,expression:f()}),true:f(),false:this.func("LIST_CONCAT",E)}))}p(hE,"arrayInsertSql");function TE(n){let o=n.args.this,s=n.args.position;if(!s?.isNumber)return this.unsupported("ARRAY_REMOVE_AT can only be transpiled with a literal position"),this.func("ARRAY_REMOVE_AT",[o,s]);let t=s.toValue(),e;if(t===0)e=new q({this:o,expressions:[new B({this:a.number(2)})]});else if(0<t){let r=new q({this:o,expressions:[new B({this:a.number(1),expression:a.number(t)})]}),i=new q({this:o,expressions:[new B({this:a.number(t+2)})]});e=this.func("LIST_CONCAT",[r,i])}else if(t===-1){let r=new z({this:o}),i=new I({this:r,expression:a.number(-1)});e=new q({this:o,expressions:[new B({this:a.number(1),expression:i})]})}else{let r=new z({this:o}),i=new I({this:r,expression:a.number(t)}),E=new I({this:i,expression:a.number(2)}),c=new q({this:o,expressions:[new B({this:a.number(1),expression:i})]}),u=new q({this:o,expressions:[new B({this:E})]});e=this.func("LIST_CONCAT",[c,u])}return this.sql(new Q({this:new at({this:o,expression:f()}),true:f(),false:e}))}p(TE,"arrayRemoveAtSql");function SE(n){return n.args.expression&&this.unsupported("DuckDB's ARRAY_SORT does not support a comparator."),this.func("ARRAY_SORT",[n.args.this])}p(SE,"arraySortSql");function ba(n){return new hs({this:m(n,0),asc:new j({this:!1})})}p(ba,"buildSortArrayDesc");function Da(n){return new Zs({this:m(n,1),expression:m(n,0)})}p(Da,"buildArrayPrepend");function Ga(n){return new ie({this:m(n,2),expression:m(n,1),unit:m(n,0)})}p(Ga,"buildDateDiff");function Fa(n={}){let{endExclusive:o=!1}=n;return s=>{s.length===1&&s.unshift(a.number("0"));let t=Ws.fromArgList(s);return t.setArgKey("isEndExclusive",o),t}}p(Fa,"buildGenerateSeries");function gE(n){return n.length===1?new st({this:m(n,0),scale:st.MICROS}):new Ci({year:m(n,0),month:m(n,1),day:m(n,2),hour:m(n,3),min:m(n,4),sec:m(n,5)})}p(gE,"buildMakeTimestamp");function Ua(...n){return function(){return this.parseShowDuckdb(n[0])}}p(Ua,"showParser");function fE(n){let o=n.findAncestor(T,nt);if(o=o instanceof nt?void 0:o,(!n.args.expressions||n.args.expressions.length===0)&&o instanceof T&&k(o.args.to,"map"))return"MAP()";let s=[],t=!n.find(Lt)&&o instanceof T&&[...o.findAll(l)].some(r=>k(r,"struct"));n.args.expressions?.forEach((r,i)=>{let E=r instanceof Lt,c=r.args.this,u=E?r.args.expression:r;if(t)s.push(this.sql(u));else{let A;c instanceof It?A=this.sql(a.string(r.name)):E?A=this.sql(r.args.this):A=this.sql(a.string(`_${i}`)),s.push(`${A}: ${this.sql(u)}`)}});let e=s.join(", ");return t?`ROW(${e})`:`{${e}}`}p(fE,"structSql");function AE(n){if(k(n,"array")){let o=this.expressions(n,{flat:!0}),s=this.expressions(n,{key:"values",flat:!0});return`${o}[${s}]`}if(k(n,["time","timetz","timestamptz"])){let o=n.args.this;return o instanceof N?o.name:o?$e(o):""}return Ct.prototype.dataTypeSql.call(this,n)}p(AE,"dataTypeSql");function xE(n){return`CAST(${this.func("TO_JSON",[n.args.this,n.args.options])} AS TEXT)`}p(xE,"jsonFormatSql");function jo(n,o,s){let t=o*8,e=a.number((2n**BigInt(t)).toString());if(s){let r=a.number((2n**BigInt(t-1)).toString());return b($t.SEQ_SIGNED.copy(),[],{base:n,maxVal:e,half:r})}return b($t.SEQ_UNSIGNED.copy(),[],{base:n,maxVal:e})}p(jo,"buildSeqExpression");function RE(n){if(!(n instanceof nt))return n;let o=n.args.from;return!o||!(o.args.this instanceof wr)||!(o.args.this.args.this instanceof $s)?n:n.transform(s=>{let t=oE.get(s._constructor);return t!==void 0?jo(new Ds({this:H("range")}),t,s.name==="1"):s},{copy:!1})}p(RE,"seqToRangeInGenerator");function Ns(n,o){let s=n.findAncestor(...EE);s&&(!(s instanceof wt||s instanceof nt)||s instanceof wt&&s.parent instanceof jt)&&this.unsupported("SEQ in restricted context is not supported - use CTE or subquery");let t=jo(aE.copy(),o,n.name==="1");return this.sql(t)}p(Ns,"seqSql");function dE(n){let o=n.args.scale,s=o?.toValue(),t=n.args.this,e=n.args.targetType,r=k(e,["timestamp","timestampntz"]);if(s===st.MILLIS.toValue())return this.func("EPOCH_MS",[t]);if(s===st.MICROS.toValue())return this.func("MAKE_TIMESTAMP",[t]);s!==void 0&&s!==st.SECONDS.toValue()&&(t=new lt({this:t,expression:x("POW",a.number(10),o)}));let i=new d({this:"TO_TIMESTAMP",expressions:[t??f()]});return r&&(i=new ct({this:i,zone:a.string("UTC")})),this.sql(i)}p(dE,"unixToTimeSql");var mE=[_t,q,zt,Ot];function Ha(n){let o=oa.call(this,n);return!n.sameParent&&mE.some(s=>n.parent instanceof s)&&(o=this.wrap(o)),o}p(Ha,"arrowJsonExtractSqlDuckDB");function dt(n,o="date"){if(n instanceof a&&n.isString){let s=n.args.this??"",t=o;return o==="date"&&s.includes(":")&&(t=eE.test(s)?"timestamptz":"timestamp"),new T({this:n,to:new l({this:t})})}return n}p(dt,"implicitDatetimeCast");function Qo(n){if(n instanceof C&&"ISOWEEK".includes(n.name.toUpperCase()))return 1;if(n instanceof Tr)return ws[n.name.toUpperCase()]}p(Qo,"weekUnitToDow");function ve(n,o,s={}){let{preserveStartDay:t=!1}=s,e=o===7?1:1-o,r=x("DATE_TRUNC",new C({this:"WEEK"}),n);if(e===0)return r;let i=new Y({this:a.string(e.toString()),unit:new C({this:"DAY"})}),E=new is({this:n,expression:i});if(r.setArgKey("this",E),t){let c=new Y({this:a.string((-e).toString()),unit:new C({this:"DAY"})});return ot(new is({this:r,expression:c}),"date")}return r}p(ve,"buildWeekTruncExpression");function Ba(n){let o=n.args.unit;if(We(o))return Zo.call(this,n.args.this??f(),n.args.expression??f());let s=dt(n.args.this),t=dt(n.args.expression),e=n.args.datePartBoundary,r=Qo(o);return e&&r!==void 0&&s&&t&&(n.setArgKey("unit",a.string("WEEK")),s=ve(s,r),t=ve(t,r)),this.func("DATE_DIFF",[yt(n),t,s])}p(Ba,"dateDiffSql");function Ya(n){let o=n instanceof ce,s=o?"date":"timestamp",t=dt(n.args.start,s),e=dt(n.args.end,s),r=new Ws({start:t,end:e,step:n.args.step});return o&&(r=new T({this:r,to:l.build("ARRAY<DATE>")})),this.sql(r)}p(Ya,"generateDatetimeArraySql");function va(n){let o=n.args.expression instanceof N?n.args.expression:void 0,s=new ps({this:n.args.this,expression:o}),t=n instanceof Se?"ARRAY<STRING>":"ARRAY<JSON>";return this.sql(new T({this:s,to:l.build(t)}))}p(va,"jsonExtractValueArraySql");function et(n){if(n!==void 0)return n instanceof N&&n.type&&!k(n,[...l.TEXT_TYPES,"unknown"])?new T({this:n,to:new l({this:"varchar"})}):n instanceof N?n:a.string(n.toString())}p(et,"castToVarchar");function ke(n){return n&&!k(n,"boolean")?new T({this:n,to:new l({this:"boolean"})}):n}p(ke,"castToBoolean");function Z(n){return k(n,["binary","varbinary","blob"])}p(Z,"isBinary");function ut(n,o){if(Z(n)){let s=l.build("BLOB",{dialect:"duckdb"});o=this.sql(new T({this:o,to:s}))}return o}p(ut,"genWithCastToBlob");function Xe(n){if(!Z(n))return n;let o=n;return n instanceof Sr&&(o=new Ii({this:a.string(n.args.this)})),new T({this:o,to:new l({this:"bit"})})}p(Xe,"castToBit");function ka(n){n.args.this instanceof N&&Z(n.args.this)&&n.setArgKey("this",Xe(n.args.this)),n.args.expression instanceof N&&Z(n.args.expression)&&n.setArgKey("expression",Xe(n.args.expression))}p(ka,"prepareBinaryBitwiseArgs");function Xa(n){let o=n.args.this,s=n.args.expression,t=x("ISODOW",o),e;if(s instanceof a){let i=(s.args.this??"").toUpperCase(),E=Object.keys(ws).find(c=>c.startsWith(i));if(E)e=a.number(ws[E]);else return this.functionFallbackSql(n)}else{let i=new Ss({this:s});e=new $({ifs:Object.entries(ws).map(([E,c])=>new Q({this:this.func("STARTS_WITH",[i.copy(),a.string(E.substring(0,2))]),true:a.number(c)}))})}let r;if(n instanceof ye){let i=xt(e.sub(t).add(6),{copy:!1}),E=new St({this:i,expression:a.number(7)}).add(1);r=new I({this:o,expression:new Y({this:E,unit:new C({this:"DAY"})})})}else{let i=xt(t.sub(e).add(6),{copy:!1}),E=new St({this:i,expression:a.number(7)}).add(1);r=new F({this:o,expression:new Y({this:E,unit:new C({this:"DAY"})})})}return this.sql(new T({this:r,to:new l({this:"date"})}))}p(Xa,"dayNavigationSql");function NE(n){let o=n.args.this;if(o instanceof ur){let s=o.args.max?"ARG_MAX_NULL":"ARG_MIN_NULL";return this.func(s,[o.args.this,o.args.expression])}return this.functionFallbackSql(n)}p(NE,"anyValueSql");function Ye(n){let o="BIT_XOR";n instanceof fs?o="BIT_OR":n instanceof gs&&(o="BIT_AND");let s=n.args.this;return k(s,[...l.REAL_TYPES,...l.TEXT_TYPES])&&(k(s,l.FLOAT_TYPES)&&(s=this.func("ROUND",[s])),s=new T({this:s,to:new l({this:"int"})})),this.func(o,[s])}p(Ye,"bitwiseAggSql");function IE(n){let o=n.split("");if(!o.some(i=>i in ms))return this.sql(a.string(n));let s=[],t=[],e=!1;for(let i of o){let E=i in ms;E!==e&&(0<t.length&&(e?t.forEach(c=>s.push(this.func("CHR",[a.number(ms[c])]))):s.push(this.sql(a.string(t.join(""))))),t=[],e=E),t.push(i)}0<t.length&&(e?t.forEach(i=>s.push(this.func("CHR",[a.number(ms[i])]))):s.push(this.sql(a.string(t.join("")))));let r=s.join(" || ");return s.length===1?r:`(${r})`}p(IE,"literalSqlWithWsChr");function wE(n,o){if(!n)return o;if(n instanceof a&&n.isString){let e=(n.args.this??"").split("").map(r=>Ma[r]??r).join("");return IE.call(this,e)}let s=o;return Object.entries(Ma).forEach(([t,e])=>{s=this.func("REPLACE",[s,this.sql(a.string(t)),this.sql(a.string(e))])}),s}p(wE,"escapeRegexMetachars");function _E(n,o){if(o==="''")return`UPPER(LEFT(${n}, 1)) || LOWER(SUBSTRING(${n}, 2))`;let s=`CONCAT('[', ${o}, ']')`,t=`CONCAT('([', ${o}, ']+|[^', ${o}, ']+)')`;return this.func("ARRAY_TO_STRING",[new $({}).when(`REGEXP_MATCHES(LEFT(${n}, 1), ${s})`,this.func("LIST_TRANSFORM",[this.func("REGEXP_EXTRACT_ALL",[n,t]),"(seg, idx) -> CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END"])).else(this.func("LIST_TRANSFORM",[this.func("REGEXP_EXTRACT_ALL",[n,t]),"(seg, idx) -> CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END"])),"''"])}p(_E,"buildCapitalizationSql");function LE(n){let o=this.sql(n,"this"),s=n.args.expression;s||(s=a.string(this.dialect._constructor.INITCAP_DEFAULT_DELIMITER_CHARS));let t=this.sql(s),e=wE.call(this,s,t);return _E.call(this,o,e)}p(LE,"initcapSql");function OE(n){return this.sql(new v({this:new vi({this:ke(n.args.this)??n.args.this}),expression:a.number(1)}))}p(OE,"boolxorAggSql");function Va(n){let o=n instanceof Hs?"<<":">>",s=!1,t=n.args.this;t instanceof N&&Z(t)?(s=!0,n.setArgKey("this",ot(t,"bit"))):n.args.requiresInt128&&t instanceof N&&t.replace(ot(t,"int128"));let e=this.binary(n,o);return n.parent instanceof _t&&(e=`(${e})`),s&&(e=this.sql(new T({this:e,to:l.build("BLOB",{dialect:"duckdb"})}))),e}p(Va,"bitshiftSql");function PE(n,o){let s=n.args.decimals;if(!s||n.args.to)return;let t=n.args.this;t instanceof _t&&(t=new L({this:t}));let e=s.isInteger||s.isType([...l.INTEGER_TYPES])?s:new T({this:s,to:new l({this:"int"})}),r=new cs({this:a.number("10"),expression:e}),i=new o({this:new gt({this:t,expression:r})}),E=new lt({this:i,expression:r.copy()});return this.roundSql(new Ne({this:E,decimals:s,castsNonIntegerDecimals:!0}))}p(PE,"scaleRoundingSql");function Ka(n){let o=PE.call(this,n,n._constructor);return o!==void 0?o:this.ceilFloor(n)}p(Ka,"ceilFloor");function Wa(n){let o=n.args.this??f(),s=n.args.expression??f(),t,e,r;n instanceof qe?(t=o,e=s,r="expression"):(t=s,e=o,r="this");let i=e.type;if(!i||typeof i=="string"||i.args.this==="unknown")try{let u=Nt(n.copy(),{dialect:this.dialect}).args[r];i=u instanceof N?u.type:void 0}catch{}(!i||typeof i=="string"||i.args.this==="unknown")&&(i=l.build("double"));let E=new T({this:f(),to:i});return this.sql(new Q({this:new at({this:t.copy(),expression:f()}),true:E,false:e.copy()}))}p(Wa,"regrValSql");function CE(n){let o=n;for(;o instanceof jt||o instanceof Gt;)o=o.args.this??f();if(!(!(o instanceof At)||!o.args.nullOnZeroVariance))return o.setArgKey("nullOnZeroVariance",!1),n}p(CE,"maybeCorrNullToFalse");function yE(n){let o=n.args.year,s=n.args.month,t=n.args.day;if(n.args.allowOverflow){let e=new d({this:"MAKE_DATE",expressions:[o??f(),a.number(1),a.number(1)]});return s&&(e=new I({this:e,expression:new Y({this:new F({this:be(s,_t),expression:a.number(1)}),unit:new C({this:"MONTH"})})})),t&&(e=new I({this:e,expression:new Y({this:new F({this:be(t,_t),expression:a.number(1)}),unit:new C({this:"DAY"})})})),this.sql(new T({this:e,to:new l({this:"date"})}))}return this.func("MAKE_DATE",[o,s,t])}p(yE,"dateFromPartsSql");function mt(n,o){return o?new Ne({this:n,decimals:a.number(0)}):n}p(mt,"roundArg");function ME(n){let o=mt(n.args.this??f(),n.args.roundInput);return this.sql(new Ot({this:new L({this:o})}))}p(ME,"boolnotSql");function qE(n){let o=n.args.roundInput,s=mt(n.args.this??f(),o),t=mt(n.args.expression??f(),o);return this.sql(new L({this:new Vi({this:new L({this:s}),expression:new L({this:t})})}))}p(qE,"boolandSql");function bE(n){let o=n.args.roundInput,s=mt(n.args.this??f(),o),t=mt(n.args.expression??f(),o);return this.sql(new L({this:new Xt({this:new L({this:s}),expression:new L({this:t})})}))}p(bE,"boolorSql");function DE(n){let o=n.args.roundInput,s=n.args.this&&mt(n.args.this,o),t=n.args.expression&&mt(n.args.expression,o);return this.sql(Kt([xt(Vt([s?.copy(),xt(t.not())],{wrap:!1})),xt(Vt([xt(s.not()),t?.copy()],{wrap:!1}))],{wrap:!1}))}p(DE,"xorSql");function Is(n,o,s={}){let{isBinary:t=!1}=s,e=n.args.this;o==="SHA256"&&(n.text("length")||"256")!=="256"&&this.unsupported("DuckDB only supports SHA256 hashing algorithm."),e instanceof N&&e.type&&(!(e.type instanceof N)||e.type.args.this!=="unknown")&&!e.isType(l.TEXT_TYPES)&&!Z(e)&&(e=new T({this:e,to:new l({this:"varchar"})}));let r=this.func(o,[e]);return t?this.func("UNHEX",[r]):r}p(Is,"shaSql");var $a,Ja,Za,ja,Qa,za,to,ht,X=class X extends(to=Wt,za=[g],Qa=[g],ja=[g],Za=[g],Ja=[g],$a=[g],to){static get BYTE_STRINGS(){return[["e'","'"],["E'","'"]]}static get BYTE_STRING_ESCAPES(){return["'","\\"]}static get HEREDOC_STRINGS(){return["$"]}static get ORIGINAL_KEYWORDS(){let s={...Wt.KEYWORDS,"//":"div","**":"dstar","^@":"caretAt","@>":"atGt","<@":"ltAt",ATTACH:"attach",BINARY:"varbinary",BITSTRING:"bit",BPCHAR:"text",CHAR:"text",DATETIME:"timestampntz",DETACH:"detach",FORCE:"force",INSTALL:"install",INT8:"bigint",LOGICAL:"boolean",MACRO:"function",ONLY:"only",PIVOT_WIDER:"pivot",POSITIONAL:"positional",RESET:"command",ROW:"struct",SIGNED:"int",STRING:"text",SUMMARIZE:"summarize",TIMESTAMP:"timestampntz",TIMESTAMP_S:"timestampS",TIMESTAMP_MS:"timestampMs",TIMESTAMP_NS:"timestampNs",TIMESTAMP_US:"timestamp",UBIGINT:"ubigint",UINTEGER:"uint",USMALLINT:"usmallint",UTINYINT:"utinyint",VARCHAR:"text"};return delete s["/*+"],s}static get SINGLE_TOKENS(){return{...Wt.SINGLE_TOKENS,$:"parameter"}}static get COMMANDS(){let s=new Set(Wt.COMMANDS);return s.delete("show"),s}};ht=Mt(to),S(ht,10,"BYTE_STRINGS",za,X),S(ht,10,"BYTE_STRING_ESCAPES",Qa,X),S(ht,10,"HEREDOC_STRINGS",ja,X),S(ht,10,"ORIGINAL_KEYWORDS",Za,X),S(ht,10,"SINGLE_TOKENS",Ja,X),S(ht,10,"COMMANDS",$a,X),qt(ht,X),bt(ht,3,X),p(X,"DuckDBTokenizer"),X.HEREDOC_TAG_IS_IDENTIFIER=!0,X.HEREDOC_STRING_ALTERNATIVE="parameter";var Ve=X,so,eo,ro,no,io,ao,oo,Eo,po,co,lo,uo,ho,To,So,go,D,M=class M extends(go=U,So=[g],To=[g],ho=[g],uo=[g],lo=[g],co=[g],po=[g],Eo=[g],oo=[g],ao=[g],io=[g],no=[g],ro=[g],eo=[g],so=[g],go){static get NO_PAREN_FUNCTIONS(){let s={...U.NO_PAREN_FUNCTIONS};return s.sessionUser=nn,s.currentCatalog=rn,s}static get BITWISE(){return(()=>{let s={...U.BITWISE};return delete s.caret,s})()}static get RANGE_PARSERS(){return{...U.RANGE_PARSERS,damp:Zt(ns),caretAt:Zt(ui),tilde:Zt(ii)}}static get EXPONENT(){return{...U.EXPONENT,caret:cs,dstar:cs}}static get FUNCTIONS_WITH_ALIASED_ARGS(){return new Set([...U.FUNCTIONS_WITH_ALIASED_ARGS,"STRUCT_PACK"])}static get SHOW_PARSERS(){return{TABLES:Ua("TABLES"),"ALL TABLES":Ua("ALL TABLES")}}static get FUNCTIONS(){return(()=>{let s={...U.FUNCTIONS,ANY_VALUE:p(t=>new lr({this:kt.fromArgList(t)}),"ANY_VALUE"),ARRAY_PREPEND:Da,ARRAY_INTERSECT:p(t=>new $r({expressions:t}),"ARRAY_INTERSECT"),ARRAY_REVERSE_SORT:ba,ARRAY_SORT:p(t=>hs.fromArgList(t),"ARRAY_SORT"),BIT_AND:p(t=>gs.fromArgList(t),"BIT_AND"),BIT_OR:p(t=>fs.fromArgList(t),"BIT_OR"),BIT_XOR:p(t=>Me.fromArgList(t),"BIT_XOR"),DATEDIFF:Ga,DATE_DIFF:Ga,DATE_TRUNC:p(t=>Ue([m(t,0),m(t,1)]),"DATE_TRUNC"),DATETRUNC:p(t=>Ue([m(t,0),m(t,1)]),"DATETRUNC"),DECODE:p(t=>new os({this:m(t,0),charset:a.string("utf-8")}),"DECODE"),EDITDIST3:p(t=>fe.fromArgList(t),"EDITDIST3"),ENCODE:p(t=>new oe({this:m(t,0),charset:a.string("utf-8")}),"ENCODE"),EPOCH:p(t=>Ce.fromArgList(t),"EPOCH"),EPOCH_MS:p(t=>new st({this:m(t,0),scale:st.MILLIS}),"EPOCH_MS"),GENERATE_SERIES:Fa(),GET_CURRENT_TIME:p(t=>ee.fromArgList(t),"GET_CURRENT_TIME"),GET_BIT:p(t=>new le({this:m(t,0),expression:m(t,1),zeroIsMsb:!0}),"GET_BIT"),JARO_WINKLER_SIMILARITY:p(t=>Ks.fromArgList(t),"JARO_WINKLER_SIMILARITY"),JSON:p(t=>jn.fromArgList(t),"JSON"),JSON_EXTRACT_PATH:Ps(ps),JSON_EXTRACT_STRING:Ps(ge),LIST_APPEND:p(t=>Js.fromArgList(t),"LIST_APPEND"),LIST_CONCAT:Je,LIST_CONTAINS:p(t=>es.fromArgList(t),"LIST_CONTAINS"),LIST_COSINE_DISTANCE:p(t=>Xs.fromArgList(t),"LIST_COSINE_DISTANCE"),LIST_DISTANCE:p(t=>Vs.fromArgList(t),"LIST_DISTANCE"),LIST_FILTER:p(t=>rs.fromArgList(t),"LIST_FILTER"),LIST_HAS:p(t=>es.fromArgList(t),"LIST_HAS"),LIST_HAS_ANY:p(t=>ns.fromArgList(t),"LIST_HAS_ANY"),LIST_PREPEND:Da,LIST_REVERSE_SORT:ba,LIST_SORT:p(t=>hs.fromArgList(t),"LIST_SORT"),LIST_TRANSFORM:p(t=>Ht.fromArgList(t),"LIST_TRANSFORM"),LIST_VALUE:p(t=>new W({expressions:t}),"LIST_VALUE"),MAKE_DATE:p(t=>ae.fromArgList(t),"MAKE_DATE"),MAKE_TIME:p(t=>yn.fromArgList(t),"MAKE_TIME"),MAKE_TIMESTAMP:gE,QUANTILE_CONT:p(t=>As.fromArgList(t),"QUANTILE_CONT"),QUANTILE_DISC:p(t=>xs.fromArgList(t),"QUANTILE_DISC"),RANGE:Fa({endExclusive:!0}),REGEXP_EXTRACT:Be(ri),REGEXP_EXTRACT_ALL:Be(Re),REGEXP_MATCHES:p(t=>de.fromArgList(t),"REGEXP_MATCHES"),REGEXP_REPLACE:p(t=>new ls({this:m(t,0),expression:m(t,1),replacement:m(t,2),modifiers:m(t,3),singleReplace:!0}),"REGEXP_REPLACE"),SHA256:p(t=>new Oe({this:m(t,0),length:a.number(256)}),"SHA256"),STRFTIME:Fe(Pe,{dialect:"duckdb"}),STRING_SPLIT:p(t=>Ts.fromArgList(t),"STRING_SPLIT"),STRING_SPLIT_REGEX:p(t=>us.fromArgList(t),"STRING_SPLIT_REGEX"),STRING_TO_ARRAY:p(t=>Ts.fromArgList(t),"STRING_TO_ARRAY"),STRPTIME:Fe(hi,{dialect:"duckdb"}),STRUCT_PACK:p(t=>ft.fromArgList(t),"STRUCT_PACK"),STR_SPLIT:p(t=>Ts.fromArgList(t),"STR_SPLIT"),STR_SPLIT_REGEX:p(t=>us.fromArgList(t),"STR_SPLIT_REGEX"),TIME_BUCKET:p(t=>ne.fromArgList(t),"TIME_BUCKET"),LIST_MAX:p(t=>js.fromArgList(t),"LIST_MAX"),LIST_MIN:p(t=>Qs.fromArgList(t),"LIST_MIN"),CURRENT_LOCALTIMESTAMP:p(t=>en.fromArgList(t),"CURRENT_LOCALTIMESTAMP"),TODAY:p(t=>tn.fromArgList(t),"TODAY"),TO_TIMESTAMP:p(t=>st.fromArgList(t),"TO_TIMESTAMP"),UNNEST:p(t=>Ee.fromArgList(t),"UNNEST"),VERSION:p(t=>se.fromArgList(t),"VERSION"),XOR:ma(Pr)};return delete s.DATE_SUB,delete s.GLOB,s})()}static get FUNCTION_PARSERS(){return(()=>{let s={...U.FUNCTION_PARSERS,...Object.fromEntries(["GROUP_CONCAT","LISTAGG","STRINGAGG"].map(t=>[t,function(){return this.parseStringAgg()}]))};return delete s.DECODE,s})()}static get NO_PAREN_FUNCTION_PARSERS(){return{...U.NO_PAREN_FUNCTION_PARSERS,MAP:p(function(){return this.parseMap()},"MAP"),"@":p(function(){return new Ut({this:this.parseBitwise()})},"@")}}static get ID_VAR_TOKENS(){return new Set([...U.ID_VAR_TOKENS,"straightJoin"])}static get TABLE_ALIAS_TOKENS(){return(()=>{let s=new Set(U.TABLE_ALIAS_TOKENS);return s.delete("semi"),s.delete("anti"),s.add("straightJoin"),s})()}static get PLACEHOLDER_PARSERS(){return{...U.PLACEHOLDER_PARSERS,parameter:function(){return this.match("number")||this.matchSet(this._constructor.ID_VAR_TOKENS)?this.expression(xr,{this:this.prev?.text}):void 0}}}static get TYPE_CONVERTERS(){return{decimal:_a(18,3),text:()=>l.build("text")??new l({this:"text"})}}static get STATEMENT_PARSERS(){return{...U.STATEMENT_PARSERS,attach:function(){return this.parseAttachDetach()},detach:function(){return this.parseAttachDetach({isAttach:!1})},force:function(){return this.parseForce()},install:function(){return this.parseInstall()},show:function(){return this.parseShow()}}}static get SET_PARSERS(){return{...U.SET_PARSERS,VARIABLE:p(function(){return this.parseSetItemAssignment({kind:"VARIABLE"})},"VARIABLE")}}parseLambda(s={}){let t=this.index;if(!this.matchTextSeq("LAMBDA"))return super.parseLambda(s);let e=this.parseCsv(()=>this.parseLambdaArg());if(!this.match("colon")){this.retreat(t);return}let r=this.replaceLambda(this.parseAssignment(),e);return this.expression(rt,{this:r,expressions:e,colon:!0})}parseExpression(){if(this.next&&this.next.tokenType==="colon"){let s=this.parseIdVar({tokens:this._constructor.ALIAS_TOKENS});this.match("colon");let t=this.prevComments??[],e=this.parseAssignment();return e instanceof N&&(t=[...t,...e.popComments()??[]]),this.expression(qs,{comments:t,this:e,alias:s})}return super.parseExpression()}parseTable(s={}){let t,e=[];this.next&&this.next.tokenType==="colon"&&(t=this.parseTableAlias({aliasTokens:s.aliasTokens??this._constructor.TABLE_ALIAS_TOKENS}),this.match("colon"),e=this.prevComments??[]);let r=super.parseTable(s);return r instanceof N&&t instanceof Dt&&(e=[...e,...r.popComments()??[]],t.comments=[...t.popComments()??[],...e],r.setArgKey("alias",t)),r}parseTableSample(s={}){let t=super.parseTableSample(s);return t&&!t.args.method&&(t.args.size?t.setArgKey("method",new C({this:"RESERVOIR"})):t.setArgKey("method",new C({this:"SYSTEM"}))),t}parseBracket(s){let t=super.parseBracket(s);return this.dialect.version.major<=1&&this.dialect.version.minor<=2&&(this.dialect.version.major!==1||this.dialect.version.minor!==2)&&t instanceof q&&t.setArgKey("returnsListForMaps",!0),t}parseMap(){if(this.match("lBrace",{advance:!1}))return this.expression(xe,{this:this.parseBracket()});let s=this.parseWrappedCsv(()=>this.parseAssignment());return this.expression(Ae,{keys:m(s,0),values:m(s,1)})}parseStructTypes(s={}){return this.parseFieldDef()}pivotColumnNames(s){return s.length===1?super.pivotColumnNames(s):da(s,{dialect:"duckdb"})}parseAttachDetach(s={}){let{isAttach:t=!0}=s,e=p(()=>this.expression(pr,{this:this.parseVar({anyToken:!0}),expression:this.parseField({anyToken:!0})}),"parseAttachOption");this.match("database");let r=this.parseExists({not:t}),i=this.parseAlias(this.parsePrimaryOrVar(),{explicit:!0}),E;return this.match("lParen",{advance:!1})&&(E=this.parseWrappedCsv(e)),t?this.expression(je,{this:i,exists:r,expressions:E}):this.expression(Qe,{this:i,exists:r})}parseShowDuckdb(s){let t=this.match("from")?this.parseTable({schema:!0}):void 0;return this.expression(tr,{this:s,from:t})}parseForce(){return this.match("install")?this.parseInstall({force:!0}):this.parseAsCommand(this.prev)}parseInstall(s={}){return this.expression(ze,{this:this.parseIdVar(),from:this.match("from")?this.parseVarOrString():void 0,force:s.force??!1})}parsePrimary(){return this.matchPair("hash","number")?new hr({this:a.number(this.prev?.text||0)}):super.parsePrimary()}};D=Mt(go),S(D,10,"NO_PAREN_FUNCTIONS",So,M),S(D,10,"BITWISE",To,M),S(D,10,"RANGE_PARSERS",ho,M),S(D,10,"EXPONENT",uo,M),S(D,10,"FUNCTIONS_WITH_ALIASED_ARGS",lo,M),S(D,10,"SHOW_PARSERS",co,M),S(D,10,"FUNCTIONS",po,M),S(D,10,"FUNCTION_PARSERS",Eo,M),S(D,10,"NO_PAREN_FUNCTION_PARSERS",oo,M),S(D,10,"ID_VAR_TOKENS",ao,M),S(D,10,"TABLE_ALIAS_TOKENS",io,M),S(D,10,"PLACEHOLDER_PARSERS",no,M),S(D,10,"TYPE_CONVERTERS",ro,M),S(D,10,"STATEMENT_PARSERS",eo,M),S(D,10,"SET_PARSERS",so,M),qt(D,M),bt(D,3,M),p(M,"DuckDBParser"),M.MAP_KEYS_ARE_ARBITRARY_EXPRESSIONS=!0;var Ke=M,fo,Ao,xo,Ro,mo,No,Io,wo,_o,Lo,Oo,Po,Co,yo,Mo,qo,bo,Do,Go,Fo,Uo,Ho,Bo,Yo,vo,w,h=class h extends(vo=Ct,Yo=[g],Bo=[g],Ho=[g],Uo=[g],Fo=[g],Go=[g],Do=[g],bo=[g],qo=[g],Mo=[g],yo=[g],Co=[g],Po=[g],Oo=[g],Lo=[g],_o=[g],wo=[g],Io=[g],No=[g],mo=[g],Ro=[g],xo=[g],Ao=[g],fo=[g],vo){static get STRTOK_TEMPLATE(){return y(`
2
2
  CASE
3
3
  WHEN :delimiter = '' AND :string = '' THEN NULL
4
4
  WHEN :delimiter = '' AND :partIndex = 1 THEN :string
@@ -7,7 +7,7 @@ import{a as Ma}from"../chunk-WDNJ5X7T.js";import"../chunk-YGEJLTA7.js";import{$d
7
7
  WHEN :string IS NULL OR :delimiter IS NULL OR :partIndex IS NULL THEN NULL
8
8
  ELSE :baseFunc
9
9
  END
10
- `)}static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let s=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(t=>s.delete(t)),s}static get STRUCT_DELIMITER(){return["(",")"]}static get ORIGINAL_TRANSFORMS(){return new Map([...Ct.TRANSFORMS,[vt,NE],[qi,aa],[Gr,yE],[Fr,qE],[Ur,bE],[W,Rs([na],Ea)],[Ws,De("LIST_APPEND")],[ts,Ia],[Wr,function(t){return this.sql(new ts({this:new W({expressions:t.args.expressions})}))}],[vr,ua("LIST_CONCAT")],[es,x("LIST_FILTER")],[Vr,hE],[js,function(t){return t.args.zeroBased?this.sql(new F({this:new js({this:t.args.this,expression:t.args.expression}),expression:a.number(1)})):this.func("ARRAY_POSITION",[t.args.this,t.args.expression])}],[Kr,TE],[Hr,wa],[Jr,SE],[$s,De("LIST_PREPEND",{swapParams:!0})],[Zr,x("LIST_SUM")],[Di,function(t){return this.func("LIST",[new qs({expressions:[t.args.this]})])}],[Bn,function(t){return qa.call(this,t,{toString:!1})}],[Yn,function(t){return qa.call(this,t,{toString:!0})}],[_r,function(t){return this.bitwiseOp(t,"&")}],[Ss,Be],[Fs,Va],[Lr,function(t){return this.bitwiseOp(t,"|")}],[gs,Be],[Or,Va],[Ce,Be],[Dr,x("BIT_COUNT")],[zt,function(t){return this.func("OCTET_LENGTH",[t.args.this])}],[gr,pa],[At,function(t){return this.corrSql(t)}],[vs,x("LIST_COSINE_DISTANCE")],[te,()=>"CURRENT_TIME"],[se,function(t){return t.args.sysdate?this.sql(new Et({this:new C({this:"CURRENT_TIMESTAMP"}),zone:a.string("UTC")})):"CURRENT_TIMESTAMP"}],[zr,function(t){return this.func("current_schemas",[t.args.this??ta()])}],[zs,x("version")],[sn,function(t){return ds.call(this,t,"this"),"LOCALTIME"}],[Tn,x("DAYOFMONTH")],[un,x("DAYOFWEEK")],[hn,x("ISODOW")],[Sn,x("DAYOFYEAR")],[gn,function(t){return t.args.abbreviated?this.func("STRFTIME",[t.args.this,a.string("%a")]):this.func("DAYNAME",[t.args.this])}],[ei,function(t){return t.args.abbreviated?this.func("STRFTIME",[t.args.this,a.string("%b")]):this.func("MONTHNAME",[t.args.this])}],[l,AE],[bn,lE],[ns,at()],[ne,ME],[an,at()],[re,Ba],[yn,Aa],[on,ga],[cn,Ba],[pn,at()],[En,at()],[qn,function(t){return`CAST(STRFTIME(${this.sql(t,"this")}, ${_s.DATEINT_FORMAT}) AS INT)`}],[as,function(t){return Ue.call(this,t,"DECODE",{replace:!1})}],[Dn,function(t){return`CAST(STRPTIME(CAST(${this.sql(t,"this")} AS TEXT), ${_s.DATEINT_FORMAT}) AS DATE)`}],[ie,function(t){return Ue.call(this,t,"ENCODE",{replace:!1})}],[Gn,function(t){return this.sql(new Mr({this:t.args.this,expression:t.args.expression}))}],[Xs,x("LIST_DISTANCE")],[Ee,Ya],[vn,Ya],[pe,Ca],[Vi,function(t){return Pa.call(this,t,{withinGroup:!1})}],[ae,x("UNNEST")],[jt,function(t){return this.binary(t,"//")}],[Vn,x("ISINF")],[ue,x("ISNAN")],[Kn,function(t){return this.sql(new v({this:this.func("JSON_TYPE",[t.args.this]),expression:a.string("NULL")}))}],[Wn,function(t){return this.sql(new v({this:this.func("JSON_TYPE",[t.args.this]),expression:a.string("ARRAY")}))}],[jr,Ka],[oe,Ka],[ks,ia("JARO_WINKLER_SIMILARITY")],[$n,x("JSON_EXISTS")],[Es,Ha],[Jn,va],[Zn,xE],[he,va],[Gs,function(t){let e=t.args.this;if(e instanceof Fn){let r=new os({expressions:[e.args.this,new Bs({this:sa("max_depth"),expression:a.number(2)})]}),i=new nt({expressions:[r]}).subquery(),E=t.args.alias;E&&!E.args.this&&E.setArgKey("this",H(`_u_${t.index}`));let c=new Gs({this:i,alias:E}),u=new er({this:c,kind:"cross"});return this.sql(u)}return La.call(this,t)}],[Zi,function(t){return this.func("BOOL_OR",[ve(t.args.this)])}],[ji,function(t){return this.func("BOOL_AND",[ve(t.args.this)])}],[me,function(t){return Ns.call(this,t,1)}],[Ne,function(t){return Ns.call(this,t,2)}],[Ie,function(t){return Ns.call(this,t,4)}],[we,function(t){return Ns.call(this,t,8)}],[Mi,OE],[dn,function(t){return Oa.call(this,t,{sep:" "})}],[ss,function(t){return this.arraycontainsSql(t)}],[rs,function(t){return this.arrayoverlapsSql(t)}],[Xr,function(t){return this.arraydistinctSql(t)}],[kr,function(t){return this.arrayexceptSql(t)}],[Js,x("LIST_MAX")],[Zs,x("LIST_MIN")],[zn,function(t){let e=new R({this:"MAP_KEYS",expressions:[t.args.key]});return this.func("ARRAY_CONTAINS",[e,t.args.this])}],[kn,LE],[si,function(t){return this.func("UNHEX",[this.func("MD5",[t.args.this])])}],[pi,function(t){return Is.call(this,t,"SHA1")}],[ci,function(t){return Is.call(this,t,"SHA1",{isBinary:!0})}],[_e,function(t){return Is.call(this,t,"SHA256")}],[li,function(t){return Is.call(this,t,"SHA256",{isBinary:!0})}],[Rn,ha],[Pe,ka],[fs,x("QUANTILE_CONT")],[As,x("QUANTILE_DISC")],[ar,Rs([ra])],[Nn,ka],[nt,Rs([RE])],[cs,function(t){return this.regexpreplaceSql(t)}],[oi,function(t){return this.regexpcountSql(t)}],[ai,function(t){return this.regexpinstrSql(t)}],[xe,function(t){return this.regexplikeSql(t)}],[ni,function(t){return this.func("REGEXP_MATCHES",[t.args.this,t.args.expression,a.string("i")])}],[ls,x("STR_SPLIT_REGEX")],[Me,Wa],[Qi,Wa],[nr,function(t){return this.sql(t,"this")}],[Ds,function(t){return t.args.this instanceof ir?"TABLE":""}],[Ti,function(t){return this.func("EPOCH",[this.func("STRPTIME",[t.args.this,this.formatTime(t)])])}],[ft,fE],[Ht,x("LIST_TRANSFORM")],[On,at()],[Pn,at()],[Si,Sa],[Cn,uE],[In,Ta],[wn,at()],[Ln,function(t){return this.func("DATE_DIFF",[a.string(t.args.unit),t.args.expression,t.args.this])}],[_n,at()],[gi,function(t){return this.sql(new T({this:t.args.this,to:new l({this:"date"})}))}],[fi,fa],[Ai,function(t){return this.func("EPOCH",[new T({this:t.args.this,to:new l({this:"timestamp"})})])}],[Le,function(t){return this.func("STRFTIME",[t.args.this,this.formatTime(t)])}],[Br,cE],[Yr,function(t){return this.sql(it(t.args.this,l.build("VARIANT",{dialect:"duckdb"})))}],[Oe,x("EPOCH")],[Ni,function(t){return`CAST(SUBSTR(REPLACE(CAST(${this.sql(t,"this")} AS TEXT), '-', ''), 1, 8) AS INT)`}],[Ri,at()],[di,function(t){let r=t.args.unit?.name?.toUpperCase()||"DAY";return this.func("DATE_DIFF",[a.string(r),new T({this:t.args.expression,to:new l({this:"timestamp"})}),new T({this:t.args.this,to:new l({this:"timestamp"})})])}],[Oi,function(t){return this.func("EPOCH_US",[dt(t.args.this)])}],[Pi,function(t){return this.func("EPOCH_MS",[dt(t.args.this)])}],[Li,function(t){return this.sql(new T({this:this.func("EPOCH",[dt(t.args.this)]),to:new l({this:"bigint"})}))}],[wi,function(t){return this.func("STRFTIME",[this.func("TO_TIMESTAMP",[t.args.this]),this.formatTime(t)])}],[ln,function(t){return this.func("DATE_TRUNC",[Mt(t),new T({this:t.args.this,to:new l({this:"datetime"})})])}],[tt,dE],[_i,function(t){return`CAST(TO_TIMESTAMP(${this.sql(t,"this")}) AS TEXT)`}],[ti,function(t){return this.func("MAP",[t.args?.keys,t.args?.values])}],[zi,x("VAR_POP")],[fn,x("WEEKOFYEAR")],[An,function(t){return this.sql(new is({this:new C({this:"ISOYEAR"}),expression:t.args.this}))}],[xn,function(t){return this.sql(new is({this:new C({this:"ISOYEAR"}),expression:t.args.this}))}],[Wi,DE],[$i,x("JSON_GROUP_OBJECT")],[Ji,x("JSON_GROUP_OBJECT")],[ee,x("TIME_BUCKET")],[mn,pE]])}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([dr,mr,Nr,Ir])}static get TYPE_MAPPING(){return new Map([...Ct.TYPE_MAPPING,["binary","BLOB"],["bpchar","TEXT"],["char","TEXT"],["datetime","TIMESTAMP"],["decfloat","DECIMAL(38, 5)"],["float","REAL"],["jsonb","JSON"],["nchar","TEXT"],["nvarchar","TEXT"],["uint","UINTEGER"],["varbinary","BLOB"],["rowversion","BLOB"],["varchar","TEXT"],["timestampltz","TIMESTAMPTZ"],["timestampntz","TIMESTAMP"],["timestampS","TIMESTAMP_S"],["timestampMs","TIMESTAMP_MS"],["timestampNs","TIMESTAMP_NS"],["bigdecimal","DECIMAL(38, 5)"]])}static get RESERVED_KEYWORDS(){return new Set(["array","analyse","union","all","when","in_p","default","create_p","window","asymmetric","to","else","localtime","from","end_p","select","current_date","foreign","with","grant","session_user","or","except","references","fetch","limit","group_p","leading","into","collate","offset","do","then","localtimestamp","check_p","lateral_p","current_role","where","asc_p","placing","desc_p","user","unique","initially","column","both","some","as","any","only","deferrable","null_p","current_time","true_p","table","case","trailing","variadic","for","on","distinct","false_p","not","constraint","current_timestamp","returning","primary","intersect","having","analyze","current_user","and","cast","symmetric","using","order","current_catalog"])}static get UNWRAPPED_INTERVAL_VALUES(){return new Set([a,w])}static get PROPERTIES_LOCATION(){let s=new Map;return[...Ct.PROPERTIES_LOCATION.keys()].forEach(t=>{s.set(t,"unsupported")}),s.set(fr,"postSchema"),s.set(Ar,"postCreate"),s.set(Ds,"postAlias"),s.set(Je,"postExpression"),s}static get IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS(){return[Hi,Gi,Bi,Fi,Yi]}static get ZIPF_TEMPLATE(){return M(`
10
+ `)}static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let s=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(t=>s.delete(t)),s}static get STRUCT_DELIMITER(){return["(",")"]}static get ORIGINAL_TRANSFORMS(){return new Map([...Ct.TRANSFORMS,[kt,NE],[qi,aa],[Gr,ME],[Fr,qE],[Ur,bE],[W,Rs([na],Ea)],[Js,Ge("LIST_APPEND")],[ss,Ia],[Wr,function(t){return this.sql(new ss({this:new W({expressions:t.args.expressions})}))}],[vr,ua("LIST_CONCAT")],[rs,R("LIST_FILTER")],[Vr,hE],[zs,function(t){return t.args.zeroBased?this.sql(new F({this:new zs({this:t.args.this,expression:t.args.expression}),expression:a.number(1)})):this.func("ARRAY_POSITION",[t.args.this,t.args.expression])}],[Kr,TE],[Hr,wa],[Jr,SE],[Zs,Ge("LIST_PREPEND",{swapParams:!0})],[Zr,R("LIST_SUM")],[Bn,function(t){return qa.call(this,t,{toString:!1})}],[Yn,function(t){return qa.call(this,t,{toString:!0})}],[_r,function(t){return this.bitwiseOp(t,"&")}],[gs,Ye],[Hs,Va],[Lr,function(t){return this.bitwiseOp(t,"|")}],[fs,Ye],[Or,Va],[Me,Ye],[Dr,R("BIT_COUNT")],[ts,function(t){return this.func("OCTET_LENGTH",[t.args.this])}],[gr,pa],[At,function(t){return this.corrSql(t)}],[Xs,R("LIST_COSINE_DISTANCE")],[ee,()=>"CURRENT_TIME"],[re,function(t){return t.args.sysdate?this.sql(new ct({this:new C({this:"CURRENT_TIMESTAMP"}),zone:a.string("UTC")})):"CURRENT_TIMESTAMP"}],[zr,function(t){return this.func("current_schemas",[t.args.this??ta()])}],[se,R("version")],[sn,function(t){return ds.call(this,t,"this"),"LOCALTIME"}],[Tn,R("DAYOFMONTH")],[un,R("DAYOFWEEK")],[hn,R("ISODOW")],[Sn,R("DAYOFYEAR")],[gn,function(t){return t.args.abbreviated?this.func("STRFTIME",[t.args.this,a.string("%a")]):this.func("DAYNAME",[t.args.this])}],[ei,function(t){return t.args.abbreviated?this.func("STRFTIME",[t.args.this,a.string("%b")]):this.func("MONTHNAME",[t.args.this])}],[l,AE],[bn,lE],[is,Et()],[ae,yE],[an,Et()],[ie,Ba],[Mn,Aa],[on,ga],[cn,Ba],[pn,Et()],[En,Et()],[qn,function(t){return`CAST(STRFTIME(${this.sql(t,"this")}, ${_s.DATEINT_FORMAT}) AS INT)`}],[os,function(t){return He.call(this,t,"DECODE",{replace:!1})}],[Dn,function(t){return`CAST(STRPTIME(CAST(${this.sql(t,"this")} AS TEXT), ${_s.DATEINT_FORMAT}) AS DATE)`}],[oe,function(t){return He.call(this,t,"ENCODE",{replace:!1})}],[Gn,function(t){return this.sql(new yr({this:t.args.this,expression:t.args.expression}))}],[Vs,R("LIST_DISTANCE")],[ce,Ya],[vn,Ya],[le,Ca],[Xi,function(t){return Pa.call(this,t,{withinGroup:!1})}],[Ee,R("UNNEST")],[Gs,function(){return""}],[Qt,function(t){return this.binary(t,"//")}],[Vn,R("ISINF")],[Te,R("ISNAN")],[Kn,function(t){return this.sql(new v({this:this.func("JSON_TYPE",[t.args.this]),expression:a.string("NULL")}))}],[Wn,function(t){return this.sql(new v({this:this.func("JSON_TYPE",[t.args.this]),expression:a.string("ARRAY")}))}],[jr,Ka],[pe,Ka],[Ks,ia("JARO_WINKLER_SIMILARITY")],[$n,R("JSON_EXISTS")],[ps,Ha],[Jn,va],[Zn,xE],[Se,va],[Us,function(t){let e=t.args.this;if(e instanceof Fn){let r=new Es({expressions:[e.args.this,new vs({this:sa("max_depth"),expression:a.number(2)})]}),i=new nt({expressions:[r]}).subquery(),E=t.args.alias;E&&!E.args.this&&E.setArgKey("this",H(`_u_${t.index}`));let c=new Us({this:i,alias:E}),u=new rr({this:c,kind:"cross"});return this.sql(u)}return La.call(this,t)}],[Ji,function(t){return this.func("BOOL_OR",[ke(t.args.this)])}],[Zi,function(t){return this.func("BOOL_AND",[ke(t.args.this)])}],[Ie,function(t){return Ns.call(this,t,1)}],[we,function(t){return Ns.call(this,t,2)}],[_e,function(t){return Ns.call(this,t,4)}],[Le,function(t){return Ns.call(this,t,8)}],[yi,OE],[dn,function(t){return Oa.call(this,t,{sep:" "})}],[es,function(t){return this.arraycontainsSql(t)}],[ns,function(t){return this.arrayoverlapsSql(t)}],[kr,function(t){return this.arraydistinctSql(t)}],[Xr,function(t){return this.arrayexceptSql(t)}],[js,R("LIST_MAX")],[Qs,R("LIST_MIN")],[zn,function(t){let e=new d({this:"MAP_KEYS",expressions:[t.args.key]});return this.func("ARRAY_CONTAINS",[e,t.args.this])}],[Xn,LE],[si,function(t){return this.func("UNHEX",[this.func("MD5",[t.args.this])])}],[pi,function(t){return Is.call(this,t,"SHA1")}],[ci,function(t){return Is.call(this,t,"SHA1",{isBinary:!0})}],[Oe,function(t){return Is.call(this,t,"SHA256")}],[li,function(t){return Is.call(this,t,"SHA256",{isBinary:!0})}],[Rn,ha],[ye,Xa],[As,R("QUANTILE_CONT")],[xs,R("QUANTILE_DISC")],[or,Rs([ra])],[Nn,Xa],[nt,Rs([RE])],[ls,function(t){return this.regexpreplaceSql(t)}],[oi,function(t){return this.regexpcountSql(t)}],[ai,function(t){return this.regexpinstrSql(t)}],[de,function(t){return this.regexplikeSql(t)}],[ni,function(t){return this.func("REGEXP_MATCHES",[t.args.this,t.args.expression,a.string("i")])}],[us,R("STR_SPLIT_REGEX")],[qe,Wa],[ji,Wa],[ir,function(t){return this.sql(t,"this")}],[Fs,function(t){return t.args.this instanceof ar?"TABLE":""}],[Ti,function(t){return this.func("EPOCH",[this.func("STRPTIME",[t.args.this,this.formatTime(t)])])}],[ft,fE],[Ht,R("LIST_TRANSFORM")],[On,Et()],[Pn,Et()],[Si,Sa],[Cn,uE],[In,Ta],[wn,Et()],[Ln,function(t){return this.func("DATE_DIFF",[a.string(t.args.unit),t.args.expression,t.args.this])}],[_n,Et()],[gi,function(t){return this.sql(new T({this:t.args.this,to:new l({this:"date"})}))}],[fi,fa],[Ai,function(t){return this.func("EPOCH",[new T({this:t.args.this,to:new l({this:"timestamp"})})])}],[Pe,function(t){return this.func("STRFTIME",[t.args.this,this.formatTime(t)])}],[Br,cE],[Yr,function(t){return this.sql(ot(t.args.this,l.build("VARIANT",{dialect:"duckdb"})))}],[Ce,R("EPOCH")],[Ni,function(t){return`CAST(SUBSTR(REPLACE(CAST(${this.sql(t,"this")} AS TEXT), '-', ''), 1, 8) AS INT)`}],[Ri,Et()],[di,function(t){let r=t.args.unit?.name?.toUpperCase()||"DAY";return this.func("DATE_DIFF",[a.string(r),new T({this:t.args.expression,to:new l({this:"timestamp"})}),new T({this:t.args.this,to:new l({this:"timestamp"})})])}],[Oi,function(t){return this.func("EPOCH_US",[dt(t.args.this)])}],[Pi,function(t){return this.func("EPOCH_MS",[dt(t.args.this)])}],[Li,function(t){return this.sql(new T({this:this.func("EPOCH",[dt(t.args.this)]),to:new l({this:"bigint"})}))}],[wi,function(t){return this.func("STRFTIME",[this.func("TO_TIMESTAMP",[t.args.this]),this.formatTime(t)])}],[ln,function(t){return this.func("DATE_TRUNC",[yt(t),new T({this:t.args.this,to:new l({this:"datetime"})})])}],[st,dE],[_i,function(t){return`CAST(TO_TIMESTAMP(${this.sql(t,"this")}) AS TEXT)`}],[ti,function(t){return this.func("MAP",[t.args?.keys,t.args?.values])}],[Qi,R("VAR_POP")],[fn,R("WEEKOFYEAR")],[An,function(t){return this.sql(new as({this:new C({this:"ISOYEAR"}),expression:t.args.this}))}],[xn,function(t){return this.sql(new as({this:new C({this:"ISOYEAR"}),expression:t.args.this}))}],[Ki,DE],[Wi,R("JSON_GROUP_OBJECT")],[$i,R("JSON_GROUP_OBJECT")],[ne,R("TIME_BUCKET")],[mn,pE]])}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([dr,mr,Nr,Ir])}static get TYPE_MAPPING(){return new Map([...Ct.TYPE_MAPPING,["binary","BLOB"],["bpchar","TEXT"],["char","TEXT"],["datetime","TIMESTAMP"],["decfloat","DECIMAL(38, 5)"],["float","REAL"],["jsonb","JSON"],["nchar","TEXT"],["nvarchar","TEXT"],["uint","UINTEGER"],["varbinary","BLOB"],["rowversion","BLOB"],["varchar","TEXT"],["timestampltz","TIMESTAMPTZ"],["timestampntz","TIMESTAMP"],["timestampS","TIMESTAMP_S"],["timestampMs","TIMESTAMP_MS"],["timestampNs","TIMESTAMP_NS"],["bigdecimal","DECIMAL(38, 5)"]])}static get RESERVED_KEYWORDS(){return new Set(["array","analyse","union","all","when","in_p","default","create_p","window","asymmetric","to","else","localtime","from","end_p","select","current_date","foreign","with","grant","session_user","or","except","references","fetch","limit","group_p","leading","into","collate","offset","do","then","localtimestamp","check_p","lateral_p","current_role","where","asc_p","placing","desc_p","user","unique","initially","column","both","some","as","any","only","deferrable","null_p","current_time","true_p","table","case","trailing","variadic","for","on","distinct","false_p","not","constraint","current_timestamp","returning","primary","intersect","having","analyze","current_user","and","cast","symmetric","using","order","current_catalog"])}static get UNWRAPPED_INTERVAL_VALUES(){return new Set([a,L])}static get PROPERTIES_LOCATION(){let s=new Map;return[...Ct.PROPERTIES_LOCATION.keys()].forEach(t=>{s.set(t,"unsupported")}),s.set(fr,"postSchema"),s.set(Ar,"postCreate"),s.set(Fs,"postAlias"),s.set(Ze,"postExpression"),s.set(Gs,"postCreate"),s}static get IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS(){return[Ui,Di,Hi,Gi,Bi]}static get ZIPF_TEMPLATE(){return y(`
11
11
  WITH rand AS (SELECT :randomExpr AS r),
12
12
  weights AS (
13
13
  SELECT i, 1.0 / POWER(i, :s) AS w
@@ -20,18 +20,18 @@ import{a as Ma}from"../chunk-WDNJ5X7T.js";import"../chunk-YGEJLTA7.js";import{$d
20
20
  SELECT MIN(i)
21
21
  FROM cdf
22
22
  WHERE p >= (SELECT r FROM rand)
23
- `)}static get NORMAL_TEMPLATE(){return M(":mean + (:stddev * SQRT(-2 * LN(GREATEST(:u1, 1e-10))) * COS(2 * PI() * :u2))")}static get SEEDED_RANDOM_TEMPLATE(){return M("(ABS(HASH(:seed)) % 1000000) / 1000000.0")}static get SEQ_UNSIGNED(){return M(":base % :maxVal")}static get SEQ_SIGNED(){return M(`
23
+ `)}static get NORMAL_TEMPLATE(){return y(":mean + (:stddev * SQRT(-2 * LN(GREATEST(:u1, 1e-10))) * COS(2 * PI() * :u2))")}static get SEEDED_RANDOM_TEMPLATE(){return y("(ABS(HASH(:seed)) % 1000000) / 1000000.0")}static get SEQ_UNSIGNED(){return y(":base % :maxVal")}static get SEQ_SIGNED(){return y(`
24
24
  (CASE WHEN :base % :maxVal >= :half
25
25
  THEN :base % :maxVal - :maxVal
26
26
  ELSE :base % :maxVal END)
27
- `)}static get MAPCAT_TEMPLATE(){return M(`CASE
27
+ `)}static get MAPCAT_TEMPLATE(){return y(`CASE
28
28
  WHEN :map1 IS NULL OR :map2 IS NULL THEN NULL
29
29
  ELSE MAP_FROM_ENTRIES(LIST_FILTER(LIST_TRANSFORM(
30
30
  LIST_DISTINCT(LIST_CONCAT(MAP_KEYS(:map1), MAP_KEYS(:map2))),
31
31
  __k -> STRUCT_PACK(key := __k, value := COALESCE(:map2[__k], :map1[__k]))
32
32
  ), __x -> __x.value IS NOT NULL))
33
33
  END
34
- `)}static get EXTRACT_STRFTIME_MAPPINGS(){return{WEEKISO:["%V","INTEGER"],YEAROFWEEK:["%G","INTEGER"],YEAROFWEEKISO:["%G","INTEGER"],NANOSECOND:["%n","BIGINT"]}}static get EXTRACT_EPOCH_MAPPINGS(){return{EPOCH_SECOND:"EPOCH",EPOCH_MILLISECOND:"EPOCH_MS",EPOCH_MICROSECOND:"EPOCH_US",EPOCH_NANOSECOND:"EPOCH_NS"}}static get BITMAP_CONSTRUCT_AGG_TEMPLATE(){return M(`
34
+ `)}static get EXTRACT_STRFTIME_MAPPINGS(){return{WEEKISO:["%V","INTEGER"],YEAROFWEEK:["%G","INTEGER"],YEAROFWEEKISO:["%G","INTEGER"],NANOSECOND:["%n","BIGINT"]}}static get EXTRACT_EPOCH_MAPPINGS(){return{EPOCH_SECOND:"EPOCH",EPOCH_MILLISECOND:"EPOCH_MS",EPOCH_MICROSECOND:"EPOCH_US",EPOCH_NANOSECOND:"EPOCH_NS"}}static get BITMAP_CONSTRUCT_AGG_TEMPLATE(){return y(`
35
35
  SELECT CASE
36
36
  WHEN l IS NULL OR LENGTH(l) = 0 THEN NULL
37
37
  WHEN LENGTH(l) != LENGTH(LIST_FILTER(l, __v -> __v BETWEEN 0 AND 32767)) THEN NULL
@@ -45,7 +45,7 @@ import{a as Ma}from"../chunk-WDNJ5X7T.js";import"../chunk-YGEJLTA7.js";import{$d
45
45
  ), '') AS h
46
46
  FROM (SELECT LIST_SORT(LIST_DISTINCT(LIST(:arg) FILTER(NOT :arg IS NULL))) AS l)
47
47
  )
48
- `)}static get RANDSTR_TEMPLATE(){return M(`
48
+ `)}static get RANDSTR_TEMPLATE(){return y(`
49
49
  SELECT LISTAGG(
50
50
  SUBSTRING(
51
51
  '${rE}',
@@ -58,13 +58,13 @@ import{a as Ma}from"../chunk-WDNJ5X7T.js";import"../chunk-YGEJLTA7.js";import{$d
58
58
  SELECT (ABS(HASH(i + :seed)) % 1000) / 1000.0 AS random_value
59
59
  FROM RANGE(:length) AS t(i)
60
60
  )
61
- `)}static get MINHASH_TEMPLATE(){return M(`
61
+ `)}static get MINHASH_TEMPLATE(){return y(`
62
62
  SELECT JSON_OBJECT('state', LIST(min_h ORDER BY seed), 'type', 'minhash', 'version', 1)
63
63
  FROM (
64
64
  SELECT seed, LIST_MIN(LIST_TRANSFORM(vals, __v -> HASH(CAST(__v AS VARCHAR) || CAST(seed AS VARCHAR)))) AS min_h
65
65
  FROM (SELECT LIST(:expr) AS vals), RANGE(0, :k) AS t(seed)
66
66
  )
67
- `)}static get MINHASH_COMBINE_TEMPLATE(){return M(`
67
+ `)}static get MINHASH_COMBINE_TEMPLATE(){return y(`
68
68
  SELECT JSON_OBJECT('state', LIST(min_h ORDER BY idx), 'type', 'minhash', 'version', 1)
69
69
  FROM (
70
70
  SELECT
@@ -75,7 +75,7 @@ import{a as Ma}from"../chunk-WDNJ5X7T.js";import"../chunk-YGEJLTA7.js";import{$d
75
75
  UNNEST(CAST(sig -> 'state' AS UBIGINT[])) WITH ORDINALITY AS t(val, pos)
76
76
  GROUP BY pos
77
77
  )
78
- `)}static get APPROXIMATE_SIMILARITY_TEMPLATE(){return M(`
78
+ `)}static get APPROXIMATE_SIMILARITY_TEMPLATE(){return y(`
79
79
  SELECT CAST(SUM(CASE WHEN num_distinct = 1 THEN 1 ELSE 0 END) AS DOUBLE) / COUNT(*)
80
80
  FROM (
81
81
  SELECT pos, COUNT(DISTINCT h) AS num_distinct
@@ -86,12 +86,12 @@ import{a as Ma}from"../chunk-WDNJ5X7T.js";import"../chunk-YGEJLTA7.js";import{$d
86
86
  )
87
87
  GROUP BY pos
88
88
  )
89
- `)}static get ARRAYS_ZIP_TEMPLATE(){return M(`
89
+ `)}static get ARRAYS_ZIP_TEMPLATE(){return y(`
90
90
  CASE WHEN :nullCheck THEN NULL
91
91
  WHEN :allEmptyCheck THEN [:emptyStruct]
92
92
  ELSE LIST_TRANSFORM(RANGE(0, :maxLen), __i -> :transformStruct)
93
93
  END
94
- `)}timeSliceSql(s){let t=s.args.this,e=s.args.expression,r=s.args.unit,i=s.text("kind").toUpperCase(),E=new Y({this:e,unit:r}),c=this.func("time_bucket",[E,t]);if(i!=="END")return this.sql(c);let u=new I({this:c,expression:E.copy()});return t?.isType("date")?this.sql(new T({this:u,to:new l({this:"date"})})):this.sql(u)}bitmapBucketNumberSql(s){let t=s.args.this,e=new I({this:new w({this:new jt({this:new w({this:new F({this:t,expression:a.number(1)})}),expression:a.number(32768)})}),expression:a.number(1)}),r=new jt({this:t,expression:a.number(32768)});return this.sql(new $({}).when(new Hs({this:t,expression:a.number(0)}),e).else(r))}bitmapBitPositionSql(s){let t=s.args.this;return this.sql(new St({this:new w({this:new j({this:new Hs({this:t,expression:a.number(0)}),true:new F({this:t,expression:a.number(1)}),false:new Ut({this:t})})}),expression:iE}))}bitmapConstructAggSql(s){let t=s.args.this;return`(${this.sql(b(this._constructor.BITMAP_CONSTRUCT_AGG_TEMPLATE.copy(),[],{arg:t}))})`}nthValueSql(s){return(s.args.fromFirst??!0)||this.unsupported("DuckDB's NTH_VALUE doesn't support starting from the end"),this.functionFallbackSql(s)}randstrSql(s){let t=s.args.this,e=s.args.generator,r;return e?e instanceof z?r=e.args.this??e:r=e:r=a.number(nE),`(${this.sql(b(this._constructor.RANDSTR_TEMPLATE.copy(),[],{seed:r,length:t}))})`}zipfSql(s){let t=s.args.this,e=s.args.elementcount,r=s.args.gen,i;return r instanceof z?i=new z({}):i=new pt({this:new w({this:new St({this:new Ut({this:new R({this:"HASH",expressions:[(r??f()).copy()]})}),expression:a.number(1e6)})}),expression:a.number("1000000.0")}),`(${this.sql(b(this._constructor.ZIPF_TEMPLATE.copy(),[],{s:t,n:e,randomExpr:i}))})`}toBinarySql(s){let t=s.args.this,e=K(s.args.format,N),r=s.args.safe,i=J(s);if(!e&&!i){let u=r?"TRY_TO_BINARY":"TO_BINARY";return this.func(u,[t])}let E=e?.name?.toUpperCase()??"HEX",c;if(E==="UTF-8"||E==="UTF8")c=this.func("ENCODE",[t]);else if(E==="BASE64")c=this.func("FROM_BASE64",[t]);else if(E==="HEX")c=this.func("UNHEX",[t]);else{if(r)return this.sql(f());this.unsupported(`format ${E} is not supported`),c=this.func("TO_BINARY",[t])}return r?`TRY(${c})`:c}greatestLeastSql(s){let t=[s.args.this,...s.args.expressions??[]],e=this.functionFallbackSql(s);if(s.args.ignoreNulls)return this.sql(e);let r=new $({}).when(xs(t.map(i=>(i??f()).is(f())),{copy:!1}),f());return r.setArgKey("default",e),this.sql(r)}generatorSql(s){let t=s.args.rowcount;return s.args.timelimit&&this.unsupported("GENERATOR TIMELIMIT parameter is not supported in DuckDB"),t?this.func("range",[t]):(this.unsupported("GENERATOR without ROWCOUNT is not supported in DuckDB"),this.func("range",[a.number(0)]))}greatestSql(s){return this.greatestLeastSql(s)}leastSql(s){return this.greatestLeastSql(s)}lambdaSql(s,t={}){let e=t.arrowSep??"->",r=t.wrap??!0,i="";s.args.colon&&(i="LAMBDA ",e=":",r=!1);let E=super.lambdaSql(s,{arrowSep:e,wrap:r});return`${i}${E}`}sortArraySql(s){let t=s.args.this,e=s.args.asc,r=s.args.nullsFirst;if(!(e instanceof Z)&&!(r instanceof Z))return this.func("LIST_SORT",[t,e,r]);let i=r instanceof Z&&r.args.this===!0,E=i?a.string("NULLS FIRST"):void 0;if(!(e instanceof Z))return this.func("LIST_SORT",[t,e,E]);let c=e.args.this===!1;return!c&&!i?this.func("LIST_SORT",[t]):i?this.func("LIST_SORT",[t,a.string(c?"DESC":"ASC"),a.string("NULLS FIRST")]):this.func("ARRAY_REVERSE_SORT",[t])}showSql(s){return`SHOW ${s.name}`}installSql(s){let t=s.args.force?"FORCE ":"",e=this.sql(s,"this"),r=s.args.from?` FROM ${s.args.from}`:"";return`${t}INSTALL ${e}${r}`}approxTopKSql(s){return this.unsupported("APPROX_TOP_K cannot be transpiled to DuckDB due to incompatible return types. "),this.functionFallbackSql(s)}fromIso8601TimestampSql(s){return this.sql(new T({this:s.args.this,to:new l({this:"timestamptz"})}))}strToTimeSql(s){let t=s.args.targetType,e=t&&["timestampltz","timestamptz"].includes(t.args.this);if(s.args.safe){let i=this.formatTime(s),E=e?"timestamptz":"timestamp";return this.sql(new T({this:this.func("TRY_STRPTIME",[s.args.this,i]),to:new l({this:E})}))}let r=Ra.call(this,s);return e?this.sql(new T({this:r,to:new l({this:"timestamptz"})})):r}strToDateSql(s){let t=this.formatTime(s),e=s.args.safe?"TRY_STRPTIME":"STRPTIME";return this.sql(new T({this:this.func(e,[s.args.this,t]),to:new l({this:"date"})}))}tsOrDsToTimeSql(s){let t=s.args.this,e=this.formatTime(s),r=s.args.safe,i=l.build("TIME",{dialect:"duckdb"}),E=r?vi:T;if(e){let c=r?"TRY_STRPTIME":"STRPTIME",u=new R({this:c,expressions:[t??f(),e]});return this.sql(new E({this:u,to:i}))}return t instanceof mi||t?.isType("time")?this.sql(t??f()):this.sql(new E({this:t,to:i}))}validateRegexpFlags(s,t){if(!(s instanceof N))return;if(!s.isString){this.unsupported("Non-literal regexp flags are not fully supported in DuckDB");return}let e=s.name??"",r=new Set(t),i=[...new Set(e)].filter(c=>!r.has(c));return 0<i.length&&this.unsupported(`Regexp flags ${JSON.stringify(i.sort())} are not supported in this context`),[...e].filter(c=>r.has(c)).join("")||void 0}regexplikeSql(s){let t=s.args.this,e=s.args.expression,r=s.args.flag;if(!s.args.fullMatch)return this.func("REGEXP_MATCHES",[t,e,r]);let i=this.validateRegexpFlags(r,"cims"),E=new Ot({expressions:[a.string("^("),new w({this:e}),a.string(")$")]});return i&&(r=a.string(i)),this.func("REGEXP_MATCHES",[t,E,r])}arrayoverlapsSql(s){if(!s.args.nullsafe)return this.binary(s,"&&");let t=s.args.this,e=s.args.expression,r=this.sql(kt([new Gt({this:new Bt({this:t.copy()}),expression:d("LIST_COUNT",t.copy())}),new Gt({this:new Bt({this:e.copy()}),expression:d("LIST_COUNT",e.copy())})]));return`(${this.binary(s,"&&")}) OR (${r})`}arraycontainsSql(s){let t=s.args.this,e=s.args.expression,r=this.func("ARRAY_CONTAINS",[t,e]);if(s.args.checkNull){let i=new le({this:new Gt({this:new Bt({this:t}),expression:new R({this:"LIST_COUNT",expressions:[t]})}),expression:new Z({this:!1})});return this.sql(new j({this:new Tt({this:e,expression:new ht({})}),true:i,false:M(r)}))}return r}arraydistinctSql(s){let t=s.args.this,e=this.func("LIST_DISTINCT",[t]);if(s.args.checkNull){let r=new R({this:"LIST_APPEND",expressions:[new R({this:"LIST_DISTINCT",expressions:[new ts({this:t})]}),new ht({})]});return this.sql(new j({this:new Gt({this:new Bt({this:t}),expression:new R({this:"LIST_COUNT",expressions:[t]})}),true:r,false:M(e)}))}return e}regexpinstrSql(s){let t=s.args.this,e=s.args.expression,r=s.args.position,i=s.args.occurrence,E=i??a.number(1),c=s.args.option,u=s.args.parameters,A=this.validateRegexpFlags(u?.[0],"ims");A&&(e=new Ot({expressions:[a.string(`(?${A})`),e]}));let L=a.number(0);r&&(!r.isNumber||1<Number(r.toValue()))&&(t=new Pt({this:t,start:r}),L=new F({this:r,expression:a.number(1)}));let O=p((ot,Wt)=>{let tE=new q({this:new R({this:ot,expressions:[t,e]}),expressions:[new B({this:a.number(1),expression:Wt})],offset:1}),sE=new R({this:"LIST_TRANSFORM",expressions:[tE,new rt({this:new Q({this:H("x")}),expressions:[H("x")]})]});return new Yt({this:new R({this:"LIST_SUM",expressions:[sE]}),expressions:[a.number(0)]})},"sumLengths"),G=new I({this:new I({this:new I({this:a.number(1),expression:O("STRING_SPLIT_REGEX",E)}),expression:O("REGEXP_EXTRACT_ALL",new F({this:E,expression:a.number(1)}))}),expression:L});if(c&&c.isNumber&&Number(c.toValue())===1){let ot=new q({this:new R({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]}),expressions:[E],offset:1});G=new I({this:G,expression:new Yt({this:new Q({this:ot}),expressions:[a.number(0)]})})}let Ls=[s.args.this,s.args.expression,r,i,c,u].filter(Boolean).map(ot=>new Tt({this:ot.copy(),expression:new ht({})})),ut=new R({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]}),zo=st().when(Ls.reduce((ot,Wt)=>ot?new Xt({this:ot,expression:Wt}):Wt),new ht({})).when(new v({this:e.copy(),expression:a.string("")}),a.number(0)).when(new Ys({this:new Q({this:ut}),expression:E}),a.number(0)).else(G);return this.sql(zo)}regexpreplaceSql(s){let t=s.args.this,e=s.args.expression,r=s.args.replacement??a.string(""),i=s.args.position,E=s.args.occurrence,c=s.args.modifiers,u=c,A="";if(c&&c.isString&&(A=this.validateRegexpFlags(c,"cimsg")??"",u=void 0),E&&!E.isNumber)this.unsupported("REGEXP_REPLACE with non-literal occurrence");else{let V=E&&E.isNumber?Number(E.toValue()):0;1<V?this.unsupported(`REGEXP_REPLACE occurrence=${V} not supported`):V===0&&!A.includes("g")&&!s.args.singleReplace&&(A+="g")}let L;if(i&&!i.isNumber)this.unsupported("REGEXP_REPLACE with non-literal position");else if(i&&i.isNumber&&1<Number(i.toValue())){let V=Number(i.toValue());L=new Pt({this:t,start:a.number(1),length:a.number(V-1)}),t=new Pt({this:t,start:a.number(V)})}let O=A?a.string(A):u,G=new R({this:"REGEXP_REPLACE",expressions:[t,e,r,...O?[O]:[]].filter(Boolean)});return L&&(G=new Ot({expressions:[L,G]})),this.sql(G)}regexpcountSql(s){let t=s.args.this,e=s.args.expression,r=s.args.position,i=s.args.parameters,E=this.validateRegexpFlags(i?.[0],"ims");r&&(t=new Pt({this:t,start:r})),E&&(e=new Ot({expressions:[a.string(`(?${E})`),e]}));let c=new $({ifs:[new j({this:new v({this:e,expression:a.string("")}),true:a.number(0)})],default:new Q({this:new R({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]})})});return this.sql(c)}arrayBagSql(s,t,e){let r=new w({this:b(s.copy(),[],{arr1:t,arr2:e})});return this.sql(b(this._constructor.ARRAY_BAG_TEMPLATE.copy(),[],{arr1:t,arr2:e,cond:r}))}arrayintersectSql(s){return s.args.isMultiset&&s.args.expressions?.length===2?this.arrayBagSql(this._constructor.ARRAY_INTERSECTION_CONDITION,s.args.expressions[0],s.args.expressions[1]):this.functionFallbackSql(s)}arrayexceptSql(s){let t=s.args.this,e=s.args.expression;return s.args.isMultiset?this.arrayBagSql(this._constructor.ARRAY_EXCEPT_CONDITION,t,e):this.sql(b(this._constructor.ARRAY_EXCEPT_SET_TEMPLATE.copy(),[],{arr1:t,arr2:e}))}currentDateSql(s){if(!s.args.this)return"CURRENT_DATE";let t=new T({this:new Et({this:new se({}),zone:s.args.this}),to:new l({this:"date"})});return this.sql(t)}parseJsonSql(s){let t=s.args.this;return s.args.safe?this.sql(new $({}).when(this.func("json_valid",[t??f()]),t instanceof N||typeof t=="string"?t:"").else(f())):this.func("JSON",[t])}truncSql(s){return ds.call(this,s,"decimals"),this.func("TRUNC",[s.args.this])}normalSql(s){let t=s.args.this,e=s.args.stddev,r=s.args.gen,i,E;if(r instanceof z&&!r.args.this)i=new z({}),E=new z({});else{let c=(r instanceof z?r.args.this:r)??f();i=b(this._constructor.SEEDED_RANDOM_TEMPLATE.copy(),[],{seed:c}),E=b(this._constructor.SEEDED_RANDOM_TEMPLATE.copy(),[],{seed:new I({this:c.copy(),expression:a.number(1)})})}return this.sql(b(this._constructor.NORMAL_TEMPLATE.copy(),[],{mean:t,stddev:e,u1:i,u2:E}))}uniformSql(s){let t=s.args.this,e=s.args.expression,r=s.args.gen,i=t instanceof a&&t.isInteger&&e instanceof a&&e.isInteger,E;r instanceof z?E=new z({}):E=new pt({this:new w({this:new St({this:new Ut({this:new R({this:"HASH",expressions:[r||""]})}),expression:a.number(1e6)})}),expression:a.number("1000000.0")});let c=new F({this:e,expression:t});i&&(c=new I({this:c,expression:a.number(1)}));let u=new I({this:t,expression:new gt({this:E,expression:new w({this:c})})});return i&&(u=new T({this:new oe({this:u}),to:new l({this:"bigint"})})),this.sql(u)}timeFromPartsSql(s){let t=s.args.nano;if(s.args.overflow){let r=K(s.args.hour,"string",a),i=K(s.args.min,"string",a),E=K(s.args.sec,"string",a);if(!t&&[r,i,E].every(u=>u instanceof a&&u.isNumber)){let u=parseInt((r instanceof a?r.args.this:r)??"0"),A=parseInt((i instanceof a?i.args.this:i)??"0"),L=parseInt((E instanceof N?E.args.this:E)??"0");if(0<=u&&u<=23&&0<=A&&A<=59&&0<=L&&L<=59)return x("MAKE_TIME").call(this,s)}t&&(E=E.add(t.pop().div(a.number("1000000000.0"))));let c=r.mul(a.number(3600)).add(i.mul(a.number(60))).add(E);return this.sql(new I({this:new T({this:a.string("00:00:00"),to:l.build("TIME")}),expression:new Y({this:c,unit:new C({this:"SECOND"})})}))}return t&&s.setArgKey("sec",new I({this:s.args.sec,expression:new pt({this:t.pop(),expression:a.number(1e9)})})),x("MAKE_TIME").call(this,s)}extractSql(s){let t=s.args.expression;t?.isType(["timestamptz","timestampltz"])&&this.unsupported("EXTRACT from TIMESTAMPTZ / TIMESTAMPLTZ may produce different results due to timezone handling differences");let e=K(s.args.this,N)?.name.toUpperCase();if(e!==void 0&&e in h.EXTRACT_STRFTIME_MAPPINGS){let[r,i]=h.EXTRACT_STRFTIME_MAPPINGS[e],E=e==="NANOSECOND"&&t?.isType(["time","timetz"]),c=t??f();if(E)return this.unsupported("Parameter NANOSECOND is not supported with TIME type in DuckDB"),this.sql(new T({this:new gt({this:new is({this:new C({this:"MICROSECOND"}),expression:c}),expression:a.number(1e3)}),to:l.build(i,{dialect:"duckdb"})}));let u=c;return e==="NANOSECOND"&&(u=new T({this:c,to:new l({this:"timestampNs"})})),this.sql(new T({this:new R({this:"STRFTIME",expressions:[u,a.string(r)]}),to:l.build(i,{dialect:"duckdb"})}))}if(e!==void 0&&e in h.EXTRACT_EPOCH_MAPPINGS){let r=h.EXTRACT_EPOCH_MAPPINGS[e],i=new R({this:r,expressions:[t??f()]});return e==="EPOCH_SECOND"&&(i=new T({this:i,to:l.build("BIGINT",{dialect:"duckdb"})})),this.sql(i)}return super.extractSql(s)}timestampFromPartsSql(s){let t=s.args.this,e=s.args.expression;if(t&&e)return this.sql(new I({this:t,expression:e}));let r=s.args.sec;if(!r)return x("MAKE_TIMESTAMP").call(this,s);let i=s.args.milli;i&&(r=new I({this:r,expression:new w({this:new pt({this:i.pop(),expression:a.number("1000.0")})})}));let E=s.args.nano;return E&&(r=new I({this:r,expression:new w({this:new pt({this:E.pop(),expression:a.number("1000000000.0")})})})),(i||E)&&s.setArgKey("sec",r),x("MAKE_TIMESTAMP").call(this,s)}timestampLtzFromPartsSql(s){let t=s.args.nano;return t&&t.pop(),`CAST(${x("MAKE_TIMESTAMP").call(this,s)} AS TIMESTAMPTZ)`}timestampTzFromPartsSql(s){let t=s.args.zone;t&&(t=t.pop());let e=s.args.nano;e&&e.pop();let r=x("MAKE_TIMESTAMP").call(this,s);return t?`${r} AT TIME ZONE ${this.sql(t)}`:r}tableSampleSql(s,t={}){let e=t.tablesampleKeyword;if(s.parent instanceof nt||(e="TABLESAMPLE"),s.args.size){let r=s.args.method;r instanceof N&&r.name?.toUpperCase()!=="RESERVOIR"&&(this.unsupported(`Sampling method ${r} is not supported with a discrete sample count, defaulting to reservoir sampling`),s.setArgKey("method",new C({this:"RESERVOIR"})))}return super.tableSampleSql(s,{tablesampleKeyword:e})}columnDefSql(s,t={}){return s.parent instanceof tr?this.sql(s,"this"):super.columnDefSql(s,t)}joinSql(s){let t=["","inner","outer"].includes(s.args.kind??"");if(!s.args.using&&!s.args.on&&!s.args.method&&t){if(s.args.this instanceof os)return super.joinSql(s.on(new Z({this:!0})));s.setArgKey("side",void 0),s.setArgKey("kind",void 0)}return super.joinSql(s)}generateSeriesSql(s){return la("GENERATE_SERIES",{exclusiveFuncName:"RANGE"}).call(this,s)}countIfSql(s){return 1<this.dialect.version.major||this.dialect.version.major===1&&2<=this.dialect.version.minor?this.functionFallbackSql(s):xa.call(this,s)}bracketSql(s){if(1<this.dialect.version.major||this.dialect.version.major===1&&2<=this.dialect.version.minor)return super.bracketSql(s);let t=s.args.this;t instanceof W&&t.replace(new w({this:t.copy()}));let e=super.bracketSql(s);if(!s.args.returnsListForMaps){let r=K(t,N),i=r?.type?r:r&&Nt(r,{dialect:this.dialect});X(i,"map")&&(e=`(${e})[1]`)}return e}withinGroupSql(s){let t=s.args.this;if(t instanceof bi){let i=s.args.expression;if(!(i instanceof wt))return this.sql(t);let E=t.args.this;t.setArgKey("this",new wt({this:K(t.args.this,N)?.copy(),expressions:i.args.expressions}));let c=this.functionFallbackSql(t);return E instanceof N?this.addArrayAggNullFilter(c,t,E):""}let e=this.sql(s,"expression");if(t instanceof fs||t instanceof As){let i=s.find(rr);i&&(t.setArgKey("expression",t.args.this),t.setArgKey("this",i.args.this))}return`${this.sql(s,"this").replace(/\)$/,"")}${e})`}lengthSql(s){let t=s.args.this;if(!s.args.binary||t instanceof a&&t.isString)return this.func("LENGTH",[t]);if((t?.type?t:t&&Nt(t,{dialect:this.dialect}))?.isType(l.TEXT_TYPES))return this.func("LENGTH",[t]);let r=new T({this:t,to:new l({this:"varbinary"})}),i=new T({this:t,to:new l({this:"varchar"})}),E=new $({this:new R({this:"TYPEOF",expressions:t?[t]:[]})}).when(a.string("BLOB"),new zt({this:r})).else(new R({this:"LENGTH",expressions:[i]}));return this.sql(E)}levenshteinSql(s){ds.call(this,s,"insCost","delCost","subCost");let t=s.args.this,e=s.args.expression,r=s.args.maxDist;if(!r)return this.func("LEVENSHTEIN",[t,e]);let i=new Se({this:t,expression:e});return this.sql(new Qn({this:i,expressions:[r],ignoreNulls:!1}))}padSql(s){let t=s.args.this,e=s.args.fillPattern??a.string(" ");if(J(t)||J(e)){let r=s.args.expression,i=s.args.isLeft,E=new zt({this:t}),c=new F({this:r,expression:E}),u=new ce({this:a.number(0),expressions:[c],ignoreNulls:!0}),A=new Re({this:e,times:[u]}),[L,O]=i?[A,t]:[t,A];return this.sql(new Cr({this:L,expression:O}))}return super.padSql(s)}minhashSql(s){let t=s.args.this,e=s.args.expressions??[];if(e.length!==1||e[0]instanceof Er)return this.unsupported("MINHASH with multiple expressions or * requires manual restructuring"),this.func("MINHASH",[t,...e]);let r=b(h.MINHASH_TEMPLATE.copy(),[],{expr:e[0],k:t});return`(${this.sql(r)})`}minhashCombineSql(s){let t=b(h.MINHASH_COMBINE_TEMPLATE.copy(),[],{expr:s.args.this});return`(${this.sql(t)})`}approximateSimilaritySql(s){let t=b(h.APPROXIMATE_SIMILARITY_TEMPLATE.copy(),[],{expr:s.args.this});return`(${this.sql(t)})`}arraySliceSql(s){let t=s.args.start,e=s.args.end;return s.args.zeroBased&&(t&&(t=st().when(new yr({this:t.copy(),expression:a.number(0)}),new I({this:t.copy(),expression:a.number(1)}),{copy:!1}),t.setArgKey("default",s.args.start)),e&&(e=st().when(new Ys({this:e.copy(),expression:a.number(0)}),new F({this:e.copy(),expression:a.number(1)}),{copy:!1}),e.setArgKey("default",s.args.end))),this.func("ARRAY_SLICE",[s.args.this,t,e,s.args.step])}arraysZipSql(s){let t=s.args.expressions??[];if(t.length===0)return this.sql(new W({expressions:[new ge({keys:new W,values:new W})]}));let e=t.map(O=>new Q({this:O})),r=e.length===1?e[0]:new ce({this:e[0],expressions:e.slice(1),ignoreNulls:!1}),i=new ft({expressions:t.map((O,G)=>new Lt({this:a.string(`$${G+1}`),expression:f()}))}),E=new I({this:new bs({this:new It({this:"__i"})}),expression:a.number(1)}),c=new ft({expressions:t.map((O,G)=>new Lt({this:a.string(`$${G+1}`),expression:new q({this:new R({this:"COALESCE",expressions:[O,new W({})]}),expressions:[E.copy()]})}))}),u=xs(t.map(O=>O.is(f()))),A=kt(t.map(O=>new v({this:new Q({this:O}),expression:a.number(0)}))),L=b(h.ARRAYS_ZIP_TEMPLATE.copy(),[],{nullCheck:u,allEmptyCheck:A,emptyStruct:i,maxLen:r,transformStruct:c});return this.sql(L)}lowerSql(s){let t=this.func("LOWER",[et(s.args.this)]);return ct.call(this,s,t)}upperSql(s){let t=this.func("UPPER",[et(s.args.this)]);return ct.call(this,s,t)}reverseSql(s){let t=this.func("REVERSE",[et(s.args.this)]);return ct.call(this,s,t)}randSql(s){s.args.this&&this.unsupported("RANDOM with seed is not supported in DuckDB");let e=s.args.lower,r=s.args.upper;if(e&&r){let i=new w({this:new F({this:r,expression:e})}),E=new I({this:e,expression:new gt({this:d("random"),expression:i})});return this.sql(it(E,"bigint"))}return"RANDOM()"}rightSql(s){let t=s.args.this,e=s.args.expression;if(J(t)){let r=new Xn({this:t}),i=new gt({this:e,expression:a.number(2)});return`UNHEX(${this.func("RIGHT",[r,i])})`}return this.func("RIGHT",[t,e])}base64EncodeSql(s){let t=s.args.this;t?.isType(l.TEXT_TYPES)&&(t=new R({this:"ENCODE",expressions:[t]})),t=new Hn({this:t});let e=s.args.maxLineLength,r=s.args.alphabet;t=Jo(t,r);let i=e instanceof a&&e.isNumber?parseInt(e.args.this??"0"):0;if(0<i){let E=new Qr({expressions:[a.number(10)]});t=new xi({this:new cs({this:t,expression:a.string(`(.{${i}})`),replacement:new Ot({expressions:[a.string("\\1"),E.copy()]})}),expression:E,position:"trailing"})}return this.sql(t)}replaceSql(s){let t=this.func("REPLACE",[et(s.args.this),et(s.args.expression),et(s.args.replacement)]);return ct.call(this,s,t)}bitwiseOp(s,t){Xa(s);let e=this.binary(s,t);return ct.call(this,s,e)}bitwiseXorSql(s){Xa(s);let t=this.func("XOR",[s.args.this,s.args.expression]);return ct.call(this,s,t)}objectInsertSql(s){let t=s.args.this,e=s.args.key,r=e instanceof N?e.name:"",i=this.sql(s,"value"),E=`${r} := ${i}`;return t instanceof ft&&(!t.args.expressions||t.args.expressions.length===0)?this.func("STRUCT_PACK",[E]):this.func("STRUCT_INSERT",[t,E])}mapCatSql(s){let t=b(h.MAPCAT_TEMPLATE.copy(),[],{map1:s.args.this,map2:s.args.expression});return this.sql(t)}mapDeleteSql(s){let t=s.args.this,e=s.args.expressions??[],r=new Us({this:H("x"),expression:H("key")}),i=new Ft({this:new Qt({this:r,expressions:e})}),E=new rt({this:i,expressions:[H("x")]}),c=new es({this:d("map_entries",t),expression:E}),u=d("map_from_entries",c);return this.sql(u)}mapSizeSql(s){return this.func("CARDINALITY",[s.args.this])}mapPickSql(s){let t=s.args.this,e=s.args.expressions??[],r=new Us({this:H("x"),expression:H("key")}),i;e.length===1&&e[0].isType?.("array")?i=new rt({this:d("ARRAY_CONTAINS",e[0],r),expressions:[H("x")]}):i=new rt({this:new Qt({this:r,expressions:e}),expressions:[H("x")]});let E=d("MAP_FROM_ENTRIES",d("LIST_FILTER",d("MAP_ENTRIES",t),i));return this.sql(E)}mapInsertSql(s){s.args.updateFlag&&this.unsupported("MAP_INSERT update_flag is not supported in DuckDB");let t=s.args.this,e=s.args.key,r=s.args.value;if(r!==void 0&&t){let u=t.type;if(u instanceof l&&u.args.expressions&&1<u.args.expressions.length){let A=u.args.expressions[1];r=it(r,A)}}let i=new ft({expressions:[new Lt({this:e,expression:r})]}),E=new fe({this:i}),c=d("MAP_CONCAT",t,E);return this.sql(c)}startsWithSql(s){return this.func("STARTS_WITH",[et(s.args.this),et(s.args.expression)])}spaceSql(s){return this.sql(new Re({this:a.string(" "),times:[new T({this:s.args.this,to:new l({this:"bigint"})})]}))}tableFromRowsSql(s){if(s.args.this instanceof Ks){let t=new Ms({this:s.args.this,alias:s.args.alias,joins:s.args.joins});return this.sql(t)}return super.tableFromRowsSql(s)}unnestSql(s){if(s.args.explodeArray){s.args.expressions||s.setArgKey("expressions",[]),s.args.expressions?.push(new Bs({this:new C({this:"max_depth"}),expression:a.number(2)}));let e=s.args.alias;e instanceof Dt&&(s.setArgKey("alias",void 0),e.args.columns&&0<e.args.columns.length&&(e=new Dt({this:m(e.args.columns,0)})));let r=super.unnestSql(s),i=e?` AS ${this.sql(e)}`:"";return`(SELECT ${r})${i}`}return super.unnestSql(s)}ignoreNullsSql(s){let t=s.args.this;if(this._constructor.IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS.some(r=>t instanceof r))return super.ignoreNullsSql(s);let e=t;return e instanceof Ui&&(e=new vt({this:e.args.this})),e instanceof vt||e instanceof yi||this.unsupported("IGNORE NULLS is not supported for non-window functions."),this.sql(e)}splitSql(s){let t=d("STR_SPLIT",s.args.this,s.args.expression),e=st();e.setArgKey("default",t);let r=!1;return s.args.nullReturnsNull&&(e=e.when(new Tt({this:s.args.expression,expression:new ht({})}),new ht({}),{copy:!1}),r=!0),s.args.emptyDelimiterReturnsWhole&&(e=e.when(new v({this:s.args.expression.copy(),expression:a.string("")}),ea([s.args.this]),{copy:!1}),r=!0),this.sql(r?e:t)}splitPartSql(s){let t=s.args.this,e=s.args.delimiter,r=s.args.partIndex;if(e&&r){s.args.partIndexZeroAsOne&&(r=new w({this:st().when(new v({this:r.copy(),expression:a.number(0)}),a.number(1),{copy:!1})}),r.args.this.setArgKey("default",s.args.partIndex));let i=new R({this:"SPLIT_PART",expressions:[t,e,r].filter(Boolean)}),E=!1,c=st();if(c.setArgKey("default",i),s.args.emptyDelimiterReturnsWhole){let u=new w({this:st().when(new Xt({this:new v({this:r.copy(),expression:a.number(1)}),expression:new v({this:r.copy(),expression:a.number(-1)})}),t,{copy:!1})});u.args.this.setArgKey("default",a.string("")),c=c.when(new v({this:e.copy(),expression:a.string("")}),u,{copy:!1}),E=!0}return this.sql(E?c:i)}return this.functionFallbackSql(s)}respectNullsSql(s){return this._constructor.IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS.some(t=>s.args.this instanceof t)?super.respectNullsSql(s):(this.unsupported("RESPECT NULLS is not supported for non-window functions."),this.sql(s,"this"))}arrayToStringSql(s){let t=s.args.null;if(s.args.nullIsEmpty){let e=H("x"),r=new Ht({this:s.args.this.copy(),expression:new rt({this:new Yt({this:it(e,"TEXT"),expressions:[a.string("")]}),expressions:[e]})}),i=new Qs({this:r,expression:s.args.expression});return s.args.nullDelimIsNull?this.sql(st().when(s.args.expression.copy().is(f()),f()).else(i)):this.sql(i)}if(t){let e=H("x");return this.sql(new Qs({this:new Ht({this:s.args.this,expression:new rt({this:new Yt({this:e,expressions:[t]}),expressions:[e]})}),expression:s.args.expression}))}return this.func("ARRAY_TO_STRING",[s.args.this,s.args.expression])}regexpExtractCommon(s){let t=s.args.this,e=s.args.group,r=s.args.parameters,i=s.args.position,E=s.args.occurrence,c="nullIfPosOverflow"in s.args?s.args.nullIfPosOverflow:void 0;r&&r.isString&&(r.name??"").includes("e")&&(r=a.string((r.name??"").replace(/e/g,"")));let u=this.validateRegexpFlags(r,"cims"),A=e,L=String(this.dialect._constructor.REGEXP_EXTRACT_DEFAULT_GROUP);!u&&e&&(e instanceof It&&e.name===L||e instanceof a&&String(e.args.this)===L)&&(A=void 0);let O=u?a.string(u):void 0;i&&(!(i instanceof a&&i.isInteger)||1<parseInt(i.args.this??"0"))&&(t=new Pt({this:t,start:i}),c&&(t=new le({this:t,expression:a.string("")})));let G=s instanceof Ae,V=E&&(!(E instanceof a&&E.isInteger)||1<parseInt(E.args.this??"0")),Ls=G||V?"REGEXP_EXTRACT_ALL":"REGEXP_EXTRACT",ut=new R({this:Ls,expressions:[t,s.args.expression,A,O].filter(Boolean)});return G&&V?ut=new q({this:ut,expressions:[new B({this:E})]}):V&&(ut=new R({this:"ARRAY_EXTRACT",expressions:[ut,E]})),this.sql(ut)}regexpExtractSql(s){return this.regexpExtractCommon(s)}regexpExtractAllSql(s){return this.regexpExtractCommon(s)}numberToStrSql(s){if(s.args.culture)return this.unsupported("DuckDB does not support the culture argument in NumberToStr"),this.functionFallbackSql(s);let t=s.args.format?.name;return t&&/^\d+$/.test(t)?this.func("FORMAT",[a.string(`{:,.${t}f}`),s.args.this]):(this.unsupported("Only integer formats are supported by NumberToStr"),this.functionFallbackSql(s))}autoIncrementColumnConstraintSql(s){return this.unsupported("The AUTOINCREMENT column constraint is not supported by DuckDB"),""}aliasesSql(s){let t=s.args.this;return t instanceof ki?this.posexplodeSql(t):super.aliasesSql(s)}posexplodeSql(s){let t=s.args.this,e=s.parent,r=new It({this:"pos",quoted:!1}),i=new It({this:"col",quoted:!1});if(e instanceof cr){let A=e.args.expressions;r=A?.[0],i=A?.[1]}else if(e instanceof Ms){let A=e.args.alias;if(A instanceof Dt){let L=A.args.columns;L&&0<L.length&&(r=L[0],i=L[1]??i),A.pop()}}let E=this.sql(new os({expressions:[t],alias:i})),c=this.sql(new ys({this:new F({this:new R({this:"GENERATE_SUBSCRIPTS",expressions:[t,a.number(1)]}),expression:a.number(1)}),alias:r})),u=this.formatArgs([c,E]);return e instanceof Cs||e&&e.parent instanceof Cs?`(SELECT ${u})`:u}addMonthsSql(s){let t=s.args.this;t?.type||(t=t&&Nt(t,{dialect:this.dialect})),t?.isType(l.TEXT_TYPES)&&(t=new T({this:t,to:new l({this:"timestamp"})}));let e=s.args.expression,r=e?.type?e:e&&Nt(e,{dialect:this.dialect}),i;r?.isType(["float","double","decimal"])?i=new R({this:"TO_MONTHS",expressions:[new T({this:new R({this:"ROUND",expressions:e&&[e]}),to:new l({this:"int"})})]}):i=new Y({this:e,unit:new C({this:"MONTH"})});let E=new I({this:t,expression:i}),c=s.args.preserveEndOfMonth,u=E;return c&&(u=new $({}).when(new v({this:d("LAST_DAY",t),expression:t}),d("LAST_DAY",E)).else(E)),t?.isType(["date","timestamptz"])?this.sql(new T({this:u,to:t.type})):this.sql(u)}formatSql(s){return s.name.toLowerCase()==="%s"&&s.args.expressions?.length===1?this.func("FORMAT",[a.string("{}"),s.args.expressions[0]]):this.functionFallbackSql(s)}dateTruncSql(s){let t=s.args.unit,e=s.args.this,r=Qo(t),i=Mt(s),E;return r?E=this.sql(Ye(e,r,{preserveStartDay:!0})):E=this.func("DATE_TRUNC",[i,e]),s.args.inputTypePreserved&&e?.isType(l.TEMPORAL_TYPES)&&!(Os(i)&&e.isType("date"))?this.sql(new T({this:E,to:e.type})):E}timestampTruncSql(s){let t=Mt(s),e=s.args.zone,r=s.args.this,i=Os(t);if(i&&e){r=new Et({this:r,zone:e});let c=this.func("DATE_TRUNC",[t,r]);return this.sql(new Et({this:c,zone:e}))}let E=this.func("DATE_TRUNC",[t,r]);if(s.args.inputTypePreserved){if(r?.isType(["time","timetz"])){let c=new T({this:a.string("1970-01-01"),to:new l({this:"date"})}),u=new I({this:c,expression:r});return E=this.func("DATE_TRUNC",[t,u]),this.sql(new T({this:E,to:r.type}))}if(r?.isType(l.TEMPORAL_TYPES)&&!(i&&r.isType("date")))return this.sql(new T({this:E,to:r.type}))}return E}trimSql(s){let t=et(s.args.this);if(t&&s.setArgKey("this",t),s.args.expression instanceof N){let r=et(s.args.expression);r&&s.setArgKey("expression",r)}let e=super.trimSql(s);return ct.call(this,s,e)}hexStringSql(s){return super.hexStringSql(s,{binaryFunctionRepr:"UNHEX"})}roundSql(s){let t=s.args.this,e=s.args.decimals,r=s.args.truncate;e&&s.args.castsNonIntegerDecimals&&(e.isInteger||e.isType([...l.INTEGER_TYPES])||(e=new T({this:e,to:new l({this:"int"})})));let i="ROUND";if(r instanceof a){let E=r.args.this?.toUpperCase();E!==void 0&&["ROUND_HALF_EVEN","HALF_TO_EVEN"].includes(E)?(i="ROUND_EVEN",r=void 0):E!==void 0&&["ROUND_HALF_AWAY_FROM_ZERO","HALF_AWAY_FROM_ZERO"].includes(E)&&(r=void 0)}return this.func(i,[t,e,r])}strPositionSql(s){let t=s.args.position;return s.args.clampPosition&&t&&(s=s.copy(),s.setArgKey("position",new j({this:new qr({this:t,expression:a.number(0)}),true:a.number(1),false:t.copy()}))),ca.call(this,s)}strtokSql(s){let t=s.args.this,e=s.args.delimiter,r=s.args.partIndex;if(e&&r){let i=new R({this:"REGEXP_REPLACE",expressions:[e,a.string(String.raw`([\[\]^.\-*+?(){}|$\\])`),a.string(String.raw`\\\1`),a.string("g")]}),E=st().when(e.eq(a.string("")),a.string("")).else(d("CONCAT",a.string("["),i,a.string("]"))),c=d("REGEXP_SPLIT_TO_ARRAY",t,E),u=H("x"),A=u.eq(a.string("")),L=d("LIST_FILTER",c,new rt({this:new Ft({this:A.copy()}),expressions:[u.copy()]})),O=new q({this:L,expressions:[r],offset:1}),G=b(this._constructor.STRTOK_TEMPLATE.copy(),[],{string:t,delimiter:e,partIndex:r,baseFunc:O});return this.sql(G)}return this.functionFallbackSql(s)}approxQuantileSql(s){let t=this.func("APPROX_QUANTILE",[s.args.this,s.args.quantile]);return s.isType(l.REAL_TYPES)&&(t=`CAST(${t} AS DOUBLE)`),t}approxQuantilesSql(s){let t=s.args.this,e;if(t instanceof qs){if(!t.args.expressions||t.args.expressions.length<2)return this.unsupported("APPROX_QUANTILES requires a bucket count argument"),this.functionFallbackSql(s);e=t.args.expressions[1].pop()}else e=s.args.expression;if(!(e instanceof a&&e.isInteger))return this.unsupported("APPROX_QUANTILES bucket count must be a positive integer"),this.functionFallbackSql(s);let r=parseInt(e.args.this??"0");if(r<=0)return this.unsupported("APPROX_QUANTILES bucket count must be a positive integer"),this.functionFallbackSql(s);let i=Array.from({length:r+1},(E,c)=>a.number(c/r));return this.sql(new ye({this:t,quantile:new W({expressions:i})}))}jsonExtractScalarSql(s){return s.args.scalarOnly&&(s=new Te({this:new R({this:"JSON_VALUE",expressions:[s.args.this,s.args.expression].filter(t=>t instanceof N)}),expression:a.string("$")})),Ha.call(this,s)}bitwiseNotSql(s){let t=s.args.this;J(t)&&(s.type=new l({this:"binary"}));let e=Xe(t);t instanceof br&&(e=new w({this:e})),s.setArgKey("this",e);let r=`~${this.sql(s,"this")}`;return ct.call(this,s,r)}windowSql(s){let t=s.args.this;return t instanceof At||t instanceof Jt&&t.args.this instanceof At?this.corrSql(s):super.windowSql(s)}filterSql(s){return s.args.this instanceof At?this.corrSql(s):super.filterSql(s)}corrSql(s){if(s instanceof At&&!s.args.nullOnZeroVariance)return this.func("CORR",[s.args.this,s.args.expression]);let t=CE(s);return t?this.sql(new $({}).when(new ue({this:t}),f()).else(t)):s instanceof Zt?super.windowSql(s):s instanceof Jt?super.filterSql(s):this.sql(s)}};_=yt(vo),S(_,10,"STRTOK_TEMPLATE",Yo,h),S(_,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",Bo,h),S(_,10,"STRUCT_DELIMITER",Ho,h),S(_,10,"ORIGINAL_TRANSFORMS",Uo,h),S(_,10,"SUPPORTED_JSON_PATH_PARTS",Fo,h),S(_,10,"TYPE_MAPPING",Go,h),S(_,10,"RESERVED_KEYWORDS",Do,h),S(_,10,"UNWRAPPED_INTERVAL_VALUES",bo,h),S(_,10,"PROPERTIES_LOCATION",qo,h),S(_,10,"IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS",yo,h),S(_,10,"ZIPF_TEMPLATE",Mo,h),S(_,10,"NORMAL_TEMPLATE",Co,h),S(_,10,"SEEDED_RANDOM_TEMPLATE",Po,h),S(_,10,"SEQ_UNSIGNED",Oo,h),S(_,10,"SEQ_SIGNED",Lo,h),S(_,10,"MAPCAT_TEMPLATE",_o,h),S(_,10,"EXTRACT_STRFTIME_MAPPINGS",wo,h),S(_,10,"EXTRACT_EPOCH_MAPPINGS",Io,h),S(_,10,"BITMAP_CONSTRUCT_AGG_TEMPLATE",No,h),S(_,10,"RANDSTR_TEMPLATE",mo,h),S(_,10,"MINHASH_TEMPLATE",Ro,h),S(_,10,"MINHASH_COMBINE_TEMPLATE",xo,h),S(_,10,"APPROXIMATE_SIMILARITY_TEMPLATE",Ao,h),S(_,10,"ARRAYS_ZIP_TEMPLATE",fo,h),qt(_,h),bt(_,3,h),p(h,"DuckDBGenerator"),h.SUPPORTS_DECODE_CASE=!1,h.SELECT_KINDS=[],h.PARAMETER_TOKEN="$",h.NAMED_PLACEHOLDER_TOKEN="$",h.JOIN_HINTS=!1,h.TABLE_HINTS=!1,h.QUERY_HINTS=!1,h.LIMIT_FETCH="LIMIT",h.RENAME_TABLE_WITH_DB=!1,h.NVL2_SUPPORTED=!1,h.SEMI_ANTI_JOIN_WITH_SIDE=!1,h.TABLESAMPLE_KEYWORDS="USING SAMPLE",h.TABLESAMPLE_SEED_KEYWORD="REPEATABLE",h.LAST_DAY_SUPPORTS_DATE_PART=!1,h.JSON_KEY_VALUE_PAIR_SEP=",",h.IGNORE_NULLS_IN_FUNC=!0,h.IGNORE_NULLS_BEFORE_ORDER=!1,h.JSON_PATH_BRACKETED_KEY_SUPPORTED=!1,h.SUPPORTS_CREATE_TABLE_LIKE=!1,h.MULTI_ARG_DISTINCT=!1,h.CAN_IMPLEMENT_ARRAY_ANY=!0,h.SUPPORTS_TO_NUMBER=!1,h.SUPPORTS_WINDOW_EXCLUDE=!0,h.COPY_HAS_INTO_KEYWORD=!1,h.STAR_EXCEPT="EXCLUDE",h.PAD_FILL_PATTERN_IS_REQUIRED=!0,h.ARRAY_SIZE_DIM_REQUIRED=!1,h.NORMALIZE_EXTRACT_DATE_PARTS=!0,h.SUPPORTS_LIKE_QUANTIFIERS=!1,h.SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD=!0,h.ARRAY_BAG_TEMPLATE=M(`CASE
94
+ `)}timeSliceSql(s){let t=s.args.this,e=s.args.expression,r=s.args.unit,i=s.text("kind").toUpperCase(),E=new Y({this:e,unit:r}),c=this.func("time_bucket",[E,t]);if(i!=="END")return this.sql(c);let u=new I({this:c,expression:E.copy()});return t?.isType("date")?this.sql(new T({this:u,to:new l({this:"date"})})):this.sql(u)}bitmapBucketNumberSql(s){let t=s.args.this,e=new I({this:new L({this:new Qt({this:new L({this:new F({this:t,expression:a.number(1)})}),expression:a.number(32768)})}),expression:a.number(1)}),r=new Qt({this:t,expression:a.number(32768)});return this.sql(new $({}).when(new Ys({this:t,expression:a.number(0)}),e).else(r))}bitmapBitPositionSql(s){let t=s.args.this;return this.sql(new St({this:new L({this:new Q({this:new Ys({this:t,expression:a.number(0)}),true:new F({this:t,expression:a.number(1)}),false:new Ut({this:t})})}),expression:iE}))}bitmapConstructAggSql(s){let t=s.args.this;return`(${this.sql(b(this._constructor.BITMAP_CONSTRUCT_AGG_TEMPLATE.copy(),[],{arg:t}))})`}nthValueSql(s){return(s.args.fromFirst??!0)||this.unsupported("DuckDB's NTH_VALUE doesn't support starting from the end"),this.functionFallbackSql(s)}randstrSql(s){let t=s.args.this,e=s.args.generator,r;return e?e instanceof tt?r=e.args.this??e:r=e:r=a.number(nE),`(${this.sql(b(this._constructor.RANDSTR_TEMPLATE.copy(),[],{seed:r,length:t}))})`}zipfSql(s){let t=s.args.this,e=s.args.elementcount,r=s.args.gen,i;return r instanceof tt?i=new tt({}):i=new lt({this:new L({this:new St({this:new Ut({this:new d({this:"HASH",expressions:[(r??f()).copy()]})}),expression:a.number(1e6)})}),expression:a.number("1000000.0")}),`(${this.sql(b(this._constructor.ZIPF_TEMPLATE.copy(),[],{s:t,n:e,randomExpr:i}))})`}toBinarySql(s){let t=s.args.this,e=K(s.args.format,N),r=s.args.safe,i=Z(s);if(!e&&!i){let u=r?"TRY_TO_BINARY":"TO_BINARY";return this.func(u,[t])}let E=e?.name?.toUpperCase()??"HEX",c;if(E==="UTF-8"||E==="UTF8")c=this.func("ENCODE",[t]);else if(E==="BASE64")c=this.func("FROM_BASE64",[t]);else if(E==="HEX")c=this.func("UNHEX",[t]);else{if(r)return this.sql(f());this.unsupported(`format ${E} is not supported`),c=this.func("TO_BINARY",[t])}return r?`TRY(${c})`:c}greatestLeastSql(s){let t=[s.args.this,...s.args.expressions??[]],e=this.functionFallbackSql(s);if(s.args.ignoreNulls)return this.sql(e);let r=new $({}).when(Kt(t.map(i=>(i??f()).is(f())),{copy:!1}),f());return r.setArgKey("default",e),this.sql(r)}generatorSql(s){let t=s.args.rowcount;return s.args.timelimit&&this.unsupported("GENERATOR TIMELIMIT parameter is not supported in DuckDB"),t?this.func("range",[t]):(this.unsupported("GENERATOR without ROWCOUNT is not supported in DuckDB"),this.func("range",[a.number(0)]))}greatestSql(s){return this.greatestLeastSql(s)}leastSql(s){return this.greatestLeastSql(s)}lambdaSql(s,t={}){let e=t.arrowSep??"->",r=t.wrap??!0,i="";s.args.colon&&(i="LAMBDA ",e=":",r=!1);let E=super.lambdaSql(s,{arrowSep:e,wrap:r});return`${i}${E}`}sortArraySql(s){let t=s.args.this,e=s.args.asc,r=s.args.nullsFirst;if(!(e instanceof j)&&!(r instanceof j))return this.func("LIST_SORT",[t,e,r]);let i=r instanceof j&&r.args.this===!0,E=i?a.string("NULLS FIRST"):void 0;if(!(e instanceof j))return this.func("LIST_SORT",[t,e,E]);let c=e.args.this===!1;return!c&&!i?this.func("LIST_SORT",[t]):i?this.func("LIST_SORT",[t,a.string(c?"DESC":"ASC"),a.string("NULLS FIRST")]):this.func("ARRAY_REVERSE_SORT",[t])}showSql(s){let t=this.sql(s,"from"),e=t?` FROM ${t}`:"";return`SHOW ${s.name}${e}`}installSql(s){let t=s.args.force?"FORCE ":"",e=this.sql(s,"this"),r=s.args.from?` FROM ${s.args.from}`:"";return`${t}INSTALL ${e}${r}`}approxTopKSql(s){return this.unsupported("APPROX_TOP_K cannot be transpiled to DuckDB due to incompatible return types. "),this.functionFallbackSql(s)}fromIso8601TimestampSql(s){return this.sql(new T({this:s.args.this,to:new l({this:"timestamptz"})}))}strToTimeSql(s){let t=s.args.targetType,e=t&&["timestampltz","timestamptz"].includes(t.args.this);if(s.args.safe){let i=this.formatTime(s),E=e?"timestamptz":"timestamp";return this.sql(new T({this:this.func("TRY_STRPTIME",[s.args.this,i]),to:new l({this:E})}))}let r=Ra.call(this,s);return e?this.sql(new T({this:r,to:new l({this:"timestamptz"})})):r}strToDateSql(s){let t=this.formatTime(s),e=s.args.safe?"TRY_STRPTIME":"STRPTIME";return this.sql(new T({this:this.func(e,[s.args.this,t]),to:new l({this:"date"})}))}tsOrDsToTimeSql(s){let t=s.args.this,e=this.formatTime(s),r=s.args.safe,i=l.build("time",{dialect:"duckdb"}),E=r?Yi:T;if(e){let c=r?"TRY_STRPTIME":"STRPTIME",u=new d({this:c,expressions:[t??f(),e]});return this.sql(new E({this:u,to:i}))}return t instanceof mi||t?.isType("time")?this.sql(t??f()):this.sql(new E({this:t,to:i}))}validateRegexpFlags(s,t){if(!(s instanceof N))return;if(!s.isString){this.unsupported("Non-literal regexp flags are not fully supported in DuckDB");return}let e=s.name??"",r=new Set(t),i=[...new Set(e)].filter(c=>!r.has(c));return 0<i.length&&this.unsupported(`Regexp flags ${JSON.stringify(i.sort())} are not supported in this context`),[...e].filter(c=>r.has(c)).join("")||void 0}regexplikeSql(s){let t=s.args.this,e=s.args.expression,r=s.args.flag;if(s.args.fullMatch){let i=this.validateRegexpFlags(r,"cims");return r=i?a.string(i):void 0,this.func("REGEXP_FULL_MATCH",[t,e,r])}return this.func("REGEXP_MATCHES",[t,e,r])}arrayoverlapsSql(s){if(!s.args.nullsafe)return this.binary(s,"&&");let t=s.args.this,e=s.args.expression,r=this.sql(Vt([new Ft({this:new Bt({this:t.copy()}),expression:x("LIST_COUNT",t.copy())}),new Ft({this:new Bt({this:e.copy()}),expression:x("LIST_COUNT",e.copy())})]));return`(${this.binary(s,"&&")}) OR (${r})`}arraycontainsSql(s){let t=s.args.this,e=s.args.expression,r=this.func("ARRAY_CONTAINS",[t,e]);if(s.args.checkNull){let i=new he({this:new Ft({this:new Bt({this:t}),expression:new d({this:"LIST_COUNT",expressions:[t]})}),expression:new j({this:!1})});return this.sql(new Q({this:new at({this:e,expression:new it({})}),true:i,false:y(r)}))}return r}arrayUniqueAggSql(s){let t=s.args.this;return this.sql(new Gt({this:x("LIST",new bs({expressions:[t]})),expression:new Ms({this:new Ot({this:new at({this:t.copy(),expression:new it})})})}))}arraydistinctSql(s){let t=s.args.this,e=this.func("LIST_DISTINCT",[t]);if(s.args.checkNull){let r=new d({this:"LIST_APPEND",expressions:[new d({this:"LIST_DISTINCT",expressions:[new ss({this:t})]}),new it({})]});return this.sql(new Q({this:new Ft({this:new Bt({this:t}),expression:new d({this:"LIST_COUNT",expressions:[t]})}),true:r,false:y(e)}))}return e}regexpinstrSql(s){let t=s.args.this,e=s.args.expression,r=s.args.position,i=s.args.occurrence,E=i??a.number(1),c=s.args.option,u=s.args.parameters,A=this.validateRegexpFlags(u?.[0],"ims");A&&(e=new vt({expressions:[a.string(`(?${A})`),e]}));let _=a.number(0);r&&(!r.isNumber||1<Number(r.toValue()))&&(t=new Pt({this:t,start:r}),_=new F({this:r,expression:a.number(1)}));let O=p((pt,Jt)=>{let tE=new q({this:new d({this:pt,expressions:[t,e]}),expressions:[new B({this:a.number(1),expression:Jt})],offset:1}),sE=new d({this:"LIST_TRANSFORM",expressions:[tE,new rt({this:new z({this:H("x")}),expressions:[H("x")]})]});return new Yt({this:new d({this:"LIST_SUM",expressions:[sE]}),expressions:[a.number(0)]})},"sumLengths"),G=new I({this:new I({this:new I({this:a.number(1),expression:O("STRING_SPLIT_REGEX",E)}),expression:O("REGEXP_EXTRACT_ALL",new F({this:E,expression:a.number(1)}))}),expression:_});if(c&&c.isNumber&&Number(c.toValue())===1){let pt=new q({this:new d({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]}),expressions:[E],offset:1});G=new I({this:G,expression:new Yt({this:new z({this:pt}),expressions:[a.number(0)]})})}let Ls=[s.args.this,s.args.expression,r,i,c,u].filter(Boolean).map(pt=>new at({this:pt.copy(),expression:new it({})})),Tt=new d({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]}),zo=J().when(Ls.reduce((pt,Jt)=>pt?new Xt({this:pt,expression:Jt}):Jt),new it({})).when(new v({this:e.copy(),expression:a.string("")}),a.number(0)).when(new ks({this:new z({this:Tt}),expression:E}),a.number(0)).else(G);return this.sql(zo)}regexpreplaceSql(s){let t=s.args.this,e=s.args.expression,r=s.args.replacement??a.string(""),i=s.args.position,E=s.args.occurrence,c=s.args.modifiers,u=c,A="";if(c&&c.isString&&(A=this.validateRegexpFlags(c,"cimsg")??"",u=void 0),E&&!E.isNumber)this.unsupported("REGEXP_REPLACE with non-literal occurrence");else{let V=E&&E.isNumber?Number(E.toValue()):0;1<V?this.unsupported(`REGEXP_REPLACE occurrence=${V} not supported`):V===0&&!A.includes("g")&&!s.args.singleReplace&&(A+="g")}let _;if(i&&!i.isNumber)this.unsupported("REGEXP_REPLACE with non-literal position");else if(i&&i.isNumber&&1<Number(i.toValue())){let V=Number(i.toValue());_=new Pt({this:t,start:a.number(1),length:a.number(V-1)}),t=new Pt({this:t,start:a.number(V)})}let O=A?a.string(A):u,G=new d({this:"REGEXP_REPLACE",expressions:[t,e,r,...O?[O]:[]].filter(Boolean)});return _&&(G=new vt({expressions:[_,G]})),this.sql(G)}regexpcountSql(s){let t=s.args.this,e=s.args.expression,r=s.args.position,i=s.args.parameters,E=this.validateRegexpFlags(i?.[0],"ims");r&&(t=new Pt({this:t,start:r})),E&&(e=new vt({expressions:[a.string(`(?${E})`),e]}));let c=new $({ifs:[new Q({this:new v({this:e,expression:a.string("")}),true:a.number(0)})],default:new z({this:new d({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]})})});return this.sql(c)}arrayBagSql(s,t,e){let r=new L({this:b(s.copy(),[],{arr1:t,arr2:e})});return this.sql(b(this._constructor.ARRAY_BAG_TEMPLATE.copy(),[],{arr1:t,arr2:e,cond:r}))}arrayintersectSql(s){return s.args.isMultiset&&s.args.expressions?.length===2?this.arrayBagSql(this._constructor.ARRAY_INTERSECTION_CONDITION,s.args.expressions[0],s.args.expressions[1]):this.functionFallbackSql(s)}arrayexceptSql(s){let t=s.args.this,e=s.args.expression;return s.args.isMultiset?this.arrayBagSql(this._constructor.ARRAY_EXCEPT_CONDITION,t,e):this.sql(b(this._constructor.ARRAY_EXCEPT_SET_TEMPLATE.copy(),[],{arr1:t,arr2:e}))}currentDateSql(s){if(!s.args.this)return"CURRENT_DATE";let t=new T({this:new ct({this:new re({}),zone:s.args.this}),to:new l({this:"date"})});return this.sql(t)}checkJsonSql(s){let t=s.args.this;return this.sql(J().when(Kt([new at({this:t,expression:new it}),t.eq(a.string("")),x("json_valid",t)]),f()).else(a.string("Invalid JSON")))}parseJsonSql(s){let t=s.args.this;return s.args.safe?this.sql(new $({}).when(this.func("json_valid",[t??f()]),t instanceof N||typeof t=="string"?t:"").else(f())):this.func("JSON",[t])}truncSql(s){return ds.call(this,s,"decimals"),this.func("TRUNC",[s.args.this])}normalSql(s){let t=s.args.this,e=s.args.stddev,r=s.args.gen,i,E;if(r instanceof tt&&!r.args.this)i=new tt({}),E=new tt({});else{let c=(r instanceof tt?r.args.this:r)??f();i=b(this._constructor.SEEDED_RANDOM_TEMPLATE.copy(),[],{seed:c}),E=b(this._constructor.SEEDED_RANDOM_TEMPLATE.copy(),[],{seed:new I({this:c.copy(),expression:a.number(1)})})}return this.sql(b(this._constructor.NORMAL_TEMPLATE.copy(),[],{mean:t,stddev:e,u1:i,u2:E}))}uniformSql(s){let t=s.args.this,e=s.args.expression,r=s.args.gen,i=t instanceof a&&t.isInteger&&e instanceof a&&e.isInteger,E;r instanceof tt?E=new tt({}):E=new lt({this:new L({this:new St({this:new Ut({this:new d({this:"HASH",expressions:[r||""]})}),expression:a.number(1e6)})}),expression:a.number("1000000.0")});let c=new F({this:e,expression:t});i&&(c=new I({this:c,expression:a.number(1)}));let u=new I({this:t,expression:new gt({this:E,expression:new L({this:c})})});return i&&(u=new T({this:new pe({this:u}),to:new l({this:"bigint"})})),this.sql(u)}timeFromPartsSql(s){let t=s.args.nano;if(s.args.overflow){let r=K(s.args.hour,"string",a),i=K(s.args.min,"string",a),E=K(s.args.sec,"string",a);if(!t&&[r,i,E].every(u=>u instanceof a&&u.isNumber)){let u=parseInt((r instanceof a?r.args.this:r)??"0"),A=parseInt((i instanceof a?i.args.this:i)??"0"),_=parseInt((E instanceof N?E.args.this:E)??"0");if(0<=u&&u<=23&&0<=A&&A<=59&&0<=_&&_<=59)return R("MAKE_TIME").call(this,s)}t&&(E=E.add(t.pop().div(a.number("1000000000.0"))));let c=r.mul(a.number(3600)).add(i.mul(a.number(60))).add(E);return this.sql(new I({this:new T({this:a.string("00:00:00"),to:l.build("time")}),expression:new Y({this:c,unit:new C({this:"SECOND"})})}))}return t&&s.setArgKey("sec",new I({this:s.args.sec,expression:new lt({this:t.pop(),expression:a.number(1e9)})})),R("MAKE_TIME").call(this,s)}extractSql(s){let t=s.args.expression;t?.isType(["timestamptz","timestampltz"])&&this.unsupported("EXTRACT from TIMESTAMPTZ / TIMESTAMPLTZ may produce different results due to timezone handling differences");let e=K(s.args.this,N)?.name.toUpperCase();if(e!==void 0&&e in h.EXTRACT_STRFTIME_MAPPINGS){let[r,i]=h.EXTRACT_STRFTIME_MAPPINGS[e],E=e==="NANOSECOND"&&t?.isType(["time","timetz"]),c=t??f();if(E)return this.unsupported("Parameter NANOSECOND is not supported with TIME type in DuckDB"),this.sql(new T({this:new gt({this:new as({this:new C({this:"MICROSECOND"}),expression:c}),expression:a.number(1e3)}),to:l.build(i,{dialect:"duckdb"})}));let u=c;return e==="NANOSECOND"&&(u=new T({this:c,to:new l({this:"timestampNs"})})),this.sql(new T({this:new d({this:"STRFTIME",expressions:[u,a.string(r)]}),to:l.build(i,{dialect:"duckdb"})}))}if(e!==void 0&&e in h.EXTRACT_EPOCH_MAPPINGS){let r=h.EXTRACT_EPOCH_MAPPINGS[e],i=new d({this:r,expressions:[t??f()]});return e==="EPOCH_SECOND"&&(i=new T({this:i,to:l.build("bigint",{dialect:"duckdb"})})),this.sql(i)}return super.extractSql(s)}timestampFromPartsSql(s){let t=s.args.this,e=s.args.expression;if(t&&e)return this.sql(new I({this:t,expression:e}));let r=s.args.sec;if(!r)return R("MAKE_TIMESTAMP").call(this,s);let i=s.args.milli;i&&(r=new I({this:r,expression:new L({this:new lt({this:i.pop(),expression:a.number("1000.0")})})}));let E=s.args.nano;return E&&(r=new I({this:r,expression:new L({this:new lt({this:E.pop(),expression:a.number("1000000000.0")})})})),(i||E)&&s.setArgKey("sec",r),R("MAKE_TIMESTAMP").call(this,s)}timestampLtzFromPartsSql(s){let t=s.args.nano;return t&&t.pop(),`CAST(${R("MAKE_TIMESTAMP").call(this,s)} AS TIMESTAMPTZ)`}timestampTzFromPartsSql(s){let t=s.args.zone;t&&(t=t.pop());let e=s.args.nano;e&&e.pop();let r=R("MAKE_TIMESTAMP").call(this,s);return t?`${r} AT TIME ZONE ${this.sql(t)}`:r}tableSampleSql(s,t={}){let e=t.tablesampleKeyword;if(s.parent instanceof nt||(e="TABLESAMPLE"),s.args.size){let r=s.args.method;r instanceof N&&r.name?.toUpperCase()!=="RESERVOIR"&&(this.unsupported(`Sampling method ${r} is not supported with a discrete sample count, defaulting to reservoir sampling`),s.setArgKey("method",new C({this:"RESERVOIR"})))}return super.tableSampleSql(s,{tablesampleKeyword:e})}columnDefSql(s,t={}){return s.parent instanceof sr?this.sql(s,"this"):super.columnDefSql(s,t)}joinSql(s){let t=["","inner","outer"].includes(s.args.kind??"");if(!s.args.using&&!s.args.on&&!s.args.method&&t){if(s.args.this instanceof Es)return super.joinSql(s.on(new j({this:!0})));s.setArgKey("side",void 0),s.setArgKey("kind",void 0)}return super.joinSql(s)}generateSeriesSql(s){return la("GENERATE_SERIES",{exclusiveFuncName:"RANGE"}).call(this,s)}countIfSql(s){return 1<this.dialect.version.major||this.dialect.version.major===1&&2<=this.dialect.version.minor?this.functionFallbackSql(s):xa.call(this,s)}bracketSql(s){if(1<this.dialect.version.major||this.dialect.version.major===1&&2<=this.dialect.version.minor)return super.bracketSql(s);let t=s.args.this;t instanceof W&&t.replace(new L({this:t.copy()}));let e=super.bracketSql(s);if(!s.args.returnsListForMaps){let r=K(t,N),i=r?.type?r:r&&Nt(r,{dialect:this.dialect});k(i,"map")&&(e=`(${e})[1]`)}return e}withinGroupSql(s){let t=s.args.this;if(t instanceof bi){let i=s.args.expression;if(!(i instanceof wt))return this.sql(t);let E=t.args.this;t.setArgKey("this",new wt({this:K(t.args.this,N)?.copy(),expressions:i.args.expressions}));let c=this.functionFallbackSql(t);return E instanceof N?this.addArrayAggNullFilter(c,t,E):""}let e=this.sql(s,"expression");if(t instanceof As||t instanceof xs){let i=s.find(nr);i&&(t.setArgKey("expression",t.args.this),t.setArgKey("this",i.args.this))}return`${this.sql(s,"this").replace(/\)$/,"")}${e})`}lengthSql(s){let t=s.args.this;if(!s.args.binary||t instanceof a&&t.isString)return this.func("LENGTH",[t]);if((t?.type?t:t&&Nt(t,{dialect:this.dialect}))?.isType(l.TEXT_TYPES))return this.func("LENGTH",[t]);let r=new T({this:t,to:new l({this:"varbinary"})}),i=new T({this:t,to:new l({this:"varchar"})}),E=new $({this:new d({this:"TYPEOF",expressions:t?[t]:[]})}).when(a.string("BLOB"),new ts({this:r})).else(new d({this:"LENGTH",expressions:[i]}));return this.sql(E)}levenshteinSql(s){ds.call(this,s,"insCost","delCost","subCost");let t=s.args.this,e=s.args.expression,r=s.args.maxDist;if(!r)return this.func("LEVENSHTEIN",[t,e]);let i=new fe({this:t,expression:e});return this.sql(new Qn({this:i,expressions:[r],ignoreNulls:!1}))}padSql(s){let t=s.args.this,e=s.args.fillPattern??a.string(" ");if(Z(t)||Z(e)){let r=s.args.expression,i=s.args.isLeft,E=new ts({this:t}),c=new F({this:r,expression:E}),u=new ue({this:a.number(0),expressions:[c],ignoreNulls:!0}),A=new me({this:e,times:[u]}),[_,O]=i?[A,t]:[t,A];return this.sql(new Cr({this:_,expression:O}))}return super.padSql(s)}minhashSql(s){let t=s.args.this,e=s.args.expressions??[];if(e.length!==1||e[0]instanceof Er)return this.unsupported("MINHASH with multiple expressions or * requires manual restructuring"),this.func("MINHASH",[t,...e]);let r=b(h.MINHASH_TEMPLATE.copy(),[],{expr:e[0],k:t});return`(${this.sql(r)})`}minhashCombineSql(s){let t=b(h.MINHASH_COMBINE_TEMPLATE.copy(),[],{expr:s.args.this});return`(${this.sql(t)})`}approximateSimilaritySql(s){let t=b(h.APPROXIMATE_SIMILARITY_TEMPLATE.copy(),[],{expr:s.args.this});return`(${this.sql(t)})`}arraySliceSql(s){let t=s.args.start,e=s.args.end;return s.args.zeroBased&&(t&&(t=J().when(new Mr({this:t.copy(),expression:a.number(0)}),new I({this:t.copy(),expression:a.number(1)}),{copy:!1}),t.setArgKey("default",s.args.start)),e&&(e=J().when(new ks({this:e.copy(),expression:a.number(0)}),new F({this:e.copy(),expression:a.number(1)}),{copy:!1}),e.setArgKey("default",s.args.end))),this.func("ARRAY_SLICE",[s.args.this,t,e,s.args.step])}arraysZipSql(s){let t=s.args.expressions??[];if(t.length===0)return this.sql(new W({expressions:[new Ae({keys:new W,values:new W})]}));let e=t.map(O=>new z({this:O})),r=e.length===1?e[0]:new ue({this:e[0],expressions:e.slice(1),ignoreNulls:!1}),i=new ft({expressions:t.map((O,G)=>new Lt({this:a.string(`$${G+1}`),expression:f()}))}),E=new I({this:new Ds({this:new It({this:"__i"})}),expression:a.number(1)}),c=new ft({expressions:t.map((O,G)=>new Lt({this:a.string(`$${G+1}`),expression:new q({this:new d({this:"COALESCE",expressions:[O,new W({})]}),expressions:[E.copy()]})}))}),u=Kt(t.map(O=>O.is(f()))),A=Vt(t.map(O=>new v({this:new z({this:O}),expression:a.number(0)}))),_=b(h.ARRAYS_ZIP_TEMPLATE.copy(),[],{nullCheck:u,allEmptyCheck:A,emptyStruct:i,maxLen:r,transformStruct:c});return this.sql(_)}lowerSql(s){let t=this.func("LOWER",[et(s.args.this)]);return ut.call(this,s,t)}upperSql(s){let t=this.func("UPPER",[et(s.args.this)]);return ut.call(this,s,t)}reverseSql(s){let t=this.func("REVERSE",[et(s.args.this)]);return ut.call(this,s,t)}randSql(s){s.args.this&&this.unsupported("RANDOM with seed is not supported in DuckDB");let e=s.args.lower,r=s.args.upper;if(e&&r){let i=new L({this:new F({this:r,expression:e})}),E=new I({this:e,expression:new gt({this:x("random"),expression:i})});return this.sql(ot(E,"bigint"))}return"RANDOM()"}rightSql(s){let t=s.args.this,e=s.args.expression;if(Z(t)){let r=new kn({this:t}),i=new gt({this:e,expression:a.number(2)});return`UNHEX(${this.func("RIGHT",[r,i])})`}return this.func("RIGHT",[t,e])}base64EncodeSql(s){let t=s.args.this;t?.isType(l.TEXT_TYPES)&&(t=new d({this:"ENCODE",expressions:[t]})),t=new Hn({this:t});let e=s.args.maxLineLength,r=s.args.alphabet;t=Jo(t,r);let i=e instanceof a&&e.isNumber?parseInt(e.args.this??"0"):0;if(0<i){let E=new Qr({expressions:[a.number(10)]});t=new xi({this:new ls({this:t,expression:a.string(`(.{${i}})`),replacement:new vt({expressions:[a.string("\\1"),E.copy()]})}),expression:E,position:"trailing"})}return this.sql(t)}replaceSql(s){let t=this.func("REPLACE",[et(s.args.this),et(s.args.expression),et(s.args.replacement)]);return ut.call(this,s,t)}bitwiseOp(s,t){ka(s);let e=this.binary(s,t);return ut.call(this,s,e)}bitwiseXorSql(s){ka(s);let t=this.func("XOR",[s.args.this,s.args.expression]);return ut.call(this,s,t)}objectInsertSql(s){let t=s.args.this,e=s.args.key,r=e instanceof N?e.name:"",i=this.sql(s,"value"),E=`${r} := ${i}`;return t instanceof ft&&(!t.args.expressions||t.args.expressions.length===0)?this.func("STRUCT_PACK",[E]):this.func("STRUCT_INSERT",[t,E])}mapCatSql(s){let t=b(h.MAPCAT_TEMPLATE.copy(),[],{map1:s.args.this,map2:s.args.expression});return this.sql(t)}mapDeleteSql(s){let t=s.args.this,e=s.args.expressions??[],r=new Bs({this:H("x"),expression:H("key")}),i=new Ot({this:new zt({this:r,expressions:e})}),E=new rt({this:i,expressions:[H("x")]}),c=new rs({this:x("map_entries",t),expression:E}),u=x("map_from_entries",c);return this.sql(u)}mapSizeSql(s){return this.func("CARDINALITY",[s.args.this])}mapPickSql(s){let t=s.args.this,e=s.args.expressions??[],r=new Bs({this:H("x"),expression:H("key")}),i;e.length===1&&e[0].isType?.("array")?i=new rt({this:x("ARRAY_CONTAINS",e[0],r),expressions:[H("x")]}):i=new rt({this:new zt({this:r,expressions:e}),expressions:[H("x")]});let E=x("MAP_FROM_ENTRIES",x("LIST_FILTER",x("MAP_ENTRIES",t),i));return this.sql(E)}mapInsertSql(s){s.args.updateFlag&&this.unsupported("MAP_INSERT update_flag is not supported in DuckDB");let t=s.args.this,e=s.args.key,r=s.args.value;if(r!==void 0&&t){let u=t.type;if(u instanceof l&&u.args.expressions&&1<u.args.expressions.length){let A=u.args.expressions[1];r=ot(r,A)}}let i=new ft({expressions:[new Lt({this:e,expression:r})]}),E=new xe({this:i}),c=x("MAP_CONCAT",t,E);return this.sql(c)}startsWithSql(s){return this.func("STARTS_WITH",[et(s.args.this),et(s.args.expression)])}spaceSql(s){return this.sql(new me({this:a.string(" "),times:[new T({this:s.args.this,to:new l({this:"bigint"})})]}))}tableFromRowsSql(s){if(s.args.this instanceof $s){let t=new ys({this:s.args.this,alias:s.args.alias,joins:s.args.joins});return this.sql(t)}return super.tableFromRowsSql(s)}unnestSql(s){if(s.args.explodeArray){s.args.expressions||s.setArgKey("expressions",[]),s.args.expressions?.push(new vs({this:new C({this:"max_depth"}),expression:a.number(2)}));let e=s.args.alias;e instanceof Dt&&(s.setArgKey("alias",void 0),e.args.columns&&0<e.args.columns.length&&(e=new Dt({this:m(e.args.columns,0)})));let r=super.unnestSql(s),i=e?` AS ${this.sql(e)}`:"";return`(SELECT ${r})${i}`}return super.unnestSql(s)}ignoreNullsSql(s){let t=s.args.this;if(this._constructor.IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS.some(r=>t instanceof r))return super.ignoreNullsSql(s);let e=t;return e instanceof Fi&&(e=new kt({this:e.args.this})),e instanceof kt||e instanceof Mi||this.unsupported("IGNORE NULLS is not supported for non-window functions."),this.sql(e)}splitSql(s){let t=x("STR_SPLIT",s.args.this,s.args.expression),e=J();e.setArgKey("default",t);let r=!1;return s.args.nullReturnsNull&&(e=e.when(new at({this:s.args.expression,expression:new it({})}),new it({}),{copy:!1}),r=!0),s.args.emptyDelimiterReturnsWhole&&(e=e.when(new v({this:s.args.expression.copy(),expression:a.string("")}),ea([s.args.this]),{copy:!1}),r=!0),this.sql(r?e:t)}splitPartSql(s){let t=s.args.this,e=s.args.delimiter,r=s.args.partIndex;if(e&&r){s.args.partIndexZeroAsOne&&(r=new L({this:J().when(new v({this:r.copy(),expression:a.number(0)}),a.number(1),{copy:!1})}),r.args.this.setArgKey("default",s.args.partIndex));let i=new d({this:"SPLIT_PART",expressions:[t,e,r].filter(Boolean)}),E=!1,c=J();if(c.setArgKey("default",i),s.args.emptyDelimiterReturnsWhole){let u=new L({this:J().when(new Xt({this:new v({this:r.copy(),expression:a.number(1)}),expression:new v({this:r.copy(),expression:a.number(-1)})}),t,{copy:!1})});u.args.this.setArgKey("default",a.string("")),c=c.when(new v({this:e.copy(),expression:a.string("")}),u,{copy:!1}),E=!0}return this.sql(E?c:i)}return this.functionFallbackSql(s)}respectNullsSql(s){return this._constructor.IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS.some(t=>s.args.this instanceof t)?super.respectNullsSql(s):(this.unsupported("RESPECT NULLS is not supported for non-window functions."),this.sql(s,"this"))}arrayToStringSql(s){let t=s.args.null;if(s.args.nullIsEmpty){let e=H("x"),r=new Ht({this:s.args.this.copy(),expression:new rt({this:new Yt({this:ot(e,"TEXT"),expressions:[a.string("")]}),expressions:[e]})}),i=new te({this:r,expression:s.args.expression});return s.args.nullDelimIsNull?this.sql(J().when(s.args.expression.copy().is(f()),f()).else(i)):this.sql(i)}if(t){let e=H("x");return this.sql(new te({this:new Ht({this:s.args.this,expression:new rt({this:new Yt({this:e,expressions:[t]}),expressions:[e]})}),expression:s.args.expression}))}return this.func("ARRAY_TO_STRING",[s.args.this,s.args.expression])}regexpExtractCommon(s){let t=s.args.this,e=s.args.group,r=s.args.parameters,i=s.args.position,E=s.args.occurrence,c="nullIfPosOverflow"in s.args?s.args.nullIfPosOverflow:void 0;r&&r.isString&&(r.name??"").includes("e")&&(r=a.string((r.name??"").replace(/e/g,"")));let u=this.validateRegexpFlags(r,"cims"),A=e,_=String(this.dialect._constructor.REGEXP_EXTRACT_DEFAULT_GROUP);!u&&e&&(e instanceof It&&e.name===_||e instanceof a&&String(e.args.this)===_)&&(A=void 0);let O=u?a.string(u):void 0;i&&(!(i instanceof a&&i.isInteger)||1<parseInt(i.args.this??"0"))&&(t=new Pt({this:t,start:i}),c&&(t=new he({this:t,expression:a.string("")})));let G=s instanceof Re,V=E&&(!(E instanceof a&&E.isInteger)||1<parseInt(E.args.this??"0")),Ls=G||V?"REGEXP_EXTRACT_ALL":"REGEXP_EXTRACT",Tt=new d({this:Ls,expressions:[t,s.args.expression,A,O].filter(Boolean)});return G&&V?Tt=new q({this:Tt,expressions:[new B({this:E})]}):V&&(Tt=new d({this:"ARRAY_EXTRACT",expressions:[Tt,E]})),this.sql(Tt)}regexpExtractSql(s){return this.regexpExtractCommon(s)}regexpExtractAllSql(s){return this.regexpExtractCommon(s)}numberToStrSql(s){if(s.args.culture)return this.unsupported("DuckDB does not support the culture argument in NumberToStr"),this.functionFallbackSql(s);let t=s.args.format?.name;return t&&/^\d+$/.test(t)?this.func("FORMAT",[a.string(`{:,.${t}f}`),s.args.this]):(this.unsupported("Only integer formats are supported by NumberToStr"),this.functionFallbackSql(s))}autoIncrementColumnConstraintSql(s){return this.unsupported("The AUTOINCREMENT column constraint is not supported by DuckDB"),""}aliasesSql(s){let t=s.args.this;return t instanceof ki?this.posexplodeSql(t):super.aliasesSql(s)}posexplodeSql(s){let t=s.args.this,e=s.parent,r=new It({this:"pos",quoted:!1}),i=new It({this:"col",quoted:!1});if(e instanceof cr){let A=e.args.expressions;r=A?.[0],i=A?.[1]}else if(e instanceof ys){let A=e.args.alias;if(A instanceof Dt){let _=A.args.columns;_&&0<_.length&&(r=_[0],i=_[1]??i),A.pop()}}let E=this.sql(new Es({expressions:[t],alias:i})),c=this.sql(new qs({this:new F({this:new d({this:"GENERATE_SUBSCRIPTS",expressions:[t,a.number(1)]}),expression:a.number(1)}),alias:r})),u=this.formatArgs([c,E]);return e instanceof Cs||e&&e.parent instanceof Cs?`(SELECT ${u})`:u}addMonthsSql(s){let t=s.args.this;t?.type||(t=t&&Nt(t,{dialect:this.dialect})),t?.isType(l.TEXT_TYPES)&&(t=new T({this:t,to:new l({this:"timestamp"})}));let e=s.args.expression,r=e?.type?e:e&&Nt(e,{dialect:this.dialect}),i;r?.isType(["float","double","decimal"])?i=new d({this:"TO_MONTHS",expressions:[new T({this:new d({this:"ROUND",expressions:e&&[e]}),to:new l({this:"int"})})]}):i=new Y({this:e,unit:new C({this:"MONTH"})});let E=new I({this:t,expression:i}),c=s.args.preserveEndOfMonth,u=E;return c&&(u=new $({}).when(new v({this:x("LAST_DAY",t),expression:t}),x("LAST_DAY",E)).else(E)),t?.isType(["date","timestamptz"])?this.sql(new T({this:u,to:t.type})):this.sql(u)}formatSql(s){return s.name.toLowerCase()==="%s"&&s.args.expressions?.length===1?this.func("FORMAT",[a.string("{}"),s.args.expressions[0]]):this.functionFallbackSql(s)}dateTruncSql(s){let t=s.args.unit,e=s.args.this,r=Qo(t),i=yt(s),E;return r?E=this.sql(ve(e,r,{preserveStartDay:!0})):E=this.func("DATE_TRUNC",[i,e]),s.args.inputTypePreserved&&e?.isType(l.TEMPORAL_TYPES)&&!(Os(i)&&e.isType("date"))?this.sql(new T({this:E,to:e.type})):E}timestampTruncSql(s){let t=yt(s),e=s.args.zone,r=s.args.this,i=Os(t);if(i&&e){r=new ct({this:r,zone:e});let c=this.func("DATE_TRUNC",[t,r]);return this.sql(new ct({this:c,zone:e}))}let E=this.func("DATE_TRUNC",[t,r]);if(s.args.inputTypePreserved){if(r?.isType(["time","timetz"])){let c=new T({this:a.string("1970-01-01"),to:new l({this:"date"})}),u=new I({this:c,expression:r});return E=this.func("DATE_TRUNC",[t,u]),this.sql(new T({this:E,to:r.type}))}if(r?.isType(l.TEMPORAL_TYPES)&&!(i&&r.isType("date")))return this.sql(new T({this:E,to:r.type}))}return E}trimSql(s){let t=et(s.args.this);if(t&&s.setArgKey("this",t),s.args.expression instanceof N){let r=et(s.args.expression);r&&s.setArgKey("expression",r)}let e=super.trimSql(s);return ut.call(this,s,e)}hexStringSql(s){return super.hexStringSql(s,{binaryFunctionRepr:"UNHEX"})}roundSql(s){let t=s.args.this,e=s.args.decimals,r=s.args.truncate;e&&s.args.castsNonIntegerDecimals&&(e.isInteger||e.isType([...l.INTEGER_TYPES])||(e=new T({this:e,to:new l({this:"int"})})));let i="ROUND";if(r instanceof a){let E=r.args.this?.toUpperCase();E!==void 0&&["ROUND_HALF_EVEN","HALF_TO_EVEN"].includes(E)?(i="ROUND_EVEN",r=void 0):E!==void 0&&["ROUND_HALF_AWAY_FROM_ZERO","HALF_AWAY_FROM_ZERO"].includes(E)&&(r=void 0)}return this.func(i,[t,e,r])}strPositionSql(s){let t=s.args.position;return s.args.clampPosition&&t&&(s=s.copy(),s.setArgKey("position",new Q({this:new qr({this:t,expression:a.number(0)}),true:a.number(1),false:t.copy()}))),ca.call(this,s)}strtokSql(s){let t=s.args.this,e=s.args.delimiter,r=s.args.partIndex;if(e&&r){let i=new d({this:"REGEXP_REPLACE",expressions:[e,a.string(String.raw`([\[\]^.\-*+?(){}|$\\])`),a.string(String.raw`\\\1`),a.string("g")]}),E=J().when(e.eq(a.string("")),a.string("")).else(x("CONCAT",a.string("["),i,a.string("]"))),c=x("REGEXP_SPLIT_TO_ARRAY",t,E),u=H("x"),A=u.eq(a.string("")),_=x("LIST_FILTER",c,new rt({this:new Ot({this:A.copy()}),expressions:[u.copy()]})),O=new q({this:_,expressions:[r],offset:1}),G=b(this._constructor.STRTOK_TEMPLATE.copy(),[],{string:t,delimiter:e,partIndex:r,baseFunc:O});return this.sql(G)}return this.functionFallbackSql(s)}approxQuantileSql(s){let t=this.func("APPROX_QUANTILE",[s.args.this,s.args.quantile]);return s.isType(l.REAL_TYPES)&&(t=`CAST(${t} AS DOUBLE)`),t}approxQuantilesSql(s){let t=s.args.this,e;if(t instanceof bs){if(!t.args.expressions||t.args.expressions.length<2)return this.unsupported("APPROX_QUANTILES requires a bucket count argument"),this.functionFallbackSql(s);e=t.args.expressions[1].pop()}else e=s.args.expression;if(!(e instanceof a&&e.isInteger))return this.unsupported("APPROX_QUANTILES bucket count must be a positive integer"),this.functionFallbackSql(s);let r=parseInt(e.args.this??"0");if(r<=0)return this.unsupported("APPROX_QUANTILES bucket count must be a positive integer"),this.functionFallbackSql(s);let i=Array.from({length:r+1},(E,c)=>a.number(c/r));return this.sql(new zi({this:t,quantile:new W({expressions:i})}))}jsonExtractScalarSql(s){return s.args.scalarOnly&&(s=new ge({this:new d({this:"JSON_VALUE",expressions:[s.args.this,s.args.expression].filter(t=>t instanceof N)}),expression:a.string("$")})),Ha.call(this,s)}bitwiseNotSql(s){let t=s.args.this;Z(t)&&(s.type=new l({this:"binary"}));let e=Xe(t);t instanceof br&&(e=new L({this:e})),s.setArgKey("this",e);let r=`~${this.sql(s,"this")}`;return ut.call(this,s,r)}windowSql(s){let t=s.args.this;return t instanceof At||t instanceof Gt&&t.args.this instanceof At?this.corrSql(s):super.windowSql(s)}filterSql(s){return s.args.this instanceof At?this.corrSql(s):super.filterSql(s)}corrSql(s){if(s instanceof At&&!s.args.nullOnZeroVariance)return this.func("CORR",[s.args.this,s.args.expression]);let t=CE(s);return t?this.sql(new $({}).when(new Te({this:t}),f()).else(t)):s instanceof jt?super.windowSql(s):s instanceof Gt?super.filterSql(s):this.sql(s)}};w=Mt(vo),S(w,10,"STRTOK_TEMPLATE",Yo,h),S(w,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",Bo,h),S(w,10,"STRUCT_DELIMITER",Ho,h),S(w,10,"ORIGINAL_TRANSFORMS",Uo,h),S(w,10,"SUPPORTED_JSON_PATH_PARTS",Fo,h),S(w,10,"TYPE_MAPPING",Go,h),S(w,10,"RESERVED_KEYWORDS",Do,h),S(w,10,"UNWRAPPED_INTERVAL_VALUES",bo,h),S(w,10,"PROPERTIES_LOCATION",qo,h),S(w,10,"IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS",Mo,h),S(w,10,"ZIPF_TEMPLATE",yo,h),S(w,10,"NORMAL_TEMPLATE",Co,h),S(w,10,"SEEDED_RANDOM_TEMPLATE",Po,h),S(w,10,"SEQ_UNSIGNED",Oo,h),S(w,10,"SEQ_SIGNED",Lo,h),S(w,10,"MAPCAT_TEMPLATE",_o,h),S(w,10,"EXTRACT_STRFTIME_MAPPINGS",wo,h),S(w,10,"EXTRACT_EPOCH_MAPPINGS",Io,h),S(w,10,"BITMAP_CONSTRUCT_AGG_TEMPLATE",No,h),S(w,10,"RANDSTR_TEMPLATE",mo,h),S(w,10,"MINHASH_TEMPLATE",Ro,h),S(w,10,"MINHASH_COMBINE_TEMPLATE",xo,h),S(w,10,"APPROXIMATE_SIMILARITY_TEMPLATE",Ao,h),S(w,10,"ARRAYS_ZIP_TEMPLATE",fo,h),qt(w,h),bt(w,3,h),p(h,"DuckDBGenerator"),h.SUPPORTS_DECODE_CASE=!1,h.SELECT_KINDS=[],h.PARAMETER_TOKEN="$",h.NAMED_PLACEHOLDER_TOKEN="$",h.JOIN_HINTS=!1,h.TABLE_HINTS=!1,h.QUERY_HINTS=!1,h.LIMIT_FETCH="LIMIT",h.RENAME_TABLE_WITH_DB=!1,h.NVL2_SUPPORTED=!1,h.SEMI_ANTI_JOIN_WITH_SIDE=!1,h.TABLESAMPLE_KEYWORDS="USING SAMPLE",h.TABLESAMPLE_SEED_KEYWORD="REPEATABLE",h.LAST_DAY_SUPPORTS_DATE_PART=!1,h.JSON_KEY_VALUE_PAIR_SEP=",",h.IGNORE_NULLS_IN_FUNC=!0,h.IGNORE_NULLS_BEFORE_ORDER=!1,h.JSON_PATH_BRACKETED_KEY_SUPPORTED=!1,h.SUPPORTS_DROP_ALTER_ICEBERG_PROPERTY=!1,h.SUPPORTS_CREATE_TABLE_LIKE=!1,h.MULTI_ARG_DISTINCT=!1,h.CAN_IMPLEMENT_ARRAY_ANY=!0,h.SUPPORTS_TO_NUMBER=!1,h.SUPPORTS_WINDOW_EXCLUDE=!0,h.COPY_HAS_INTO_KEYWORD=!1,h.STAR_EXCEPT="EXCLUDE",h.PAD_FILL_PATTERN_IS_REQUIRED=!0,h.ARRAY_SIZE_DIM_REQUIRED=!1,h.NORMALIZE_EXTRACT_DATE_PARTS=!0,h.SUPPORTS_LIKE_QUANTIFIERS=!1,h.SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD=!0,h.ARRAY_BAG_TEMPLATE=y(`CASE
95
95
  WHEN :arr1 IS NULL OR :arr2 IS NULL THEN NULL
96
96
  ELSE LIST_TRANSFORM(
97
97
  LIST_FILTER(
@@ -100,11 +100,11 @@ import{a as Ma}from"../chunk-WDNJ5X7T.js";import"../chunk-YGEJLTA7.js";import{$d
100
100
  ),
101
101
  pair -> pair[0]
102
102
  )
103
- END`),h.ARRAY_EXCEPT_CONDITION=M("LEN(LIST_FILTER(:arr1[1:pair[1]], e -> e IS NOT DISTINCT FROM pair[0])) > LEN(LIST_FILTER(:arr2, e -> e IS NOT DISTINCT FROM pair[0]))"),h.ARRAY_INTERSECTION_CONDITION=M("LEN(LIST_FILTER(:arr1[1:pair[1]], e -> e IS NOT DISTINCT FROM pair[0])) <= LEN(LIST_FILTER(:arr2, e -> e IS NOT DISTINCT FROM pair[0]))"),h.ARRAY_EXCEPT_SET_TEMPLATE=M(`CASE
103
+ END`),h.ARRAY_EXCEPT_CONDITION=y("LEN(LIST_FILTER(:arr1[1:pair[1]], e -> e IS NOT DISTINCT FROM pair[0])) > LEN(LIST_FILTER(:arr2, e -> e IS NOT DISTINCT FROM pair[0]))"),h.ARRAY_INTERSECTION_CONDITION=y("LEN(LIST_FILTER(:arr1[1:pair[1]], e -> e IS NOT DISTINCT FROM pair[0])) <= LEN(LIST_FILTER(:arr2, e -> e IS NOT DISTINCT FROM pair[0]))"),h.ARRAY_EXCEPT_SET_TEMPLATE=y(`CASE
104
104
  WHEN :arr1 IS NULL OR :arr2 IS NULL THEN NULL
105
105
  ELSE LIST_FILTER(
106
106
  LIST_DISTINCT(:arr1),
107
107
  e -> LEN(LIST_FILTER(:arr2, x -> x IS NOT DISTINCT FROM e)) = 0
108
108
  )
109
- END`);var Kt=h,Xo,ko,Vo,Ko,Wo,$o,Rt,P=class P extends($o=be,Wo=[g],Ko=[g],Vo=[g],ko=[g],Xo=[g],$o){static get NULL_ORDERING(){return"nulls_are_last"}static get NORMALIZATION_STRATEGY(){return"caseInsensitive"}static get DATE_PART_MAPPING(){let s={...be.DATE_PART_MAPPING,DAYOFWEEKISO:"ISODOW"};return delete s.WEEKDAY,s}static get EXPRESSION_METADATA(){return new Map(Ma.EXPRESSION_METADATA)}static get INVERSE_TIME_MAPPING(){return{"%e":"%-d","%:z":"%z","%-z":"%z","%f_zero":"%n","%f_one":"%n","%f_two":"%n","%f_three":"%g","%f_four":"%n","%f_five":"%n","%f_seven":"%n","%f_eight":"%n","%f_nine":"%n"}}toJsonPath(s){if(s instanceof a&&s.isString){let t=s.name;if(t.startsWith("/")||t.includes("[#"))return s}return super.toJsonPath(s)}};Rt=yt($o),S(Rt,10,"NULL_ORDERING",Wo,P),S(Rt,10,"NORMALIZATION_STRATEGY",Ko,P),S(Rt,10,"DATE_PART_MAPPING",Vo,P),S(Rt,10,"EXPRESSION_METADATA",ko,P),S(Rt,10,"INVERSE_TIME_MAPPING",Xo,P),qt(Rt,P),bt(Rt,3,P),p(P,"DuckDB"),P.DIALECT_NAME="duckdb",P.SUPPORTS_USER_DEFINED_TYPES=!0,P.SAFE_DIVISION=!0,P.INDEX_OFFSET=1,P.CONCAT_COALESCE=!0,P.SUPPORTS_ORDER_BY_ALL=!0,P.SUPPORTS_FIXED_SIZE_ARRAYS=!0,P.STRICT_JSON_PATH_SYNTAX=!1,P.NUMBERS_CAN_BE_UNDERSCORE_SEPARATED=!0,P.Tokenizer=ke,P.Parser=Ve,P.Generator=Kt;var _s=P;export{_s as DuckDB,iE as MAX_BIT_POSITION,rE as RANDSTR_CHAR_POOL,nE as RANDSTR_SEED,ya as REGEX_ESCAPE_REPLACEMENTS,aE as SEQ_BASE,EE as SEQ_RESTRICTED,eE as TIMEZONE_PATTERN,ws as WEEK_START_DAY_TO_DOW,ms as WS_CONTROL_CHARS_TO_DUCK};
109
+ END`);var $t=h,ko,Xo,Vo,Ko,Wo,$o,Rt,P=class P extends($o=De,Wo=[g],Ko=[g],Vo=[g],Xo=[g],ko=[g],$o){static get NULL_ORDERING(){return"nulls_are_last"}static get NORMALIZATION_STRATEGY(){return"caseInsensitive"}static get DATE_PART_MAPPING(){let s={...De.DATE_PART_MAPPING,DAYOFWEEKISO:"ISODOW"};return delete s.WEEKDAY,s}static get EXPRESSION_METADATA(){return new Map(ya.EXPRESSION_METADATA)}static get INVERSE_TIME_MAPPING(){return{"%e":"%-d","%:z":"%z","%-z":"%z","%f_zero":"%n","%f_one":"%n","%f_two":"%n","%f_three":"%g","%f_four":"%n","%f_five":"%n","%f_seven":"%n","%f_eight":"%n","%f_nine":"%n"}}toJsonPath(s){if(s instanceof a&&s.isString){let t=s.name;if(t.startsWith("/")||t.includes("[#"))return s}return super.toJsonPath(s)}};Rt=Mt($o),S(Rt,10,"NULL_ORDERING",Wo,P),S(Rt,10,"NORMALIZATION_STRATEGY",Ko,P),S(Rt,10,"DATE_PART_MAPPING",Vo,P),S(Rt,10,"EXPRESSION_METADATA",Xo,P),S(Rt,10,"INVERSE_TIME_MAPPING",ko,P),qt(Rt,P),bt(Rt,3,P),p(P,"DuckDB"),P.DIALECT_NAME="duckdb",P.SUPPORTS_USER_DEFINED_TYPES=!0,P.SAFE_DIVISION=!0,P.INDEX_OFFSET=1,P.CONCAT_COALESCE=!0,P.SUPPORTS_ORDER_BY_ALL=!0,P.SUPPORTS_FIXED_SIZE_ARRAYS=!0,P.STRICT_JSON_PATH_SYNTAX=!1,P.NUMBERS_CAN_BE_UNDERSCORE_SEPARATED=!0,P.Tokenizer=Ve,P.Parser=Ke,P.Generator=$t;var _s=P;export{_s as DuckDB,iE as MAX_BIT_POSITION,rE as RANDSTR_CHAR_POOL,nE as RANDSTR_SEED,Ma as REGEX_ESCAPE_REPLACEMENTS,aE as SEQ_BASE,EE as SEQ_RESTRICTED,eE as TIMEZONE_PATTERN,ws as WEEK_START_DAY_TO_DOW,ms as WS_CONTROL_CHARS_TO_DUCK};
110
110
  //# sourceMappingURL=duckdb.js.map