@hdnax/sqlingo.js 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +8 -14
  3. package/README.npm.md +8 -14
  4. package/README.repo.md +1 -2
  5. package/dist/chunk-2YNOERAO.cjs +2 -0
  6. package/dist/chunk-2YNOERAO.cjs.map +1 -0
  7. package/dist/chunk-2Z3O2CFM.cjs +19 -0
  8. package/dist/chunk-2Z3O2CFM.cjs.map +1 -0
  9. package/dist/chunk-4ZMKB6PV.cjs +2 -0
  10. package/dist/chunk-4ZMKB6PV.cjs.map +1 -0
  11. package/dist/chunk-53OWF4GG.js +2 -0
  12. package/dist/chunk-53OWF4GG.js.map +1 -0
  13. package/dist/chunk-C4CLTVOW.cjs +2 -0
  14. package/dist/chunk-C4CLTVOW.cjs.map +1 -0
  15. package/dist/chunk-DOKMTZYO.cjs +4 -0
  16. package/dist/chunk-DOKMTZYO.cjs.map +1 -0
  17. package/dist/chunk-FCGUTI7Y.js +2 -0
  18. package/dist/chunk-FCGUTI7Y.js.map +1 -0
  19. package/dist/chunk-IPCIXWCY.js +2 -0
  20. package/dist/chunk-IPCIXWCY.js.map +1 -0
  21. package/dist/chunk-KCNOE4DZ.js +19 -0
  22. package/dist/chunk-KCNOE4DZ.js.map +1 -0
  23. package/dist/chunk-NRJHX2GZ.js +2 -0
  24. package/dist/chunk-NRJHX2GZ.js.map +1 -0
  25. package/dist/chunk-O2J5RKBN.js +2 -0
  26. package/dist/chunk-O2J5RKBN.js.map +1 -0
  27. package/dist/chunk-PXUASP5I.js +2 -0
  28. package/dist/chunk-PXUASP5I.js.map +1 -0
  29. package/dist/chunk-R7C3ZHVK.cjs +2 -0
  30. package/dist/chunk-R7C3ZHVK.cjs.map +1 -0
  31. package/dist/chunk-UHWHUDLE.cjs +2 -0
  32. package/dist/chunk-UHWHUDLE.cjs.map +1 -0
  33. package/dist/chunk-WRNYJ54A.cjs +2 -0
  34. package/dist/chunk-WRNYJ54A.cjs.map +1 -0
  35. package/dist/chunk-XZQFOICX.cjs +3 -0
  36. package/dist/chunk-XZQFOICX.cjs.map +1 -0
  37. package/dist/chunk-YLOQRUXC.js +2 -0
  38. package/dist/chunk-YLOQRUXC.js.map +1 -0
  39. package/dist/chunk-YSS2WVCM.cjs +2 -0
  40. package/dist/chunk-YSS2WVCM.cjs.map +1 -0
  41. package/dist/chunk-Z5V6VOIN.js +3 -0
  42. package/dist/chunk-Z5V6VOIN.js.map +1 -0
  43. package/dist/chunk-ZBFGQPJR.js +4 -0
  44. package/dist/chunk-ZBFGQPJR.js.map +1 -0
  45. package/dist/dialects/athena.cjs +2 -0
  46. package/dist/dialects/athena.cjs.map +1 -0
  47. package/dist/dialects/athena.d.cts +66 -0
  48. package/dist/dialects/athena.d.ts +66 -0
  49. package/dist/dialects/athena.js +2 -0
  50. package/dist/dialects/athena.js.map +1 -0
  51. package/dist/dialects/bigquery.cjs +3 -0
  52. package/dist/dialects/bigquery.cjs.map +1 -0
  53. package/dist/dialects/bigquery.d.cts +651 -0
  54. package/dist/dialects/bigquery.d.ts +651 -0
  55. package/dist/dialects/bigquery.js +3 -0
  56. package/dist/dialects/bigquery.js.map +1 -0
  57. package/dist/dialects/clickhouse.cjs +2 -0
  58. package/dist/dialects/clickhouse.cjs.map +1 -0
  59. package/dist/dialects/clickhouse.d.cts +634 -0
  60. package/dist/dialects/clickhouse.d.ts +634 -0
  61. package/dist/dialects/clickhouse.js +2 -0
  62. package/dist/dialects/clickhouse.js.map +1 -0
  63. package/dist/dialects/databricks.cjs +2 -0
  64. package/dist/dialects/databricks.cjs.map +1 -0
  65. package/dist/dialects/databricks.d.cts +484 -0
  66. package/dist/dialects/databricks.d.ts +484 -0
  67. package/dist/dialects/databricks.js +2 -0
  68. package/dist/dialects/databricks.js.map +1 -0
  69. package/dist/dialects/doris.cjs +2 -0
  70. package/dist/dialects/doris.cjs.map +1 -0
  71. package/dist/dialects/doris.d.cts +484 -0
  72. package/dist/dialects/doris.d.ts +484 -0
  73. package/dist/dialects/doris.js +2 -0
  74. package/dist/dialects/doris.js.map +1 -0
  75. package/dist/dialects/dremio.cjs +2 -0
  76. package/dist/dialects/dremio.cjs.map +1 -0
  77. package/dist/dialects/dremio.d.cts +522 -0
  78. package/dist/dialects/dremio.d.ts +522 -0
  79. package/dist/dialects/dremio.js +2 -0
  80. package/dist/dialects/dremio.js.map +1 -0
  81. package/dist/dialects/drill.cjs +2 -0
  82. package/dist/dialects/drill.cjs.map +1 -0
  83. package/dist/dialects/drill.d.cts +512 -0
  84. package/dist/dialects/drill.d.ts +512 -0
  85. package/dist/dialects/drill.js +2 -0
  86. package/dist/dialects/drill.js.map +1 -0
  87. package/dist/dialects/druid.cjs +2 -0
  88. package/dist/dialects/druid.cjs.map +1 -0
  89. package/dist/dialects/druid.d.cts +17 -0
  90. package/dist/dialects/druid.d.ts +17 -0
  91. package/dist/dialects/druid.js +2 -0
  92. package/dist/dialects/druid.js.map +1 -0
  93. package/dist/dialects/duckdb.cjs +86 -0
  94. package/dist/dialects/duckdb.cjs.map +1 -0
  95. package/dist/dialects/duckdb.d.cts +756 -0
  96. package/dist/dialects/duckdb.d.ts +756 -0
  97. package/dist/dialects/duckdb.js +86 -0
  98. package/dist/dialects/duckdb.js.map +1 -0
  99. package/dist/dialects/dune.cjs +2 -0
  100. package/dist/dialects/dune.cjs.map +1 -0
  101. package/dist/dialects/dune.d.cts +21 -0
  102. package/dist/dialects/dune.d.ts +21 -0
  103. package/dist/dialects/dune.js +2 -0
  104. package/dist/dialects/dune.js.map +1 -0
  105. package/dist/dialects/exasol.cjs +2 -0
  106. package/dist/dialects/exasol.cjs.map +1 -0
  107. package/dist/dialects/exasol.d.cts +507 -0
  108. package/dist/dialects/exasol.d.ts +507 -0
  109. package/dist/dialects/exasol.js +2 -0
  110. package/dist/dialects/exasol.js.map +1 -0
  111. package/dist/dialects/fabric.cjs +2 -0
  112. package/dist/dialects/fabric.cjs.map +1 -0
  113. package/dist/dialects/fabric.d.cts +463 -0
  114. package/dist/dialects/fabric.d.ts +463 -0
  115. package/dist/dialects/fabric.js +2 -0
  116. package/dist/dialects/fabric.js.map +1 -0
  117. package/dist/dialects/hive.cjs +2 -0
  118. package/dist/dialects/hive.cjs.map +1 -0
  119. package/dist/dialects/hive.d.cts +585 -0
  120. package/dist/dialects/hive.d.ts +585 -0
  121. package/dist/dialects/hive.js +2 -0
  122. package/dist/dialects/hive.js.map +1 -0
  123. package/dist/dialects/materialize.cjs +2 -0
  124. package/dist/dialects/materialize.cjs.map +1 -0
  125. package/dist/dialects/materialize.d.cts +890 -0
  126. package/dist/dialects/materialize.d.ts +890 -0
  127. package/dist/dialects/materialize.js +2 -0
  128. package/dist/dialects/materialize.js.map +1 -0
  129. package/dist/dialects/mysql.cjs +2 -0
  130. package/dist/dialects/mysql.cjs.map +1 -0
  131. package/dist/dialects/mysql.d.cts +292 -0
  132. package/dist/dialects/mysql.d.ts +292 -0
  133. package/dist/dialects/mysql.js +2 -0
  134. package/dist/dialects/mysql.js.map +1 -0
  135. package/dist/dialects/oracle.cjs +2 -0
  136. package/dist/dialects/oracle.cjs.map +1 -0
  137. package/dist/dialects/oracle.d.cts +539 -0
  138. package/dist/dialects/oracle.d.ts +539 -0
  139. package/dist/dialects/oracle.js +2 -0
  140. package/dist/dialects/oracle.js.map +1 -0
  141. package/dist/dialects/postgres.cjs +2 -0
  142. package/dist/dialects/postgres.cjs.map +1 -0
  143. package/dist/dialects/postgres.d.cts +587 -0
  144. package/dist/dialects/postgres.d.ts +587 -0
  145. package/dist/dialects/postgres.js +2 -0
  146. package/dist/dialects/postgres.js.map +1 -0
  147. package/dist/dialects/presto.cjs +2 -0
  148. package/dist/dialects/presto.cjs.map +1 -0
  149. package/dist/dialects/presto.d.cts +173 -0
  150. package/dist/dialects/presto.d.ts +173 -0
  151. package/dist/dialects/presto.js +2 -0
  152. package/dist/dialects/presto.js.map +1 -0
  153. package/dist/dialects/prql.cjs +2 -0
  154. package/dist/dialects/prql.cjs.map +1 -0
  155. package/dist/dialects/prql.d.cts +496 -0
  156. package/dist/dialects/prql.d.ts +496 -0
  157. package/dist/dialects/prql.js +2 -0
  158. package/dist/dialects/prql.js.map +1 -0
  159. package/dist/dialects/redshift.cjs +2 -0
  160. package/dist/dialects/redshift.cjs.map +1 -0
  161. package/dist/dialects/redshift.d.cts +132 -0
  162. package/dist/dialects/redshift.d.ts +132 -0
  163. package/dist/dialects/redshift.js +2 -0
  164. package/dist/dialects/redshift.js.map +1 -0
  165. package/dist/dialects/risingwave.cjs +2 -0
  166. package/dist/dialects/risingwave.cjs.map +1 -0
  167. package/dist/dialects/risingwave.d.cts +478 -0
  168. package/dist/dialects/risingwave.d.ts +478 -0
  169. package/dist/dialects/risingwave.js +2 -0
  170. package/dist/dialects/risingwave.js.map +1 -0
  171. package/dist/dialects/singlestore.cjs +2 -0
  172. package/dist/dialects/singlestore.cjs.map +1 -0
  173. package/dist/dialects/singlestore.d.cts +73 -0
  174. package/dist/dialects/singlestore.d.ts +73 -0
  175. package/dist/dialects/singlestore.js +2 -0
  176. package/dist/dialects/singlestore.js.map +1 -0
  177. package/dist/dialects/snowflake.cjs +3 -0
  178. package/dist/dialects/snowflake.cjs.map +1 -0
  179. package/dist/dialects/snowflake.d.cts +320 -0
  180. package/dist/dialects/snowflake.d.ts +320 -0
  181. package/dist/dialects/snowflake.js +3 -0
  182. package/dist/dialects/snowflake.js.map +1 -0
  183. package/dist/dialects/solr.cjs +2 -0
  184. package/dist/dialects/solr.cjs.map +1 -0
  185. package/dist/dialects/solr.d.cts +458 -0
  186. package/dist/dialects/solr.d.ts +458 -0
  187. package/dist/dialects/solr.js +2 -0
  188. package/dist/dialects/solr.js.map +1 -0
  189. package/dist/dialects/spark.cjs +2 -0
  190. package/dist/dialects/spark.cjs.map +1 -0
  191. package/dist/dialects/spark.d.cts +484 -0
  192. package/dist/dialects/spark.d.ts +484 -0
  193. package/dist/dialects/spark.js +2 -0
  194. package/dist/dialects/spark.js.map +1 -0
  195. package/dist/dialects/spark2.cjs +2 -0
  196. package/dist/dialects/spark2.cjs.map +1 -0
  197. package/dist/dialects/spark2.d.cts +486 -0
  198. package/dist/dialects/spark2.d.ts +486 -0
  199. package/dist/dialects/spark2.js +2 -0
  200. package/dist/dialects/spark2.js.map +1 -0
  201. package/dist/dialects/sqlite.cjs +2 -0
  202. package/dist/dialects/sqlite.cjs.map +1 -0
  203. package/dist/dialects/sqlite.d.cts +510 -0
  204. package/dist/dialects/sqlite.d.ts +510 -0
  205. package/dist/dialects/sqlite.js +2 -0
  206. package/dist/dialects/sqlite.js.map +1 -0
  207. package/dist/dialects/starrocks.cjs +2 -0
  208. package/dist/dialects/starrocks.cjs.map +1 -0
  209. package/dist/dialects/starrocks.d.cts +518 -0
  210. package/dist/dialects/starrocks.d.ts +518 -0
  211. package/dist/dialects/starrocks.js +2 -0
  212. package/dist/dialects/starrocks.js.map +1 -0
  213. package/dist/dialects/tableau.cjs +2 -0
  214. package/dist/dialects/tableau.cjs.map +1 -0
  215. package/dist/dialects/tableau.d.cts +466 -0
  216. package/dist/dialects/tableau.d.ts +466 -0
  217. package/dist/dialects/tableau.js +2 -0
  218. package/dist/dialects/tableau.js.map +1 -0
  219. package/dist/dialects/teradata.cjs +2 -0
  220. package/dist/dialects/teradata.cjs.map +1 -0
  221. package/dist/dialects/teradata.d.cts +539 -0
  222. package/dist/dialects/teradata.d.ts +539 -0
  223. package/dist/dialects/teradata.js +2 -0
  224. package/dist/dialects/teradata.js.map +1 -0
  225. package/dist/dialects/trino.cjs +2 -0
  226. package/dist/dialects/trino.cjs.map +1 -0
  227. package/dist/dialects/trino.d.cts +465 -0
  228. package/dist/dialects/trino.d.ts +465 -0
  229. package/dist/dialects/trino.js +2 -0
  230. package/dist/dialects/trino.js.map +1 -0
  231. package/dist/dialects/tsql.cjs +2 -0
  232. package/dist/dialects/tsql.cjs.map +1 -0
  233. package/dist/dialects/tsql.d.cts +703 -0
  234. package/dist/dialects/tsql.d.ts +703 -0
  235. package/dist/dialects/tsql.js +2 -0
  236. package/dist/dialects/tsql.js.map +1 -0
  237. package/dist/index.cjs +5 -25
  238. package/dist/index.cjs.map +1 -1
  239. package/dist/index.d.cts +3 -14178
  240. package/dist/index.d.ts +3 -14178
  241. package/dist/index.js +5 -25
  242. package/dist/index.js.map +1 -1
  243. package/dist/tokens-VcMD09XM.d.cts +15805 -0
  244. package/dist/tokens-VcMD09XM.d.ts +15805 -0
  245. package/package.json +171 -5
@@ -0,0 +1,19 @@
1
+ var xq=Object.create;var rN=Object.defineProperty;var fq=Object.getOwnPropertyDescriptor;var gw=(i,e)=>(e=Symbol[i])?e:Symbol.for("Symbol."+i),Cf=i=>{throw TypeError(i)};var Tq=(i,e,t)=>e in i?rN(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var lw=(i,e)=>rN(i,"name",{value:e,configurable:!0});var Sq=(i,e)=>{for(var t in e)rN(i,t,{get:e[t],enumerable:!0})};var Bt=i=>[,,,xq(i?.[gw("metadata")]??null)],Ew=["class","method","getter","setter","accessor","field","value","get","set"],yf=i=>i!==void 0&&typeof i!="function"?Cf("Function expected"):i,mq=(i,e,t,s,r)=>({kind:Ew[i],name:e,metadata:s,addInitializer:n=>t._?Cf("Already initialized"):r.push(yf(n||null))}),bt=(i,e)=>Tq(e,gw("metadata"),i[3]),Lt=(i,e,t,s)=>{for(var r=0,n=i[e>>1],a=n&&n.length;r<a;r++)e&1?n[r].call(t):s=n[r].call(t,s);return s},S=(i,e,t,s,r,n)=>{var a,o,c,l,u,h=e&7,d=!!(e&8),x=!!(e&16),f=h>3?i.length+1:h?d?1:2:0,y=Ew[h+5],I=h>3&&(i[f-1]=[]),N=i[f]||(i[f]=[]),P=h&&(!x&&!d&&(r=r.prototype),h<5&&(h>3||!x)&&fq(h<4?r:{get[t](){return uw(this,n)},set[t](_){return hw(this,n,_)}},t));h?x&&h<4&&lw(n,(h>2?"set ":h>1?"get ":"")+t):lw(r,t);for(var k=s.length-1;k>=0;k--)l=mq(h,t,c={},i[3],N),h&&(l.static=d,l.private=x,u=l.access={has:x?_=>Oq(r,_):_=>t in _},h^3&&(u.get=x?_=>(h^1?uw:Rq)(_,r,h^4?n:P.get):_=>_[t]),h>2&&(u.set=x?(_,W)=>hw(_,r,W,h^4?n:P.set):(_,W)=>_[t]=W)),o=(0,s[k])(h?h<4?x?n:P[y]:h>4?void 0:{get:P.get,set:P.set}:r,l),c._=1,h^4||o===void 0?yf(o)&&(h>4?I.unshift(o):h?x?n=o:P[y]=o:r=o):typeof o!="object"||o===null?Cf("Object expected"):(yf(a=o.get)&&(P.get=a),yf(a=o.set)&&(P.set=a),yf(a=o.init)&&I.unshift(a));return h||bt(i,r),P&&rN(r,t,P),x?h^4?n:P:r};var oI=(i,e,t)=>e.has(i)||Cf("Cannot "+t),Oq=(i,e)=>Object(e)!==e?Cf('Cannot use the "in" operator on this value'):i.has(e),uw=(i,e,t)=>(oI(i,e,"read from private field"),t?t.call(i):e.get(i));var hw=(i,e,t,s)=>(oI(i,e,"write to private field"),s?s.call(i,t):e.set(i,t),t),Rq=(i,e,t)=>(oI(i,e,"access private method"),t);var Nq="\x1B[4m",Iq="\x1B[0m";var iN=(r=>(r[r.IGNORE=0]="IGNORE",r[r.WARN=1]="WARN",r[r.RAISE=2]="RAISE",r[r.IMMEDIATE=3]="IMMEDIATE",r))(iN||{}),za=class extends Error{constructor(e){super(e),this.name="SqlglotError",Error.captureStackTrace(this,this.constructor)}},Wn=class extends za{constructor(e){super(e),this.name="UnsupportedError",Error.captureStackTrace(this,this.constructor)}},xt=class i extends za{constructor(e,t){super(e),this.name="ParseError",this.errors=t||[],Error.captureStackTrace(this,this.constructor)}static new(e,t,s,r,n,a,o,c){return new i(e,[{description:t,line:s,col:r,startContext:n,highlight:a,endContext:o,intoExpression:c}])}},iA=class extends za{constructor(e){super(e),this.name="TokenError",Error.captureStackTrace(this,this.constructor)}},dl=class extends za{constructor(e){super(e),this.name="OptimizeError",Error.captureStackTrace(this,this.constructor)}},ms=class extends za{constructor(e){super(e),this.name="SchemaError",Error.captureStackTrace(this,this.constructor)}},Aw=class extends za{constructor(e){super(e),this.name="ExecuteError",Error.captureStackTrace(this,this.constructor)}};function dw(i){let{sql:e,positions:t,contextLength:s=100}=i;if(t.length===0)throw new Error("positions must contain at least one [start, end] tuple");let r="",n="",a=0,o=[],c=0,l=[...t].sort((d,x)=>d[0]-x[0]);0<l[0][0]&&(a=l[0][0],r=e.slice(Math.max(0,a-s),a),o.push(r),c=a);for(let[d,x]of l){let f=Math.max(d,c),y=x+1;y<=f||(c<f&&o.push(e.slice(c,f)),o.push(`${Nq}${e.slice(f,y)}${Iq}`),c=y)}c<e.length&&(n=e.slice(c,c+s),o.push(n));let u=o.join(""),h=e.slice(a,c);return{formattedSql:u,startContext:r,highlight:h,endContext:n}}function nN(i,e){let t=i.slice(0,e).map(r=>String(r)),s=i.length-e;return 0<s&&t.push(`... and ${s} more`),t.join(`
2
+
3
+ `)}function cI(i){return i.flatMap(e=>e.errors)}function aN(i,e){return typeof e=="string"?typeof i===e||e==="object"&&i===null:i instanceof e}function yq(i){return typeof i=="string"?`typeof === '${i}'`:i.name??String(i)}function $(i,...e){return e.some(t=>aN(i,t))}function te(i,...e){if(!e.some(t=>aN(i,t))){let t=e.map(yq).join(" | ");throw new TypeError(`Expected ${t}, got ${typeof i}`)}}function ft(i,...e){return e.some(t=>aN(i,t))?i:void 0}function Rt(i,...e){let t=[];for(let s of i)e.some(r=>aN(s,r))&&t.push(s);return t}function m(i,e){let t=new WeakMap;return e.addInitializer(function(){Object.defineProperty(this,e.name,{get(){return t.has(this)||t.set(this,i.call(this)),t.get(this)},set(s){t.set(this,s)},configurable:!0})}),i}var pI=new WeakMap;function Cq(i){let e=[],t=i;for(;t&&t!==Object&&t.prototype;)e.push(t),t=Object.getPrototypeOf(t);return e}function G(i,...e){class t extends i{}let s=[i,...e],r=[],n=new Set;for(let a of s){let o=Cq(a);for(let c of o)n.has(c)||(n.add(c),r.push(c))}for(let a of r){for(let c of Object.getOwnPropertyNames(a.prototype))if(c!=="constructor"&&!Object.getOwnPropertyDescriptor(t.prototype,c)){let l=Object.getOwnPropertyDescriptor(a.prototype,c);l&&Object.defineProperty(t.prototype,c,l)}for(let c of Object.getOwnPropertyNames(a))if(!["prototype","length","name"].includes(c)&&!Object.getOwnPropertyDescriptor(t,c)){let l=Object.getOwnPropertyDescriptor(a,c);l&&Object.defineProperty(t,c,l)}let o=pI.get(a);o||(o=new Set,pI.set(a,o),Object.defineProperty(a,Symbol.hasInstance,{value(c){if(this.prototype.isPrototypeOf(Object(c)))return!0;let l=pI.get(this);if(!l)return!1;let u=c?.constructor;for(;u&&u!==Object;){if(l.has(u))return!0;u=Object.getPrototypeOf(u)}return!1},configurable:!0})),o.add(t)}return t}var nA=class{constructor(){this._map=new Map}get(e,t){return this._map.get(e)?.get(t)}set(e,t,s){let r=this._map.get(e);return r||(r=new Map,this._map.set(e,r)),r.set(t,s),this}has(e,t){return this._map.get(e)?.has(t)??!1}delete(e,t){let s=this._map.get(e);if(!s)return!1;let r=s.delete(t);return s.size===0&&this._map.delete(e),r}clear(){this._map.clear()}get size(){let e=0;for(let t of this._map.values())e+=t.size;return e}*[Symbol.iterator](){for(let[e,t]of this._map)for(let[s,r]of t)yield[[e,s],r]}*keys(){for(let[e,t]of this._map)for(let s of t.keys())yield[e,s]}*values(){for(let e of this._map.values())yield*e.values()}*entries(){yield*this}};function ut(i,e){let t=Object.values(i),s=e?.toLowerCase();return t.find(r=>r===s)??t.find(r=>r.toLowerCase()===s)}function Pf(i){return i!=null&&typeof i[Symbol.iterator]=="function"}var Pq=0n,xw=new WeakMap,fw=new Map;function Tw(){return(Pq++).toString()}function bq(i){if(i!==null&&typeof i=="object"||typeof i=="function"){let t=i,s=xw.get(t);return s===void 0&&(s=Tw(),xw.set(t,s)),s}let e=fw.get(i);return e===void 0&&(e=Tw(),fw.set(i,e)),e}function Sw(i){return i!==null&&typeof i=="object"&&typeof i.add=="function"}function mw(i){return i!==null&&typeof i=="object"&&typeof i.radd=="function"}function Lq(i,e){return Sw(i)?i.add(e):mw(e)?e.radd(i):Array.isArray(i)&&Array.isArray(e)?[...i,...e]:i+e}function Ow(i){return i!==null&&typeof i=="object"&&typeof i.sub=="function"}function Rw(i){return i!==null&&typeof i=="object"&&typeof i.rsub=="function"}function wq(i,e){return Ow(i)?i.sub(e):Rw(e)?e.rsub(i):i instanceof Set&&e instanceof Set?new Set([...i].filter(t=>!e.has(t))):i-e}function Nw(i){return i!==null&&typeof i=="object"&&typeof i.mul=="function"}function Iw(i){return i!==null&&typeof i=="object"&&typeof i.rmul=="function"}function Mq(i,e){return Nw(i)?i.mul(e):Iw(e)?e.rmul(i):i*e}function yw(i){return i!==null&&typeof i=="object"&&typeof i.truediv=="function"}function Cw(i){return i!==null&&typeof i=="object"&&typeof i.rtruediv=="function"}function Dq(i,e){return yw(i)?i.truediv(e):Cw(e)?e.rtruediv(i):i/e}function Pw(i){return i!==null&&typeof i=="object"&&typeof i.floorDiv=="function"}function bw(i){return i!==null&&typeof i=="object"&&typeof i.rfloorDiv=="function"}function kq(i,e){return Pw(i)?i.floorDiv(e):bw(e)?e.rfloorDiv(i):Math.trunc(i/e)}function Lw(i){return i!==null&&typeof i=="object"&&typeof i.mod=="function"}function ww(i){return i!==null&&typeof i=="object"&&typeof i.rmod=="function"}function _q(i,e){return Lw(i)?i.mod(e):ww(e)?e.rmod(i):i%e}function Mw(i){return i!==null&&typeof i=="object"&&typeof i.pow=="function"}function Dw(i){return i!==null&&typeof i=="object"&&typeof i.rpow=="function"}function qq(i,e){return Mw(i)?i.pow(e):Dw(e)?e.rpow(i):i**e}function hI(i){return i!==null&&typeof i=="object"&&typeof i.lt=="function"}function Uq(i,e){return hI(i)?i.lt(e):EI(e)?e.gt(i):i<e}function gI(i){return i!==null&&typeof i=="object"&&typeof i.lte=="function"}function vq(i,e){return gI(i)?i.lte(e):AI(e)?e.gte(i):i<=e}function EI(i){return i!==null&&typeof i=="object"&&typeof i.gt=="function"}function Fq(i,e){return EI(i)?i.gt(e):hI(e)?e.lt(i):e<i}function AI(i){return i!==null&&typeof i=="object"&&typeof i.gte=="function"}function Bq(i,e){return AI(i)?i.gte(e):gI(e)?e.lte(i):e<=i}function lI(i){return i!==null&&typeof i=="object"&&typeof i.eq=="function"}function kw(i,e){return lI(i)?i.eq(e):lI(e)?e.eq(i):i===e}function uI(i){return i!==null&&typeof i=="object"&&typeof i.neq=="function"}function $q(i,e){return uI(i)?i.neq(e):uI(e)?e.neq(i):!kw(i,e)}function _w(i){return i!==null&&typeof i=="object"&&typeof i.or=="function"}function qw(i){return i!==null&&typeof i=="object"&&typeof i.ror=="function"}function Gq(i,e){return _w(i)?i.or(e):qw(e)?e.ror(i):i instanceof Set&&e instanceof Set?new Set([...i,...e]):i|e}function Uw(i){return i!==null&&typeof i=="object"&&typeof i.and=="function"}function vw(i){return i!==null&&typeof i=="object"&&typeof i.rand=="function"}function Yq(i,e){return Uw(i)?i.and(e):vw(e)?e.rand(i):i instanceof Set&&e instanceof Set?new Set([...i].filter(t=>e.has(t))):i&e}function Fw(i){return i!==null&&typeof i=="object"&&typeof i.xor=="function"}function Bw(i){return i!==null&&typeof i=="object"&&typeof i.rxor=="function"}function Vq(i,e){if(Fw(i))return i.xor(e);if(Bw(e))return e.rxor(i);if(i instanceof Set&&e instanceof Set){let t=i,s=e;return new Set([...[...t].filter(r=>!s.has(r)),...[...s].filter(r=>!t.has(r))])}return i^e}function $w(i){return i!==null&&typeof i=="object"&&typeof i.lshift=="function"}function Gw(i){return i!==null&&typeof i=="object"&&typeof i.rlshift=="function"}function Hq(i,e){return $w(i)?i.lshift(e):Gw(e)?e.rlshift(i):i<<e}function Yw(i){return i!==null&&typeof i=="object"&&typeof i.rshift=="function"}function Vw(i){return i!==null&&typeof i=="object"&&typeof i.rrshift=="function"}function Wq(i,e){return Yw(i)?i.rshift(e):Vw(e)?e.rrshift(i):i>>e}var ty={};Sq(ty,{ALL_FUNCTIONS:()=>$f,AbsExpr:()=>$T,AcosExpr:()=>PT,AcoshExpr:()=>bT,AddConstraintExpr:()=>mc,AddExpr:()=>Le,AddMonthsExpr:()=>zP,AddPartitionExpr:()=>Oc,AdjacentExpr:()=>ip,AggFuncExpr:()=>D,AiAggExpr:()=>RL,AiClassifyExpr:()=>$y,AiSummarizeAggExpr:()=>NL,AlgorithmPropertyExpr:()=>qr,AliasExpr:()=>Re,AliasesExpr:()=>kr,AllExpr:()=>ys,AllowedValuesPropertyExpr:()=>Dr,AlterColumnExpr:()=>as,AlterDistStyleExpr:()=>ta,AlterExpr:()=>sn,AlterExprKind:()=>bf,AlterIndexExpr:()=>XA,AlterRenameExpr:()=>Mr,AlterSessionExpr:()=>ia,AlterSetExpr:()=>Co,AlterSortKeyExpr:()=>sa,AnalyzeColumnsExpr:()=>nn,AnalyzeDeleteExpr:()=>Tc,AnalyzeDeleteExprKind:()=>cM,AnalyzeExpr:()=>na,AnalyzeExprKind:()=>nM,AnalyzeHistogramExpr:()=>dc,AnalyzeListChainedRowsExpr:()=>fc,AnalyzeSampleExpr:()=>xc,AnalyzeSampleExprKind:()=>oM,AnalyzeStatisticsExpr:()=>Ac,AnalyzeStatisticsExprKind:()=>aM,AnalyzeValidateExpr:()=>Sc,AnalyzeValidateExprKind:()=>pM,AnalyzeWithExpr:()=>rn,AndExpr:()=>ce,AnonymousAggFuncExpr:()=>MN,AnonymousExpr:()=>je,AnyExpr:()=>Ct,AnyValueExpr:()=>hm,ApplyExpr:()=>by,ApproxDistinctExpr:()=>pm,ApproxPercentileAccumulateExpr:()=>BL,ApproxPercentileCombineExpr:()=>gL,ApproxPercentileEstimateExpr:()=>ob,ApproxQuantileExpr:()=>$n,ApproxQuantilesExpr:()=>hL,ApproxTopKAccumulateExpr:()=>pL,ApproxTopKCombineExpr:()=>lL,ApproxTopKEstimateExpr:()=>Ny,ApproxTopKExpr:()=>cL,ApproxTopSumExpr:()=>uL,ApproximateSimilarityExpr:()=>dL,ArgMaxExpr:()=>IA,ArgMinExpr:()=>yA,ArrayAggExpr:()=>uo,ArrayAllExpr:()=>Gy,ArrayAnyExpr:()=>Yy,ArrayAppendExpr:()=>Wf,ArrayCompactExpr:()=>Vy,ArrayConcatAggExpr:()=>lm,ArrayConcatExpr:()=>_l,ArrayConstructCompactExpr:()=>jy,ArrayContainsAllExpr:()=>lo,ArrayContainsExpr:()=>Jy,ArrayExpr:()=>ue,ArrayFilterExpr:()=>dp,ArrayFirstExpr:()=>HT,ArrayInsertExpr:()=>Hy,ArrayIntersectExpr:()=>Xy,ArrayLastExpr:()=>WT,ArrayOverlapsExpr:()=>TT,ArrayPrependExpr:()=>jf,ArrayRemoveAtExpr:()=>Wy,ArrayRemoveExpr:()=>kl,ArrayReverseExpr:()=>jT,ArraySizeExpr:()=>Bn,ArraySliceExpr:()=>JT,ArraySortExpr:()=>Ky,ArraySumExpr:()=>eC,ArrayToStringExpr:()=>XT,ArrayUnionAggExpr:()=>IL,ArrayUniqueAggExpr:()=>OL,ArraysZipExpr:()=>tC,AsciiExpr:()=>YT,AsinExpr:()=>LT,AsinhExpr:()=>wT,AtIndexExpr:()=>Nc,AtTimeZoneExpr:()=>Wt,Atan2Expr:()=>ry,AtanExpr:()=>MT,AtanhExpr:()=>DT,AttachExpr:()=>YA,AttachOptionExpr:()=>hd,AutoIncrementColumnConstraintExpr:()=>bA,AutoIncrementPropertyExpr:()=>Ur,AutoRefreshPropertyExpr:()=>vr,AvgExpr:()=>um,BackupPropertyExpr:()=>Fr,Base64DecodeBinaryExpr:()=>JC,Base64DecodeStringExpr:()=>XC,Base64EncodeExpr:()=>zC,BetweenExpr:()=>ss,BinaryExpr:()=>q,BitLengthExpr:()=>MS,BitStringExpr:()=>PA,BitmapBitPositionExpr:()=>fy,BitmapBucketNumberExpr:()=>dy,BitmapConstructAggExpr:()=>aL,BitmapCountExpr:()=>xy,BitmapOrAggExpr:()=>oL,BitwiseAndAggExpr:()=>sL,BitwiseAndExpr:()=>Ta,BitwiseCountExpr:()=>Ay,BitwiseLeftShiftExpr:()=>wl,BitwiseNotExpr:()=>np,BitwiseOrAggExpr:()=>rL,BitwiseOrExpr:()=>Ml,BitwiseRightShiftExpr:()=>Sa,BitwiseXorAggExpr:()=>iL,BitwiseXorExpr:()=>Dl,BlockCompressionPropertyExpr:()=>hn,BoolandExpr:()=>my,BooleanExpr:()=>ot,BoolnotExpr:()=>Sy,BoolorExpr:()=>Oy,BoolxorAggExpr:()=>nL,BracketExpr:()=>Dt,BuildPropertyExpr:()=>Rd,ByteLengthExpr:()=>Ty,ByteStringExpr:()=>Nl,COLUMN_PARTS:()=>lq,CONSTANTS:()=>bI,CacheExpr:()=>go,CaseExpr:()=>nt,CaseSpecificColumnConstraintExpr:()=>Pr,CastExpr:()=>X,CastToStrTypeExpr:()=>Jf,CbrtExpr:()=>vl,CeilExpr:()=>Oa,ChangesExpr:()=>wo,CharacterSetColumnConstraintExpr:()=>Uc,CharacterSetExpr:()=>ea,CharacterSetPropertyExpr:()=>ir,CheckColumnConstraintExpr:()=>yl,CheckExpr:()=>KA,CheckJsonExpr:()=>rC,CheckXmlExpr:()=>iC,ChecksumPropertyExpr:()=>gn,ChrExpr:()=>ql,CloneExpr:()=>fo,ClusterExpr:()=>Nr,ClusteredByPropertyExpr:()=>si,ClusteredColumnConstraintExpr:()=>vc,CoalesceExpr:()=>rt,CodePointsToBytesExpr:()=>Uy,CodePointsToStringExpr:()=>Fy,CollateColumnConstraintExpr:()=>Fc,CollateExpr:()=>RA,CollatePropertyExpr:()=>Br,CollationExpr:()=>nC,ColumnConstraintExpr:()=>Or,ColumnConstraintExprKind:()=>Kw,ColumnConstraintKindExpr:()=>ae,ColumnDefExpr:()=>Ie,ColumnDefExprKind:()=>Qw,ColumnExpr:()=>B,ColumnPositionExpr:()=>yo,ColumnPrefixExpr:()=>td,ColumnsExpr:()=>Hf,CombinedAggFuncExpr:()=>sw,CombinedParameterizedAggExpr:()=>rw,CommandExpr:()=>Ws,CommentColumnConstraintExpr:()=>Bc,CommentExpr:()=>Po,CommentExprKind:()=>Zw,CommitExpr:()=>gc,ComprehensionExpr:()=>bo,CompressColumnConstraintExpr:()=>oo,CompressExpr:()=>oP,ComputedColumnConstraintExpr:()=>Fi,ConcatExpr:()=>Gt,ConcatWsExpr:()=>wt,ConditionExpr:()=>ye,ConditionalInsertExpr:()=>Bo,ConnectByRootExpr:()=>Ul,ConnectExpr:()=>Mo,ConnectorExpr:()=>Ee,ConstraintExpr:()=>Lo,ContainsExpr:()=>eS,ConvertExpr:()=>vy,ConvertTimezoneExpr:()=>po,ConvertToCharsetExpr:()=>fT,CopyExpr:()=>Kc,CopyExprKind:()=>EM,CopyGrantsPropertyExpr:()=>$r,CopyParameterExpr:()=>Do,CorrExpr:()=>Qb,CosExpr:()=>_T,CoshExpr:()=>BT,CosineDistanceExpr:()=>ly,CotExpr:()=>kT,CothExpr:()=>iy,CountExpr:()=>Jl,CountIfExpr:()=>Em,CovarPopExpr:()=>tw,CovarSampExpr:()=>ew,CreateExpr:()=>qt,CreateExprKind:()=>oA,CredentialsExpr:()=>ko,CredentialsPropertyExpr:()=>va,CscExpr:()=>ny,CschExpr:()=>ay,CteExpr:()=>Tt,CubeExpr:()=>Xo,CumeDistExpr:()=>KL,CurrentAccountExpr:()=>aC,CurrentAccountNameExpr:()=>oC,CurrentAvailableRolesExpr:()=>cC,CurrentCatalogExpr:()=>Ql,CurrentClientExpr:()=>pC,CurrentDatabaseExpr:()=>uC,CurrentDateExpr:()=>$i,CurrentDatetimeExpr:()=>tS,CurrentIpAddressExpr:()=>lC,CurrentOrganizationNameExpr:()=>mC,CurrentOrganizationUserExpr:()=>IC,CurrentRegionExpr:()=>RC,CurrentRoleExpr:()=>Qf,CurrentRoleTypeExpr:()=>NC,CurrentSchemaExpr:()=>OC,CurrentSchemasExpr:()=>hC,CurrentSecondaryRolesExpr:()=>gC,CurrentSessionExpr:()=>EC,CurrentStatementExpr:()=>AC,CurrentTimeExpr:()=>Ra,CurrentTimestampExpr:()=>Na,CurrentTimestampLtzExpr:()=>sS,CurrentTimezoneExpr:()=>SC,CurrentTransactionExpr:()=>xC,CurrentUserExpr:()=>zf,CurrentVersionExpr:()=>dC,CurrentWarehouseExpr:()=>fC,DPipeExpr:()=>Mt,DataBlocksizePropertyExpr:()=>En,DataDeletionPropertyExpr:()=>An,DataTypeExpr:()=>O,DataTypeExprKind:()=>ht,DataTypeParamExpr:()=>rr,DateAddExpr:()=>yt,DateBinExpr:()=>yC,DateDiffExpr:()=>wa,DateExpr:()=>La,DateFormatColumnConstraintExpr:()=>$c,DateFromPartsExpr:()=>xS,DateFromUnixDateExpr:()=>PC,DateStrToDateExpr:()=>fS,DateSubExpr:()=>ts,DateToDateStrExpr:()=>TS,DateToDiExpr:()=>SS,DateTruncExpr:()=>bs,DatetimeAddExpr:()=>fr,DatetimeDiffExpr:()=>iS,DatetimeExpr:()=>rS,DatetimeSubExpr:()=>_i,DatetimeTruncExpr:()=>CC,DayExpr:()=>Vn,DayOfMonthExpr:()=>oS,DayOfWeekExpr:()=>nS,DayOfWeekIsoExpr:()=>aS,DayOfYearExpr:()=>cS,DaynameExpr:()=>pS,DdlExpr:()=>gr,DeclareExpr:()=>Oo,DeclareItemExpr:()=>Ro,DeclareItemExprKind:()=>Jw,DecodeCaseExpr:()=>Kf,DecodeExpr:()=>Zf,DecompressBinaryExpr:()=>cP,DecompressStringExpr:()=>pP,DecryptExpr:()=>BC,DecryptRawExpr:()=>$C,DefaultColumnConstraintExpr:()=>Gc,DefinerPropertyExpr:()=>Gr,DegreesExpr:()=>py,DeleteExpr:()=>Js,DenseRankExpr:()=>DL,DerivedTableExpr:()=>hr,DescribeExpr:()=>Vi,DescribeExprKind:()=>Ww,DetachExpr:()=>VA,DiToDateExpr:()=>mS,DictPropertyExpr:()=>mn,DictPropertyExprKind:()=>dM,DictRangeExpr:()=>On,DictSubPropertyExpr:()=>wA,DirectoryExpr:()=>Xi,DirectoryStageExpr:()=>ed,DistKeyPropertyExpr:()=>Yr,DistStylePropertyExpr:()=>Hr,DistanceExpr:()=>kA,DistinctExpr:()=>We,DistributeExpr:()=>LA,DistributedByPropertyExpr:()=>Vr,DistributedByPropertyExprKind:()=>AM,DivExpr:()=>mt,DmlExpr:()=>ls,DotExpr:()=>Se,DotProductExpr:()=>uy,DropExpr:()=>Ji,DropExprKind:()=>oN,DropPartitionExpr:()=>Rc,DuplicateKeyPropertyExpr:()=>dn,DynamicPropertyExpr:()=>ri,EltExpr:()=>qC,EmptyPropertyExpr:()=>ii,EncodeColumnConstraintExpr:()=>Yc,EncodeExpr:()=>GC,EncodePropertyExpr:()=>Ba,EncryptExpr:()=>YC,EncryptRawExpr:()=>VC,EndsWithExpr:()=>HS,EnginePropertyExpr:()=>Wr,EnviromentPropertyExpr:()=>ti,EphemeralColumnConstraintExpr:()=>xa,EqExpr:()=>me,EqualNullExpr:()=>HC,EscapeExpr:()=>ma,EuclideanDistanceExpr:()=>hy,ExceptExpr:()=>wr,ExcludeColumnConstraintExpr:()=>Vc,ExecuteAsPropertyExpr:()=>Ms,ExistsExpr:()=>Pi,ExpExpr:()=>OS,ExplodeExpr:()=>rs,ExplodeOuterExpr:()=>zl,ExplodingGenerateSeriesExpr:()=>mL,ExportExpr:()=>ZA,Expression:()=>A,ExpressionKey:()=>aA,ExtendsLeftExpr:()=>ep,ExtendsRightExpr:()=>tp,ExternalPropertyExpr:()=>Xr,ExtractExpr:()=>Gi,FUNCTION_BY_NAME:()=>Rl,FactorialExpr:()=>WC,FallbackPropertyExpr:()=>xn,FarmFingerprintExpr:()=>Iy,FeaturesAtTimeExpr:()=>rb,FetchExpr:()=>_s,FileFormatPropertyExpr:()=>ws,FilterExpr:()=>sr,FinalExpr:()=>Ka,FirstExpr:()=>PL,FirstValueExpr:()=>LL,FlattenExpr:()=>yy,Float64Expr:()=>Cy,FloorExpr:()=>Bl,ForInExpr:()=>dd,ForcePropertyExpr:()=>Ua,ForeignKeyExpr:()=>qo,FormatExpr:()=>gP,FormatJsonExpr:()=>Cc,FormatPhraseExpr:()=>Ad,FreespacePropertyExpr:()=>fn,FromBase32Expr:()=>RS,FromBase64Expr:()=>NS,FromBaseExpr:()=>Yb,FromExpr:()=>Je,FromIso8601TimestampExpr:()=>tP,FromTimeZoneExpr:()=>Ed,FuncExpr:()=>g,GapFillExpr:()=>eT,GenerateDateArrayExpr:()=>Ia,GenerateEmbeddingExpr:()=>ib,GenerateSeriesExpr:()=>Fs,GenerateTimestampArrayExpr:()=>CS,GeneratedAsIdentityColumnConstraintExpr:()=>Zn,GeneratedAsRowColumnConstraintExpr:()=>Hc,GeneratorExpr:()=>By,GetExpr:()=>lp,GetExtractExpr:()=>sP,GetbitExpr:()=>PS,GlobExpr:()=>ua,GlobalPropertyExpr:()=>zr,GrantExpr:()=>jo,GrantExprKind:()=>tM,GrantPrincipalExpr:()=>sc,GrantPrincipalExprKind:()=>sM,GrantPrivilegeExpr:()=>tc,GreatestExpr:()=>ya,GroupConcatExpr:()=>Ui,GroupExpr:()=>Xs,GroupingExpr:()=>xL,GroupingIdExpr:()=>fL,GroupingSetsExpr:()=>zo,GtExpr:()=>Be,GteExpr:()=>Me,HashAggExpr:()=>TL,HavingExpr:()=>Zt,HavingMaxExpr:()=>qs,HeapPropertyExpr:()=>jr,HeredocExpr:()=>Kn,HexDecodeStringExpr:()=>rP,HexEncodeExpr:()=>iP,HexExpr:()=>ap,HexStringExpr:()=>da,HintExpr:()=>us,HistoricalDataExpr:()=>ac,HistoricalDataExprKind:()=>rM,HllExpr:()=>SL,HostExpr:()=>KP,HourExpr:()=>bS,ILikeExpr:()=>Us,INTERVAL_DAY_TIME_RE:()=>vI,INTERVAL_STRING_RE:()=>UI,IcebergPropertyExpr:()=>Qr,IdentifierExpr:()=>U,IfExpr:()=>le,IgnoreNullsExpr:()=>aa,InExpr:()=>it,InOutColumnConstraintExpr:()=>Zc,IncludePropertyExpr:()=>$a,IndexColumnConstraintExpr:()=>Od,IndexColumnConstraintExprKind:()=>gM,IndexConstraintOptionExpr:()=>zA,IndexExpr:()=>vo,IndexParametersExpr:()=>Fo,IndexTableHintExpr:()=>nc,InheritsPropertyExpr:()=>Zr,InitcapExpr:()=>$l,InlineExpr:()=>ET,InlineLengthColumnConstraintExpr:()=>Wc,InputModelPropertyExpr:()=>Kr,InputOutputFormatExpr:()=>rc,InsertExpr:()=>kt,InstallExpr:()=>HA,Int64Expr:()=>eu,IntDivExpr:()=>ha,IntersectExpr:()=>kn,IntervalExpr:()=>Ce,IntervalOpExpr:()=>Cs,IntervalSpanExpr:()=>Ks,IntoExpr:()=>Qi,IntroducerExpr:()=>Yo,IsArrayExpr:()=>hP,IsAsciiExpr:()=>lP,IsExpr:()=>_e,IsInfExpr:()=>wS,IsNanExpr:()=>LS,IsNullValueExpr:()=>uP,IsolatedLoadingPropertyExpr:()=>Tn,JSON_PATH_PARTS:()=>lv,JarowinklerSimilarityExpr:()=>Ey,JoinExpr:()=>oe,JoinExprKind:()=>Qt,JoinHintExpr:()=>ur,JournalPropertyExpr:()=>Sn,JsonArrayAggExpr:()=>_L,JsonArrayAppendExpr:()=>yP,JsonArrayContainsExpr:()=>pu,JsonArrayExpr:()=>AP,JsonArrayInsertExpr:()=>CP,JsonBoolExpr:()=>Ry,JsonCastExpr:()=>_A,JsonColumnDefExpr:()=>bc,JsonColumnDefExprKind:()=>lM,JsonExistsExpr:()=>dP,JsonExpr:()=>yc,JsonExtractArrayExpr:()=>NP,JsonExtractExpr:()=>js,JsonExtractQuoteExpr:()=>fd,JsonExtractScalarExpr:()=>ao,JsonFormatExpr:()=>IP,JsonKeyValueExpr:()=>Pc,JsonKeysAtDepthExpr:()=>EP,JsonKeysExpr:()=>tT,JsonObjectAggExpr:()=>gT,JsonObjectExpr:()=>Gl,JsonPathExpr:()=>bi,JsonPathFilterExpr:()=>xs,JsonPathKeyExpr:()=>jt,JsonPathPartExpr:()=>dt,JsonPathRecursiveExpr:()=>cr,JsonPathRootExpr:()=>cs,JsonPathScriptExpr:()=>fs,JsonPathSelectorExpr:()=>lr,JsonPathSliceExpr:()=>pr,JsonPathSubscriptExpr:()=>Ts,JsonPathUnionExpr:()=>vs,JsonPathWildcardExpr:()=>Pt,JsonRemoveExpr:()=>SP,JsonSchemaExpr:()=>Lc,JsonSetExpr:()=>xP,JsonStripNullsExpr:()=>fP,JsonTableExpr:()=>sT,JsonTypeExpr:()=>mP,JsonValueArrayExpr:()=>TP,JsonValueExpr:()=>wc,JsonbContainsAllTopKeysExpr:()=>Un,JsonbContainsAnyTopKeysExpr:()=>qn,JsonbContainsExpr:()=>Ca,JsonbDeleteAtPathExpr:()=>vn,JsonbExistsExpr:()=>RP,JsonbExtractExpr:()=>Yl,JsonbExtractScalarExpr:()=>iT,JsonbObjectAggExpr:()=>kL,JustifyDaysExpr:()=>QT,JustifyHoursExpr:()=>ZT,JustifyIntervalExpr:()=>KT,KillExpr:()=>So,KillExprKind:()=>jw,KurtosisExpr:()=>Im,KwargExpr:()=>sp,LagExpr:()=>yL,LambdaExpr:()=>Yt,LanguagePropertyExpr:()=>nr,LastDayExpr:()=>xp,LastExpr:()=>bL,LastValueExpr:()=>gm,LateralExpr:()=>St,LaxBoolExpr:()=>MC,LaxFloat64Expr:()=>DC,LaxInt64Expr:()=>kC,LaxStringExpr:()=>_C,LeadExpr:()=>CL,LeastExpr:()=>Vl,LeftExpr:()=>kP,LengthExpr:()=>nu,LevenshteinExpr:()=>DS,LikeExpr:()=>Ut,LikePropertyExpr:()=>Rn,LimitExpr:()=>Et,LimitOptionsExpr:()=>Qo,ListExpr:()=>Yf,LiteralExpr:()=>R,LnExpr:()=>Hl,LoadDataExpr:()=>Ho,LocaltimeExpr:()=>Fl,LocaltimestampExpr:()=>Xf,LocationExpr:()=>pd,LocationPropertyExpr:()=>ar,LockExpr:()=>Aa,LockPropertyExpr:()=>Fa,LockingPropertyExpr:()=>Nn,LockingPropertyExprKind:()=>xM,LockingStatementExpr:()=>GA,LogExpr:()=>Yi,LogPropertyExpr:()=>ni,LogicalAndExpr:()=>dm,LogicalOrExpr:()=>Am,LowerExpr:()=>Fn,LowerHexExpr:()=>pp,LtExpr:()=>De,LteExpr:()=>$e,MakeIntervalExpr:()=>gS,ManhattanDistanceExpr:()=>gy,MapCatExpr:()=>FP,MapContainsKeyExpr:()=>BP,MapDeleteExpr:()=>$P,MapExpr:()=>io,MapFromEntriesExpr:()=>vP,MapInsertExpr:()=>GP,MapKeysExpr:()=>YP,MapPickExpr:()=>VP,MapSizeExpr:()=>HP,MaskingPolicyColumnConstraintExpr:()=>km,MatchAgainstExpr:()=>aT,MatchExpr:()=>Pd,MatchRecognizeExpr:()=>Ko,MatchRecognizeMeasureExpr:()=>Zo,MaterializedPropertyExpr:()=>ai,MaxExpr:()=>xm,Md5DigestExpr:()=>WP,Md5Expr:()=>kS,Md5NumberLower64Expr:()=>jP,Md5NumberUpper64Expr:()=>JP,MedianExpr:()=>qL,MergeBlockRatioPropertyExpr:()=>br,MergeExpr:()=>fa,MergeTreeTtlActionExpr:()=>Sr,MergeTreeTtlExpr:()=>Ir,MinExpr:()=>fm,MinhashCombineExpr:()=>AL,MinhashExpr:()=>EL,MinuteExpr:()=>nP,MlForecastExpr:()=>nb,MlTranslateExpr:()=>sb,ModExpr:()=>Bi,ModeExpr:()=>UL,ModelAttributeExpr:()=>Td,MonthExpr:()=>_S,MonthnameExpr:()=>XP,MonthsBetweenExpr:()=>LC,MulExpr:()=>Ns,MultitableInsertsExpr:()=>Zi,MultitableInsertsExprKind:()=>eM,NONNULL_CONSTANTS:()=>PI,NationalExpr:()=>Vo,NegExpr:()=>It,NeqExpr:()=>st,NetFuncExpr:()=>NT,NextDayExpr:()=>Kb,NextValueForExpr:()=>hT,NoPrimaryIndexPropertyExpr:()=>oi,NonClusteredColumnConstraintExpr:()=>jc,NormalExpr:()=>ZP,NormalizeExpr:()=>oT,NotExpr:()=>be,NotForReplicationColumnConstraintExpr:()=>pn,NotNullColumnConstraintExpr:()=>la,NthValueExpr:()=>wL,NtileExpr:()=>vL,NullExpr:()=>Ze,NullSafeEqExpr:()=>Ps,NullSafeNeqExpr:()=>Gs,NullifExpr:()=>Kl,NumberToStrExpr:()=>Gb,Nvl2Expr:()=>QP,ObjectAggExpr:()=>ML,ObjectIdentifierExpr:()=>Ll,ObjectInsertExpr:()=>OP,OffsetExpr:()=>Rr,OnClusterExpr:()=>Nd,OnCommitPropertyExpr:()=>Qs,OnConditionExpr:()=>Go,OnConflictExpr:()=>$o,OnPropertyExpr:()=>zs,OnUpdateColumnConstraintExpr:()=>Jc,OpclassExpr:()=>Uo,OpenJsonColumnDefExpr:()=>Mc,OpenJsonColumnDefExprKind:()=>uM,OpenJsonExpr:()=>rT,OperatorExpr:()=>_n,OrExpr:()=>ze,OrderExpr:()=>fe,OrderedExpr:()=>Ht,OutputModelPropertyExpr:()=>ei,OverflowTruncateBehaviorExpr:()=>Ic,OverlapsExpr:()=>DA,OverlayExpr:()=>cT,PERCENTILES:()=>NN,POSITION_META_KEYS:()=>uq,PadExpr:()=>Vf,ParameterExpr:()=>Cl,ParameterizedAggExpr:()=>wN,ParenExpr:()=>Oe,ParseBignumericExpr:()=>PP,ParseDatetimeExpr:()=>DP,ParseIpExpr:()=>wP,ParseJsonExpr:()=>Pa,ParseNumericExpr:()=>bP,ParseTimeExpr:()=>MP,ParseUrlExpr:()=>LP,PartitionBoundSpecExpr:()=>Ki,PartitionByListPropertyExpr:()=>yd,PartitionByRangePropertyDynamicExpr:()=>id,PartitionByRangePropertyExpr:()=>Id,PartitionByTruncateExpr:()=>yn,PartitionExpr:()=>Wo,PartitionIdExpr:()=>rd,PartitionListExpr:()=>ad,PartitionRangeExpr:()=>sd,PartitionedByBucketExpr:()=>In,PartitionedByPropertyExpr:()=>os,PartitionedOfPropertyExpr:()=>Cn,PathColumnConstraintExpr:()=>Qc,PercentRankExpr:()=>FL,PercentileContExpr:()=>FA,PercentileDiscExpr:()=>DN,PeriodForSystemTimeConstraintExpr:()=>qc,PiExpr:()=>qS,PivotAliasExpr:()=>MA,PivotAnyExpr:()=>Cr,PivotExpr:()=>yr,PlaceholderExpr:()=>Ds,PlaceholderExprKind:()=>mM,PosexplodeExpr:()=>Ma,PosexplodeOuterExpr:()=>bd,PositionalColumnExpr:()=>up,PowExpr:()=>au,PragmaExpr:()=>mo,PreWhereExpr:()=>uc,PredicateExpr:()=>Ne,PredictExpr:()=>tb,PreviousDayExpr:()=>wC,PrimaryKeyColumnConstraintExpr:()=>Xc,PrimaryKeyExpr:()=>zi,PriorExpr:()=>_o,ProjectionDefExpr:()=>JA,ProjectionPolicyColumnConstraintExpr:()=>vA,PropertiesExpr:()=>Ke,PropertiesLocation:()=>dI,PropertyEqExpr:()=>ct,PropertyExpr:()=>L,PseudoTypeExpr:()=>bl,PseudocolumnExpr:()=>lA,PutExpr:()=>Da,QUERY_MODIFIERS:()=>HU,QualifyExpr:()=>Os,QuantileExpr:()=>$A,QuarterExpr:()=>US,QueryBandExpr:()=>WA,QueryExpr:()=>z,QueryOptionExpr:()=>ld,QueryTransformExpr:()=>od,RadiansExpr:()=>vS,RandExpr:()=>fl,RandnExpr:()=>Df,RandstrExpr:()=>cb,RangeBucketExpr:()=>lb,RangeNExpr:()=>pb,RankExpr:()=>$L,RawStringExpr:()=>pa,ReadCsvExpr:()=>ub,ReadParquetExpr:()=>hb,RecursiveWithSearchExpr:()=>Io,RecursiveWithSearchExprKind:()=>zw,ReduceExpr:()=>gb,ReferenceExpr:()=>ic,RefreshExpr:()=>Ao,RefreshExprKind:()=>Hw,RefreshTriggerPropertyExpr:()=>Ap,RefreshTriggerPropertyExprKind:()=>fM,RegDomainExpr:()=>eb,RegexpCountExpr:()=>Tb,RegexpExtractAllExpr:()=>Eb,RegexpExtractExpr:()=>Pm,RegexpFullMatchExpr:()=>db,RegexpILikeExpr:()=>pT,RegexpInstrExpr:()=>xb,RegexpLikeExpr:()=>op,RegexpReplaceExpr:()=>Ab,RegexpSplitExpr:()=>fb,RegrAvgxExpr:()=>HL,RegrAvgyExpr:()=>VL,RegrCountExpr:()=>WL,RegrInterceptExpr:()=>jL,RegrR2Expr:()=>JL,RegrSlopeExpr:()=>ZL,RegrSxxExpr:()=>XL,RegrSxyExpr:()=>zL,RegrSyyExpr:()=>QL,RegrValxExpr:()=>GL,RegrValyExpr:()=>YL,RemoteWithConnectionModelPropertyExpr:()=>pi,RenameColumnExpr:()=>ga,RepeatExpr:()=>Sb,ReplaceExpr:()=>bm,ReplacePartitionExpr:()=>gd,RespectNullsExpr:()=>oa,ReturnExpr:()=>en,ReturningExpr:()=>Ea,ReturnsPropertyExpr:()=>or,ReverseExpr:()=>qP,RevokeExpr:()=>Jo,RightExpr:()=>_P,RollbackExpr:()=>Ec,RollupExpr:()=>ra,RollupIndexExpr:()=>nd,RollupPropertyExpr:()=>Ep,RoundExpr:()=>FS,RowFormatDelimitedPropertyExpr:()=>Pn,RowFormatPropertyExpr:()=>ui,RowFormatSerdePropertyExpr:()=>bn,RowNumberExpr:()=>AT,RtrimmedLengthExpr:()=>UP,SAFE_IDENTIFIER_RE:()=>wm,SQLGLOT_ANONYMOUS:()=>qI,SQLGLOT_META:()=>pq,SafeAddExpr:()=>Ib,SafeConvertBytesToStringExpr:()=>bb,SafeDivideExpr:()=>BS,SafeFuncExpr:()=>xT,SafeMultiplyExpr:()=>yb,SafeNegateExpr:()=>Cb,SafeSubtractExpr:()=>Pb,SamplePropertyExpr:()=>hi,SchemaCommentPropertyExpr:()=>Ei,SchemaExpr:()=>At,ScopeResolutionExpr:()=>ca,SearchExpr:()=>vb,SearchIpExpr:()=>Fb,SecExpr:()=>oy,SechExpr:()=>cy,SecondExpr:()=>aP,SecurePropertyExpr:()=>Ti,SecurityPropertyExpr:()=>gi,SelectExpr:()=>ee,SelectExprKind:()=>TM,SemanticViewExpr:()=>cd,SemicolonExpr:()=>_c,Seq1Expr:()=>mb,Seq2Expr:()=>Ob,Seq4Expr:()=>Rb,Seq8Expr:()=>Nb,SequencePropertiesExpr:()=>Hs,SerdePropertiesExpr:()=>Ln,SessionParameterExpr:()=>Pl,SessionParameterExprKind:()=>SM,SessionUserExpr:()=>ST,SetConfigPropertyExpr:()=>ka,SetExpr:()=>Hi,SetItemExpr:()=>vi,SetItemExprKind:()=>Xw,SetOperationExpr:()=>Xe,SetOperationExprKind:()=>cN,SetPropertyExpr:()=>Zs,SettingsPropertyExpr:()=>di,Sha1DigestExpr:()=>Lb,Sha2DigestExpr:()=>wb,Sha2Expr:()=>GS,ShaExpr:()=>$S,SharingPropertyExpr:()=>Ai,ShowExpr:()=>jA,SignExpr:()=>YS,SimilarToExpr:()=>rp,SinExpr:()=>qT,SinhExpr:()=>UT,SkewnessExpr:()=>ym,SliceExpr:()=>Tr,SortArrayExpr:()=>VS,SortExpr:()=>co,SortKeyPropertyExpr:()=>xi,SoundexExpr:()=>Mb,SoundexP123Expr:()=>Db,SpaceExpr:()=>WS,SplitExpr:()=>kb,SplitPartExpr:()=>_b,SqlReadWritePropertyExpr:()=>Es,SqlSecurityPropertyExpr:()=>fi,SqrtExpr:()=>Wl,StDistanceExpr:()=>Qy,StPointExpr:()=>zy,StabilityPropertyExpr:()=>As,StandardHashExpr:()=>Ub,StarExpr:()=>xe,StarMapExpr:()=>nT,StartsWithExpr:()=>Tl,StddevExpr:()=>Sm,StddevPopExpr:()=>mm,StddevSampExpr:()=>Om,StorageHandlerPropertyExpr:()=>wn,StrPositionExpr:()=>mr,StrToDateExpr:()=>ba,StrToMapExpr:()=>$b,StrToTimeExpr:()=>tr,StrToUnixExpr:()=>Bb,StreamExpr:()=>on,StreamingTablePropertyExpr:()=>ci,StrictPropertyExpr:()=>li,StringExpr:()=>zT,StringToArrayExpr:()=>Zy,StructExpr:()=>ks,StructExtractExpr:()=>Vb,StuffExpr:()=>Hb,SubExpr:()=>ke,SubqueryExpr:()=>Te,SubqueryPredicateExpr:()=>$s,SubstringExpr:()=>er,SubstringIndexExpr:()=>qb,SumExpr:()=>Tm,SummarizeExpr:()=>To,SwapTableExpr:()=>Wi,SystimestampExpr:()=>TC,TABLE_PARTS:()=>nw,TIMESTAMP_PARTS:()=>WU,TableAliasExpr:()=>ie,TableColumnExpr:()=>Mi,TableExpr:()=>V,TableFromRowsExpr:()=>zn,TableSampleExpr:()=>cc,TagExpr:()=>Dm,TagsExpr:()=>_a,TanExpr:()=>vT,TanhExpr:()=>FT,TemporaryPropertyExpr:()=>ds,TimeAddExpr:()=>iu,TimeDiffExpr:()=>dS,TimeExpr:()=>jS,TimeFromPartsExpr:()=>FC,TimeSliceExpr:()=>UC,TimeSliceExprKind:()=>OM,TimeStrToDateExpr:()=>XS,TimeStrToTimeExpr:()=>ou,TimeStrToUnixExpr:()=>jb,TimeSubExpr:()=>AS,TimeToStrExpr:()=>Gn,TimeToTimeStrExpr:()=>JS,TimeToUnixExpr:()=>Wb,TimeTruncExpr:()=>vC,TimeUnitExpr:()=>K,TimestampAddExpr:()=>ru,TimestampDiffExpr:()=>Zl,TimestampExpr:()=>Xl,TimestampFromPartsExpr:()=>bN,TimestampLtzFromPartsExpr:()=>am,TimestampSubExpr:()=>ES,TimestampTruncExpr:()=>ro,TimestampTzFromPartsExpr:()=>om,TitleColumnConstraintExpr:()=>zc,ToArrayExpr:()=>Ly,ToBase32Expr:()=>IS,ToBase64Expr:()=>yS,ToBinaryExpr:()=>jC,ToBooleanExpr:()=>wy,ToCharExpr:()=>Cm,ToCodePointsExpr:()=>My,ToDaysExpr:()=>bC,ToDecfloatExpr:()=>ky,ToDoubleExpr:()=>VT,ToFileExpr:()=>qy,ToMapExpr:()=>tu,ToNumberExpr:()=>Dy,ToTablePropertyExpr:()=>Jr,TransactionExpr:()=>hc,TransformExpr:()=>Py,TransformModelPropertyExpr:()=>Si,TransientPropertyExpr:()=>mi,TranslateCharactersExpr:()=>xd,TranslateExpr:()=>GT,TrimExpr:()=>cp,TrimPosition:()=>xI,TruncExpr:()=>Lm,TruncateTableExpr:()=>xo,TryBase64DecodeBinaryExpr:()=>QC,TryBase64DecodeStringExpr:()=>ZC,TryCastExpr:()=>_t,TryExpr:()=>sC,TryHexDecodeBinaryExpr:()=>KC,TryHexDecodeStringExpr:()=>eP,TryToDecfloatExpr:()=>_y,TsOrDiToDiExpr:()=>QS,TsOrDsAddExpr:()=>cu,TsOrDsDiffExpr:()=>Jb,TsOrDsToDateExpr:()=>Is,TsOrDsToDateStrExpr:()=>zS,TsOrDsToDatetimeExpr:()=>IT,TsOrDsToTimeExpr:()=>yT,TsOrDsToTimestampExpr:()=>CT,TupleExpr:()=>Ge,TypeExpr:()=>ud,TypeofExpr:()=>sy,UNWRAPPED_QUERIES:()=>Er,UdtfExpr:()=>Nt,UnaryExpr:()=>hs,UncacheExpr:()=>Eo,UnhexExpr:()=>Xb,UnicodeExpr:()=>ZS,UnicodeStringExpr:()=>Il,UniformExpr:()=>zb,UnionExpr:()=>Lr,UniqueColumnConstraintExpr:()=>ln,UniqueKeyPropertyExpr:()=>Cd,UnixDateExpr:()=>KS,UnixMicrosExpr:()=>im,UnixMillisExpr:()=>nm,UnixSecondsExpr:()=>rm,UnixToStrExpr:()=>em,UnixToTimeExpr:()=>tm,UnixToTimeStrExpr:()=>sm,UnloggedPropertyExpr:()=>Oi,UnnestExpr:()=>ge,UnpivotColumnsExpr:()=>pc,UpdateExpr:()=>Vt,UpperExpr:()=>jl,UppercaseColumnConstraintExpr:()=>un,UseExpr:()=>kc,UseExprKind:()=>hM,UserDefinedFunctionExpr:()=>No,UsingDataExpr:()=>an,UsingTemplatePropertyExpr:()=>qa,UtcDateExpr:()=>mT,UtcTimeExpr:()=>OT,UtcTimestampExpr:()=>RT,UuidExpr:()=>NA,ValuesExpr:()=>Ls,VarExpr:()=>qe,VarMapExpr:()=>Ys,VariadicExpr:()=>hp,VarianceExpr:()=>Rm,VariancePopExpr:()=>Nm,VectorSearchExpr:()=>ab,VersionExpr:()=>oc,ViewAttributePropertyExpr:()=>Ri,VolatilePropertyExpr:()=>Ni,WatermarkColumnConstraintExpr:()=>QA,WeekExpr:()=>BA,WeekOfYearExpr:()=>lS,WeekStartExpr:()=>Sd,WhenExpr:()=>_r,WhensExpr:()=>cn,WhereExpr:()=>at,WidthBucketExpr:()=>Zb,WindowExpr:()=>we,WindowSpecExpr:()=>lc,WindowSpecExprKind:()=>iM,WithDataPropertyExpr:()=>Mn,WithExpr:()=>tt,WithFillExpr:()=>ec,WithJournalTablePropertyExpr:()=>Ii,WithOperatorExpr:()=>ji,WithProcedureOptionsExpr:()=>Ci,WithSchemaBindingPropertyExpr:()=>yi,WithSystemVersioningPropertyExpr:()=>Dn,WithTableHintExpr:()=>tn,WithinGroupExpr:()=>$t,XmlElementExpr:()=>lT,XmlGetExpr:()=>eL,XmlKeyValueOptionExpr:()=>md,XmlNamespaceExpr:()=>Dc,XmlTableExpr:()=>uT,XorExpr:()=>qi,YearExpr:()=>cm,YearOfWeekExpr:()=>uS,YearOfWeekIsoExpr:()=>hS,ZeroFillColumnConstraintExpr:()=>gp,ZipfExpr:()=>tL,alias:()=>Ye,and:()=>Fe,array:()=>CA,case_:()=>WI,cast:()=>j,column:()=>ho,columnTableNames:()=>RN,combine:()=>qA,condition:()=>Aq,convert:()=>Ot,delete_:()=>ZU,except:()=>Eq,expand:()=>pv,false_:()=>gt,findTables:()=>tv,from:()=>XU,func:()=>jI,insert:()=>QU,intersect:()=>gq,isType:()=>Sl,literal:()=>ml,maybeCopy:()=>Ve,maybeParse:()=>H,merge:()=>ev,normalizeTableName:()=>KR,not:()=>xr,null_:()=>pe,or:()=>Kt,paren:()=>ki,parseIdentifier:()=>Bf,renameColumn:()=>iv,renameTable:()=>rv,replaceChildren:()=>hN,replacePlaceholders:()=>cv,replaceTables:()=>ov,replaceTree:()=>av,select:()=>pt,subquery:()=>HI,table:()=>hq,tableName:()=>nv,table_:()=>jU,toColumn:()=>iw,toIdentifier:()=>Z,toInterval:()=>JU,toTable:()=>Nf,true_:()=>Qe,tuple:()=>sv,union:()=>UA,update:()=>KU,values:()=>zU,var_:()=>Q,wrap:()=>Yn,xor:()=>CI});import{DateTime as cq}from"luxon";var aA=(p=>(p.ABS="abs",p.ACOS="acos",p.ACOSH="acosh",p.ADD="add",p.ADD_CONSTRAINT="addConstraint",p.ADD_MONTHS="addMonths",p.ADD_PARTITION="addPartition",p.ADJACENT="adjacent",p.AGG_FUNC="aggFunc",p.AI_AGG="aiAgg",p.AI_CLASSIFY="aiClassify",p.AI_SUMMARIZE_AGG="aiSummarizeAgg",p.ALGORITHM_PROPERTY="algorithmProperty",p.ALIAS="alias",p.ALIASES="aliases",p.ALL="all",p.ALLOWED_VALUES_PROPERTY="allowedValuesProperty",p.ALTER="alter",p.ALTER_COLUMN="alterColumn",p.ALTER_DIST_STYLE="alterDistStyle",p.ALTER_INDEX="alterIndex",p.ALTER_RENAME="alterRename",p.ALTER_SESSION="alterSession",p.ALTER_SET="alterSet",p.ALTER_SORT_KEY="alterSortKey",p.ANALYZE="analyze",p.ANALYZE_COLUMNS="analyzeColumns",p.ANALYZE_DELETE="analyzeDelete",p.ANALYZE_HISTOGRAM="analyzeHistogram",p.ANALYZE_LIST_CHAINED_ROWS="analyzeListChainedRows",p.ANALYZE_SAMPLE="analyzeSample",p.ANALYZE_STATISTICS="analyzeStatistics",p.ANALYZE_VALIDATE="analyzeValidate",p.ANALYZE_WITH="analyzeWith",p.AND="and",p.ANONYMOUS="anonymous",p.ANONYMOUS_AGG_FUNC="anonymousAggFunc",p.ANY="any",p.ANY_VALUE="anyValue",p.APPLY="apply",p.APPROXIMATE_SIMILARITY="approximateSimilarity",p.APPROX_DISTINCT="approxDistinct",p.APPROX_PERCENTILE_ACCUMULATE="approxPercentileAccumulate",p.APPROX_PERCENTILE_COMBINE="approxPercentileCombine",p.APPROX_PERCENTILE_ESTIMATE="approxPercentileEstimate",p.APPROX_QUANTILE="approxQuantile",p.APPROX_QUANTILES="approxQuantiles",p.APPROX_TOP_K="approxTopK",p.APPROX_TOP_K_ACCUMULATE="approxTopKAccumulate",p.APPROX_TOP_K_COMBINE="approxTopKCombine",p.APPROX_TOP_K_ESTIMATE="approxTopKEstimate",p.APPROX_TOP_SUM="approxTopSum",p.ARG_MAX="argMax",p.ARG_MIN="argMin",p.ARRAY="array",p.ARRAYS_ZIP="arraysZip",p.ARRAY_AGG="arrayAgg",p.ARRAY_ALL="arrayAll",p.ARRAY_ANY="arrayAny",p.ARRAY_APPEND="arrayAppend",p.ARRAY_COMPACT="arrayCompact",p.ARRAY_CONCAT="arrayConcat",p.ARRAY_CONCAT_AGG="arrayConcatAgg",p.ARRAY_CONSTRUCT_COMPACT="arrayConstructCompact",p.ARRAY_CONTAINS="arrayContains",p.ARRAY_CONTAINS_ALL="arrayContainsAll",p.ARRAY_FILTER="arrayFilter",p.ARRAY_FIRST="arrayFirst",p.ARRAY_INSERT="arrayInsert",p.ARRAY_INTERSECT="arrayIntersect",p.ARRAY_LAST="arrayLast",p.ARRAY_OVERLAPS="arrayOverlaps",p.ARRAY_PREPEND="arrayPrepend",p.ARRAY_REMOVE="arrayRemove",p.ARRAY_REMOVE_AT="arrayRemoveAt",p.ARRAY_REVERSE="arrayReverse",p.ARRAY_SIZE="arraySize",p.ARRAY_SLICE="arraySlice",p.ARRAY_SORT="arraySort",p.ARRAY_SUM="arraySum",p.ARRAY_TO_STRING="arrayToString",p.ARRAY_UNION_AGG="arrayUnionAgg",p.ARRAY_UNIQUE_AGG="arrayUniqueAgg",p.ASCII="ascii",p.ASIN="asin",p.ASINH="asinh",p.ATAN="atan",p.ATAN2="atan2",p.ATANH="atanh",p.ATTACH="attach",p.ATTACH_OPTION="attachOption",p.AT_INDEX="atIndex",p.AT_TIME_ZONE="atTimeZone",p.AUTO_INCREMENT_COLUMN_CONSTRAINT="autoIncrementColumnConstraint",p.AUTO_INCREMENT_PROPERTY="autoIncrementProperty",p.AUTO_REFRESH_PROPERTY="autoRefreshProperty",p.AVG="avg",p.BACKUP_PROPERTY="backupProperty",p.BASE64_DECODE_BINARY="base64DecodeBinary",p.BASE64_DECODE_STRING="base64DecodeString",p.BASE64_ENCODE="base64Encode",p.BETWEEN="between",p.BINARY="binary",p.BITMAP_BIT_POSITION="bitmapBitPosition",p.BITMAP_BUCKET_NUMBER="bitmapBucketNumber",p.BITMAP_CONSTRUCT_AGG="bitmapConstructAgg",p.BITMAP_COUNT="bitmapCount",p.BITMAP_OR_AGG="bitmapOrAgg",p.BITWISE_AND="bitwiseAnd",p.BITWISE_AND_AGG="bitwiseAndAgg",p.BITWISE_COUNT="bitwiseCount",p.BITWISE_LEFT_SHIFT="bitwiseLeftShift",p.BITWISE_NOT="bitwiseNot",p.BITWISE_OR="bitwiseOr",p.BITWISE_OR_AGG="bitwiseOrAgg",p.BITWISE_RIGHT_SHIFT="bitwiseRightShift",p.BITWISE_XOR="bitwiseXor",p.BITWISE_XOR_AGG="bitwiseXorAgg",p.BIT_LENGTH="bitLength",p.BIT_STRING="bitString",p.BLOCK_COMPRESSION_PROPERTY="blockCompressionProperty",p.BOOLAND="booland",p.BOOLEAN="boolean",p.BOOLNOT="boolnot",p.BOOLOR="boolor",p.BOOLXOR_AGG="boolxorAgg",p.BRACKET="bracket",p.BUILD_PROPERTY="buildProperty",p.BYTE_LENGTH="byteLength",p.BYTE_STRING="byteString",p.CACHE="cache",p.CASE="case",p.CASE_SPECIFIC_COLUMN_CONSTRAINT="caseSpecificColumnConstraint",p.CAST="cast",p.CAST_TO_STR_TYPE="castToStrType",p.CBRT="cbrt",p.CEIL="ceil",p.CHANGES="changes",p.CHARACTER_SET="characterSet",p.CHARACTER_SET_COLUMN_CONSTRAINT="characterSetColumnConstraint",p.CHARACTER_SET_PROPERTY="characterSetProperty",p.CHECK="check",p.CHECKSUM_PROPERTY="checksumProperty",p.CHECK_COLUMN_CONSTRAINT="checkColumnConstraint",p.CHECK_JSON="checkJson",p.CHECK_XML="checkXml",p.CHR="chr",p.CLONE="clone",p.CLUSTER="cluster",p.CLUSTERED_BY_PROPERTY="clusteredByProperty",p.CLUSTERED_COLUMN_CONSTRAINT="clusteredColumnConstraint",p.COALESCE="coalesce",p.CODE_POINTS_TO_BYTES="codePointsToBytes",p.CODE_POINTS_TO_STRING="codePointsToString",p.COLLATE="collate",p.COLLATE_COLUMN_CONSTRAINT="collateColumnConstraint",p.COLLATE_PROPERTY="collateProperty",p.COLLATION="collation",p.COLUMN="column",p.COLUMNS="columns",p.COLUMN_CONSTRAINT="columnConstraint",p.COLUMN_CONSTRAINT_KIND="columnConstraintKind",p.COLUMN_DEF="columnDef",p.COLUMN_POSITION="columnPosition",p.COLUMN_PREFIX="columnPrefix",p.COMBINED_AGG_FUNC="combinedAggFunc",p.COMBINED_PARAMETERIZED_AGG="combinedParameterizedAgg",p.COMMAND="command",p.COMMENT="comment",p.COMMENT_COLUMN_CONSTRAINT="commentColumnConstraint",p.COMMIT="commit",p.COMPREHENSION="comprehension",p.COMPRESS="compress",p.COMPRESS_COLUMN_CONSTRAINT="compressColumnConstraint",p.COMPUTED_COLUMN_CONSTRAINT="computedColumnConstraint",p.CONCAT="concat",p.CONCAT_WS="concatWs",p.CONDITION="condition",p.CONDITIONAL_INSERT="conditionalInsert",p.CONNECT="connect",p.CONNECTOR="connector",p.CONNECT_BY_ROOT="connectByRoot",p.CONSTRAINT="constraint",p.CONTAINS="contains",p.CONVERT="convert",p.CONVERT_TIMEZONE="convertTimezone",p.CONVERT_TO_CHARSET="convertToCharset",p.COPY="copy",p.COPY_GRANTS_PROPERTY="copyGrantsProperty",p.COPY_PARAMETER="copyParameter",p.CORR="corr",p.COS="cos",p.COSH="cosh",p.COSINE_DISTANCE="cosineDistance",p.COT="cot",p.COTH="coth",p.COUNT="count",p.COUNT_IF="countIf",p.COVAR_POP="covarPop",p.COVAR_SAMP="covarSamp",p.CREATE="create",p.CREDENTIALS="credentials",p.CREDENTIALS_PROPERTY="credentialsProperty",p.CSC="csc",p.CSCH="csch",p.CTE="cte",p.CUBE="cube",p.CUME_DIST="cumeDist",p.CURRENT_ACCOUNT="currentAccount",p.CURRENT_ACCOUNT_NAME="currentAccountName",p.CURRENT_AVAILABLE_ROLES="currentAvailableRoles",p.CURRENT_CATALOG="currentCatalog",p.CURRENT_CLIENT="currentClient",p.CURRENT_DATABASE="currentDatabase",p.CURRENT_DATE="currentDate",p.CURRENT_DATETIME="currentDatetime",p.CURRENT_IP_ADDRESS="currentIpAddress",p.CURRENT_ORGANIZATION_NAME="currentOrganizationName",p.CURRENT_ORGANIZATION_USER="currentOrganizationUser",p.CURRENT_REGION="currentRegion",p.CURRENT_ROLE="currentRole",p.CURRENT_ROLE_TYPE="currentRoleType",p.CURRENT_SCHEMA="currentSchema",p.CURRENT_SCHEMAS="currentSchemas",p.CURRENT_SECONDARY_ROLES="currentSecondaryRoles",p.CURRENT_SESSION="currentSession",p.CURRENT_STATEMENT="currentStatement",p.CURRENT_TIME="currentTime",p.CURRENT_TIMESTAMP="currentTimestamp",p.CURRENT_TIMESTAMP_LTZ="currentTimestampLtz",p.CURRENT_TIMEZONE="currentTimezone",p.CURRENT_TRANSACTION="currentTransaction",p.CURRENT_USER="currentUser",p.CURRENT_VERSION="currentVersion",p.CURRENT_WAREHOUSE="currentWarehouse",p.DATA_BLOCKSIZE_PROPERTY="dataBlocksizeProperty",p.DATA_DELETION_PROPERTY="dataDeletionProperty",p.DATA_TYPE="dataType",p.DATA_TYPE_PARAM="dataTypeParam",p.DATE="date",p.DATETIME="datetime",p.DATETIME_ADD="datetimeAdd",p.DATETIME_DIFF="datetimeDiff",p.DATETIME_SUB="datetimeSub",p.DATETIME_TRUNC="datetimeTrunc",p.DATE_ADD="dateAdd",p.DATE_BIN="dateBin",p.DATE_DIFF="dateDiff",p.DATE_FORMAT_COLUMN_CONSTRAINT="dateFormatColumnConstraint",p.DATE_FROM_PARTS="dateFromParts",p.DATE_FROM_UNIX_DATE="dateFromUnixDate",p.DATE_STR_TO_DATE="dateStrToDate",p.DATE_SUB="dateSub",p.DATE_TO_DATE_STR="dateToDateStr",p.DATE_TO_DI="dateToDi",p.DATE_TRUNC="dateTrunc",p.DAY="day",p.DAYNAME="dayname",p.DAY_OF_MONTH="dayOfMonth",p.DAY_OF_WEEK="dayOfWeek",p.DAY_OF_WEEK_ISO="dayOfWeekIso",p.DAY_OF_YEAR="dayOfYear",p.DDL="ddl",p.DECLARE="declare",p.DECLARE_ITEM="declareItem",p.DECODE="decode",p.DECODE_CASE="decodeCase",p.DECOMPRESS_BINARY="decompressBinary",p.DECOMPRESS_STRING="decompressString",p.DECRYPT="decrypt",p.DECRYPT_RAW="decryptRaw",p.DEFAULT_COLUMN_CONSTRAINT="defaultColumnConstraint",p.DEFINER_PROPERTY="definerProperty",p.DEGREES="degrees",p.DELETE="delete",p.DENSE_RANK="denseRank",p.DERIVED_TABLE="derivedTable",p.DESCRIBE="describe",p.DETACH="detach",p.DICT_PROPERTY="dictProperty",p.DICT_RANGE="dictRange",p.DICT_SUB_PROPERTY="dictSubProperty",p.DIRECTORY="directory",p.DIRECTORY_STAGE="directoryStage",p.DISTANCE="distance",p.DISTINCT="distinct",p.DISTRIBUTE="distribute",p.DISTRIBUTED_BY_PROPERTY="distributedByProperty",p.DIST_KEY_PROPERTY="distKeyProperty",p.DIST_STYLE_PROPERTY="distStyleProperty",p.DIV="div",p.DI_TO_DATE="diToDate",p.DML="dml",p.DOT="dot",p.DOT_PRODUCT="dotProduct",p.DROP="drop",p.DROP_PARTITION="dropPartition",p.DUPLICATE_KEY_PROPERTY="duplicateKeyProperty",p.DYNAMIC_PROPERTY="dynamicProperty",p.D_PIPE="dPipe",p.ELT="elt",p.EMPTY_PROPERTY="emptyProperty",p.ENCODE="encode",p.ENCODE_COLUMN_CONSTRAINT="encodeColumnConstraint",p.ENCODE_PROPERTY="encodeProperty",p.ENCRYPT="encrypt",p.ENCRYPT_RAW="encryptRaw",p.ENDS_WITH="endsWith",p.ENGINE_PROPERTY="engineProperty",p.ENVIROMENT_PROPERTY="enviromentProperty",p.EPHEMERAL_COLUMN_CONSTRAINT="ephemeralColumnConstraint",p.EQ="eq",p.EqUAL_NULL="equalNull",p.ESCAPE="escape",p.EUCLIDEAN_DISTANCE="euclideanDistance",p.EXCEPT="except",p.EXCLUDE_COLUMN_CONSTRAINT="excludeColumnConstraint",p.EXECUTE_AS_PROPERTY="executeAsProperty",p.EXISTS="exists",p.EXP="exp",p.EXPLODE="explode",p.EXPLODE_OUTER="explodeOuter",p.EXPLODING_GENERATE_SERIES="explodingGenerateSeries",p.EXPORT="export",p.EXPRESSION="expression",p.EXTENDS_LEFT="extendsLeft",p.EXTENDS_RIGHT="extendsRight",p.EXTERNAL_PROPERTY="externalProperty",p.EXTRACT="extract",p.FACTORIAL="factorial",p.FALLBACK_PROPERTY="fallbackProperty",p.FARM_FINGERPRINT="farmFingerprint",p.FEATURES_AT_TIME="featuresAtTime",p.FETCH="fetch",p.FILE_FORMAT_PROPERTY="fileFormatProperty",p.FILTER="filter",p.FINAL="final",p.FIRST="first",p.FIRST_VALUE="firstValue",p.FLATTEN="flatten",p.FLOAT64="float64",p.FLOOR="floor",p.FORCE_PROPERTY="forceProperty",p.FOREIGN_KEY="foreignKey",p.FORMAT="format",p.FORMAT_JSON="formatJson",p.FORMAT_PHRASE="formatPhrase",p.FOR_IN="forIn",p.FREESPACE_PROPERTY="freespaceProperty",p.FROM="from",p.FROM_BASE="fromBase",p.FROM_BASE32="fromBase32",p.FROM_BASE64="fromBase64",p.FROM_ISO8601_TIMESTAMP="fromIso8601Timestamp",p.FROM_TIME_ZONE="fromTimeZone",p.FUNC="func",p.GAP_FILL="gapFill",p.GENERATED_AS_IDENTITY_COLUMN_CONSTRAINT="generatedAsIdentityColumnConstraint",p.GENERATED_AS_ROW_COLUMN_CONSTRAINT="generatedAsRowColumnConstraint",p.GENERATE_DATE_ARRAY="generateDateArray",p.GENERATE_EMBEDDING="generateEmbedding",p.GENERATE_SERIES="generateSeries",p.GENERATE_TIMESTAMP_ARRAY="generateTimestampArray",p.GENERATOR="generator",p.GET="get",p.GETBIT="getbit",p.GET_EXTRACT="getExtract",p.GLOB="glob",p.GLOBAL_PROPERTY="globalProperty",p.GRANT="grant",p.GRANT_PRINCIPAL="grantPrincipal",p.GRANT_PRIVILEGE="grantPrivilege",p.GREATEST="greatest",p.GROUP="group",p.GROUPING="grouping",p.GROUPING_ID="groupingId",p.GROUPING_SETS="groupingSets",p.GROUP_CONCAT="groupConcat",p.GT="gt",p.GTE="gte",p.HASH_AGG="hashAgg",p.HAVING="having",p.HAVING_MAX="havingMax",p.HEAP_PROPERTY="heapProperty",p.HEREDOC="heredoc",p.HEX="hex",p.HEX_DECODE_STRING="hexDecodeString",p.HEX_ENCODE="hexEncode",p.HEX_STRING="hexString",p.HINT="hint",p.HISTORICAL_DATA="historicalData",p.HLL="hll",p.HOST="host",p.HOUR="hour",p.ICEBERG_PROPERTY="icebergProperty",p.IDENTIFIER="identifier",p.IF="if",p.IGNORE_NULLS="ignoreNulls",p.IN="in",p.INCLUDE_PROPERTY="includeProperty",p.INDEX="index",p.INDEX_COLUMN_CONSTRAINT="indexColumnConstraint",p.INDEX_CONSTRAINT_OPTION="indexConstraintOption",p.INDEX_PARAMETERS="indexParameters",p.INDEX_TABLE_HINT="indexTableHint",p.INHERITS_PROPERTY="inheritsProperty",p.INITCAP="initcap",p.INLINE="inline",p.INLINE_LENGTH_COLUMN_CONSTRAINT="inlineLengthColumnConstraint",p.INPUT_MODEL_PROPERTY="inputModelProperty",p.INPUT_OUTPUT_FORMAT="inputOutputFormat",p.INSERT="insert",p.INSTALL="install",p.INT64="int64",p.INTERSECT="intersect",p.INTERVAL="interval",p.INTERVAL_OP="intervalOp",p.INTERVAL_SPAN="intervalSpan",p.INTO="into",p.INTRODUCER="introducer",p.INT_DIV="intDiv",p.IN_OUT_COLUMN_CONSTRAINT="inOutColumnConstraint",p.IS="is",p.ISOLATED_LOADING_PROPERTY="isolatedLoadingProperty",p.IS_ARRAY="isArray",p.IS_ASCII="isAscii",p.IS_INF="isInf",p.IS_NAN="isNan",p.IS_NULL_VALUE="isNullValue",p.ILIKE="iLike",p.JAROWINKLER_SIMILARITY="jarowinklerSimilarity",p.JOIN="join",p.JOIN_HINT="joinHint",p.JOURNAL_PROPERTY="journalProperty",p.JSON="json",p.JSON_ARRAY="jsonArray",p.JSON_ARRAY_AGG="jsonArrayAgg",p.JSON_ARRAY_APPEND="jsonArrayAppend",p.JSON_ARRAY_CONTAINS="jsonArrayContains",p.JSON_ARRAY_INSERT="jsonArrayInsert",p.JSON_BOOL="jsonBool",p.JSONB_CONTAINS="jsonbContains",p.JSONB_CONTAINS_ALL_TOP_KEYS="jsonbContainsAllTopKeys",p.JSONB_CONTAINS_ANY_TOP_KEYS="jsonbContainsAnyTopKeys",p.JSONB_DELETE_AT_PATH="jsonbDeleteAtPath",p.JSONB_EXISTS="jsonbExists",p.JSONB_EXTRACT="jsonbExtract",p.JSONB_EXTRACT_SCALAR="jsonbExtractScalar",p.JSONB_OBJECT_AGG="jsonbObjectAgg",p.JSON_CAST="jsonCast",p.JSON_COLUMN_DEF="jsonColumnDef",p.JSON_EXISTS="jsonExists",p.JSON_EXTRACT="jsonExtract",p.JSON_EXTRACT_ARRAY="jsonExtractArray",p.JSON_EXTRACT_QUOTE="jsonExtractQuote",p.JSON_EXTRACT_SCALAR="jsonExtractScalar",p.JSON_FORMAT="jsonFormat",p.JSON_KEYS="jsonKeys",p.JSON_KEYS_AT_DEPTH="jsonKeysAtDepth",p.JSON_KEY_VALUE="jsonKeyValue",p.JSON_OBJECT="jsonObject",p.JSON_OBJECT_AGG="jsonObjectAgg",p.JSON_PATH="jsonPath",p.JSON_PATH_FILTER="jsonPathFilter",p.JSON_PATH_KEY="jsonPathKey",p.JSON_PATH_PART="jsonPathPart",p.JSON_PATH_RECURSIVE="jsonPathRecursive",p.JSON_PATH_ROOT="jsonPathRoot",p.JSON_PATH_SCRIPT="jsonPathScript",p.JSON_PATH_SELECTOR="jsonPathSelector",p.JSON_PATH_SLICE="jsonPathSlice",p.JSON_PATH_SUBSCRIPT="jsonPathSubscript",p.JSON_PATH_UNION="jsonPathUnion",p.JSON_PATH_WILDCARD="jsonPathWildcard",p.JSON_REMOVE="jsonRemove",p.JSON_SCHEMA="jsonSchema",p.JSON_SET="jsonSet",p.JSON_STRIP_NULLS="jsonStripNulls",p.JSON_TABLE="jsonTable",p.JSON_TYPE="jsontype",p.JSON_VALUE="jsonValue",p.JSON_VALUE_ARRAY="jsonValueArray",p.JUSTIFY_DAYS="justifyDays",p.JUSTIFY_HOURS="justifyHours",p.JUSTIFY_INTERVAL="justifyInterval",p.KILL="kill",p.KURTOSIS="kurtosis",p.KWARG="kwarg",p.LAG="lag",p.LAMBDA="lambda",p.LANGUAGE_PROPERTY="languageProperty",p.LAST="last",p.LAST_DAY="lastDay",p.LAST_VALUE="lastValue",p.LATERAL="lateral",p.LAX_BOOL="laxBool",p.LAX_FLOAT64="laxFloat64",p.LAX_INT64="laxInt64",p.LAX_STRING="laxString",p.LEAD="lead",p.LEAST="least",p.LEFT="left",p.LENGTH="length",p.LEVENSHTEIN="levenshtein",p.LIKE="like",p.LIKE_PROPERTY="likeProperty",p.LIMIT="limit",p.LIMIT_OPTIONS="limitOptions",p.LIST="list",p.LITERAL="literal",p.LN="ln",p.LOAD_DATA="loadData",p.LOCALTIME="localtime",p.LOCALTIMESTAMP="localtimestamp",p.LOCATION="location",p.LOCATION_PROPERTY="locationProperty",p.LOCK="lock",p.LOCKING_PROPERTY="lockingProperty",p.LOCKING_STATEMENT="lockingStatement",p.LOCK_PROPERTY="lockProperty",p.LOG="log",p.LOGICAL_AND="logicalAnd",p.LOGICAL_OR="logicalOr",p.LOG_PROPERTY="logProperty",p.LOWER="lower",p.LOWER_HEX="lowerHex",p.LT="lt",p.LTE="lte",p.MAKE_INTERVAL="makeInterval",p.MANHATTAN_DISTANCE="manhattanDistance",p.MAP="map",p.MAP_CAT="mapCat",p.MAP_CONTAINS_KEY="mapContainsKey",p.MAP_DELETE="mapDelete",p.MAP_FROM_ENTRIES="mapFromEntries",p.MAP_INSERT="mapInsert",p.MAP_KEYS="mapkeys",p.MAP_PICK="mapPick",p.MAP_SIZE="mapSize",p.MASKING_POLICY_COLUMN_CONSTRAINT="maskingPolicyColumnConstraint",p.MATCH="match",p.MATCH_AGAINST="matchAgainst",p.MATCH_RECOGNIZE="matchRecognize",p.MATCH_RECOGNIZE_MEASURE="matchRecognizeMeasure",p.MATERIALIZED_PROPERTY="materializedProperty",p.MAX="max",p.MD5="md5",p.MD5_DIGEST="md5Digest",p.MD5_NUMBER_LOWER64="md5NumberLower64",p.MD5_NUMBER_UPPER64="md5NumberUpper64",p.MEDIAN="median",p.MERGE="merge",p.MERGE_BLOCK_RATIO_PROPERTY="mergeBlockRatioProperty",p.MERGE_TREE_TTL="mergeTreeTtl",p.MERGE_TREE_TTL_ACTION="mergeTreeTtlAction",p.MIN="min",p.MINHASH="minhash",p.MINHASH_COMBINE="minhashCombine",p.MINUTE="minute",p.ML_FORECAST="mlForecast",p.ML_TRANSLATE="mlTranslate",p.MOD="mod",p.MODE="mode",p.MODEL_ATTRIBUTE="modelAttribute",p.MONTH="month",p.MONTHNAME="monthname",p.MONTHS_BETWEEN="monthsBetween",p.MUL="mul",p.MULTITABLE_INSERTS="multitableInserts",p.NATIONAL="national",p.NEG="neg",p.NEQ="neq",p.NET_FUNC="netFunc",p.NEXT_DAY="nextDay",p.NEXT_VALUE_FOR="nextValueFor",p.NON_CLUSTERED_COLUMN_CONSTRAINT="nonClusteredColumnConstraint",p.NORMAL="normal",p.NORMALIZE="normalize",p.NOT="not",p.NOT_FOR_REPLICATION_COLUMN_CONSTRAINT="notForReplicationColumnConstraint",p.NOT_NULL_COLUMN_CONSTRAINT="notNullColumnConstraint",p.NO_PRIMARY_INDEX_PROPERTY="noPrimaryIndexProperty",p.NTH_VALUE="nthValue",p.NTILE="ntile",p.NULL="null",p.NULLIF="nullif",p.NULL_SAFE_EQ="nullSafeEq",p.NULL_SAFE_NEQ="nullSafeNeq",p.NUMBER_TO_STR="numberToStr",p.NVL2="nvl2",p.OBJECT_AGG="objectAgg",p.OBJECT_IDENTIFIER="objectIdentifier",p.OBJECT_INSERT="objectInsert",p.OFFSET="offset",p.ON_CLUSTER="onCluster",p.ON_COMMIT_PROPERTY="onCommitProperty",p.ON_CONDITION="onCondition",p.ON_CONFLICT="onConflict",p.ON_PROPERTY="onProperty",p.ON_UPDATE_COLUMN_CONSTRAINT="onUpdateColumnConstraint",p.OPCLASS="opclass",p.OPEN_JSON="openJson",p.OPEN_JSON_COLUMN_DEF="openJsonColumnDef",p.OPERATOR="operator",p.OR="or",p.ORDER="order",p.ORDERED="ordered",p.OUTPUT_MODEL_PROPERTY="outputModelProperty",p.OVERFLOW_TRUNCATE_BEHAVIOR="overflowTruncateBehavior",p.OVERLAPS="overlaps",p.OVERLAY="overlay",p.PAD="pad",p.PARAMETER="parameter",p.PARAMETERIZED_AGG="parameterizedAgg",p.PAREN="paren",p.PARSE_BIGNUMERIC="parseBignumeric",p.PARSE_DATETIME="parseDatetime",p.PARSE_IP="parseIp",p.PARSE_JSON="parseJson",p.PARSE_NUMERIC="parseNumeric",p.PARSE_TIME="parseTime",p.PARSE_URL="parseUrl",p.PARTITION="partition",p.PARTITIONED_BY_BUCKET="partitionedByBucket",p.PARTITIONED_BY_PROPERTY="partitionedByProperty",p.PARTITIONED_OF_PROPERTY="partitionedOfProperty",p.PARTITION_BOUND_SPEC="partitionBoundSpec",p.PARTITION_BY_LIST_PROPERTY="partitionByListProperty",p.PARTITION_BY_RANGE_PROPERTY="partitionByRangeProperty",p.PARTITION_BY_RANGE_PROPERTY_DYNAMIC="partitionByRangePropertyDynamic",p.PARTITION_BY_TRUNCATE="partitionByTruncate",p.PARTITION_ID="partitionId",p.PARTITION_LIST="partitionList",p.PARTITION_RANGE="partitionRange",p.PATH_COLUMN_CONSTRAINT="pathColumnConstraint",p.PERCENTILE_CONT="percentileCont",p.PERCENTILE_DISC="percentileDisc",p.PERCENT_RANK="percentRank",p.PERIOD_FOR_SYSTEM_TIME_CONSTRAINT="periodForSystemTimeConstraint",p.PI="pi",p.PIVOT="pivot",p.PIVOT_ALIAS="pivotAlias",p.PIVOT_ANY="pivotAny",p.PLACEHOLDER="placeholder",p.POSEXPLODE="posexplode",p.POSEXPLODE_OUTER="posexplodeOuter",p.POSITIONAL_COLUMN="positionalColumn",p.POW="pow",p.PRAGMA="pragma",p.PREDICATE="predicate",p.PREDICT="predict",p.PREVIOUS_DAY="previousDay",p.PRE_WHERE="preWhere",p.PRIMARY_KEY="primaryKey",p.PRIMARY_KEY_COLUMN_CONSTRAINT="primaryKeyColumnConstraint",p.PRIOR="prior",p.PROJECTION_DEF="projectionDef",p.PROJECTION_POLICY_COLUMN_CONSTRAINT="projectionPolicyColumnConstraint",p.PROPERTIES="properties",p.PROPERTY="property",p.PROPERTY_EQ="propertyEq",p.PSEUDOCOLUMN="pseudocolumn",p.PSEUDO_TYPE="pseudoType",p.PUT="put",p.QUALIFY="qualify",p.QUANTILE="quantile",p.QUARTER="quarter",p.QUERY="query",p.QUERY_BAND="queryBand",p.QUERY_OPTION="queryOption",p.QUERY_TRANSFORM="queryTransform",p.RADIANS="radians",p.RAND="rand",p.RANDN="randn",p.RANDSTR="randstr",p.RANGE_BUCKET="rangeBucket",p.RANGE_N="rangeN",p.RANK="rank",p.RAW_STRING="rawString",p.READ_CSV="readCsv",p.READ_PARQUET="readParquet",p.RECURSIVE_WITH_SEARCH="recursiveWithSearch",p.REDUCE="reduce",p.REFERENCE="reference",p.REFRESH="refresh",p.REFRESH_TRIGGER_PROPERTY="refreshTriggerProperty",p.REGEXP_COUNT="regexpCount",p.REGEXP_EXTRACT="regexpExtract",p.REGEXP_EXTRACT_ALL="regexpExtractAll",p.REGEXP_FULL_MATCH="regexpFullMatch",p.REGEXP_INSTR="regexpInstr",p.REGEXP_ILIKE="regexpIlike",p.REGEXP_LIKE="regexpLike",p.REGEXP_REPLACE="regexpReplace",p.REGEXP_SPLIT="regexpSplit",p.REGR_AVGX="regrAvgx",p.REGR_AVGY="regrAvgy",p.REGR_COUNT="regrCount",p.REGR_INTERCEPT="regrIntercept",p.REGR_R2="regrR2",p.REGR_SLOPE="regrSlope",p.REGR_SXX="regrSxx",p.REGR_SXY="regrSxy",p.REGR_SYY="regrSyy",p.REGR_VALX="regrValx",p.REGR_VALY="regrValy",p.REG_DOMAIN="regDomain",p.REMOTE_WITH_CONNECTION_MODEL_PROPERTY="remoteWithConnectionModelProperty",p.RENAME_COLUMN="renameColumn",p.REPEAT="repeat",p.REPLACE="replace",p.REPLACE_PARTITION="replacePartition",p.RESPECT_NULLS="respectNulls",p.RETURN="return",p.RETURNING="returning",p.RETURNS_PROPERTY="returnsProperty",p.REVERSE="reverse",p.REVOKE="revoke",p.RIGHT="right",p.ROLLBACK="rollback",p.ROLLUP="rollup",p.ROLLUP_INDEX="rollupIndex",p.ROLLUP_PROPERTY="rollupProperty",p.ROUND="round",p.ROW_FORMAT_DELIMITED_PROPERTY="rowFormatDelimitedProperty",p.ROW_FORMAT_PROPERTY="rowFormatProperty",p.ROW_FORMAT_SERDE_PROPERTY="rowFormatSerdeProperty",p.ROW_NUMBER="rowNumber",p.RTRIMMED_LENGTH="rtrimmedLength",p.SAFE_ADD="safeAdd",p.SAFE_CONVERT_BYTES_TO_STRING="safeConvertBytesToString",p.SAFE_DIVIDE="safeDivide",p.SAFE_FUNC="safeFunc",p.SAFE_MULTIPLY="safeMultiply",p.SAFE_NEGATE="safeNegate",p.SAFE_SUBTRACT="safeSubtract",p.SAMPLE_PROPERTY="sampleProperty",p.SCHEMA="schema",p.SCHEMA_COMMENT_PROPERTY="schemaCommentProperty",p.SCOPE_RESOLUTION="scopeResolution",p.SEARCH="search",p.SEARCH_IP="searchIp",p.SEC="sec",p.SECH="sech",p.SECOND="second",p.SECURE_PROPERTY="secureProperty",p.SECURITY_PROPERTY="securityProperty",p.SELECT="select",p.SEMANTIC_VIEW="semanticView",p.SEMICOLON="semicolon",p.SEQ1="seq1",p.SEQ2="seq2",p.SEQ4="seq4",p.SEQ8="seq8",p.SEQUENCE_PROPERTIES="sequenceProperties",p.SERDE_PROPERTIES="serdeProperties",p.SESSION_PARAMETER="sessionParameter",p.SESSION_USER="sessionUser",p.SET="set",p.SETTINGS_PROPERTY="settingsProperty",p.SET_CONFIG_PROPERTY="setConfigProperty",p.SET_ITEM="setItem",p.SET_OPERATION="setOperation",p.SET_PROPERTY="setProperty",p.SHA="sha",p.Sha1_DIGEST="sha1Digest",p.Sha2="sha2",p.Sha2_DIGEST="sha2Digest",p.SHARING_PROPERTY="sharingProperty",p.SHOW="show",p.SIGN="sign",p.SIMILAR_TO="similarTo",p.SIN="sin",p.SINH="sinh",p.SKEWNESS="skewness",p.SLICE="slice",p.SORT="sort",p.SORT_ARRAY="sortArray",p.SORT_KEY_PROPERTY="sortKeyProperty",p.SOUNDEX="soundex",p.SOUNDEX_P123="soundexP123",p.SPACE="space",p.SPLIT="split",p.SPLIT_PART="splitPart",p.SQL_READ_WRITE_PROPERTY="sqlReadWriteProperty",p.SQL_SECURITY_PROPERTY="sqlSecurityProperty",p.SQRT="sqrt",p.STABILITY_PROPERTY="stabilityProperty",p.STANDARD_HASH="standardHash",p.STAR="star",p.STARTS_WITH="startswith",p.STAR_MAP="starMap",p.STDDEV="stddev",p.STDDEV_POP="stddevPop",p.STDDEV_SAMP="stddevSamp",p.STORAGE_HANDLER_PROPERTY="storageHandlerProperty",p.STREAM="stream",p.STREAMING_TABLE_PROPERTY="streamingTableProperty",p.STRICT_PROPERTY="strictProperty",p.STRING="string",p.STRING_TO_ARRAY="stringToArray",p.STRUCT="struct",p.STRUCT_EXTRACT="structExtract",p.STR_POSITION="strPosition",p.STR_TO_DATE="strToDate",p.STR_TO_MAP="strToMap",p.STR_TO_TIME="strToTime",p.STR_TO_UNIX="strToUnix",p.STUFF="stuff",p.ST_DISTANCE="stDistance",p.ST_POINT="stPoint",p.SUB="sub",p.SUBQUERY="subquery",p.SUBQUERY_PREDICATE="subqueryPredicate",p.SUBSTRING="substring",p.SUBSTRING_INDEX="substringIndex",p.SUM="sum",p.SUMMARIZE="summarize",p.SWAP_TABLE="swapTable",p.SYSTIMESTAMP="systimestamp",p.TABLE="table",p.TABLE_ALIAS="tableAlias",p.TABLE_COLUMN="tableColumn",p.TABLE_FROM_ROWS="tableFromRows",p.TABLE_SAMPLE="tableSample",p.TAG="tag",p.TAGS="tags",p.TAN="tan",p.TANH="tanh",p.TEMPORARY_PROPERTY="temporaryProperty",p.TIME="time",p.TIMESTAMP="timestamp",p.TIMESTAMP_ADD="timestampAdd",p.TIMESTAMP_DIFF="timestampDiff",p.TIMESTAMP_FROM_PARTS="timestampFromParts",p.TIMESTAMP_LTZ_FROM_PARTS="timestampLtzFromParts",p.TIMESTAMP_SUB="timestampSub",p.TIMESTAMP_TRUNC="timestampTrunc",p.TIMESTAMP_TZ_FROM_PARTS="timestampTzFromParts",p.TIME_ADD="timeAdd",p.TIME_DIFF="timeDiff",p.TIME_FROM_PARTS="timeFromParts",p.TIME_SLICE="timeSlice",p.TIME_STR_TO_DATE="timeStrToDate",p.TIME_STR_TO_TIME="timeStrToTime",p.TIME_STR_TO_UNIX="timeStrToUnix",p.TIME_SUB="timeSub",p.TIME_TO_STR="timeToStr",p.TIME_TO_TIME_STR="timeToTimeStr",p.TIME_TO_UNIX="timeToUnix",p.TIME_TRUNC="timeTrunc",p.TIME_UNIT="timeUnit",p.TITLE_COLUMN_CONSTRAINT="titleColumnConstraint",p.TO_ARRAY="toArray",p.TO_BASE32="toBase32",p.TO_BASE64="toBase64",p.TO_BINARY="toBinary",p.TO_BOOLEAN="toBoolean",p.TO_CHAR="toChar",p.TO_CODE_POINTS="toCodePoints",p.TO_DAYS="toDays",p.TO_DECFLOAT="toDecfloat",p.TO_DOUBLE="toDouble",p.TO_FILE="toFile",p.TO_MAP="toMap",p.TO_NUMBER="toNumber",p.TO_TABLE_PROPERTY="toTableProperty",p.TRANSACTION="transaction",p.TRANSFORM="transform",p.TRANSFORM_MODEL_PROPERTY="transformModelProperty",p.TRANSIENT_PROPERTY="transientProperty",p.TRANSLATE="translate",p.TRANSLATE_CHARACTERS="translateCharacters",p.TRIM="trim",p.TRUNC="trunc",p.TRUNCATE_TABLE="truncateTable",p.TRY="try",p.TRY_BASE64_DECODE_BINARY="tryBase64DecodeBinary",p.TRY_BASE64_DECODE_STRING="tryBase64DecodeString",p.TRY_CAST="tryCast",p.TRY_HEX_DECODE_BINARY="tryHexDecodeBinary",p.TRY_HEX_DECODE_STRING="tryHexDecodeString",p.TRY_TO_DECFLOAT="tryToDecfloat",p.TS_OR_DI_TO_DI="tsOrDiToDi",p.TS_OR_DS_ADD="tsOrDsAdd",p.TS_OR_DS_DIFF="tsOrDsDiff",p.TS_OR_DS_TO_DATE="tsOrDsToDate",p.TS_OR_DS_TO_DATETIME="tsOrDsToDatetime",p.TS_OR_DS_TO_DATE_STR="tsOrDsToDateStr",p.TS_OR_DS_TO_TIME="tsOrDsToTime",p.TS_OR_DS_TO_TIMESTAMP="tsOrDsToTimestamp",p.TUPLE="tuple",p.TYPE="type",p.TYPEOF="typeof",p.UDTF="udtf",p.UNARY="unary",p.UNCACHE="uncache",p.UNHEX="unhex",p.UNICODE="unicode",p.UNICODE_STRING="unicodeString",p.UNIFORM="uniform",p.UNION="union",p.UNIQUE_COLUMN_CONSTRAINT="uniqueColumnConstraint",p.UNIQUE_KEY_PROPERTY="uniqueKeyProperty",p.UNIX_DATE="unixDate",p.UNIX_MICROS="unixMicros",p.UNIX_MILLIS="unixMillis",p.UNIX_SECONDS="unixSeconds",p.UNIX_TO_STR="unixToStr",p.UNIX_TO_TIME="unixToTime",p.UNIX_TO_TIME_STR="unixToTimeStr",p.UNLOGGED_PROPERTY="unloggedProperty",p.UNNEST="unnest",p.UNPIVOT_COLUMNS="unpivotColumns",p.UPDATE="update",p.UPPER="upper",p.UPPERCASE_COLUMN_CONSTRAINT="uppercaseColumnConstraint",p.USE="use",p.USER_DEFINED_FUNCTION="userDefinedFunction",p.USING_DATA="usingData",p.USING_TEMPLATE_PROPERTY="usingTemplateProperty",p.UTC_DATE="utcDate",p.UTC_TIME="utcTime",p.UTC_TIMESTAMP="utcTimestamp",p.UUID="uuid",p.VALUES="values",p.VAR="var",p.VARIADIC="variadic",p.VARIANCE="variance",p.VARIANCE_POP="variancePop",p.VAR_MAP="varMap",p.VECTOR_SEARCH="vectorSearch",p.VERSION="version",p.VIEW_ATTRIBUTE_PROPERTY="viewAttributeProperty",p.VOLATILE_PROPERTY="volatileProperty",p.WATERMARK_COLUMN_CONSTRAINT="watermarkColumnConstraint",p.WEEK="week",p.WEEK_OF_YEAR="weekOfYear",p.WEEK_START="weekStart",p.WHEN="when",p.WHENS="whens",p.WHERE="where",p.WIDTH_BUCKET="widthBucket",p.WINDOW="window",p.WINDOW_SPEC="windowSpec",p.WITH="with",p.WITHIN_GROUP="withinGroup",p.WITH_DATA_PROPERTY="withDataProperty",p.WITH_FILL="withFill",p.WITH_JOURNAL_TABLE_PROPERTY="withJournalTableProperty",p.WITH_OPERATOR="withOperator",p.WITH_PROCEDURE_OPTIONS="withProcedureOptions",p.WITH_SCHEMA_BINDING_PROPERTY="withSchemaBindingProperty",p.WITH_SYSTEM_VERSIONING_PROPERTY="withSystemVersioningProperty",p.WITH_TABLE_HINT="withTableHint",p.XML_ELEMENT="xmlElement",p.XML_GET="xmlGet",p.XML_KEY_VALUE_OPTION="xmlKeyValueOption",p.XML_NAMESPACE="xmlNamespace",p.XML_TABLE="xmlTable",p.XOR="xor",p.YEAR="year",p.YEAR_OF_WEEK="yearOfWeek",p.YEAR_OF_WEEK_ISO="yearOfWeekIso",p.ZERO_FILL_COLUMN_CONSTRAINT="zeroFillColumnConstraint",p.ZIPF="zipf",p))(aA||{}),Hw=(t=>(t.INCREMENTAL="incremental",t.FULL="full",t))(Hw||{}),oA=(u=>(u.TABLE="table",u.VIEW="view",u.INDEX="index",u.SCHEMA="schema",u.DATABASE="database",u.FUNCTION="function",u.PROCEDURE="procedure",u.TRIGGER="trigger",u.SEQUENCE="sequence",u.TEMPORARY_VIEW="temporary view",u))(oA||{}),Ww=(n=>(n.TABLE="table",n.VIEW="view",n.SCHEMA="schema",n.FUNCTION="function",n.PROCEDURE="procedure",n))(Ww||{}),jw=(t=>(t.CONNECTION="connection",t.QUERY="query",t))(jw||{}),Jw=(r=>(r.CURSOR="cursor",r.VARIABLE="variable",r.TABLE="table",r.CONSTANT="constant",r))(Jw||{}),Xw=(n=>(n.SESSION="session",n.GLOBAL="global",n.LOCAL="local",n.PERSIST="persist",n.PERSIST_ONLY="persistOnly",n))(Xw||{}),zw=(t=>(t.BREADTH="breadth",t.DEPTH="depth",t))(zw||{}),Qw=(r=>(r.GENERATED="generated",r.STORED="stored",r.VIRTUAL="virtual",r.DEFAULT="default",r))(Qw||{}),Zw=(s=>(s.TABLE="table",s.COLUMN="column",s.VIEW="view",s))(Zw||{}),Kw=(a=>(a.PRIMARY_KEY="primaryKey",a.UNIQUE="unique",a.NOT_NULL="notNull",a.CHECK="check",a.DEFAULT="default",a.FOREIGN_KEY="foreignKey",a))(Kw||{}),oN=(h=>(h.TABLE="table",h.VIEW="view",h.INDEX="index",h.SCHEMA="schema",h.DATABASE="database",h.FUNCTION="function",h.PROCEDURE="procedure",h.TRIGGER="trigger",h.SEQUENCE="sequence",h.CONSTRAINT="constraint",h.COLUMN="column",h))(oN||{}),eM=(t=>(t.CONDITIONAL="conditional",t.UNCONDITIONAL="unconditional",t))(eM||{}),tM=(t=>(t.GRANT="grant",t.REVOKE="revoke",t))(tM||{}),Qt=(u=>(u.INNER="inner",u.OUTER="outer",u.LEFT="left",u.RIGHT="right",u.FULL="full",u.CROSS="cross",u.SEMI="semi",u.ANTI="anti",u.STRAIGHT_JOIN="straightJoin",u.ARRAY="array",u))(Qt||{}),sM=(r=>(r.USER="user",r.ROLE="role",r.GROUP="group",r.PUBLIC="public",r))(sM||{}),rM=(t=>(t.SYSTEM_TIME="systemTime",t.TRANSACTION_TIME="transactionTime",t))(rM||{}),iM=(s=>(s.ROWS="rows",s.RANGE="range",s.GROUPS="groups",s))(iM||{}),ht=(C=>(C.ARRAY="array",C.AGGREGATEFUNCTION="aggregatefunction",C.SIMPLEAGGREGATEFUNCTION="simpleaggregatefunction",C.BIGDECIMAL="bigdecimal",C.BIGINT="bigint",C.BIGNUM="bignum",C.BIGSERIAL="bigserial",C.BINARY="binary",C.BIT="bit",C.BLOB="blob",C.BOOLEAN="boolean",C.BPCHAR="bpchar",C.CHAR="char",C.DATE="date",C.DATE32="date32",C.DATEMULTIRANGE="datemultirange",C.DATERANGE="daterange",C.DATETIME="datetime",C.DATETIME2="datetime2",C.DATETIME64="datetime64",C.DECIMAL="decimal",C.DECIMAL32="decimal32",C.DECIMAL64="decimal64",C.DECIMAL128="decimal128",C.DECIMAL256="decimal256",C.DECFLOAT="decfloat",C.DOUBLE="double",C.DYNAMIC="dynamic",C.ENUM="enum",C.ENUM8="enum8",C.ENUM16="enum16",C.FILE="file",C.FIXEDSTRING="fixedstring",C.FLOAT="float",C.GEOGRAPHY="geography",C.GEOGRAPHYPOINT="geographypoint",C.GEOMETRY="geometry",C.POINT="point",C.RING="ring",C.LINESTRING="linestring",C.MULTILINESTRING="multilinestring",C.POLYGON="polygon",C.MULTIPOLYGON="multipolygon",C.HLLSKETCH="hllsketch",C.HSTORE="hstore",C.IMAGE="image",C.INET="inet",C.INT="int",C.INT128="int128",C.INT256="int256",C.INT4MULTIRANGE="int4multirange",C.INT4RANGE="int4range",C.INT8MULTIRANGE="int8multirange",C.INT8RANGE="int8range",C.INTERVAL="interval",C.IPADDRESS="ipaddress",C.IPPREFIX="ipprefix",C.IPV4="ipv4",C.IPV6="ipv6",C.JSON="json",C.JSONB="jsonb",C.LIST="list",C.LONGBLOB="longblob",C.LONGTEXT="longtext",C.LOWCARDINALITY="lowcardinality",C.MAP="map",C.MEDIUMBLOB="mediumblob",C.MEDIUMINT="mediumint",C.MEDIUMTEXT="mediumtext",C.MONEY="money",C.NAME="name",C.NCHAR="nchar",C.NESTED="nested",C.NOTHING="nothing",C.NULL="null",C.NUMMULTIRANGE="nummultirange",C.NUMRANGE="numrange",C.NVARCHAR="nvarchar",C.OBJECT="object",C.RANGE="range",C.ROWVERSION="rowversion",C.SERIAL="serial",C.SET="set",C.SMALLDATETIME="smalldatetime",C.SMALLINT="smallint",C.SMALLMONEY="smallmoney",C.SMALLSERIAL="smallserial",C.STRUCT="struct",C.SUPER="super",C.TEXT="text",C.TINYBLOB="tinyblob",C.TINYTEXT="tinytext",C.TIME="time",C.TIMETZ="timetz",C.TIME_NS="timeNs",C.TIMESTAMP="timestamp",C.TIMESTAMPNTZ="timestampntz",C.TIMESTAMPLTZ="timestampltz",C.TIMESTAMPTZ="timestamptz",C.TIMESTAMP_S="timestampS",C.TIMESTAMP_MS="timestampMs",C.TIMESTAMP_NS="timestampNs",C.TINYINT="tinyint",C.TSMULTIRANGE="tsmultirange",C.TSRANGE="tsrange",C.TSTZMULTIRANGE="tstzmultirange",C.TSTZRANGE="tstzrange",C.UBIGINT="ubigint",C.UINT="uint",C.UINT128="uint128",C.UINT256="uint256",C.UMEDIUMINT="umediumint",C.UDECIMAL="udecimal",C.UDOUBLE="udouble",C.UNION="union",C.UNKNOWN="unknown",C.USERDEFINED="user-defined",C.USMALLINT="usmallint",C.UTINYINT="utinyint",C.UUID="uuid",C.VARBINARY="varbinary",C.VARCHAR="varchar",C.VARIANT="variant",C.VECTOR="vector",C.XML="xml",C.YEAR="year",C.TDIGEST="tdigest",C))(ht||{}),bf=(a=>(a.TABLE="table",a.VIEW="view",a.SCHEMA="schema",a.DATABASE="database",a.INDEX="index",a.COLUMN="column",a))(bf||{}),nM=(s=>(s.STATISTICS="statistics",s.COMPUTE="compute",s.TABLE="table",s))(nM||{}),aM=(s=>(s.ALL="all",s.DEFAULT="default",s.COLUMNS="columns",s))(aM||{}),oM=(t=>(t.PERCENT="percent",t.ROWS="rows",t))(oM||{}),cM=(e=>(e.STATISTICS="statistics",e))(cM||{}),pM=(t=>(t.REF_UPDATE="refUpdate",t.STRUCTURE="structure",t))(pM||{}),lM=(r=>(r.PATH="path",r.EXISTS="exists",r.VALUE="value",r.QUERY="query",r))(lM||{}),uM=(r=>(r.PATH="path",r.EXISTS="exists",r.VALUE="value",r.QUERY="query",r))(uM||{}),hM=(n=>(n.DATABASE="database",n.SCHEMA="schema",n.WAREHOUSE="warehouse",n.ROLE="role",n.CATALOG="catalog",n))(hM||{}),gM=(r=>(r.PRIMARY="primary",r.UNIQUE="unique",r.FULLTEXT="fulltext",r.SPATIAL="spatial",r))(gM||{}),EM=(t=>(t.LOCAL="local",t.REMOTE="remote",t))(EM||{}),AM=(r=>(r.HASH="hash",r.RANGE="range",r.LIST="list",r.REPLICATE="replicate",r))(AM||{}),dM=(o=>(o.FLAT="flat",o.HASHED="hashed",o.RANGE_HASHED="rangeHashed",o.CACHE="cache",o.DIRECT="direct",o.IP_TRIE="ipTrie",o.POLYGON="polygon",o))(dM||{}),xM=(r=>(r.DEFAULT="default",r.ALL="all",r.FALLBACK="fallback",r.LOCKING="locking",r))(xM||{}),fM=(r=>(r.ON_COMMIT="onCommit",r.ON_DEMAND="onDemand",r.START_WITH="startWith",r.NEXT="next",r))(fM||{}),dI=(c=>(c.POST_CREATE="postCreate",c.POST_NAME="postName",c.POST_SCHEMA="postSchema",c.POST_WITH="postWith",c.POST_ALIAS="postAlias",c.POST_EXPRESSION="postExpression",c.POST_INDEX="postIndex",c.UNSUPPORTED="unsupported",c))(dI||{}),cN=(n=>(n.UNION="union",n.INTERSECT="intersect",n.EXCEPT="except",n.INNER="inner",n.OUTER="outer",n))(cN||{}),TM=(n=>(n.STRUCT="struct",n.VALUE="value",n.OBJECT="object",n.ALL="all",n.DISTINCT="distinct",n))(TM||{}),SM=(r=>(r.SESSION="session",r.GLOBAL="global",r.LOCAL="local",r.VARIABLE="variable",r))(SM||{}),mM=(n=>(n.POSITIONAL="positional",n.NAMED="named",n.QUESTION="question",n.NUMERIC="numeric",n.DOLLAR="dollar",n))(mM||{}),OM=(t=>(t.START="start",t.END="end",t))(OM||{}),xI=(s=>(s.LEADING="leading",s.TRAILING="trailing",s.BOTH="both",s))(xI||{});import{DateTime as uD}from"luxon";import{DateTime as so,Duration as eo}from"luxon";var wi=class i{constructor(e){this._collected=!1;let{expression:t,sources:s,outerColumns:r,parent:n,scopeType:a="root",lateralSources:o,cteSources:c,canBeCorrelated:l}=e;this.expression=t,this.sources=s||new Map,this.lateralSources=o||new Map,this.cteSources=c||new Map;for(let[u,h]of this.lateralSources)this.sources.set(u,h);for(let[u,h]of this.cteSources)this.sources.set(u,h);this.outerColumns=r||[],this.parent=n,this.scopeType=a,this.subqueryScopes=[],this.derivedTableScopes=[],this.tableScopes=[],this.cteScopes=[],this.unionScopes=[],this.udtfScopes=[],this.canBeCorrelated=l??!1,this.clearCache()}clearCache(){this._collected=!1,this._rawColumns=void 0,this._tableColumns=void 0,this._stars=void 0,this._derivedTables=void 0,this._udtfs=void 0,this._tables=void 0,this._ctes=void 0,this._subqueries=void 0,this._selectedSources=void 0,this._columns=void 0,this._externalColumns=void 0,this._localColumns=void 0,this._joinHints=void 0,this._pivots=void 0,this._references=void 0,this._semiAntiJoinTables=void 0,this._columnIndex=void 0}branch(e){let{expression:t,scopeType:s,sources:r,cteSources:n,lateralSources:a,...o}=e,c=new Map(this.cteSources);if(n)for(let[l,u]of n)c.set(l,u);return new i({expression:t.unnest(),sources:r?new Map(r):void 0,parent:this,scopeType:s,cteSources:c,lateralSources:a?new Map(a):void 0,canBeCorrelated:this.canBeCorrelated||s==="subquery"||s==="udtf",...o})}collect(){this._tables=[],this._ctes=[],this._subqueries=[],this._derivedTables=[],this._udtfs=[],this._rawColumns=[],this._tableColumns=[],this._stars=[],this._joinHints=[],this._semiAntiJoinTables=new Set,this._columnIndex=new WeakSet;for(let e of this.walk({bfs:!1}))if(e!==this.expression)if(e instanceof Se&&e.isStar)this._stars.push(e);else if(e instanceof B&&!(e instanceof lA))this._columnIndex.add(e),e.args.this instanceof xe?this._stars.push(e):this._rawColumns.push(e);else if(e instanceof V&&!(e.parent instanceof ur)){let t=e.parent;if(t instanceof oe){let s=t;(s.args.kind==="semi"||s.args.kind==="anti")&&this._semiAntiJoinTables.add(e.aliasOrName)}this._tables.push(e)}else if(e instanceof ur)this._joinHints.push(e);else if(e instanceof Nt)this._udtfs.push(e);else if(e instanceof Tt)this._ctes.push(e);else if(e instanceof Te){let t=NM(e);fI(e)&&t&&this._derivedTables.push(e)}else Er.some(t=>e instanceof t)&&!NM(e)?this._subqueries.push(e):e instanceof Mi&&this._tableColumns.push(e);this._collected=!0}ensureCollected(){this._collected||this.collect()}walk(e={}){return pA(this.expression,e)}find(...e){return Xq(this.expression,e,{bfs:!0})}findAll(...e){return jn(this.expression,e,{bfs:!0})}replace(e,t){e.replace(t),this.clearCache()}get tables(){return this.ensureCollected(),this._tables??[]}get ctes(){return this.ensureCollected(),this._ctes??[]}get derivedTables(){return this.ensureCollected(),this._derivedTables??[]}get udtfs(){return this.ensureCollected(),this._udtfs??[]}get subqueries(){return this.ensureCollected(),this._subqueries??[]}get stars(){return this.ensureCollected(),this._stars??[]}get columnIndex(){return this.ensureCollected(),this._columnIndex??new WeakSet}get isSubquery(){return this.scopeType==="subquery"}get isDerivedTable(){return this.scopeType==="derivedTable"}get isUnion(){return this.scopeType==="union"}get isCte(){return this.scopeType==="cte"}get isRoot(){return this.scopeType==="root"}get isUdtf(){return this.scopeType==="udtf"}get isCorrelatedSubquery(){return!!(this.canBeCorrelated&&0<this.externalColumns.length)}get columns(){if(this._columns===void 0){this.ensureCollected();let e=this._rawColumns??[],t=[];for(let r of[...this.subqueryScopes,...this.udtfScopes,...this.derivedTableScopes.filter(n=>n.canBeCorrelated)])t.push(...r.externalColumns);let s=new Set(this.expression.namedSelects);this._columns=[];for(let r of[...e,...t]){let n=r.findAncestor(ee,Os,fe,Zt,us,V,xe,We);(!n||r.table||n instanceof ee||n instanceof V&&!(n.args.this instanceof g)||(n instanceof fe||n instanceof We)&&(n.parent instanceof we||n.parent instanceof $t||!(n.parent instanceof ee)||!s.has(r.name))||n instanceof xe&&r.argKey!=="except")&&this._columns.push(r)}}return this._columns}get tableColumns(){return this._tableColumns===void 0&&this.ensureCollected(),this._tableColumns??[]}get externalColumns(){return this._externalColumns===void 0&&(this._externalColumns=this.columns.filter(e=>!this.sources.has(e.table)&&!this.semiOrAntiJoinTables.has(e.table))),this._externalColumns}get localColumns(){if(this._localColumns===void 0){let e=new Set(this.externalColumns);this._localColumns=this.columns.filter(t=>!e.has(t))}return this._localColumns}get unqualifiedColumns(){return this.columns.filter(e=>!e.table)}get joinHints(){return this._joinHints===void 0?[]:this._joinHints}get pivots(){if(!this._pivots){this._pivots=[];for(let[,e]of this.references){let t=e.args.pivots;t&&Array.isArray(t)&&this._pivots.push(...t)}}return this._pivots}get semiOrAntiJoinTables(){return this._semiAntiJoinTables||new Set}get references(){if(this._references===void 0){this._references=[];for(let e of this.tables)this._references.push([e.aliasOrName,e]);for(let e of[...this.derivedTables,...this.udtfs]){let t=TI(e),s=e.getArgKey("pivots")?e:e.unnest();this._references.push([t,s])}}return this._references}get selectedSources(){if(this._selectedSources===void 0){this._selectedSources={};for(let[e,t]of this.references){if(this.semiOrAntiJoinTables.has(e))continue;if(e in this._selectedSources)throw new dl(`Alias already used: ${e}`);let s=this.sources.get(e);s!==void 0&&(this._selectedSources[e]=[t,s])}}return this._selectedSources}sourceColumns(e){return this.columns.filter(t=>t.table===e)}renameSource(e,t){let s=e||"",r=this.sources.get(s);r!==void 0&&(this.sources.delete(s),this.sources.set(t,r))}addSource(e,t){this.sources.set(e,t),this.clearCache()}removeSource(e){this.sources.delete(e),this.clearCache()}*traverse(){let e=[this],t=[];for(;0<e.length;){let s=e.pop();t.push(s),e.push(...s.cteScopes,...s.unionScopes,...s.tableScopes,...s.subqueryScopes)}for(let s=t.length-1;0<=s;s--)yield t[s]}refCount(){let e=new Map;for(let t of this.traverse()){for(let[,s]of Object.values(t.selectedSources))s instanceof i&&e.set(s,(e.get(s)||0)+1);for(let s of t.semiOrAntiJoinTables){let r=t.sources.get(s);r!==void 0&&r instanceof i&&e.set(r,(e.get(r)||0)+1)}}return e}toString(){return`<Scope ${this.scopeType}>`}};function cA(i){if(![z,gr,ls].some(s=>i instanceof s))return[];let t=[];for(let s of Qa(new wi({expression:i})))t.push(s);return t}function*Qa(i){let e=i.expression;if(e instanceof ee)yield*RM(i);else if(e instanceof Xe){yield*Lf(i),yield*jq(i);return}else if(e instanceof Te)i.isRoot?yield*RM(i):yield*yM(i);else if(e instanceof V)yield*IM(i);else if(e instanceof Nt)yield*Jq(i);else if(e instanceof gr){e.args.expression instanceof z&&(yield*Lf(i),yield*Qa(new wi({expression:e.args.expression,cteSources:i.cteSources})));return}else if(e instanceof ls){yield*Lf(i);for(let t of jn(e,[z])){let s=t.parent;s&&!(s instanceof Tt)&&!(s instanceof Te)&&(yield*Qa(new wi({expression:t,cteSources:i.cteSources})))}return}else return;yield i}function*RM(i){yield*Lf(i),yield*IM(i),yield*yM(i)}function*jq(i){let e,t=[i],s=i.expression,r=[s.right,s.left];for(;0<r.length;){let n=r.pop(),a=t[t.length-1],o=a.branch({expression:n,outerColumns:a.outerColumns,scopeType:"union"});if(n instanceof Xe){yield*Lf(o),t.push(o),r.push(n.right),r.push(n.left);continue}let c;for(let l of Qa(o))yield l,c=l;e&&c?(t.pop(),a.unionScopes=[e,c],e=a,yield a):e=c}}function*Lf(i){let e=new Map;for(let t of i.ctes){let s=t.alias,r=i.expression.args.with;if(r&&$(r,tt)&&r.args.recursive){let o=t.args.this;o instanceof Xe&&o.args.this&&e.set(s,i.branch({expression:o.args.this,scopeType:"cte"}))}let n=t.args.this;if(!n)continue;let a;for(let o of Qa(i.branch({expression:n,cteSources:e,outerColumns:t.aliasColumnNames||[],scopeType:"cte"})))yield o,a=o;a&&(e.set(s,a),i.cteScopes.push(a))}for(let[t,s]of e)i.sources.set(t,s),i.cteSources.set(t,s)}function fI(i){return!!(i instanceof Te&&(i.alias||Er.some(e=>i.args.this instanceof e)))}function NM(i){let e=i.parent;for(;e instanceof Te;)e=e.parent;return e instanceof Je||e instanceof oe}function TI(i){let e=i.getArgKey("alias"),t=i.alias;return!t&&e instanceof ie&&e.columns.length===1&&(t=e.columns[0].name),t}function*IM(i){let e=new Map,t=[],s=i.expression.getArgKey("from");s?.args.this&&t.push(s.args.this);for(let n of i.expression.getArgKey("joins")||[])n.args.this&&t.push(n.args.this);i.expression instanceof V&&t.push(i.expression);for(let n of i.expression.getArgKey("laterals")||[])t.push(n);let r=0;for(;r<t.length;){let n=t[r++];if(n instanceof Ka&&(n=n.getArgKey("this")),n instanceof V){let u=n.name,h=n.aliasOrName;if(i.sources.has(u)&&!n.db){let d=n.args.pivots;d&&0<d.length?e.set(d[0].alias,n):e.set(h,i.sources.get(u))}else e.has(h)?e.set(Za(Array.from(e.keys()),u),n):e.set(h,n);if(n!==i.expression)for(let d of n.args.joins||[])$(d.args.this,A)&&t.push(d.args.this);continue}if(!(n instanceof hr))continue;let a,o,c;if(n instanceof Nt)a=e,o="udtf",c=i.udtfScopes;else if(n instanceof Te&&fI(n)){a=void 0,o="derivedTable",c=i.derivedTableScopes;for(let u of n.getArgKey("joins")||[])u.args.this&&t.push(u.args.this)}else{t.push(n.getArgKey("this"));for(let u of n.getArgKey("joins")||[])u.args.this&&t.push(u.args.this);continue}let l;for(let u of Qa(i.branch({expression:n,lateralSources:a,outerColumns:n.aliasColumnNames||[],scopeType:o})))yield u,l=u,e.set(TI(n),l);l&&(c.push(l),i.tableScopes.push(l))}for(let[n,a]of e)i.sources.set(n,a)}function*yM(i){for(let e of i.subqueries){let t;for(let s of Qa(i.branch({expression:e,scopeType:"subquery"})))yield s,t=s;t&&i.subqueryScopes.push(t)}}function*Jq(i){let e;i.expression instanceof ge?e=i.expression.args.expressions??[]:i.expression instanceof St&&i.expression.args.this?e=[i.expression.args.this]:e=[];let t=new Map;for(let s of e){if(!(s instanceof Te))continue;let r;for(let n of Qa(i.branch({expression:s,scopeType:"subquery",outerColumns:s.aliasColumnNames||[]})))yield n,r=n,t.set(TI(s),n);r&&i.subqueryScopes.push(r)}for(let[s,r]of t)i.sources.set(s,r)}function hF(i){let e=cA(i);return M(e,-1)}function*pA(i,e={}){let{bfs:t=!0,prune:s}=e,r=!1;for(let n of i.walk({bfs:t,prune:a=>r||(s?s(a):!1)}))if(r=!1,yield n,n!==i&&(n instanceof Tt||(n.parent instanceof Je||n.parent instanceof oe)&&fI(n)||n.parent instanceof Nt&&n instanceof z||Er.some(a=>n instanceof a))&&(r=!0,n instanceof Te||n instanceof Nt))for(let a of["joins","laterals","pivots"]){let o=n.getArgKey(a);if(Array.isArray(o))for(let c of o)yield*pA(c,{bfs:t})}}function jn(i,e,t={}){let{bfs:s=!0}=t,r=[];for(let n of pA(i,{bfs:s}))for(let a of e)if(n instanceof a){r.push(n);break}return r}function Xq(i,e,t={}){let{bfs:s=!0}=t;for(let r of pA(i,{bfs:s}))for(let n of J(e))if(r instanceof n)return r}function TF(i,e={}){let{dnf:t=!1,maxDistance:s=128}=e,r=new hA({annotateNewExpressions:!1}),n=[];for(let a of i.walk({prune:o=>o instanceof Ee}))a instanceof Ee&&n.push(a);for(let a of n){if(lN(a,{dnf:t}))continue;let o=a===i,c=a.copy();a.transform(u=>r.rewriteBetween(u),{copy:!1});let l=CM(a,{dnf:t,max:s});if(s<l)return i;try{let u=uN(a,h=>PM(h,{dnf:t,maxDistance:s,simplifier:r}));a=a.replace(u)}catch(u){if(u instanceof dl)return a.replace(c),o?c:i;throw u}o&&(i=a)}return i}function lN(i,e={}){let{dnf:t=!1}=e,[s,r]=t?[ce,ze]:[ze,ce];return!jn(i,[r]).some(n=>n.findAncestor(s))}function CM(i,e={}){let{dnf:t=!1,max:s=1/0}=e,r=-1;for(let n of i.findAll(Ee))r-=1;for(let n of wf(i,{dnf:t,max:s}))if(r+=n,s<r)return r;return r}function*wf(i,e){let{dnf:t,max:s=1/0,depth:r=0}=e;if(s<r){yield r;return}let n=i.unnest();if(!(n instanceof Ee)){yield 1;return}let a=r+1,o=n.left,c=n.right;if(!o||!c){yield 1;return}if(n instanceof(t?ce:ze))for(let u of wf(o,{dnf:t,max:s,depth:a}))for(let h of wf(c,{dnf:t,max:s,depth:a}))yield u+h;else yield*wf(o,{dnf:t,max:s,depth:a}),yield*wf(c,{dnf:t,max:s,depth:a})}function PM(i,e){let{dnf:t,maxDistance:s,simplifier:r}=e;if(lN(i,{dnf:t}))return i;let n=CM(i,{dnf:t,max:s});if(s<n)throw new dl(`Normalization distance ${n} exceeds max ${s}`);hN(i,x=>PM(x,e));let[a,o]=t?[ze,ce]:[ce,ze];if(!(i instanceof o))return i;let[c,l]=i.unnestOperands();if(!c||!l)return i;let u=o===ce?Fe:Kt,h=a===ce?Fe:Kt,d=r??new hA({annotateNewExpressions:!1});if(c instanceof a&&l instanceof a){let x=Array.from(c.findAll(Ee)).length;return Array.from(l.findAll(Ee)).length<x?pN(c,l,u,h,d):pN(l,c,u,h,d)}return c instanceof a?pN(l,c,u,h,d):l instanceof a?pN(c,l,u,h,d):i}function pN(i,e,t,s,r){let n=e.left,a=e.right;if(!n||!a)return i;if(i instanceof Ee)return hN(i,l=>{let u=uA(t([l,n])),h=uA(t([l,a]));return s([r.uniqSort(u),r.uniqSort(h)],{copy:!1})}),i;let o=uA(t([i,n])),c=uA(t([i,a]));return s([r.uniqSort(o),r.uniqSort(c)],{copy:!1})}var to="final";function xN(i,e={}){let{constantPropagation:t=!1,coalesceSimplification:s=!1,dialect:r}=e;return new hA({dialect:r}).simplify(i,{constantPropagation:t,coalesceSimplification:s})}var dr=class extends Error{constructor(e){super(e),this.name="UnsupportedUnit"}};function gA(...i){return function(e,t){return function(...s){try{return e.apply(this,s)}catch(r){if(i.some(n=>r instanceof n))return s[0];throw r}}}}function Di(i,e){return function(...t){let s=t[0],r=i.apply(this,t);if(r===void 0)return r;if(this.annotateNewExpressions&&s!==r&&r instanceof A){this._annotator.clear();let n=this._annotator.annotate(r,{annotateScope:!1});return n.type=s.type,n}return r}}function uA(i){if(!(i instanceof Ee))return i;let e=i.args,t=Object.values(e);for(let s of t){if(!(s instanceof A))continue;let r=s.unnest();r._constructor===i._constructor&&s.replace(r)}return i}function zq(i,e){if(!(i instanceof Oe))return i;let t=i.args.this,s=i.parent,r=s instanceof Ne;return t instanceof ee||s instanceof $s||s instanceof Dt||se.getOrRaise(e)._constructor.REQUIRES_PARENTHESIZED_STRUCT_ACCESS&&s instanceof Se&&(s.right instanceof U||s.right instanceof xe)?i:!(s instanceof ye||s instanceof q)||s instanceof Oe||!(t instanceof q)&&!((t instanceof be||t instanceof _e)&&r)||t instanceof Ne&&!(r||s instanceof It)||t instanceof Le&&s instanceof Le||t instanceof Ns&&s instanceof Ns||t instanceof Ns&&(s instanceof Le||s instanceof ke)?t??i:i}function Qq(i,e={}){let{root:t=!0}=e;if(i instanceof ce&&(t||!i.sameParent)&&lN(i,{dnf:!0})){let s=new Map;for(let r of pA(i,{prune:n=>n instanceof le}))if(r instanceof me){let n=r.left,a=r.right;n instanceof B&&a instanceof R?s.set(n.sql(),[n,a]):a instanceof B&&n instanceof R&&s.set(a.sql(),[a,n])}if(0<s.size)for(let r of jn(i,[B])){let n=r.parent,a=s.get(r.sql()),[o,c]=a||[void 0,void 0];o!==void 0&&r!==o&&!(n instanceof _e&&n.args.expression instanceof Ze)&&r.replace(c.copy())}}return i}function Zq(i,e,t=28){let s=y=>{let I=y.indexOf("."),N=I===-1?0:I-y.length+1;return[BigInt(y.replace(".","")),N]},[r,n]=s(i),[a,o]=s(e),c=r*10n**BigInt(t+1)/a,u=c.toString().length-t,h;if(u<=0)h=c;else if(u===1)h=c/10n+(5n<=c%10n?1n:0n);else{let y=10n**BigInt(u),I=10n**BigInt(u-1)*5n;h=c/y+(I<=c%y?1n:0n)}let d=h.toString(),x=d.length+(n-o-t-1+u),f;return x<=0?f="0."+"0".repeat(-x)+d:d.length<=x?f=d+"0".repeat(x-d.length):f=d.slice(0,x)+"."+d.slice(x),f.includes(".")?f.replace(/\.?0+$/,"")||"0":f}function bM(i){return i instanceof A&&i.isNumber}function Kq(i){return i instanceof Ce&&RI(i)!==void 0}function eU(i){return PI.some(e=>i instanceof e)||Jn(i)}function Mf(i){return bI.some(e=>i instanceof e)||Jn(i)}function yI(i,e,t){let s=xA(i,e,t);if(i.toMillis()===s.toMillis())return[s,s.plus(fA(e))]}function tU(i){if(i.length===0)return[];let e=[...i].sort((s,r)=>s[0].toMillis()-r[0].toMillis()),t=[e[0]];for(let[s,r]of e.slice(1)){let n=t[t.length-1];s.toMillis()<=n[1].toMillis()?t[t.length-1]=[n[0],n[1].toMillis()<r.toMillis()?r:n[1]]:t.push([s,r])}return t}function oD(i,e,t){return Fe([new Me({this:i,expression:Bs(e[0],t)}),new De({this:i,expression:Bs(e[1],t)})],{copy:!1})}function sU(i,e,t,s,r){let n=yI(e,t,s);if(n)return oD(i,n,r)}function rU(i,e,t,s,r){let n=yI(e,t,s);if(n)return Fe([new De({this:i,expression:Bs(n[0],r)}),new Me({this:i,expression:Bs(n[1],r)})],{copy:!1})}function Rs(i){return i instanceof ot&&i.args.this||i instanceof R&&i.isNumber&&!AN(i)}function gN(i){return dA(i)||es(i)||AN(i)}function AN(i){return i instanceof R&&i.toValue()===0}function dA(i){return i instanceof ot&&!i.args.this}function es(i){return i instanceof Ze}function SI(i,e,t){if(i instanceof me||i instanceof _e)return AA(e===t);if(i instanceof st)return AA(e!==t);if(i instanceof Be)return AA(t<e);if(i instanceof Me)return AA(t<=e);if(i instanceof De)return AA(e<t);if(i instanceof $e)return AA(e<=t)}function cD(i){let e=so.fromISO(i,{zone:"utc"});return e.isValid?e:so.fromSQL(i,{zone:"utc"})}function iU(i){if(so.isDateTime(i))return i.toUTC().startOf("day");let e=typeof i=="string"?cD(i):so.fromMillis(i,{zone:"utc"});return e.isValid?e.startOf("day"):void 0}function OI(i){if(so.isDateTime(i))return i.toUTC();let e=typeof i=="string"?cD(i):so.fromMillis(i,{zone:"utc"});return e.isValid?e:void 0}function nU(i,e){if(i){if(e.isType("date"))return iU(i);if(e.isType(Array.from(O.TEMPORAL_TYPES)))return OI(i)}}function Ar(i){let e;if(i instanceof X&&i.to instanceof O)e=i.to;else if(i instanceof Is&&!i.args.format)e=new O({this:"date"});else return;let t,s=i.args.this;if(s instanceof R)t=s.name;else if(s instanceof X||s instanceof Is)t=Ar(s);else return;return nU(t,e)}function Jn(i){return Ar(i)!==void 0}function RI(i){if(i.args.this!==void 0)try{let e=parseInt(String(i.args.this.toValue())),t=i.text("unit").toLowerCase();return fA(t,e)}catch(e){if(e instanceof dr||e instanceof Error)return;throw e}}function EA(...i){let e;for(let t of i){if(t instanceof X){let s=t.to;e=$(s,O)||$(s,Ie)?s:void 0}else{let s=t.type;e=$(s,O)||$(s,Ie)?s:void 0}if(e)break}return e}function Bs(i,e){let t;!e||!e.isType(Array.from(O.TEMPORAL_TYPES))?t=i.hour===0&&i.minute===0&&i.second===0?"date":"datetime":t=e.args.this;let s=t==="date"?i.toISODate():i.toFormat("yyyy-MM-dd HH:mm:ss");return new X({this:R.string(s),to:new O({this:t})})}function fA(i,e=1){switch(i.toLowerCase()){case"year":return eo.fromObject({years:e});case"quarter":return eo.fromObject({months:3*e});case"month":return eo.fromObject({months:e});case"week":return eo.fromObject({weeks:e});case"day":return eo.fromObject({days:e});case"hour":return eo.fromObject({hours:e});case"minute":return eo.fromObject({minutes:e});case"second":return eo.fromObject({seconds:e});default:throw new dr(`Unsupported unit: ${i}`)}}function xA(i,e,t){switch(e.toLowerCase()){case"year":return i.set({month:1,day:1,hour:0,minute:0,second:0,millisecond:0});case"quarter":{let s=Math.floor((i.month-1)/3)*3+1;return i.set({month:s,day:1,hour:0,minute:0,second:0,millisecond:0})}case"month":return i.set({day:1,hour:0,minute:0,second:0,millisecond:0});case"week":return i.startOf("week").plus({days:t._constructor.WEEK_OFFSET||0});case"day":return i;default:throw new dr(`Unsupported unit: ${e}`)}}function aU(i,e,t){let s=xA(i,e,t);return s.toMillis()===i.toMillis()?i:s.plus(fA(e))}function AA(i){return i?Qe():gt()}var LM,wM,MM,DM,kM,_M,qM,UM,vM,FM,BM,$M,GM,YM,VM,HM,WM,jM,JM,XM,zM,QM,ZM,KM,eD,tD,sD,rD,iD,nD,aD,Ae;aD=[m],nD=[m],iD=[m],rD=[m],sD=[m],tD=[m],eD=[m],KM=[m],ZM=[m],QM=[m],zM=[m],XM=[m],JM=[m],jM=[m],WM=[m],HM=[m],VM=[m],YM=[m],GM=[gA(dr)],$M=[Di],BM=[Di],FM=[Di,gA(dr)],vM=[Di,gA(dr)],UM=[gA(dr)],qM=[Di],_M=[Di],kM=[gA(dr)],DM=[Di,gA(dr)],MM=[Di],wM=[Di],LM=[Di];var v=class v{constructor(e={}){Lt(Ae,5,this);this.dialect=void 0;this.annotateNewExpressions=void 0;this._annotator=void 0;let{dialect:t,annotateNewExpressions:s=!0}=e;this.dialect=se.getOrRaise(t),this.annotateNewExpressions=s,this._annotator=new xl({schema:dN(void 0,{dialect:this.dialect}),overwriteTypes:!1})}static get SIMPLIFIABLE(){return[q,g,Yt,Ne,hs]}static get COMPLEMENT_COMPARISONS(){return{[De.key]:Me,[Be.key]:$e,[$e.key]:Be,[Me.key]:De,[me.key]:st,[st.key]:me}}static get COMPLEMENT_SUBQUERY_PREDICATES(){return{[ys.key]:Ct,[Ct.key]:ys}}static get LT_LTE(){return[De,$e]}static get GT_GTE(){return[Be,Me]}static get COMPARISONS(){return[...v.LT_LTE,...v.GT_GTE,me,st,_e]}static get INVERSE_COMPARISONS(){return{[De.key]:Be,[Be.key]:De,[$e.key]:Me,[Me.key]:$e}}static get NONDETERMINISTIC(){return[fl,Df]}static get AND_OR(){return[ce,ze]}static get INVERSE_DATE_OPS(){return{[yt.key]:ke,[ts.key]:Le,[fr.key]:ke,[_i.key]:Le}}static get INVERSE_OPS(){return{...v.INVERSE_DATE_OPS,[Le.key]:ke,[ke.key]:Le}}static get NULL_OK(){return[Ps,Gs,ct]}static get CONCATS(){return[Gt,Mt]}static get DATETRUNC_BINARY_COMPARISONS(){return{[De.key]:(e,t,s,r,n)=>{let a=xA(t,s,r),o=t.toMillis()===a.toMillis()?t:a.plus(fA(s));return new De({this:e,expression:Bs(o,n)})},[Be.key]:(e,t,s,r,n)=>{let a=xA(t,s,r);return new Me({this:e,expression:Bs(a.plus(fA(s)),n)})},[$e.key]:(e,t,s,r,n)=>{let a=xA(t,s,r);return new De({this:e,expression:Bs(a.plus(fA(s)),n)})},[Me.key]:(e,t,s,r,n)=>{let a=aU(t,s,r);return new Me({this:e,expression:Bs(a,n)})},[me.key]:sU,[st.key]:rU}}static get DATETRUNC_COMPARISONS(){return new Set([it.key,...Object.keys(v.DATETRUNC_BINARY_COMPARISONS)])}static get DATETRUNCS(){return[bs,ro]}static get SAFE_CONNECTOR_ELIMINATION_RESULT(){return[Ee,ot]}static get JOINS(){return[["",""],["","inner"],["right",""],["right","outer"]]}simplify(e,t={}){let{constantPropagation:s=!1,coalesceSimplification:r=!1}=t,n=[],a=[];for(let o of e.walk({prune:c=>c instanceof ye?!0:!!c.meta[to]})){if(o.meta[to])continue;let c=o.getArgKey("group");if(c instanceof A&&o instanceof ee){let l=c.args.expressions;if(l){let u=new Set(l.map(x=>x.hash()));c.meta[to]=!0;let h=o.selects;for(let x of h)for(let f of x.walk({prune:y=>!!y.meta[to]}))if(u.has(f.hash())){x.meta[to]=!0;break}let d=o.args.having;if(d){for(let x of d.walk())if(u.has(x.hash())){d.meta[to]=!0;break}}}}if(o instanceof ye){let l=uN(o,u=>this._simplify(u,{constantPropagation:s,coalesceSimplification:r}));o===e&&(e=l)}else if(o instanceof at)n.push(o);else if(o instanceof oe){let l=o.args.matchCondition;l&&(l.meta[to]=!0),a.push(o)}}for(let o of n)Rs(o.args.this)&&o.pop();for(let o of a){let c=o.args.on,l=o.args.using,u=o.args.method,h=o.args.side||"",d=o.args.kind||"";c&&Rs(c)&&!l&&!u&&v.JOINS.some(([x,f])=>x===h&&f===d)&&(c.pop(),o.setArgKey("side",void 0),o.setArgKey("kind","cross"))}return e}_simplify(e,t){let{constantPropagation:s,coalesceSimplification:r}=t,n=[e],a=[];for(;0<n.length;){let c=n.pop();if(!c)continue;let l=c;if(!v.SIMPLIFIABLE.some(d=>l instanceof d)){l instanceof z&&this.simplify(l,{constantPropagation:s,coalesceSimplification:r});continue}let u=l.parent,h=l===e;l=this.rewriteBetween(l),l=this.uniqSort(l,{root:h}),l=this.absorbAndEliminate(l,{root:h}),l=this.simplifyConcat(l),l=this.simplifyConditionals(l),s&&(l=Qq(l,{root:h})),l!==c&&c?.replace(l);for(let d of l.iterExpressions({reverse:!0}))d.meta[to]||n.push(d);a.push([l,u])}let o=e;for(;0<a.length;){let[c,l]=a.pop(),u=c===e;for(let[d,x]of Object.entries(c.args))c?.setArgKey(d,x);let h=this.simplifyNot(c);h=uA(h),h=this.simplifyConnectors(h,{root:u}),h=this.removeComplements(h,{root:u}),r&&(h=this.simplifyCoalesce(h)),h.parent=l,h=this.simplifyLiterals(h,{root:u}),h=this.simplifyEquality(h),h=zq(h,this.dialect),h=this.simplifyDateTrunc(h),h=this.sortComparison(h),h=this.simplifyStartsWith(h),h!==c&&c.replace(h),o=h}return o}absorbAndEliminate(e,t={}){let{root:s=!0}=t;if(v.AND_OR.some(r=>e instanceof r)&&(s||!e.sameParent)){let r=e instanceof ce?ze:ce,n=Array.from(e.flatten()),a=new Set,o=new Map,c=new Map;for(let l of n){let u=this.genSql(l);if(a.add(u),!(l instanceof r)){let f=o.get(u);f||(f=[],o.set(u,f)),f.push(new Set([u]));continue}let h=new Set(Array.from(l.flatten()).map(f=>this.genSql(f)));for(let f of h){let y=o.get(f);y||(y=[],o.set(f,y)),y.push(h)}let[d,x]=l.unnestOperands();if(d&&x){if(d instanceof be&&d.args.this instanceof A){let f=`${this.genSql(d.args.this)}|${this.genSql(x)}`;c.has(f)||c.set(f,[]),c.get(f).push([l,x])}if(x instanceof be&&x.args.this instanceof A){let f=`${this.genSql(x.args.this)}|${this.genSql(d)}`;c.has(f)||c.set(f,[]),c.get(f).push([l,d])}}}for(let l of n){if(!(l instanceof r))continue;let[u,h]=l.unnestOperands();if(!u||!h)continue;if(u instanceof be&&u.args.this instanceof A&&a.has(this.genSql(u.args.this))){u.replace(r===ce?Qe():gt());continue}if(h instanceof be&&h.args.this instanceof A&&a.has(this.genSql(h.args.this))){h.replace(r===ce?Qe():gt());continue}let d=new Set(Array.from(l.flatten()).map(P=>this.genSql(P)));if(Array.from(d).some(P=>{let k=o.get(P);return k?k.some(_=>{if(d.size<=_.size)return!1;for(let W of _)if(!d.has(W))return!1;return!0}):!1})){l.replace(r===ce?gt():Qe());continue}let f=this.genSql(u),y=this.genSql(h),I=`${f}|${y}`,N=`${y}|${f}`;for(let[P,k]of[...c.get(I)||[],...c.get(N)||[]])l.replace(k),P.replace(k)}}return e}simplifyConcat(e){if(!v.CONCATS.some(l=>e instanceof l))return e;if(e instanceof wt){let[l]=e.args.expressions??[];if(!(l instanceof A)||!l.isString)return e}let t,s,r,n,a;if(e instanceof wt){let[l,...u]=e.args.expressions??[];t=l,s=u,r=t.name,n=wt,a={}}else s=e.args.expressions??[],r="",n=Gt,a={safe:e.args.safe,coalesce:e.args.coalesce};let o=[],c=[];for(let l of 0<s.length?s:Array.from(e.flatten()))l instanceof A&&(l.isString?c.push(l.name):(0<c.length&&(o.push(R.string(c.join(r))),c=[]),o.push(l)));return 0<c.length&&o.push(R.string(c.join(r))),o.length===1&&o[0].isString?o[0]:n===wt&&t?new wt({expressions:[t,...o]}):e instanceof Mt?o.reduce((l,u)=>new Mt({this:l,expression:u})):new n({expressions:o,...a})}simplifyConditionals(e){if(e instanceof nt){let t=e.args.this;for(let s of e.args.ifs||[]){let r=s.args.this;if(t&&(r=r.replace(t.pop().eq(r))),Rs(r))return s.getArgKey("true");if(gN(r)){s.pop();let n=e.args.ifs;if(!n||n.length===0)return e.args.default||pe()}}}else if(e instanceof le&&!(e.parent instanceof nt)){let t=e.args.this;if(Rs(t))return ft(e.args.true,A)??e;if(gN(t))return ft(e.args.false,A)??pe()}return e}simplifyNot(e){if(e instanceof be){let t=e.args.this;if(es(t))return Fe([pe(),Qe()],{copy:!1});if(t instanceof A){let s=v.COMPLEMENT_COMPARISONS[t._constructor.key];if(s){let r=t.args.expression;if(r instanceof A){let n=v.COMPLEMENT_SUBQUERY_PREDICATES[r._constructor.key];n&&(r=new n({this:r.args.this}))}return new s({this:t.args.this,expression:r})}}if(t instanceof Oe){let s=t.unnest();if(s instanceof ce)return ki(Kt([xr(s.args.this!==void 0?EN(s.args.this):void 0,{copy:!1}),xr(s.args.expression!==void 0?EN(s.args.expression):void 0,{copy:!1})],{copy:!1}),{copy:!1});if(s instanceof ze)return ki(Fe([xr(s.args.this,{copy:!1}),xr(s.args.expression!==void 0?EN(s.args.expression):void 0,{copy:!1})],{copy:!1}),{copy:!1});if(es(s))return Fe([pe(),Qe()],{copy:!1})}if(Rs(t))return gt();if(dA(t))return Qe();if(t instanceof be&&this.dialect._constructor.SAFE_TO_ELIMINATE_DOUBLE_NEGATION){let s=t.args.this;if(Sl(s,"boolean"))return s??e}}return e}simplifyConnectors(e,t={}){let{root:s=!0}=t;if(e instanceof Ee){let r=e.parent;if(e=this.flatSimplify(e,(n,a,o)=>{if(n instanceof ce)return dA(a)||dA(o)?gt():AN(a)||AN(o)?gt():es(a)&&es(o)||es(a)&&Rs(o)||Rs(a)&&es(o)?pe():Rs(a)&&Rs(o)?Qe():Rs(a)?o:Rs(o)?a:this.simplifyComparison(n,a,o,{or:!1});if(n instanceof ze)return Rs(a)||Rs(o)?Qe():es(a)&&es(o)||es(a)&&gN(o)||gN(a)&&es(o)?pe():dA(a)?o:dA(o)?a:this.simplifyComparison(n,a,o,{or:!0})},{root:s}),!v.SAFE_CONNECTOR_ELIMINATION_RESULT.some(n=>e instanceof n)&&!e.isType("boolean")){let n=r;for(;!(n instanceof Ee);){if(!(n instanceof Oe)){e=Fe([e,Qe()],{copy:!1});break}n=n.parent}}}return e}simplifyComparison(e,t,s,r){let{or:n=!1}=r;if(v.COMPARISONS.some(a=>t instanceof a)&&v.COMPARISONS.some(a=>s instanceof a)){let a=t.args.this,o=t.args.expression,c=s.args.this,l=s.args.expression;if(!a||!o||!c||!l)return;let u=[a,o],h=[c,l],d=new Map(u.map(N=>[ft(N,A)?.hash(),N])),x=new Map(h.map(N=>[ft(N,A)?.hash(),N])),f=new Set([...d.keys()].filter(N=>x.has(N))),y=[...f].map(N=>d.get(N)).filter(N=>!Mf(N)&&!ft(N,A)?.find(v.NONDETERMINISTIC)),I=new Set(y.map(N=>ft(N,A)?.hash()));if(0<f.size&&0<y.length){let N=u.filter(ve=>!I.has(ft(ve,A)?.hash())),P=h.filter(ve=>!I.has(ft(ve,A)?.hash()));if(N.length===0||P.length===0)return e;let k,_;try{k=II(N),_=II(P)}catch{return e}if(!(k instanceof A)||!(_ instanceof A))return;let W=k,he=_,ne,Y;if(W.isNumber&&he.isNumber)ne=W.toValue(),Y=he.toValue();else if(W.isString&&he.isString)ne=W.name,Y=he.name;else{let ve=Ar(W);if(!ve)return;let Xt=Ar(he);if(!Xt)return;ne=OI(ve),Y=OI(Xt)}let He=[[[t,ne],[s,Y]],[[s,Y],[t,ne]]];for(let[[ve,Xt],[Ft,Li]]of He){let zt=typeof Xt=="number"?Xt:so.isDateTime(Xt)?Xt.toMillis():String(Xt),lt=typeof Li=="number"?Li:so.isDateTime(Li)?Li.toMillis():String(Li);if(v.LT_LTE.some(ps=>ve instanceof ps)&&v.LT_LTE.some(ps=>Ft instanceof ps))return n?lt<zt?t:s:zt<=lt?t:s;if(v.GT_GTE.some(ps=>ve instanceof ps)&&v.GT_GTE.some(ps=>Ft instanceof ps))return n?zt<lt?t:s:lt<=zt?t:s;if(!n){if(ve instanceof De&&v.GT_GTE.some(ps=>Ft instanceof ps)){if(zt<=lt)return gt()}else if(ve instanceof Be&&v.LT_LTE.some(ps=>Ft instanceof ps)){if(lt<=zt)return gt()}else if(ve instanceof me){if(Ft instanceof De)return lt<=zt?gt():ve;if(Ft instanceof $e)return lt<zt?gt():ve;if(Ft instanceof Be)return zt<=lt?gt():ve;if(Ft instanceof Me)return zt<lt?gt():ve;if(Ft instanceof st)return zt===lt?gt():ve}}}}}}flatSimplify(e,t,s){let{root:r}=s;if(!r&&e.sameParent)return e;let n=[],a=Array.from(e.flatten({unnest:!1})),o=a.length;for(;a.length;){let c=a.shift(),l=!1;for(let u of a){let h=t(e,c,u);if(h&&h!==e){a.splice(a.indexOf(u),1),a.unshift(h),l=!0;break}}l||n.push(c)}return n.length<o?n.reduce((c,l)=>new e._constructor({this:c,expression:l})):e}removeComplements(e,t={}){let{root:s=!0}=t;if(v.AND_OR.some(r=>e instanceof r)&&(s||!e.sameParent)){let r=Array.from(e.flatten()),n=new Set(r.map(a=>a.hash()));for(let a of r)if(a instanceof be){let o=a.args.this;if(o&&n.has(o.hash())&&e.meta.nonnull===!0)return e instanceof ce?gt():Qe()}}return e}simplifyCoalesce(e){if(e instanceof rt&&(e.args.expressions?.length===0||eU(e.args.this))&&!(e.parent instanceof us))return e.args.this;if(this.dialect._constructor.COALESCE_COMPARISON_NON_STANDARD||!v.COMPARISONS.some(l=>e instanceof l))return e;let t,s,r=e.args.this,n=e.args.expression;if(r instanceof rt)t=r,s=n;else if(n instanceof rt)t=n,s=r;else return e;if(!Mf(s))return e;let a=-1;for(let l=0;l<(t.args.expressions?.length??0);l++){let u=t.args.expressions?.[l];if(Mf(u)){a=l;break}}if(a===-1)return e;let o=t.args.expressions?.[a];t.setArgKey("expressions",t.args.expressions?.slice(0,a));let c=0<(t.args.expressions?.length??0)?t:t.args.this;return ki(Kt([Fe([xr(c?.is(pe()),{copy:!1}),e.copy()],{copy:!1}),Fe([c?.is(pe()),new e._constructor({this:o.copy(),expression:s.copy()})],{copy:!1})],{copy:!1}),{copy:!1})}simplifyLiterals(e,t={}){let{root:s=!0}=t;if(e instanceof q&&!(e instanceof Ee))return this.flatSimplify(e,(r,n,a)=>this.simplifyBinary(r,n,a),{root:s});if(e instanceof It&&e.args.this instanceof It)return e.args.this.args.this??e;if(v.INVERSE_DATE_OPS[e._constructor.key]){let r=e.args.this;if(r instanceof A&&e instanceof Cs)return this.simplifyBinary(e,r,e.interval())||e}return e}simplifyIntegerCast(e){if(!(e instanceof X))return e;let t=e.args.this,s;if(t instanceof X?s=this.simplifyIntegerCast(t):s=t,s instanceof A&&s.isInteger){let r=s.toValue(),n=e.args.to;if(!n)return e;if(n instanceof A&&(v.TINYINT_MIN<=r&&r<=v.TINYINT_MAX&&n.args.this&&O.SIGNED_INTEGER_TYPES.has(n.args.this)||v.UTINYINT_MIN<=r&&r<=v.UTINYINT_MAX&&n.args.this&&O.UNSIGNED_INTEGER_TYPES.has(n.args.this)))return s}return e}simplifyBinary(e,t,s){if(v.COMPARISONS.some(r=>e instanceof r)&&(t=this.simplifyIntegerCast(t),s=this.simplifyIntegerCast(s)),e instanceof _e){let r,n;if(s instanceof be?(r=s.args.this,n=!0):(r=s,n=!1),es(r)){if(t instanceof R)return n?Qe():gt();if(es(t))return n?gt():Qe()}}else{if(v.NULL_OK.some(r=>e instanceof r))return;if((es(t)||es(s))&&e.parent instanceof le)return pe()}if(t.isNumber&&s.isNumber){let r=t.toValue(),n=s.toValue(),a=x=>{let f=x.match(/[eE]([+-]?\d+)/),y=f?parseInt(f[1]):0,I=x.replace(/[eE][+-]?\d+/,"").match(/\.(\d+)/),N=I?I[1].length:0;return Math.max(0,N-y)},o=String(t.args.this??""),c=String(s.args.this??""),l=a(o),u=a(c),h=(x,f)=>0<f?x.toFixed(f):String(x);if(e instanceof Le)return R.number(h(r+n,Math.max(l,u)));if(e instanceof Ns)return R.number(h(r*n,l+u));if(e instanceof ke)return t.parent===s.parent?R.number(h(r-n,Math.max(l,u))):void 0;if(e instanceof mt){let x=!o.includes(".")&&!o.toLowerCase().includes("e"),f=!c.includes(".")&&!c.toLowerCase().includes("e");return x&&f||t.parent!==s.parent?void 0:R.number(Zq(o,c))}let d=SI(e,r,n);if(d)return d}else if(t.isString&&s.isString){let r=t.args.this,n=s.args.this,a=SI(e,r,n);if(a)return a}else if(Jn(t)&&s instanceof Ce){let r=Ar(t),n=RI(s);if(r&&n!==void 0){if(e instanceof Le||e instanceof yt||e instanceof fr)return Bs(r.plus(n),EA(t));if(e instanceof ke||e instanceof ts||e instanceof _i)return Bs(r.minus(n),EA(t))}}else if(t instanceof Ce&&Jn(s)){let r=RI(t),n=Ar(s);if(r!==void 0&&n&&e instanceof Le)return Bs(n.plus(r),EA(s))}else if(Jn(t)&&Jn(s)&&e instanceof Ne){let r=Ar(t),n=Ar(s);if(r&&n){let a=SI(e,r.toMillis(),n.toMillis());if(a)return a}}}simplifyEquality(e){if(v.COMPARISONS.some(t=>e instanceof t)){let t=e.args.this,s=e.args.expression;if(!(t instanceof A)||!(s instanceof A))return e;let r=v.INVERSE_OPS[t._constructor.key];if(!r)return e;let n,a;if(s.isNumber)n=bM,a=bM;else if(Jn(s))n=Jn,a=Kq;else return e;let o,c;if(v.INVERSE_DATE_OPS[t._constructor.key]?(o=t.args.this,c=t.interval()):(o=t.args.this,c=t.args.expression),!o||!c)return e;if(!(!n(o)&&a(c)))if(!n(c)&&a(o))[o,c]=[c,o];else return e;return new e._constructor({this:o,expression:new r({this:s,expression:c})})}return e}isDatetruncPredicate(e,t){return v.DATETRUNCS.some(s=>e instanceof s)&&Jn(t)}simplifyDateTrunc(e){let t=e._constructor;if(v.DATETRUNCS.some(s=>e instanceof s)){let s=e,r=s.args.this,n=r&&EA(r),a=Ar(r);if(a&&s.args.unit){let o=s.args.unit.name.toLowerCase();return Bs(xA(a,o,this.dialect),n)}}else if(!v.DATETRUNC_COMPARISONS.has(t.key))return e;if(e instanceof q){let s=e.args.this,r=e.args.expression;if(!this.isDatetruncPredicate(s,r))return e;let n=s.args.unit.name.toLowerCase(),a=s.args.this,o=Ar(r);return o&&v.DATETRUNC_BINARY_COMPARISONS[t.key]?.(a,o,n,this.dialect,EA(r))||e}if(e instanceof it){let s=e.args.this,r=e.args.expressions;if(r&&r.every(n=>this.isDatetruncPredicate(s,n))){let n=s.args.unit.name.toLowerCase(),a=[];for(let l of r){let u=Ar(l);if(!u)return e;let h=yI(u,n,this.dialect);h&&a.push(h)}if(a.length===0)return e;let o=tU(a),c=EA(...r.filter(l=>l instanceof A));return Kt(o.map(l=>oD(s,l,c)),{copy:!1})}}return e}sortComparison(e){if(Object.values(v.COMPLEMENT_COMPARISONS).some(t=>e instanceof t)){let t=e.args.this,s=e.args.expression,r=t instanceof B,n=s instanceof B,a=Mf(t),o=Mf(s);if(r&&!n||o&&!a||s instanceof $s)return e;if(n&&!r||a&&!o||mI(s)<mI(t)){let c=v.INVERSE_COMPARISONS[e._constructor.key]||e._constructor;return new c({this:s,expression:t})}}return e}simplifyStartsWith(e){return e instanceof Tl&&e.args.this instanceof A&&e.args.expression instanceof A&&e.args.this.isString&&e.args.expression.isString?e.args.this.name.startsWith(e.args.expression.name)?Qe():gt():e}rewriteBetween(e){if(!(e instanceof ss))return e;let s=e.parent instanceof be,r=e.args.this,n=e.args.low,a=e.args.high;if(!(r instanceof A)||!(n instanceof A)||!(a instanceof A))return e;let o=Fe([new Me({this:r.copy(),expression:n}),new $e({this:r.copy(),expression:a})],{copy:!1});return s&&(o=ki(o,{copy:!1})),o}uniqSort(e,t={}){let{root:s=!0}=t;if(!(e instanceof Ee)||!s&&e.sameParent)return e;let r=Array.from(e.flatten()),n,a,o;if(e instanceof qi)n=CI,a=void 0,o=r.map(c=>[this.genSql(c),c]);else{n=e instanceof ce?Fe:Kt,a=new Map;for(let c of r){let l=this.genSql(c);a.has(l)||a.set(l,c)}o=Array.from(a.entries())}for(let c=1;c<o.length;c++)if(o[c][0]<o[c-1][0]){let l=o.sort((u,h)=>u[0]<h[0]?-1:h[0]<u[0]?1:0);return e=n(l.map(([,u])=>u),{copy:!1}),e}if(a&&a.size<r.length){let c=r[0];a.size===1?c instanceof A&&(e=Fe([c,Qe()],{copy:!1})):e=n(Array.from(a.values()),{copy:!1})}return e}genSql(e){return mI(e)}};Ae=Bt(null),S(Ae,10,"SIMPLIFIABLE",aD,v),S(Ae,10,"COMPLEMENT_COMPARISONS",nD,v),S(Ae,10,"COMPLEMENT_SUBQUERY_PREDICATES",iD,v),S(Ae,10,"LT_LTE",rD,v),S(Ae,10,"GT_GTE",sD,v),S(Ae,10,"COMPARISONS",tD,v),S(Ae,10,"INVERSE_COMPARISONS",eD,v),S(Ae,10,"NONDETERMINISTIC",KM,v),S(Ae,10,"AND_OR",ZM,v),S(Ae,10,"INVERSE_DATE_OPS",QM,v),S(Ae,10,"INVERSE_OPS",zM,v),S(Ae,10,"NULL_OK",XM,v),S(Ae,10,"CONCATS",JM,v),S(Ae,10,"DATETRUNC_BINARY_COMPARISONS",jM,v),S(Ae,10,"DATETRUNC_COMPARISONS",WM,v),S(Ae,10,"DATETRUNCS",HM,v),S(Ae,10,"SAFE_CONNECTOR_ELIMINATION_RESULT",VM,v),S(Ae,10,"JOINS",YM,v),S(Ae,1,"absorbAndEliminate",GM,v),S(Ae,1,"simplifyConcat",$M,v),S(Ae,1,"simplifyConditionals",BM,v),S(Ae,1,"simplifyNot",FM,v),S(Ae,1,"simplifyConnectors",vM,v),S(Ae,1,"removeComplements",UM,v),S(Ae,1,"simplifyCoalesce",qM,v),S(Ae,1,"simplifyLiterals",_M,v),S(Ae,1,"simplifyEquality",kM,v),S(Ae,1,"simplifyDateTrunc",DM,v),S(Ae,1,"sortComparison",MM,v),S(Ae,1,"simplifyStartsWith",wM,v),S(Ae,1,"uniqSort",LM,v),bt(Ae,v),Lt(Ae,3,v),v.TINYINT_MIN=-128,v.TINYINT_MAX=127,v.UTINYINT_MIN=0,v.UTINYINT_MAX=255;var hA=v;function mI(i,e={}){return new NI().gen(i,e)}var NI=class{constructor(){this.stack=[];this.sqls=[]}gen(e,t={}){let{comments:s=!1}=t;for(this.stack=[e],this.sqls=[];0<this.stack.length;){let r=this.stack.pop();if(r instanceof A){s&&r.comments&&0<r.comments.length&&this.stack.push(` /*${r.comments.join(",")}*/`);let n=`${r._constructor.key}Sql`;if(typeof this[n]=="function")this[n].call(this,r);else if(r instanceof g)this.function(r);else{let a=r._constructor.key.toUpperCase();this.stack.push(this.args(r)?`${a} `:a)}}else if(Array.isArray(r)){let n=!1;for(let a=r.length-1;0<=a;a--){let o=r[a];if(o!=null)if(Array.isArray(o)&&typeof o[0]=="string"&&o[0].startsWith(":")){let[c,l]=o;this.stack.push(l),this.stack.push(c),n=!1}else Array.isArray(o)?(this.stack.push(o),this.stack.push(","),n=!0):(this.stack.push(o),this.stack.push(","),n=!0)}n&&this.stack.pop()}else r!=null&&this.sqls.push(String(r))}return this.sqls.join("")}addDql(e){this.binary(e," + ")}aliasSql(e){this.stack.push(e.args.alias," AS ",e.args.this)}andSql(e){this.binary(e," AND ")}anonymousSql(e){let t=e.args.this,s;if(typeof t=="string")s=t.toUpperCase();else if(t instanceof U){let r=t.args.this;s=t.args.quoted?`"${r}"`:String(r).toUpperCase()}else throw new Error(`Anonymous.args.this expects a string or an Identifier, got '${t?._constructor?.name||typeof t}'.`);this.stack.push(")",e.args.expressions||[],"(",s)}betweenSql(e){this.stack.push(e.args.high," AND ",e.args.low," BETWEEN ",e.args.this)}booleanSql(e){this.stack.push(e.args.this?"TRUE":"FALSE")}bracketSql(e){this.stack.push("]",e.args.expressions||[],"[",e.args.this)}columnSql(e){let t=e.parts;for(let s=t.length-1;0<=s;s--)this.stack.push(t[s],".");this.stack.pop()}dataTypeSql(e){this.args(e,1);let t=e.args.this,s=typeof t=="string"?t:String(t);this.stack.push(`${s} `)}divSql(e){this.binary(e," / ")}dotSql(e){this.binary(e,".")}eqSql(e){this.binary(e," = ")}fromSql(e){this.stack.push(e.args.this,"FROM ")}gtSql(e){this.binary(e," > ")}gteSql(e){this.binary(e," >= ")}identifierSql(e){let t=e.args.this,s=String(t);this.stack.push(e.args.quoted?`"${s}"`:s)}iLikeSql(e){this.binary(e," ILIKE ")}inSql(e){this.stack.push(")"),this.args(e,1),this.stack.push("("," IN ",e.args.this)}intdivSql(e){this.binary(e," DIV ")}isSql(e){this.binary(e," IS ")}likeSql(e){this.binary(e," LIKE ")}literalSql(e){let t=e.args.this;this.stack.push(e.isString?`'${t}'`:String(t))}ltSql(e){this.binary(e," < ")}lteSql(e){this.binary(e," <= ")}modSql(e){this.binary(e," % ")}mulSql(e){this.binary(e," * ")}negSql(e){this.unary(e,"-")}neqSql(e){this.binary(e," <> ")}notSql(e){this.unary(e,"NOT ")}nullSql(e){this.stack.push("NULL")}orSql(e){this.binary(e," OR ")}parenSql(e){this.stack.push(")",e.args.this,"(")}subSql(e){this.binary(e," - ")}subquerySql(e){this.args(e,2);let t=e.args.alias;t&&this.stack.push(t),this.stack.push(")",e.args.this,"(")}tableSql(e){this.args(e,4);let t=e.args.alias;t&&this.stack.push(t);let s=e.parts;for(let r=s.length-1;0<=r;r--)this.stack.push(s[r],".");this.stack.pop()}tableAliasSql(e){let t=e.columns;t&&0<t.length&&this.stack.push(")",t,"("),this.stack.push(e.args.this||[]," AS ")}varSql(e){this.stack.push(String(e.args.this))}binary(e,t){this.stack.push(e.args.expression,t,e.args.this)}unary(e,t){this.stack.push(e.args.this,t)}function(e){this.stack.push(")",Object.values(e.args),"(",e._constructor.sqlName())}args(e,t=0){let s=[],r=Array.from(e._constructor.availableArgs||[]),n=0<t?r.slice(t):r;for(let a of n){let o=e.getArgKey(a);o!=null&&s.push([`:${a}`,o])}return 0<s.length?(this.stack.push(s),!0):!1}};function LI(i,e,t){let s=oU(e,t,1),r=M(s,0),n=r?` Did you mean ${r}?`:"";throw new Error(`Unknown ${i} '${e}'.${n}`)}function M(i,e){if(Array.isArray(i)){let r=e<0?i.length+e:e;return 0<=r&&r<i.length?i[r]:void 0}let t=[...i],s=e<0?t.length+e:e;return 0<=s&&s<t.length?t[s]:void 0}function EN(i){return typeof i=="boolean"||typeof i=="number"?String(i):i}function J(i){return i===void 0?[]:i instanceof A?[i]:typeof i!="string"&&Pf(i)?[...i]:[i]}function kf(i,e={}){let{sep:t=", "}=e,s=[];for(let r of i)r&&s.push(r);return s.join(t??", ")}function oU(i,e,t,s=.6){let r=[];for(let n of e){let a=cU(i,n);s<=a&&r.push({match:n,ratio:a})}return r.sort((n,a)=>a.ratio-n.ratio),r.slice(0,t).map(n=>n.match)}function cU(i,e){let t=e.length<i.length?i:e,s=e.length<i.length?e:i;if(t.length===0)return 1;let r=pU(s,t);return(t.length-r)/t.length}function pU(i,e){let t=[];for(let s=0;s<=e.length;s++)t[s]=[s];for(let s=0;s<=i.length;s++)t[0][s]=s;for(let s=1;s<=e.length;s++)for(let r=1;r<=i.length;r++)e.charAt(s-1)===i.charAt(r-1)?t[s][r]=t[s-1][r-1]:t[s][r]=Math.min(t[s-1][r-1]+1,t[s][r-1]+1,t[s-1][r]+1);return t[e.length][i.length]}function hD(i){return i.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function uN(i,e){let t=i;for(;;){let s=pD(t);t=e(t);let r=pD(t);if(s===r)break}return t}function pD(i){return i instanceof A?i.sql():JSON.stringify(i)}function gD(i){let e=[],t=new Map(i);for(let[s,r]of Array.from(i.entries()))for(let n of Array.from(r))t.has(n)||t.set(n,new Set);for(;0<t.size;){let s=new Set;for(let[r,n]of Array.from(t.entries()))n.size===0&&s.add(r);if(s.size===0)throw new Error("Cycle error");for(let r of Array.from(s))t.delete(r);for(let r of Array.from(t.values()))for(let n of Array.from(s))r.delete(n);e.push(...Array.from(s).sort())}return e}function Za(i,e){let t=new Set(i);if(!t.has(e))return e;let s=2,r=`${e}_${s}`;for(;t.has(r);)s++,r=`${e}_${s}`;return r}function ED(i){return lU(i,e=>{let t=Number(e);return Number.isInteger(t)})}function lU(i,e){try{return e(i)}catch{return!1}}function fN(i){let e=0;return()=>`${i}${e++}`}function AD(i,e,t,s={}){let{fillFromStart:r=!0}=s,n=i.split(e),a=Math.max(0,t-n.length);return r?[...Array(a).fill(void 0),...n]:[...n,...Array(a).fill(void 0)]}function TA(i){try{if(typeof i!="object"||i===null||i.constructor!==Object)return 0;let e=Object.values(i);return e.length===0?1:1+TA(e[0])}catch{return 0}}function II(i){for(let e of i)return e;throw new Error("Iterable is empty")}function dD(i){if(typeof i=="boolean"||i===void 0)return i;let e=i.toLowerCase();return e==="true"||e==="1"?!0:e==="false"||e==="0"?!1:i}function SA(i){return uD.fromISO(i).isValid&&/^\d{4}-\d{2}-\d{2}$/.test(i)}function _f(i){return uD.fromSQL(i).isValid}var uU=new Set(["day","week","month","quarter","year","year_month"]);function mA(i){return i!==void 0&&uU.has(i.name.toLowerCase())}var lD=class{constructor(e,t){this._keys=new Set(e),this._value=t}get(e){return this._keys.has(e)?this._value:void 0}has(e){return this._keys.has(e)}get size(){return this._keys.size}*[Symbol.iterator](){for(let e of Array.from(this._keys))yield[e,this._value]}*entries(){for(let e of Array.from(this._keys))yield[e,this._value]}keys(){return this._keys.values()}*values(){for(let e of Array.from(this._keys))yield this._value}forEach(e,t){for(let s of Array.from(this._keys))e.call(t,this._value,s,this)}clear(){throw new Error("Method not supported")}delete(e){throw new Error("Method not supported")}set(e,t){throw new Error("Method not supported")}get[Symbol.toStringTag](){return"SingleValuedMapping"}};function TN(i,e,t,s){let r=[...e];if(!t||r.length!==1)return r;let n=r[0];i.type||gs(i,{dialect:s?.dialect});let a=i.type;if(a?.args.this!=="unknown"&&a?.args.this!=="array")return r;n.type||gs(n,{dialect:s?.dialect});let o=n.type;if(o?.args.this&&O.INTEGER_TYPES?.has(o.args.this)){let c=new Le({this:n,expression:ml(t)});return[xN(c)]}return r}function xD(i,e){return i instanceof A?e==="name"?i.name:e==="sql"?i.sql():e(i):i}function SN(i){return i.replace(/([A-Z])/g,"_$1").toUpperCase()}var hU=new Set(["EPOCH_SECOND","EPOCH_MILLISECOND","EPOCH_MICROSECOND","EPOCH_NANOSECOND","NANOSECOND"]);function gs(i,e={}){let{schema:t,expressionMetadata:s,coercesTo:r,dialect:n,overwriteTypes:a=!0}=e,o=dN(t,{dialect:n});return new xl({schema:o,expressionMetadata:s,coercesTo:r,overwriteTypes:a}).annotate(i)}function fD(i,e){let t=i.name,s=SA(t);return s&&mA(e)?"date":s||_f(t)?"datetime":"unknown"}function TD(i,e){if(!mA(e))return"datetime";let t=i.type?.args.this;return typeof t=="string"?t:t instanceof U?t.args.this:"unknown"}function gU(i){return(e,t)=>i(t,e)}function EU(i){let e=new nA;for(let[[t,s],r]of i)e.set(t,s,r),e.set(s,t,gU(r));return e}var SD,mD,OD,qf;OD=[m],mD=[m],SD=[m];var Xn=class Xn{constructor(e){this.schema=void 0;this.dialect=void 0;this.overwriteTypes=void 0;this.expressionMetadata=void 0;this.coercesTo=void 0;this.binaryCoercions=void 0;this.visited=void 0;this.nullExpressions=void 0;this.supportsNullType=void 0;this.setopColumnTypes=void 0;this.scopeSelects=void 0;let{schema:t,expressionMetadata:s,coercesTo:r,binaryCoercions:n,overwriteTypes:a=!0}=e;if(this.schema=t,this.dialect=t.dialect||new se,this.overwriteTypes=a,this.expressionMetadata=s??this.dialect._constructor.EXPRESSION_METADATA,r)this.coercesTo=r;else{let o=this.dialect._constructor.COERCES_TO;o instanceof Map&&0<o.size?this.coercesTo=o:!(o instanceof Map)&&0<Object.keys(o).length?this.coercesTo=new Map(Object.entries(o).map(([c,l])=>[c,new Set(l)])):this.coercesTo=Xn.COERCES_TO}this.binaryCoercions=n??Xn.BINARY_COERCIONS,this.visited=new Set,this.nullExpressions=new Map,this.supportsNullType=this.dialect._constructor.SUPPORTS_NULL_TYPE,this.setopColumnTypes=new Map,this.scopeSelects=new Map}static get NESTED_TYPES(){return new Set(["array"])}static get COERCES_TO(){let e=new Map,t=["text","nvarchar","varchar","nchar","char"],s=["decfloat","double","float","bigdecimal","decimal","bigint","int","smallint","tinyint"],r=["timestampltz","timestamptz","timestamp","datetime","date"];for(let n of[t,s,r]){let a=new Set;for(let o of n)e.set(o,new Set(a)),a.add(o)}return e}static get BINARY_COERCIONS(){return EU((()=>{let e=new nA;for(let t of O.TEXT_TYPES)e.set(t,"interval",(s,r)=>fD(s,r.unit));for(let t of O.TEXT_TYPES)for(let s of O.NUMERIC_TYPES)e.set(t,s,(r,n)=>{let a=r.type?.args.this;return O.NUMERIC_TYPES.has(a)?a:n.type?.args.this});return e.set("date","interval",(t,s)=>TD(t,s.unit)),e})())}clear(){this.visited.clear(),this.nullExpressions.clear(),this.setopColumnTypes.clear(),this.scopeSelects.clear()}annotate(e,t={}){let{annotateScope:s=!0}=t;if(s)for(let n of cA(e))this.annotateScope(n);this.annotateExpression(e);let r=this.dialect._constructor.DEFAULT_NULL_TYPE;for(let[,n]of this.nullExpressions)n.type=r;return e}annotateScope(e){if(this.schema instanceof Uf)for(let t of e.tableColumns){let s=e.sources.get(t.name);if(s instanceof V){let r=this.schema.find(s,{raiseOnMissing:!1,ensureDataTypes:!0});if(typeof r!="object"||!r)continue;let n=new O({this:"struct",expressions:Object.entries(r).map(([a,o])=>new Ie({this:Z(a),kind:o})),nested:!0});this.setType(t,n)}else s instanceof wi&&s.expression instanceof z&&(s.expression.meta.queryType||O.build("unknown")).isType("struct")&&this.setType(t,s.expression.meta.queryType)}if(this.annotateExpression(e.expression,e),this.dialect._constructor.QUERY_RESULTS_ARE_STRUCTS&&e.expression instanceof z){let t=new O({this:"struct",expressions:e.expression.selects.map(s=>new Ie({this:Z(s.outputName),kind:s.type instanceof A?s.type.name:s.type||""})),nested:!0});t.args.expressions?.some(s=>{let r=s.args.kind;return r?typeof r=="string"?r==="unknown":r.isType("unknown"):!0})||(e.expression.meta.queryType=t)}}getScopeSelects(e){let t=this.scopeSelects.get(e);if(t!==void 0)return t;let s=new Map;for(let[r,n]of e.sources){if(!(n instanceof wi))continue;let a=n.expression;if(a instanceof Nt&&!(a instanceof zn)){let o=[];if(a instanceof St){let l=a.args.this;l instanceof rs&&(o=[l.args.this])}else if(a instanceof ge)o=[a];else{let l=M(a.args.expressions??[],0);l&&(o=l instanceof A?l.args.expressions:[])}if(o.length===0)continue;let c=a.aliasColumnNames;if(a instanceof ge&&a.type instanceof A&&a.type.isType("struct")){let l={};for(let u of a.type.args.expressions||[]){let h=u.name,d=u.args.kind;h&&(l[h]=d)}s.set(r,l)}else{let l={};for(let u=0;u<c.length&&u<o.length;u++){let h=o[u].type;l[c[u]]=$(h,O)||$(h,Ie)?h:void 0}s.set(r,l)}}else if(a instanceof Xe&&$(a.left,z)&&$(a.right,z)&&a.left.selects.length===a.right.selects.length)s.set(r,this.getSetopColumnTypes(a));else{let o={};for(let c of a.selects){let l=c.type;o[c.aliasOrName]=$(l,O)||$(l,Ie)?l:void 0}s.set(r,o)}}return this.scopeSelects.set(e,s),s}getSetopColumnTypes(e){let t=this.setopColumnTypes.get(e);if(t!==void 0)return t;let s={},r=e.left,n=e.right;if(!$(r,z)||!$(n,z)||!r.selects.length||!n.selects.length||r.selects.length!==n.selects.length)return s;for(let a of e.walk({prune:o=>!(o instanceof Xe)&&!(o instanceof Te)})){if(!(a instanceof Xe))continue;let o,c=a.left,l=a.right;if(te(c,z),te(l,z),a.args.byName){let u={};for(let h of l.selects){let d=h.type;u[h.aliasOrName]=$(d,O)||$(d,Ie)?d:void 0}o={};for(let h of c.selects){let d=h.type,x=($(d,O)?d:void 0)??"unknown",f=u[h.aliasOrName]??"unknown";o[h.aliasOrName]=this.maybeCoerce(x,f)}}else{o={};for(let u=0;u<c.selects.length;u++){let h=c.selects[u],d=l.selects[u],x=h.type,f=d.type,y=($(x,O)?x:void 0)??"unknown",I=($(f,O)?f:void 0)??"unknown";o[h.aliasOrName]=this.maybeCoerce(y,I)}}for(let[u,h]of Object.entries(o)){let d=s[u]??"null";s[u]=this.maybeCoerce(h,d)}}return this.setopColumnTypes.set(e,s),s}annotateExpression(e,t){let s=[[e,!1]];for(;0<s.length;){let[r,n]=s.pop();if(this.visited.has(r)||!this.overwriteTypes&&r.type&&!r.isType("unknown"))continue;if(!n){s.push([r,!0]);for(let o of r.iterExpressions())s.push([o,!1]);continue}if(t&&r instanceof B&&r.args.table){let o,c=t;for(;c&&!o;)o=c.sources.get(r.table),o||(c=c.parent);if(o instanceof V)this.setType(r,this.schema.getColumnType?.(o,r));else if(o){let l=c?this.getScopeSelects(c).get(r.table)?.[r.name]:void 0;if(l)this.setType(r,l);else if(o.expression instanceof ge){let u=o.expression.type;this.setType(r,$(u,O)?u:void 0)}else this.setType(r,"unknown")}else this.setType(r,"unknown");r.type?.getArgKey("nullable")===!1&&(r.meta.nonnull=!0);continue}let a=this.expressionMetadata.get(r._constructor);if(a){if(a.annotator){a.annotator(this,r);continue}if(a.returns!==void 0){this.setType(r,a.returns);continue}}if(r instanceof Dt){this.annotateBracket(r);continue}if(r instanceof q){this.annotateBinary(r);continue}if(r instanceof hs){this.annotateUnary(r);continue}this.setType(r,"unknown")}}maybeCoerce(e,t){let s;if(e instanceof O){if(e.args.expressions&&0<e.args.expressions.length)return e;s=e.args.this}else s=e??"unknown";let r;if(t instanceof O){if(t.args.expressions&&0<t.args.expressions.length)return t;r=t.args.this}else r=t??"unknown";return s==="unknown"||r==="unknown"?"unknown":s==="null"?r:r==="null"?s:this.coercesTo.get(s)?.has(r)?r:s}setType(e,t){let s=e.type;if(e.type=t??"unknown",this.visited.add(e),!this.supportsNullType&&e.type?.args.this==="null"?this.nullExpressions.set(e,e):s?.isType("null")&&this.nullExpressions.delete(e),e instanceof B&&e.isType("json")&&e.meta.dotParts){let n=e.meta.dotParts[Symbol.iterator](),a=e.parent;for(;a instanceof Se;){let o=n.next();o.done||a.setArgKey("expression",Z(o.value,{quoted:!0})),a=a.parent}delete e.meta.dotParts}return e}annotateBinary(e){let t=e.left,s=e.right;if(!t||!s){this.setType(e);return}let r=t.type?.args.this?.toString(),n=s.type?.args.this?.toString();if(e instanceof Ee||e instanceof Ne)this.setType(e,"boolean");else{let a=this.binaryCoercions.get(r,n);a?this.setType(e,a(t,s)):this.annotateByArgs(e,[t,s])}(e instanceof _e||t.meta.nonnull===!0&&s.meta.nonnull===!0)&&(e.meta.nonnull=!0)}annotateUnary(e){if(e instanceof be)this.setType(e,"boolean");else{let r=e.args.this?.type;this.setType(e,r)}e.args.this?.meta.nonnull===!0&&(e.meta.nonnull=!0)}annotateLiteral(e){e.args.isString?this.setType(e,"varchar"):e.isInteger?this.setType(e,"int"):this.setType(e,"double"),e.meta.nonnull=!0}annotateByArgs(e,t,s={}){let{promote:r=!1,array:n=!1}=s,a=null,o=null,c;e:for(let u of t){let h;if(typeof u=="string"){let d=e.args[u];h=J(d)}else Array.isArray(u)?h=u:h=[u];for(let d of h){if(!(d instanceof A))continue;let x=d.type;if(!x)continue;let f=$(x,O)||$(x,Ie)?x:void 0;if(f){if(f.getArgKey("nested")){c=f;break e}d instanceof R?a=this.maybeCoerce(a??f,f):o=this.maybeCoerce(o??f,f)}}}let l;if(c)l=c;else if(a!==null&&o!==null){if(this.dialect._constructor.PRIORITIZE_NON_LITERAL_TYPES){let u=a instanceof O?a.args.this:a,h=o instanceof O?o.args.this:o;(O.INTEGER_TYPES.has(u)&&O.INTEGER_TYPES.has(h)||O.REAL_TYPES.has(u)&&O.REAL_TYPES.has(h))&&(l=o)}}else l=a??o??"unknown";if(this.setType(e,l??this.maybeCoerce(o??void 0,a??void 0)),r){let u=e.type?.args.this;O.INTEGER_TYPES.has(u)?this.setType(e,"bigint"):O.FLOAT_TYPES.has(u)&&this.setType(e,"double")}if(n){let u=e.type?.copy()??new O({this:"unknown"});this.setType(e,new O({this:"array",expressions:[u],nested:!0}))}}annotateTimeunit(e){let t=e.args.this;if(!t?.type){this.setType(e,"unknown");return}let s=t.type.args.this,r;if(O.TEXT_TYPES.has(s)){let n=e.unit;r=fD(t,n)}else if(O.TEMPORAL_TYPES.has(s)){let n=e.unit;r=TD(t,n)}else r="unknown";this.setType(e,r)}annotateBracket(e){let t=M(e.args.expressions??[],0),s=e.args.this;if(t instanceof Tr){let r=s.type;this.setType(e,$(r,O)?r:void 0)}else if(s.type?.isType("array")){let r=M(s.type.args.expressions??[],0);this.setType(e,r)}else if(s instanceof io||s instanceof Ys){let r=s.keys;if(t){let n=r.findIndex(a=>a instanceof A&&a.equals(t));if(0<=n){let a=s.values,o=M(a,n),c=o instanceof A?o.type:void 0;this.setType(e,$(c,O)?c:void 0)}else this.setType(e,"unknown")}else this.setType(e,"unknown")}else this.setType(e,"unknown")}annotateDiv(e){let t=e.left,s=e.right,r=t?.type?.args.this,n=s?.type?.args.this;if(e.args.typed&&O.INTEGER_TYPES.has(r)&&O.INTEGER_TYPES.has(n))this.setType(e,"bigint");else{this.setType(e,this.maybeCoerce(r,n));let a=e.type?.args.this;if(!O.REAL_TYPES.has(a)){let o=e.type;this.setType(e,this.maybeCoerce($(o,O)?o:void 0,"double"))}}}annotateDot(e){this.setType(e);let t=e.args.expression;if(t instanceof je){let r=t.type;this.setType(e,$(r,O)?r:void 0);return}let s=e.args.this?.type;if(Sl(s,"struct")){for(let r of s?.args.expressions||[])if(r.name===t?.name){let n=r.args.kind;this.setType(e,n);break}}}annotateExtract(e){let t=e.name?.toUpperCase();t==="TIME"?this.setType(e,"time"):t==="DATE"?this.setType(e,"date"):t&&hU.has(t)?this.setType(e,"bigint"):this.setType(e,"int")}annotateExplode(e){let t=e.args.this,s=M(t?.type?.args.expressions??[],0);this.setType(e,s)}annotateUnnest(e){let t=M(e.args.expressions??[],0),s;t instanceof A&&t.isType("array")&&(s=M(t.type?.args.expressions??[],0)),this.setType(e,s)}annotateSubquery(e){let t=e.unnest();if(t instanceof z){let s=t.selects;if(s.length===1){let r=s[0].type;this.setType(e,$(r,O)||$(r,Ie)?r:void 0);return}}this.setType(e,"unknown")}annotateStructValue(e){let t,s=e.type,r=$(s,O)||$(s,Ie)?s:void 0,n=e.args.alias;if(n instanceof A)t=n.copy();else if(e.args.expression instanceof A){t=e.args.this?.copy();let a=e.args.expression?.type;r=$(a,O)||$(a,Ie)?a:void 0}else e instanceof B&&(t=e.args.this?.copy());return $(r,O)&&r.isType("unknown")?null:t?new Ie({this:t,kind:r}):r??"unknown"}annotateStruct(e){let t=[];for(let s of e.args.expressions){let r=this.annotateStructValue(s);if(r===null){this.setType(e);return}t.push(r)}this.setType(e,new O({this:"struct",expressions:t,nested:!0}))}annotateMap(e){let t,s;if(e instanceof Ys)t=e.args.keys,s=e.args.values;else{let n=e.args.keys,a=e.args.values;t=n?.[0]instanceof ue?n[0]:void 0,s=a?.[0]instanceof ue?a[0]:void 0}let r=new O({this:"map"});if(t instanceof ue&&s instanceof ue){let n=M(t.type?.args.expressions??[],0),a=M(s.type?.args.expressions??[],0),o=n instanceof O?n.args.this:n,c=a instanceof O?a.args.this:a;o!=="unknown"&&c!=="unknown"&&(r.setArgKey("expressions",[n??new O({this:"unknown"}),a??new O({this:"unknown"})]),r.setArgKey("nested",!0))}this.setType(e,r)}annotateToMap(e){let t=new O({this:"map"}),s=e.args.this;if(s?.isType("struct")&&s.type instanceof A)for(let r of s.type.args.expressions||[]){let n=r.args.kind,a=n instanceof O?n.args.this:n;if(a!=="unknown"){let o=O.build("varchar");t.setArgKey("expressions",[...o?[o]:[],n instanceof O?n:new O({this:a??"unknown"})]),t.args.nested=!0;break}}this.setType(e,t)}annotateByArrayElement(e){let t=e.args.this;if(t?.type?.isType("array")){let s=M(t.type.args.expressions??[],0);this.setType(e,s??"unknown")}else this.setType(e,"unknown")}};qf=Bt(null),S(qf,10,"NESTED_TYPES",OD,Xn),S(qf,10,"COERCES_TO",mD,Xn),S(qf,10,"BINARY_COERCIONS",SD,Xn),bt(qf,Xn),Lt(qf,3,Xn);var xl=Xn;function is(i,e){let t=e??{};for(let s of i){let r=t;for(let n of s)r[n]||(r[n]={}),r=r[n];r["\0"]=!0}return t}function no(i,e){let t=Array.from(e);if(!t.length)return[0,i];let s=i;for(let r of t){if(!s[r])return[0,s];s=s[r]}return s["\0"]?[2,s]:[1,s]}var OA=(E=>(E.L_PAREN="lParen",E.R_PAREN="rParen",E.L_BRACKET="lBracket",E.R_BRACKET="rBracket",E.L_BRACE="lBrace",E.R_BRACE="rBrace",E.COMMA="comma",E.DOT="dot",E.DASH="dash",E.PLUS="plus",E.COLON="colon",E.DOTCOLON="dotcolon",E.DCOLON="dcolon",E.DCOLONDOLLAR="dcolondollar",E.DCOLONPERCENT="dcolonpercent",E.DCOLONQMARK="dcolonqmark",E.DQMARK="dqmark",E.SEMICOLON="semicolon",E.STAR="star",E.BACKSLASH="backslash",E.SLASH="slash",E.LT="lt",E.LTE="lte",E.GT="gt",E.GTE="gte",E.NOT="not",E.EQ="eq",E.NEQ="neq",E.NULLSAFE_EQ="nullsafeEq",E.COLON_EQ="colonEq",E.COLON_GT="colonGt",E.NCOLON_GT="ncolonGt",E.AND="and",E.OR="or",E.AMP="amp",E.DPIPE="dpipe",E.PIPE_GT="pipeGt",E.PIPE="pipe",E.PIPE_SLASH="pipeSlash",E.DPIPE_SLASH="dpipeSlash",E.CARET="caret",E.CARET_AT="caretAt",E.TILDE="tilde",E.ARROW="arrow",E.DARROW="darrow",E.FARROW="farrow",E.HASH="hash",E.HASH_ARROW="hashArrow",E.DHASH_ARROW="dhashArrow",E.LR_ARROW="lrArrow",E.DAT="dat",E.LT_AT="ltAt",E.AT_GT="atGt",E.DOLLAR="dollar",E.PARAMETER="parameter",E.SESSION="session",E.SESSION_PARAMETER="sessionParameter",E.SESSION_USER="sessionUser",E.DAMP="damp",E.AMP_LT="ampLt",E.AMP_GT="ampGt",E.ADJACENT="adjacent",E.XOR="xor",E.DSTAR="dstar",E.QMARK_AMP="qmarkAmp",E.QMARK_PIPE="qmarkPipe",E.HASH_DASH="hashDash",E.EXCLAMATION="exclamation",E.URI_START="uriStart",E.BLOCK_START="blockStart",E.BLOCK_END="blockEnd",E.SPACE="space",E.BREAK="break",E.STRING="string",E.NUMBER="number",E.IDENTIFIER="identifier",E.DATABASE="database",E.COLUMN="column",E.COLUMN_DEF="columnDef",E.SCHEMA="schema",E.TABLE="table",E.WAREHOUSE="warehouse",E.STAGE="stage",E.STREAMLIT="streamlit",E.VAR="var",E.BIT_STRING="bitString",E.HEX_STRING="hexString",E.BYTE_STRING="byteString",E.NATIONAL_STRING="nationalString",E.RAW_STRING="rawString",E.HEREDOC_STRING="heredocString",E.UNICODE_STRING="unicodeString",E.BIT="bit",E.BOOLEAN="boolean",E.TINYINT="tinyint",E.UTINYINT="utinyint",E.SMALLINT="smallint",E.USMALLINT="usmallint",E.MEDIUMINT="mediumint",E.UMEDIUMINT="umediumint",E.INT="int",E.UINT="uint",E.BIGINT="bigint",E.UBIGINT="ubigint",E.BIGNUM="bignum",E.INT128="int128",E.UINT128="uint128",E.INT256="int256",E.UINT256="uint256",E.FLOAT="float",E.DOUBLE="double",E.UDOUBLE="udouble",E.DECIMAL="decimal",E.DECIMAL32="decimal32",E.DECIMAL64="decimal64",E.DECIMAL128="decimal128",E.DECIMAL256="decimal256",E.DECFLOAT="decfloat",E.UDECIMAL="udecimal",E.BIGDECIMAL="bigdecimal",E.CHAR="char",E.NCHAR="nchar",E.VARCHAR="varchar",E.NVARCHAR="nvarchar",E.BPCHAR="bpchar",E.TEXT="text",E.MEDIUMTEXT="mediumtext",E.LONGTEXT="longtext",E.BLOB="blob",E.MEDIUMBLOB="mediumblob",E.LONGBLOB="longblob",E.TINYBLOB="tinyblob",E.TINYTEXT="tinytext",E.NAME="name",E.BINARY="binary",E.VARBINARY="varbinary",E.JSON="json",E.JSONB="jsonb",E.TIME="time",E.TIMETZ="timetz",E.TIME_NS="timeNs",E.TIMESTAMP="timestamp",E.TIMESTAMPTZ="timestamptz",E.TIMESTAMPLTZ="timestampltz",E.TIMESTAMPNTZ="timestampntz",E.TIMESTAMP_S="timestampS",E.TIMESTAMP_MS="timestampMs",E.TIMESTAMP_NS="timestampNs",E.DATETIME="datetime",E.DATETIME2="datetime2",E.DATETIME64="datetime64",E.SMALLDATETIME="smalldatetime",E.DATE="date",E.DATE32="date32",E.INT4RANGE="int4range",E.INT4MULTIRANGE="int4multirange",E.INT8RANGE="int8range",E.INT8MULTIRANGE="int8multirange",E.NUMRANGE="numrange",E.NUMMULTIRANGE="nummultirange",E.TSRANGE="tsrange",E.TSMULTIRANGE="tsmultirange",E.TSTZRANGE="tstzrange",E.TSTZMULTIRANGE="tstzmultirange",E.DATERANGE="daterange",E.DATEMULTIRANGE="datemultirange",E.UUID="uuid",E.GEOGRAPHY="geography",E.GEOGRAPHYPOINT="geographypoint",E.NULLABLE="nullable",E.GEOMETRY="geometry",E.POINT="point",E.RING="ring",E.LINESTRING="linestring",E.LOCALTIME="localtime",E.LOCALTIMESTAMP="localtimestamp",E.SYSTIMESTAMP="systimestamp",E.MULTILINESTRING="multilinestring",E.POLYGON="polygon",E.MULTIPOLYGON="multipolygon",E.HLLSKETCH="hllsketch",E.HSTORE="hstore",E.SUPER="super",E.SERIAL="serial",E.SMALLSERIAL="smallserial",E.BIGSERIAL="bigserial",E.XML="xml",E.YEAR="year",E.USERDEFINED="userdefined",E.MONEY="money",E.SMALLMONEY="smallmoney",E.ROWVERSION="rowversion",E.IMAGE="image",E.VARIANT="variant",E.OBJECT="object",E.INET="inet",E.IPADDRESS="ipaddress",E.IPPREFIX="ipprefix",E.IPV4="ipv4",E.IPV6="ipv6",E.ENUM="enum",E.ENUM8="enum8",E.ENUM16="enum16",E.FIXEDSTRING="fixedstring",E.LOWCARDINALITY="lowcardinality",E.NESTED="nested",E.AGGREGATEFUNCTION="aggregatefunction",E.SIMPLEAGGREGATEFUNCTION="simpleaggregatefunction",E.TDIGEST="tdigest",E.UNKNOWN="unknown",E.VECTOR="vector",E.DYNAMIC="dynamic",E.VOID="void",E.ALIAS="alias",E.ALTER="alter",E.ALL="all",E.ANTI="anti",E.ANY="any",E.APPLY="apply",E.ARRAY="array",E.ASC="asc",E.ASOF="asof",E.ATTACH="attach",E.AUTO_INCREMENT="autoIncrement",E.BEGIN="begin",E.BETWEEN="between",E.BULK_COLLECT_INTO="bulkCollectInto",E.CACHE="cache",E.CASE="case",E.CHARACTER_SET="characterSet",E.CLUSTER_BY="clusterBy",E.COLLATE="collate",E.COMMAND="command",E.COMMENT="comment",E.COMMIT="commit",E.CONNECT_BY="connectBy",E.CONSTRAINT="constraint",E.COPY="copy",E.CREATE="create",E.CROSS="cross",E.CUBE="cube",E.CURRENT_DATE="currentDate",E.CURRENT_DATETIME="currentDatetime",E.CURRENT_SCHEMA="currentSchema",E.CURRENT_TIME="currentTime",E.CURRENT_TIMESTAMP="currentTimestamp",E.CURRENT_USER="currentUser",E.CURRENT_ROLE="currentRole",E.CURRENT_CATALOG="currentCatalog",E.DECLARE="declare",E.DEFAULT="default",E.DELETE="delete",E.DESC="desc",E.DESCRIBE="describe",E.DETACH="detach",E.DICTIONARY="dictionary",E.DISTINCT="distinct",E.DISTRIBUTE_BY="distributeBy",E.DIV="div",E.DROP="drop",E.ELSE="else",E.END="end",E.ESCAPE="escape",E.EXCEPT="except",E.EXECUTE="execute",E.EXISTS="exists",E.FALSE="false",E.FETCH="fetch",E.FILE="file",E.FILE_FORMAT="fileFormat",E.FILTER="filter",E.FINAL="final",E.FIRST="first",E.FOR="for",E.FORCE="force",E.FOREIGN_KEY="foreignKey",E.FORMAT="format",E.FROM="from",E.FULL="full",E.FUNCTION="function",E.GET="get",E.GLOB="glob",E.GLOBAL="global",E.GRANT="grant",E.GROUP_BY="groupBy",E.GROUPING_SETS="groupingSets",E.HAVING="having",E.HINT="hint",E.IGNORE="ignore",E.ILIKE="ilike",E.IN="in",E.INDEX="index",E.INDEXED_BY="indexedBy",E.INNER="inner",E.INSERT="insert",E.INSTALL="install",E.INTERSECT="intersect",E.INTERVAL="interval",E.INTO="into",E.INTRODUCER="introducer",E.IRLIKE="irlike",E.IS="is",E.ISNULL="isnull",E.JOIN="join",E.JOIN_MARKER="joinMarker",E.KEEP="keep",E.KEY="key",E.KILL="kill",E.LANGUAGE="language",E.LATERAL="lateral",E.LEFT="left",E.LIKE="like",E.LIMIT="limit",E.LIST="list",E.LOAD="load",E.LOCK="lock",E.MAP="map",E.MATCH="match",E.MATCH_CONDITION="matchCondition",E.MATCH_RECOGNIZE="matchRecognize",E.MEMBER_OF="memberOf",E.MERGE="merge",E.MOD="mod",E.MODEL="model",E.NATURAL="natural",E.NEXT="next",E.NOTHING="nothing",E.NOTNULL="notnull",E.NULL="null",E.OBJECT_IDENTIFIER="objectIdentifier",E.OFFSET="offset",E.ON="on",E.ONLY="only",E.OPERATOR="operator",E.ORDER_BY="orderBy",E.ORDER_SIBLINGS_BY="orderSiblingsBy",E.ORDERED="ordered",E.ORDINALITY="ordinality",E.OUT="out",E.INOUT="inout",E.OUTER="outer",E.OVER="over",E.OVERLAPS="overlaps",E.OVERWRITE="overwrite",E.PARTITION="partition",E.PARTITION_BY="partitionBy",E.PERCENT="percent",E.PIVOT="pivot",E.PLACEHOLDER="placeholder",E.POSITIONAL="positional",E.PRAGMA="pragma",E.PREWHERE="prewhere",E.PRIMARY_KEY="primaryKey",E.PROCEDURE="procedure",E.PROPERTIES="properties",E.PSEUDO_TYPE="pseudoType",E.PUT="put",E.QUALIFY="qualify",E.QUOTE="quote",E.QDCOLON="qdcolon",E.RANGE="range",E.RECURSIVE="recursive",E.REFRESH="refresh",E.RENAME="rename",E.REPLACE="replace",E.RETURNING="returning",E.REVOKE="revoke",E.REFERENCES="references",E.RIGHT="right",E.RLIKE="rlike",E.ROLLBACK="rollback",E.ROLLUP="rollup",E.ROW="row",E.ROWS="rows",E.SELECT="select",E.SEMI="semi",E.SEPARATOR="separator",E.SEQUENCE="sequence",E.SERDE_PROPERTIES="serdeProperties",E.SET="set",E.SETTINGS="settings",E.SHOW="show",E.SIMILAR_TO="similarTo",E.SOME="some",E.SORT_BY="sortBy",E.SOUNDS_LIKE="soundsLike",E.START_WITH="startWith",E.STORAGE_INTEGRATION="storageIntegration",E.STRAIGHT_JOIN="straightJoin",E.STRUCT="struct",E.SUMMARIZE="summarize",E.TABLE_SAMPLE="tableSample",E.TAG="tag",E.TEMPORARY="temporary",E.TOP="top",E.THEN="then",E.TRUE="true",E.TRUNCATE="truncate",E.UNCACHE="uncache",E.UNION="union",E.UNNEST="unnest",E.UNPIVOT="unpivot",E.UPDATE="update",E.USE="use",E.USING="using",E.VALUES="values",E.VARIADIC="variadic",E.VIEW="view",E.SEMANTIC_VIEW="semanticView",E.VOLATILE="volatile",E.WHEN="when",E.WHERE="where",E.WINDOW="window",E.WITH="with",E.UNIQUE="unique",E.UTC_DATE="utcDate",E.UTC_TIME="utcTime",E.UTC_TIMESTAMP="utcTimestamp",E.VERSION_SNAPSHOT="versionSnapshot",E.TIMESTAMP_SNAPSHOT="timestampSnapshot",E.OPTION="option",E.SINK="sink",E.SOURCE="source",E.ANALYZE="analyze",E.NAMESPACE="namespace",E.EXPORT="export",E.HIVE_TOKEN_STREAM="hiveTokenStream",E))(OA||{}),vf=class i{static number(e){return new i("number",String(e))}static string(e){return new i("string",e)}static identifier(e){return new i("identifier",e)}constructor(e,t,s=1,r=1,n=0,a=0,o=[]){this.tokenType=e,this.text=t,this.line=s,this.col=r,this.start=n,this.end=a,this.comments=o}},RD,ND,ID,yD,CD,PD,bD,LD,wD,MD,Vs;MD=[m],wD=[m],LD=[m],bD=[m],PD=[m],CD=[m],yD=[m],ID=[m],ND=[m],RD=[m];var re=class re{constructor(e={}){this.sql="";this.size=0;this.tokens=[];this.dialect=void 0;this._start=0;this._current=0;this.line=1;this._col=0;this.comments=[];this.char="";this._end=!1;this.peek="";this.prevTokenLine=-1;let{dialect:t}=e;this.dialect=se.getOrRaise(t),this.reset()}static get BYTE_STRING_ESCAPES(){return this.STRING_ESCAPES}static get _COMMENTS(){let e={};for(let t of this.COMMENTS)typeof t=="string"?e[t]=void 0:e[t[0]]=t[1];return e["{#"]="#}",this.HINT_START in this.KEYWORDS&&(e[this.HINT_START]="*/"),e}static get _FORMAT_STRINGS(){let e={};for(let[t,s]of Object.entries(this._QUOTES))for(let r of["n","N"])e[r+t]=[s,"nationalString"];return{...e,...this.quotesToFormat("bitString",this.BIT_STRINGS),...this.quotesToFormat("byteString",this.BYTE_STRINGS),...this.quotesToFormat("hexString",this.HEX_STRINGS),...this.quotesToFormat("string",this.RAW_STRINGS),...this.quotesToFormat("heredocString",this.HEREDOC_STRINGS),...this.quotesToFormat("unicodeString",this.UNICODE_STRINGS)}}static get _IDENTIFIERS(){return this.convertQuotes(this.IDENTIFIERS)}static get _IDENTIFIER_ESCAPES(){return new Set(this.IDENTIFIER_ESCAPES)}static get _QUOTES(){return this.convertQuotes(this.QUOTES)}static get _STRING_ESCAPES(){return new Set(this.STRING_ESCAPES)}static get _BYTE_STRING_ESCAPES(){return new Set(this.BYTE_STRING_ESCAPES)}static get _ESCAPE_FOLLOW_CHARS(){return new Set(this.ESCAPE_FOLLOW_CHARS)}static get _KEYWORD_TRIE(){let e=Object.keys(this.SINGLE_TOKENS),t=[...Object.keys(this.KEYWORDS),...Object.keys(this._COMMENTS),...Object.keys(this._QUOTES),...Object.keys(this._FORMAT_STRINGS)];return is(t.filter(s=>s.includes(" ")||e.some(r=>s.includes(r))).map(s=>Array.from(s.toUpperCase())))}static get KEYWORDS(){return this.ORIGINAL_KEYWORDS}reset(){this.sql="",this.size=0,this.tokens=[],this._start=0,this._current=0,this.line=1,this._col=0,this.comments=[],this.char="",this._end=!1,this.peek="",this.prevTokenLine=-1}tokenize(e){this.reset(),this.sql=e,this.size=e.length;try{this.scan()}catch{let t=Math.max(this._current-50,0),s=Math.min(this._current+50,this.size-1),r=this.sql.slice(t,s);throw new iA(`Error tokenizing '${r}'`)}return this.tokens}scan(e){for(;this.size&&!this._end;){let t=this._current;for(;t<this.size;){let r=this.sql[t];if(this.isWhitespace(r)&&(r===" "||r===" "))t++;else break}let s=this._current<t?t-this._current:1;if(this._start=t,this.advance({i:s}),this.isWhitespace(this.char)||(this.isDigit(this.char)?this.scanNumber():this.char in this._constructor._IDENTIFIERS?this.scanIdentifier(this._constructor._IDENTIFIERS[this.char]):this.scanKeywords()),e?.())break}this.tokens.length&&this.comments.length&&this.tokens[this.tokens.length-1].comments.push(...this.comments)}chars(e){if(e===1)return this.char;let t=this._current-1,s=t+e;return s<=this.size?this.sql.slice(t,s):""}advance(e={}){let{i:t=1,alnum:s=!1}=e;if(this._constructor.WHITE_SPACE[this.char]==="break"?this.char==="\r"&&this.peek===`
4
+ `||(this._col=t,this.line+=1):this._col+=t,this._current+=t,this._end=this.size<=this._current,this.char=this.sql[this._current-1],this.char===void 0)throw new Error("Index out of bound");if(this.peek=this._end?"":this.sql[this._current],s&&this.isAlnum(this.char)){let{_col:n,_current:a,_end:o,peek:c}=this;for(;this.isAlnum(c);)n+=1,a+=1,o=this.size<=a,c=o?"":this.sql[a];this._col=n,this._current=a,this._end=o,this.peek=c,this.char=this.sql[a-1]}}get text(){return this.sql.slice(this._start,this._current)}add(e,t){this.prevTokenLine=this.line,this.comments.length&&e==="semicolon"&&this.tokens.length&&(this.tokens[this.tokens.length-1].comments.push(...this.comments),this.comments=[]),this.tokens.push(new vf(e,t??this.text,this.line,this._col,this._start,this._current-1,this.comments)),this.comments=[];let s=this._constructor;if(s.COMMANDS.has(e)&&this.peek!==";"&&(this.tokens.length===1||s.COMMAND_PREFIX_TOKENS.has(this.tokens[this.tokens.length-2].tokenType))){let r=this._current,n=this.tokens.length;this.scan(()=>this.peek===";"),this.tokens=this.tokens.slice(0,n);let a=this.sql.slice(r,this._current).trim();a&&this.add("string",a)}}scanKeywords(){let e=0,t,s=this.text,r=s,n=!1,a=!1,o=this._constructor,c=o._KEYWORD_TRIE,l=r in this._constructor.SINGLE_TOKENS;for(;s;){let h;if(a?h=1:[h,c]=no(c,Array.from(r.toUpperCase())),h===0)break;h===2&&(t=s);let d=this._current+e;if(e+=1,d<this.size){r=this.sql[d],l=l||r in this._constructor.SINGLE_TOKENS;let x=this.isWhitespace(r);!x||!n?(x&&(r=" "),s+=r,n=x,a=!1):a=!0}else{r="";break}}if(t){if(this.scanString(t)||this.scanComment(t))return;if(n||l||!r){this.advance({i:e-1});let h=t.toUpperCase();this.add(o.KEYWORDS[h],h);return}}let u=this._constructor.SINGLE_TOKENS[this.char];if(u!==void 0){this.add(u,this.char);return}this.scanVar()}scanComment(e){let t=this._constructor;if(!(e in t._COMMENTS))return!1;let s=this.line,r=e.length,n=t._COMMENTS[e];if(n){this.advance({i:r});let a=1,o=n.length;for(;!this._end&&!(this.chars(o)===n&&(a-=1,!a));)this.advance({alnum:!0}),t.NESTED_COMMENTS&&!this._end&&this.chars(r)===e&&(this.advance({i:r}),a+=1);this.comments.push(this.text.slice(r,-o+1)),this.advance({i:o-1})}else{for(;!this._end&&t.WHITE_SPACE[this.peek]!=="break";)this.advance({i:1,alnum:!0});this.comments.push(this.text.slice(r))}return e===t.HINT_START&&this.tokens.length&&t.TOKENS_PRECEDING_HINT.has(this.tokens[this.tokens.length-1].tokenType)&&this.add("hint"),s===this.prevTokenLine&&(this.tokens[this.tokens.length-1].comments.push(...this.comments),this.comments=[],this.prevTokenLine=this.line),!0}scanNumber(){let e=this._constructor;if(this.char==="0"){let r=this.peek.toUpperCase();if(r==="B")return e.BIT_STRINGS.length?this.scanBits():this.add("number");if(r==="X")return e.HEX_STRINGS.length?this.scanHex():this.add("number")}let t=!1,s=0;for(;;)if(this.isDigit(this.peek))this.advance();else if(this.peek==="."&&!t){if(this.tokens.length&&this.tokens[this.tokens.length-1].tokenType==="parameter")return this.add("number");t=!0,this.advance()}else if(["-","+"].includes(this.peek)&&s===1)if(this._current+1<this.size&&this.isDigit(this.sql[this._current+1]))s+=1,this.advance();else return this.add("number");else if(this.peek.toUpperCase()==="E"&&!s)s+=1,this.advance();else if(this.peek==="_"&&this.dialect._constructor.NUMBERS_CAN_BE_UNDERSCORE_SEPARATED)this.advance();else if(this.isIdentifierChar(this.peek)){let r=this.text,n="";for(;this.peek.trim()&&!this._constructor.SINGLE_TOKENS[this.peek];)n+=this.peek,this.advance();let a=e.KEYWORDS[e.NUMERIC_LITERALS[n.toUpperCase()]||""];return a?(this.add("number",r),this.add("dcolon","::"),this.add(a,n)):this.dialect._constructor.IDENTIFIERS_CAN_START_WITH_DIGIT?this.add("var"):(this.advance({i:-n.length}),this.add("number",r))}else return this.add("number")}scanBits(){this.advance();let e=this.extractValue();Number.isNaN(parseInt(e,2))?this.add("identifier"):this.add("bitString",e.slice(2))}scanHex(){this.advance();let e=this.extractValue();Number.isNaN(parseInt(e,16))?this.add("identifier"):this.add("hexString",e.slice(2))}extractValue(){for(;;){let e=this.peek.trim();if(e&&!this._constructor.SINGLE_TOKENS[e])this.advance({i:1,alnum:!0});else break}return this.text}scanString(e){let t=this._constructor,s,r="string",n;if(e in t._QUOTES)n=t._QUOTES[e];else if(e in t._FORMAT_STRINGS){if([n,r]=t._FORMAT_STRINGS[e],r==="hexString")s=16;else if(r==="bitString")s=2;else if(r==="heredocString"){this.advance();let o;if(this.char===n?o="":o=this.extractString(n,void 0,{rawString:!0,raiseUnmatched:!t.HEREDOC_TAG_IS_IDENTIFIER}),o&&t.HEREDOC_TAG_IS_IDENTIFIER&&(this._end||this.isDigit(o)||this.isWhitespace(o)))return this._end||this.advance({i:-1}),this.advance({i:-o.length}),this.add(t.HEREDOC_STRING_ALTERNATIVE),!0;n=`${e}${o}${n}`}}else return!1;this.advance({i:e.length});let a=this.extractString(n,r==="byteString"?t._BYTE_STRING_ESCAPES:t._STRING_ESCAPES,{rawString:r==="rawString"});if(s&&a&&Number.isNaN(parseInt(a,s)))throw new Error(`Numeric string contains invalid characters from ${this.line}:${this._start}`);return this.add(r,a),!0}scanIdentifier(e){this.advance();let t=this._constructor,s=new Set([...Array.from(t._IDENTIFIER_ESCAPES),e]),r=this.extractString(e,s);this.add("identifier",r)}scanVar(){let e=this._constructor;for(;;){let t=this.peek.trim();if(t&&(e.VAR_SINGLE_TOKENS.has(t)||!this._constructor.SINGLE_TOKENS[t]))this.advance({i:1,alnum:!0});else break}this.add(this.tokens.length&&this.tokens[this.tokens.length-1].tokenType==="parameter"?"var":e.KEYWORDS[this.text.toUpperCase()]||"var")}extractString(e,t=void 0,s={}){let{rawString:r=!1,raiseUnmatched:n=!0}=s,a=this._constructor,o="",c=e.length;for(t=t===void 0?a._STRING_ESCAPES:t;;){if(!r&&this.dialect._constructor.UNESCAPED_SEQUENCES&&this.peek&&t.has(this.char)){let u=this.dialect._constructor.UNESCAPED_SEQUENCES[this.char+this.peek];if(u){this.advance({i:2}),o+=u;continue}}let l=a.ESCAPE_FOLLOW_CHARS.length&&this.char==="\\"&&!a.ESCAPE_FOLLOW_CHARS.includes(this.peek);if((a.STRING_ESCAPES_ALLOWED_IN_RAW_STRINGS||!r)&&t.has(this.char)&&(this.peek===e||t.has(this.peek)||l)&&(!(this.char in a._QUOTES)||this.char===this.peek))if(this.peek===e?o+=this.peek:l&&this.char!==this.peek?o+=this.peek:o+=this.char+this.peek,this._current+1<this.size)this.advance({i:2});else throw new iA(`Missing ${e} from ${this.line}:${this._current}`);else{if(this.chars(c)===e){1<c&&this.advance({i:c-1});break}if(this._end){if(!n)return o+this.char;throw new iA(`Missing ${e} from ${this.line}:${this._start}`)}let u=this._current-1;this.advance({i:1,alnum:!0}),o+=this.sql.slice(u,this._current-1)}}return o}static convertQuotes(e){let t={};for(let s of e){let r=typeof s=="string"?s:s[0],n=typeof s=="string"?s:s[1];t[r]=n}return t}static quotesToFormat(e,t){let s=this.convertQuotes(t),r={};for(let[n,a]of Object.entries(s))r[n]=[a,e];return r}isWhitespace(e){return/\s/.test(e)}isDigit(e){return/\d/.test(e)}isAlnum(e){return/[a-zA-Z0-9]/.test(e)}isIdentifierChar(e){return/[a-zA-Z_]/.test(e)}get _constructor(){return this.constructor}};Vs=Bt(null),S(Vs,10,"_COMMENTS",MD,re),S(Vs,10,"_FORMAT_STRINGS",wD,re),S(Vs,10,"_IDENTIFIERS",LD,re),S(Vs,10,"_IDENTIFIER_ESCAPES",bD,re),S(Vs,10,"_QUOTES",PD,re),S(Vs,10,"_STRING_ESCAPES",CD,re),S(Vs,10,"_BYTE_STRING_ESCAPES",yD,re),S(Vs,10,"_ESCAPE_FOLLOW_CHARS",ID,re),S(Vs,10,"_KEYWORD_TRIE",ND,re),S(Vs,10,"KEYWORDS",RD,re),bt(Vs,re),Lt(Vs,3,re),re.SINGLE_TOKENS={"(":"lParen",")":"rParen","[":"lBracket","]":"rBracket","{":"lBrace","}":"rBrace","&":"amp","^":"caret",":":"colon",",":"comma",".":"dot","-":"dash","=":"eq",">":"gt","<":"lt","%":"mod","!":"not","|":"pipe","+":"plus",";":"semicolon","/":"slash","\\":"backslash","*":"star","~":"tilde","?":"placeholder","@":"parameter","#":"hash","'":"unknown","`":"unknown",'"':"unknown"},re.BIT_STRINGS=[],re.BYTE_STRINGS=[],re.HEX_STRINGS=[],re.RAW_STRINGS=[],re.HEREDOC_STRINGS=[],re.IDENTIFIERS=['"'],re.QUOTES=["'"],re.UNICODE_STRINGS=[],re.STRING_ESCAPES=["'"],re.VAR_SINGLE_TOKENS=new Set,re.ESCAPE_FOLLOW_CHARS=[],re.IDENTIFIER_ESCAPES=[],re.HEREDOC_TAG_IS_IDENTIFIER=!1,re.HEREDOC_STRING_ALTERNATIVE="var",re.STRING_ESCAPES_ALLOWED_IN_RAW_STRINGS=!0,re.NESTED_COMMENTS=!0,re.HINT_START="/*+",re.TOKENS_PRECEDING_HINT=new Set(["select","insert","update","delete"]),re.ORIGINAL_KEYWORDS={"{%":"blockStart","{%+":"blockStart","{%-":"blockStart","%}":"blockEnd","+%}":"blockEnd","-%}":"blockEnd","{{+":"blockStart","{{-":"blockStart","+}}":"blockEnd","-}}":"blockEnd",[re.HINT_START]:"hint","&<":"ampLt","&>":"ampGt","==":"eq","::":"dcolon","?::":"qdcolon","||":"dpipe","|>":"pipeGt",">=":"gte","<=":"lte","<>":"neq","!=":"neq",":=":"colonEq","<=>":"nullsafeEq","->":"arrow","->>":"darrow","=>":"farrow","#>":"hashArrow","#>>":"dhashArrow","<->":"lrArrow","&&":"damp","??":"dqmark","~~~":"glob","~~":"like","~~*":"ilike","~*":"irlike","-|-":"adjacent",ALL:"all",AND:"and",ANTI:"anti",ANY:"any",ASC:"asc",AS:"alias",ASOF:"asof",AUTOINCREMENT:"autoIncrement",AUTO_INCREMENT:"autoIncrement",BEGIN:"begin",BETWEEN:"between",CACHE:"cache",UNCACHE:"uncache",CASE:"case","CHARACTER SET":"characterSet","CLUSTER BY":"clusterBy",COLLATE:"collate",COLUMN:"column",COMMIT:"commit","CONNECT BY":"connectBy",CONSTRAINT:"constraint",COPY:"copy",CREATE:"create",CROSS:"cross",CUBE:"cube",CURRENT_DATE:"currentDate",CURRENT_SCHEMA:"currentSchema",CURRENT_TIME:"currentTime",CURRENT_TIMESTAMP:"currentTimestamp",CURRENT_USER:"currentUser",CURRENT_CATALOG:"currentCatalog",DATABASE:"database",DEFAULT:"default",DELETE:"delete",DESC:"desc",DESCRIBE:"describe",DISTINCT:"distinct","DISTRIBUTE BY":"distributeBy",DIV:"div",DROP:"drop",ELSE:"else",END:"end",ENUM:"enum",ESCAPE:"escape",EXCEPT:"except",EXECUTE:"execute",EXISTS:"exists",FALSE:"false",FETCH:"fetch",FILTER:"filter",FILE:"file",FIRST:"first",FULL:"full",FUNCTION:"function",FOR:"for","FOREIGN KEY":"foreignKey",FORMAT:"format",FROM:"from",GEOGRAPHY:"geography",GEOMETRY:"geometry",GLOB:"glob","GROUP BY":"groupBy","GROUPING SETS":"groupingSets",HAVING:"having",ILIKE:"ilike",IN:"in",INDEX:"index",INET:"inet",INNER:"inner",INSERT:"insert",INTERVAL:"interval",INTERSECT:"intersect",INTO:"into",IS:"is",ISNULL:"isnull",JOIN:"join",KEEP:"keep",KILL:"kill",LATERAL:"lateral",LEFT:"left",LIKE:"like",LIMIT:"limit",LOAD:"load",LOCALTIME:"localtime",LOCALTIMESTAMP:"localtimestamp",LOCK:"lock",MERGE:"merge",NAMESPACE:"namespace",NATURAL:"natural",NEXT:"next",NOT:"not",NOTNULL:"notnull",NULL:"null",OBJECT:"object",OFFSET:"offset",ON:"on",OR:"or",XOR:"xor","ORDER BY":"orderBy",ORDINALITY:"ordinality",OUT:"out",OUTER:"outer",OVER:"over",OVERLAPS:"overlaps",OVERWRITE:"overwrite",PARTITION:"partition","PARTITION BY":"partitionBy","PARTITIONED BY":"partitionBy",PARTITIONED_BY:"partitionBy",PERCENT:"percent",PIVOT:"pivot",PRAGMA:"pragma","PRIMARY KEY":"primaryKey",PROCEDURE:"procedure",OPERATOR:"operator",QUALIFY:"qualify",RANGE:"range",RECURSIVE:"recursive",REGEXP:"rlike",RENAME:"rename",REPLACE:"replace",RETURNING:"returning",REFERENCES:"references",RIGHT:"right",RLIKE:"rlike",ROLLBACK:"rollback",ROLLUP:"rollup",ROW:"row",ROWS:"rows",SCHEMA:"schema",SELECT:"select",SEMI:"semi",SESSION:"session",SESSION_USER:"sessionUser",SET:"set",SETTINGS:"settings",SHOW:"show","SIMILAR TO":"similarTo",SOME:"some","SORT BY":"sortBy","START WITH":"startWith",STRAIGHT_JOIN:"straightJoin",TABLE:"table",TABLESAMPLE:"tableSample",TEMP:"temporary",TEMPORARY:"temporary",THEN:"then",TRUE:"true",TRUNCATE:"truncate",UNION:"union",UNKNOWN:"unknown",UNNEST:"unnest",UNPIVOT:"unpivot",UPDATE:"update",USE:"use",USING:"using",UUID:"uuid",VALUES:"values",VIEW:"view",VOLATILE:"volatile",WHEN:"when",WHERE:"where",WINDOW:"window",WITH:"with",APPLY:"apply",ARRAY:"array",BIT:"bit",BOOL:"boolean",BOOLEAN:"boolean",BYTE:"tinyint",MEDIUMINT:"mediumint",INT1:"tinyint",TINYINT:"tinyint",INT16:"smallint",SHORT:"smallint",SMALLINT:"smallint",HUGEINT:"int128",UHUGEINT:"uint128",INT2:"smallint",INTEGER:"int",INT:"int",INT4:"int",INT32:"int",INT64:"bigint",INT128:"int128",INT256:"int256",LONG:"bigint",BIGINT:"bigint",INT8:"tinyint",UINT:"uint",UINT128:"uint128",UINT256:"uint256",DEC:"decimal",DECIMAL:"decimal",DECIMAL32:"decimal32",DECIMAL64:"decimal64",DECIMAL128:"decimal128",DECIMAL256:"decimal256",DECFLOAT:"decfloat",BIGDECIMAL:"bigdecimal",BIGNUMERIC:"bigdecimal",BIGNUM:"bignum",LIST:"list",MAP:"map",NULLABLE:"nullable",NUMBER:"decimal",NUMERIC:"decimal",FIXED:"decimal",REAL:"float",FLOAT:"float",FLOAT4:"float",FLOAT8:"double",DOUBLE:"double","DOUBLE PRECISION":"double",JSON:"json",JSONB:"jsonb",CHAR:"char",CHARACTER:"char","CHAR VARYING":"varchar","CHARACTER VARYING":"varchar",NCHAR:"nchar",VARCHAR:"varchar",VARCHAR2:"varchar",NVARCHAR:"nvarchar",NVARCHAR2:"nvarchar",BPCHAR:"bpchar",STR:"text",STRING:"text",TEXT:"text",LONGTEXT:"longtext",MEDIUMTEXT:"mediumtext",TINYTEXT:"tinytext",CLOB:"text",LONGVARCHAR:"text",BINARY:"binary",BLOB:"varbinary",LONGBLOB:"longblob",MEDIUMBLOB:"mediumblob",TINYBLOB:"tinyblob",BYTEA:"varbinary",VARBINARY:"varbinary",TIME:"time",TIMETZ:"timetz",TIME_NS:"timeNs",TIMESTAMP:"timestamp",TIMESTAMPTZ:"timestamptz",TIMESTAMPLTZ:"timestampltz",TIMESTAMP_LTZ:"timestampltz",TIMESTAMPNTZ:"timestampntz",TIMESTAMP_NTZ:"timestampntz",DATE:"date",DATETIME:"datetime",INT4RANGE:"int4range",INT4MULTIRANGE:"int4multirange",INT8RANGE:"int8range",INT8MULTIRANGE:"int8multirange",NUMRANGE:"numrange",NUMMULTIRANGE:"nummultirange",TSRANGE:"tsrange",TSMULTIRANGE:"tsmultirange",TSTZRANGE:"tstzrange",TSTZMULTIRANGE:"tstzmultirange",DATERANGE:"daterange",DATEMULTIRANGE:"datemultirange",UNIQUE:"unique",VECTOR:"vector",STRUCT:"struct",SEQUENCE:"sequence",VARIANT:"variant",ALTER:"alter",ANALYZE:"analyze",CALL:"command",COMMENT:"comment",EXPLAIN:"command",GRANT:"grant",REVOKE:"revoke",OPTIMIZE:"command",PREPARE:"command",VACUUM:"command","USER-DEFINED":"userdefined","FOR VERSION":"versionSnapshot","FOR TIMESTAMP":"timestampSnapshot"},re.WHITE_SPACE={" ":"space"," ":"space","\n":"break","\r":"break"},re.COMMANDS=new Set(["command","execute","fetch","show","rename"]),re.COMMAND_PREFIX_TOKENS=new Set(["semicolon","begin"]),re.NUMERIC_LITERALS={},re.COMMENTS=["--",["/*","*/"]];var Qn=re;import{DateTime as AU}from"luxon";function Ol(i,e,t){if(!i)return;let s=0,r=1,n=i.length,a=t??is(Object.keys(e).map(u=>Array.from(u))),o=a,c=[],l;for(;r<=n;){let u=i.substring(s,r),[h,d]=no(o,[u[u.length-1]]);o=d,h===0?(l?(r-=1,u=l,l=void 0):(u=u[0],r=s+1),s+=u.length,c.push(u),o=a):h===2&&(l=u),r+=1,h!==0&&n<r&&c.push(u)}return c.map(u=>e[u]??u).join("")}var MI=new Set(["africa/abidjan","africa/accra","africa/addis_ababa","africa/algiers","africa/asmara","africa/asmera","africa/bamako","africa/bangui","africa/banjul","africa/bissau","africa/blantyre","africa/brazzaville","africa/bujumbura","africa/cairo","africa/casablanca","africa/ceuta","africa/conakry","africa/dakar","africa/dar_es_salaam","africa/djibouti","africa/douala","africa/el_aaiun","africa/freetown","africa/gaborone","africa/harare","africa/johannesburg","africa/juba","africa/kampala","africa/khartoum","africa/kigali","africa/kinshasa","africa/lagos","africa/libreville","africa/lome","africa/luanda","africa/lubumbashi","africa/lusaka","africa/malabo","africa/maputo","africa/maseru","africa/mbabane","africa/mogadishu","africa/monrovia","africa/nairobi","africa/ndjamena","africa/niamey","africa/nouakchott","africa/ouagadougou","africa/porto-novo","africa/sao_tome","africa/timbuktu","africa/tripoli","africa/tunis","africa/windhoek","america/adak","america/anchorage","america/anguilla","america/antigua","america/araguaina","america/argentina/buenos_aires","america/argentina/catamarca","america/argentina/comodrivadavia","america/argentina/cordoba","america/argentina/jujuy","america/argentina/la_rioja","america/argentina/mendoza","america/argentina/rio_gallegos","america/argentina/salta","america/argentina/san_juan","america/argentina/san_luis","america/argentina/tucuman","america/argentina/ushuaia","america/aruba","america/asuncion","america/atikokan","america/atka","america/bahia","america/bahia_banderas","america/barbados","america/belem","america/belize","america/blanc-sablon","america/boa_vista","america/bogota","america/boise","america/buenos_aires","america/cambridge_bay","america/campo_grande","america/cancun","america/caracas","america/catamarca","america/cayenne","america/cayman","america/chicago","america/chihuahua","america/ciudad_juarez","america/coral_harbour","america/cordoba","america/costa_rica","america/creston","america/cuiaba","america/curacao","america/danmarkshavn","america/dawson","america/dawson_creek","america/denver","america/detroit","america/dominica","america/edmonton","america/eirunepe","america/el_salvador","america/ensenada","america/fort_nelson","america/fort_wayne","america/fortaleza","america/glace_bay","america/godthab","america/goose_bay","america/grand_turk","america/grenada","america/guadeloupe","america/guatemala","america/guayaquil","america/guyana","america/halifax","america/havana","america/hermosillo","america/indiana/indianapolis","america/indiana/knox","america/indiana/marengo","america/indiana/petersburg","america/indiana/tell_city","america/indiana/vevay","america/indiana/vincennes","america/indiana/winamac","america/indianapolis","america/inuvik","america/iqaluit","america/jamaica","america/jujuy","america/juneau","america/kentucky/louisville","america/kentucky/monticello","america/knox_in","america/kralendijk","america/la_paz","america/lima","america/los_angeles","america/louisville","america/lower_princes","america/maceio","america/managua","america/manaus","america/marigot","america/martinique","america/matamoros","america/mazatlan","america/mendoza","america/menominee","america/merida","america/metlakatla","america/mexico_city","america/miquelon","america/moncton","america/monterrey","america/montevideo","america/montreal","america/montserrat","america/nassau","america/new_york","america/nipigon","america/nome","america/noronha","america/north_dakota/beulah","america/north_dakota/center","america/north_dakota/new_salem","america/nuuk","america/ojinaga","america/panama","america/pangnirtung","america/paramaribo","america/phoenix","america/port-au-prince","america/port_of_spain","america/porto_acre","america/porto_velho","america/puerto_rico","america/punta_arenas","america/rainy_river","america/rankin_inlet","america/recife","america/regina","america/resolute","america/rio_branco","america/rosario","america/santa_isabel","america/santarem","america/santiago","america/santo_domingo","america/sao_paulo","america/scoresbysund","america/shiprock","america/sitka","america/st_barthelemy","america/st_johns","america/st_kitts","america/st_lucia","america/st_thomas","america/st_vincent","america/swift_current","america/tegucigalpa","america/thule","america/thunder_bay","america/tijuana","america/toronto","america/tortola","america/vancouver","america/virgin","america/whitehorse","america/winnipeg","america/yakutat","america/yellowknife","antarctica/casey","antarctica/davis","antarctica/dumontdurville","antarctica/macquarie","antarctica/mawson","antarctica/mcmurdo","antarctica/palmer","antarctica/rothera","antarctica/south_pole","antarctica/syowa","antarctica/troll","antarctica/vostok","arctic/longyearbyen","asia/aden","asia/almaty","asia/amman","asia/anadyr","asia/aqtau","asia/aqtobe","asia/ashgabat","asia/ashkhabad","asia/atyrau","asia/baghdad","asia/bahrain","asia/baku","asia/bangkok","asia/barnaul","asia/beirut","asia/bishkek","asia/brunei","asia/calcutta","asia/chita","asia/choibalsan","asia/chongqing","asia/chungking","asia/colombo","asia/dacca","asia/damascus","asia/dhaka","asia/dili","asia/dubai","asia/dushanbe","asia/famagusta","asia/gaza","asia/harbin","asia/hebron","asia/ho_chi_minh","asia/hong_kong","asia/hovd","asia/irkutsk","asia/istanbul","asia/jakarta","asia/jayapura","asia/jerusalem","asia/kabul","asia/kamchatka","asia/karachi","asia/kashgar","asia/kathmandu","asia/katmandu","asia/khandyga","asia/kolkata","asia/krasnoyarsk","asia/kuala_lumpur","asia/kuching","asia/kuwait","asia/macao","asia/macau","asia/magadan","asia/makassar","asia/manila","asia/muscat","asia/nicosia","asia/novokuznetsk","asia/novosibirsk","asia/omsk","asia/oral","asia/phnom_penh","asia/pontianak","asia/pyongyang","asia/qatar","asia/qostanay","asia/qyzylorda","asia/rangoon","asia/riyadh","asia/saigon","asia/sakhalin","asia/samarkand","asia/seoul","asia/shanghai","asia/singapore","asia/srednekolymsk","asia/taipei","asia/tashkent","asia/tbilisi","asia/tehran","asia/tel_aviv","asia/thimbu","asia/thimphu","asia/tokyo","asia/tomsk","asia/ujung_pandang","asia/ulaanbaatar","asia/ulan_bator","asia/urumqi","asia/ust-nera","asia/vientiane","asia/vladivostok","asia/yakutsk","asia/yangon","asia/yekaterinburg","asia/yerevan","atlantic/azores","atlantic/bermuda","atlantic/canary","atlantic/cape_verde","atlantic/faeroe","atlantic/faroe","atlantic/jan_mayen","atlantic/madeira","atlantic/reykjavik","atlantic/south_georgia","atlantic/st_helena","atlantic/stanley","australia/act","australia/adelaide","australia/brisbane","australia/broken_hill","australia/canberra","australia/currie","australia/darwin","australia/eucla","australia/hobart","australia/lhi","australia/lindeman","australia/lord_howe","australia/melbourne","australia/nsw","australia/north","australia/perth","australia/queensland","australia/south","australia/sydney","australia/tasmania","australia/victoria","australia/west","australia/yancowinna","brazil/acre","brazil/denoronha","brazil/east","brazil/west","cet","cst6cdt","canada/atlantic","canada/central","canada/eastern","canada/mountain","canada/newfoundland","canada/pacific","canada/saskatchewan","canada/yukon","chile/continental","chile/easterisland","cuba","eet","est","est5edt","egypt","eire","etc/gmt","etc/gmt+0","etc/gmt+1","etc/gmt+10","etc/gmt+11","etc/gmt+12","etc/gmt+2","etc/gmt+3","etc/gmt+4","etc/gmt+5","etc/gmt+6","etc/gmt+7","etc/gmt+8","etc/gmt+9","etc/gmt-0","etc/gmt-1","etc/gmt-10","etc/gmt-11","etc/gmt-12","etc/gmt-13","etc/gmt-14","etc/gmt-2","etc/gmt-3","etc/gmt-4","etc/gmt-5","etc/gmt-6","etc/gmt-7","etc/gmt-8","etc/gmt-9","etc/gmt0","etc/greenwich","etc/uct","etc/utc","etc/universal","etc/zulu","europe/amsterdam","europe/andorra","europe/astrakhan","europe/athens","europe/belfast","europe/belgrade","europe/berlin","europe/bratislava","europe/brussels","europe/bucharest","europe/budapest","europe/busingen","europe/chisinau","europe/copenhagen","europe/dublin","europe/gibraltar","europe/guernsey","europe/helsinki","europe/isle_of_man","europe/istanbul","europe/jersey","europe/kaliningrad","europe/kiev","europe/kirov","europe/kyiv","europe/lisbon","europe/ljubljana","europe/london","europe/luxembourg","europe/madrid","europe/malta","europe/mariehamn","europe/minsk","europe/monaco","europe/moscow","europe/nicosia","europe/oslo","europe/paris","europe/podgorica","europe/prague","europe/riga","europe/rome","europe/samara","europe/san_marino","europe/sarajevo","europe/saratov","europe/simferopol","europe/skopje","europe/sofia","europe/stockholm","europe/tallinn","europe/tirane","europe/tiraspol","europe/ulyanovsk","europe/uzhgorod","europe/vaduz","europe/vatican","europe/vienna","europe/vilnius","europe/volgograd","europe/warsaw","europe/zagreb","europe/zaporozhye","europe/zurich","gb","gb-eire","gmt","gmt+0","gmt-0","gmt0","greenwich","hst","hongkong","iceland","indian/antananarivo","indian/chagos","indian/christmas","indian/cocos","indian/comoro","indian/kerguelen","indian/mahe","indian/maldives","indian/mauritius","indian/mayotte","indian/reunion","iran","israel","jamaica","japan","kwajalein","libya","met","mst","mst7mdt","mexico/bajanorte","mexico/bajasur","mexico/general","nz","nz-chat","navajo","prc","pst8pdt","pacific/apia","pacific/auckland","pacific/bougainville","pacific/chatham","pacific/chuuk","pacific/easter","pacific/efate","pacific/enderbury","pacific/fakaofo","pacific/fiji","pacific/funafuti","pacific/galapagos","pacific/gambier","pacific/guadalcanal","pacific/guam","pacific/honolulu","pacific/johnston","pacific/kanton","pacific/kiritimati","pacific/kosrae","pacific/kwajalein","pacific/majuro","pacific/marquesas","pacific/midway","pacific/nauru","pacific/niue","pacific/norfolk","pacific/noumea","pacific/pago_pago","pacific/palau","pacific/pitcairn","pacific/pohnpei","pacific/ponape","pacific/port_moresby","pacific/rarotonga","pacific/saipan","pacific/samoa","pacific/tahiti","pacific/tarawa","pacific/tongatapu","pacific/truk","pacific/wake","pacific/wallis","pacific/yap","poland","portugal","roc","rok","singapore","turkey","uct","us/alaska","us/aleutian","us/arizona","us/central","us/east-indiana","us/eastern","us/hawaii","us/indiana-starke","us/michigan","us/mountain","us/pacific","us/samoa","utc","universal","w-su","wet","zulu"]);function DD(i){try{if(!AU.fromISO(i).isValid)return 0;let t=i.match(/\.(\d+)/);if(!t)return 0;let r=t[1].replace(/0+$/,"").length;return 3<r?6:0<r?3:0}catch{return 0}}function Ff(i,e={}){let{dialect:t,storeOriginalColumnIdentifiers:s=!1}=e,r=se.getOrRaise(t),n;typeof i=="string"?n=Bf(i,{dialect:r}):n=i;for(let a of n.walk({prune:o=>!!o.meta?.caseSensitive}))if(!a.meta?.caseSensitive){if(s&&a instanceof B){let o=a;for(;o&&o.parent instanceof Se;)o=o.parent;"parts"in o&&Array.isArray(o.parts)&&(a.meta.dotParts=o.parts.map(c=>c.name))}r.normalizeIdentifier(a)}return n}var Rl=new Map,$f=new Set;function kD(i){$f.add(i);let e=i.sqlNames();for(let t of e)Rl.set(t.toUpperCase(),i)}function xB(i,e){return se.getOrRaise(e?.read??e?.dialect).parse(i,e)}function _I(i,e){let t=se.getOrRaise(e?.read??e?.dialect),s=e?.into?t.parseIntoTypes(e.into,i,e):t.parse(i,e);for(let r of s){if(!r)throw new xt(`No expression was parsed from '${i}'`);return r}throw new xt(`No expression was parsed from '${i}'`)}var dU=/:.*?[a-zA-Z+\-]/;function xU(i){if(i.length<1)throw new Error("buildVarMap only accepts an expression list with at least one expression");if(i.length===1&&i[0].isStar)return new nT({this:i[0]});let e=[],t=[];for(let s=0;s<i.length;s+=2)e.push(i[s]),t.push(i[s+1]);return new Ys({keys:CA(e,{copy:!1}),values:CA(t,{copy:!1})})}function fU(i){if(i.length<2)throw new Error("buildLike only accept expression lists with at least 2 expressions");let e=new Ut({this:i[1],expression:i[0]});return 2<i.length?new ma({this:e,expression:i[2]}):e}function ns(i,e={}){let{reverseArgs:t=!1}=e;return function(r){let n=this.parseBitwise(),a=r;return t&&([a,n]=[n,a]),this.parseEscape(this.expression(i,{this:a,expression:n}))}}function TU(i,{dialect:e}){if(i.length<1)throw new Error("buildAlgorithm only accepts an expression list with at least one expression");let t=M(i,0),s=M(i,1);return t&&s?(e._constructor.LOG_BASE_FIRST||([t,s]=[s,t]),new Yi({this:t,expression:s})):e._constructor.parserClass?.LOG_DEFAULTS_TO_LN??!1?new Hl({this:t}):new Yi({this:t})}function _D(i,{dialect:e}){if(i.length<1)throw new Error("buildHex only accepts an expression list with at least one expression");let t=i[0];return e._constructor.HEX_LOWERCASE?new pp({this:t}):new ap({this:t})}function SU(i){if(i.length<1)throw new Error("buildLower only accepts an expression list with at least one expression");let e=i[0];return e instanceof ap?new pp({this:e.args.this}):new Fn({this:e})}function mU(i){if(i.length<1)throw new Error("buildUpper only accepts an expression list with at least one expression");let e=i[0];return e instanceof pp?new ap({this:e.args.this}):new jl({this:e})}function DI(i){return function(t,{dialect:s}){if(t.length<2)throw new Error("buildExtractJsonWithPath only accepts an expression list with at least two expressions");let r=new i({this:t[0],expression:s.toJsonPath(M(t,1))});return 2<t.length&&r instanceof js&&r.setArgKey("expressions",t.slice(2)),r instanceof ao&&r.setArgKey("scalarOnly",s._constructor.JSON_EXTRACT_SCALAR_SCALAR_ONLY),r}}function OU(i){if(i.length<2)throw new Error("buildMod only accepts an expression list with at least two expressions");let e=i[0],t=i[1];return e=e instanceof q?new Oe({this:e}):e,t=t instanceof q?new Oe({this:t}):t,new Bi({this:e,expression:t})}function mN(i,e={}){if(i.length<2)throw new Error("buildPad only accepts an expression list with at least two expressions");let{isLeft:t=!0}=e;return new Vf({this:M(i,0),expression:M(i,1),fillPattern:M(i,2),isLeft:t})}function qD(i,e,t,s){let r=new i({expressions:e});return r instanceof ue&&s._constructor.HAS_DISTINCT_ARRAY_CONSTRUCTORS&&r.setArgKey("bracketNotation",t==="lBracket"),r}function RU(i,e={}){if(i.length<2)throw new Error("buildConvertTimezone only accepts an expression list with at least two expressions");let{defaultSourceTz:t}=e;if(i.length===2){let s=t?R.string(t):void 0,r=M(i,0),n=typeof r=="string"?R.string(r):r,a=M(i,1),o=typeof a=="string"?R.string(a):a;return new po({sourceTz:s,targetTz:n,timestamp:o})}return po.fromArgList(i)}function UD(i,e={}){if(i.length<1)throw new Error("buildTrim only accepts an expression list with at least one expression");let{isLeft:t=!0,reverseArgs:s=!1}=e,r=M(i,0),n=M(i,1);return n&&s&&([r,n]=[n,r]),new cp({this:r,expression:n,position:t?"leading":"trailing"})}function NU(i,e={}){if(i.length<1)throw new Error("buildCoalesce only accepts an expression list with at least one expression");let{isNvl:t,isNull:s}=e;return new rt({this:M(i,0),expressions:i.slice(1),isNvl:t,isNull:s})}function vD(i){if(i.length<2)throw new Error("buildLocateStrposition only accepts an expression list with at least two expressions");return new mr({this:M(i,1),substr:M(i,0),position:M(i,2)})}function IU(i,{dialect:e}){if(i.length<2)throw new Error("buildArrayAppend only accepts an expression list with at least two expressions");return new Wf({this:M(i,0),expression:M(i,1),nullPropagation:e._constructor.ARRAY_FUNCS_PROPAGATES_NULLS})}function yU(i,{dialect:e}){if(i.length<2)throw new Error("buildArrayPrepend only accepts an expression list with at least two expressions");return new jf({this:i[0],expression:i[1],nullPropagation:e._constructor.ARRAY_FUNCS_PROPAGATES_NULLS})}function FD(i,{dialect:e}){if(i.length<1)throw new Error("buildArrayConcat only accepts an expression list with at least one expression");return new _l({this:i[0],expressions:i.slice(1),nullPropagation:e._constructor.ARRAY_FUNCS_PROPAGATES_NULLS})}function CU(i,{dialect:e}){if(i.length<2)throw new Error("buildArrayRemove only accepts an expression list with at least two expressions");return new kl({this:i[0],expression:i[1],nullPropagation:e._constructor.ARRAY_FUNCS_PROPAGATES_NULLS})}var BD,$D,GD,YD,VD,HD,WD,jD,JD,XD,zD,QD,ZD,KD,ek,tk,sk,rk,ik,nk,ak,ok,ck,pk,lk,uk,hk,gk,Ek,Ak,dk,xk,fk,Tk,Sk,mk,Ok,Rk,Nk,Ik,yk,Ck,Pk,bk,Lk,wk,Mk,Dk,kk,_k,qk,Uk,vk,Fk,Bk,$k,Gk,Yk,Vk,Hk,Wk,jk,Jk,Xk,zk,Qk,Zk,Kk,e_,t_,s_,r_,i_,n_,a_,F;a_=[m],n_=[m],i_=[m],r_=[m],s_=[m],t_=[m],e_=[m],Kk=[m],Zk=[m],Qk=[m],zk=[m],Xk=[m],Jk=[m],jk=[m],Wk=[m],Hk=[m],Vk=[m],Yk=[m],Gk=[m],$k=[m],Bk=[m],Fk=[m],vk=[m],Uk=[m],qk=[m],_k=[m],kk=[m],Dk=[m],Mk=[m],wk=[m],Lk=[m],bk=[m],Pk=[m],Ck=[m],yk=[m],Ik=[m],Nk=[m],Rk=[m],Ok=[m],mk=[m],Sk=[m],Tk=[m],fk=[m],xk=[m],dk=[m],Ak=[m],Ek=[m],gk=[m],hk=[m],uk=[m],lk=[m],pk=[m],ck=[m],ok=[m],ak=[m],nk=[m],ik=[m],rk=[m],sk=[m],tk=[m],ek=[m],KD=[m],ZD=[m],QD=[m],zD=[m],XD=[m],JD=[m],jD=[m],WD=[m],HD=[m],VD=[m],YD=[m],GD=[m],$D=[m],BD=[m];var T=class T{constructor(e={}){this.sql=void 0;this.dialect=void 0;this.errorLevel=void 0;this.errorMessageContext=void 0;this.maxErrors=void 0;this.errors=void 0;this.tokens=void 0;this.index=void 0;this.curr=void 0;this.next=void 0;this.prev=void 0;this.prevComments=void 0;this.pipeCteCounter=void 0;let{errorLevel:t=3,errorMessageContext:s=100,maxErrors:r=3}=e;this.sql="",this.dialect=se.getOrRaise(e.dialect),this.errorLevel=t,this.errorMessageContext=s,this.maxErrors=r,this.errors=[],this.tokens=[],this.index=0,this.curr=void 0,this.next=void 0,this.prev=void 0,this.prevComments=void 0,this.pipeCteCounter=0,this.reset()}static get SHOW_TRIE(){return this._showTrie||(this._showTrie=is(Object.keys(this.SHOW_PARSERS).map(e=>e.split(" ")))),this._showTrie}static get SET_TRIE(){return this._setTrie||(this._setTrie=is(Object.keys(this.SET_PARSERS).map(e=>e.split(" ")))),this._setTrie}static get FUNCTIONS(){return{...Object.fromEntries(Array.from(Rl.entries()).map(([e,t])=>[e,(s,r)=>t.fromArgList(s)])),...Object.fromEntries(["COALESCE","IFNULL","NVL"].map(e=>[e,(t,s)=>NU(t)])),ARRAY:(e,t)=>new ue({expressions:e}),ARRAYAGG:(e,{dialect:t})=>new uo({this:e[0],nullsExcluded:t._constructor.ARRAY_AGG_INCLUDES_NULLS===void 0?!0:void 0}),ARRAY_AGG:(e,{dialect:t})=>new uo({this:e[0],nullsExcluded:t._constructor.ARRAY_AGG_INCLUDES_NULLS===void 0?!0:void 0}),ARRAY_APPEND:IU,ARRAY_CAT:FD,ARRAY_CONCAT:FD,ARRAY_PREPEND:yU,ARRAY_REMOVE:CU,COUNT:(e,t)=>new Jl({this:e[0],expressions:e.slice(1),bigInt:!0}),CONCAT:(e,{dialect:t})=>new Gt({expressions:e,safe:!t._constructor.STRICT_STRING_CONCAT,coalesce:t._constructor.CONCAT_COALESCE}),CONCAT_WS:(e,{dialect:t})=>new wt({expressions:e,safe:!t._constructor.STRICT_STRING_CONCAT,coalesce:t._constructor.CONCAT_COALESCE}),CONVERT_TIMEZONE:(e,t)=>RU(e),DATE_ADD:e=>e.length===3?kI(yt)([e[2],e[1],e[0]]):new yt({this:M(e,0),expression:M(e,1)}),DATE_SUB:e=>e.length===3?kI(ts)([e[2],e[1],e[0]]):new ts({this:M(e,0),expression:M(e,1)}),DATE_TO_DATE_STR:(e,t)=>new X({this:e[0],to:new O({this:"text"})}),TIME_TO_TIME_STR:(e,t)=>new X({this:e[0],to:new O({this:"text"})}),GENERATE_DATE_ARRAY:(e,t)=>new Ia({start:e[0],end:e[1],step:M(e,2)||new Ce({this:R.string("1"),unit:Q("DAY")})}),GENERATE_UUID:(e,{dialect:t})=>new NA({isString:t._constructor.UUID_IS_STRING_TYPE||void 0}),GLOB:(e,t)=>new ua({this:e[1],expression:e[0]}),LIKE:(e,t)=>fU(e),GREATEST:(e,{dialect:t})=>new ya({this:e[0],expressions:e.slice(1),ignoreNulls:t._constructor.LEAST_GREATEST_IGNORES_NULLS}),LEAST:(e,{dialect:t})=>new Vl({this:e[0],expressions:e.slice(1),ignoreNulls:t._constructor.LEAST_GREATEST_IGNORES_NULLS}),HEX:(e,{dialect:t})=>_D(e,{dialect:t}),TO_HEX:(e,{dialect:t})=>_D(e,{dialect:t}),JSON_EXTRACT:DI(js),JSON_EXTRACT_SCALAR:DI(ao),JSON_EXTRACT_PATH_TEXT:DI(ao),JSON_KEYS:(e,{dialect:t})=>new tT({this:e[0],expression:t.toJsonPath(M(e,1))}),LOG:(e,{dialect:t})=>TU(e,{dialect:t}),LOG2:(e,t)=>new Yi({this:R.number(2),expression:M(e,0)}),LOG10:(e,t)=>new Yi({this:R.number(10),expression:M(e,0)}),MOD:(e,t)=>OU(e),LOWER:(e,t)=>SU(e),UPPER:(e,t)=>mU(e),LPAD:(e,t)=>mN(e),LEFTPAD:(e,t)=>mN(e),RPAD:(e,t)=>mN(e,{isLeft:!1}),RIGHTPAD:(e,t)=>mN(e,{isLeft:!1}),LTRIM:(e,t)=>UD(e),RTRIM:(e,t)=>UD(e,{isLeft:!1}),STRPOS:(e,t)=>mr.fromArgList(e),INSTR:(e,t)=>mr.fromArgList(e),CHARINDEX:(e,t)=>vD(e),LOCATE:(e,t)=>vD(e),SCOPE_RESOLUTION:(e,t)=>e.length!==2?new ca({expression:e[0]}):new ca({this:M(e,0),expression:e[1]}),TS_OR_DS_TO_DATE_STR:(e,t)=>new er({this:new X({this:e[0],to:new O({this:"text"})}),start:R.number(1),length:R.number(10)}),UNNEST:(e,t)=>new ge({expressions:[e[0]]}),UUID:(e,{dialect:t})=>new NA({isString:t._constructor.UUID_IS_STRING_TYPE||void 0}),VAR_MAP:(e,t)=>xU(e)}}static get NO_PAREN_FUNCTIONS(){return{currentDate:$i,currentDatetime:$i,currentTime:Ra,currentTimestamp:Na,currentUser:zf,localtime:Fl,localtimestamp:Xf,currentRole:Qf}}static get STRUCT_TYPE_TOKENS(){return new Set(["file","nested","object","struct","union"])}static get NESTED_TYPE_TOKENS(){return new Set(["array","list","lowcardinality","map","nullable","range",...T.STRUCT_TYPE_TOKENS])}static get ENUM_TYPE_TOKENS(){return new Set(["dynamic","enum","enum8","enum16"])}static get AGGREGATE_TYPE_TOKENS(){return new Set(["aggregatefunction","simpleaggregatefunction"])}static get TYPE_TOKENS(){return new Set(["bit","boolean","tinyint","utinyint","smallint","usmallint","int","uint","bigint","ubigint","bignum","int128","uint128","int256","uint256","mediumint","umediumint","fixedstring","float","double","udouble","char","nchar","varchar","nvarchar","bpchar","text","mediumtext","longtext","blob","mediumblob","longblob","binary","varbinary","json","jsonb","interval","tinyblob","tinytext","time","timetz","timeNs","timestamp","timestampS","timestampMs","timestampNs","timestamptz","timestampltz","timestampntz","datetime","datetime2","datetime64","smalldatetime","date","date32","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange","decimal","decimal32","decimal64","decimal128","decimal256","decfloat","udecimal","bigdecimal","uuid","geography","geographypoint","geometry","point","ring","linestring","multilinestring","polygon","multipolygon","hllsketch","hstore","pseudoType","super","serial","smallserial","bigserial","xml","year","userdefined","money","smallmoney","rowversion","image","variant","vector","void","object","objectIdentifier","inet","ipaddress","ipprefix","ipv4","ipv6","unknown","nothing","null","name","tdigest","dynamic",...T.ENUM_TYPE_TOKENS,...T.NESTED_TYPE_TOKENS,...T.AGGREGATE_TYPE_TOKENS])}static get SIGNED_TO_UNSIGNED_TYPE_TOKEN(){return{bigint:"ubigint",int:"uint",mediumint:"umediumint",smallint:"usmallint",tinyint:"utinyint",decimal:"udecimal",double:"udouble"}}static get SUBQUERY_PREDICATES(){return{any:Ct,all:ys,exists:Pi,some:Ct}}static get RESERVED_TOKENS(){return new Set([...Object.values(Qn.SINGLE_TOKENS),"select"].filter(e=>e!=="identifier"))}static get DB_CREATABLES(){return new Set(["database","dictionary","fileFormat","model","namespace","schema","semanticView","sequence","sink","source","stage","storageIntegration","streamlit","table","tag","view","warehouse"])}static get CREATABLES(){return new Set(["column","constraint","foreignKey","function","index","procedure",...T.DB_CREATABLES])}static get ALTERABLES(){return new Set(["index","table","view","session"])}static get ID_VAR_TOKENS(){return(()=>{let e=new Set(["all","analyze","attach","var","anti","apply","asc","asof","autoIncrement","begin","bpchar","cache","case","collate","command","comment","commit","constraint","copy","cube","currentSchema","default","delete","desc","describe","detach","dictionary","div","end","execute","export","escape","false","first","filter","final","format","full","get","identifier","inout","is","isnull","interval","keep","kill","left","limit","load","lock","match","merge","natural","next","offset","operator","ordinality","over","overlaps","overwrite","partition","percent","pivot","pragma","put","range","recursive","references","refresh","rename","replace","right","rollup","row","rows","semi","set","settings","show","temporary","top","true","truncate","unique","unnest","unpivot","update","use","volatile","window",...T.ALTERABLES,...T.CREATABLES,...Object.keys(T.SUBQUERY_PREDICATES),...T.TYPE_TOKENS,...Object.keys(T.NO_PAREN_FUNCTIONS)]);return e.delete("union"),e})()}static get TABLE_ALIAS_TOKENS(){return new Set([...T.ID_VAR_TOKENS].filter(e=>!["anti","asof","full","left","lock","natural","right","semi","window"].includes(e)))}static get ALIAS_TOKENS(){return T.ID_VAR_TOKENS}static get COLON_PLACEHOLDER_TOKENS(){return T.ID_VAR_TOKENS}static get ARRAY_CONSTRUCTORS(){return{ARRAY:ue,LIST:Yf}}static get COMMENT_TABLE_ALIAS_TOKENS(){return new Set([...T.TABLE_ALIAS_TOKENS].filter(e=>e!=="is"))}static get UPDATE_ALIAS_TOKENS(){return new Set([...T.TABLE_ALIAS_TOKENS].filter(e=>e!=="set"))}static get TRIM_TYPES(){return new Set(["leading".toUpperCase(),"trailing".toUpperCase(),"both".toUpperCase()])}static get FUNC_TOKENS(){return new Set(["collate","command","currentDate","currentDatetime","currentSchema","currentTimestamp","currentTime","currentUser","currentCatalog","filter","first","format","get","glob","identifier","index","isnull","ilike","insert","like","localtime","localtimestamp","merge","next","offset","primaryKey","range","replace","rlike","row","sessionUser","unnest","var","left","right","sequence","date","datetime","table","timestamp","timestamptz","truncate","utcDate","utcTime","utcTimestamp","window","xor",...T.TYPE_TOKENS,...Object.keys(T.SUBQUERY_PREDICATES)])}static get CONJUNCTION(){return{and:ce}}static get ASSIGNMENT(){return{colonEq:ct}}static get DISJUNCTION(){return{or:ze}}static get EQUALITY(){return{eq:me,neq:st,nullsafeEq:Ps}}static get COMPARISON(){return{gt:Be,gte:Me,lt:De,lte:$e}}static get BITWISE(){return{amp:Ta,caret:Dl,pipe:Ml}}static get TERM(){return{dash:ke,plus:Le,mod:Bi,collate:RA}}static get FACTOR(){return{div:ha,lrArrow:kA,slash:mt,star:Ns}}static get EXPONENT(){return{}}static get TIMES(){return new Set(["time","timetz"])}static get TIMESTAMPS(){return new Set(["timestamp","timestampntz","timestamptz","timestampltz",...T.TIMES])}static get SET_OPERATIONS(){return new Set(["union","intersect","except"])}static get JOIN_METHODS(){return new Set(["asof","natural","positional"])}static get JOIN_SIDES(){return new Set(["left","right","full"])}static get JOIN_KINDS(){return new Set(["anti","cross","inner","outer","semi","straightJoin"])}static get LAMBDAS(){return{arrow:function(e){return this.expression(Yt,{this:this.replaceLambda(this.parseDisjunction(),e),expressions:e})},farrow:function(e){return this.expression(sp,{this:Q(e[0].name),expression:this.parseDisjunction()})}}}static get COLUMN_OPERATORS(){return{dot:void 0,dotcolon:function(e,t){return this.expression(_A,{this:e,to:t})},dcolon:function(e,t){return this.buildCast({strict:this._constructor.STRICT_CAST,this:e,to:t})},arrow:function(e,t){return this.expression(js,{this:e,expression:this.dialect.toJsonPath(t),onlyJsonTypes:this._constructor.JSON_ARROWS_REQUIRE_JSON_TYPE})},darrow:function(e,t){return this.expression(ao,{this:e,expression:this.dialect.toJsonPath(t),onlyJsonTypes:this._constructor.JSON_ARROWS_REQUIRE_JSON_TYPE,scalarOnly:this._dialectConstructor.JSON_EXTRACT_SCALAR_SCALAR_ONLY})},hashArrow:function(e,t){return this.expression(Yl,{this:e,expression:t})},dhashArrow:function(e,t){return this.expression(iT,{this:e,expression:t})},placeholder:function(e,t){return this.expression(Ca,{this:e,expression:t})}}}static get CAST_COLUMN_OPERATORS(){return new Set(["dotcolon","dcolon"])}static get EXPRESSION_PARSERS(){return{cluster:function(){return this.parseSort(Nr,"clusterBy")},column:function(){return this.parseColumn()},columnDef:function(){return this.parseColumnDef(this.parseColumn())},condition:function(){return this.parseDisjunction()},dataType:function(){return this.parseTypes({allowIdentifiers:!1,schema:!0})},expression:function(){return this.parseExpression()},from:function(){return this.parseFrom({joins:!0})},grantPrincipal:function(){return this.parseGrantPrincipal()},grantPrivilege:function(){return this.parseGrantPrivilege()},group:function(){return this.parseGroup()},having:function(){return this.parseHaving()},hint:function(){return this.parseHintBody()},identifier:function(){return this.parseIdVar()},join:function(){return this.parseJoin()},lambda:function(){return this.parseLambda()},lateral:function(){return this.parseLateral()},limit:function(){return this.parseLimit()},offset:function(){return this.parseOffset()},order:function(){return this.parseOrder()},ordered:function(){return this.parseOrdered()},properties:function(){return this.parseProperties()},partitionedByProperty:function(){return this.parsePartitionedBy()},qualify:function(){return this.parseQualify()},returning:function(){return this.parseReturning()},select:function(){return this.parseSelect()},sort:function(){return this.parseSort(co,"sortBy")},table:function(){return this.parseTableParts()},tableAlias:function(){return this.parseTableAlias()},tuple:function(){return this.parseValue({values:!1})},whens:function(){return this.parseWhenMatched()},where:function(){return this.parseWhere()},window:function(){return this.parseNamedWindow()},with:function(){return this.parseWith()},JOIN_TYPE:function(){let{method:e,side:t,kind:s}=this.parseJoinParts();return new oe({method:e?.text,side:ut(Qt,t?.text),kind:ut(Qt,s?.text)})}}}static get STATEMENT_PARSERS(){return{alter:function(){return this.parseAlter()},analyze:function(){return this.parseAnalyze()},begin:function(){return this.parseTransaction()},cache:function(){return this.parseCache()},comment:function(){return this.parseComment()},commit:function(){return this.parseCommitOrRollback()},copy:function(){return this.parseCopy()},create:function(){return this.parseCreate()},delete:function(){return this.parseDelete()},desc:function(){return this.parseDescribe()},describe:function(){return this.parseDescribe()},drop:function(){return this.parseDrop()},grant:function(){return this.parseGrant()},revoke:function(){return this.parseRevoke()},insert:function(){return this.parseInsert()},kill:function(){return this.parseKill()},load:function(){return this.parseLoad()},merge:function(){return this.parseMerge()},pivot:function(){return this.parseSimplifiedPivot()},pragma:function(){return this.expression(mo,{this:this.parseExpression()})},refresh:function(){return this.parseRefresh()},rollback:function(){return this.parseCommitOrRollback()},set:function(){return this.parseSet()},truncate:function(){return this.parseTruncateTable()},uncache:function(){return this.parseUncache()},unpivot:function(){return this.parseSimplifiedPivot({isUnpivot:!0})},update:function(){return this.parseUpdate()},use:function(){return this.parseUse()},semicolon:()=>new _c({})}}static get UNARY_PARSERS(){return{plus:function(){return this.parseUnary()},not:function(){return this.expression(be,{this:this.parseEquality()})},tilde:function(){return this.expression(np,{this:this.parseUnary()})},dash:function(){return this.expression(It,{this:this.parseUnary()})},pipeSlash:function(){return this.expression(Wl,{this:this.parseUnary()})},dpipeSlash:function(){return this.expression(vl,{this:this.parseUnary()})}}}static get STRING_PARSERS(){return{heredocString:function(e){return this.expression(pa,{token:e})},nationalString:function(e){return this.expression(Vo,{token:e})},rawString:function(e){return this.expression(pa,{token:e})},string:function(e){return this.expression(R,{token:e,isString:!0})},unicodeString:function(e){return this.expression(Il,{token:e,escape:this.matchTextSeq("UESCAPE")&&this.parseString()})}}}static get NUMERIC_PARSERS(){return{bitString:function(e){return this.expression(PA,{token:e})},byteString:function(e){return this.expression(Nl,{token:e,isBytes:this._dialectConstructor.BYTE_STRING_IS_BYTES_TYPE||void 0})},hexString:function(e){return this.expression(da,{token:e,isInteger:this._dialectConstructor.HEX_STRING_IS_INTEGER_TYPE||void 0})},number:function(e){return this.expression(R,{token:e,isString:!1})}}}static get PRIMARY_PARSERS(){return{...T.STRING_PARSERS,...T.NUMERIC_PARSERS,introducer:function(e){return this.parseIntroducer(e)},null:function(e){return this.expression(Ze,{})},true:function(e){return this.expression(ot,{this:!0})},false:function(e){return this.expression(ot,{this:!1})},sessionParameter:function(e){return this.parseSessionParameter()},star:function(e){return this.parseStarOps()}}}static get PLACEHOLDER_PARSERS(){return{placeholder:function(){return this.expression(Ds)},parameter:function(){return this.parseParameter()},colon:function(){return this.matchSet(this._constructor.COLON_PLACEHOLDER_TOKENS)?this.expression(Ds,{this:this.prev?.text}):void 0}}}static get RANGE_PARSERS(){return{atGt:ns(lo),between:function(e){return this.parseBetween(e)},glob:ns(ua),ilike:ns(Us),in:function(e){return this.parseIn(e)},irlike:ns(pT),is:function(e){return this.parseIs(e)},like:ns(Ut),ltAt:ns(lo,{reverseArgs:!0}),overlaps:ns(DA),rlike:ns(op),similarTo:ns(rp),for:function(e){return this.parseComprehension(e)},qmarkAmp:ns(Un),qmarkPipe:ns(qn),hashDash:ns(vn),adjacent:ns(ip),operator:function(e){return this.parseOperator(e)},ampLt:ns(ep),ampGt:ns(tp)}}static get PIPE_SYNTAX_TRANSFORM_PARSERS(){return{AGGREGATE:function(e){return this.parsePipeSyntaxAggregate(e)},AS:function(e){return this.buildPipeCte({query:e,expressions:[new xe({})],aliasCte:this.parseTableAlias()})},EXTEND:function(e){return this.parsePipeSyntaxExtend(e)},LIMIT:function(e){return this.parsePipeSyntaxLimit(e)},"ORDER BY":function(e){return e.orderBy(this.parseOrder(),{append:!1,copy:!1})},PIVOT:function(e){return this.parsePipeSyntaxPivot(e)},SELECT:function(e){return this.parsePipeSyntaxSelect(e)},TABLESAMPLE:function(e){return this.parsePipeSyntaxTablesample(e)},UNPIVOT:function(e){return this.parsePipeSyntaxPivot(e)},WHERE:function(e){return e.where(this.parseWhere(),{copy:!1})}}}static get PROPERTY_PARSERS(){return{ALLOWED_VALUES:function(){return this.expression(Dr,{expressions:this.parseCsv(this.parsePrimary.bind(this))})},ALGORITHM:function(){return this.parsePropertyAssignment(qr)},AUTO:function(){return this.parseAutoProperty()},AUTO_INCREMENT:function(){return this.parsePropertyAssignment(Ur)},BACKUP:function(){return this.expression(Fr,{this:this.parseVar({anyToken:!0})})},BLOCKCOMPRESSION:function(){return this.parseBlockCompression()},CHARSET:function(e){return this.parseCharacterSet(e)},"CHARACTER SET":function(e){return this.parseCharacterSet(e)},CHECKSUM:function(){return this.parseChecksum()},"CLUSTER BY":function(){return this.parseCluster()},CLUSTERED:function(){return this.parseClusteredBy()},COLLATE:function(){return this.parsePropertyAssignment(Br)},COMMENT:function(){return this.parsePropertyAssignment(Ei)},CONTAINS:function(){return this.parseContainsProperty()},COPY:function(){return this.parseCopyProperty()},DATABLOCKSIZE:function(e){return this.parseDataBlocksize(e)},DATA_DELETION:function(){return this.parseDataDeletionProperty()},DEFINER:function(){return this.parseDefiner()},DETERMINISTIC:function(){return this.expression(As,{this:R.string("IMMUTABLE")})},DISTRIBUTED:function(){return this.parseDistributedProperty()},DUPLICATE:function(){return this.parseCompositeKeyProperty(dn)},DYNAMIC:function(){return this.expression(ri,{})},DISTKEY:function(){return this.parseDistkey()},DISTSTYLE:function(){return this.parsePropertyAssignment(Hr)},EMPTY:function(){return this.expression(ii,{})},ENGINE:function(){return this.parsePropertyAssignment(Wr)},ENVIRONMENT:function(){return this.expression(ti,{expressions:this.parseWrappedCsv(this.parseAssignment.bind(this))})},EXECUTE:function(){return this.parsePropertyAssignment(Ms)},EXTERNAL:function(){return this.expression(Xr,{})},FALLBACK:function(e){return this.parseFallback(e)},FORMAT:function(){return this.parsePropertyAssignment(ws)},FREESPACE:function(){return this.parseFreespace()},GLOBAL:function(){return this.expression(zr,{})},HEAP:function(){return this.expression(jr,{})},ICEBERG:function(){return this.expression(Qr,{})},IMMUTABLE:function(){return this.expression(As,{this:R.string("IMMUTABLE")})},INHERITS:function(){return this.expression(Zr,{expressions:this.parseWrappedCsv(this.parseTable.bind(this))})},INPUT:function(){return this.expression(Kr,{this:this.parseSchema()})},JOURNAL:function(e){return this.parseJournal(e)},LANGUAGE:function(){return this.parsePropertyAssignment(nr)},LAYOUT:function(){return this.parseDictProperty({this:"LAYOUT"})},LIFETIME:function(){return this.parseDictRange({this:"LIFETIME"})},LIKE:function(){return this.parseCreateLike()},LOCATION:function(){return this.parsePropertyAssignment(ar)},LOCK:function(){return this.parseLocking()},LOCKING:function(){return this.parseLocking()},LOG:function(e){return this.parseLog(e)},MATERIALIZED:function(){return this.expression(ai,{})},MERGEBLOCKRATIO:function(e){return this.parseMergeBlockRatio(e)},MODIFIES:function(){return this.parseModifiesProperty()},MULTISET:function(){return this.expression(Zs,{multi:!0})},NO:function(){return this.parseNoProperty()},ON:function(){return this.parseOnProperty()},"ORDER BY":function(){return this.parseOrder({skipOrderToken:!0})},OUTPUT:function(){return this.expression(ei,{this:this.parseSchema()})},PARTITION:function(){return this.parsePartitionedOf()},"PARTITION BY":function(){return this.parsePartitionedBy()},"PARTITIONED BY":function(){return this.parsePartitionedBy()},PARTITIONED_BY:function(){return this.parsePartitionedBy()},"PRIMARY KEY":function(){return this.parsePrimaryKey({inProps:!0})},RANGE:function(){return this.parseDictRange({this:"RANGE"})},READS:function(){return this.parseReadsProperty()},REMOTE:function(){return this.parseRemoteWithConnection()},RETURNS:function(){return this.parseReturns()},STRICT:function(){return this.expression(li,{})},STREAMING:function(){return this.expression(ci,{})},ROW:function(){return this.parseRow()},ROW_FORMAT:function(){return this.parsePropertyAssignment(ui)},SAMPLE:function(){return this.expression(hi,{this:this.matchTextSeq("BY")&&this.parseBitwise()})},SECURE:function(){return this.expression(Ti,{})},SECURITY:function(){return this.parseSecurity()},SET:function(){return this.expression(Zs,{multi:!1})},SETTINGS:function(){return this.parseSettingsProperty()},SHARING:function(){return this.parsePropertyAssignment(Ai)},SORTKEY:function(){return this.parseSortkey()},SOURCE:function(){return this.parseDictProperty({this:"SOURCE"})},STABLE:function(){return this.expression(As,{this:R.string("STABLE")})},STORED:function(){return this.parseStored()},SYSTEM_VERSIONING:function(){return this.parseSystemVersioningProperty()},TBLPROPERTIES:function(){return this.parseWrappedProperties()},TEMP:function(){return this.expression(ds,{})},TEMPORARY:function(){return this.expression(ds,{})},TO:function(){return this.parseToTable()},TRANSIENT:function(){return this.expression(mi,{})},TRANSFORM:function(){return this.expression(Si,{expressions:this.parseWrappedCsv(this.parseExpression.bind(this))})},TTL:function(){return this.parseTtl()},USING:function(){return this.parsePropertyAssignment(ws)},UNLOGGED:function(){return this.expression(Oi,{})},VOLATILE:function(){return this.parseVolatileProperty()},WITH:function(){return this.parseWithProperty()}}}static get CONSTRAINT_PARSERS(){return{AUTOINCREMENT:function(){return this.parseAutoIncrement()},AUTO_INCREMENT:function(){return this.parseAutoIncrement()},CASESPECIFIC:function(){return this.expression(Pr,{not:!1})},"CHARACTER SET":function(){return this.expression(Uc,{this:this.parseVarOrString()})},CHECK:function(){return this.parseCheckConstraint()},COLLATE:function(){return this.expression(Fc,{this:this.parseIdentifier()||this.parseColumn()})},COMMENT:function(){return this.expression(Bc,{this:this.parseString()})},COMPRESS:function(){return this.parseCompress()},CLUSTERED:function(){return this.expression(vc,{this:this.parseWrappedCsv(()=>this.parseOrdered())})},NONCLUSTERED:function(){return this.expression(jc,{this:this.parseWrappedCsv(()=>this.parseOrdered())})},DEFAULT:function(){return this.expression(Gc,{this:this.parseBitwise()})},ENCODE:function(){return this.expression(Yc,{this:this.parseVar()})},EPHEMERAL:function(){return this.expression(xa,{this:this.parseBitwise()})},EXCLUDE:function(){return this.expression(Vc,{this:this.parseIndexParams()})},"FOREIGN KEY":function(){return this.parseForeignKey()},FORMAT:function(){return this.expression($c,{this:this.parseVarOrString()})},GENERATED:function(){return this.parseGeneratedAsIdentity()},IDENTITY:function(){return this.parseAutoIncrement()},INLINE:function(){return this.parseInline()},LIKE:function(){return this.parseCreateLike()},NOT:function(){return this.parseNotConstraint()},NULL:function(){return this.expression(la,{allowNull:!0})},ON:function(){return this.match("update")&&this.expression(Jc,{this:this.parseFunction()})||this.expression(zs,{this:this.parseIdVar()})},PATH:function(){return this.expression(Qc,{this:this.parseString()})},PERIOD:function(){return this.parsePeriodForSystemTime()},"PRIMARY KEY":function(){return this.parsePrimaryKey()},REFERENCES:function(){return this.parseReferences({match:!1})},TITLE:function(){return this.expression(zc,{this:this.parseVarOrString()})},TTL:function(){return this.expression(Ir,{expressions:[this.parseBitwise()]})},UNIQUE:function(){return this.parseUnique()},UPPERCASE:function(){return this.expression(un)},WITH:function(){return this.expression(Ke,{expressions:this.parseWrappedProperties()})},BUCKET:function(){return this.parsePartitionedByBucketOrTruncate()},TRUNCATE:function(){return this.parsePartitionedByBucketOrTruncate()}}}static get ALTER_PARSERS(){return{ADD:function(){return this.parseAlterTableAdd()},AS:function(){return this.parseSelect()},ALTER:function(){return this.parseAlterTableAlter()},"CLUSTER BY":function(){return this.parseCluster({wrapped:!0})},DELETE:function(){return this.expression(Js,{where:this.parseWhere()})},DROP:function(){return this.parseAlterTableDrop()},RENAME:function(){return this.parseAlterTableRename()},SET:function(){return this.parseAlterTableSet()},SWAP:function(){return this.expression(Wi,{this:this.match("with")&&this.parseTable({schema:!0})})}}}static get NO_PAREN_FUNCTION_PARSERS(){return{ANY:function(){return this.expression(Ct,{this:this.parseBitwise()})},CASE:function(){return this.parseCase()},CONNECT_BY_ROOT:function(){return this.expression(Ul,{this:this.parseColumn()})},IF:function(){return this.parseIf()}}}static get INVALID_FUNC_NAME_TOKENS(){return new Set(["identifier","string"])}static get KEY_VALUE_DEFINITIONS(){return new Set([Re,me,ct,Tr])}static get FUNCTION_PARSERS(){return{...Object.fromEntries(IA.sqlNames().map(e=>[e,function(){return this.parseMaxMinBy(IA)}])),...Object.fromEntries(yA.sqlNames().map(e=>[e,function(){return this.parseMaxMinBy(yA)}])),CAST:function(){return this.parseCast({strict:this._constructor.STRICT_CAST})},CEIL:function(){return this.parseCeilFloor(Oa)},CONVERT:function(){return this.parseConvert({strict:this._constructor.STRICT_CAST})},CHAR:function(){return this.parseChar()},CHR:function(){return this.parseChar()},DECODE:function(){return this.parseDecode()},EXTRACT:function(){return this.parseExtract()},FLOOR:function(){return this.parseCeilFloor(Bl)},GAP_FILL:function(){return this.parseGapFill()},INITCAP:function(){return this.parseInitcap()},JSON_OBJECT:function(){return this.parseJsonObject()},JSON_OBJECTAGG:function(){return this.parseJsonObject({agg:!0})},JSON_TABLE:function(){return this.parseJsonTable()},MATCH:function(){return this.parseMatchAgainst()},NORMALIZE:function(){return this.parseNormalize()},OPENJSON:function(){return this.parseOpenJson()},OVERLAY:function(){return this.parseOverlay()},POSITION:function(){return this.parsePosition()},SAFE_CAST:function(){return this.parseCast({strict:!1,safe:!0})},STRING_AGG:function(){return this.parseStringAgg()},SUBSTRING:function(){return this.parseSubstring()},TRIM:function(){return this.parseTrim()},TRY_CAST:function(){return this.parseCast({strict:!1,safe:!0})},TRY_CONVERT:function(){return this.parseConvert({strict:!1,safe:!0})},XMLELEMENT:function(){return this.parseXmlElement()},XMLTABLE:function(){return this.parseXmlTable()}}}static get QUERY_MODIFIER_PARSERS(){return{matchRecognize:function(){return["match",this.parseMatchRecognize()]},prewhere:function(){return["prewhere",this.parsePrewhere()]},where:function(){return["where",this.parseWhere()]},groupBy:function(){return["group",this.parseGroup()]},having:function(){return["having",this.parseHaving()]},qualify:function(){return["qualify",this.parseQualify()]},window:function(){return["windows",this.parseWindowClause()]},orderBy:function(){return["order",this.parseOrder()]},limit:function(){return["limit",this.parseLimit()]},fetch:function(){return["limit",this.parseLimit()]},offset:function(){return["offset",this.parseOffset()]},for:function(){return["locks",this.parseLocks()]},lock:function(){return["locks",this.parseLocks()]},tableSample:function(){return["sample",this.parseTableSample({asModifier:!0})]},using:function(){return["sample",this.parseTableSample({asModifier:!0})]},clusterBy:function(){return["cluster",this.parseSort(Nr,"clusterBy")]},distributeBy:function(){return["distribute",this.parseSort(LA,"distributeBy")]},sortBy:function(){return["sort",this.parseSort(co,"sortBy")]},connectBy:function(){return["connect",this.parseConnect({skipStartToken:!0})]},startWith:function(){return["connect",this.parseConnect()]}}}static get QUERY_MODIFIER_TOKENS(){return new Set(Object.keys(T.QUERY_MODIFIER_PARSERS))}static get TYPE_LITERAL_PARSERS(){return{json:function(e,t){return this.expression(Pa,{this:e})}}}static get TYPE_CONVERTERS(){return{}}static get DDL_SELECT_TOKENS(){return new Set(["select","with","lParen"])}static get PRE_VOLATILE_TOKENS(){return new Set(["create","replace","unique"])}static get OPTYPE_FOLLOW_TOKENS(){return new Set(["comma","rParen"])}static get TABLE_INDEX_HINT_TOKENS(){return new Set(["force","ignore","use"])}static get WINDOW_ALIAS_TOKENS(){return(()=>{let e=new Set(T.ID_VAR_TOKENS);return e.delete("range"),e.delete("rows"),e})()}static get WINDOW_BEFORE_PAREN_TOKENS(){return new Set(["over"])}static get JSON_KEY_VALUE_SEPARATOR_TOKENS(){return new Set(["colon","comma","is"])}static get FETCH_TOKENS(){return(()=>{let e=new Set(T.ID_VAR_TOKENS);return e.delete("row"),e.delete("rows"),e.delete("percent"),e})()}static get ADD_CONSTRAINT_TOKENS(){return new Set(["constraint","foreignKey","index","key","primaryKey","unique"])}static get DISTINCT_TOKENS(){return new Set(["distinct"])}static get UNNEST_OFFSET_ALIAS_TOKENS(){return(()=>{let e=new Set(T.TABLE_ALIAS_TOKENS);for(let t of T.SET_OPERATIONS)e.delete(t);return e})()}static get SELECT_START_TOKENS(){return new Set(["lParen","with","select"])}static get PRIVILEGE_FOLLOW_TOKENS(){return new Set(["on","comma","lParen"])}static get AMBIGUOUS_ALIAS_TOKENS(){return["limit","offset"]}static get MODIFIABLES(){return[z,V,zn,Ls]}reset(){this.sql="",this.errors=[],this.tokens=[],this.index=0,this.curr=void 0,this.next=void 0,this.prev=void 0,this.prevComments=void 0,this.pipeCteCounter=0}parse(e,t){return this._parse({parseMethod:function(){return this.parseStatement()},rawTokens:e,sql:t})}_parse(e){let{parseMethod:t,rawTokens:s,sql:r}=e;this.reset(),this.sql=r||"";let n=s.length,a=[[]];for(let c=0;c<s.length;c++){let l=s[c];l.tokenType==="semicolon"?(l.comments.length&&a.push([l]),c<n-1&&a.push([])):a[a.length-1].push(l)}let o=[];for(let c of a)this.index=-1,this.tokens=c,this.advance(),o.push(t.call(this)),this.index<this.tokens.length&&this.raiseError("Invalid expression / Unexpected token"),this.checkErrors();return o}parseIntoTypes(e,t,s){let r=[],n=J(e);for(let c of n){let l=typeof c=="string"?this._constructor.EXPRESSION_PARSERS[c]??this._constructor.EXPRESSION_PARSERS[c.charAt(0).toLowerCase()+c.slice(1)]:this._constructor.EXPRESSION_PARSERS[c.key];if(!l)throw new TypeError(`No parser registered for ${c}`);try{return this._parse({parseMethod:l,rawTokens:t,sql:s})}catch(u){if(u instanceof xt)u.errors[0].intoExpression=typeof c=="string"?c:c.name,r.push(u);else throw u}}let o=`[${J(e).map(c=>typeof c=="string"?c:c.name).join(", ")}]`;throw new xt(`Failed to parse '${s||t}' into ${o}`,cI(r))}findSql(e,t){return this.sql.slice(e?.start??0,(t?.end??0)+1)}isConnected(){return!!(this.prev&&this.curr&&(this.prev.end??0)+1===(this.curr.start??0))}advance(e=1){this.index+=e,this.curr=M(this.tokens,this.index),this.next=M(this.tokens,this.index+1),0<this.index?(this.prev=this.tokens[this.index-1],this.prevComments=this.prev.comments):(this.prev=void 0,this.prevComments=void 0)}retreat(e){e!==this.index&&this.advance(e-this.index)}warnUnsupported(){if(this.tokens.length<=1)return;let e=this.findSql(this.tokens[0],this.tokens[this.tokens.length-1]).slice(0,this.errorMessageContext);console.warn(`'${e}' contains unsupported syntax. Falling back to parsing as a 'Command'.`)}match(e,t={}){let{advance:s=!0,expression:r}=t;return this.curr?.tokenType===e?(s&&this.advance(),this.addComments(r),!0):!1}tryParse(e,t={}){let{retreat:s=!1}=t,r=this.index,n=this.errorLevel;this.errorLevel=3;let a;try{a=e()}catch(o){if(o instanceof xt)a=void 0;else throw o}finally{(!a||s)&&this.retreat(r),this.errorLevel=n}return a}parseParen(){if(!this.match("lParen"))return;let e=this.prevComments,t=this.parseSelect(),s;t?s=[t]:s=this.parseExpressions();let r=M(s,0);return!r&&this.match("rParen",{advance:!1})?r=this.expression(Ge,{}):r&&Er.some(n=>r instanceof n)?r=this.parseSubquery(r,{parseAlias:!1}):r instanceof Te||r instanceof Ls?r=this.parseSubquery(this.parseQueryModifiers(this.parseSetOperations(r)),{parseAlias:!1}):1<s.length||this.prev?.tokenType==="comma"?r=this.expression(Ge,{expressions:s}):r=this.expression(Oe,{this:r}),r&&e&&r.addComments(e),this.matchRParen(r),r instanceof Oe&&r.args.this instanceof D?this.parseWindow(r):r}parseDrop(e={}){let{exists:t}=e,s=this.prev,r=this.match("temporary")||void 0,n=this.matchTextSeq("MATERIALIZED")||void 0,a=(this.matchSet(this._constructor.CREATABLES)||void 0)&&this.prev?.text.toUpperCase();if(!a)return this.parseAsCommand(s);let o=this.matchTextSeq("CONCURRENTLY")||void 0,c=t||this.parseExists(),l;a==="COLUMN"?l=this.parseColumn():l=this.parseTableParts({schema:!0,isDbReference:this.prev?.tokenType==="schema"});let u=this.match("on")?this.parseOnProperty():void 0,h;return this.match("lParen",{advance:!1})&&(h=this.parseWrappedCsv(()=>this.parseTypes())),this.expression(Ji,{exists:c,this:l,expressions:h,kind:ut(oN,this._dialectConstructor.CREATABLE_KIND_MAPPING[a]||a)??(this._dialectConstructor.CREATABLE_KIND_MAPPING[a]||a),temporary:r,materialized:n,cascade:this.matchTextSeq("CASCADE"),constraints:this.matchTextSeq("CONSTRAINTS"),purge:this.matchTextSeq("PURGE"),cluster:u,concurrently:o})}parseExists(e={}){let{not:t}=e;return this.matchTextSeq("IF")&&(!t||this.match("not"))&&this.match("exists")?!0:void 0}parseCreate(){let e=this.prev,t=e?.tokenType==="replace"||this.matchPair("or","replace")||this.matchPair("or","alter"),s=this.matchPair("or","refresh")||void 0,r=this.match("unique")||void 0,n;this.matchTextSeq(["CLUSTERED","COLUMNSTORE"])?n=!0:(this.matchTextSeq(["NONCLUSTERED","COLUMNSTORE"])||this.matchTextSeq("COLUMNSTORE"))&&(n=!1),this.matchPair("table","function",{advance:!1})&&this.advance();let a,o=(this.matchSet(this._constructor.CREATABLES)||void 0)&&this.prev;if(!o&&(a=this.parseProperties(),o=(this.matchSet(this._constructor.CREATABLES)||void 0)&&this.prev,!a||!o))return this.parseAsCommand(e);let c=this.matchTextSeq("CONCURRENTLY")||void 0,l=this.parseExists({not:!0}),u,h,d,x,f,y,I,N=_=>{a&&_?a.args.expressions?.push(..._.args.expressions??[]):_&&(a=_)};if(o.tokenType==="function"||o.tokenType==="procedure"){if(u=this.parseUserDefinedFunction({kind:o.tokenType}),N(this.parseProperties()),h=this.match("alias")&&this.parseHeredoc()||void 0,N(this.parseProperties()),!h)if(this.match("command"))h=this.parseAsCommand(this.prev);else{f=this.match("begin")||void 0;let _=this.matchTextSeq("RETURN")||void 0;this.match("string",{advance:!1})?(h=this.parseString(),N(this.parseProperties())):h=this.parseUserDefinedFunctionExpression(),y=this.matchTextSeq("END")||void 0,_&&(h=this.expression(en,{this:h}))}}else if(o.tokenType==="index"){let _,W;this.match("on")?(_=void 0,W=!0):(_=this.parseIdVar(),W=!1),u=this.parseIndex({index:_,anonymous:W})}else if(this._constructor.DB_CREATABLES.has(o.tokenType)){let _=this.parseTableParts({schema:!0,isDbReference:o.tokenType==="schema"});this.match("comma"),N(this.parseProperties({before:!0})),u=this.parseSchema({this:_}),N(this.parseProperties());let W=this.match("alias")||void 0;if(this.matchSet(this._constructor.DDL_SELECT_TOKENS,{advance:!1})||N(this.parseProperties()),o.tokenType==="sequence"){h=this.parseTypes();let ne=this.parseProperties();if(ne){let Y=new Hs({}),He=[];for(let ve of ne.args.expressions??[])if(ve instanceof Hs){for(let[Xt,Ft]of Object.entries(ve.args))Xt==="options"?He.push(...Ft):Y.setArgKey(Xt,Ft);ve.pop()}0<He.length&&Y.setArgKey("options",He),ne.args.expressions?.push(Y),N(ne)}}else h=this.parseDdlSelect(),!h&&W&&(h=this.tryParse(()=>this.parseTableParts()));if(o.tokenType==="table")for(N(this.parseProperties()),d=[];;){let ne=this.parseIndex();if(N(this.parseProperties()),ne)this.match("comma"),d.push(ne);else break}else o.tokenType==="view"?this.matchTextSeq(["WITH","NO","SCHEMA","BINDING"])&&(x=!0):(o.tokenType==="sink"||o.tokenType==="source")&&N(this.parseProperties());let he=this.matchTextSeq("SHALLOW")||void 0;if(this.matchTexts(this._constructor.CLONE_KEYWORDS)){let ne=this.prev?.text.toLowerCase()==="copy";I=this.expression(fo,{this:this.parseTable({schema:!0}),shallow:he,copy:ne})}}if(this.curr&&!this.matchSet(new Set(["rParen","comma"]),{advance:!1}))return this.parseAsCommand(e);let P=o.text.toUpperCase(),k=this._dialectConstructor.CREATABLE_KIND_MAPPING[P]||P;return this.expression(qt,{this:u,kind:ut(oA,k)??k,replace:t,refresh:s,unique:r,expression:h,exists:l,properties:a,indexes:d,noSchemaBinding:x,begin:f,end:y,clone:I,concurrently:c,clustered:n})}parseCommand(){return this.warnUnsupported(),this.expression(Ws,{comments:this.prevComments,this:this.prev?.text.toUpperCase(),expression:this.parseString()})}parseSequenceProperties(){let e=new Hs({}),t=[],s=this.index;for(;this.curr;)if(this.match("comma"),this.matchTextSeq("INCREMENT"))this.matchTextSeq("BY"),this.matchTextSeq("="),e.setArgKey("increment",this.parseTerm());else if(this.matchTextSeq("MINVALUE"))e.setArgKey("minvalue",this.parseTerm());else if(this.matchTextSeq("MAXVALUE"))e.setArgKey("maxvalue",this.parseTerm());else if(this.match("startWith")||this.matchTextSeq("START"))this.matchTextSeq("="),e.setArgKey("start",this.parseTerm());else if(this.matchTextSeq("CACHE"))e.setArgKey("cache",this.parseNumber()||!0);else if(this.matchTextSeq(["OWNED","BY"]))e.setArgKey("owned",this.matchTextSeq("NONE")?void 0:this.parseColumn());else{let r=this.parseVarFromOptions(this._constructor.CREATE_SEQUENCE,{raiseUnmatched:!1});if(r)t.push(r);else break}return e.setArgKey("options",0<t.length?t:void 0),this.index===s?void 0:e}parsePropertyBefore(){this.match("comma");let e={no:this.matchTextSeq("NO")||!1,dual:this.matchTextSeq("DUAL")||!1,before:this.matchTextSeq("BEFORE")||!1,default:this.matchTextSeq("DEFAULT")||!1,local:this.matchTextSeq("LOCAL")&&"LOCAL"||this.matchTextSeq(["NOT","LOCAL"])&&"NOT LOCAL"||!1,after:this.matchTextSeq("AFTER")||!1,minimum:this.matchTexts(["MIN","MINIMUM"])||!1,maximum:this.matchTexts(["MAX","MAXIMUM"])||!1};if(this.matchTexts(Object.keys(this._constructor.PROPERTY_PARSERS))){let t=this._constructor.PROPERTY_PARSERS[(this.prev?.text??"").toUpperCase()];try{let s=Object.fromEntries(Object.entries(e).filter(([,n])=>n));return t.call(this,s)??void 0}catch(s){if(s instanceof xt)throw s;this.raiseError(`Cannot parse property '${this.prev?.text??""}'`)}}}parseWrappedProperties(){return this.parseWrappedCsv(()=>this.parseProperty())}parseProperty(){if(this.matchTexts(Object.keys(this._constructor.PROPERTY_PARSERS)))return this._constructor.PROPERTY_PARSERS[(this.prev?.text??"").toUpperCase()].call(this)??void 0;if(this.match("default")&&this.matchTexts(Object.keys(this._constructor.PROPERTY_PARSERS)))return this._constructor.PROPERTY_PARSERS[(this.prev?.text??"").toUpperCase()].call(this,{default:!0})??void 0;if(this.matchTextSeq(["COMPOUND","SORTKEY"]))return this.parseSortkey({compound:!0});if(this.matchTextSeq(["SQL","SECURITY"]))return this.expression(fi,{this:this.matchTexts(["DEFINER","INVOKER"])&&(this.prev?.text??"").toUpperCase()});let e=this.index,t=this.parseSequenceProperties();if(t)return t;this.retreat(e);let s=this.parseColumn();if(!this.match("eq")){this.retreat(e);return}s instanceof B&&(s=s.parts&&1<s.parts.length?s.toDot()||Q(s.name):Q(s.name));let r=this.parseBitwise()||this.parseVar({anyToken:!0});return r instanceof B&&(r=Q(r.name)),this.expression(L,{this:s,value:r})}parseStored(){if(this.matchTextSeq("BY"))return this.expression(wn,{this:this.parseVarOrString()});this.match("alias");let e=(this.matchTextSeq("INPUTFORMAT")||void 0)&&this.parseString(),t=(this.matchTextSeq("OUTPUTFORMAT")||void 0)&&this.parseString();return this.expression(ws,{this:e||t?this.expression(rc,{inputFormat:e,outputFormat:t}):this.parseVarOrString()||this.parseNumber()||this.parseIdVar(),hiveFormat:!0})}parseUnquotedField(){let e=this.parseField();return e instanceof U&&!e.args.quoted?Q(e):e}parsePropertyAssignment(e,t){return this.match("eq"),this.match("alias"),this.expression(e,{this:this.parseUnquotedField(),...t})}parseProperties(e){let t=[];for(;;){let s=e?.before?this.parsePropertyBefore():this.parseProperty();if(s===void 0||Array.isArray(s)&&s.length===0)break;let r=Array.isArray(s)?s:[s];for(let n of r)t.push(n)}if(0<t.length)return this.expression(Ke,{expressions:t})}parseFallback(e){return this.expression(xn,{no:e?.no,protection:this.matchTextSeq("PROTECTION")})}parseSecurity(){if(this.matchTexts(["NONE","DEFINER","INVOKER"])){let e=this.prev?.text.toUpperCase();return this.expression(gi,{this:e})}}parseSettingsProperty(){return this.expression(di,{expressions:this.parseCsv(()=>this.parseAssignment())})}parseVolatileProperty(){let e;return 2<=this.index&&(e=this.tokens[this.index-2]),e&&this._constructor.PRE_VOLATILE_TOKENS.has(e.tokenType)?new Ni({}):this.expression(As,{this:R.string("VOLATILE")})}parseRetentionPeriod(){let e=this.parseNumber(),t=e?`${e} `:"",s=this.parseVar({anyToken:!0});return Q(`${t}${s}`)}parseSystemVersioningProperty(e={}){let{with:t=!1}=e;this.match("eq");let s=this.expression(Dn,{on:!0,with:t});if(this.matchTextSeq("OFF"))return s.setArgKey("on",!1),s;if(this.match("on"),this.match("lParen"))for(;this.curr&&!this.match("rParen");)this.matchTextSeq(["HISTORY_TABLE","="])?s.setArgKey("this",this.parseTableParts()):this.matchTextSeq(["DATA_CONSISTENCY_CHECK","="])?(this.advance(),s.setArgKey("dataConsistency",this.prev?.text.toUpperCase())):this.matchTextSeq(["HISTORY_RETENTION_PERIOD","="])&&s.setArgKey("retentionPeriod",this.parseRetentionPeriod()),this.match("comma");return s}parseDataDeletionProperty(){this.match("eq");let e=this.matchTextSeq("ON")||!this.matchTextSeq("OFF"),t=this.expression(An,{on:e});if(this.match("lParen"))for(;this.curr&&!this.match("rParen");)this.matchTextSeq(["FILTER_COLUMN","="])?t.setArgKey("filterColumn",this.parseColumn()):this.matchTextSeq(["RETENTION_PERIOD","="])&&t.setArgKey("retentionPeriod",this.parseRetentionPeriod()),this.match("comma");return t}parseDistributedProperty(){let e="HASH",t;this.matchTextSeq(["BY","HASH"])?t=this.parseWrappedCsv(()=>this.parseIdVar()):this.matchTextSeq(["BY","RANDOM"])&&(e="RANDOM");let s;return this.matchTextSeq("BUCKETS")&&!this.matchTextSeq("AUTO")&&(s=this.parseNumber()),this.expression(Vr,{expressions:t,kind:e,buckets:s,order:this.parseOrder()})}parseCompositeKeyProperty(e){this.matchTextSeq("KEY");let t=this.parseWrappedIdVars();return this.expression(e,{expressions:t})}parseWithProperty(){if(this.matchTextSeq(["(","SYSTEM_VERSIONING"])){let e=this.parseSystemVersioningProperty({with:!0});return this.matchRParen(),e}if(this.match("lParen",{advance:!1}))return this.parseWrappedProperties();if(this.matchTextSeq("JOURNAL"))return this.parseWithjournaltable();if(this.matchTexts(Array.from(this._constructor.VIEW_ATTRIBUTES)))return this.expression(Ri,{this:this.prev?.text.toUpperCase()});if(this.matchTextSeq("DATA"))return this.parseWithdata({no:!1});if(this.matchTextSeq(["NO","DATA"]))return this.parseWithdata({no:!0});if(this.match("serdeProperties",{advance:!1}))return this.parseSerdeProperties({with:!0});if(this.match("schema"))return this.expression(yi,{this:this.parseVarFromOptions(this._constructor.SCHEMA_BINDING_OPTIONS)});if(this.matchTexts(Object.keys(this._constructor.PROCEDURE_OPTIONS),{advance:!1}))return this.expression(Ci,{expressions:this.parseCsv(()=>this.parseProcedureOption())});if(this.next)return this.parseWithIsolatedLoading()}parseProcedureOption(){return this.matchTextSeq(["EXECUTE","AS"])?this.expression(Ms,{this:this.parseVarFromOptions(this._constructor.EXECUTE_AS_OPTIONS,{raiseUnmatched:!1})||this.parseString()}):this.parseVarFromOptions(this._constructor.PROCEDURE_OPTIONS)}parseDefiner(){this.match("eq");let e=this.parseIdVar();this.match("parameter");let t=this.parseIdVar()||this.match("mod")&&this.prev?.text;if(!(!e||!t))return new Gr({this:`${e}@${t}`})}parseWithjournaltable(){return this.match("table"),this.match("eq"),this.expression(Ii,{this:this.parseTableParts()})}parseLog(e={}){let{no:t=!1}=e;return this.expression(ni,{no:t})}parseJournal(e){return this.expression(Sn,e)}parseChecksum(){this.match("eq");let e;return this.match("on")?e=!0:this.matchTextSeq("OFF")&&(e=!1),this.expression(gn,{on:e,default:this.match("default")})}parseCluster(e={}){let{wrapped:t=!1}=e;return this.expression(Nr,{expressions:t?this.parseWrappedCsv(()=>this.parseOrdered()):this.parseCsv(()=>this.parseOrdered())})}parseClusteredBy(){this.matchTextSeq("BY"),this.matchLParen();let e=this.parseCsv(()=>this.parseColumn());this.matchRParen();let t;this.matchTextSeq(["SORTED","BY"])&&(this.matchLParen(),t=this.parseCsv(()=>this.parseOrdered()),this.matchRParen()),this.match("into");let s=this.parseNumber();return this.matchTextSeq("BUCKETS"),this.expression(si,{expressions:e,sortedBy:t,buckets:s})}parseCopyProperty(){if(!this.matchTextSeq("GRANTS")){this.retreat(this.index-1);return}return this.expression($r,{})}parseFreespace(){return this.match("eq"),this.expression(fn,{this:this.parseNumber(),percent:this.match("percent")})}parseMergeBlockRatio(e={}){let{no:t=!1,default:s=!1}=e;return this.match("eq")?this.expression(br,{this:this.parseNumber(),percent:this.match("percent")}):this.expression(br,{no:t,default:s})}parseDataBlocksize(e={}){let{default:t,minimum:s,maximum:r}=e;this.match("eq");let n=this.parseNumber(),a;return this.matchTexts(["BYTES","KBYTES","KILOBYTES"])&&(a=this.prev?.text??""),this.expression(En,{size:n,units:a,default:t,minimum:s,maximum:r})}parseBlockCompression(){this.match("eq");let e=this.matchTextSeq("ALWAYS")||void 0,t=this.matchTextSeq("MANUAL")||void 0,s=this.matchTextSeq("NEVER")||void 0,r=this.matchTextSeq("DEFAULT")||void 0,n;return this.matchTextSeq("AUTOTEMP")&&(n=this.parseSchema()),this.expression(hn,{always:e,manual:t,never:s,default:r,autotemp:n})}parseWithIsolatedLoading(){let e=this.index,t=this.matchTextSeq("NO")||void 0,s=this.matchTextSeq("CONCURRENT")||void 0;if(!this.matchTextSeq(["ISOLATED","LOADING"])){this.retreat(e);return}let r=this.parseVarFromOptions(this._constructor.ISOLATED_LOADING_OPTIONS,{raiseUnmatched:!1});return this.expression(Tn,{no:t,concurrent:s,target:r})}parseLocking(){let e;this.match("table")?e="TABLE":this.match("view")?e="VIEW":this.match("row")?e="ROW":this.matchTextSeq("DATABASE")&&(e="DATABASE");let t;(e==="DATABASE"||e==="TABLE"||e==="VIEW")&&(t=this.parseTableParts());let s;this.match("for")?s="FOR":this.match("in")&&(s="IN");let r;this.matchTextSeq("ACCESS")?r="ACCESS":this.matchTexts(["EXCL","EXCLUSIVE"])?r="EXCLUSIVE":this.matchTextSeq("SHARE")?r="SHARE":this.matchTextSeq("READ")?r="READ":this.matchTextSeq("WRITE")?r="WRITE":this.matchTextSeq("CHECKSUM")&&(r="CHECKSUM");let n=this.matchTextSeq("OVERRIDE")||void 0;return this.expression(Nn,{this:t,kind:e,forOrIn:s,lockType:r,override:n})}parsePartitionBy(){return this.match("partitionBy")?this.parseCsv(()=>this.parseDisjunction()):[]}parsePartitionBoundSpec(){let e=()=>this.matchTextSeq("MINVALUE")?Q("MINVALUE"):this.matchTextSeq("MAXVALUE")?Q("MAXVALUE"):this.parseBitwise(),t,s,r,n;return this.match("in")?t=this.parseWrappedCsv(()=>this.parseBitwise()):this.match("from")?(r=this.parseWrappedCsv(e),this.matchTextSeq("TO"),n=this.parseWrappedCsv(e)):this.matchTextSeq(["WITH","(","MODULUS"])?(t=this.parseNumber(),this.matchTextSeq([",","REMAINDER"]),s=this.parseNumber(),this.matchRParen()):this.raiseError("Failed to parse partition bound spec."),this.expression(Ki,{this:t,expression:s,fromExpressions:r,toExpressions:n})}parsePartitionedOf(){if(!this.matchTextSeq("OF")){this.retreat(this.index-1);return}let e=this.parseTable({schema:!0}),t;return this.match("default")?t=Q("DEFAULT"):this.matchTextSeq(["FOR","VALUES"])?t=this.parsePartitionBoundSpec():(this.raiseError("Expecting either DEFAULT or FOR VALUES clause."),t=Q("DEFAULT")),this.expression(Cn,{this:e,expression:t})}parsePartitionedBy(){return this.match("eq"),this.expression(os,{this:this.parseSchema()||this.parseBracket(this.parseField())})}parseWithdata(e={}){let t;return this.matchTextSeq(["AND","STATISTICS"])?t=!0:this.matchTextSeq(["AND","NO","STATISTICS"])&&(t=!1),this.expression(Mn,{no:e?.no,statistics:t})}parseContainsProperty(){if(this.matchTextSeq("SQL"))return this.expression(Es,{this:"CONTAINS SQL"})}parseModifiesProperty(){if(this.matchTextSeq(["SQL","DATA"]))return this.expression(Es,{this:"MODIFIES SQL DATA"})}parseNoProperty(){if(this.matchTextSeq(["PRIMARY","INDEX"]))return new oi({});if(this.matchTextSeq("SQL"))return this.expression(Es,{this:"NO SQL"})}parseOnProperty(){return this.matchTextSeq(["COMMIT","PRESERVE","ROWS"])?new Qs({}):this.matchTextSeq(["COMMIT","DELETE","ROWS"])?new Qs({delete:!0}):this.expression(zs,{this:this.parseSchema({this:this.parseIdVar()})})}parseReadsProperty(){if(this.matchTextSeq(["SQL","DATA"]))return this.expression(Es,{this:"READS SQL DATA"})}parseDistkey(){return this.expression(Yr,{this:this.parseWrapped(()=>this.parseIdVar())})}parseCreateLike(){let e=this.parseTable({schema:!0}),t=[];for(;this.matchTexts(["INCLUDING","EXCLUDING"]);){let s=(this.prev?.text??"").toUpperCase(),r=this.parseIdVar();if(!r)return;let n=r.args.this;t.push(this.expression(L,{this:s,value:Q(typeof n=="string"?n.toUpperCase():"")}))}return this.expression(Rn,{this:e,expressions:t})}parseSortkey(e={}){let t=this.parseWrappedIdVars(),s=t.length===1?t[0]:this.expression(Ge,{expressions:t});return this.expression(xi,{this:s,compound:e?.compound})}parseCharacterSet(e={}){return this.match("eq"),this.expression(ir,{this:this.parseVarOrString(),default:e?.default})}parseRemoteWithConnection(){return this.matchTextSeq(["WITH","CONNECTION"]),this.expression(pi,{this:this.parseTableParts()})}parseReturns(){let e,t,s=this.match("table")||void 0;return s?this.match("lt")?(e=this.expression(At,{this:"TABLE",expressions:this.parseCsv(()=>this.parseStructTypes())}),this.match("gt")||this.raiseError("Expecting >")):e=this.parseSchema({this:Q("TABLE")}):this.matchTextSeq(["NULL","ON","NULL","INPUT"])?(t=!0,e=void 0):e=this.parseTypes(),this.expression(or,{this:e,isTable:s,null:t})}parseDescribe(){let e=(this.matchSet(this._constructor.CREATABLES)||void 0)&&this.prev?.text,t=(this.matchTexts(Array.from(this._constructor.DESCRIBE_STYLES))||void 0)&&this.prev?.text.toUpperCase();this.match("dot")&&(t=void 0,this.retreat(this.index-2));let s=this.match("format",{advance:!1})?this.parseProperty():void 0,r;this.matchSet(new Set(Object.keys(this._constructor.STATEMENT_PARSERS)),{advance:!1})?r=this.parseStatement():r=this.parseTable({schema:!0});let a=this.parseProperties()?.args.expressions,o=this.parsePartition();return this.expression(Vi,{this:r,style:t,kind:e,expressions:a,partition:o,format:s,asJson:this.matchTextSeq(["AS","JSON"])})}parseMultitableInserts(e){let t=(this.prev?.text??"").toUpperCase(),s=[],r=()=>{let a;this.match("when")&&(a=this.parseDisjunction(),this.match("then"));let o=this.match("else")||void 0;if(this.match("into"))return this.expression(Bo,{this:this.expression(kt,{this:this.parseTable({schema:!0}),expression:this.parseDerivedTableValues()}),expression:a,else:o})},n=r();for(;n!==void 0;)s.push(n),n=r();return this.expression(Zi,{kind:t,comments:e,expressions:s,source:this.parseTable()})}parseInsert(){let e=[],t=this.parseHint(),s=this.match("overwrite")||void 0,r=this.match("ignore")||void 0,n=this.matchTextSeq("LOCAL")||void 0,a,o,c;if(this.matchTextSeq("DIRECTORY"))c=this.expression(Xi,{this:this.parseVarOrString(),local:n,rowFormat:this.parseRowFormat({matchRow:!0})});else{if(this.matchSet(new Set(["first","all"])))return e.push(...J(this.prevComments)),this.parseMultitableInserts(e);this.match("or")&&(a=this.matchTexts(Array.from(this._constructor.INSERT_ALTERNATIVES))&&this.prev?.text||void 0),this.match("into"),e.push(...J(this.prevComments)),this.match("table"),o=this.match("function")||void 0,c=o?this.parseFunction():this.parseInsertTable()}let l=this.parseReturning();return this.expression(kt,{comments:e,hint:t,isFunction:o,this:c,stored:this.matchTextSeq("STORED")&&this.parseStored(),byName:this.matchTextSeq(["BY","NAME"]),exists:this.parseExists(),where:this.matchPair("replace","where")&&this.parseDisjunction(),partition:this.match("partitionBy")&&this.parsePartitionedBy(),settings:this.matchTextSeq("SETTINGS")&&this.parseSettingsProperty(),default:this.matchTextSeq(["DEFAULT","VALUES"]),expression:this.parseDerivedTableValues()||this.parseDdlSelect(),conflict:this.parseOnConflict(),returning:l||this.parseReturning(),overwrite:s,alternative:a,ignore:r,source:this.match("table")&&this.parseTable()})}parseInsertTable(){let e=this.parseTable({schema:!0,parsePartition:!0});return e instanceof V&&this.match("alias",{advance:!1})&&e.setArgKey("alias",this.parseTableAlias()),e}parseKill(){let e=this.matchTexts(["CONNECTION","QUERY"])?Q(this.prev?.text??""):void 0;return this.expression(So,{this:this.parsePrimary(),kind:e})}parseOnConflict(){let e=this.matchTextSeq(["ON","CONFLICT"])||void 0,t=this.matchTextSeq(["ON","DUPLICATE","KEY"])||void 0;if(!e&&!t)return;let s,r;e&&(this.matchTextSeq(["ON","CONSTRAINT"])?r=this.parseIdVar():this.match("lParen")&&(s=this.parseCsv(()=>this.parseIdVar()),this.matchRParen()));let n=this.parseWhere(),a=this.parseVarFromOptions(this._constructor.CONFLICT_ACTIONS),o;return this.prev?.tokenType==="update"&&(this.match("set"),o=this.parseCsv(()=>this.parseEquality())),this.expression($o,{duplicate:t,expressions:o,action:a,conflictKeys:s,indexPredicate:n,constraint:r,where:this.parseWhere()})}parseReturning(){if(this.match("returning"))return this.expression(Ea,{expressions:this.parseCsv(()=>this.parseExpression()),into:this.match("into")&&this.parseTablePart()})}parseRow(){if(this.match("format"))return this.parseRowFormat()}parseSerdeProperties(e={}){let t=this.index,s=e?.with||this.matchTextSeq("WITH");if(!this.match("serdeProperties")){this.retreat(t);return}return this.expression(Ln,{expressions:this.parseWrappedProperties(),with:s})}parseRowFormat(e={}){if(e?.matchRow&&!this.matchPair("row","format"))return;if(this.matchTextSeq("SERDE")){let s=this.parseString(),r=this.parseSerdeProperties();return this.expression(bn,{this:s,serdeProperties:r})}this.matchTextSeq("DELIMITED");let t={};return this.matchTextSeq(["FIELDS","TERMINATED","BY"])&&(t.fields=this.parseString(),this.matchTextSeq(["ESCAPED","BY"])&&(t.escaped=this.parseString())),this.matchTextSeq(["COLLECTION","ITEMS","TERMINATED","BY"])&&(t.collectionItems=this.parseString()),this.matchTextSeq(["MAP","KEYS","TERMINATED","BY"])&&(t.mapKeys=this.parseString()),this.matchTextSeq(["LINES","TERMINATED","BY"])&&(t.lines=this.parseString()),this.matchTextSeq(["NULL","DEFINED","AS"])&&(t.null=this.parseString()),this.expression(Pn,t)}parseSelect(e={}){let{nested:t=!1,table:s=!1,parseSubqueryAlias:r=!0,parseSetOperation:n=!0,consumePipe:a=!0,from:o}=e,c=this.parseSelectQuery({nested:t,table:s,parseSubqueryAlias:r,parseSetOperation:n});return a&&this.match("pipeGt",{advance:!1})&&(!c&&o&&(c=pt("*").from(o)),c instanceof z&&(c=this.parsePipeSyntaxQuery(c),c=c&&s?c.subquery(void 0,{copy:!1}):c)),c}parseSelectQuery(e={}){let{nested:t=!1,table:s=!1,parseSubqueryAlias:r=!0,parseSetOperation:n=!0}=e,a=this.parseWith(),o;if(a){if(o=this.parseStatement(),!o)return this.raiseError("Failed to parse any statement following CTE"),a;for(;o instanceof Te&&o.isWrapper;)o=o.args.this;return o?._constructor.availableArgs.has("with")?o.setArgKey("with",a):(this.raiseError(`${o?._constructor.key||"Unknown expression"} does not support CTE`),o=a),o}let c;if(this.match("from",{advance:!1})&&(c=this.parseFrom({joins:!0,consumePipe:!0})),this.match("select")){let l=this.prevComments,u=this.parseHint(),h,d;this.next&&this.next.tokenType!=="dot"&&(h=this.match("all")||void 0,d=this.matchSet(this._constructor.DISTINCT_TOKENS)?new We:void 0);let x=this.match("alias")&&this.matchTexts(["STRUCT","VALUE"])&&this.prev?.text.toUpperCase()||void 0;d&&(d=this.expression(We,{on:this.match("on")?this.parseValue({values:!1}):void 0})),h&&d&&this.raiseError("Cannot specify both ALL and DISTINCT after SELECT");let f=[];for(;this.curr&&this.matchTexts(Array.from(this._constructor.OPERATION_MODIFIERS));)f.push(Q((this.prev?.text??"").toUpperCase()));let y=this.parseLimit(void 0,{top:!0}),I=this.parseProjections();o=this.expression(ee,{kind:x,hint:u,distinct:d,expressions:I,limit:y,operationModifiers:0<f.length?f:void 0}),o.comments=l;let N=this.parseInto();N&&o.setArgKey("into",N),c||(c=this.parseFrom()),c&&o.setArgKey("from",c),o=this.parseQueryModifiers(o)}else{if((s||t)&&this.match("lParen"))return o=this.parseWrappedSelect({table:s}),this.matchRParen(),this.parseSubquery(o,{parseAlias:r});if(this.match("values",{advance:!1}))o=this.parseDerivedTableValues();else if(c)o=pt("*").from(c.args.this,{copy:!1});else if(this.match("summarize")){let l=this.match("table")||void 0;return o=this.parseSelect()||this.parseString()||this.parseTable(),this.expression(To,{this:o,table:l})}else{if(this.match("describe"))return this.parseDescribe();o=void 0}}return n?this.parseSetOperations(o):o}parseRecursiveWithSearch(){this.matchTextSeq("SEARCH");let e=(this.matchTexts(Array.from(this._constructor.RECURSIVE_CTE_SEARCH_KIND))||void 0)&&this.prev?.text.toUpperCase();if(e)return this.matchTextSeq(["FIRST","BY"]),this.expression(Io,{kind:e,this:this.parseIdVar(),expression:this.matchTextSeq("SET")&&this.parseIdVar(),using:this.matchTextSeq("USING")&&this.parseIdVar()})}parseWith(e={}){let{skipWithToken:t=!1}=e;if(!t&&!this.match("with"))return;let s=this.prevComments,r=this.match("recursive")||void 0,n,a=[];for(;;){let o=this.parseCte();if(o instanceof Tt&&(a.push(o),n&&o.addComments(n)),!this.match("comma")&&!this.match("with"))break;this.match("with"),n=this.prevComments}return this.expression(tt,{comments:s,expressions:a,recursive:r,search:this.parseRecursiveWithSearch()})}parseCte(){let e=this.index,t=this.parseTableAlias({aliasTokens:this._constructor.ID_VAR_TOKENS});(!t||!t.args.this)&&this.raiseError("Expected CTE to have alias");let s=this.matchTextSeq(["USING","KEY"])?this.parseWrappedIdVars():void 0;if(!this.match("alias")&&!this._constructor.OPTIONAL_ALIAS_TOKEN_CTE){this.retreat(e);return}let r=this.prevComments,n;this.matchTextSeq(["NOT","MATERIALIZED"])?n=!1:this.matchTextSeq("MATERIALIZED")&&(n=!0);let a=this.expression(Tt,{this:this.parseWrapped(()=>this.parseStatement()),alias:t,materialized:n,keyExpressions:s,comments:r}),o=a.args.this;return o instanceof Ls&&(o.alias?a.setArgKey("this",pt("*").from(o)):a.setArgKey("this",pt("*").from(Ye(o,"_values",{table:!0})))),a}parseTableAlias(e={}){let{aliasTokens:t}=e;if(this.canParseLimitOrOffset())return;let s=this.match("alias"),r=this.parseIdVar({anyToken:s,tokens:t||this._constructor.TABLE_ALIAS_TOKENS})||this.parseStringAsIdentifier(),n=this.index,a;if(this.match("lParen")?(a=this.parseCsv(()=>this.parseFunctionParameter()),!a||a.length===0?this.retreat(n):this.matchRParen()):a=void 0,!r&&(!a||a.length===0))return;let o=this.expression(ie,{this:r,columns:a});return r instanceof U&&o.addComments(r.popComments()),o}parseSubquery(e,t={}){let{parseAlias:s=!0}=t;if(e)return this.expression(Te,{this:e,pivots:this.parsePivots(),alias:s?this.parseTableAlias():void 0,sample:this.parseTableSample()})}implicitUnnestsToExplicit(e){let t=new Set,s=e.args;if("from"in s){let n=s.from?.args.this;if(n){let a=Ff(n.copy(),{dialect:this.dialect});t.add(a.aliasOrName||"")}}if("joins"in s){let r=s.joins?Rt(s.joins,oe):void 0;if(r)for(let n of r){let a=n.args.this;if(a instanceof V&&!n.args.on){let o=a.copy();o.meta.maybeColumn=!0;let c=Ff(o,{dialect:this.dialect}),l=c.parts;if(l&&0<l.length&&t.has(l[0].name||"")){let u=a.toColumn();if(u){let h=new ge({expressions:[u]});if(a.args.alias instanceof ie&&u.args.this instanceof A){u.replace(u.args.this);let d=a.args.alias?.args.this,x={table:d?typeof d=="string"?[d]:(te(d,U),[d]):void 0,copy:!1};Ye(h,void 0,x)}a.replace(h)}}t.add(c.aliasOrName||"")}}}return e}parseQueryModifiers(e){if(e&&this._constructor.MODIFIABLES.some(t=>e instanceof t)){for(let s of this.parseJoins())e.append("joins",s);let t=this.parseLateral();for(;t;)e.append("laterals",t),t=this.parseLateral();for(;;){if(this.matchSet(new Set(Object.keys(this._constructor.QUERY_MODIFIER_PARSERS)),{advance:!1})){let s=this.curr,r=this._constructor.QUERY_MODIFIER_PARSERS[s.tokenType],[n,a]=r?.call(this)||[];if(n!==void 0&&a!==void 0){if(e.getArgKey(n)&&this.raiseError(`Found multiple '${s.text.toUpperCase()}' clauses`,s),e.setArgKey(n,a),n==="limit"){let o=a,c=o.args.offset;if(o.setArgKey("offset",void 0),c){let l=new Rr({expression:c});e.setArgKey("offset",l);let u=a.args.expressions;o.setArgKey("expressions",void 0),l.setArgKey("expressions",u)}}continue}}break}}return this._constructor.SUPPORTS_IMPLICIT_UNNEST&&e&&e.args.from&&(e=this.implicitUnnestsToExplicit(e)),e}parseHintFallbackToString(){let e=this.curr;for(;this.curr;)this.advance();let t=this.tokens[this.index-1];return new us({expressions:[this.findSql(e,t)]})}parseHintFunctionCall(){return this.parseFunctionCall()}parseHintBody(){let e=this.index,t=!1,s=[];try{let r=this.parseCsv(()=>this.parseHintFunctionCall()||this.parseVar({upper:!0}));for(;0<r.length;)s.push(...r),r=this.parseCsv(()=>this.parseHintFunctionCall()||this.parseVar({upper:!0}))}catch{t=!0}return t||this.curr?(this.retreat(e),this.parseHintFallbackToString()):this.expression(us,{expressions:s})}parseHint(){if(this.match("hint")&&this.prevComments&&0<this.prevComments.length)return H(this.prevComments[0],{into:"hint",dialect:this.dialect})}parseInto(){if(!this.match("into"))return;let e=this.match("temporary")||void 0,t=this.matchTextSeq("UNLOGGED")||void 0;return this.match("table"),this.expression(Qi,{this:this.parseTable({schema:!0}),temporary:e,unlogged:t})}parseFrom(e={}){let{joins:t=!1,skipFromToken:s=!1,consumePipe:r=!1}=e;if(!(!s&&!this.match("from")))return this.expression(Je,{comments:this.prevComments,this:this.parseTable({joins:t,consumePipe:r})})}parseMatchRecognizeMeasure(){return this.expression(Zo,{windowFrame:this.matchTexts(["FINAL","RUNNING"])&&(this.prev?.text??"").toUpperCase(),this:this.parseExpression()})}parseMatchRecognize(){if(!this.match("matchRecognize"))return;this.matchLParen();let e=this.parsePartitionBy(),t=this.parseOrder(),s=this.matchTextSeq("MEASURES")?this.parseCsv(()=>this.parseMatchRecognizeMeasure()):void 0,r;if(this.matchTextSeq(["ONE","ROW","PER","MATCH"]))r=Q("ONE ROW PER MATCH");else if(this.matchTextSeq(["ALL","ROWS","PER","MATCH"])){let c="ALL ROWS PER MATCH";this.matchTextSeq(["SHOW","EMPTY","MATCHES"])?c+=" SHOW EMPTY MATCHES":this.matchTextSeq(["OMIT","EMPTY","MATCHES"])?c+=" OMIT EMPTY MATCHES":this.matchTextSeq(["WITH","UNMATCHED","ROWS"])&&(c+=" WITH UNMATCHED ROWS"),r=Q(c)}let n;if(this.matchTextSeq(["AFTER","MATCH","SKIP"])){let c="AFTER MATCH SKIP";this.matchTextSeq(["PAST","LAST","ROW"])?c+=" PAST LAST ROW":this.matchTextSeq(["TO","NEXT","ROW"])?c+=" TO NEXT ROW":this.matchTextSeq(["TO","FIRST"])?(this.advance(),c+=` TO FIRST ${this.prev?.text}`):this.matchTextSeq(["TO","LAST"])&&(this.advance(),c+=` TO LAST ${this.prev?.text}`),n=Q(c)}let a;if(this.matchTextSeq("PATTERN")){this.matchLParen(),this.curr||this.raiseError("Expecting )",this.curr);let c=1,l=this.curr,u=this.prev;for(;this.curr&&0<c;)this.curr.tokenType==="lParen"&&c++,this.curr.tokenType==="rParen"&&c--,u=this.prev,this.advance();0<c&&this.raiseError("Expecting )",this.curr),a=Q(this.findSql(l,u))}let o=this.matchTextSeq("DEFINE")?this.parseCsv(()=>this.parseNameAsExpression()):void 0;return this.matchRParen(),this.expression(Ko,{partitionBy:e,order:t,measures:s,rows:r,after:n,pattern:a,define:o,alias:this.parseTableAlias()})}parseLateral(){let e=this.matchPair("cross","apply")||void 0;!e&&this.matchPair("outer","apply")&&(e=!1);let t,s,r;if(e!==void 0)t=this.parseSelect({table:!0}),s=void 0,r=void 0;else if(this.match("lateral"))t=this.parseSelect({table:!0}),s=this.match("view")||void 0,r=this.match("outer")||void 0;else return;if(!t)for(t=this.parseUnnest()||this.parseFunction()||this.parseIdVar({anyToken:!1});this.match("dot");){let o=this.parseFunction()||this.parseIdVar({anyToken:!1});t=new Se({this:t,expression:o})}let n,a;if(s){let o=this.parseIdVar({anyToken:!1}),c=this.match("alias")?this.parseCsv(()=>this.parseIdVar()):[];a=this.expression(ie,{this:o,columns:c})}else(t instanceof Te||t instanceof ge)&&t.alias?a=t.args.alias?.pop():(n=this.matchPair("with","ordinality")||void 0,a=this.parseTableAlias());return this.expression(St,{this:t,view:s,outer:r,alias:a,crossApply:e,ordinality:n})}parseStream(){let e=this.index;if(this.matchTextSeq("STREAM")){let t=this.tryParse(this.parseTable.bind(this));if(t)return this.expression(on,{this:t})}this.retreat(e)}parseJoinParts(){return{method:this.matchSet(this._constructor.JOIN_METHODS)?this.prev:void 0,side:this.matchSet(this._constructor.JOIN_SIDES)?this.prev:void 0,kind:this.matchSet(this._constructor.JOIN_KINDS)?this.prev:void 0}}parseUsingIdentifiers(){let e=()=>{let t=this.parseColumn();return t instanceof B?t.args.this instanceof A?t.args.this:Z(t.args.this):t};return this.parseWrappedCsv(e,{optional:!0})}parseJoin(e={}){let{skipJoinToken:t=!1,parseBracket:s=!1}=e;if(this.match("comma")){let I=this.tryParse(this.parseTable.bind(this)),N=I?this.expression(oe,{this:I}):void 0;return N&&this._constructor.JOINS_HAVE_EQUAL_PRECEDENCE&&N.setArgKey("kind","cross"),N}let r=this.index,{method:n,side:a,kind:o}=this.parseJoinParts(),c=this.matchTextSeq("DIRECTED")||void 0,l=(this.matchTexts(this._constructor.JOIN_HINTS)||void 0)&&this.prev?.text,u=this.match("join")||o?.tokenType==="straightJoin",h=this.prevComments;!t&&!u&&(this.retreat(r),o=void 0,n=void 0,a=void 0);let d=this.matchPair("outer","apply",{advance:!1})||void 0,x=this.matchPair("cross","apply",{advance:!1})||void 0;if(!t&&!u&&!d&&!x)return;let f={this:d||x?this.parseLateral():this.parseTable({parseBracket:s})};if(o?.tokenType==="array"&&this.match("comma")&&(f.expressions=this.parseCsv(()=>this.parseTable({parseBracket:s}))),n&&(f.method=n.text.toUpperCase()),a&&(f.side=ut(Qt,a.text)),o&&(f.kind=o.tokenType==="straightJoin"?"straightJoin":ut(Qt,o.text)),l&&(f.hint=l),this.match("matchCondition")&&(f.matchCondition=this.parseWrapped(()=>this.parseComparison())),this.match("on"))f.on=this.parseDisjunction();else if(this.match("using"))f.using=this.parseUsingIdentifiers();else if(!n&&!(d||x)&&!(f.this instanceof ge)&&!(o?.tokenType==="cross"||o?.tokenType==="array")){let I=this.index,N=[...this.parseJoins()];0<N.length&&this.match("on")?f.on=this.parseDisjunction():0<N.length&&this.match("using")?f.using=this.parseUsingIdentifiers():this.retreat(I),0<N.length&&(f.on||f.using)&&f.this?.setArgKey("joins",N)}f.pivots=this.parsePivots();let y=[...h||[],...[n,a,o].flatMap(I=>I?.comments||[])];return this._constructor.ADD_JOIN_ON_TRUE&&!f.on&&!f.using&&!f.method&&(!f.kind||f.kind==="inner"||f.kind==="outer")&&(f.on=new ot({this:!0})),c&&(f.directed=c),this.expression(oe,{comments:y,...f})}parseOpClass(){let e=this.parseDisjunction();return this.matchTexts(Array.from(this._constructor.OPCLASS_FOLLOW_KEYWORDS),{advance:!1})||this.matchSet(this._constructor.OPTYPE_FOLLOW_TOKENS,{advance:!1})?e:this.expression(Uo,{this:e,expression:this.parseTableParts()})}parseIndexParams(){let e=this.match("using")?this.parseVar({anyToken:!0}):void 0,t=this.match("lParen",{advance:!1})?this.parseWrappedCsv(()=>this.parseWithOperator()):void 0,s=this.matchTextSeq("INCLUDE")?this.parseWrappedIdVars():void 0,r=this.parsePartitionBy(),n=(this.match("with")||void 0)&&this.parseWrappedProperties(),a=this.matchTextSeq(["USING","INDEX","TABLESPACE"])?this.parseVar({anyToken:!0}):void 0,o=this.parseWhere(),c=this.match("on")?this.parseField():void 0;return this.expression(Fo,{using:e,columns:t,include:s,partitionBy:r,where:o,withStorage:n,tablespace:a,on:c})}parseIndex(e={}){let{anonymous:t=!1,index:s}=e,r=s,n,a,o,c;if(r||t)n=void 0,a=void 0,o=void 0,this.match("on"),this.match("table"),c=this.parseTableParts({schema:!0});else{if(n=this.match("unique")||void 0,a=this.matchTextSeq("PRIMARY")||void 0,o=this.matchTextSeq("AMP")||void 0,!this.match("index"))return;r=this.parseIdVar(),c=void 0}let l=this.parseIndexParams();return this.expression(vo,{this:r,table:c,unique:n,primary:a,amp:o,params:l})}parseTableHints(){let e=[];if(this.matchPair("with","lParen"))e.push(this.expression(tn,{expressions:this.parseCsv(()=>this.parseFunction()||this.parseVar({anyToken:!0}))})),this.matchRParen();else for(;this.matchSet(this._constructor.TABLE_INDEX_HINT_TOKENS);){let t=new nc({this:(this.prev?.text??"").toUpperCase()});this.matchSet(new Set(["index","key"])),this.match("for")&&(this.advanceAny(),t.setArgKey("target",(this.prev?.text??"").toUpperCase())),t.setArgKey("expressions",this.parseWrappedIdVars()),e.push(t)}return 0<e.length?e:void 0}parseTablePart(e={}){let{schema:t=!1}=e;return!t&&this.parseFunction({optionalParens:!1})||this.parseIdVar({anyToken:!1})||this.parseStringAsIdentifier()||this.parsePlaceholder()}parseTableParts(e={}){let{schema:t=!1,isDbReference:s=!1,wildcard:r=!1}=e,n,a,o=this.parseTablePart({schema:t});for(;this.match("dot");)n?o=this.expression(Se,{this:o,expression:this.parseTablePart({schema:t})}):(n=a,a=o,o=this.parseTablePart({schema:t})||"");r&&this.isConnected()&&(o instanceof U||!o)&&this.match("star")&&(o instanceof U?o.args.this+="*":o=new U({this:"*"}));let c=o instanceof A?o.popComments():void 0;s&&(n=a,a=o,o=void 0),!o&&!s&&this.raiseError(`Expected table name but got ${this.curr}`,this.curr),!a&&s&&this.raiseError(`Expected database name but got ${this.curr}`,this.curr);let l=this.expression(V,{comments:c,this:o,db:a,catalog:n}),u=this.parseChanges();u&&l.setArgKey("changes",u);let h=this.parseHistoricalData();h&&l.setArgKey("when",h);let d=this.parsePivots();return d&&l.setArgKey("pivots",d),l}parseTable(e={}){let{schema:t=!1,joins:s=!1,aliasTokens:r,parseBracket:n=!1,isDbReference:a=!1,parsePartition:o=!1,consumePipe:c=!1}=e,l=this.parseStream();if(l)return l;let u=this.parseLateral();if(u)return u;let h=this.parseUnnest();if(h)return h;let d=this.parseDerivedTableValues();if(d)return d;let x=this.parseSelect({table:!0,consumePipe:c});if(x)return x.args.pivots||x.setArgKey("pivots",this.parsePivots()),x;let f=n&&this.parseBracket(void 0);f=f?this.expression(V,{this:f}):void 0;let y=(this.matchTextSeq(["ROWS","FROM"])||void 0)&&this.parseWrappedCsv(()=>this.parseTable());y=y?this.expression(V,{rowsFrom:y}):void 0;let I=this.match("only")||void 0,N=f||y||this.parseBracket(this.parseTableParts({schema:t,isDbReference:a}));if(I&&N?.setArgKey("only",I),this.matchTextSeq("*"),(o||this._constructor.SUPPORTS_PARTITION_SELECTION)&&this.match("partition",{advance:!1})&&N?.setArgKey("partition",this.parsePartition()),t)return this.parseSchema({this:N});let k=this.parseVersion();k&&N?.setArgKey("version",k),this._dialectConstructor.ALIAS_POST_TABLESAMPLE&&N?.setArgKey("sample",this.parseTableSample());let _=this.parseTableAlias({aliasTokens:r||this._constructor.TABLE_ALIAS_TOKENS});if(_&&N?.setArgKey("alias",_),this.match("indexedBy")?N?.setArgKey("indexed",this.parseTableParts()):this.matchTextSeq(["NOT","INDEXED"])&&N?.setArgKey("indexed",!1),N instanceof V&&this.matchTextSeq("AT"))return this.expression(Nc,{this:N.toColumn?.({copy:!1}),expression:this.parseIdVar()});if(N?.setArgKey("hints",this.parseTableHints()),N?.args.pivots||N?.setArgKey("pivots",this.parsePivots()),this._dialectConstructor.ALIAS_POST_TABLESAMPLE||N?.setArgKey("sample",this.parseTableSample()),s)for(let W of this.parseJoins())N?.append("joins",W);return this.matchPair("with","ordinality")&&(N?.setArgKey("ordinality",!0),N?.setArgKey("alias",this.parseTableAlias())),N}parseVersion(){let e;if(this.match("timestampSnapshot"))e="TIMESTAMP";else if(this.match("versionSnapshot"))e="VERSION";else return;let t,s;if(this.matchSet(new Set(["from","between"]))){t=(this.prev?.text??"").toUpperCase();let r=this.parseBitwise();this.matchTexts(["TO","AND"]);let n=this.parseBitwise();s=this.expression(Ge,{expressions:[r,n]})}else this.matchTextSeq(["CONTAINED","IN"])?(t="CONTAINED IN",s=this.expression(Ge,{expressions:this.parseWrappedCsv(()=>this.parseBitwise())})):this.match("all")?(t="ALL",s=void 0):(this.matchTextSeq(["AS","OF"]),t="AS OF",s=this.parseType());return this.expression(oc,{this:e,expression:s,kind:t})}parseHistoricalData(){let e=this.index,t;if(this.matchTexts(Array.from(this._constructor.HISTORICAL_DATA_PREFIX))){let s=(this.prev?.text??"").toUpperCase(),r=this.match("lParen")&&this.matchTexts(Array.from(this._constructor.HISTORICAL_DATA_KIND))&&(this.prev?.text??"").toUpperCase(),n=(this.match("farrow")||void 0)&&this.parseBitwise();n?(this.matchRParen(),t=this.expression(ac,{this:s,kind:r,expression:n})):this.retreat(e)}return t}parseChanges(){if(!this.matchTextSeq(["CHANGES","(","INFORMATION","=>"]))return;let e=this.parseVar({anyToken:!0});return this.matchRParen(),this.expression(wo,{information:e,atBefore:this.parseHistoricalData(),end:this.parseHistoricalData()})}parseUnnest(e={}){let{withAlias:t=!0}=e;if(!this.matchPair("unnest","lParen",{advance:!1}))return;this.advance();let s=this.parseWrappedCsv(()=>this.parseEquality()),r=this.matchPair("with","ordinality")||void 0,n=t?this.parseTableAlias():void 0;if(n){this._dialectConstructor.UNNEST_COLUMN_ONLY&&(n.args.columns&&this.raiseError("Unexpected extra column alias in unnest."),n.setArgKey("columns",[n.args.this]),n.setArgKey("this",void 0));let a=n.args.columns;r&&a&&s.length<a.length&&(r=a.pop())}return!r&&this.matchPair("with","offset")&&(this.match("alias"),r=this.parseIdVar({anyToken:!1,tokens:this._constructor.UNNEST_OFFSET_ALIAS_TOKENS})||Z("offset")),this.expression(ge,{expressions:s,alias:n,offset:r})}parseDerivedTableValues(){let e=this.matchPair("lParen","values")||void 0;if(!e&&!(this.matchTextSeq("VALUES")||this.matchTextSeq(["FORMAT","VALUES"])))return;let t=this.parseCsv(()=>this.parseValue()),s=this.parseTableAlias();return e&&this.matchRParen(),this.expression(Ls,{expressions:t,alias:s||this.parseTableAlias()})}parseTableSample(e={}){let{asModifier:t=!1}=e;if(!this.match("tableSample")&&!(t&&this.matchTextSeq(["USING","SAMPLE"])))return;let s,r,n,a,o,c,l=this.parseVar({tokens:new Set(["row"]),upper:!0}),u=this.match("lParen")||void 0,h,d;return this._constructor.TABLESAMPLE_CSV?(d=void 0,h=this.parseCsv(()=>this.parsePrimary())):(h=void 0,d=this.match("number",{advance:!1})?this.parseFactor():this.parsePrimary()||this.parsePlaceholder()),this.matchTextSeq("BUCKET")?(s=this.parseNumber(),this.matchTextSeq(["OUT","OF"]),r=this.parseNumber(),this.match("on"),n=this.parseField()):this.matchSet(new Set(["percent","mod"]))?a=d:this.match("rows")||!this._dialectConstructor.TABLESAMPLE_SIZE_IS_PERCENT?o=d:a=d,u&&this.matchRParen(),this.match("lParen")?(l=this.parseVar({upper:!0}),c=(this.match("comma")||void 0)&&this.parseNumber(),this.matchRParen()):this.matchTexts(["SEED","REPEATABLE"])&&(c=this.parseWrapped(()=>this.parseNumber())),!l&&this._constructor.DEFAULT_SAMPLING_METHOD&&(l=Q(this._constructor.DEFAULT_SAMPLING_METHOD)),this.expression(cc,{expressions:h,method:l,bucketNumerator:s,bucketDenominator:r,bucketField:n,percent:a,size:o,seed:c})}parsePivots(){let e=[],t=this.parsePivot();for(;t;)e.push(t),t=this.parsePivot();return 0<e.length?e:void 0}parseJoins(){let e=[],t=this.parseJoin();for(;t;)e.push(t),t=this.parseJoin();return e}parseUnpivotColumns(){if(this.match("into"))return this.expression(pc,{this:this.matchTextSeq("NAME")&&this.parseColumn(),expressions:this.matchTextSeq("VALUE")&&this.parseCsv(()=>this.parseColumn())})}parseSimplifiedPivot(e={}){let{isUnpivot:t}=e,s=()=>{let l=this.parseBitwise();return this.match("in")?this.parseIn(l):this.match("alias",{advance:!1})?this.parseAlias(l):l},r=this.parseTable(),n=(this.match("on")||void 0)&&this.parseCsv(s),a=this.parseUnpivotColumns(),o=(this.match("using")||void 0)&&this.parseCsv(()=>this.parseAlias(this.parseColumn())),c=this.parseGroup();return this.expression(yr,{this:r,expressions:n,using:o,group:c,unpivot:t,into:a})}parsePivotIn(){let e=()=>{let n=this.parseSelectOrExpression();this.match("alias");let a=this.parseBitwise();if(a){let o=a;return a instanceof B&&!a.args.db&&(te(a.args.this,A),o=a.args.this),this.expression(MA,{this:n,alias:o})}return n},t=this.parseColumn();this.match("in")||this.raiseError("Expecting IN",this.curr);let s;if(this.match("lParen"))return this.match("any")?s=[...J(new Cr({this:this.parseOrder()}))]:s=this.parseCsv(e),this.matchRParen(),this.expression(it,{this:t,expressions:s});let r=this.parseIdVar();return this.expression(it,{this:t,field:r})}parsePivotAggregation(){let e=this.parseFunction();if(!e){if(this.prev&&this.prev.tokenType==="comma")return;this.raiseError("Expecting an aggregation function in PIVOT",this.curr)}return this.parseAlias(e)}parsePivot(){let e=this.index,t,s;if(this.match("pivot"))s=!1;else if(this.match("unpivot"))s=!0,this.matchTextSeq(["INCLUDE","NULLS"])?t=!0:this.matchTextSeq(["EXCLUDE","NULLS"])&&(t=!1);else return;if(!this.match("lParen")){this.retreat(e);return}let r;s?r=this.parseCsv(()=>this.parseColumn()):r=this.parseCsv(()=>this.parsePivotAggregation()),r.length===0&&this.raiseError("Failed to parse PIVOT's aggregation list",this.curr),this.match("for")||this.raiseError("Expecting FOR",this.curr);let n=[];for(;;){let l=this.tryParse(()=>this.parsePivotIn());if(!l)break;n.push(l)}let a=(this.matchTextSeq(["DEFAULT","ON","NULL"])||void 0)&&this.parseWrapped(()=>this.parseBitwise()),o=this.parseGroup();this.matchRParen();let c=this.expression(yr,{expressions:r,fields:n,unpivot:s,includeNulls:t,defaultOnNull:a,group:o});if(this.matchSet(new Set(["pivot","unpivot"]),{advance:!1})||c.setArgKey("alias",this.parseTableAlias()),!s){let l=this.pivotColumnNames(r),u=[],h=[];for(let d of c.args.fields){let x=d.args.expressions;x?.[0]instanceof Cr||x&&h.push(x.map(f=>this._constructor.IDENTIFY_PIVOT_STRINGS?f.sql():f.aliasOrName||""))}if(0<h.length){0<l.length&&h.push(l);for(let d of this.product(h)){let x=[...d];0<l.length&&this._constructor.PREFIXED_PIVOT_COLUMNS&&x.unshift(x.pop()),u.push(Z(x.join("_")))}}c.setArgKey("columns",u)}return c}pivotColumnNames(e){return e.map(t=>t.alias).filter(t=>t)}product(e){if(e.length===0)return[[]];if(e.length===1)return e[0].map(a=>[a]);let t=[],[s,...r]=e,n=this.product(r);for(let a of s)for(let o of n)t.push([a,...o]);return t}parsePrewhere(e={}){let{skipWhereToken:t=!1}=e;if(!(!t&&!this.match("prewhere")))return this.expression(uc,{comments:this.prevComments,this:this.parseDisjunction()})}parseWhere(e={}){let{skipWhereToken:t=!1}=e;if(!(!t&&!this.match("where")))return this.expression(at,{comments:this.prevComments,this:this.parseDisjunction()})}parseGroup(e={}){let{skipGroupByToken:t=!1}=e;if(!t&&!this.match("groupBy"))return;let s=this.prevComments,r={expressions:[],rollup:[],cube:[],groupingSets:[]};if(this.match("all")?r.all=!0:this.match("distinct")&&(r.all=!1),this.matchSet(this._constructor.QUERY_MODIFIER_TOKENS,{advance:!1}))return this.expression(Xs,{comments:s,...r});for(;;){let n=this.index;r.expressions.push(...this.parseCsv(()=>this.matchSet(new Set(["cube","rollup"]),{advance:!1})?void 0:this.parseDisjunction()));let a=this.index,o=this.match("with")||void 0,c=this.parseCubeOrRollup({withPrefix:o});if(c){let l=c instanceof ra?"rollup":"cube";r[l].push(c)}else{let l=this.parseGroupingSets();l?r.groupingSets.push(l):this.matchTextSeq("TOTALS")&&(r.totals=!0)}if(a<=this.index&&this.index<=a+1){this.retreat(a);break}if(n===this.index)break}return this.expression(Xs,{comments:s,...r})}parseCubeOrRollup(e={}){let{withPrefix:t=!1}=e,s;if(this.match("cube"))s=Xo;else if(this.match("rollup"))s=ra;else return;return this.expression(s,{expressions:t?[]:this.parseWrappedCsv(()=>this.parseBitwise())})}parseGroupingSets(){if(this.match("groupingSets"))return this.expression(zo,{expressions:this.parseWrappedCsv(()=>this.parseGroupingSet())})}parseGroupingSet(){return this.parseGroupingSets()||this.parseCubeOrRollup()||this.parseBitwise()}parseHaving(e={}){let{skipHavingToken:t=!1}=e;if(!(!t&&!this.match("having")))return this.expression(Zt,{comments:this.prevComments,this:this.parseDisjunction()})}parseQualify(){if(this.match("qualify"))return this.expression(Os,{this:this.parseDisjunction()})}parseConnectWithPrior(){this._constructor.NO_PAREN_FUNCTION_PARSERS.PRIOR=function(){return this.expression(_o,{this:this.parseBitwise()})};let e=this.parseDisjunction();return delete this._constructor.NO_PAREN_FUNCTION_PARSERS.PRIOR,e}parseConnect(e={}){let{skipStartToken:t=!1}=e,s;if(t)s=void 0;else if(this.match("startWith"))s=this.parseDisjunction();else return;this.match("connectBy");let r=this.matchTextSeq("NOCYCLE")||void 0,n=this.parseConnectWithPrior();return!s&&this.match("startWith")&&(s=this.parseDisjunction()),this.expression(Mo,{start:s,connect:n,nocycle:r})}parseNameAsExpression(){let e=this.parseIdVar({anyToken:!0});return this.match("alias")&&(e=this.expression(Re,{alias:e,this:this.parseDisjunction()})),e}parseInterpolate(){if(this.matchTextSeq("INTERPOLATE"))return this.parseWrappedCsv(()=>this.parseNameAsExpression())}parseOrder(e={}){let{thisExpr:t,skipOrderToken:s=!1}=e,r;if(!s&&!this.match("orderBy")){if(!this.match("orderSiblingsBy"))return t;r=!0}return this.expression(fe,{comments:this.prevComments,this:t,expressions:this.parseCsv(()=>this.parseOrdered()),siblings:r})}parseSort(e,t){if(this.match(t))return this.expression(e,{expressions:this.parseCsv(()=>this.parseOrdered())})}parseOrdered(e){let t=e?e():this.parseDisjunction();if(!t)return;let s=t;t.name?.toUpperCase()==="ALL"&&this._dialectConstructor.SUPPORTS_ORDER_BY_ALL&&(s=Q("ALL"));let r=this.match("asc")||void 0,n=this.match("desc")||void 0||r&&!1,a=this.matchTextSeq(["NULLS","FIRST"])||void 0,o=this.matchTextSeq(["NULLS","LAST"])||void 0,c=a||!1;!(a||o)&&(!n&&this._dialectConstructor.NULL_ORDERING==="nulls_are_small"||n&&this._dialectConstructor.NULL_ORDERING!=="nulls_are_small")&&this._dialectConstructor.NULL_ORDERING!=="nulls_are_last"&&(c=!0);let u;return this.matchTextSeq(["WITH","FILL"])&&(u=this.expression(ec,{fromValue:this.match("from")&&this.parseBitwise(),to:this.matchTextSeq("TO")&&this.parseBitwise(),step:this.matchTextSeq("STEP")&&this.parseBitwise(),interpolate:this.parseInterpolate()})),this.expression(Ht,{this:s,desc:n,nullsFirst:c,withFill:u})}parseLimitOptions(){let e=this.matchSet(new Set(["percent","mod"]))||void 0,t=this.matchSet(new Set(["row","rows"]))||void 0;this.matchTextSeq("ONLY");let s=this.matchTextSeq(["WITH","TIES"])||void 0;if(e||t||s)return this.expression(Qo,{percent:e,rows:t,withTies:s})}parseLimit(e,t={}){let{top:s=!1,skipLimitToken:r=!1}=t;if(r||this.match(s?"top":"limit")){let n=this.prevComments,a;if(s){let u=this.match("lParen")||void 0;a=u?this.parseTerm():this.parseNumber(),u&&this.matchRParen()}else{let u=this.index;a=this.tryParse(()=>this.parseTerm()),a instanceof Bi?(this.retreat(u),a=this.parseFactor()):a||(a=this.parseFactor())}let o=this.parseLimitOptions(),c;return this.match("comma")&&(c=a,a=this.parseTerm()),this.expression(Et,{this:e,expression:a,offset:c,comments:n,limitOptions:o,expressions:this.parseLimitBy()})}if(this.match("fetch")){let a=this.matchSet(new Set(["first","next"]))||void 0?(this.prev?.text??"").toUpperCase():"FIRST",o=this.parseField({tokens:this._constructor.FETCH_TOKENS});return this.expression(_s,{direction:a,count:o,limitOptions:this.parseLimitOptions()})}return e}parseOffset(e){if(!this.match("offset"))return e;let t=this.parseTerm();return this.matchSet(new Set(["row","rows"])),this.expression(Rr,{this:e,expression:t,expressions:this.parseLimitBy()})}canParseLimitOrOffset(){if(!this.matchSet(new Set(this._constructor.AMBIGUOUS_ALIAS_TOKENS),{advance:!1}))return!1;let e=this.index,t=!!(this.tryParse(()=>this.parseLimit(),{retreat:!0})||this.tryParse(()=>this.parseOffset(),{retreat:!0}));return this.retreat(e),this.next&&this.next.tokenType==="matchCondition"?!1:t}parseLimitBy(){return this.matchTextSeq("BY")?this.parseCsv(()=>this.parseBitwise()):void 0}parseLocks(){let e=[];for(;;){let t,s;if(this.matchTextSeq(["FOR","UPDATE"]))t=!0;else if(this.matchTextSeq(["FOR","SHARE"])||this.matchTextSeq(["LOCK","IN","SHARE","MODE"]))t=!1;else if(this.matchTextSeq(["FOR","KEY","SHARE"]))t=!1,s=!0;else if(this.matchTextSeq(["FOR","NO","KEY","UPDATE"]))t=!0,s=!0;else break;let r;this.matchTextSeq("OF")&&(r=this.parseCsv(()=>this.parseTable({schema:!0})));let n;this.matchTextSeq("NOWAIT")?n=!0:this.matchTextSeq("WAIT")?n=this.parsePrimary():this.matchTextSeq(["SKIP","LOCKED"])&&(n=!1),e.push(this.expression(Aa,{update:t,expressions:r,wait:n,key:s}))}return e}parseSetOperation(e,t={}){let{consumePipe:s=!1}=t,r=this.index,{side:n,kind:a}=this.parseJoinParts(),o=ut(Qt,n?.text),c=ut(cN,a?.text);if(!this.matchSet(this._constructor.SET_OPERATIONS)){this.retreat(r);return}let l=this.prev?.tokenType,u;l==="union"?u=Lr:l==="except"?u=wr:u=kn;let h=this.prev?.comments,d;this.match("distinct")?d=!0:this.match("all")?d=!1:(d=this._dialectConstructor.SET_OP_DISTINCT_BY_DEFAULT[u.key],d===void 0&&this.raiseError(`Expected DISTINCT or ALL for ${u.name}`,this.curr));let x=this.matchTextSeq(["BY","NAME"])||this.matchTextSeq(["STRICT","CORRESPONDING"])||void 0;this.matchTextSeq("CORRESPONDING")&&(x=!0,!o&&!c&&(c="inner"));let f;x&&this.matchTexts(["ON","BY"])&&(f=this.parseWrappedCsv(()=>this.parseColumn()));let y=this.parseSelect({nested:!0,parseSetOperation:!1,consumePipe:s});return this.expression(u,{comments:h,this:e,distinct:d,byName:x,expression:y,side:o,kind:c,on:f})}parseSetOperations(e){let t=e;for(;t;){let s=this.parseSetOperation(t);if(!s)break;t=s}if(t instanceof Xe&&this._constructor.MODIFIERS_ATTACHED_TO_SET_OP){let s=t.args.expression;if(s)for(let r of this._constructor.SET_OP_MODIFIERS){let n=s.args[r];n instanceof A&&t.setArgKey(r,n.pop())}}return t}parseExpression(){return this.parseAlias(this.parseAssignment())}parseAssignment(){let e=this.parseDisjunction();if(!e&&this.next&&this.next.tokenType in this._constructor.ASSIGNMENT){let s=this.advanceAny({ignoreReserved:!0});e=ho({col:s&&this.prev?.text})}let t=Object.keys(this._constructor.ASSIGNMENT);for(;this.matchSet(t);)e instanceof B&&e.parts.length===1&&(e=e.args.this),e=this.expression(this._constructor.ASSIGNMENT[this.prev.tokenType],{this:e,comments:this.prevComments,expression:this.parseAssignment()});return e}parseDisjunction(){return this.parseTokens(()=>this.parseConjunction(),this._constructor.DISJUNCTION)}parseConjunction(){return this.parseTokens(()=>this.parseEquality(),this._constructor.CONJUNCTION)}parseEquality(){return this.parseTokens(()=>this.parseComparison(),this._constructor.EQUALITY)}parseComparison(){return this.parseTokens(()=>this.parseRange(),this._constructor.COMPARISON)}parseRange(e){let t=e||this.parseBitwise(),s=this.match("not")||void 0;if(this.matchSet(Object.keys(this._constructor.RANGE_PARSERS))){let r=this._constructor.RANGE_PARSERS[this.prev?.tokenType??"unknown"];if(r&&t){let n=r.call(this,t);if(!n)return t;t=n}}else(this.match("isnull")||s&&this.match("null"))&&(t=this.expression(_e,{this:t,expression:pe()}));return this.match("notnull")&&(t=this.expression(_e,{this:t,expression:pe()}),t=this.expression(be,{this:t})),s&&(t=this.negateRange(t)),this.match("is")&&(t=this.parseIs(t)),t}negateRange(e){return e&&this.expression(be,{this:e})}parseIs(e){let t=this.index-1,s=this.match("not")||void 0;if(this.matchTextSeq(["DISTINCT","FROM"])){let a=s?Ps:Gs;return this.expression(a,{this:e,expression:this.parseBitwise()})}let r;if(this.match("json")){let a=(this.matchTexts(Array.from(this._constructor.IS_JSON_PREDICATE_KIND))||void 0)&&(this.prev?.text??"").toUpperCase(),o;this.matchTextSeq("WITH")?o=!0:this.matchTextSeq("WITHOUT")&&(o=!1);let c=this.match("unique")||void 0;this.matchTextSeq("KEYS"),r=this.expression(yc,{this:a,with:o,unique:c})}else if(r=this.parseNull()||this.parseBitwise(),!r){this.retreat(t);return}let n=this.expression(_e,{this:e,expression:r});return s?this.expression(be,{this:n}):this.parseColumnOps(n)}parseIn(e,t={}){let{alias:s=!1}=t,r=this.parseUnnest({withAlias:!1}),n;if(r)n=this.expression(it,{this:e,unnest:r});else if(this.matchSet(new Set(["lParen","lBracket"]))){let a=this.prev?.tokenType==="lParen",o=this.parseCsv(()=>this.parseSelectOrExpression({alias:s}));if(o.length===1&&o[0]instanceof z){let c=o[0],u=this.parseQueryModifiers(c).subquery(void 0,{copy:!1});n=this.expression(it,{this:e,query:u})}else n=this.expression(it,{this:e,expressions:o});a?this.matchRParen(n):this.match("rBracket",{expression:n})||this.raiseError("Expecting ]",this.curr)}else n=this.expression(it,{this:e,field:this.parseColumn()});return n}parseBetween(e){let t;this.matchTextSeq("SYMMETRIC")?t=!0:this.matchTextSeq("ASYMMETRIC")&&(t=!1);let s=this.parseBitwise();this.match("and");let r=this.parseBitwise();return this.expression(ss,{this:e,low:s,high:r,symmetric:t})}parseEscape(e){return this.match("escape")?this.expression(ma,{this:e,expression:this.parseString()||this.parseNull()}):e}parseIntervalSpan(e){let t;if(e&&e.isString&&this._constructor.SUPPORTS_OMITTED_INTERVAL_SPAN_UNIT&&e.name?.match?.(vI)){let n=this.index,a=this.parseVar({anyToken:!0,upper:!0}),o;a&&this.matchTextSeq("TO")&&(o=this.parseVar({anyToken:!0,upper:!0})),t=!(a&&o),this.retreat(n)}let s=t?void 0:this.parseFunction()||!this.match("alias",{advance:!1})&&this.parseVar({anyToken:!0,upper:!0})||void 0,r=e;if(e&&e.isNumber)r=R.string(e.toValue()||e.sql());else if(e&&e.isString){let n=Array.from(e.name?.matchAll(new RegExp(UI,"g"))||[]);0<n.length&&s&&(s=void 0,this.retreat(this.index-1)),n.length===1&&(r=R.string(n[0][1]),s=this.expression(qe,{this:n[0][2].toUpperCase()}))}return this._constructor.INTERVAL_SPANS&&this.matchTextSeq("TO")&&(s=this.expression(Ks,{this:s,expression:this.parseFunction()||this.parseVar({anyToken:!0,upper:!0})})),this.expression(Ce,{this:r,unit:s})}parseInterval(e={}){let{matchInterval:t=!0}=e,s=this.index;if(!this.match("interval")&&t)return;let r;if(this.match("string",{advance:!1})?r=this.parsePrimary():r=this.parseTerm(),!r||r instanceof B&&!r.args.table&&r.args.this instanceof U&&!r.args.this.args.quoted&&this.curr&&!this._dialectConstructor.VALID_INTERVAL_UNITS.has(this.curr.text.toUpperCase())){this.retreat(s);return}let n=this.parseIntervalSpan(r),a=this.index;return this.match("plus"),this.matchSet(new Set(["string","number"]),{advance:!1})?this.expression(Le,{this:n,expression:this.parseInterval({matchInterval:!1})}):(this.retreat(a),n)}parseBitwise(){let e=this.parseTerm(),t=Object.keys(this._constructor.BITWISE);for(;;)if(this.matchSet(t)){let s=this._constructor.BITWISE[this.prev?.tokenType??"unknown"];s&&(e=this.expression(s,{this:e,expression:this.parseTerm()}))}else if(this._dialectConstructor.DPIPE_IS_STRING_CONCAT&&this.match("dpipe"))e=this.expression(Mt,{this:e,expression:this.parseTerm(),safe:!this._dialectConstructor.STRICT_STRING_CONCAT});else if(this.match("dqmark"))e=this.expression(rt,{this:e,expressions:J(this.parseTerm())});else if(this.matchPair("lt","lt"))e=this.expression(wl,{this:e,expression:this.parseTerm()});else if(this.matchPair("gt","gt"))e=this.expression(Sa,{this:e,expression:this.parseTerm()});else break;return e}parseTerm(){let e=this.parseFactor(),t=Object.keys(this._constructor.TERM);for(;this.matchSet(t);){let s=this._constructor.TERM[this.prev?.tokenType??"unknown"],r=this.prevComments,n=this.parseFactor();if(s&&(e=this.expression(s,{this:e,comments:r,expression:n}),e instanceof RA)){let a=e.args.expression;if(a instanceof B&&a.parts.length===1){let o=a.args.this;o instanceof U&&e.setArgKey("expression",o.args.quoted?o:Q(o.name))}}}return e}parseFactor(){let e=this._constructor.EXPONENT?()=>this.parseExponent():()=>this.parseUnary(),t=this.parseAtTimeZone(e()),s=Object.keys(this._constructor.FACTOR);for(;this.matchSet(s);){let r=this._constructor.FACTOR[this.prev?.tokenType??"unknown"],n=this.prevComments,a=e();if(!a&&r===ha&&/^[a-zA-Z]/.test(this.prev?.text??""))return this.retreat(this.index-1),t;r&&(t=this.expression(r,{this:t,comments:n,expression:a}),t instanceof mt&&(t.setArgKey("typed",this._dialectConstructor.TYPED_DIVISION),t.setArgKey("safe",this._dialectConstructor.SAFE_DIVISION)))}return t}parseExponent(){return this.parseTokens(()=>this.parseUnary(),this._constructor.EXPONENT)}parseUnary(){if(this.matchSet(Object.keys(this._constructor.UNARY_PARSERS))){let e=this._constructor.UNARY_PARSERS[this.prev?.tokenType??"unknown"];return e?e.call(this):void 0}return this.parseType()}parseType(e={}){let{parseInterval:t=!0,fallbackToIdentifier:s=!1}=e,r=t&&this.parseInterval();if(r)return this.parseColumnOps(r);let n=this.index,a=this.parseTypes({checkFunc:!0,allowIdentifiers:!1});if(a instanceof X)return this.parseColumnOps(a);if(a){let c=this.index,l=this.parsePrimary();if(l instanceof R){let u=l.name,h=this.parseColumnOps(l),d=typeof a.args.this=="string"?this._constructor.TYPE_LITERAL_PARSERS[a.args.this]:void 0;return d?d.call(this,h,a):(this._constructor.ZONE_AWARE_TIMESTAMP_CONSTRUCTOR&&a.isType?.(["timestamp"])&&dU.test(u)&&a.setArgKey("this","timestamptz"),this.expression(X,{this:h,to:a}))}if(a.args.expressions&&1<c-n)return this.retreat(c),this.parseColumnOps(a);this.retreat(n)}if(s)return this.parseIdVar();let o=this.parseColumn();return o&&this.parseColumnOps(o)}parseTypeSize(){let e=this.parseType();if(e)return e instanceof B&&!e.args.table&&(e=Q(e.name.toUpperCase())),this.expression(rr,{this:e,expression:this.parseVar({anyToken:!0})})}parseUserDefinedType(e){let t=e.name;for(;this.match("dot");)this.advanceAny(),t=`${t}.${this.prev?.text??""}`;return O.build(t,{dialect:this.dialect,udt:!0})}parseTypes(e={}){let{checkFunc:t=!1,schema:s=!1,allowIdentifiers:r=!0}=e,n=this.index,a,o=this.matchTextSeq(["SYSUDTLIB","."])||void 0,c,l;if(this.matchSet(this._constructor.TYPE_TOKENS))c=this.prev?.tokenType,l=this.prev?.text;else{let P=r&&this.parseIdVar({anyToken:!1,tokens:new Set(["var"])});if(P instanceof U){let k;try{k=this.dialect.tokenize?.(P.name)}catch{k=void 0}if(k&&k.length===1&&this._constructor.TYPE_TOKENS.has(k[0].tokenType))c=k[0].tokenType,l=k[0].text;else if(this._dialectConstructor.SUPPORTS_USER_DEFINED_TYPES)a=this.parseUserDefinedType(P);else{this.retreat(this.index-1);return}}else return}if(c==="pseudoType")return this.expression(bl,{this:(this.prev?.text??"").toUpperCase()});if(c==="objectIdentifier")return this.expression(Ll,{this:(this.prev?.text??"").toUpperCase()});if(c==="map"&&this.match("lBracket")){let P=this.parseTypes({checkFunc:t,schema:s,allowIdentifiers:r});if(!this.match("farrow")){this.retreat(n);return}let k=this.parseTypes({checkFunc:t,schema:s,allowIdentifiers:r});if(!this.match("rBracket")){this.retreat(n);return}return new O({this:"map",expressions:[P,k],nested:!0,prefix:o})}let u=c&&this._constructor.NESTED_TYPE_TOKENS.has(c),h=c&&this._constructor.STRUCT_TYPE_TOKENS.has(c),d=c&&this._constructor.AGGREGATE_TYPE_TOKENS.has(c),x,f=!1;if(this.match("lParen")){if(h)x=this.parseCsv(()=>this.parseStructTypes({typeRequired:!0}));else if(u){if(x=this.parseCsv(()=>this.parseTypes({checkFunc:t,schema:s,allowIdentifiers:r})),c==="nullable"&&x.length===1)return a=x[0],a.setArgKey("nullable",!0),this.matchRParen(),a}else if(c&&this._constructor.ENUM_TYPE_TOKENS.has(c))x=this.parseCsv(()=>this.parseEquality());else if(d){let P=this.parseFunction({anonymous:!0})||this.parseIdVar({anyToken:!1,tokens:new Set(["var","any"])});if(!P)return;x=[P],this.match("comma")&&x.push(...this.parseCsv(()=>this.parseTypes({checkFunc:t,schema:s,allowIdentifiers:r})))}else x=this.parseCsv(()=>this.parseTypeSize()),c==="vector"&&x.length===2&&(x=this.parseVectorExpressions(x));if(!this.match("rParen")){this.retreat(n);return}f=!0}let y;if(u&&this.match("lt")&&(h?x=this.parseCsv(()=>this.parseStructTypes({typeRequired:!0})):x=this.parseCsv(()=>this.parseTypes({checkFunc:t,schema:s,allowIdentifiers:r})),this.match("gt")||this.raiseError("Expecting >",this.curr),this.matchSet(new Set(["lBracket","lParen"]))&&(y=this.parseCsv(()=>this.parseDisjunction()),!y&&h?(y=void 0,this.retreat(this.index-1)):this.matchSet(new Set(["rBracket","rParen"])))),c&&this._constructor.TIMESTAMPS.has(c))if(this.matchTextSeq(["WITH","TIME","ZONE"])){f=!1;let P=this._constructor.TIMES.has(c)?"timetz":"timestamptz";a=new O({this:P,expressions:x})}else this.matchTextSeq(["WITH","LOCAL","TIME","ZONE"])?(f=!1,a=new O({this:"timestampltz",expressions:x})):this.matchTextSeq(["WITHOUT","TIME","ZONE"])&&(f=!1);else if(c==="interval")if(this.curr&&this._dialectConstructor.VALID_INTERVAL_UNITS.has(this.curr.text.toUpperCase())){let P=this.parseVar({upper:!0});this.matchTextSeq("TO")&&(P=new Ks({this:P,expression:this.parseVar({upper:!0})})),a=this.expression(O,{this:new Ce({unit:P})})}else a=this.expression(O,{this:"interval"});else c==="void"&&(a=new O({this:"null"}));if(f&&t){let P=this.index;if(!this.parseString()){this.retreat(n);return}this.retreat(P)}if(a)x&&a.setArgKey("expressions",x);else{if(this.matchTextSeq("UNSIGNED")){let P=c&&this._constructor.SIGNED_TO_UNSIGNED_TYPE_TOKEN[c];P||this.raiseError(`Cannot convert ${c?.valueOf()} to unsigned.`,this.curr),c=P||c}if(c==="nullable"&&!x){this.retreat(n);return}if(c&&(a=new O({this:ht[SN(c)],expressions:x,nested:u,prefix:o}),y!==void 0)){let P=h?ks:ue;a=j(new P({expressions:y}),a,{copy:!1})}}for(;this.match("list");)a=new O({this:"list",expressions:[a],nested:!0});let I=this.index,N=this.match("array")||!1;for(;this.curr;){let P=this.prev?.tokenType;if(!(this.match("lBracket")||void 0)&&!N||P==="array"&&this.match("rBracket"))break;N=!1;let _=this.parseCsv(()=>this.parseDisjunction());if(0<_.length&&!s&&(!this._dialectConstructor.SUPPORTS_FIXED_SIZE_ARRAYS||P==="array"||!this.match("rBracket",{advance:!1}))){this.retreat(I);break}a=new O({this:"array",expressions:[a],values:_,nested:!0}),this.match("rBracket")}if(a&&this._constructor.TYPE_CONVERTERS&&typeof a.args.this=="string"){let P=this._constructor.TYPE_CONVERTERS[a.args.this];P&&(a=P(a))}return a}parseVectorExpressions(e){let t=O.build(e[0].name,{dialect:this.dialect});return[...t?[t]:[],...e.slice(1)]}parseStructTypes(e={}){let{typeRequired:t=!1}=e,s=this.index,r;return this.curr&&this.next&&this._constructor.TYPE_TOKENS.has(this.curr.tokenType)&&this._constructor.TYPE_TOKENS.has(this.next.tokenType)?r=this.parseIdVar():r=this.parseType({parseInterval:!1,fallbackToIdentifier:!0})||this.parseIdVar(),this.match("colon"),t&&!(r instanceof O)&&!this.matchSet(this._constructor.TYPE_TOKENS,{advance:!1})?(this.retreat(s),this.parseTypes()):this.parseColumnDef(r)}parseAtTimeZone(e){return this.matchTextSeq(["AT","TIME","ZONE"])?this.parseAtTimeZone(this.expression(Wt,{this:e,zone:this.parseUnary()})):e}parseColumn(){let e=this.parseColumnReference(),t=e?this.parseColumnOps(e):this.parseBracket(e);return this._dialectConstructor.SUPPORTS_COLUMN_JOIN_MARKS&&t&&t.setArgKey("joinMark",this.match("joinMarker")),t}parseColumnReference(){let e=this.parseField();return!e&&this.match("values",{advance:!1})&&this._constructor.VALUES_FOLLOWED_BY_PAREN&&(!this.next||this.next.tokenType!=="lParen")&&(e=this.parseIdVar()),e instanceof U&&(e=this.expression(B,{comments:e.popComments(),this:e})),e}parseColonAsVariantExtract(e){let t=[],s=[],r;for(;this.match("colon");){let n=this.index,a=this.parseColumnOps(this.parseField({anyToken:!0,tokens:new Set(["select"])}));for(;a instanceof X;)t.push(a.args.to),a=a.args.this;let o;if(0<t.length){let c=this.tokens.slice(n).findIndex(l=>l.tokenType==="dcolon");o=this.tokens[n+c-1]}else o=this.prev;a&&(a instanceof U&&a.args.quoted&&(r=!0),s.push(this.findSql(this.tokens[n],o)))}if(0<s.length){let n=this.dialect.toJsonPath?.(R.string("."+s.join(".")));for(n&&n.setArgKey("escape",r),e=this.expression(js,{this:e,expression:n,variantExtract:!0,requiresJson:this._constructor.JSON_EXTRACT_REQUIRES_JSON_EXPRESSION});0<t.length;)e=this.expression(X,{this:e,to:t.pop()})}return e}parseDcolon(){return this.parseTypes()}parseColumnOps(e){let t=this.parseBracket(e);for(;this.matchSet(Object.keys(this._constructor.COLUMN_OPERATORS));){let s=this.prev?.tokenType??"unknown",r=this._constructor.COLUMN_OPERATORS[s],n;if(this._constructor.CAST_COLUMN_OPERATORS.has(s)?(n=this.parseDcolon(),n||this.raiseError("Expected type",this.curr)):r&&this.curr?(n=this.parseColumnReference()||this.parseBitwise(),n instanceof B&&this.match("dot",{advance:!1})&&(n=this.parseColumnOps(n))):n=this.parseField({anyToken:!0,anonymousFunc:!0}),(n instanceof g||n instanceof we)&&t&&(t=t.transform(a=>a instanceof B&&a.toDot?.({includeDots:!1})||a)),r)t=r.call(this,t,n);else if(t instanceof B&&!t.args.catalog)t=this.expression(B,{comments:t.comments,this:n,table:t.args.this,db:t.args.table,catalog:t.args.db});else if(n instanceof we){let a=this.expression(Se,{this:t,expression:n.args.this});n.setArgKey("this",a),t=n}else t=this.expression(Se,{this:t,expression:n});n?.comments&&t?.addComments?.(n.popComments()),t=this.parseBracket(t)}return this._constructor.COLON_IS_VARIANT_EXTRACT?this.parseColonAsVariantExtract(t):t}parseComment(e={}){let{allowExists:t=!0}=e,s=this.prev,r=t?this.parseExists():void 0;this.match("on");let n=this.matchTextSeq("MATERIALIZED")||void 0,a=(this.matchSet(this._constructor.CREATABLES)||void 0)&&this.prev;if(!a)return this.parseAsCommand(s);let o;return a.tokenType==="function"||a.tokenType==="procedure"?o=this.parseUserDefinedFunction({kind:a.tokenType}):a.tokenType==="table"?o=this.parseTable({aliasTokens:this._constructor.COMMENT_TABLE_ALIAS_TOKENS}):a.tokenType==="column"?o=this.parseColumn():o=this.parseIdVar(),this.match("is"),this.expression(Po,{this:o,kind:a.text,expression:this.parseString(),exists:r,materialized:n})}parseToTable(){let e=this.parseTableParts({schema:!0});return this.expression(Jr,{this:e})}parseTtl(){let e=()=>{let a=this.parseBitwise();return this.matchTextSeq("DELETE")?this.expression(Sr,{this:a,delete:!0}):this.matchTextSeq("RECOMPRESS")?this.expression(Sr,{this:a,recompress:this.parseBitwise()}):this.matchTextSeq(["TO","DISK"])?this.expression(Sr,{this:a,toDisk:this.parseString()}):this.matchTextSeq(["TO","VOLUME"])?this.expression(Sr,{this:a,toVolume:this.parseString()}):a},t=this.parseCsv(e),s=this.parseWhere(),r=this.parseGroup(),n;return r&&this.match("set")&&(n=this.parseCsv(this.parseSetItem.bind(this))),this.expression(Ir,{expressions:t,where:s,group:r,aggregates:n})}parseStatement(){if(this.curr===void 0)return;let e=Object.keys(this._constructor.STATEMENT_PARSERS);if(this.matchSet(e)){let s=this.prevComments,r=this._constructor.STATEMENT_PARSERS[this.prev?.tokenType??"unknown"]?.call(this);return r?.addComments(s,{prepend:!0}),r}if(this.matchSet(this._dialectConstructor.tokenizerClass.COMMANDS))return this.parseCommand();let t=this.parseExpression();return t=t?this.parseSetOperations(t):this.parseSelect(),this.parseQueryModifiers(t)}parsePartitionedByBucketOrTruncate(){if(this.curr?.tokenType!=="lParen"){this.retreat(this.index-1);return}let e=this.prev?.text.toUpperCase()==="BUCKET"?In:yn,t=this.parseWrappedCsv(()=>this.parsePrimary()||this.parseColumn()),s=M(t,0),r=M(t,1);return s instanceof R&&([s,r]=[r,s]),this.expression(e,{this:s,expression:r})}raiseError(e,t){let s=t||this.curr||this.prev||vf.string(""),{formattedSql:r,startContext:n,highlight:a,endContext:o}=dw({sql:this.sql,positions:[[s.start??0,s.end??0]],contextLength:this.errorMessageContext}),c=`${e}. Line ${s.line}, Col: ${s.col}.
5
+ ${r}`,l=new xt(c,[{description:e,line:s.line,col:s.col,startContext:n,highlight:a,endContext:o}]);if(this.errorLevel===3)throw l;this.errors.push(l)}checkErrors(){if(this.errorLevel===1)for(let e of this.errors)console.error(e.toString());else if(this.errorLevel===2&&0<this.errors.length)throw new xt(nN(this.errors,this.maxErrors),cI(this.errors))}expression(e,t={}){let{token:s,comments:r,...n}=t,a;return s?(a=new e({this:s.text,...n}),a.updatePositions(s)):a=new e(n),r?.length?a.addComments(r):this.addComments(a),this.validateExpression(a)}addComments(e){e&&this.prevComments?.length&&(e.addComments(this.prevComments),this.prevComments=void 0)}parseIdVar(e={}){let{anyToken:t=!0,tokens:s}=e,r=this.parseIdentifier();if(!r&&(t&&this.advanceAny()||this.matchSet(s||this._constructor.ID_VAR_TOKENS))){let n=this.prev?.tokenType==="string";r=this.identifierExpression(void 0,{quoted:n})}return r}parseGrantPrincipal(){let e=(this.matchTexts(["ROLE","GROUP"])||void 0)&&this.prev?.text.toUpperCase(),t=this.parseIdVar();if(t)return this.expression(sc,{this:t,kind:e})}parseGrantPrivilege(){let e=[];for(;this.curr&&!this.matchSet(this._constructor.PRIVILEGE_FOLLOW_TOKENS,{advance:!1});)e.push(this.curr.text.toUpperCase()),this.advance();let t=this.expression(qe,{this:e.join(" ")}),s=this.match("lParen",{advance:!1})?this.parseWrappedCsv(()=>this.parseColumn()):void 0;return this.expression(tc,{this:t,expressions:s})}matchTexts(e,t={}){let{advance:s=!0}=t,r=Array.from(e instanceof Set?e:J(e));return this.curr&&this.curr.tokenType!=="string"&&r.includes(this.curr.text.toUpperCase())?(s&&this.advance(),!0):!1}matchSet(e,t={}){let{advance:s=!0}=t;return this.curr&&(Array.isArray(e)?e.includes(this.curr.tokenType):e.has(this.curr.tokenType))?(s&&this.advance(),!0):!1}matchPair(e,t,s={}){let{advance:r=!0}=s;return!this.curr||!this.next?!1:this.curr.tokenType===e&&this.next.tokenType===t?(r&&this.advance(2),!0):!1}matchLParen(e){this.match("lParen",{advance:!0,expression:e})||this.raiseError("Expecting (")}matchRParen(e){this.match("rParen",{advance:!0,expression:e})||this.raiseError("Expecting )")}matchTextSeq(e,t={}){let{advance:s=!0}=t,r=J(e),n=this.index;for(let a of r)if(this.curr&&this.curr.tokenType!=="string"&&this.curr.text.toUpperCase()===a)this.advance();else return this.retreat(n),!1;return s||this.retreat(n),!0}replaceLambda(e,t){if(!e)return e;let s={};for(let r of t)s[r.name]=r.args.to||!1;for(let r of e.findAll(B)){let n=s[r.parts[0]?.name||""];if(n!==void 0){let a=r.args.this;te(a,U);let o=r.table?r.toDot():a;n&&(o=this.expression(X,{this:o,to:n}));let c=r.parent;for(;c instanceof Se;){if(!(c.parent instanceof Se)){c.replace(o);break}c=c.parent}(!c||!(c instanceof Se))&&(r===e?e=o:r.replace(o))}}return e}parseTruncateTable(){let e=this.prev;if(this.match("lParen"))return this.retreat(this.index-2),this.parseFunction();let t=this.match("database")||void 0;this.match("table");let s=this.parseExists({not:!1}),r=this.parseCsv(()=>this.parseTable({schema:!0,isDbReference:t})),n=this.match("on")?this.parseOnProperty():void 0,a;this.matchTextSeq(["RESTART","IDENTITY"])?a="RESTART":this.matchTextSeq(["CONTINUE","IDENTITY"])?a="CONTINUE":a=void 0;let o;this.matchTextSeq("CASCADE")||this.matchTextSeq("RESTRICT")?o=this.prev?.text:o=void 0;let c=this.parsePartition();return this.curr?this.parseAsCommand(e):this.expression(xo,{expressions:r,isDatabase:t,exists:s,cluster:n,identity:a,option:o,partition:c})}parseWithOperator(){let e=this.parseOrdered(()=>this.parseOpClass());if(!this.match("with"))return e;let t=this.parseVar({anyToken:!0,tokens:this._constructor.RESERVED_TOKENS});return this.expression(ji,{this:e,op:t})}parseWrappedOptions(){this.match("eq"),this.match("lParen");let e=[],t;for(;this.curr&&!this.match("rParen");){if(this.matchTextSeq(["FORMAT_NAME","="])?t=this.parseFormatName():t=this.parseProperty(),t===void 0){this.raiseError("Unable to parse option");break}e.push(...Array.isArray(t)?t:[t])}return e}parseCopyParameters(){let e=this._dialectConstructor.COPY_PARAMS_ARE_CSV?"comma":void 0,t=[];for(;this.curr&&!this.match("rParen",{advance:!1});){let s=this.parseVar({anyToken:!0}),r=this.prev?.text.toUpperCase();this.match("eq"),this.match("alias");let n=this.expression(Do,{this:s});r&&this._constructor.COPY_INTO_VARLEN_OPTIONS.has(r)&&this.match("lParen",{advance:!1})?n.setArgKey("expressions",this.parseWrappedOptions()):r==="FILE_FORMAT"?n.setArgKey("expression",this.parseField()):r==="FORMAT"&&this.prev?.tokenType==="alias"&&this.matchTexts(["AVRO","JSON"])?(n.setArgKey("this",this.expression(qe,{this:`FORMAT AS ${this.prev?.text.toUpperCase()}`})),n.setArgKey("expression",this.parseField())):n.setArgKey("expression",this.parseUnquotedField()||this.parseBracket()),t.push(n),e&&this.match(e)}return t}parseCredentials(){let e=this.expression(ko,{});if(this.matchTextSeq(["STORAGE_INTEGRATION","="])&&e.setArgKey("storage",this.parseField()),this.matchTextSeq("CREDENTIALS")){let t=this.match("eq")?this.parseWrappedOptions():this.parseField();e.setArgKey("credentials",t)}return this.matchTextSeq("ENCRYPTION")&&e.setArgKey("encryption",this.parseWrappedOptions()),this.matchTextSeq("IAM_ROLE")&&e.setArgKey("iamRole",this.match("default")?this.expression(qe,{this:this.prev?.text}):this.parseField()),this.matchTextSeq("REGION")&&e.setArgKey("region",this.parseField()),e}parseFileLocation(){return this.parseField()}parseCopy(){let e=this.prev;this.match("into");let t=this.match("lParen",{advance:!1})?this.parseSelect({nested:!0,parseSubqueryAlias:!1}):this.parseTable({schema:!0}),s=this.match("from")||!this.matchTextSeq("TO"),r=this.parseCsv(()=>this.parseFileLocation());this.match("eq",{advance:!1})&&(this.advance(-1),r=[]);let n=this.parseCredentials();this.matchTextSeq("WITH");let a=this.parseWrapped(()=>this.parseCopyParameters(),{optional:!0});return this.curr?this.parseAsCommand(e):this.expression(Kc,{this:t,kind:s,credentials:n,files:r,params:a})}parseNormalize(){return this.expression(oT,{this:this.parseBitwise(),form:this.match("comma")&&this.parseVar()})}parseCeilFloor(e){let t=this.parseCsv(()=>this.parseLambda()),s=M(t,0),r=M(t,1);return new e({this:s,decimals:r,to:this.matchTextSeq("TO")&&this.parseVar()})}parseStarOps(){let e=this.prev;if(this.matchTextSeq(["COLUMNS","("],{advance:!1})){let t=this.parseFunction();return t instanceof Hf&&t.setArgKey("unpack",!0),t}return this.expression(xe,{except:this.parseStarOp("EXCEPT")||this.parseStarOp("EXCLUDE"),replace:this.parseStarOp("REPLACE"),rename:this.parseStarOp("RENAME")}).updatePositions(e)}parseGrantRevokeCommon(){let e=this.parseCsv(()=>this.parseGrantPrivilege());this.match("on");let t=(this.matchSet(this._constructor.CREATABLES)||void 0)&&this.prev?.text.toUpperCase(),s=this.tryParse(()=>this.parseTableParts());return{privileges:e,kind:t,securable:s}}parseGrant(){let e=this.prev,{privileges:t,kind:s,securable:r}=this.parseGrantRevokeCommon();if(!r||!this.matchTextSeq("TO"))return this.parseAsCommand(e);let n=this.parseCsv(()=>this.parseGrantPrincipal()),a=this.matchTextSeq(["WITH","GRANT","OPTION"])||void 0;return this.curr?this.parseAsCommand(e):this.expression(jo,{privileges:t,kind:s,securable:r,principals:n,grantOption:a})}parseRevoke(){let e=this.prev,t=this.matchTextSeq(["GRANT","OPTION","FOR"])||void 0,{privileges:s,kind:r,securable:n}=this.parseGrantRevokeCommon();if(!n||!this.matchTextSeq("FROM"))return this.parseAsCommand(e);let a=this.parseCsv(()=>this.parseGrantPrincipal()),o;return this.matchTexts(["CASCADE","RESTRICT"])&&(o=this.prev?.text.toUpperCase()),this.curr?this.parseAsCommand(e):this.expression(Jo,{privileges:s,kind:r,securable:n,principals:a,grantOption:t,cascade:o})}parseOverlay(){let e=t=>(this.match("comma")||this.matchTextSeq(t)||void 0)&&this.parseBitwise();return this.expression(cT,{this:this.parseBitwise(),expression:e("PLACING"),from:e("FROM"),for:e("FOR")})}parseFormatName(){return this.expression(L,{this:this.expression(qe,{this:"FORMAT_NAME"}),value:this.parseString()||this.parseTableParts()})}parseMaxMinBy(e){let t=[];return this.match("distinct")&&(t.push(this.expression(We,{expressions:[this.parseLambda()]})),this.match("comma")),t.push(...this.parseFunctionArgs()),this.expression(e,{this:M(t,0),expression:M(t,1),count:M(t,2)})}identifierExpression(e,t){return this.expression(U,{token:e||this.prev,...t})}parseTokens(e,t){let s=e(),r=new Set(Object.keys(t));for(;this.matchSet(r);){let n=t[this.prev?.tokenType??"unknown"];if(!n)break;s=this.expression(n,{this:s,comments:this.prevComments,expression:e()})}return s}parseWrappedIdVars(e={}){let{optional:t=!1}=e;return this.parseWrappedCsv(()=>this.parseIdVar(),{optional:t})}parseWrappedCsv(e,t={}){let{sep:s="comma",optional:r=!1}=t;return this.parseWrapped(()=>this.parseCsv(e,{sep:s}),{optional:r})}parseWrapped(e,t={}){let{optional:s=!1}=t,r=this.match("lParen")||void 0;!r&&!s&&this.raiseError("Expecting (");let n=e();return r&&this.matchRParen(),n}parseExpressions(){return this.parseCsv(()=>this.parseExpression())}parseSelectOrExpression(e={}){let{alias:t=!1}=e;return this.parseSetOperations(t?this.parseAlias(this.parseAssignment(),{explicit:!0}):this.parseAssignment())||this.parseSelect()}parseDdlSelect(){return this.parseQueryModifiers(this.parseSetOperations(this.parseSelect({nested:!0,parseSubqueryAlias:!1})))}parseTransaction(){let e;this.matchTexts(this._constructor.TRANSACTION_KIND)&&(e=this.prev?.text),this.matchTexts(["TRANSACTION","WORK"]);let t=[];for(;;){let s=[];for(;this.match("var")||this.match("not");)s.push(this.prev?.text??"");if(0<s.length&&t.push(s.join(" ")),!this.match("comma"))break}return this.expression(hc,{this:e,modes:t})}parseStar(){return this.match("star")?this._constructor.PRIMARY_PARSERS.star?.call(this,this.prev):this.parsePlaceholder()}parseParameter(){let e=this.parseIdentifier()||this.parsePrimaryOrVar();return this.expression(Cl,{this:e})}parsePlaceholder(){if(this.matchSet(new Set(Object.keys(this._constructor.PLACEHOLDER_PARSERS)))){let e=this._constructor.PLACEHOLDER_PARSERS[this.prev?.tokenType??"unknown"]?.call(this);if(e)return e;this.advance(-1)}}parseStarOp(...e){if(!this.matchTexts(e))return;if(this.match("lParen",{advance:!1}))return this.parseWrappedCsv(()=>this.parseExpression());let t=this.parseAlias(this.parseDisjunction(),{explicit:!0});return t?[t]:void 0}parseCsv(e,t={}){let{sep:s="comma"}=t,r=e(),n=r!==void 0?[r]:[];for(;this.match(s);)this.addComments(r),r=e(),r!==void 0&&n.push(r);return n}parseIdentifier(){return this.match("identifier")?this.identifierExpression(void 0,{quoted:!0}):this.parsePlaceholder()}parseVar(e={}){let{anyToken:t=!1,tokens:s,upper:r=!1}=e;if(t&&this.advanceAny()||this.match("var")||s&&this.matchSet(s)){let n=r?(this.prev?.text??"").toUpperCase():this.prev?.text??"";return this.expression(qe,{this:n})}return this.parsePlaceholder()}advanceAny(e={}){let{ignoreReserved:t=!1}=e;if(this.curr&&(t||!this._constructor.RESERVED_TOKENS.has(this.curr.tokenType)))return this.advance(),this.prev}parseVarOrString(e={}){let{upper:t=!1}=e;return this.parseString()||this.parseVar({anyToken:!0,upper:t})}parsePrimaryOrVar(){return this.parsePrimary()||this.parseVar({anyToken:!0})}parseNull(){return this.matchSet(new Set(["null","unknown"]))?this._constructor.PRIMARY_PARSERS.null?.call(this,this.prev):this.parsePlaceholder()}parseBoolean(){return this.match("true")?this._constructor.PRIMARY_PARSERS.true?.call(this,this.prev):this.match("false")?this._constructor.PRIMARY_PARSERS.false?.call(this,this.prev):this.parsePlaceholder()}parseString(){return this.matchSet(new Set(Object.keys(this._constructor.STRING_PARSERS)))?this._constructor.STRING_PARSERS[this.prev?.tokenType??"unknown"]?.call(this,this.prev):this.parsePlaceholder()}parseStringAsIdentifier(){let e=(this.match("string")||void 0)&&this.prev?.text,t=e===void 0?void 0:Z(e,{quoted:!0});return t&&this.prev&&t.updatePositions(this.prev),t}parseNumber(){return this.matchSet(new Set(Object.keys(this._constructor.NUMERIC_PARSERS)))?this._constructor.NUMERIC_PARSERS[this.prev?.tokenType??"unknown"]?.call(this,this.prev):this.parsePlaceholder()}parseHavingMax(e){if(this.match("having")){this.matchTexts(["MAX","MIN"]);let t=this.prev?.text.toUpperCase()!=="MIN";return this.expression(qs,{this:e,expression:this.parseColumn(),max:t})}return e}parseWindow(e,t={}){let{alias:s=!1}=t,r=e,n=r instanceof A?r.comments:void 0;if(this.matchTextSeq(["WITHIN","GROUP"])){let f=this.parseWrapped(()=>this.parseOrder());e=this.expression($t,{this:e,expression:f})}if(this.matchPair("filter","lParen")&&(this.match("where"),e=this.expression(sr,{this:e,expression:this.parseWhere({skipWhereToken:!0})}),this.matchRParen()),e instanceof D){let f=e.find([aa,oa]);f&&f!==e&&(f.replace(f.args.this),e=this.expression(f._constructor,{this:e}))}e=this.parseRespectOrIgnoreNulls(e);let a;if(s)a=void 0,this.match("alias");else if(this.matchSet(this._constructor.WINDOW_BEFORE_PAREN_TOKENS))a=this.prev?.text.toUpperCase();else return e;if(n&&r instanceof A&&r.popComments(),!this.match("lParen"))return this.expression(we,{comments:n,this:e,alias:this.parseIdVar({anyToken:!1}),over:a});let o=this.parseIdVar({anyToken:!1,tokens:this._constructor.WINDOW_ALIAS_TOKENS}),c=this.match("first")||void 0;this.matchTextSeq("LAST")&&(c=!1);let[l,u]=this.parsePartitionAndOrder(),h=(this.matchSet(new Set(["rows","range"]))||void 0)&&this.prev?.text,d;if(h){this.match("between");let f=this.parseWindowSpec(),y=this.match("and")?this.parseWindowSpec():{},I=this.matchTextSeq("EXCLUDE")?this.parseVarFromOptions(this._constructor.WINDOW_EXCLUDE_OPTIONS):void 0;d=this.expression(lc,{kind:h,start:f.value,startSide:f.side,end:y.value,endSide:y.side,exclude:I})}else d=void 0;this.matchRParen();let x=this.expression(we,{comments:n,this:e,partitionBy:l,order:u,spec:d,alias:o,over:a,first:c});return this.matchSet(this._constructor.WINDOW_BEFORE_PAREN_TOKENS,{advance:!1})?this.parseWindow(x,{alias:s}):x}parsePartitionAndOrder(){return[this.parsePartitionBy(),this.parseOrder()]}parseWindowSpec(){return this.match("between"),{value:this.matchTextSeq("UNBOUNDED")&&"UNBOUNDED"||this.matchTextSeq(["CURRENT","ROW"])&&"CURRENT ROW"||this.parseBitwise()||void 0,side:(this.matchTexts(this._constructor.WINDOW_SIDES)||void 0)&&this.prev?.text}}parseAlias(e,t={}){let{explicit:s=!1}=t;if(this.canParseLimitOrOffset())return e;let r=this.match("alias"),n=this.prevComments??[];if(s&&!r)return e;if(this.match("lParen")){let o=this.expression(kr,{comments:n,this:e,expressions:this.parseCsv(()=>this.parseIdVar({anyToken:r}))});return this.matchRParen(o),o}let a=this.parseIdVar({anyToken:r,tokens:this._constructor.ALIAS_TOKENS})||this._constructor.STRING_ALIASES&&this.parseStringAsIdentifier();if(a){n.push(...a.popComments()),e=this.expression(Re,{comments:n,this:e,alias:a});let o=e.args.this;(!e.comments||e.comments.length===0)&&o&&o.comments&&0<o.comments.length&&(e.comments=o.popComments())}return e}parseOpenJson(){let e=this.parseBitwise(),t=(this.match("comma")||void 0)&&this.parseString(),s=()=>{let n=this.parseField({anyToken:!0}),a=this.parseTypes(),o=this.parseString(),c=this.matchPair("alias","json")||void 0;return this.expression(Mc,{this:n,kind:a,path:o,asJson:c})},r;return this.matchPair("rParen","with")&&(this.matchLParen(),r=this.parseCsv(s)),this.expression(rT,{this:e,path:t,expressions:r})}parsePosition(e={}){let{haystackFirst:t=!1}=e,s=this.parseCsv(()=>this.parseBitwise());if(this.match("in"))return this.expression(mr,{this:this.parseBitwise(),substr:M(s,0)});let r=t?M(s,0):M(s,1),n=t?M(s,1):M(s,0);return this.expression(mr,{this:r,substr:n,position:M(s,2)})}parseJoinHint(e){let t=this.parseCsv(()=>this.parseTable());return new ur({this:e.toUpperCase(),expressions:t})}parseSubstring(){let e=this.parseCsv(()=>this.parseBitwise()),t,s;for(;this.curr;)if(this.match("from"))t=this.parseBitwise();else if(this.match("for"))t||(t=R.number(1)),s=this.parseBitwise();else break;return t&&e.push(t),s&&e.push(s),this.validateExpression(er.fromArgList(e),e)}parseTrim(){let e,t,s;this.matchTexts(this._constructor.TRIM_TYPES)&&(e=this.prev?.text.toUpperCase());let r=this.parseBitwise();if(this.matchSet(new Set(["from","comma"]))){let n=this.prev?.tokenType==="from"||this._constructor.TRIM_PATTERN_FIRST;s=this.parseBitwise(),n&&([r,s]=[s,r])}return this.match("collate")&&(t=this.parseBitwise()),this.expression(cp,{this:r,position:e,expression:s,collation:t})}parseWindowClause(){return(this.match("window")||void 0)&&this.parseCsv(()=>this.parseNamedWindow())}parseNamedWindow(){return this.parseWindow(this.parseIdVar(),{alias:!0})}parseRespectOrIgnoreNulls(e){return this.matchTextSeq(["IGNORE","NULLS"])?this.expression(aa,{this:e}):this.matchTextSeq(["RESPECT","NULLS"])?this.expression(oa,{this:e}):e}parseJsonObject(e={}){let{agg:t=!1}=e,s=this.parseStar(),r=s?[s]:this.parseCsv(()=>this.parseFormatJson(this.parseJsonKeyValue())),n=this.parseOnHandling("NULL",["NULL","ABSENT"]),a;this.matchTextSeq(["WITH","UNIQUE"])?a=!0:this.matchTextSeq(["WITHOUT","UNIQUE"])&&(a=!1),this.matchTextSeq("KEYS");let o=(this.matchTextSeq("RETURNING")||void 0)&&this.parseFormatJson(this.parseType()),c=(this.matchTextSeq("ENCODING")||void 0)&&this.parseVar();return this.expression(t?gT:Gl,{expressions:r,nullHandling:n,uniqueKeys:a,returnType:o,encoding:c})}parseJsonColumnDef(){let e,t,s,r;this.matchTextSeq("NESTED")?(e=void 0,t=void 0,s=void 0,r=!0):(e=this.parseIdVar(),t=this.matchPair("for","ordinality")||void 0,s=this.parseTypes({allowIdentifiers:!1}),r=void 0);let n=(this.matchTextSeq("PATH")||void 0)&&this.parseString(),a=r&&this.parseJsonSchema();return this.expression(bc,{this:e,kind:s,path:n,nestedSchema:a,ordinality:t})}parseJsonSchema(){return this.matchTextSeq("COLUMNS"),this.expression(Lc,{expressions:this.parseWrappedCsv(()=>this.parseJsonColumnDef(),{optional:!0})})}parseJsonTable(){let e=this.parseFormatJson(this.parseBitwise());e||this.raiseError("Expected expression for JSON_TABLE");let t=(this.match("comma")||void 0)&&this.parseString(),s=this.parseOnHandling("ERROR",["ERROR","NULL"]),r=this.parseOnHandling("EMPTY",["ERROR","NULL"]),n=this.parseJsonSchema();return new sT({this:e,schema:n,path:t,errorHandling:s,emptyHandling:r})}parseMatchAgainst(){let e;if(this.matchTextSeq("TABLE")){e=[];let r=this.parseTable();r&&(e=[r])}else e=this.parseCsv(()=>this.parseColumn());this.matchTextSeq([")","AGAINST","("]);let t=this.parseString(),s;return this.matchTextSeq(["IN","NATURAL","LANGUAGE","MODE"])?(s="IN NATURAL LANGUAGE MODE",this.matchTextSeq(["WITH","QUERY","EXPANSION"])&&(s=`${s} WITH QUERY EXPANSION`)):this.matchTextSeq(["IN","BOOLEAN","MODE"])?s="IN BOOLEAN MODE":this.matchTextSeq(["WITH","QUERY","EXPANSION"])?s="WITH QUERY EXPANSION":s=void 0,this.expression(aT,{this:t,expressions:e,modifier:s})}parseJsonKeyValue(){this.matchTextSeq("KEY");let e=this.parseColumn();this.matchSet(this._constructor.JSON_KEY_VALUE_SEPARATOR_TOKENS),this.matchTextSeq("VALUE");let t=this.parseBitwise();if(!(!e&&!t))return this.expression(Pc,{this:e,expression:t})}parseFormatJson(e){return!e||!this.matchTextSeq(["FORMAT","JSON"])?e:this.expression(Cc,{this:e})}parseOnCondition(){let e,t;this._dialectConstructor.ON_CONDITION_EMPTY_BEFORE_ERROR?(e=this.parseOnHandling("EMPTY",[...this._constructor.ON_CONDITION_TOKENS]),t=this.parseOnHandling("ERROR",[...this._constructor.ON_CONDITION_TOKENS])):(t=this.parseOnHandling("ERROR",[...this._constructor.ON_CONDITION_TOKENS]),e=this.parseOnHandling("EMPTY",[...this._constructor.ON_CONDITION_TOKENS]));let s=this.parseOnHandling("NULL",[...this._constructor.ON_CONDITION_TOKENS]);if(!(!e&&!t&&!s))return this.expression(Go,{empty:e,error:t,null:s})}parseOnHandling(e,t){for(let r of t)if(this.matchTextSeq([r,"ON",e]))return`${r} ON ${e}`;let s=this.index;if(this.match("default")){let r=this.parseBitwise();if(this.matchTextSeq(["ON",e]))return r;this.retreat(s)}}parseConvert(e){let{safe:t,strict:s}=e,r=this.parseBitwise(),n;return this.match("using")?n=this.expression(ea,{this:this.parseVar({tokens:new Set(["binary"])})}):this.match("comma")?n=this.parseTypes():n=void 0,this.buildCast({strict:s,this:r,to:n,safe:t})}parseXmlElement(){let e,t;return this.matchTextSeq("EVALNAME")?(e=!0,t=this.parseBitwise()):(e=void 0,this.matchTextSeq("NAME"),t=this.parseIdVar()),this.expression(lT,{this:t,expressions:(this.match("comma")||void 0)&&this.parseCsv(()=>this.parseBitwise()),evalname:e})}parseXmlTable(){let e,t,s;this.matchTextSeq(["XMLNAMESPACES","("])&&(e=this.parseXmlNamespace(),this.match("rParen"),this.match("comma"));let r=this.parseString();this.matchTextSeq("PASSING")&&(this.matchTextSeq(["BY","VALUE"]),t=this.parseCsv(()=>this.parseColumn()));let n=this.matchTextSeq(["RETURNING","SEQUENCE","BY","REF"])||void 0;return this.matchTextSeq("COLUMNS")&&(s=this.parseCsv(()=>this.parseFieldDef())),this.expression(uT,{this:r,namespaces:e,passing:t,columns:s,byRef:n})}parseXmlNamespace(){let e=[];for(;;){let t;if(this.match("default")?t=this.parseString():t=this.parseAlias(this.parseString()),e.push(this.expression(Dc,{this:t})),!this.match("comma"))break}return e}parseDecode(){let e=this.parseCsv(()=>this.parseDisjunction());return e.length<3?this.expression(Zf,{this:M(e,0),charset:M(e,1)}):this.expression(Kf,{expressions:e})}parseGapFill(){this.match("table");let e=this.parseTable();this.match("comma");let t=[e,...this.parseCsv(()=>this.parseLambda())].filter(r=>r instanceof A),s=eT.fromArgList(t);return this.validateExpression(s,t)}parseChar(){return this.expression(ql,{expressions:this.parseCsv(()=>this.parseAssignment()),charset:(this.match("using")||void 0)&&this.parseVar()})}parseCast(e){let{safe:t,strict:s}=e,r=this.parseDisjunction();if(!this.match("alias")){if(this.match("comma"))return this.expression(Jf,{this:r,to:this.parseString()});this.raiseError("Expected AS after CAST")}let n,a=this.parseTypes(),o;if(this.match("default")&&(o=this.parseBitwise(),this.matchTextSeq(["ON","CONVERSION","ERROR"])),this.matchSet(new Set(["format","comma"]))){let c=this.parseString();if(n=this.parseAtTimeZone(c),a||(a=O.build("unknown")),a&&O.TEMPORAL_TYPES.has(a.args.this))return r=this.expression(a.args.this==="date"?ba:tr,{this:r,format:R.string(Ol(c?.args.this??"",Object.keys(this._dialectConstructor.FORMAT_MAPPING).length?this._dialectConstructor.FORMAT_MAPPING:this._dialectConstructor.TIME_MAPPING,Object.keys(this._dialectConstructor.FORMAT_MAPPING).length?this._dialectConstructor.FORMAT_TRIE:this._dialectConstructor.TIME_TRIE)??""),safe:t}),n instanceof Wt&&r instanceof tr&&r.setArgKey("zone",n.args.zone),r}else a?a instanceof U?a=O.build(a.name,{dialect:this.dialect,udt:!0}):a.args.this==="char"&&this.match("characterSet")&&(a=this.expression(ea,{this:this.parseVarOrString()})):this.raiseError("Expected TYPE after CAST");return this.buildCast({strict:s,this:r,to:a,format:n,safe:t,action:this.parseVarFromOptions(this._constructor.CAST_ACTIONS,{raiseUnmatched:!1}),default:o})}parseStringAgg(){let e;this.match("distinct")?(e=[this.expression(We,{expressions:[this.parseDisjunction()]})],this.match("comma")&&e.push(...this.parseCsv(()=>this.parseDisjunction()))):e=this.parseCsv(()=>this.parseDisjunction());let t;this.matchTextSeq(["ON","OVERFLOW"])?this.matchTextSeq("ERROR")?t=Q("ERROR"):(this.matchTextSeq("TRUNCATE"),t=this.expression(Ic,{this:this.parseString(),withCount:this.matchTextSeq(["WITH","COUNT"])||!this.matchTextSeq(["WITHOUT","COUNT"])})):t=void 0;let s=this.index;return!this.match("rParen")&&0<e.length?(e[0]=this.parseLimit(this.parseOrder({thisExpr:e[0]})),this.expression(Ui,{this:e[0],separator:M(e,1)})):this.matchTextSeq(["WITHIN","GROUP"])?(this.matchLParen(),this.expression(Ui,{this:this.parseOrder({thisExpr:M(e,0)}),separator:M(e,1),onOverflow:t})):(this.retreat(s),this.validateExpression(Ui.fromArgList(e.filter(r=>r instanceof A)),e))}parseBracket(e){if(!this.matchSet(new Set(["lBracket","lBrace"])))return e;let t;if(this._constructor.MAP_KEYS_ARE_ARBITRARY_EXPRESSIONS){let n=M(this.tokens,this.index-2);t=n!==void 0&&n.text.toUpperCase()==="MAP"}else t=!1;let s=this.prev?.tokenType;if(s==="lBrace"&&this.curr&&this.curr.tokenType==="var"&&this._constructor.ODBC_DATETIME_LITERALS[this.curr.text.toLowerCase()])return this.parseOdbcDatetimeLiteral();let r=this.parseCsv(()=>this.parseBracketKeyValue({isMap:s==="lBrace"}));if(s==="lBracket"&&!this.match("rBracket")?this.raiseError("Expected ]"):s==="lBrace"&&!this.match("rBrace")&&this.raiseError("Expected }"),s==="lBrace")e=this.expression(ks,{expressions:this.kvToPropEq(r,{parseMap:t})});else if(!e&&s)e=qD(ue,r,s,this.dialect);else if(e&&s){let n=this._constructor.ARRAY_CONSTRUCTORS[e?.name.toUpperCase()??""];if(n)return qD(n,r,s,this.dialect);let a=TN(e,r,-this._dialectConstructor.INDEX_OFFSET,{dialect:this.dialect});e=this.expression(Dt,{this:e,expressions:a,comments:e.popComments()})}return this.addComments(e),this.parseBracket(e)}parseSlice(e){if(!this.match("colon"))return e;let t;this.matchPair("dash","colon",{advance:!1})?(this.advance(),t=R.number("1").neg()):t=this.parseAssignment();let s=this.match("colon")?this.parseUnary():void 0;return this.expression(Tr,{this:e,expression:t,step:s})}parseCase(){if(this.match("dot",{advance:!1})){this.retreat(this.index-1);return}let e=[],t,s=this.prevComments,r=this.parseDisjunction();for(;this.match("when");){let n=this.parseDisjunction();this.match("then");let a=this.parseDisjunction();e.push(this.expression(le,{this:n,true:a}))}return this.match("else")&&(t=this.parseDisjunction()),this.match("end")||(t instanceof Ce&&(typeof t.args.this=="string"?t.args.this:t.args.this?.sql())?.toUpperCase()==="END"?t=ho({col:"interval"}):this.raiseError("Expected END after CASE",this.prev)),this.expression(nt,{comments:s,this:r,ifs:e,default:t})}parseIf(){if(this.match("lParen")){let e=this.parseCsv(()=>this.parseAlias(this.parseAssignment(),{explicit:!0})),t=this.validateExpression(le.fromArgList(e),e);return this.matchRParen(),t}else{let e=this.index-1;if(this._constructor.NO_PAREN_IF_COMMANDS&&e===0)return this.parseAsCommand(this.prev);let t=this.parseDisjunction();if(!t){this.retreat(e);return}this.match("then");let s=this.parseDisjunction(),r=this.match("else")?this.parseDisjunction():void 0;return this.match("end"),this.expression(le,{this:t,true:s,false:r})}}parseNextValueFor(){if(!this.matchTextSeq(["VALUE","FOR"])){this.retreat(this.index-1);return}return this.expression(hT,{this:this.parseColumn(),order:(this.match("over")||void 0)&&this.parseWrapped(()=>this.parseOrder())})}parseExtract(){let e=this.parseFunction()||this.parseVarOrString({upper:!0});return this.match("from")?this.expression(Gi,{this:e,expression:this.parseBitwise()}):(this.match("comma")||this.raiseError("Expected FROM or comma after EXTRACT",this.prev),this.expression(Gi,{this:e,expression:this.parseBitwise()}))}parsePrimaryKeyPart(){return this.parseField()}parsePeriodForSystemTime(){if(!this.match("timestampSnapshot")){this.retreat(this.index-1);return}let e=this.parseWrappedIdVars();return this.expression(qc,{this:M(e,0),expression:M(e,1)})}parsePrimaryKey(e={}){let{wrappedOptional:t=!1,inProps:s=!1,namedPrimaryKey:r=!1}=e,n=this.matchSet(new Set(["asc","desc"]))?this.prev?.tokenType==="desc":void 0,a;if(r&&!((this.curr?.text.toUpperCase()||"")in this._constructor.CONSTRAINT_PARSERS)&&this.next&&this.next.tokenType==="lParen"&&(a=this.parseIdVar()),!s&&!this.match("lParen",{advance:!1}))return this.expression(Xc,{desc:n,options:this.parseKeyConstraintOptions()});let o=this.parseWrappedCsv(()=>this.parsePrimaryKeyPart(),{optional:t});return this.expression(zi,{this:a,expressions:o,include:this.parseIndexParams(),options:this.parseKeyConstraintOptions()})}parseBracketKeyValue(e={}){return this.parseSlice(this.parseAlias(this.parseDisjunction(),{explicit:!0}))}parseOdbcDatetimeLiteral(){this.match("var");let e=this._constructor.ODBC_DATETIME_LITERALS[this.prev?.text??"".toLowerCase()],t=this.expression(e,{this:this.parseString()});return this.match("rBrace")||this.raiseError("Expected }"),t}parseUniqueKey(){return this.parseIdVar({anyToken:!1})}parseUnique(){return this.matchTexts(["KEY","INDEX"]),this.expression(ln,{nulls:this.matchTextSeq(["NULLS","NOT","DISTINCT"])||void 0,this:this.parseSchema({this:this.parseUniqueKey()}),indexType:(this.match("using")||void 0)&&this.advanceAny()&&this.prev?.text,onConflict:this.parseOnConflict(),options:this.parseKeyConstraintOptions()})}parseKeyConstraintOptions(){let e=[];for(;this.curr;)if(this.match("on")){let t,s=this.advanceAny()&&this.prev?.text;this.matchTextSeq(["NO","ACTION"])?t="NO ACTION":this.matchTextSeq("CASCADE")?t="CASCADE":this.matchTextSeq("RESTRICT")?t="RESTRICT":this.matchPair("set","null")?t="SET NULL":this.matchPair("set","default")?t="SET DEFAULT":this.raiseError("Invalid key constraint"),e.push(`ON ${s} ${t}`)}else{let t=this.parseVarFromOptions(this._constructor.KEY_CONSTRAINT_OPTIONS,{raiseUnmatched:!1});if(!t)break;e.push(t.name)}return e}parseReferences(e={}){let{match:t=!0}=e;if(t&&!this.match("references"))return;let s,r=this.parseTable({schema:!0}),n=this.parseKeyConstraintOptions();return this.expression(ic,{this:r,expressions:s,options:n})}parseForeignKey(){let e=this.match("references",{advance:!1})?void 0:this.parseWrappedIdVars(),t=this.parseReferences(),s={};for(;this.match("on");){this.matchSet(new Set(["delete","update"]))||this.raiseError("Expected DELETE or UPDATE");let r=(this.prev?.text??"").toLowerCase(),n;this.matchTextSeq(["NO","ACTION"])?n="NO ACTION":this.match("set")?(this.matchSet(new Set(["null","default"])),n="SET "+(this.prev?.text??"").toUpperCase()):(this.advance(),n=(this.prev?.text??"").toUpperCase()),s[r]=n}return this.expression(qo,{expressions:e,reference:t,options:this.parseKeyConstraintOptions(),...s})}parsePrimary(){if(this.matchSet(Object.keys(this._constructor.PRIMARY_PARSERS))){let e=this.prev?.tokenType??"unknown",t=this._constructor.PRIMARY_PARSERS[e]?.call(this,this.prev);if(e==="string"){let s=[t];for(;this.match("string");)s.push(R.string(this.prev?.text??""));if(1<s.length)return this.expression(Gt,{expressions:s,coalesce:this._dialectConstructor.CONCAT_COALESCE})}return t}return this.matchPair("dot","number")?R.number(`0.${this.prev?.text??""}`):this.parseParen()}parseField(e={}){let{anyToken:t=!1,tokens:s,anonymousFunc:r=!1}=e||{},n;return r?n=this.parseFunction({anonymous:r,anyToken:t})||this.parsePrimary():n=this.parsePrimary()||this.parseFunction({anonymous:r,anyToken:t}),n||this.parseIdVar({anyToken:t,tokens:s})}parseGeneratedAsIdentity(){let e;if(this.matchTextSeq(["BY","DEFAULT"])){let s=this.matchPair("on","null")||void 0;e=this.expression(Zn,{this:!1,onNull:s})}else this.matchTextSeq("ALWAYS"),e=this.expression(Zn,{this:!0});if(this.match("alias"),this.matchTextSeq("ROW")){let s=this.matchTextSeq("START")||void 0;s||this.match("end");let r=this.matchTextSeq("HIDDEN")||void 0;return this.expression(Hc,{start:s,hidden:r})}let t=this.matchTextSeq("IDENTITY")||void 0;if(this.match("lParen")){if(this.match("startWith")&&e.setArgKey("start",this.parseBitwise()),this.matchTextSeq(["INCREMENT","BY"])&&e.setArgKey("increment",this.parseBitwise()),this.matchTextSeq("MINVALUE")&&e.setArgKey("minvalue",this.parseBitwise()),this.matchTextSeq("MAXVALUE")&&e.setArgKey("maxvalue",this.parseBitwise()),this.matchTextSeq("CYCLE")?e.setArgKey("cycle",!0):this.matchTextSeq(["NO","CYCLE"])&&e.setArgKey("cycle",!1),!t)e.setArgKey("expression",this.parseRange());else if(!e.args.start&&this.match("number",{advance:!1})){let s=this.parseCsv(this.parseBitwise.bind(this));e.setArgKey("start",M(s,0)),e.setArgKey("increment",M(s,1))}this.matchRParen()}return e}parseInline(){return this.matchTextSeq("LENGTH"),this.expression(Wc,{this:this.parseBitwise()})}parseNotConstraint(){if(this.matchTextSeq("NULL"))return this.expression(la);if(this.matchTextSeq("CASESPECIFIC"))return this.expression(Pr,{not:!0});if(this.matchTextSeq(["FOR","REPLICATION"]))return this.expression(pn);this.retreat(this.index-1)}parseColumnConstraint(){let e=(this.match("constraint")||void 0)&&this.parseIdVar();if(!((this.match("with",{advance:!1})||void 0)&&this.next&&this.next.text.toUpperCase()in this._constructor.PROCEDURE_OPTIONS)&&this.matchTexts(Object.keys(this._constructor.CONSTRAINT_PARSERS))){let s=this._constructor.CONSTRAINT_PARSERS[(this.prev?.text??"").toUpperCase()]?.call(this);if(!s){this.retreat(this.index-1);return}return this.expression(Or,{this:e,kind:s})}return e}parseConstraint(){return this.match("constraint")?this.expression(Lo,{this:this.parseIdVar(),expressions:this.parseUnnamedConstraints()}):this.parseUnnamedConstraint({constraints:this._constructor.SCHEMA_UNNAMED_CONSTRAINTS})}parseUnnamedConstraints(){let e=[];for(;;){let t=this.parseUnnamedConstraint()||this.parseFunction();if(!t)break;e.push(t)}return e}parseUnnamedConstraint(e={}){let t=this.index,{constraints:s}=e;if(this.match("identifier",{advance:!1})||!this.matchTexts(s||Object.keys(this._constructor.CONSTRAINT_PARSERS)))return;let r=(this.prev?.text??"").toUpperCase();r in this._constructor.CONSTRAINT_PARSERS||this.raiseError(`No parser found for schema constraint ${r}.`);let n=this._constructor.CONSTRAINT_PARSERS[r]?.call(this);if(!n||Array.isArray(n)){this.retreat(t);return}return n}parseFieldDef(){return this.parseColumnDef(this.parseField({anyToken:!0}))}parseColumnDef(e,t={}){let{computedColumn:s=!0}=t,r=e;r instanceof B&&(r=r.args.this),s||this.match("alias");let n=this.parseTypes({schema:!0});if(this.matchTextSeq(["FOR","ORDINALITY"]))return this.expression(Ie,{this:r,ordinality:!0});let a=[];if(!n&&this.match("alias")||this.matchTexts(["ALIAS","MATERIALIZED"])){let o=(this.prev?.text??"").toUpperCase()==="MATERIALIZED",c=new Fi({this:this.parseDisjunction(),persisted:o||this.matchTextSeq("PERSISTED")||void 0,dataType:this.matchTextSeq("AUTO")?new O({this:"AUTO"}):this.parseTypes(),notNull:this.matchPair("not","null")||void 0});a.push(this.expression(Or,{kind:c}))}else if(!n&&this.matchSet(["in","out"],{advance:!1})){let o=this.expression(Zc,{input:this.match("in")||void 0,output:this.match("out")||void 0});a.push(o),n=this.parseTypes()}else n&&this.match("alias",{advance:!1})&&(!this._constructor.WRAPPED_TRANSFORM_COLUMN_CONSTRAINT||this.next&&this.next.tokenType==="lParen")&&(this.advance(),a.push(this.expression(Or,{kind:new Fi({this:this.parseDisjunction(),persisted:(this.matchTexts(["STORED","VIRTUAL"])||void 0)&&(this.prev?.text??"").toUpperCase()==="STORED"})})));for(;;){let o=this.parseColumnConstraint();if(!o)break;a.push(o)}return!n&&a.length===0?r:this.expression(Ie,{this:r,kind:n,constraints:a})}parseAutoIncrement(){let e,t,s;if(this.match("lParen",{advance:!1})){let r=this.parseWrappedCsv(this.parseBitwise.bind(this));e=M(r,0),t=M(r,1)}else this.matchTextSeq("START")&&(e=this.parseBitwise(),this.matchTextSeq("INCREMENT"),t=this.parseBitwise(),this.matchTextSeq("ORDER")?s=!0:this.matchTextSeq("NOORDER")&&(s=!1));return e&&t?new Zn({start:e,increment:t,this:!1,order:s}):new bA({})}parseCheckConstraint(){if(this.match("lParen",{advance:!1}))return this.expression(yl,{this:this.parseWrapped(this.parseAssignment.bind(this)),enforced:this.matchTextSeq("ENFORCED")||void 0})}parseAutoProperty(){if(!this.matchTextSeq("REFRESH")){this.retreat(this.index-1);return}return this.expression(vr,{this:this.parseVar({upper:!0})})}parseCompress(){return this.match("lParen",{advance:!1})?this.expression(oo,{this:this.parseWrappedCsv(this.parseBitwise.bind(this))}):this.expression(oo,{this:this.parseBitwise()})}parseFunction(e={}){let{functions:t,anonymous:s=!1,optionalParens:r=!0,anyToken:n=!1}=e,a=!1;this.match("lBrace",{advance:!1})&&this.next&&this.next.text.toUpperCase()==="FN"&&(this.advance(2),a=!0);let o=this.parseFunctionCall({functions:t,anonymous:s,optionalParens:r,anyToken:n});return a&&this.match("rBrace"),o}parseFunctionArgs(e={}){let{alias:t=!1}=e;return this.parseCsv(()=>this.parseLambda({alias:t}))}parseFunctionCall(e={}){let{functions:t,anonymous:s=!1,optionalParens:r=!0,anyToken:n=!1}=e;if(!this.curr)return;let a=this.curr.comments,o=this.prev,c=this.curr,l=this.curr.tokenType,u=this.curr.text,h=u.toUpperCase(),d=this._constructor.NO_PAREN_FUNCTION_PARSERS[h];if(d&&r&&!this._constructor.INVALID_FUNC_NAME_TOKENS.has(l))return this.advance(),this.parseWindow(d.call(this));if(!this.next||this.next.tokenType!=="lParen"){let f=this._constructor.NO_PAREN_FUNCTIONS[l];return r&&f?(this.advance(),this.expression(f)):void 0}if(n){if(this._constructor.RESERVED_TOKENS.has(l))return}else if(!this._constructor.FUNC_TOKENS.has(l))return;this.advance(2);let x=this._constructor.FUNCTION_PARSERS[h];if(x&&!s){let f=x.call(this);return f instanceof A&&f.addComments(a),this.matchRParen(f),this.parseWindow(f)}else{let f=this._constructor.SUBQUERY_PREDICATES[l];if(f){let Y;if(this.curr.tokenType==="select"||this.curr.tokenType==="with"?(Y=this.parseSelect(),this.matchRParen()):o&&(o.tokenType==="like"||o.tokenType==="ilike")&&(this.advance(-1),Y=this.parseBitwise()),Y)return this.expression(f,{comments:a,this:Y})}let I=(t??this._constructor.FUNCTIONS)[h],N=I&&!s,P=!N||this._constructor.FUNCTIONS_WITH_ALIASED_ARGS.has(h),k=this.parseFunctionArgs({alias:P}),_=this.curr?.comments,W=N;W&&_&&_.some(Y=>Y.trimStart().startsWith(qI))&&(W=!1);let he=P&&W?this.kvToPropEq(k):k,ne;if(W){let Y;1<I.length?Y=I(he,{dialect:this.dialect}):Y=I(he),Y=this.validateExpression(Y,he),this._dialectConstructor.PRESERVE_ORIGINAL_NAMES&&(Y.meta.name=u),ne=Y}else{let Y=u;l==="identifier"&&(Y=new U({this:u,quoted:!0}).updatePositions(c)),ne=this.expression(je,{this:Y,expressions:k})}return ne=ne.updatePositions(c),ne instanceof A&&ne.addComments(a),this.matchRParen(ne),this.parseWindow(ne)}}toPropEq(e,t){return e}kvToPropEq(e,t={}){let{parseMap:s=!1}=t,r=[];for(let n=0;n<e.length;n++){let a=e[n];if([...this._constructor.KEY_VALUE_DEFINITIONS.keys()].some(o=>a instanceof o)){if(a instanceof Re&&(a=this.expression(ct,{this:a.args.alias,expression:a.args.this})),!(a instanceof ct)){let o=a.args.this;a=this.expression(ct,{this:s?a.args.this:Z(o instanceof A?o.name:o?.toString()),expression:a.args.expression})}a.args.this instanceof B&&a.args.this.replace(a.args.this.args.this)}else a=this.toPropEq(a,n);r.push(a)}return r}parseUserDefinedFunctionExpression(){return this.parseStatement()}parseFunctionParameter(){return this.parseColumnDef(this.parseIdVar(),{computedColumn:!1})}parseUserDefinedFunction(e={}){let t=this.parseTableParts({schema:!0});if(!this.match("lParen"))return t;let s=this.parseCsv(this.parseFunctionParameter.bind(this));return this.matchRParen(),this.expression(No,{this:t,expressions:s,wrapped:!0})}parseIntroducer(e){let t=this.parsePrimary();return t?this.expression(Yo,{token:e,expression:t}):this.identifierExpression(e)}parseSessionParameter(){let e,t=this.parseIdVar()||this.parsePrimary();return t&&this.match("dot")&&(e=t.name,t=this.parseVar()||this.parsePrimary()),this.expression(Pl,{this:t,kind:e})}parseLambdaArg(){return this.parseIdVar()}parseLambda(e={}){let{alias:t=!1}=e,s=this.index,r;if(this.match("lParen")?(r=this.parseCsv(this.parseLambdaArg.bind(this)),this.match("rParen")||this.retreat(s)):r=[this.parseLambdaArg()],this.matchSet(Object.keys(this._constructor.LAMBDAS))){let a=this.prev?.tokenType;return a&&this._constructor.LAMBDAS[a]?.call(this,r.filter(o=>!!o))}this.retreat(s);let n;return this.match("distinct")?n=this.expression(We,{expressions:this.parseCsv(this.parseDisjunction.bind(this))}):n=this.parseSelectOrExpression({alias:t}),this.parseLimit(this.parseOrder({thisExpr:this.parseHavingMax(this.parseRespectOrIgnoreNulls(n))}))}parseSchema(e={}){let{this:t}=e,s=this.index;if(!this.match("lParen"))return t;if(this.matchSet(this._constructor.SELECT_START_TOKENS))return this.retreat(s),t;let r=this.parseCsv(()=>this.parseConstraint()||this.parseFieldDef());return this.matchRParen(),this.expression(At,{this:t,expressions:r})}parseAlterTableSet(){let e=this.expression(Co);if(this.match("lParen",{advance:!1})||this.matchTextSeq(["TABLE","PROPERTIES"]))e.setArgKey("expressions",this.parseWrappedCsv(this.parseAssignment.bind(this)));else if(this.matchTextSeq("FILESTREAM_ON",{advance:!1}))e.setArgKey("expressions",[this.parseAssignment()]);else if(this.matchTexts(["LOGGED","UNLOGGED"]))e.setArgKey("option",Q((this.prev?.text??"").toUpperCase()));else if(this.matchTextSeq("WITHOUT")&&this.matchTexts(["CLUSTER","OIDS"]))e.setArgKey("option",Q(`WITHOUT ${(this.prev?.text??"").toUpperCase()}`));else if(this.matchTextSeq("LOCATION"))e.setArgKey("location",this.parseField());else if(this.matchTextSeq(["ACCESS","METHOD"]))e.setArgKey("accessMethod",this.parseField());else if(this.matchTextSeq("TABLESPACE"))e.setArgKey("tablespace",this.parseField());else if(this.matchTextSeq(["FILE","FORMAT"])||this.matchTextSeq("FILEFORMAT"))e.setArgKey("fileFormat",[this.parseField()]);else if(this.matchTextSeq("STAGE_FILE_FORMAT"))e.setArgKey("fileFormat",this.parseWrappedOptions());else if(this.matchTextSeq("STAGE_COPY_OPTIONS"))e.setArgKey("copyOptions",this.parseWrappedOptions());else if(this.matchTextSeq("TAG")||this.matchTextSeq("TAGS"))e.setArgKey("tag",this.parseCsv(this.parseAssignment.bind(this)));else{this.matchTextSeq("SERDE")&&e.setArgKey("serde",this.parseField());let t=this.parseWrapped(this.parseProperties.bind(this),{optional:!0});e.setArgKey("expressions",t?[t]:[])}return e}parseAlterSession(){if(this.match("set")){let t=this.parseCsv(()=>this.parseSetItemAssignment());return this.expression(ia,{expressions:t,unset:!1})}this.matchTextSeq("UNSET");let e=this.parseCsv(()=>this.expression(vi,{this:this.parseIdVar({anyToken:!0})}));return this.expression(ia,{expressions:e,unset:!0})}parseAlter(){let e=this.prev,t=(this.matchSet(this._constructor.ALTERABLES)||void 0)&&this.prev;if(!t)return this.parseAsCommand(e);let s=this.parseExists(),r=this.matchTextSeq("ONLY")||void 0,n,a,o;t.tokenType==="session"?(n=void 0,a=void 0,o=void 0):(n=this.parseTable({schema:!0,parsePartition:this._constructor.ALTER_TABLE_PARTITIONS}),a=this.matchTextSeq(["WITH","CHECK"])||void 0,o=this.match("on")?this.parseOnProperty():void 0,this.next&&this.advance());let c=this.prev?this._constructor.ALTER_PARSERS[this.prev.text.toUpperCase()]:void 0;if(c){let l=J(c.call(this)),u=this.matchTextSeq(["NOT","VALID"])||void 0,h=this.parseCsv(this.parseProperty.bind(this)),d=this._dialectConstructor.ALTER_TABLE_SUPPORTS_CASCADE&&this.matchTextSeq("CASCADE");if(!this.curr&&l)return this.expression(sn,{this:n,kind:ut(bf,t.text)??t.text.toUpperCase(),exists:s,actions:l,only:r,options:h,cluster:o,notValid:u,check:a,cascade:d})}return this.parseAsCommand(e)}parseAnalyze(){let e=this.prev;if(!this.curr)return this.expression(na);let t=[];for(;this.matchTexts(this._constructor.ANALYZE_STYLES);)(this.prev?.text??"").toUpperCase()==="BUFFER_USAGE_LIMIT"?t.push(`BUFFER_USAGE_LIMIT ${this.parseNumber()}`):t.push((this.prev?.text??"").toUpperCase());let s,r,n=this.curr?.text.toUpperCase();this.match("table")||this.match("index")?s=this.parseTableParts():this.matchTextSeq("TABLES")?this.matchSet(["from","in"])&&(n=`${n} ${(this.prev?.text??"").toUpperCase()}`,s=this.parseTable({schema:!0,isDbReference:!0})):this.matchTextSeq("DATABASE")?s=this.parseTable({schema:!0,isDbReference:!0}):this.matchTextSeq("CLUSTER")?s=this.parseTable():this.matchTexts(Object.keys(this._constructor.ANALYZE_EXPRESSION_PARSERS))?(n=void 0,r=this._constructor.ANALYZE_EXPRESSION_PARSERS[(this.prev?.text??"").toUpperCase()].call(this)):(n=void 0,s=this.parseTableParts());let a=this.tryParse(this.parsePartition.bind(this));if(!a&&this.matchTexts(this._constructor.PARTITION_KEYWORDS))return this.parseAsCommand(e);let o;this.matchTextSeq(["WITH","SYNC","MODE"])||this.matchTextSeq(["WITH","ASYNC","MODE"])?o=`WITH ${this.tokens[this.index-2].text.toUpperCase()} MODE`:o=void 0,this.matchTexts(Object.keys(this._constructor.ANALYZE_EXPRESSION_PARSERS))&&(r=this._constructor.ANALYZE_EXPRESSION_PARSERS[(this.prev?.text??"").toUpperCase()].call(this));let c=this.parseProperties();return this.expression(na,{kind:n,this:s,mode:o,partition:a,properties:c,expression:r,options:t})}parseAnalyzeStatistics(){let e,t=(this.prev?.text??"").toUpperCase(),s=this.matchTextSeq("DELTA")?(this.prev?.text??"").toUpperCase():void 0,r=[];if(this.matchTextSeq("STATISTICS")||this.raiseError("Expecting token STATISTICS"),this.matchTextSeq("NOSCAN"))e="NOSCAN";else if(this.match("for"))this.matchTextSeq(["ALL","COLUMNS"])&&(e="FOR ALL COLUMNS"),this.matchTexts("COLUMNS")&&(e="FOR COLUMNS",r=this.parseCsv(this.parseColumnReference.bind(this)));else if(this.matchTextSeq("SAMPLE")){let n=this.parseNumber();r=[this.expression(xc,{sample:n,kind:this.match("percent")?(this.prev?.text??"").toUpperCase():void 0})]}return this.expression(Ac,{kind:t,option:s,this:e,expressions:r})}parseAnalyzeValidate(){let e,t,s;return this.matchTextSeq(["REF","UPDATE"])?(e="REF",t="UPDATE",this.matchTextSeq(["SET","DANGLING","TO","NULL"])&&(t="UPDATE SET DANGLING TO NULL")):this.matchTextSeq("STRUCTURE")&&(e="STRUCTURE",this.matchTextSeq(["CASCADE","FAST"])?t="CASCADE FAST":this.matchTextSeq(["CASCADE","COMPLETE"])&&this.matchTexts(["ONLINE","OFFLINE"])&&(t=`CASCADE COMPLETE ${(this.prev?.text??"").toUpperCase()}`,s=this.parseInto())),this.expression(Sc,{kind:e,this:t,expression:s})}parseAnalyzeColumns(){let e=(this.prev?.text??"").toUpperCase();if(this.matchTextSeq("COLUMNS"))return this.expression(nn,{this:`${e} ${(this.prev?.text??"").toUpperCase()}`})}parseAnalyzeDelete(){let e=this.matchTextSeq("SYSTEM")?(this.prev?.text??"").toUpperCase():void 0;if(this.matchTextSeq("STATISTICS"))return this.expression(Tc,{kind:e})}parseAnalyzeList(){if(this.matchTextSeq(["CHAINED","ROWS"]))return this.expression(fc,{expression:this.parseInto()})}parseAnalyzeHistogram(){let e=(this.prev?.text??"").toUpperCase(),t,s=[],r;if(this.matchTextSeq(["HISTOGRAM","ON"])){s=this.parseCsv(this.parseColumnReference.bind(this));let n=[];for(;this.match("with");)if(this.matchTexts(["SYNC","ASYNC"]))this.matchTextSeq("MODE",{advance:!1})&&(n.push(`${(this.prev?.text??"").toUpperCase()} MODE`),this.advance());else{let a=this.parseNumber();this.matchTextSeq("BUCKETS")&&n.push(`${a} BUCKETS`)}0<n.length&&(t=this.expression(rn,{expressions:n})),this.matchTexts(["MANUAL","AUTO"])&&this.match("update",{advance:!1})?(r=(this.prev?.text??"").toUpperCase(),this.advance()):this.matchTextSeq(["USING","DATA"])&&(t=this.expression(an,{this:this.parseString()}))}return this.expression(dc,{this:e,expressions:s,expression:t,updateOptions:r})}parseMerge(){this.match("into");let e=this.parseTable();e&&this.match("alias",{advance:!1})&&e.setArgKey("alias",this.parseTableAlias()),this.match("using");let t=this.parseTable();return this.expression(fa,{this:e,using:t,on:(this.match("on")||void 0)&&this.parseDisjunction(),usingCond:(this.match("using")||void 0)&&this.parseUsingIdentifiers(),whens:this.parseWhenMatched(),returning:this.parseReturning()})}parseWhenMatched(){let e=[];for(;this.match("when");){let t=!this.match("not");this.matchTextSeq("MATCHED");let s=this.matchTextSeq(["BY","TARGET"])?!1:this.matchTextSeq(["BY","SOURCE"]),r=this.match("and")?this.parseDisjunction():void 0;this.match("then");let n;if(this.match("insert")){let a=this.parseStar();a?n=this.expression(kt,{this:a}):n=this.expression(kt,{this:this.matchTextSeq("ROW")?Q("ROW"):this.parseValue({values:!1}),expression:this.matchTextSeq("VALUES")&&this.parseValue()})}else if(this.match("update")){let a=this.parseStar();a?n=this.expression(Vt,{expressions:a}):n=this.expression(Vt,{expressions:this.match("set")&&this.parseCsv(this.parseEquality.bind(this))})}else this.match("delete")?n=this.expression(qe,{this:this.prev?.text??""}):n=this.parseVarFromOptions(this._constructor.CONFLICT_ACTIONS);e.push(this.expression(_r,{matched:t,source:s,condition:r,then:n}))}return this.expression(cn,{expressions:e})}parseShow(){let e=this.findParser(this._constructor.SHOW_PARSERS,this._constructor.SHOW_TRIE);return e?e.call(this):this.parseAsCommand(this.prev)}parseSetItemAssignment(e={}){let{kind:t}=e,s=this.index;if((t==="GLOBAL"||t==="SESSION")&&this.matchTextSeq("TRANSACTION"))return this.parseSetTransaction({global:t==="GLOBAL"});let r=this.parsePrimary()||this.parseColumn(),n=this.matchTexts(this._constructor.SET_ASSIGNMENT_DELIMITERS)||void 0;if(!r||this._constructor.SET_REQUIRES_ASSIGNMENT_DELIMITER&&!n){this.retreat(s);return}let a=this.parseStatement()||this.parseIdVar();(a instanceof B||a instanceof U)&&(a=Q(a.name));let o=this.expression(me,{this:r,expression:a});return this.expression(vi,{this:o,kind:t})}parseSetTransaction(e={}){let{global:t=!1}=e;this.matchTextSeq("TRANSACTION");let s=this.parseCsv(()=>this.parseVarFromOptions(this._constructor.TRANSACTION_CHARACTERISTICS));return this.expression(vi,{expressions:s,kind:"TRANSACTION",global:t})}parseSetItem(){let e=this.findParser(this._constructor.SET_PARSERS,this._constructor.SET_TRIE);return e?e.call(this):this.parseSetItemAssignment({kind:void 0})}parseSet(e={}){let{unset:t=!1,tag:s=!1}=e,r=this.index,n=this.expression(Hi,{expressions:this.parseCsv(this.parseSetItem.bind(this)),unset:t,tag:s});return this.curr?(this.retreat(r),this.parseAsCommand(this.prev)):n}parseVarFromOptions(e,t={}){let{raiseUnmatched:s=!0}=t,r=this.curr;if(!r)return;let n=r.text.toUpperCase(),a=e[n],o=this.index;this.advance();let c=!1;for(let l of a||[]){let u=typeof l=="string"?[l]:l;if(this.matchTextSeq(u)){n=`${n} ${u.join(" ")}`,c=!0;break}}if(!c&&(a===void 0||0<a.length)){s&&this.raiseError(`Unknown option ${n}`),this.retreat(o);return}return Q(n)}parseCache(){let e=this.matchTextSeq("LAZY")||void 0;this.match("table");let t=this.parseTable({schema:!0}),s=[];if(this.matchTextSeq("OPTIONS")){this.matchLParen();let r=this.parseString();r||this.raiseError("Expected option key"),this.match("eq");let n=this.parseString();n||this.raiseError("Expected option value"),s=[r,n].filter(Boolean),this.matchRParen()}return this.match("alias"),this.expression(go,{this:t,lazy:e,options:s,expression:this.parseSelect({nested:!0})})}parsePartition(){if(this.matchTexts(this._constructor.PARTITION_KEYWORDS))return this.expression(Wo,{subpartition:(this.prev?.text??"").toUpperCase()==="SUBPARTITION",expressions:this.parseWrappedCsv(this.parseDisjunction.bind(this))})}parseValue(e){let t=()=>this._dialectConstructor.SUPPORTS_VALUES_DEFAULT&&this.match("default")?Q((this.prev?.text??"").toUpperCase()):this.parseExpression();if(this.match("lParen")){let r=this.parseCsv(t);return this.matchRParen(),this.expression(Ge,{expressions:r})}let s=this.parseExpression();if(s)return this.expression(Ge,{expressions:[s]})}parseProjections(){return this.parseExpressions()}parseWrappedSelect(e={}){let{table:t=!1}=e,s;if(this.matchSet(["pivot","unpivot"]))s=this.parseSimplifiedPivot({isUnpivot:this.prev?.tokenType==="unpivot"});else if(this.match("from")){let r=this.parseFrom({skipFromToken:!0,consumePipe:!0}),n=this.parseSelect({from:r});n?(n.args.from||n.setArgKey("from",r),s=n):(s=pt("*").from(r),s=this.parseQueryModifiers(this.parseSetOperations(s)))}else{if(s=t?this.parseTable({consumePipe:!0}):this.parseSelect({nested:!0,parseSetOperation:!1}),t&&s instanceof Ls&&s.alias){let r=s.args.alias?.pop();s=new V({this:s,alias:r})}s=this.parseQueryModifiers(this.parseSetOperations(s))}return s}parseCommitOrRollback(){let e,t,s=this.prev?.tokenType==="rollback";return this.matchTexts(["TRANSACTION","WORK"]),this.matchTextSeq("TO")&&(this.matchTextSeq("SAVEPOINT"),t=this.parseIdVar()),this.match("and")&&(e=!this.matchTextSeq("NO"),this.matchTextSeq("CHAIN")),s?this.expression(Ec,{savepoint:t}):this.expression(gc,{chain:e})}parseRefresh(){let e;this.match("table")?e="TABLE":this.matchTextSeq(["MATERIALIZED","VIEW"])?e="MATERIALIZED VIEW":e="";let t=this.parseString()||this.parseTable();return!e&&!(t instanceof R)?this.parseAsCommand(this.prev):this.expression(Ao,{this:t,kind:e})}parseColumnDefWithExists(){let e=this.index;this.match("column");let t=this.parseExists({not:!0}),s=this.parseFieldDef();if(!(s instanceof Ie)){this.retreat(e);return}return s.setArgKey("exists",t),s}parseAddColumn(){if((this.prev?.text??"").toUpperCase()!=="ADD")return;let e=this.parseColumnDefWithExists();if(e){if(this.matchTexts(["FIRST","AFTER"])){let t=this.prev?.text??"",s=this.expression(yo,{this:this.parseColumn(),position:t});e.setArgKey("position",s)}return e}}parseDropColumn(){let e=(this.match("drop")||void 0)&&this.parseDrop();return e&&!(e instanceof Ws)&&e.setArgKey("kind",e.args.kind||"COLUMN"),e}parseDropPartition(e={}){let{exists:t}=e;return this.expression(Rc,{expressions:this.parseCsv(this.parsePartition.bind(this)),exists:t})}parseAlterTableAdd(){let e=()=>{if(this.matchTextSeq("ADD"),this.matchSet(this._constructor.ADD_CONSTRAINT_TOKENS,{advance:!1}))return this.expression(mc,{expressions:this.parseCsv(this.parseConstraint.bind(this))});let t=this.parseAddColumn();if(t instanceof Ie)return t;let s=this.parseExists({not:!0});if(this.matchPair("partition","lParen",{advance:!1}))return this.expression(Oc,{exists:s,this:this.parseField({anyToken:!0}),location:this.matchTextSeq("LOCATION",{advance:!1})&&this.parseProperty()})};if(!this.matchSet(this._constructor.ADD_CONSTRAINT_TOKENS,{advance:!1})&&(!this._dialectConstructor.ALTER_TABLE_ADD_REQUIRED_FOR_EACH_COLUMN||this.matchTextSeq("COLUMNS"))){let t=this.parseSchema();return t?Array.from(J(t)):this.parseCsv(this.parseColumnDefWithExists.bind(this))}return this.parseCsv(e)}parseAlterTableAlter(){if(this.matchTexts(Object.keys(this._constructor.ALTER_ALTER_PARSERS)))return this._constructor.ALTER_ALTER_PARSERS[(this.prev?.text??"").toUpperCase()]?.call(this);this.match("column");let e=this.parseField({anyToken:!0});return this.matchPair("drop","default")?this.expression(as,{this:e,drop:!0}):this.matchPair("set","default")?this.expression(as,{this:e,default:this.parseDisjunction()}):this.match("comment")?this.expression(as,{this:e,comment:this.parseString()}):this.matchTextSeq(["DROP","NOT","NULL"])?this.expression(as,{this:e,drop:!0,allowNull:!0}):this.matchTextSeq(["SET","NOT","NULL"])?this.expression(as,{this:e,allowNull:!1}):this.matchTextSeq(["SET","VISIBLE"])?this.expression(as,{this:e,visible:"VISIBLE"}):this.matchTextSeq(["SET","INVISIBLE"])?this.expression(as,{this:e,visible:"INVISIBLE"}):(this.matchTextSeq(["SET","DATA"]),this.matchTextSeq("TYPE"),this.expression(as,{this:e,dtype:this.parseTypes(),collate:this.match("collate")&&this.parseTerm(),using:this.match("using")&&this.parseDisjunction()}))}parseAlterDiststyle(){return this.matchTexts(["ALL","EVEN","AUTO"])?this.expression(ta,{this:Q((this.prev?.text??"").toUpperCase())}):(this.matchTextSeq(["KEY","DISTKEY"]),this.expression(ta,{this:this.parseColumn()}))}parseAlterSortkey(e={}){let{compound:t}=e;return t&&this.matchTextSeq("SORTKEY"),this.match("lParen",{advance:!1})?this.expression(sa,{expressions:this.parseWrappedIdVars(),compound:t}):(this.matchTexts(["AUTO","NONE"]),this.expression(sa,{this:Q((this.prev?.text??"").toUpperCase()),compound:t}))}parseAlterTableDrop(){let e=this.index-1,t=this.parseExists();return this.match("partition",{advance:!1})?this.parseCsv(()=>this.parseDropPartition({exists:t})):(this.retreat(e),this.parseCsv(this.parseDropColumn.bind(this)))}parseAlterTableRename(){if(this.match("column")||!this._constructor.ALTER_RENAME_REQUIRES_COLUMN){let e=this.parseExists(),t=this.parseColumn(),s=this.matchTextSeq("TO")||void 0,r=this.parseColumn();return!t||!s||!r?void 0:this.expression(ga,{this:t,to:r,exists:e})}return this.matchTextSeq("TO"),this.expression(Mr,{this:this.parseTable({schema:!0})})}parseLoad(){if(this.matchTextSeq("DATA")){let e=this.matchTextSeq("LOCAL")||void 0;this.matchTextSeq("INPATH");let t=this.parseString(),s=this.match("overwrite")||void 0;return this.matchPair("into","table"),this.expression(Ho,{this:this.parseTable({schema:!0}),local:e,overwrite:s,inpath:t,partition:this.parsePartition(),inputFormat:this.matchTextSeq("INPUTFORMAT")&&this.parseString(),serde:this.matchTextSeq("SERDE")&&this.parseString()})}return this.parseAsCommand(this.prev)}parseDelete(){let e;this.match("from",{advance:!1})||(e=this.parseCsv(this.parseTable.bind(this))||void 0);let t=this.parseReturning();return this.expression(Js,{tables:e,this:this.match("from")&&this.parseTable({joins:!0}),using:this.match("using")&&this.parseCsv(()=>this.parseTable({joins:!0})),cluster:this.match("on")&&this.parseOnProperty(),where:this.parseWhere(),returning:t||this.parseReturning(),order:this.parseOrder(),limit:this.parseLimit()})}parseUpdate(){let e={this:this.parseTable({joins:!0,aliasTokens:this._constructor.UPDATE_ALIAS_TOKENS})};for(;this.curr;)if(this.match("set"))e.expressions=this.parseCsv(this.parseEquality.bind(this));else if(this.match("returning",{advance:!1}))e.returning=this.parseReturning();else if(this.match("from",{advance:!1})){let t=this.parseFrom({joins:!0}),s=t?.args.this;if(s instanceof Te&&this.match("join",{advance:!1})){let r=this.parseJoins();s.setArgKey("joins",0<r.length?r:void 0)}e.from=t}else if(this.match("where",{advance:!1}))e.where=this.parseWhere();else if(this.match("orderBy",{advance:!1}))e.order=this.parseOrder();else if(this.match("limit",{advance:!1}))e.limit=this.parseLimit();else break;return this.expression(Vt,e)}parseUse(){return this.expression(kc,{kind:this.parseVarFromOptions(this._constructor.USABLES,{raiseUnmatched:!1}),this:this.parseTable({schema:!1})})}parseUncache(){return this.match("table")||this.raiseError("Expecting TABLE after UNCACHE"),this.expression(Eo,{exists:this.parseExists(),this:this.parseTable({schema:!0})})}parseAsCommand(e){for(;this.curr;)this.advance();let t=this.findSql(e,this.prev),s=e?.text.length||0;return this.warnUnsupported(),new Ws({this:t.substring(0,s),expression:t.substring(s)})}parseDictProperty(e){let t=[];this.matchLParen();let s=this.parseIdVar();if(this.match("lParen")){for(;;){let r=this.parseIdVar(),n=this.parsePrimary();if(!r&&!n)break;t.push(this.expression(wA,{this:r,value:n}))}this.match("rParen")}return this.matchRParen(),this.expression(mn,{this:e.this,kind:s?.args.this,settings:t})}parseDictRange(e){this.matchLParen();let t=this.matchTextSeq("MIN")||void 0,s,r;return t?(s=this.parseVar()||this.parsePrimary(),s||this.raiseError("Expected MIN value"),this.matchTextSeq("MAX"),r=this.parseVar()||this.parsePrimary(),r||this.raiseError("Expected MAX value")):(r=this.parseVar()||this.parsePrimary(),r||this.raiseError("Expected MAX value"),s=R.number(0)),this.matchRParen(),this.expression(On,{this:e.this,min:s,max:r})}parseComprehension(e){let t=this.index,s=this.parseColumn(),r=(this.match("comma")||void 0)&&this.parseColumn();if(!this.match("in")){this.retreat(t-1);return}let n=this.parseColumn(),a=this.matchTextSeq("IF")?this.parseDisjunction():void 0;return this.expression(bo,{this:e,expression:s,position:r,iterator:n,condition:a})}parseHeredoc(){if(this.match("heredocString"))return this.expression(Kn,{this:this.prev?.text??""});if(!this.matchTextSeq("$"))return;let e=["$"],t;this.isConnected()?(this.advance(),e.push((this.prev?.text??"").toUpperCase())):this.raiseError("No closing $ found"),e[e.length-1]!=="$"&&(this.isConnected()&&this.matchTextSeq("$")?(t=e[e.length-1],e.push("$")):this.raiseError("No closing $ found"));let s=this.curr;for(;this.curr;){if(this.matchTextSeq(e,{advance:!1})){let r=this.findSql(s,this.prev);return this.advance(e.length),this.expression(Kn,{this:r,tag:t})}this.advance()}this.raiseError(`No closing ${e.join("")} found`)}findParser(e,t){if(!this.curr)return;let s=this.index,r=[];for(;;){let n=this.curr.text.toUpperCase(),a=n.split(" ");r.push(n),this.advance();let[o,c]=no(t,a);if(t=c,o===0)break;if(o===2)return e[r.join(" ")]}this.retreat(s)}parseGroupConcat(){let e=(n,a)=>{if(n instanceof We&&1<(n.args.expressions?.length??0)){let o=[this.expression(Gt,{expressions:n.args.expressions,safe:!0,coalesce:this._dialectConstructor.CONCAT_COALESCE})];return n.setArgKey("expressions",o),n}return a.length===1?a[0]:this.expression(Gt,{expressions:a,safe:!0,coalesce:this._dialectConstructor.CONCAT_COALESCE})},t=this.parseCsv(this.parseLambda.bind(this)),s;if(t){let n=t[t.length-1],a=n instanceof fe?n:void 0;a?.args.this&&(t[t.length-1]=a.args.this,a.setArgKey("this",e(a.args.this,t))),s=a||e(t[0],t)}else s=void 0;let r=this.match("separator")?this.parseField():void 0;return this.expression(Ui,{this:s,separator:r})}parseInitcap(){let e=$l.fromArgList(this.parseFunctionArgs());return e.args.expression||e.setArgKey("expression",R.string(this._dialectConstructor.INITCAP_DEFAULT_DELIMITER_CHARS)),e}parseOperator(e){let t=e;for(;this.match("lParen");){let s="";for(;this.curr&&!this.match("rParen");)s+=this.curr.text,this.advance();if(t=this.expression(_n,{comments:this.prevComments,this:t,operator:s,expression:this.parseBitwise()}),!this.match("operator"))break}return t}buildPipeCte(e){let{query:t,expressions:s,aliasCte:r}=e,n;r?n=r:(this.pipeCteCounter+=1,n=`__tmp${this.pipeCteCounter}`);let o=t.args.with?.pop(),c=pt(...s,{copy:!1}).from(n,{copy:!1});return o&&c.setArgKey("with",o),c.with(n,t,{copy:!1})}parsePipeSyntaxSelect(e){let t=this.parseSelect({consumePipe:!1});return t?this.buildPipeCte({query:e.select(t.args.expressions,{append:!1}),expressions:[new xe({})]}):e}parsePipeSyntaxLimit(e){let t=this.parseLimit(),s=this.parseOffset();if(t){let r=e.args.limit||t,n;if(typeof r=="number")n=r;else{te(r,Et);let o=r.args.expression;te(o,A),n=o.toValue()}(t.args.expression?.toValue()??0)<=n&&e.limit(t,{copy:!1})}if(s){let r=e.args.offset,n;if(r===void 0)n=0;else if(typeof r=="number")n=r;else{te(r,Rr);let c=r.args.expression;n=typeof c=="number"?c:(te(c,A),c.toValue())}let a=s.args.expression,o=typeof a=="number"?a:(te(a,A),a.toValue());e.offset(R.number(n+o))}return e}parsePipeSyntaxAggregateFields(){let e=this.parseDisjunction();return this.matchTextSeq(["GROUP","AND"],{advance:!1})?e:(e=this.parseAlias(e),this.matchSet(["asc","desc"],{advance:!1})?this.parseOrdered(()=>e):e)}parsePipeSyntaxAggregateGroupOrderBy(e,t={}){let{groupByExists:s=!0}=t,r=this.parseCsv(this.parsePipeSyntaxAggregateFields.bind(this)),n=[],a=[];for(let o of r){let c;o instanceof Ht?(c=o.args.this,c instanceof Re&&o.setArgKey("this",c.args.alias),a.push(o)):c=o,c&&n.push(c)}return s?e.select(n,{copy:!1}).groupBy(...n.map(o=>o.args.alias||o),{copy:!1}):e.select(n,{append:!1,copy:!1}),0<a.length?e.orderBy(...a,{append:!1,copy:!1}):e}parsePipeSyntaxAggregate(e){return this.matchTextSeq("AGGREGATE"),e=this.parsePipeSyntaxAggregateGroupOrderBy(e,{groupByExists:!1}),(this.match("groupBy")||this.matchTextSeq(["GROUP","AND"])&&this.match("orderBy"))&&(e=this.parsePipeSyntaxAggregateGroupOrderBy(e)),this.buildPipeCte({query:e,expressions:[new xe({})]})}parsePipeSyntaxSetOperator(e){if(!e)return;let t=this.parseSetOperation(e);if(!t)return;let s=()=>{let o=this.parseParen();return o?o.assertIs(Te).unnest():void 0};t.args.this?.pop();let r=[t.args.expression?.pop().assertIs(Te).unnest(),...this.parseCsv(s)];e=this.buildPipeCte({query:e,expressions:[new xe({})]});let a=e.args.with?.pop();if(t instanceof Lr?e=e.union(...r,{copy:!1,...t.args}):t instanceof wr?e=e.except(...r,{copy:!1,...t.args}):e=e.intersect(...r,{copy:!1,...t.args}),!!e)return e.setArgKey("with",a),this.buildPipeCte({query:e,expressions:[new xe({})]})}parsePipeSyntaxJoin(e){if(!e)return;let t=this.parseJoin();if(t)return e instanceof ee?e.join(t,{copy:!1}):e}parsePipeSyntaxPivot(e){let t=this.parsePivots();if(!t)return e;let s=e.args.from;if(s){let r=s.args.this;$(r,A)&&r.setArgKey("pivots",t)}return this.buildPipeCte({query:e,expressions:[new xe({})]})}parsePipeSyntaxExtend(e){return this.matchTextSeq("EXTEND"),e.select([new xe({}),...this.parseExpressions()],{append:!1,copy:!1}),this.buildPipeCte({query:e,expressions:[new xe({})]})}parsePipeSyntaxTablesample(e){let t=this.parseTableSample(),s=e.args.with;if(s){let r=s.args.expressions?.[s.args.expressions.length-1];r instanceof A&&r.args.this instanceof A&&r.args.this.setArgKey("sample",t)}else e.setArgKey("sample",t);return e}parsePipeSyntaxQuery(e){let t=e;for(t instanceof Te&&(t=pt("*").from(t,{copy:!1})),t.args.from||(t=pt("*").from(t.subquery(void 0,{copy:!1}),{copy:!1}));this.match("pipeGt");){let s=this.curr,r=s?this.tokens.indexOf(s):-1,n=this._constructor.PIPE_SYNTAX_TRANSFORM_PARSERS[this.curr?.text.toUpperCase()??""];if(n)t=n.call(this,t);else{let a=this.parsePipeSyntaxSetOperator(t);if(a=a||this.parsePipeSyntaxJoin(t),!a&&0<=r){this.retreat(r),this.raiseError(`Unsupported pipe syntax operator: '${s?.text.toUpperCase()}'.`);break}t=a}}return t}parseDeclareitem(){let e=this.parseCsv(this.parseIdVar.bind(this));if(e)return this.expression(Ro,{this:e,kind:this.parseTypes(),default:this.match("default")&&this.parseBitwise()})}parseDeclare(){let e=this.prev,t=this.tryParse(()=>this.parseCsv(this.parseDeclareitem.bind(this)));return!t||this.curr?this.parseAsCommand(e):this.expression(Oo,{expressions:t})}buildCast(e){let{strict:t}=e,s=t?X:_t,r={...e};return delete r.strict,s===_t&&(r.requiresString=this._dialectConstructor.TRY_CAST_REQUIRES_STRING),this.expression(s,r)}parseJsonValue(){let e=this.parseBitwise();this.match("comma");let t=this.parseBitwise(),s=(this.match("returning")||void 0)&&this.parseType();return this.expression(wc,{this:e,path:this.dialect.toJsonPath(t),returning:s,onCondition:this.parseOnCondition()})}validateExpression(e,t){if(this.errorLevel!==0)for(let s of e.errorMessages(t))this.raiseError(s);return e}get _constructor(){return this.constructor}get _dialectConstructor(){return this.dialect._constructor}};F=Bt(null),S(F,10,"FUNCTIONS",a_,T),S(F,10,"NO_PAREN_FUNCTIONS",n_,T),S(F,10,"STRUCT_TYPE_TOKENS",i_,T),S(F,10,"NESTED_TYPE_TOKENS",r_,T),S(F,10,"ENUM_TYPE_TOKENS",s_,T),S(F,10,"AGGREGATE_TYPE_TOKENS",t_,T),S(F,10,"TYPE_TOKENS",e_,T),S(F,10,"SIGNED_TO_UNSIGNED_TYPE_TOKEN",Kk,T),S(F,10,"SUBQUERY_PREDICATES",Zk,T),S(F,10,"RESERVED_TOKENS",Qk,T),S(F,10,"DB_CREATABLES",zk,T),S(F,10,"CREATABLES",Xk,T),S(F,10,"ALTERABLES",Jk,T),S(F,10,"ID_VAR_TOKENS",jk,T),S(F,10,"TABLE_ALIAS_TOKENS",Wk,T),S(F,10,"ALIAS_TOKENS",Hk,T),S(F,10,"COLON_PLACEHOLDER_TOKENS",Vk,T),S(F,10,"ARRAY_CONSTRUCTORS",Yk,T),S(F,10,"COMMENT_TABLE_ALIAS_TOKENS",Gk,T),S(F,10,"UPDATE_ALIAS_TOKENS",$k,T),S(F,10,"TRIM_TYPES",Bk,T),S(F,10,"FUNC_TOKENS",Fk,T),S(F,10,"CONJUNCTION",vk,T),S(F,10,"ASSIGNMENT",Uk,T),S(F,10,"DISJUNCTION",qk,T),S(F,10,"EQUALITY",_k,T),S(F,10,"COMPARISON",kk,T),S(F,10,"BITWISE",Dk,T),S(F,10,"TERM",Mk,T),S(F,10,"FACTOR",wk,T),S(F,10,"EXPONENT",Lk,T),S(F,10,"TIMES",bk,T),S(F,10,"TIMESTAMPS",Pk,T),S(F,10,"SET_OPERATIONS",Ck,T),S(F,10,"JOIN_METHODS",yk,T),S(F,10,"JOIN_SIDES",Ik,T),S(F,10,"JOIN_KINDS",Nk,T),S(F,10,"LAMBDAS",Rk,T),S(F,10,"COLUMN_OPERATORS",Ok,T),S(F,10,"CAST_COLUMN_OPERATORS",mk,T),S(F,10,"EXPRESSION_PARSERS",Sk,T),S(F,10,"STATEMENT_PARSERS",Tk,T),S(F,10,"UNARY_PARSERS",fk,T),S(F,10,"STRING_PARSERS",xk,T),S(F,10,"NUMERIC_PARSERS",dk,T),S(F,10,"PRIMARY_PARSERS",Ak,T),S(F,10,"PLACEHOLDER_PARSERS",Ek,T),S(F,10,"RANGE_PARSERS",gk,T),S(F,10,"PIPE_SYNTAX_TRANSFORM_PARSERS",hk,T),S(F,10,"PROPERTY_PARSERS",uk,T),S(F,10,"CONSTRAINT_PARSERS",lk,T),S(F,10,"ALTER_PARSERS",pk,T),S(F,10,"NO_PAREN_FUNCTION_PARSERS",ck,T),S(F,10,"INVALID_FUNC_NAME_TOKENS",ok,T),S(F,10,"KEY_VALUE_DEFINITIONS",ak,T),S(F,10,"FUNCTION_PARSERS",nk,T),S(F,10,"QUERY_MODIFIER_PARSERS",ik,T),S(F,10,"QUERY_MODIFIER_TOKENS",rk,T),S(F,10,"TYPE_LITERAL_PARSERS",sk,T),S(F,10,"TYPE_CONVERTERS",tk,T),S(F,10,"DDL_SELECT_TOKENS",ek,T),S(F,10,"PRE_VOLATILE_TOKENS",KD,T),S(F,10,"OPTYPE_FOLLOW_TOKENS",ZD,T),S(F,10,"TABLE_INDEX_HINT_TOKENS",QD,T),S(F,10,"WINDOW_ALIAS_TOKENS",zD,T),S(F,10,"WINDOW_BEFORE_PAREN_TOKENS",XD,T),S(F,10,"JSON_KEY_VALUE_SEPARATOR_TOKENS",JD,T),S(F,10,"FETCH_TOKENS",jD,T),S(F,10,"ADD_CONSTRAINT_TOKENS",WD,T),S(F,10,"DISTINCT_TOKENS",HD,T),S(F,10,"UNNEST_OFFSET_ALIAS_TOKENS",VD,T),S(F,10,"SELECT_START_TOKENS",YD,T),S(F,10,"PRIVILEGE_FOLLOW_TOKENS",GD,T),S(F,10,"AMBIGUOUS_ALIAS_TOKENS",$D,T),S(F,10,"MODIFIABLES",BD,T),bt(F,T),Lt(F,3,T),T._showTrie=void 0,T._setTrie=void 0,T.JOIN_HINTS=new Set,T.ALTER_ALTER_PARSERS={DISTKEY:function(){return this.parseAlterDiststyle()},DISTSTYLE:function(){return this.parseAlterDiststyle()},SORTKEY:function(){return this.parseAlterSortkey()},COMPOUND:function(){return this.parseAlterSortkey({compound:!0})}},T.SCHEMA_UNNAMED_CONSTRAINTS=new Set(["CHECK","EXCLUDE","FOREIGN KEY","LIKE","PERIOD","PRIMARY KEY","UNIQUE","BUCKET","TRUNCATE"]),T.FUNCTIONS_WITH_ALIASED_ARGS=new Set(["STRUCT"]),T.SET_PARSERS={GLOBAL:function(){return this.parseSetItemAssignment({kind:"GLOBAL"})},LOCAL:function(){return this.parseSetItemAssignment({kind:"LOCAL"})},SESSION:function(){return this.parseSetItemAssignment({kind:"SESSION"})},TRANSACTION:function(){return this.parseSetTransaction()}},T.SHOW_PARSERS={},T.TRANSACTION_KIND=new Set(["DEFERRED","IMMEDIATE","EXCLUSIVE"]),T.TRANSACTION_CHARACTERISTICS={ISOLATION:[["LEVEL","REPEATABLE","READ"],["LEVEL","READ","COMMITTED"],["LEVEL","READ","UNCOMITTED"],["LEVEL","SERIALIZABLE"]],READ:["WRITE","ONLY"]},T.CONFLICT_ACTIONS={...Object.fromEntries(["ABORT","FAIL","IGNORE","REPLACE","ROLLBACK","UPDATE"].map(e=>[e,[]])),DO:["NOTHING","UPDATE"]},T.CREATE_SEQUENCE={SCALE:["EXTEND","NOEXTEND"],ShaRD:["EXTEND","NOEXTEND"],NO:["CYCLE","CACHE","MAXVALUE","MINVALUE"],...Object.fromEntries(["SESSION","GLOBAL","KEEP","NOKEEP","ORDER","NOORDER","NOCACHE","CYCLE","NOCYCLE","NOMINVALUE","NOMAXVALUE","NOSCALE","NOSHARD"].map(e=>[e,[]]))},T.ISOLATED_LOADING_OPTIONS={FOR:["ALL","INSERT","NONE"]},T.USABLES=Object.fromEntries(["ROLE","WAREHOUSE","DATABASE","SCHEMA","CATALOG"].map(e=>[e,[]])),T.CAST_ACTIONS=Object.fromEntries(["RENAME","ADD"].map(e=>[e,["FIELDS"]])),T.SCHEMA_BINDING_OPTIONS={TYPE:["EVOLUTION"],...Object.fromEntries(["BINDING","COMPENSATION","EVOLUTION"].map(e=>[e,[]]))},T.PROCEDURE_OPTIONS={},T.EXECUTE_AS_OPTIONS=Object.fromEntries(["CALLER","SELF","OWNER"].map(e=>[e,[]])),T.KEY_CONSTRAINT_OPTIONS={NOT:["ENFORCED"],MATCH:["FULL","PARTIAL","SIMPLE"],INITIALLY:["DEFERRED","IMMEDIATE"],USING:["BTREE","HASH"],...Object.fromEntries(["DEFERRABLE","NORELY","RELY"].map(e=>[e,[]]))},T.WINDOW_EXCLUDE_OPTIONS={NO:["OTHERS"],CURRENT:["ROW"],...Object.fromEntries(["GROUP","TIES"].map(e=>[e,[]]))},T.INSERT_ALTERNATIVES=new Set(["ABORT","FAIL","IGNORE","REPLACE","ROLLBACK"]),T.CLONE_KEYWORDS=new Set(["CLONE","COPY"]),T.HISTORICAL_DATA_PREFIX=new Set(["AT","BEFORE","END"]),T.HISTORICAL_DATA_KIND=new Set(["OFFSET","STATEMENT","STREAM","TIMESTAMP","VERSION"]),T.OPCLASS_FOLLOW_KEYWORDS=new Set(["ASC","DESC","NULLS","WITH"]),T.VIEW_ATTRIBUTES=new Set(["ENCRYPTION","SCHEMABINDING","VIEW_METADATA"]),T.WINDOW_SIDES=new Set(["FOLLOWING","PRECEDING"]),T.COPY_INTO_VARLEN_OPTIONS=new Set(["FILE_FORMAT","COPY_OPTIONS","FORMAT_OPTIONS","CREDENTIAL"]),T.IS_JSON_PREDICATE_KIND=new Set(["VALUE","SCALAR","ARRAY","OBJECT"]),T.ODBC_DATETIME_LITERALS={},T.ON_CONDITION_TOKENS=new Set(["ERROR","NULL","TRUE","FALSE","EMPTY"]),T.DESCRIBE_STYLES=new Set(["ANALYZE","EXTENDED","FORMATTED","HISTORY"]),T.SET_ASSIGNMENT_DELIMITERS=new Set(["=",":=","TO"]),T.ANALYZE_STYLES=new Set(["BUFFER_USAGE_LIMIT","FULL","LOCAL","NO_WRITE_TO_BINLOG","SAMPLE","SKIP_LOCKED","VERBOSE"]),T.ANALYZE_EXPRESSION_PARSERS={ALL:function(){return this.parseAnalyzeColumns()},COMPUTE:function(){return this.parseAnalyzeStatistics()},DELETE:function(){return this.parseAnalyzeDelete()},DROP:function(){return this.parseAnalyzeHistogram()},ESTIMATE:function(){return this.parseAnalyzeStatistics()},LIST:function(){return this.parseAnalyzeList()},PREDICATE:function(){return this.parseAnalyzeColumns()},UPDATE:function(){return this.parseAnalyzeHistogram()},VALIDATE:function(){return this.parseAnalyzeValidate()}},T.PARTITION_KEYWORDS=new Set(["PARTITION","SUBPARTITION"]),T.OPERATION_MODIFIERS=new Set,T.RECURSIVE_CTE_SEARCH_KIND=new Set(["BREADTH","DEPTH","CYCLE"]),T.STRICT_CAST=!0,T.PREFIXED_PIVOT_COLUMNS=!1,T.IDENTIFY_PIVOT_STRINGS=!1,T.LOG_DEFAULTS_TO_LN=!1,T.TABLESAMPLE_CSV=!1,T.DEFAULT_SAMPLING_METHOD=void 0,T.SET_REQUIRES_ASSIGNMENT_DELIMITER=!0,T.TRIM_PATTERN_FIRST=!1,T.STRING_ALIASES=!1,T.MODIFIERS_ATTACHED_TO_SET_OP=!0,T.SET_OP_MODIFIERS=new Set(["order","limit","offset"]),T.NO_PAREN_IF_COMMANDS=!0,T.JSON_ARROWS_REQUIRE_JSON_TYPE=!1,T.COLON_IS_VARIANT_EXTRACT=!1,T.VALUES_FOLLOWED_BY_PAREN=!0,T.SUPPORTS_IMPLICIT_UNNEST=!1,T.INTERVAL_SPANS=!0,T.SUPPORTS_PARTITION_SELECTION=!1,T.WRAPPED_TRANSFORM_COLUMN_CONSTRAINT=!0,T.OPTIONAL_ALIAS_TOKEN_CTE=!0,T.ALTER_RENAME_REQUIRES_COLUMN=!0,T.ALTER_TABLE_PARTITIONS=!1,T.JOINS_HAVE_EQUAL_PRECEDENCE=!1,T.ZONE_AWARE_TIMESTAMP_CONSTRUCTOR=!1,T.MAP_KEYS_ARE_ARBITRARY_EXPRESSIONS=!1,T.JSON_EXTRACT_REQUIRES_JSON_EXPRESSION=!1,T.ADD_JOIN_ON_TRUE=!1,T.SUPPORTS_OMITTED_INTERVAL_SPAN_UNIT=!1;var Gf=T;var o_,c_,FI,vt=class extends(c_=Qn,o_=[m],c_){static get KEYWORDS(){return{"..":"dot"}}};FI=Bt(c_),S(FI,10,"KEYWORDS",o_,vt),bt(FI,vt),Lt(FI,3,vt),vt.SINGLE_TOKENS={"(":"lParen",")":"rParen","[":"lBracket","]":"rBracket",":":"colon",",":"comma","-":"dash",".":"dot","?":"placeholder","@":"parameter","'":"quote",'"':"quote",$:"dollar","*":"star"},vt.IDENTIFIER_ESCAPES=["\\"],vt.STRING_ESCAPES=["\\"],vt.VAR_TOKENS=new Set(["var"]);var bU={jsonPathFilter:(i,e)=>`?${e.args.this}`,jsonPathKey:(i,e)=>i.jsonPathKeySql(e),jsonPathRecursive:(i,e)=>`..${e.args.this||""}`,jsonPathRoot:(i,e)=>"$",jsonPathScript:(i,e)=>`(${e.args.this}`,jsonPathSelector:(i,e)=>`[${i.jsonPathPart(e.args.this)}]`,jsonPathSlice:(i,e)=>[e.args.start,e.args.end,e.args.step].filter(s=>s!==void 0).map(s=>s===void 0?"":i.jsonPathPart(s)).join(":"),jsonPathSubscript:(i,e)=>i.jsonPathSubscriptSql(e),jsonPathUnion:(i,e)=>`[${(e.args.expressions??[]).map(t=>i.jsonPathPart(t)).join(",")}]`,jsonPathWildcard:(i,e)=>"*"},ON=new Set([xs,jt,cr,cs,fs,lr,pr,Ts,vs,Pt]);function BI(i,e){let s=se.getOrRaise(e?.dialect).jsonpathTokenizer().tokenize(i),r=s.length,n=0;function a(){return n<r?s[n].tokenType:void 0}function o(){return s[n-1]}function c(){return n+=1,o()}function l(N){return`${N} at index ${n}: ${i}`}function u(N,P={}){let{raiseUnmatched:k=!1}=P;if(a()===N)return c();if(k)throw new xt(l(`Expected ${N}`))}function h(N){let P=a();if(P!==void 0)return N.has(P)?c():void 0}function d(){let N=u("string")||u("identifier");if(N)return N.text;if(u("star"))return new Pt({});if(u("placeholder")||u("lParen")){let _=o().text==="(",W=n;for(;;){u("lBracket")&&f();let He=a();if(He==="rBracket"||He===void 0)break;c()}let he=_?fs:xs,ne=s[W].start??0,Y=n<r?s[n].end??i.length:i.length;return new he({this:i.slice(ne,Y)})}let P=u("dash")?"-":"",k=u("number");return k&&(P+=k.text),P?parseInt(P,10):!1}function x(){let N=d(),P=!!u("colon"),k=P?d():void 0,_=!!u("colon"),W=_?d():void 0;return!P&&!_?N:new pr({start:N,end:k,step:W})}function f(){let N=x();if(typeof N=="string"||N!==!1){let P=[N];for(;u("comma");){let _=x();_!==!1&&P.push(_)}let k;return P.length===1?typeof N=="string"?k=new jt({this:P[0]}):N instanceof fs||N instanceof xs?k=new lr({this:P[0]}):k=new Ts({this:P[0]}):k=new vs({expressions:P}),u("rBracket",{raiseUnmatched:!0}),k}else throw new xt(l("Cannot have empty segment"))}function y(){let N=n-2;for(;h(vt.VAR_TOKENS););let P=N<0?0:(s[N].end??0)+1,k;return s.length<=n?k=i.slice(P):k=i.slice(P,s[n].start??i.length),k}u("dollar");let I=[new cs({})];for(;a();)if(u("dot")||u("colon")){let N=o().text==="..",P;if(h(vt.VAR_TOKENS)?P=y():u("identifier")?P=o().text:u("star")?P=new Pt({}):P=void 0,N)I.push(new cr({this:P}));else if(P)I.push(new jt({this:P}));else throw new xt(l("Expected key name or * after DOT"))}else if(u("lBracket"))I.push(f());else if(h(vt.VAR_TOKENS))I.push(new jt({this:y()}));else if(u("identifier"))I.push(new jt({this:o().text}));else if(u("star"))I.push(new Pt({}));else throw new xt(l(`Unexpected ${s[n].tokenType}`));return new bi({expressions:I})}function $B(i,e={}){let{dialect:t}=e,s=se.getOrRaise(t);function r(n){return n=LU(n),n=wU(n,s),n=DU(n,{promoteToInferredDatetimeType:s._constructor.PROMOTE_TO_INFERRED_DATETIME_TYPE}),n=kU(n),n=YI(n,GI),n=_U(n),n}return i.transform(r,{copy:!1})}function LU(i){if(i instanceof Le&&i.type instanceof A&&i.type.args.this&&O.TEXT_TYPES.has(i.type.args.this)){let e=i.args.this,t=i.args.expression;return!e||!t?i:new Gt({expressions:[e,t],coalesce:!1})}return i}function wU(i,e){if(i instanceof La||i instanceof Is){let t=i.args.expressions,s=i instanceof La?i.args.zone:void 0,r=i.args.this;if(!(t&&Array.isArray(t)&&0<t.length)&&!s&&r){let a=r;if(a.isString&&SA(a.name))return new X({this:r,to:new O({this:"date"})})}}if(i instanceof Xl&&!i.args.zone){let r=i;i.type||(r=gs(i,{dialect:e}));let n=r.args.this;if(!n)return i;let a=r.type||new O({this:"timestamp"});return a instanceof O?new X({this:n,to:a}):i}return i}var MU=[Le,ke,me,st,Be,Me,De,$e,Ps,Gs];function DU(i,e={}){let{promoteToInferredDatetimeType:t=!1}=e;if(MU.some(r=>i instanceof r)){let r=i.args.this,n=i.args.expression;r&&n&&p_(r,n,{promoteToInferredDatetimeType:t})}else if(i instanceof ss){let r=i.args.this,n=i.args.low;r&&n&&p_(r,n,{promoteToInferredDatetimeType:t})}else if(i instanceof Gi){let r=i.args.expression;if(r){let n=r;n.type instanceof A&&n.type.args.this&&O.TEMPORAL_TYPES.has(n.type.args.this)||$I(n,"datetime")}}else if(i instanceof yt||i instanceof ts||i instanceof bs){let r=i.args.this,n=i.args.unit;r&&l_(r,n)}else i instanceof wa&&qU(i);return i}function kU(i){if(i instanceof X){let e=i.args.this,t=i.args.to;if(e&&t){let s=e,r=t;if(s.type&&r.equals(s.type))return s}}if(i instanceof La||i instanceof Is){let e=i.args.this;if(e){let t=e;if(t.type instanceof A&&t.type.args.this==="date"){let s=t.type.args.expressions;if(!(s&&Array.isArray(s)&&0<s.length))return t}}}return i}function YI(i,e){if(i instanceof Ee){let t=i.args.this,s=i.args.expression;t&&e(t),s&&e(s)}else if(i instanceof be){let t=i.args.this;t&&e(t)}else if(i instanceof le){let t=i.parent;if(!(t instanceof nt&&t.args.this)){let r=i.args.this;r&&e(r)}}else if(i instanceof at||i instanceof Zt){let t=i.args.this;t&&e(t)}return i}function _U(i){if(i instanceof Ht){let e=i.args;e.desc===!1&&(e.desc=void 0)}return i}function p_(i,e,t){let{promoteToInferredDatetimeType:s}=t;for(let[r,n]of[[i,e],[e,i]]){if(n instanceof Ce){let u=n.args.unit;l_(r,u)}let a=r.type;if(!a||!(a instanceof A)||!a.args.this||!O.TEMPORAL_TYPES.has(a.args.this))continue;let o=a,c=n.type;if(!c||!(c instanceof A)||!c.args.this||!O.TEXT_TYPES.has(c.args.this))continue;let l;if(s){let u;if(n.isString){let d=n.name;SA(d)?u="date":_f(d)?u="datetime":u=o.args.this}else u="datetime";let h=xl.COERCES_TO.get(o.args.this);l=h&&h.has(u)?u:o.args.this}else l=o.args.this;l!==o.args.this&&$I(r,l),$I(n,l)}}function l_(i,e){if(!i.type)return i;if(i.type instanceof A&&i.type.args.this&&O.TEXT_TYPES.has(i.type.args.this)){let t=i.name,s=SA(t);if(s&&mA(e))return i.replace(new X({this:i.copy(),to:new O({this:"date"})}));if(s||_f(t))return i.replace(new X({this:i.copy(),to:new O({this:"datetime"})}))}else if(i.type instanceof A&&i.type.args.this==="date"&&!mA(e))return i.replace(new X({this:i.copy(),to:new O({this:"datetime"})}));return i}function qU(i){let e=i.args.this,t=i.args.expression;for(let s of[e,t])if(s){let r=s;r.type instanceof A&&r.type.args.this&&!O.TEMPORAL_TYPES.has(r.type.args.this)&&r.replace(new X({this:r.copy(),to:new O({this:"datetime"})}))}}function $I(i,e){i.replace(new X({this:i.copy(),to:new O({this:e})}))}function GI(i){if(i instanceof rt){let e=i.args.this;e instanceof A&&GI(e);let t=i.args.expressions;if(t)for(let s of t)s instanceof A&&GI(s)}else i.type instanceof A&&i.type.args.this&&O.INTEGER_TYPES.has(i.type.args.this)&&i.replace(i.neq(0))}var UU=["on","side","kind","using","method"];function WB(i){for(let e of i.findAll(ee)){let t=Rt(e.args.joins??[],oe);if(!h_(t))continue;let s={},r=[];for(let n of t){let a=VI(n);if(0<a.size)for(let o of a)s[o]||(s[o]=[]),s[o].push(n);else r.push([n.aliasOrName,n])}for(let[n,a]of r)for(let o of s[n]??[]){let c=o.args.on;if(c instanceof Ee){if(VI(o).size<2)continue;let l=c.constructor;for(let u of c.flatten())if(RN(u).has(n)){u.replace(Qe());let h=qA([a.args.on,u],l,{copy:!1});a.on(h,{append:!1,copy:!1})}}}}return i=vU(i),i=u_(i),i}function vU(i){for(let e of i.findAll(Je)){let t=e.parent;if(!t)continue;let s=Rt(t.args.joins??[],oe);if(!h_(s))continue;let r=new Map;for(let l of s)r.set(l.aliasOrName,l);let n=new Map;for(let[l,u]of r)n.set(l,VI(u));let a=gD(n),o=e.aliasOrName,c=a.filter(l=>l!==o&&r.has(l)).map(l=>r.get(l));t.setArgKey("joins",c)}return i}function u_(i){for(let e of i.findAll(oe)){let t=UU.some(r=>e.args[r]!=null),s=e.args;t||(s.kind="cross"),s.kind==="cross"?s.on=void 0:((s.kind==="inner"||s.kind==="outer")&&(s.kind=void 0),!s.on&&!s.using&&(s.on=Qe()))}return i}function VI(i){let e=i.args.on;return e?RN(e,{exclude:i.aliasOrName}):new Set}function h_(i){for(let e of i)if(e.args.side)return!1;return!0}function t$(i,e){return function(t){let s=t,r=s.constructor;try{for(let o of i)s=o(s)}catch(o){if(o instanceof Wn)this.unsupported(o.message);else throw o}if(e)return e.call(this,s);let n=this[`${s._constructor.key}Sql`];if(n instanceof Function)return n.call(this,s);let a=this._constructor.TRANSFORMS.get(s._constructor);if(a){if(r===s.constructor){if(s instanceof g)return this.functionFallbackSql(s);throw new Error(`Expression type ${s.constructor.name} requires a _sql method to be transformed.`)}return a.call(this,s)}throw new Error(`Unsupported expression type ${s.constructor.name}.`)}}function s$(i){if(i instanceof ee){let e=0,t=[];for(let s of i.findAll(ge)){let r=s.parent;if(!(r instanceof Je||r instanceof oe)||s.args.expressions?.length!==1||!(s.args.expressions[0]instanceof Ia))continue;let n=s.args.expressions[0],a=n.args.start,o=n.args.end,c=n.args.step;if(!a||!o||!(c instanceof Ce))continue;let l=s.args.alias,u=l instanceof ie?l.columns[0]:void 0,h=$(u,U)?u:$(u,A)?u.name:"date_value",d=j(a,"date"),x=new je({this:"date_add",expressions:[h,R.number(c.name),c.args.unit||""]}),f=j(x,"date"),y=`_generated_dates${e?`_${e}`:""}`,I=pt(new Re({this:d,alias:h})),N=pt(f).from(y).where(new $e({this:f,expression:j(o,"date")})),P=I.union(N,{distinct:!1});s.replace(pt(h).from(y).subquery(y)),t.push(Ye(new Tt({this:P}),y,{table:[h]})),e++}if(0<t.length){let s=ft(i.args.with,tt)??new tt({expressions:[]});s.setArgKey("recursive",!0),s.setArgKey("expressions",[...t,...s.args.expressions??[]]),i.setArgKey("with",s)}}return i}function r$(i){let e=i.args.this;if(i instanceof V&&e instanceof Fs){let t=new ge({expressions:[e]});return i.args.alias?Ye(t,"_u",{table:[i.args.alias instanceof ie?$(i.args.alias.args.this,U)||typeof i.args.alias.args.this=="string"?i.args.alias.args.this:"":typeof i.args.alias=="string"?i.args.alias:""]}):t}return i}function i$(i){if(i instanceof ee&&i.args.distinct&&i.args.distinct.getArgKey("on")instanceof Ge){let e=Za(i.namedSelects,"_row_number"),t=i.args.distinct.pop().getArgKey("on").args.expressions,s=new we({this:new AT({}),partitionBy:t}),r=i.args.order;r?s.setArgKey("order",r.pop()):s.setArgKey("order",new fe({expressions:t?.map(o=>o instanceof A?o.copy():o)??[]})),i.select(Ye(s,e),{copy:!1});let n=[],a=[e];for(let o of i.selects.slice(0,-1)){if(o.isStar){n=[new xe];break}let c=o;if(!(c instanceof Re)){let l=Za(a,c.outputName||"_col"),u=c instanceof B&&c.args.this instanceof A?!!c.args.this?.getArgKey("quoted"):void 0;c=c.replace(Ye(c,l,{quoted:u}))}a.push(c.outputName),n.push(c.getArgKey("alias"))}return pt(n).from(i.subquery("_t",{copy:!1})).where(new B({this:e}).eq(1))}return i}function n$(i){if(i instanceof ee&&i.args.qualify){let e=new Set(i.namedSelects);for(let o of i.selects)if(!o.aliasOrName){let c=Za(e,"_c");o.replace(Ye(o,c)),e.add(c)}let t=o=>{let c=o.aliasOrName,l=o.getArgKey("alias")||o.args.this;return l instanceof U?ho({col:c},{quoted:l.args.quoted}):c},s=pt(i.selects.map(t)),r=ft(i.args.qualify.pop().args.this,A),n={};for(let o of i.selects)o instanceof Re&&(n[o.alias]=o.args.this);let a=i.isStar?[we]:[we,B];for(let o of[...r?.findAll(a)??[]])if(o instanceof we){if(n)for(let u of o.findAll(B)){let h=n[u.name];h&&u.replace(h)}let c=Za(i.namedSelects,"_w");i.select(Ye(o,c),{copy:!1});let l=ho({col:c});o.parent instanceof Os?r=l:o.replace(l)}else i.namedSelects.includes(o.name)||i.select(o.copy(),{copy:!1});return s.from(i.subquery("_t",{copy:!1}),{copy:!1}).where(r,{copy:!1})}return i}function a$(i){for(let e of i.findAll(O))e.setArgKey("expressions",e.args.expressions?.filter(t=>!(t instanceof rr)));return i}function o$(i){if(i instanceof ee){let e=new Set(jn(i,[ge]).filter(t=>t.parent instanceof Je||t.parent instanceof oe).map(t=>t.alias));if(0<e.size)for(let t of i.findAll(B)){let s=t.parts[0];s&&s.argKey!=="this"&&s.args&&e.has(s.args.this)&&s.pop()}}return i}function c$(i,e={}){let{unnestUsingArraysZip:t=!0}=e;function s(n,a,o){let{hasMultiExpr:c}=o;if(c){if(!t)throw new Wn("Cannot transpile UNNEST with multiple input arrays");let l=[new je({this:"ARRAYS_ZIP",expressions:a})];return n.setArgKey("expressions",l),l}return a}function r(n,a={}){let{hasMultiExpr:o}=a;return n.args.offset?Ma:o?ET:rs}if(i instanceof ee){let n=i.args.from;if(n&&n.args.this instanceof ge){let o=n.args.this,c=o.args.alias,l=o.args.expressions,u=1<(l?.length??0),[h]=s(o,l??[],{hasMultiExpr:u}),d=$(c,ie)?Rt(c.columns,U):[],x=o.args.offset;x&&d.unshift(x instanceof U?x:new U({this:"pos",quoted:!1}));let f=r(o,{hasMultiExpr:u});o.replace(new V({this:new f({this:h}),alias:$(c,ie)?new ie({this:$(c.args.this,A)||typeof c.args.this=="string"?c.args.this:void 0,columns:d}):void 0}))}let a=i.args.joins||[];for(let o of[...a]){let c=o.args.this,l=c instanceof St,u=l?c.args.this:c;if(u instanceof ge){let h=l?c.args.alias:u.args.alias,d=u.args.expressions,x=1<(d?.length??0),f=s(u,d??[],{hasMultiExpr:x});a.splice(a.indexOf(o),1);let y=$(h,ie)?h:void 0,I=y?Rt(y.columns,U):[];if(!x&&I.length!==1&&I.length!==2)throw new Wn("CROSS JOIN UNNEST to LATERAL VIEW EXPLODE transformation requires explicit column aliases");let N=u.args.offset;N&&I.unshift(N instanceof U?N:new U({this:"pos",quoted:!1}));let P=r(u,{hasMultiExpr:x});for(let k of f)i.append("laterals",new St({this:new P({this:k}),view:!0,alias:new ie({this:y&&($(y.args.this,A)||typeof y.args.this=="string")?y.args.this:void 0,columns:I})}))}}}return i}function g_(i){let e=i.getArgKey("with");for(let t of i.findAll(tt))if(t.parent!==i)if(!e)e=t.pop(),i.setArgKey("with",e);else{t.recursive&&e.setArgKey("recursive",!0);let s=t.findAncestor(Tt);t.pop();let r=t.args.expressions;if(te(e,tt),s){let n=e.args.expressions?.indexOf(s)??-1;e.args.expressions?.splice(n,0,...Rt(r??[],A))}else e.setArgKey("expressions",[...e.args.expressions??[],...Rt(r??[],A)])}return i}function p$(i){if(i instanceof ee)for(let e of i.findAll(Ct)){let t=e.args.this;if(t instanceof z||e.parent instanceof Ut||e.parent instanceof Us)continue;let s=e.parent;if(s instanceof q){let r=new U({this:"x",quoted:!1});e.replace(r);let n=new Yt({this:s.copy(),expressions:[r]});s.replace(new Pi({this:t?.unnest(),expression:n}))}}return i}function l$(i=0){return e=>{if(e instanceof ee){let t=[...e.namedSelects],r=[...new wi({expression:e}).references].map(([u])=>u),n=(u,h)=>{let d=Za(u,h);return u.push(d),d},a=[],o=n(t,"pos"),c=n(r,"_u"),l=Ye(new ge({expressions:[new Fs({start:R.number(i)})]}),c,{table:[o]});for(let u of[...e.selects]){let h=u.find(rs);if(h){let d,x,f;if(u instanceof Re)x=u.alias,f=u;else if(u instanceof kr)d=u.aliases[0],x=u.aliases[1],f=u.replace(new Re({this:u.args.this,alias:""}));else{let Y=new Re({alias:""});u.replace(Y),Y.setArgKey("this",u),f=Y;let He=f.find(rs);He&&(h=He)}let y=h instanceof Ma,I=h.args.this;if(h instanceof zl){let Y=I instanceof A?I.args.expressions?.[0]:void 0;Y instanceof A&&(Y.setArgKey("safe",!0),Y.setArgKey("offset",!0),I=new je({this:"IF",expressions:[new me({this:new je({this:"ARRAY_SIZE",expressions:I!==void 0?[new rt({expressions:[I,new ue({expressions:[]})]})]:void 0}),expression:R.number(0)}),new ue({expressions:[Y.copy()]}),...I!==void 0?[I]:[]]}))}I instanceof B&&t.push(I.outputName);let N=n(r,"_u");x||(x=n(t,"col")),y&&!d&&(d=n(t,"pos")),d||(d=n(t,"pos")),f.setArgKey("alias",new U({this:x,quoted:!1}));let P=l.args.alias?.args.this,k=Z(N),_=(Y,He)=>new B({this:$(Y,U)?Y.copy():Z(Y??""),table:typeof He=="string"?Z(He):He?.copy()}),W=new le({this:_(o,P).eq(_(d,k)),true:_(x,k)});if(h.replace(W),y){let Y=e.args.expressions,He=Y?.indexOf(f)??-1;Y?.splice(He+1,0,Ye(new le({this:_(o,P).eq(_(d,k)),true:_(d,k)}),$(d,U)||typeof d=="string"?d:void 0)),e.setArgKey("expressions",Y)}a.length===0&&(e.args.from?e.join(l,{joinType:"cross",copy:!1}):e.from(l,{copy:!1}));let he=new Bn({this:I instanceof A?I.copy():I});a.push(he),e.join(Ye(new ge({expressions:I!==void 0?[I instanceof A?I.copy():I]:void 0,offset:new U({this:d,quoted:!1})}),N,{table:[$(x,U)||typeof x=="string"?x:""]}),{joinType:"cross",copy:!1});let ne=he;i!==1&&(ne=new Oe({this:new ke({this:he,expression:R.number(1)})})),e.where(_(o,P).eq(_(d,k)).or(new ce({this:new Be({this:_(o,P),expression:ne}),expression:new me({this:_(d,k),expression:ne.copy()})})),{copy:!1})}}if(0<a.length){let u=new ya({this:a[0],expressions:a.slice(1),ignoreNulls:!1});i!==1&&(u=new ke({this:u,expression:R.number(1-i)})),ft(l.args.expressions?.[0],A)?.setArgKey("end",u)}}return e}}function u$(i){if(NN.some(e=>i instanceof e)&&!(i.parent instanceof $t)&&i.args.expression){let e=i,t=e.args.this?.pop();e.setArgKey("this",e.args.expression?.pop());let s=new fe({expressions:[new Ht({this:t,nullsFirst:!1})]});return new $t({this:e,expression:s})}return i}function h$(i){if(i instanceof $t&&NN.some(e=>i.args.this instanceof e)&&i.args.expression instanceof fe){let e=ft(i.args.this,A)?.args.this,t=i.find(Ht),s=t?t.args.this:void 0;return i.replace(new $n({this:s,quantile:e}))}return i}function g$(i){if(i instanceof tt&&i.recursive){let e=fN("_c_");for(let t of i.args.expressions??[]){te(t,Tt);let s=$(t.args.alias,ie)?t.args.alias:void 0;if(!s?.columns.length){let r=t.args.this;r instanceof Xe&&(r=r.args.this),te(r,z),s?.setArgKey("columns",r.selects.map(n=>Z(n.aliasOrName||e())))}}}return i}function E$(i){return(i instanceof X||i instanceof _t)&&i.name.toLowerCase()==="epoch"&&O.TEMPORAL_TYPES.has(ut(ht,(i.args.to instanceof A?i.args.to.args.this?.toString():i.args.to?.toString())??"")??"")&&ft(i.args.this,A)?.replace(R.string("1970-01-01 00:00:00")),i}function A$(i){if(i instanceof ee){let e=i.args.joins||[];for(let t of[...e]){te(t,oe);let s=t.args.on;if(s&&(t.args.kind==="semi"||t.args.kind==="anti")){let r=pt("1").from(t.args.this).where(s),n=new Pi({this:r});t.args.kind==="anti"&&(n=n.not()),t.pop(),i.where(n,{copy:!1})}}}return i}function d$(i){if(i instanceof ee){let e=i.args.joins||[],s=Rt(e,oe).map((r,n)=>({index:n,join:r})).filter(({join:r})=>r.args.side==="full");if(s.length===1){let r=i.copy();i.setArgKey("limit",void 0);let{index:n,join:a}=s[0],o=i.args.from?.aliasOrName,c=a.aliasOrName,l=a.args.on||new ce({expressions:(a.args.using||[]).map(x=>new me({this:new B({this:x,table:o}),expression:new B({this:x,table:c})}))});a.setArgKey("side","left");let u=pt("1").from(i.args.from).where(l);r.args.joins?.[n]?.setArgKey("side","right");let d=new Pi({this:u}).not();return r.where(d),r.setArgKey("with",void 0),i.setArgKey("order",void 0),UA([i,r],{distinct:!1})??i}}return i}function E_(i){let e=t=>{(t.isNumber||!(t instanceof $s)&&t.isType(["unknown",...O.NUMERIC_TYPES])||t instanceof B&&!t.type)&&t.replace(t.neq(0))};for(let t of i.walk())YI(t,e);return i}function x$(i){for(let e of i.findAll(B)){let t=e.parts;for(let s=0;s<t.length-1;s++)t[s].pop()}return i}function f$(i){if(!(i instanceof qt))return i;for(let e of i.findAll(ln))e.parent&&e.parent.pop();return i}function T$(i,e=t=>t){if(!(i instanceof qt))return i;let s=i.args.properties?.args.expressions?.some(r=>r instanceof ds);return i.kind==="table"&&s?i.args.expression?new qt({kind:"temporary view",this:i.args.this,expression:i.args.expression}):e(i):i}function S$(i){if(!(i instanceof qt))return i;let e=i.args.this instanceof At,t=i.kind==="table"||i.kind==="view";if(e&&t){let s=i.find(os);if(s&&s.args.this&&!(s.args.this instanceof At)){let r=i.args.this;te(r,At);let n=new Set(s.args.this.args.expressions?.map(o=>o instanceof A?o.name.toUpperCase():o.toString())),a=r.args.expressions?.filter(o=>n.has(o.name.toUpperCase()));r.setArgKey("expressions",r.args.expressions?.filter(o=>!a?.includes(o))),s.replace(new os({this:new At({expressions:Rt(a??[],A)})})),i.setArgKey("this",r)}}return i}function m$(i){if(!(i instanceof qt))return i;let e=i.find(os);if(e&&e.args.this instanceof At&&e.args.this.args.expressions?.every(t=>t instanceof Ie&&t.kind)){let t=new Ge({expressions:e.args.this.args.expressions.map(r=>{let n=r.args.this;return n instanceof A?Z($(n,U)?n:n.name):Z(n?.toString()??"")})}),s=i.args.this;for(let r of e.args.this.args.expressions)s.append("expressions",r);e.setArgKey("this",t)}return i}function O$(i){if(i instanceof ee&&i.args.windows){let e=i.args.windows;i.setArgKey("windows",void 0);let t={},s=r=>{let n=r.alias?.toLowerCase();if(n===void 0)return;let a=t[n];if(a){r.setArgKey("alias",void 0);for(let o of["partitionBy","order","spec"]){let c=a.getArgKey(o);c instanceof A&&r.setArgKey(o,c.copy()),Array.isArray(c)&&0<c.length&&r.setArgKey(o,[...c])}}};for(let r of e)s(r),t[r.name.toLowerCase()]=r;for(let r of jn(i,[we]))s(r)}return i}function R$(i){if(i instanceof ue&&i.args.structNameInheritance&&i.args.expressions?.[0]instanceof ks){let e=i.args.expressions[0];if(!e.args.expressions?.every(s=>s instanceof ct))return i;let t=e.args.expressions.map(s=>s.args.this);for(let s of i.args.expressions.slice(1)){if(!(s instanceof ks)||s.args.expressions?.length!==t.length)continue;let r=s.args.expressions.map((n,a)=>{if(!(n instanceof ct)){let o=t[a],c=o instanceof A?o.args.this:o,l=new ct({this:new U({this:c instanceof A?c.copy():c?.toString()||"",quoted:!1}),expression:n});return l.type=n.type,l}return n});s.setArgKey("expressions",r)}}return i}var FU=/\\(\d+)/g;function dT(i,...e){let t=i._constructor.name,s=this.dialect._constructor.name;for(let r of e){let[n,a]=typeof r=="string"?[r,void 0]:r;i.getArgKey(n)&&this.unsupported(a??`Argument '${n}' is not supported for expression '${t}' when targeting ${s}.`)}}var A_,d_,x_,f_,T_,S_,m_,O_,R_,N_,I_,y_,Ss;y_=[m,m],I_=[m],N_=[m],R_=[m],O_=[m],m_=[m],S_=[m],T_=[m],f_=[m],x_=[m],d_=[m],A_=[m];var b=class{constructor(e={}){this.pretty=void 0;this.identify=void 0;this.normalize=void 0;this.pad=void 0;this.indentAmount=void 0;this.normalizeFunctions=void 0;this.unsupportedLevel=void 0;this.maxUnsupported=void 0;this.leadingComma=void 0;this.maxTextWidth=void 0;this.comments=void 0;this.dialect=void 0;this.unsupportedMessages=void 0;this.escapedQuoteEnd=void 0;this.nextName=void 0;this.escapedByteQuoteEnd=void 0;this.escapedIdentifierEnd=void 0;this.identifierStart=void 0;this.identifierEnd=void 0;this.quoteJsonPathKeyUsingBrackets=void 0;this.pretty=e.pretty??!1,this.identify=e.identify??!1,this.normalize=e.normalize??!1,this.pad=e.pad??2,this.indentAmount=e.indent??2,this.unsupportedLevel=e.unsupportedLevel??1,this.maxUnsupported=e.maxUnsupported??3,this.leadingComma=e.leadingComma??!1,this.maxTextWidth=e.maxTextWidth??80,this.comments=e.comments??!0,this.dialect=se.getOrRaise(e.dialect);let t=this.dialect._constructor;this.normalizeFunctions=e.normalizeFunctions??t.NORMALIZE_FUNCTIONS??"upper";let s=t.tokenizerClass.STRING_ESCAPES,r=s&&0<s.length?s[0]:"";this.escapedQuoteEnd=r+this.dialect._constructor.QUOTE_END,this.escapedByteQuoteEnd=this.dialect._constructor.BYTE_END?r+this.dialect._constructor.BYTE_END:"",this.escapedIdentifierEnd=this.dialect._constructor.IDENTIFIER_END+this.dialect._constructor.IDENTIFIER_END,this.identifierStart=this.dialect._constructor.IDENTIFIER_START,this.identifierEnd=this.dialect._constructor.IDENTIFIER_END,this.unsupportedMessages=[],this.nextName=fN("_t"),this.quoteJsonPathKeyUsingBrackets=!0}static get NULL_ORDERING_SUPPORTED(){return"supported"}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([...ON])}static get UNWRAPPED_INTERVAL_VALUES(){return new Set([B,R,It,Oe])}static get WITH_SEPARATED_COMMENTS(){return new Set([Ws,qt,Vi,Js,Ji,Je,kt,oe,Zi,fe,Xs,Zt,ee,Xe,Vt,at,tt])}static get EXCLUDE_COMMENTS(){return new Set([q,Xe])}static get TYPE_MAPPING(){return new Map([["datetime2","TIMESTAMP"],["nchar","CHAR"],["nvarchar","VARCHAR"],["mediumtext","TEXT"],["longtext","TEXT"],["tinytext","TEXT"],["blob","VARBINARY"],["mediumblob","BLOB"],["longblob","BLOB"],["tinyblob","BLOB"],["inet","INET"],["rowversion","VARBINARY"],["smalldatetime","TIMESTAMP"]])}static get UNSUPPORTED_TYPES(){return new Set}static get PARAMETERIZABLE_TEXT_TYPES(){return new Set(["nvarchar","varchar","char","nchar"])}static get TOKEN_MAPPING(){return{}}static get ORIGINAL_TRANSFORMS(){return new Map([[ip,function(e){return this.binary(e,"-|-")}],[Dr,function(e){return`ALLOWED_VALUES ${this.expressions(e,{flat:!0})}`}],[nn,function(e){return this.sql(e,"this")}],[rn,function(e){return this.expressions(e,{prefix:"WITH ",sep:" "})}],[lo,function(e){return this.binary(e,"@>")}],[TT,function(e){return this.binary(e,"&&")}],[vr,function(e){return`AUTO REFRESH ${this.sql(e,"this")}`}],[Fr,function(e){return`BACKUP ${this.sql(e,"this")}`}],[Pr,e=>`${e.getArgKey("not")?"NOT ":""}CASESPECIFIC`],[Oa,function(e){return this.ceilFloor(e)}],[Uc,function(e){return`CHARACTER SET ${this.sql(e,"this")}`}],[ir,function(e){return`${e.getArgKey("default")?"DEFAULT ":""}CHARACTER SET=${this.sql(e,"this")}`}],[vc,function(e){return`CLUSTERED (${this.expressions(e,{key:"this",indent:!1})})`}],[Fc,function(e){return`COLLATE ${this.sql(e,"this")}`}],[Bc,function(e){return`COMMENT ${this.sql(e,"this")}`}],[Ul,function(e){return`CONNECT_BY_ROOT ${this.sql(e,"this")}`}],[fT,function(e){return this.func("CONVERT",[e.args.this,e.args.dest,e.args.source])}],[$r,()=>"COPY GRANTS"],[va,function(e){return`CREDENTIALS=(${this.expressions(e,{key:"expressions",sep:" "})})`}],[Ql,()=>"CURRENT_CATALOG"],[ST,()=>"SESSION_USER"],[$c,function(e){return`FORMAT ${this.sql(e,"this")}`}],[Gc,function(e){return`DEFAULT ${this.sql(e,"this")}`}],[ri,()=>"DYNAMIC"],[ii,()=>"EMPTY"],[Yc,function(e){return`ENCODE ${this.sql(e,"this")}`}],[ti,function(e){return`ENVIRONMENT (${this.expressions(e,{flat:!0})})`}],[xa,function(e){return`EPHEMERAL${e.args.this?" "+this.sql(e,"this"):""}`}],[Vc,function(e){return`EXCLUDE ${this.sql(e,"this").trimStart()}`}],[Ms,function(e){return this.nakedProperty(e)}],[wr,function(e){return this.setOperations(e)}],[Xr,()=>"EXTERNAL"],[Bl,function(e){return this.ceilFloor(e)}],[lp,function(e){return this.getPutSql(e)}],[zr,()=>"GLOBAL"],[jr,()=>"HEAP"],[Qr,()=>"ICEBERG"],[Zr,function(e){return`INHERITS (${this.expressions(e,{flat:!0})})`}],[Wc,function(e){return`INLINE LENGTH ${this.sql(e,"this")}`}],[Kr,function(e){return`INPUT${this.sql(e,"this")}`}],[kn,function(e){return this.setOperations(e)}],[Ks,function(e){return`${this.sql(e,"this")} TO ${this.sql(e,"expression")}`}],[eu,function(e){return this.sql(j(e.args.this||"","bigint"))}],[qn,function(e){return this.binary(e,"?|")}],[Un,function(e){return this.binary(e,"?&")}],[vn,function(e){return this.binary(e,"#-")}],[xs,function(e){return`?${e.args.this}`}],[cr,function(e){return`..${e.args.this||""}`}],[cs,()=>"$"],[fs,function(e){return`(${e.args.this}`}],[lr,function(e){return`[${this.jsonPathPart(e.args.this)}]`}],[pr,function(e){return[e.args.start,e.args.end,e.args.step].filter(t=>t!==void 0).map(t=>t===!1?"":this.jsonPathPart(t)).join(":")}],[vs,function(e){return`[${(e.args.expressions??[]).map(s=>this.jsonPathPart(s)).join(",")}]`}],[Pt,()=>"*"],[nr,function(e){return this.nakedProperty(e)}],[ar,function(e){return this.nakedProperty(e)}],[ni,e=>`${e.getArgKey("no")?"NO ":""}LOG`],[ai,()=>"MATERIALIZED"],[NT,function(e){return`NET.${this.sql(e,"this")}`}],[jc,function(e){return`NONCLUSTERED (${this.expressions(e,{key:"this",indent:!1})})`}],[oi,()=>"NO PRIMARY INDEX"],[pn,()=>"NOT FOR REPLICATION"],[Qs,e=>`ON COMMIT ${e.getArgKey("delete")?"DELETE":"PRESERVE"} ROWS`],[zs,function(e){return`ON ${this.sql(e,"this")}`}],[Jc,function(e){return`ON UPDATE ${this.sql(e,"this")}`}],[_n,function(e){return this.binary(e,"")}],[ei,function(e){return`OUTPUT${this.sql(e,"this")}`}],[ep,function(e){return this.binary(e,"&<")}],[tp,function(e){return this.binary(e,"&>")}],[Qc,function(e){return`PATH ${this.sql(e,"this")}`}],[In,function(e){return this.func("BUCKET",[e.args.this,e.args.expression])}],[yn,function(e){return this.func("TRUNCATE",[e.args.this,e.args.expression])}],[Cr,function(e){return`ANY${this.sql(e,"this")}`}],[up,function(e){return`#${this.sql(e,"this")}`}],[vA,function(e){return`PROJECTION POLICY ${this.sql(e,"this")}`}],[gp,()=>"ZEROFILL"],[Da,function(e){return this.getPutSql(e)}],[pi,function(e){return`REMOTE WITH CONNECTION ${this.sql(e,"this")}`}],[or,function(e){return e.getArgKey("null")?"RETURNS NULL ON NULL INPUT":this.nakedProperty(e)}],[xT,function(e){return`SAFE.${this.sql(e,"this")}`}],[hi,function(e){return`SAMPLE BY ${this.sql(e,"this")}`}],[Ti,()=>"SECURE"],[gi,function(e){return`SECURITY ${this.sql(e,"this")}`}],[ka,function(e){return this.sql(e,"this")}],[Zs,e=>`${e.getArgKey("multi")?"MULTI":""}SET`],[di,function(e){return`SETTINGS${this.seg("")}${this.expressions(e)}`}],[Ai,function(e){return`SHARING=${this.sql(e,"this")}`}],[Es,e=>e.name],[fi,function(e){return`SQL SECURITY ${this.sql(e,"this")}`}],[As,e=>e.name],[on,function(e){return`STREAM ${this.sql(e,"this")}`}],[ci,()=>"STREAMING"],[li,()=>"STRICT"],[Wi,function(e){return`SWAP WITH ${this.sql(e,"this")}`}],[Mi,function(e){return this.sql(e.args.this)}],[_a,function(e){return`TAG (${this.expressions(e,{flat:!0})})`}],[ds,()=>"TEMPORARY"],[zc,function(e){return`TITLE ${this.sql(e,"this")}`}],[tu,function(e){return`MAP ${this.sql(e,"this")}`}],[Jr,function(e){return`TO ${this.sql(e.args.this)}`}],[Si,function(e){return this.func("TRANSFORM",e.args.expressions||[])}],[mi,()=>"TRANSIENT"],[Lr,function(e){return this.setOperations(e)}],[Oi,()=>"UNLOGGED"],[qa,function(e){return`USING TEMPLATE ${this.sql(e,"this")}`}],[an,function(e){return`USING DATA ${this.sql(e,"this")}`}],[un,()=>"UPPERCASE"],[mT,function(e){return this.sql(new $i({this:R.string("UTC")}))}],[OT,function(e){return this.sql(new Ra({this:R.string("UTC")}))}],[RT,function(e){return this.sql(new Na({this:R.string("UTC")}))}],[hp,function(e){return`VARIADIC ${this.sql(e,"this")}`}],[Ys,function(e){return this.func("MAP",[e.args.keys,e.args.values])}],[Ri,function(e){return`WITH ${this.sql(e,"this")}`}],[Ni,()=>"VOLATILE"],[Ii,function(e){return`WITH JOURNAL TABLE=${this.sql(e,"this")}`}],[Ci,function(e){return`WITH ${this.expressions(e,{flat:!0})}`}],[yi,function(e){return`WITH SCHEMA ${this.sql(e,"this")}`}],[ji,function(e){return`${this.sql(e,"this")} WITH ${this.sql(e,"op")}`}],[Ua,()=>"FORCE"]])}static get TRANSFORMS(){let e=new Map(this.ORIGINAL_TRANSFORMS);for(let t of Array.from(ON).filter(s=>!this.SUPPORTED_JSON_PATH_PARTS.has(s)))e.delete(t);return e}static get PROPERTIES_LOCATION(){return new Map([[Dr,"postSchema"],[qr,"postCreate"],[Ur,"postSchema"],[vr,"postSchema"],[Fr,"postSchema"],[hn,"postName"],[ir,"postSchema"],[gn,"postName"],[Br,"postSchema"],[$r,"postSchema"],[Nr,"postSchema"],[si,"postSchema"],[Vr,"postSchema"],[dn,"postSchema"],[En,"postName"],[An,"postSchema"],[Gr,"postCreate"],[On,"postSchema"],[mn,"postSchema"],[ri,"postCreate"],[Yr,"postSchema"],[Hr,"postSchema"],[ii,"postSchema"],[Ba,"postExpression"],[Wr,"postSchema"],[ti,"postSchema"],[Ms,"postSchema"],[Xr,"postCreate"],[xn,"postName"],[ws,"postWith"],[fn,"postName"],[zr,"postCreate"],[jr,"postWith"],[Zr,"postSchema"],[Qr,"postCreate"],[$a,"postSchema"],[Kr,"postSchema"],[Tn,"postName"],[Sn,"postName"],[nr,"postSchema"],[Rn,"postSchema"],[ar,"postSchema"],[Fa,"postSchema"],[Nn,"postAlias"],[ni,"postName"],[ai,"postCreate"],[br,"postName"],[oi,"postExpression"],[zs,"postSchema"],[Qs,"postExpression"],[fe,"postSchema"],[ei,"postSchema"],[os,"postWith"],[Cn,"postSchema"],[zi,"postSchema"],[L,"postWith"],[Ap,"postSchema"],[pi,"postSchema"],[or,"postSchema"],[Ep,"unsupported"],[ui,"postSchema"],[Pn,"postSchema"],[bn,"postSchema"],[hi,"postSchema"],[Ei,"postSchema"],[Ti,"postCreate"],[gi,"postSchema"],[Ln,"postSchema"],[Hi,"postSchema"],[di,"postSchema"],[Zs,"postCreate"],[ka,"postSchema"],[Ai,"postExpression"],[Hs,"postExpression"],[xi,"postSchema"],[Es,"postSchema"],[fi,"postCreate"],[As,"postSchema"],[wn,"postSchema"],[ci,"postCreate"],[li,"postSchema"],[_a,"postWith"],[ds,"postCreate"],[Jr,"postSchema"],[mi,"postCreate"],[Si,"postSchema"],[Ir,"postSchema"],[Oi,"postCreate"],[qa,"postSchema"],[Ri,"postSchema"],[Ni,"postCreate"],[Mn,"postExpression"],[Ii,"postName"],[Ci,"postSchema"],[yi,"postSchema"],[Dn,"postSchema"],[Ua,"postCreate"]])}get _constructor(){return this.constructor}generate(e,t={}){let{copy:s=!0}=t,r=s?e.copy():e;r=this.preprocess(r),this.unsupportedMessages=[];let n=this.sql(r).trim();if(this.pretty&&(n=n.replaceAll(this._constructor.SENTINEL_LINE_BREAK,`
6
+ `)),this.unsupportedLevel===0)return n;if(this.unsupportedLevel===1)for(let a of this.unsupportedMessages)console.warn(a);else if(this.unsupportedLevel===2&&0<this.unsupportedMessages.length)throw new Wn(nN(this.unsupportedMessages,this.maxUnsupported));return n}preprocess(e){return e=this.moveCtesToTopLevel(e),this._constructor.ENSURE_BOOLS&&(e=E_(e)),e}moveCtesToTopLevel(e){return!e.parent&&this.constructor.EXPRESSIONS_WITHOUT_NESTED_CTES.has(e._constructor)&&[...e.findAll(tt)].some(t=>t.parent!==e)?g_(e):e}unsupported(e){if(this.unsupportedLevel===3)throw new Wn(e);this.unsupportedMessages.push(e)}sep(e=" "){return this.pretty?`${e.trim()}
7
+ `:e}seg(e,t=" "){return`${this.sep(t)}${e}`}sanitizeComment(e){let t=e;return t[0]&&t[0].trim()!==""&&(t=" "+t),t[t.length-1]&&t[t.length-1].trim()!==""&&(t=t+" "),this.dialect._constructor.tokenizerClass.NESTED_COMMENTS||(t=t.replace(/\*\//g,"* /")),t}wrap(e){let t;return typeof e!="string"&&Er.some(s=>e instanceof s)?t=this.sql(e):t=this.sql(e,"this"),t?(t=this.indent(t,{level:1,pad:0}),`(${this.sep("")}${t}${this.seg(")","")}`):"()"}noIdentify(e,...t){let s=this.identify;this.identify=!1;let r=e(...t);return this.identify=s,r}normalizeFunc(e){return this.normalizeFunctions==="upper"?e.toUpperCase():this.normalizeFunctions==="lower"?e.toLowerCase():e}indent(e,t={}){let{skipFirst:s=!1,skipLast:r=!1,pad:n=this.pad,level:a=0}=t;if(!this.pretty||!e)return e;let o=e.split(`
8
+ `);return o.map((c,l)=>s&&l===0||r&&l===o.length-1?c:`${" ".repeat(a*this.indentAmount+n)}${c}`).join(`
9
+ `)}sql(e,t,s={}){let{comment:r=!0}=s;if(e===void 0)return"";if(typeof e=="number"||typeof e=="string"||typeof e=="boolean")return e.toString();if(Array.isArray(e))return e.map(o=>this.sql(o)).join(", ");if(t){let o=e.getArgKey(t);return o&&(typeof o=="string"||o instanceof A)?this.sql(o):""}let n=this._constructor.TRANSFORMS.get(e._constructor),a="";if(n instanceof Function)a=n.call(this,e);else if(e instanceof A){let o=`${e._constructor.key}Sql`,c=this[o];if(c instanceof Function)a=c.call(this,e);else if(e instanceof g||$f.has(e._constructor))a=this.functionFallbackSql(e);else if(e instanceof L)a=this.propertySql(e);else throw new Error(`Unsupported expression type ${e._constructor.name}`)}else throw new Error(`Expected an Expression. Received ${typeof e}: ${e}`);return this.comments&&r?this.maybeComment(a,e):a}maybeComment(e,t,s,r=!1){let n=this.comments?s!==void 0?s:t?.comments:void 0;if(!n||n.length===0||t&&[...this._constructor.EXCLUDE_COMMENTS].some(c=>t instanceof c))return e;let a=n.filter(c=>c).map(c=>`/*${this.sanitizeComment(c)}*/`).join(" ");if(!a)return e;let o=this.replaceLineBreaks(a);return r||t&&[...this._constructor.WITH_SEPARATED_COMMENTS].some(c=>t instanceof c)?!e||e[0]===" "||e[0]===`
10
+ `?`${this.sep()}${o}${e}`:`${o}${this.sep()}${e}`:`${e} ${o}`}uncacheSql(e){let t=this.sql(e,"this");return`UNCACHE TABLE${e.args.exists?" IF EXISTS":""} ${t}`}cacheSql(e){let t=e.args.lazy?" LAZY":"",s=this.sql(e,"this"),r=e.args.options,n=r?.length?` OPTIONS(${this.sql(r[0])} = ${this.sql(r[1])})`:"",a=this.sql(e,"expression");return a=a?` AS${this.sep()}${a}`:"",a=`CACHE${t} TABLE ${s}${n}${a}`,this.prependCtes(e,a)}characterSetSql(e){return e.parent instanceof X?`CHAR CHARACTER SET ${this.sql(e,"this")}`:`${e.args.default?"DEFAULT ":""}CHARACTER SET=${this.sql(e,"this")}`}columnParts(e){return[e.args.catalog,e.args.db,e.args.table,e.args.this].filter(Boolean).map(s=>this.sql(s)).join(".")}columnSql(e){let t=e.args.joinMark?" (+)":"";return t&&!this.dialect._constructor.SUPPORTS_COLUMN_JOIN_MARKS?(this.unsupported("Outer join syntax using the (+) operator is not supported."),this.columnParts(e)):`${this.columnParts(e)}${t}`}pseudocolumnSql(e){return this.columnSql(e)}columnPositionSql(e){let t=this.sql(e,"this"),s=t?` ${t}`:"";return`${this.sql(e,"position")}${s}`}columnDefSql(e,t={}){let{sep:s=" "}=t,r=this.sql(e,"this"),n=this.sql(e,"kind"),a=this.expressions(e,{key:"constraints",sep:" ",flat:!0}),o=e.args.exists?"IF NOT EXISTS ":"";n=n?`${s}${n}`:"";let c=a?` ${a}`:"",l=this.sql(e,"position");return l=l?` ${l}`:"",0<Array.from(e.findAll(Fi)).length&&!this._constructor.COMPUTED_COLUMN_WITH_TYPE&&(n=""),`${o}${r}${n}${c}${l}`}columnConstraintSql(e){let t=this.sql(e,"this"),s=this.sql(e,"kind").trim();return t?`CONSTRAINT ${t} ${s}`:s}computedColumnConstraintSql(e){let t=this.sql(e,"this"),s;return e.args.notNull?s=" PERSISTED NOT NULL":e.args.persisted?s=" PERSISTED":s="",`AS ${t}${s}`}autoIncrementColumnConstraintSql(e){return this.tokenSql("autoIncrement")}compressColumnConstraintSql(e){let t;return Array.isArray(e.args.this)?t=this.wrap(this.expressions(e,{key:"this",flat:!0})):t=this.sql(e,"this"),`COMPRESS ${t}`}generatedAsIdentityColumnConstraintSql(e){let t="";if(e.args.this!==void 0){let y=e.args.onNull?" ON NULL":"";t=e.args.this?" ALWAYS":` BY DEFAULT${y}`}let s=e.args.start,r=s?`START WITH ${s}`:"",n=e.args.increment,a=n?` INCREMENT BY ${n}`:"",o=e.args.minvalue,c=o?` MINVALUE ${o}`:"",l=e.args.maxvalue,u=l?` MAXVALUE ${l}`:"",h=e.args.cycle,d="";h!==void 0&&(d=`${h?"":" NO"} CYCLE`,d=!r&&!a?d.trim():d);let x="";(r||a||d)&&(x=`${r}${a}${c}${u}${d}`,x=` (${x.trim()})`);let f=this.sql(e,"expression");return f=f?`(${f})`:"IDENTITY",`GENERATED${t} AS ${f}${x}`}generatedAsRowColumnConstraintSql(e){let t=e.args.start?"START":"END",s=e.args.hidden?" HIDDEN":"";return`GENERATED ALWAYS AS ROW ${t}${s}`}periodForSystemTimeConstraintSql(e){return`PERIOD FOR SYSTEM_TIME (${this.sql(e,"this")}, ${this.sql(e,"expression")})`}notNullColumnConstraintSql(e){return e.args.allowNull?"NULL":"NOT NULL"}primaryKeyColumnConstraintSql(e){let t=e.args.desc;if(t!==void 0)return`PRIMARY KEY${t?" DESC":" ASC"}`;let s=this.expressions(e,{key:"options",flat:!0,sep:" "});return s=s?` ${s}`:"",`PRIMARY KEY${s}`}uniqueColumnConstraintSql(e){let t=this.sql(e,"this");t=t?` ${t}`:"";let s=e.args.indexType,r=s?` USING ${s}`:"",n=this.sql(e,"onConflict");n=n?` ${n}`:"";let a=e.args.nulls?" NULLS NOT DISTINCT":"",o=this.expressions(e,{key:"options",flat:!0,sep:" "});return o=o?` ${o}`:"",`UNIQUE${a}${t}${r}${n}${o}`}inOutColumnConstraintSql(e){let t=e.args.input,s=e.args.output;return e.args.variadic?"VARIADIC":t&&s?`IN${this._constructor.INOUT_SEPARATOR}OUT`:t?"IN":s?"OUT":""}createableSql(e,t){return this.sql(e,"this")}createSql(e){let t=this.sql(e,"kind").toUpperCase();t=this.dialect._constructor.INVERSE_CREATABLE_KIND_MAPPING[t]??t;let s=e.args.properties;s&&te(s,Ke);let r=s?this.locateProperties(s):new Map,n=this.createableSql(e,r),a="",o=r.get("postSchema"),c=r.get("postWith");if(o||c){let lt=new Ke({expressions:[...o??[],...c??[]]});lt.parent=e,a=this.sql(lt),o?a=this.sep()+a:this.pretty||(a=` ${a}`)}let l=e.args.begin?" BEGIN":"",u=e.args.end?" END":"",h=this.sql(e,"expression");if(h&&(h=`${l}${this.sep()}${h}${u}`,this._constructor.CREATE_FUNCTION_RETURN_AS||!(e.args.expression instanceof en))){let lt="",ps=r.get("postAlias");ps&&(lt=this.properties(new Ke({expressions:ps}),{wrapped:!1})),lt=lt?` ${lt}`:"",h=` AS${lt}${h}`}let d="",x=r.get("postIndex");x&&(d=this.properties(new Ke({expressions:x}),{wrapped:!1,prefix:" "}));let f=this.expressions(e,{key:"indexes",indent:!1,sep:" "});f=f?` ${f}`:"";let y=f+d,I=e.args.replace?" OR REPLACE":"",N=e.args.refresh?" OR REFRESH":"",P=e.args.unique?" UNIQUE":"",k=e.args.clustered,_="";k===void 0?_="":k?_=" CLUSTERED COLUMNSTORE":_=" NONCLUSTERED COLUMNSTORE";let W="",he=r.get("postCreate");he&&(W=this.properties(new Ke({expressions:he}),{sep:" ",prefix:" ",wrapped:!1}));let ne=`${_}${I}${N}${P}${W}`,Y="",He=r.get("postExpression");He&&(Y=this.properties(new Ke({expressions:He}),{sep:" ",prefix:" ",wrapped:!1}));let ve=e.args.concurrently?" CONCURRENTLY":"",Xt=e.args.exists?" IF NOT EXISTS":"",Ft=e.args.noSchemaBinding?" WITH NO SCHEMA BINDING":"",Li=this.sql(e,"clone");Li=Li?` ${Li}`:"";let zt;return this._constructor.EXPRESSION_PRECEDES_PROPERTIES_CREATABLES.has(t)?zt=`${h}${a}`:zt=`${a}${h}`,h=`CREATE${ne} ${t}${ve}${Xt} ${n}${zt}${Y}${y}${Ft}${Li}`,this.prependCtes(e,h)}sequencePropertiesSql(e){let t=this.sql(e,"start");t=t?`START WITH ${t}`:"";let s=this.sql(e,"increment");s=s?` INCREMENT BY ${s}`:"";let r=this.sql(e,"minvalue");r=r?` MINVALUE ${r}`:"";let n=this.sql(e,"maxvalue");n=n?` MAXVALUE ${n}`:"";let a=this.sql(e,"owned");a=a?` OWNED BY ${a}`:"";let o=e.args.cache,c="";o===void 0?c="":o===!0?c=" CACHE":c=` CACHE ${o}`;let l=this.expressions(e,{key:"options",flat:!0,sep:" "}),u=l?` ${l}`:"";return`${t}${s}${r}${n}${c}${u}${a}`.trimStart()}cloneSql(e){let t=this.sql(e,"this"),s=e.args.shallow?"ShaLLOW ":"",r=e.args.copy&&this._constructor.SUPPORTS_TABLE_COPY?"COPY":"CLONE";return`${s}${r} ${t}`}describeSql(e){let t=e.args.style,s=t?` ${t}`:"",r=this.sql(e,"partition");r=r?` ${r}`:"";let n=this.sql(e,"format");n=n?` ${n}`:"";let a=e.args.asJson?" AS JSON":"";return`DESCRIBE${s}${n} ${this.sql(e,"this")}${r}${a}`}heredocSql(e){let t=this.sql(e,"tag");return`$${t}$${this.sql(e,"this")}$${t}$`}prependCtes(e,t){let s=this.sql(e,"with");return s?`${s}${this.sep()}${t}`:t}withSql(e){let t=this.expressions(e,{flat:!0}),s=this._constructor.CTE_RECURSIVE_KEYWORD_REQUIRED&&e.args.recursive?"RECURSIVE ":"",r=this.sql(e,"search");return r=r?` ${r}`:"",`WITH ${s}${t}${r}`}cteSql(e){let t=e.args.alias;t&&t.addComments?.(e.popComments());let s=this.sql(e,"alias"),r=e.args.materialized,n="";r===!1?n="NOT MATERIALIZED ":r&&(n="MATERIALIZED ");let a=this.expressions(e,{key:"keyExpressions",flat:!0}),o=a?` USING KEY (${a})`:"";return`${s}${o} AS ${n}${this.wrap(e)}`}tableAliasSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{key:"columns",flat:!0});return s=s?`(${s})`:"",s&&!this._constructor.SUPPORTS_TABLE_ALIAS_COLUMNS&&(s="",this.unsupported("Named columns are not supported in table alias.")),!t&&!this.dialect._constructor.UNNEST_COLUMN_ONLY&&(t=this.nextName()),`${t}${s}`}bitStringSql(e){let t=this.sql(e,"this");return this.dialect._constructor.BIT_START?`${this.dialect._constructor.BIT_START}${t}${this.dialect._constructor.BIT_END}`:`${parseInt(t,2)}`}hexStringSql(e,t={}){let{binaryFunctionRepr:s}=t,r=this.sql(e,"this"),n=e.args.isInteger;if(n&&!this.dialect._constructor.HEX_STRING_IS_INTEGER_TYPE||!this.dialect._constructor.HEX_START&&!s)return`${parseInt(r,16)}`;if(!n){if(s)return this.func(s,[ml(r)]);this.dialect._constructor.HEX_STRING_IS_INTEGER_TYPE&&this.unsupported("Unsupported transpilation from BINARY/BLOB hex string")}return`${this.dialect._constructor.HEX_START}${r}${this.dialect._constructor.HEX_END}`}byteStringSql(e){let t=this.sql(e,"this");if(this.dialect._constructor.BYTE_START){let s=this.escapeStr(t,{escapeBackslash:!1,delimiter:this.dialect._constructor.BYTE_END,escapedDelimiter:this.escapedByteQuoteEnd,isByteString:!0}),r=e.args.isBytes||!1,n=`${this.dialect._constructor.BYTE_START}${s}${this.dialect._constructor.BYTE_END}`;return r&&!this.dialect._constructor.BYTE_STRING_IS_BYTES_TYPE?this.sql(j(n,"BINARY",{dialect:this.dialect})):!r&&this.dialect._constructor.BYTE_STRING_IS_BYTES_TYPE?this.sql(j(n,"VARCHAR",{dialect:this.dialect})):n}return t}unicodeStringSql(e){let t=this.sql(e,"this"),s=e.args.escape,r,n,a;this.dialect._constructor.UNICODE_START?(r="\\$1",n=this.dialect._constructor.UNICODE_START,a=this.dialect._constructor.UNICODE_END):(r="\\u$1",n=this.dialect._constructor.QUOTE_START,a=this.dialect._constructor.QUOTE_END);let o,c;s?(o=new RegExp(`${s.name}(\\d+)`,"g"),c=this._constructor.SUPPORTS_UESCAPE?` UESCAPE ${this.sql(s)}`:""):(o=FU,c="");let l=t;if(!this.dialect._constructor.UNICODE_START||s&&!this._constructor.SUPPORTS_UESCAPE){let u=this._constructor.UNICODE_SUBSTITUTE||r;l=l.replace(o,u)}return`${n}${l}${a}${c}`}rawStringSql(e){let t=e.args.this?.toString()||"";return this.dialect._constructor.tokenizerClass.STRING_ESCAPES.includes("\\")&&(t=t?.replace(/\\/g,"\\\\")),t=this.escapeStr(t,{escapeBackslash:!1}),`${this.dialect._constructor.QUOTE_START}${t}${this.dialect._constructor.QUOTE_END}`}dataTypeParamSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression"),r=s&&this._constructor.DATA_TYPE_SPECIFIERS_ALLOWED?` ${s}`:"";return`${t}${r}`}dataTypeSql(e){let t="",s="",r=e.args.nested,n=r&&this.pretty?this.expressions(e,{dynamic:!0,newLine:!0,skipFirst:!0,skipLast:!0}):this.expressions(e,{flat:!0}),a=e.args.this;typeof a=="string"&&this._constructor.UNSUPPORTED_TYPES.has(a)&&this.unsupported(`Data type ${a} is not supported when targeting ${this.dialect._constructor.name}`);let o;if(a instanceof A)o=this.sql(a);else if(a==="user-defined"&&e.args.kind)o=this.sql(e,"kind");else{let c=a&&this._constructor.TYPE_MAPPING.get(a),l=a!==void 0&&Object.values(ht).includes(a);o=c!==void 0?c:a&&(l?SN(a):a)}if(n)if(r){let c=this._constructor.STRUCT_DELIMITER;if(t=`${c[0]}${n}${c[1]}`,e.args.values?.length){let l=a==="array"?["[","]"]:["(",")"],u=this.expressions(e,{key:"values",flat:!0});s=`${l[0]}${u}${l[1]}`}}else a==="interval"?t=` ${n}`:t=`(${n})`;return o=`${o}${t}${s}`,this._constructor.TZ_TO_WITH_TIME_ZONE&&(a==="timetz"||a==="timestamptz")&&(o=`${o} WITH TIME ZONE`),o}directorySql(e){let t=e.args.local?"LOCAL ":"",s=this.sql(e,"rowFormat");return s=s?` ${s}`:"",`${t}DIRECTORY ${this.sql(e,"this")}${s}`}deleteSql(e){let t=this.sql(e,"this"),s=t?` FROM ${t}`:"",r=this.expressions(e,{key:"using"});r=r?` USING ${r}`:"";let n=this.sql(e,"cluster");n=n?` ${n}`:"";let a=this.sql(e,"where"),o=this.sql(e,"returning"),c=this.sql(e,"order"),l=this.sql(e,"limit"),u=this.expressions(e,{key:"tables"});u=u?` ${u}`:"";let h;return this._constructor.RETURNING_END?h=`${s}${r}${n}${a}${o}${c}${l}`:h=`${o}${s}${r}${n}${a}${c}${l}`,this.prependCtes(e,`DELETE${u}${h}`)}dropSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{flat:!0});s=s?` (${s})`:"";let r=e.args.kind?.toString(),n=r&&(this.dialect._constructor.INVERSE_CREATABLE_KIND_MAPPING?.[r]||r).toUpperCase(),a=e.args.exists?" IF EXISTS ":" ",o=e.args.concurrently?" CONCURRENTLY":"",c=this.sql(e,"cluster");c=c?` ${c}`:"";let l=e.args.temporary?" TEMPORARY":"",u=e.args.materialized?" MATERIALIZED":"",h=e.args.cascade?" CASCADE":"",d=e.args.constraints?" CONSTRAINTS":"",x=e.args.purge?" PURGE":"";return`DROP${l}${u} ${n}${o}${a}${t}${c}${s}${h}${d}${x}`}setOperation(e){let t=e._constructor,s=t.key.toUpperCase(),r=e.args.distinct;r===!1&&(e instanceof wr||e instanceof kn)&&!this._constructor.EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE&&this.unsupported(`${s} ALL is not supported`);let n=this.dialect._constructor.SET_OP_DISTINCT_BY_DEFAULT?.[t.key];r===void 0&&(r=n,r===void 0&&this.unsupported(`${s} requires DISTINCT or ALL to be specified`));let a;r===n?a="":a=r?" DISTINCT":" ALL";let o=[e.args.side,e.args.kind].filter(Boolean).join(" ").toUpperCase(),c=o?`${o} `:"",l=e.args.byName?" BY NAME":"",u=this.expressions(e,{key:"on",flat:!0});return u=u?` ON (${u})`:"",`${c}${s}${a}${l}${u}`}setOperations(e){if(!this._constructor.SET_OP_MODIFIERS){let n=e.args.limit,a=e.args.order;if(n||a){let c=this.moveCtesToTopLevel(HI(e,"_l_0",{copy:!1}).select("*",{copy:!1}));return n&&(c=c.limit(typeof n=="number"?n:n.pop(),{copy:!1})),a&&(c=c.orderBy(a.pop(),{copy:!1})),this.sql(c)}}let t=[],s=[e];for(;0<s.length;){let n=s.pop();if(n instanceof Xe)n.args.expression&&s.push(n.args.expression),s.push(this.maybeComment(this.setOperation(n),void 0,n.comments,!0)),n.args.this&&s.push(n.args.this);else{let a=typeof n=="string"?n:this.sql(n);t.push(a)}}let r=t.join(this.sep());return r=this.queryModifiers(e,r),this.prependCtes(e,r)}fetchSql(e){let t=e.args.direction,s=t?` ${t}`:"",r=this.sql(e,"count"),n=r?` ${r}`:"",a=this.sql(e,"limitOptions"),o=a?`${a}`:" ROWS ONLY";return`${this.seg("FETCH")}${s}${n}${o}`}limitOptionsSql(e){let t=e.args.percent?" PERCENT":"",s=e.args.rows?" ROWS":"",r=e.args.withTies?" WITH TIES":"";return!r&&s&&(r=" ONLY"),`${t}${s}${r}`}filterSql(e){if(this._constructor.AGGREGATE_FILTER_SUPPORTED){let a=this.sql(e,"this"),o=this.sql(e,"expression").trim();return`${a} FILTER(${o})`}let s=e.args.this,r=s?s.args.this:void 0,n=e.args.expression?.args.this;return r instanceof A&&n instanceof A&&r.replace(new le({this:n.copy(),true:r.copy()})),this.sql(s)}hintSql(e){return this._constructor.QUERY_HINTS?` /*+ ${this.expressions(e,{sep:this._constructor.QUERY_HINT_SEP}).trim()} */`:(this.unsupported("Hints are not supported"),"")}indexParametersSql(e){let t=this.sql(e,"using");t=t?` USING ${t}`:"";let s=this.expressions(e,{key:"columns",flat:!0}),r=s?`(${s})`:"",n=this.expressions(e,{key:"partitionBy",flat:!0}),a=n?` PARTITION BY ${n}`:"",o=this.sql(e,"where"),c=this.expressions(e,{key:"include",flat:!0});c&&(c=` INCLUDE (${c})`);let l=this.expressions(e,{key:"withStorage",flat:!0}),u=l?` WITH (${l})`:"",h=this.sql(e,"tablespace"),d=h?` USING INDEX TABLESPACE ${h}`:"",x=this.sql(e,"on"),f=x?` ON ${x}`:"";return`${t}${r}${c}${u}${d}${a}${o}${f}`}indexSql(e){let t=e.args.unique?"UNIQUE ":"",s=e.args.primary?"PRIMARY ":"",r=e.args.amp?"AMP ":"",n=this.sql(e,"this");n=n?`${n} `:"";let a=this.sql(e,"table");a=a?`${this._constructor.INDEX_ON} ${a}`:"";let o=a?"":"INDEX ",c=this.sql(e,"params");return`${t}${s}${r}${o}${n}${a}${c}`}identifierSql(e){let t=e.name,s=t.toLowerCase();return t=this.normalize&&!e.args.quoted?s:t,t=t.replaceAll(this.identifierEnd,this.escapedIdentifierEnd),(e.args.quoted||this.dialect.canQuote(e,{identify:this.identify})||this._constructor.RESERVED_KEYWORDS.has(s)||!this.dialect._constructor.IDENTIFIERS_CAN_START_WITH_DIGIT&&/^\d/.test(t))&&(t=`${this.identifierStart}${t}${this.identifierEnd}`),t}hexSql(e){let t=this._constructor.HEX_FUNC,s=this.func(t,[this.sql(e,"this")]);return this.dialect._constructor.HEX_LOWERCASE&&(s=this.func("LOWER",[s])),s}lowerHexSql(e){let t=this._constructor.HEX_FUNC,s=this.func(t,[this.sql(e,"this")]);return this.dialect._constructor.HEX_LOWERCASE||(s=this.func("LOWER",[s])),s}inputOutputFormatSql(e){let t=this.sql(e,"inputFormat"),s=t?`INPUTFORMAT ${t}`:"",r=this.sql(e,"outputFormat"),n=r?`OUTPUTFORMAT ${r}`:"";return[s,n].join(this.sep())}nationalSql(e,t={}){let{prefix:s="N"}=t,r=this.sql(ml(e.name));return`${s}${r}`}partitionSql(e){return`${e.args.subpartition?"SUBPARTITION":"PARTITION"}(${this.expressions(e,{flat:!0})})`}propertiesSql(e){let t=[],s=[];for(let c of e.args.expressions||[]){let l=this._constructor.PROPERTIES_LOCATION.get(c._constructor);l==="postWith"?s.push(c):l==="postSchema"&&t.push(c)}let r=new Ke({expressions:t});r.parent=e.parent;let n=new Ke({expressions:s});n.parent=e.parent;let a=this.rootProperties(r),o=this.withProperties(n);return a&&o&&!this.pretty&&(o=` ${o}`),a+o}rootProperties(e){return 0<(e.args.expressions||[]).length?this.expressions(e,{indent:!1,sep:" "}):""}properties(e,t={}){let{prefix:s="",sep:r=", ",suffix:n="",wrapped:a=!0}=t;if(0<(e.args.expressions||[]).length){let o=this.expressions(e,{sep:r,indent:!1});if(o){let c=a?this.wrap(o):o;return`${s}${s.trim()?" ":""}${c}${n}`}}return""}withProperties(e){return this.properties(e,{prefix:this.seg(this._constructor.WITH_PROPERTIES_PREFIX,"")})}locateProperties(e){let t=new Map,s=e.args.expressions||[];for(let r of s){let n=this._constructor.PROPERTIES_LOCATION.get(r._constructor)||"unsupported";n!=="unsupported"?(t.has(n)||t.set(n,[]),t.get(n)?.push(r)):this.unsupported(`Unsupported property ${r._constructor.key}`)}return t}propertyName(e,t={}){let{stringKey:s=!1}=t;return e.args.this instanceof Se?this.sql(e,"this"):s?`'${e.name}'`:e.name}propertySql(e){let t=e._constructor;if(t===L)return`${this.propertyName(e)}=${this.sql(e,"value")}`;let s=Ke.PROPERTY_TO_NAME?.[t.key];return s||this.unsupported(`Unsupported property ${e._constructor.key}`),`${s}=${this.sql(e,"this")}`}likePropertySql(e){if(this._constructor.SUPPORTS_CREATE_TABLE_LIKE){let t=(e.args.expressions||[]).map(r=>`${r.name} ${this.sql(r,"value")}`).join(" "),s=t?` ${t}`:"";return`LIKE ${this.sql(e,"this")}${s}`}return this.propertySql(e)}fallbackPropertySql(e){let t=e.args.no?"NO ":"",s=e.args.protection?" PROTECTION":"";return`${t}FALLBACK${s}`}journalPropertySql(e){let t=e.args.no?"NO ":"",s=e.args.local,r=s?`${s} `:"",n=e.args.dual?"DUAL ":"",a=e.args.before?"BEFORE ":"",o=e.args.after?"AFTER ":"";return`${t}${r}${n}${a}${o}JOURNAL`}freespacePropertySql(e){let t=this.sql(e,"this"),s=e.args.percent?" PERCENT":"";return`FREESPACE=${t}${s}`}checksumPropertySql(e){let t;return e.args.default?t="DEFAULT":e.args.on?t="ON":t="OFF",`CHECKSUM=${t}`}mergeBlockRatioPropertySql(e){if(e.args.no)return"NO MERGEBLOCKRATIO";if(e.args.default)return"DEFAULT MERGEBLOCKRATIO";let t=e.args.percent?" PERCENT":"";return`MERGEBLOCKRATIO=${this.sql(e,"this")}${t}`}dataBlocksizePropertySql(e){let t=e.args.default,s=e.args.minimum,r=e.args.maximum;if(t||s||r){let o;return t?o="DEFAULT":s?o="MINIMUM":o="MAXIMUM",`${o} DATABLOCKSIZE`}let n=e.args.units,a=n?` ${n}`:"";return`DATABLOCKSIZE=${this.sql(e,"size")}${a}`}blockCompressionPropertySql(e){let t=e.args.autotemp,s=e.args.always,r=e.args.default,n=e.args.manual,a=e.args.never,o;return t!==void 0?o=`AUTOTEMP${this.sql(t)}`:s?o="ALWAYS":r?o="DEFAULT":n?o="MANUAL":a?o="NEVER":o="",`BLOCKCOMPRESSION=${o}`}isolatedLoadingPropertySql(e){let s=e.args.no?" NO":"",n=e.args.concurrent?" CONCURRENT":"",a=this.sql(e,"target");return a=a?` ${a}`:"",`WITH${s}${n} ISOLATED LOADING${a}`}partitionBoundSpecSql(e){if(Array.isArray(e.args.this))return`IN (${this.expressions(e,{key:"this",flat:!0})})`;if(e.args.this){let r=this.sql(e,"this"),n=this.sql(e,"expression");return`WITH (MODULUS ${r}, REMAINDER ${n})`}let t=this.expressions(e,{key:"fromExpressions",flat:!0}),s=this.expressions(e,{key:"toExpressions",flat:!0});return`FROM (${t}) TO (${s})`}partitionedOfPropertySql(e){let t=this.sql(e,"this"),s=e.args.expression??"";return s instanceof Ki?s=` FOR VALUES ${this.sql(s)}`:s=" DEFAULT",`PARTITION OF ${t}${s}`}lockingPropertySql(e){let t=e.args.kind,s=e.args.this?` ${this.sql(e,"this")}`:"",r=e.args.forOrIn,n=r?` ${r}`:"",a=e.args.lockType,o=e.args.override?" OVERRIDE":"";return`LOCKING ${t}${s}${n} ${a}${o}`}withDataPropertySql(e){let t=`WITH ${e.args.no?"NO ":""}DATA`,s=e.args.statistics,r="";return s!==void 0&&(r=` AND ${s?"":"NO "}STATISTICS`),`${t}${r}`}withSystemVersioningPropertySql(e){let t=this.sql(e,"this");t=t?`HISTORY_TABLE=${t}`:"";let s=this.sql(e,"dataConsistency"),r=s?`DATA_CONSISTENCY_CHECK=${s}`:void 0,n=this.sql(e,"retentionPeriod"),a=n?`HISTORY_RETENTION_PERIOD=${n}`:void 0,o;t?o=this.func("ON",[t,r,a]):o=e.args.on?"ON":"OFF";let c=`SYSTEM_VERSIONING=${o}`;return e.args.with?`WITH(${c})`:c}insertSql(e){let t=this.sql(e,"hint"),s=e.args.overwrite,r=e.args.this instanceof Xi,n;r?n=s?" OVERWRITE":" INTO":n=s?this._constructor.INSERT_OVERWRITE:" INTO";let a=this.sql(e,"stored"),o=a?` ${a}`:"",c=e.args.alternative,l=c?` OR ${c}`:"",u=e.args.ignore?" IGNORE":"";e.args.isFunction&&(n=`${n} FUNCTION`);let d=`${n} ${this.sql(e,"this")}`,x=e.args.exists?" IF EXISTS":"",f=this.sql(e,"where"),y=f?`${this.sep()}REPLACE WHERE ${f}`:"",I=`${this.sep()}${this.sql(e,"expression")}`,N=this.sql(e,"conflict"),P=N?` ${N}`:"",k=e.args.byName?" BY NAME":"",_=e.args.default?"DEFAULT VALUES":"",W=this.sql(e,"returning");this._constructor.RETURNING_END?I=`${I}${P}${_}${W}`:I=`${W}${I}${P}`;let he=this.sql(e,"partition"),ne=he?` ${he}`:"",Y=this.sql(e,"settings"),He=Y?` ${Y}`:"",ve=this.sql(e,"source"),Xt=ve?`TABLE ${ve}`:"",Ft=`INSERT${t}${l}${u}${d}${o}${k}${x}${ne}${He}${y}${I}${Xt}`;return this.prependCtes(e,Ft)}introducerSql(e){return`_${this.sql(e,"this")} ${this.sql(e,"expression")}`}killSql(e){return`KILL ${e.args.kind?`${e.args.kind} `:""}${this.sql(e,"this")}`}pseudoTypeSql(e){return e.name}objectIdentifierSql(e){return e.name}onConflictSql(e){let t=e.args.duplicate?"ON DUPLICATE KEY":"ON CONFLICT",s=this.sql(e,"constraint");s=s?` ON CONSTRAINT ${s}`:"";let r=this.expressions(e,{key:"conflictKeys",flat:!0});r&&(r=`(${r})`);let n=this.sql(e,"indexPredicate");r=`${r}${n} `;let a=this.sql(e,"action"),o=this.expressions(e,{flat:!0});o&&(o=` ${this._constructor.DUPLICATE_KEY_UPDATE_WITH_SET?"SET ":""}${o}`);let c=this.sql(e,"where");return`${t}${s}${r}${a}${o}${c}`}returningSql(e){return this.opExpressions("RETURNING",e)}rowFormatDelimitedPropertySql(e){let t=this.sql(e,"fields"),s=t?` FIELDS TERMINATED BY ${t}`:"",r=this.sql(e,"collectionItems"),n=r?` COLLECTION ITEMS TERMINATED BY ${r}`:"",a=this.sql(e,"mapKeys"),o=a?` MAP KEYS TERMINATED BY ${a}`:"",c=this.sql(e,"lines"),l=c?` LINES TERMINATED BY ${c}`:"",u=this.sql(e,"null"),h=u?` NULL DEFINED AS ${u}`:"";return`ROW FORMAT DELIMITED${s}${n}${o}${l}${h}`}withTableHintSql(e){return`WITH (${this.expressions(e,{flat:!0})})`}indexTableHintSql(e){let t=`${this.sql(e,"this")} INDEX`,s=this.sql(e,"target");return s=s?` FOR ${s}`:"",`${t}${s} (${this.expressions(e,{flat:!0})})`}historicalDataSql(e){let t=this.sql(e,"this"),s=this.sql(e,"kind"),r=this.sql(e,"expression");return`${t} (${s} => ${r})`}tableParts(e){return[e.args.catalog,e.args.db,e.args.this].filter(t=>t!==void 0).map(t=>this.sql(t)).join(".")}tableSql(e,t={}){let{sep:s=" AS "}=t,r=this.tableParts(e),n=e.args.only?"ONLY ":"",a=this.sql(e,"partition");a=a?` ${a}`:"";let o=this.sql(e,"version");o=o?` ${o}`:"";let c=this.sql(e,"alias");c=c?`${s}${c}`:"";let l=this.sql(e,"sample"),u,h;this.dialect._constructor.ALIAS_POST_TABLESAMPLE?(u=l,h=""):(u="",h=l);let d=this.expressions(e,{key:"hints",sep:" "});d=d&&this._constructor.TABLE_HINTS?` ${d}`:"";let x=this.expressions(e,{key:"pivots",sep:"",flat:!0}),f=this.indent(this.expressions(e,{key:"joins",sep:"",flat:!0}),{skipFirst:!0}),y=this.expressions(e,{key:"laterals",sep:""}),I=this.sql(e,"format");if(I){let Y=this.sql(e,"pattern"),He=Y?`, PATTERN => ${Y}`:"";I=` (FILE_FORMAT => ${I}${He})`}let N=e.args.ordinality||"";N&&(N=` WITH ORDINALITY${c}`,c="");let P=this.sql(e,"when"),k=r;P&&(k=`${r} ${P}`);let _=this.sql(e,"changes");_=_?` ${_}`:"";let W=this.expressions(e,{key:"rowsFrom"});W&&(k=`ROWS FROM ${this.wrap(W)}`);let he=e.args.indexed,ne;return he!==void 0?ne=he?` INDEXED BY ${this.sql(he)}`:" NOT INDEXED":ne="",`${n}${k}${_}${a}${o}${I}${u}${c}${ne}${d}${x}${h}${f}${y}${N}`}tableFromRowsSql(e){let t=this.func("TABLE",[e.args.this]),s=this.sql(e,"alias");s=s?` AS ${s}`:"";let r=this.sql(e,"sample"),n=this.expressions(e,{key:"pivots",sep:"",flat:!0}),a=this.indent(this.expressions(e,{key:"joins",sep:"",flat:!0}),{skipFirst:!0});return`${t}${s}${n}${r}${a}`}pivotSql(e){let t=this.expressions(e,{flat:!0}),s=e.args.unpivot?"UNPIVOT":"PIVOT",r=this.sql(e,"group");if(e.args.this){let h=this.sql(e,"this"),d;if(!t)d=`UNPIVOT ${h}`;else{let x=`${this.seg("ON")} ${t}`,f=this.sql(e,"into");f=f?`${this.seg("INTO")} ${f}`:"";let y=this.expressions(e,{key:"using",flat:!0});y=y?`${this.seg("USING")} ${y}`:"",d=`${s} ${h}${x}${f}${y}${r}`}return this.prependCtes(e,d)}let n=this.sql(e,"alias");n=n?` AS ${n}`:"";let a=this.expressions(e,{key:"fields",sep:" ",dynamic:!0,newLine:!0,skipFirst:!0,skipLast:!0}),o=e.args.includeNulls,c;o!==void 0?c=o?" INCLUDE NULLS ":" EXCLUDE NULLS ":c="";let l=this.sql(e,"defaultOnNull");l=l?` DEFAULT ON NULL (${l})`:"";let u=`${this.seg(s)}${c}(${t} FOR ${a}${l}${r})${n}`;return this.prependCtes(e,u)}versionSql(e){let t=`FOR ${e.name}`,s=e.text?.("kind")||"",r=this.sql(e,"expression");return`${t} ${s} ${r}`}tupleSql(e){return`(${this.expressions(e,{dynamic:!0,newLine:!0,skipFirst:!0,skipLast:!0})})`}updateFromJoinsSql(e){let t=e.args.from;if(this.constructor.UPDATE_STATEMENT_SUPPORTS_FROM||!t)return["",this.sql(e,"from")];let s=e.args.this;if(s instanceof V){let o=Z(s.aliasOrName);for(let c of e.args.expressions||[]){let l=c.args.this;l instanceof B&&!l.table&&l.setArgKey("table",o)}}let r=t.args.this,n=($(r,A)?r.args.joins:void 0)||[];0<n.length&&$(r,A)&&r.setArgKey("joins",void 0);let a=$(r,A)?this.sql(new oe({this:r,on:Qe()})):"";for(let o of n)!o.getArgKey("on")&&!o.getArgKey("using")&&o.setArgKey("on",Qe()),a+=this.sql(o);return[a,""]}updateSql(e){let t=this.sql(e,"this"),[s,r]=this.updateFromJoinsSql(e),n=this.expressions(e,{flat:!0}),a=this.sql(e,"where"),o=this.sql(e,"returning"),c=this.sql(e,"order"),l=this.sql(e,"limit"),u;this._constructor.RETURNING_END?u=`${r}${a}${o}`:u=`${o}${r}${a}`;let h=this.expressions(e,{key:"options"});h=h?` OPTION(${h})`:"";let d=`UPDATE ${t}${s} SET ${n}${u}${c}${l}${h}`;return this.prependCtes(e,d)}valuesSql(e,t={}){let{valuesAsTable:s=!0}=t;if(s&&this._constructor.VALUES_AS_TABLE||!e.findAncestor(Je,oe)){let h=this.expressions(e),d=this.sql(e,"alias"),x=`VALUES${this.seg("")}${h}`;return this._constructor.WRAP_DERIVED_VALUES&&(d||[Je,V].some(y=>e.parent instanceof y))&&(x=`(${x})`),x=this.queryModifiers(e,x),d?`${x} AS ${d}`:x}let n=$(e.args.alias,ie)?e.args.alias:void 0,a=n?.columns,o=[],c=e.args.expressions;if(c)for(let h=0;h<c.length;h++){let x=c[h].args.expressions||[];h===0&&a&&0<a.length&&(x=x.map((f,y)=>{let I=a[y];return Ye(f,I instanceof U?I:I.name,{copy:!1})})),o.push(new ee({expressions:x}))}if(o.length===0)return"";if(this.pretty){let h=o.reduce((f,y)=>UA([f,y],{distinct:!1,copy:!1})??f),d=n?.args.this,x=d instanceof A?d:void 0;return this.subquerySql(h.subquery(x,{copy:!1}))}let l=n?` AS ${this.sql(n,"this")}`:"";return`(${o.map(h=>this.sql(h)).join(" UNION ALL ")})${l}`}varSql(e){return this.sql(e,"this")}intoSql(e){dT.call(this,e,"expressions");let t=e.args.temporary?" TEMPORARY":"",s=e.args.unlogged?" UNLOGGED":"",r=t||s;return`${this.seg("INTO")}${r} ${this.sql(e,"this")}`}fromSql(e){return`${this.seg("FROM")} ${this.sql(e,"this")}`}groupingSetsSql(e){let t=this.expressions(e,{indent:!1});return`GROUPING SETS ${this.wrap(t)}`}rollupSql(e){let t=this.expressions(e,{indent:!1});return t?`ROLLUP ${this.wrap(t)}`:"WITH ROLLUP"}rollupIndexSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{flat:!0}),r=this.sql(e,"fromIndex"),n=r?` FROM ${r}`:"",a=e.args.properties;a&&te(a,Ke);let o=a?` ${this.properties(a,{prefix:"PROPERTIES"})}`:"";return`${t}(${s})${n}${o}`}rollupPropertySql(e){return`ROLLUP (${this.expressions(e,{flat:!0})})`}cubeSql(e){let t=this.expressions(e,{indent:!1});return t?`CUBE ${this.wrap(t)}`:"WITH CUBE"}groupSql(e){let t=e.args.all,s="";t===!0?s=" ALL":t===!1&&(s=" DISTINCT");let r=this.opExpressions(`GROUP BY${s}`,e),n=this.expressions(e,{key:"groupingSets"}),a=this.expressions(e,{key:"cube"}),o=this.expressions(e,{key:"rollup"}),c=kf([n?this.seg(n):"",a?this.seg(a):"",o?this.seg(o):"",e.args.totals?this.seg("WITH TOTALS"):""],{sep:this._constructor.GROUPINGS_SEP}),l=r;return e.args.expressions?.length&&c&&c.trim()!=="WITH CUBE"&&c.trim()!=="WITH ROLLUP"&&(l=`${l}${this._constructor.GROUPINGS_SEP}`),`${l}${c}`}havingSql(e){let t=this.indent(this.sql(e,"this"));return`${this.seg("HAVING")}${this.sep()}${t}`}connectSql(e){let t=this.sql(e,"start");t=t?this.seg(`START WITH ${t}`):"";let s=e.args.nocycle?" NOCYCLE":"",r=this.sql(e,"connect"),n=this.seg(`CONNECT BY${s} ${r}`);return t+n}priorSql(e){return`PRIOR ${this.sql(e,"this")}`}joinSql(e){let t=this._constructor,s;!t.SEMI_ANTI_JOIN_WITH_SIDE&&(e.args.kind==="semi"||e.args.kind==="anti")?s=void 0:s=e.args.side?.toUpperCase();let r=[e.args.method,e.args.global?"GLOBAL":void 0,s,e.args.kind==="straightJoin"?"STRAIGHT_JOIN":e.args.kind?.toUpperCase(),e.args.hint&&t.JOIN_HINTS?e.args.hint:void 0,e.args.directed&&t.DIRECTED_JOINS?"DIRECTED":void 0].filter(x=>x).join(" "),n=this.sql(e,"matchCondition");n=n?` MATCH_CONDITION (${n})`:"";let a=this.sql(e,"on"),o=e.args.using;!a&&o&&(a=o.map(x=>this.sql(x)).join(", "));let c=e.args.this,l=this.sql(c),u=this.expressions(e);if(u&&(l=`${l},${this.seg(u)}`),a){a=this.indent(a,{skipFirst:!0});let x=this.pretty?this.seg(" ".repeat(this.pad)):" ";o?a=`${x}USING (${a})`:a=`${x}ON ${a}`}else if(!r)return c instanceof St&&c.args.crossApply!==void 0?` ${l}`:`, ${l}`;let h=e.args.kind!=="straightJoin"?r?`${r} JOIN`:"JOIN":r,d=this.expressions(e,{key:"pivots",sep:"",flat:!0});return`${this.seg(h)} ${l}${n}${a}${d}`}lambdaSql(e,t={}){let{arrowSep:s="->",wrap:r=!0}=t,n=this.expressions(e,{flat:!0});return n=r&&1<n.split(",").length?`(${n})`:n,`${n} ${s} ${this.sql(e,"this")}`}lateralOp(e){let t=e.args.crossApply,s="";return t===!0?s="INNER JOIN ":t===!1&&(s="LEFT JOIN "),`${s}LATERAL`}lateralSql(e){let t=this.sql(e,"this");if(e.args.view){let n=e.args.alias,a=this.expressions(n,{key:"columns",flat:!0}),o=n?.name?` ${n.name}`:"",c=a?` AS ${a}`:"",l=e.args.outer?" OUTER":"";return`${this.seg(`LATERAL VIEW${l}`)}${this.sep()}${t}${o}${c}`}let s=this.sql(e,"alias");s=s?` AS ${s}`:"";let r=e.args.ordinality||"";return r&&(r=` WITH ORDINALITY${s}`,s=""),`${this.lateralOp(e)} ${t}${s}${r}`}limitSql(e,t={}){let{top:s=!1}=t,r=this.sql(e,"this"),n=["offset","expression"].map(u=>e.getArgKey(u)).filter(Boolean).map(u=>this._constructor.LIMIT_ONLY_LITERALS?this.simplifyUnlessLiteral(u):u),a=n.map(u=>this.sql(u)).join(", ");s&&n.some(u=>!u.isNumber)&&(a=`(${a})`);let o=this.expressions(e,{flat:!0}),c=this.sql(e,"limitOptions");o=o?` BY ${o}`:"";let l=s?"TOP":"LIMIT";return`${r}${this.seg(l)} ${a}${c}${o}`}offsetSql(e){let t=this.sql(e,"this"),s=e.args.expression;s=this._constructor.LIMIT_ONLY_LITERALS?this.simplifyUnlessLiteral(s):s;let r=this.expressions(e,{flat:!0}),n=r?` BY ${r}`:"";return`${t}${this.seg("OFFSET")} ${this.sql(s)}${n}`}setItemSql(e){let t=this.sql(e,"kind");!this._constructor.SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD&&t==="VARIABLE"?t="":t=t?`${t} `:"";let s=this.sql(e,"this"),r=this.expressions(e),n=this.sql(e,"collate");return n=n?` COLLATE ${n}`:"",`${e.args.global?"GLOBAL ":""}${t}${s}${r}${n}`}setSql(e){let t=` ${this.expressions(e,{flat:!0})}`,s=e.args.tag?" TAG":"";return`${e.args.unset?"UNSET":"SET"}${s}${t}`}queryBandSql(e){let t=this.sql(e,"this"),s=e.args.update?" UPDATE":"",r=this.sql(e,"scope"),n=r?` FOR ${r}`:"";return`QUERY_BAND = ${t}${s}${n}`}pragmaSql(e){return`PRAGMA ${this.sql(e,"this")}`}lockSql(e){if(!this._constructor.LOCKING_READS_SUPPORTED)return this.unsupported("Locking reads using 'FOR UPDATE/SHARE' are not supported"),"";let t=e.args.update,s=e.args.key,r;(t instanceof R?t.args.this!=="0":!!t)?r=s?"FOR NO KEY UPDATE":"FOR UPDATE":r=s?"FOR KEY SHARE":"FOR SHARE";let a=this.expressions(e,{flat:!0}),o=a?` OF ${a}`:"",c=e.args.wait,l="";return c!==void 0&&(c instanceof R?l=` WAIT ${this.sql(c)}`:l=c?" NOWAIT":" SKIP LOCKED"),`${r}${o}${l||""}`}literalSql(e){let t=e.args.this||"";return e.isString&&(t=`${this.dialect._constructor.QUOTE_START}${this.escapeStr(t)}${this.dialect._constructor.QUOTE_END}`),t}escapeStr(e,t={}){let{escapeBackslash:s=!0,delimiter:r,escapedDelimiter:n,isByteString:a=!1}=t;(a?this.dialect._constructor.BYTE_STRINGS_SUPPORT_ESCAPED_SEQUENCES:this.dialect._constructor.STRINGS_SUPPORT_ESCAPED_SEQUENCES)&&(e=Array.from(e).map(l=>{let u=this.dialect._constructor.ESCAPED_SEQUENCES[l];return u!==void 0&&(s||l!=="\\")?u:l}).join(""));let c=r||this.dialect._constructor.QUOTE_END;return this.replaceLineBreaks(e).replaceAll(c,n||this.escapedQuoteEnd)}loadDataSql(e){let t=e.args.local?" LOCAL":"",s=` INPATH ${this.sql(e,"inpath")}`,r=e.args.overwrite?" OVERWRITE":"",n=` INTO TABLE ${this.sql(e,"this")}`,a=this.sql(e,"partition"),o=a?` ${a}`:"",c=this.sql(e,"inputFormat"),l=c?` INPUTFORMAT ${c}`:"",u=this.sql(e,"serde"),h=u?` SERDE ${u}`:"";return`LOAD DATA${t}${s}${r}${n}${o}${l}${h}`}nullSql(...e){return"NULL"}booleanSql(e){return e.args.this?"TRUE":"FALSE"}boolandSql(e){return`((${this.sql(e,"this")}) AND (${this.sql(e,"expression")}))`}boolorSql(e){return`((${this.sql(e,"this")}) OR (${this.sql(e,"expression")}))`}orderSql(e,t={}){let{flat:s=!1}=t,r=this.sql(e,"this");r=r&&`${r} `;let n=e.args.siblings?"SIBLINGS ":"";return this.opExpressions(`${r}ORDER ${n}BY`,e,{flat:s||!!r})}withFillSql(e){let t=this.sql(e,"from");t=t?` FROM ${t}`:"";let s=this.sql(e,"to");s=s?` TO ${s}`:"";let r=this.sql(e,"step");r=r?` STEP ${r}`:"";let a=e.args.interpolate?.map(c=>c instanceof Re?`${this.sql(c,"alias")} AS ${this.sql(c,"this")}`:this.sql(c,"this"))||[],o=a.length?` INTERPOLATE (${a.join(", ")})`:"";return`WITH FILL${t}${s}${r}${o}`}clusterSql(e){return this.opExpressions("CLUSTER BY",e)}distributeSql(e){return this.opExpressions("DISTRIBUTE BY",e)}sortSql(e){return this.opExpressions("SORT BY",e)}orderedSql(e){let t=e.args.desc,s=!t,r=e.args.nullsFirst,n=!r,a=this.dialect._constructor.NULL_ORDERING==="nulls_are_large",o=this.dialect._constructor.NULL_ORDERING==="nulls_are_small",c=this.dialect._constructor.NULL_ORDERING==="nulls_are_last",l=this.sql(e,"this"),u=t?" DESC":t===!1?" ASC":"",h="";if(r&&(s&&a||t&&o||c)?h=" NULLS FIRST":n&&(s&&o||t&&a)&&!c&&(h=" NULLS LAST"),h&&this._constructor.NULL_ORDERING_SUPPORTED!=="supported"){let x=e.findAncestor(we,ee);if(x instanceof we&&x.args.spec)this.unsupported(`'${h.trim()}' translation not supported in window functions`),h="";else if(this._constructor.NULL_ORDERING_SUPPORTED==="partial"&&(s&&h===" NULLS LAST"||t&&h===" NULLS FIRST")){let f=e.findAncestor(D,we,ee);f instanceof we&&(f=f.args.this),f instanceof D&&(this.unsupported(`'${h.trim()}' translation not supported for aggregate functions with ${u} sort order`),h="")}else this._constructor.NULL_ORDERING_SUPPORTED==="unsupported"&&(e.args.this?.isInteger?this.unsupported(`'${h.trim()}' translation not supported with positional ordering`):e.args.this instanceof fl||(l=`CASE WHEN ${l} IS NULL THEN 1 ELSE 0 END${h===" NULLS FIRST"?" DESC":""}, ${l}`),h="")}let d=this.sql(e,"withFill");return d=d?` ${d}`:"",`${l}${u}${h}${d}`}matchRecognizeMeasureSql(e){let t=this.sql(e,"windowFrame"),s=t?`${t} `:"",r=this.sql(e,"this");return`${s}${r}`}matchRecognizeSql(e){let t=this.partitionBySql(e),s=this.sql(e,"order"),r=this.expressions(e,{key:"measures"}),n=r?this.seg(`MEASURES${this.seg(r)}`):"",a=this.sql(e,"rows"),o=a?this.seg(a):"",c=this.sql(e,"after"),l=c?this.seg(c):"",u=this.sql(e,"pattern"),h=u?this.seg(`PATTERN (${u})`):"",d=(e.args.define||[]).map(P=>`${this.sql(P,"alias")} AS ${this.sql(P,"this")}`),x=this.expressions(void 0,{sqls:d}),f=x?this.seg(`DEFINE${this.seg(x)}`):"",y=[t,s,n,o,l,h,f].join(""),I=this.sql(e,"alias"),N=I?` ${I}`:"";return`${this.seg("MATCH_RECOGNIZE")} ${this.wrap(y)}${N}`}queryModifiers(e,...t){let s=e.getArgKey("limit");if(s!==void 0&&!(s instanceof _s||s instanceof Et))return"";let r=this._constructor.LIMIT_FETCH;return r==="LIMIT"&&s instanceof _s?s=new Et({expression:Ve(s.args.count)}):r==="FETCH"&&s instanceof Et&&(s=new _s({direction:"FIRST",count:Ve(s.args.expression)})),kf([...t,...e.args.joins?.map(n=>this.sql(n))??[],this.sql(e,"match"),...e.args.laterals?.map(n=>this.sql(n))??[],this.sql(e,"prewhere"),this.sql(e,"where"),this.sql(e,"connect"),this.sql(e,"group"),this.sql(e,"having"),...Array.from(this._constructor.AFTER_HAVING_MODIFIER_TRANSFORMS.values()).map(n=>n.call(this,e)),this.sql(e,"order"),...this.offsetLimitModifiers(e,{fetch:s instanceof _s},s),...this.afterLimitModifiers(e),this.optionsModifier(e),this.forModifiers(e)],{sep:""})}optionsModifier(e){let t=this.expressions(e,{key:"options"});return t?` ${t}`:""}forModifiers(e){let t=this.expressions(e,{key:"for"});return t?`${this.sep()}FOR XML${this.seg(t)}`:""}queryOptionSql(e){return this.unsupported("Unsupported query option."),""}afterLimitModifiers(e){let t=this.expressions(e,{key:"locks",sep:" "});return t=t?` ${t}`:"",[t,this.sql(e,"sample")]}selectSql(e){let t=e.args.into;!this._constructor.SUPPORTS_SELECT_INTO&&t&&t.pop();let s=this.sql(e,"hint"),r=this.sql(e,"distinct");r=r?` ${r}`:"";let n=this.sql(e,"kind"),a=e.args.limit,o="";this._constructor.LIMIT_IS_TOP&&a instanceof Et&&(o=this.limitSql(a,{top:!0}),a.pop());let c=this.expressions(e),l=this._constructor;if(n)if(l.SELECT_KINDS.includes(n))n=` AS ${n}`;else{if(n==="STRUCT"){let y=(e.args.expressions||[]).map(I=>I instanceof Re?new ct({this:I.args.alias instanceof U?I.args.alias:new U({this:I.args.alias?.toString()||""}),expression:I.args.this}):I);c=this.expressions(void 0,{sqls:[new ks({expressions:y})]})}n=""}let u=this.expressions(e,{key:"operationModifiers",sep:" "}),h=u?`${this.sep()}${u}`:"",d=l.LIMIT_IS_TOP?`${r}${s}${o}`:`${o}${s}${r}`;c=c&&`${this.sep()}${c}`;let x=this.queryModifiers(e,`SELECT${d}${h}${n}${c}`,this.sql(e,"into",{comment:!1}),this.sql(e,"from",{comment:!1}));if(x=this.prependCtes(e,x),!l.SUPPORTS_SELECT_INTO&&t){te(t,Qi);let f="";t.args.temporary?f=" TEMPORARY":l.SUPPORTS_UNLOGGED_TABLES&&t.args.unlogged&&(f=" UNLOGGED"),x=`CREATE${f} TABLE ${this.sql(t.args.this)} AS ${x}`}return x}schemaSql(e){let t=this.sql(e,"this"),s=this.schemaColumnsSql(e);return t&&s?`${t} ${s}`:t||s}schemaColumnsSql(e){return e.args.expressions?.length?`(${this.sep("")}${this.expressions(e)}${this.seg(")","")}`:""}starSql(e){let t=this.expressions(e,{key:"except",flat:!0});t=t?`${this.seg(this._constructor.STAR_EXCEPT)} (${t})`:"";let s=this.expressions(e,{key:"replace",flat:!0});s=s?`${this.seg("REPLACE")} (${s})`:"";let r=this.expressions(e,{key:"rename",flat:!0});return r=r?`${this.seg("RENAME")} (${r})`:"",`*${t}${s}${r}`}parameterSql(e){let t=this.sql(e,"this");return`${this._constructor.PARAMETER_TOKEN}${t}`}sessionParameterSql(e){let t=this.sql(e,"this"),s=e.text("kind");return s&&(s=`${s}.`),`@@${s}${t}`}placeholderSql(e){return e.args.this!==void 0?`${this._constructor.NAMED_PLACEHOLDER_TOKEN}${e.name}`:"?"}subquerySql(e,t={}){let{sep:s=" AS "}=t,r=this.sql(e,"alias");r=r?`${s}${r}`:"";let n=this.sql(e,"sample");this.dialect._constructor.ALIAS_POST_TABLESAMPLE&&n&&(r=`${n}${r}`,e.setArgKey("sample",void 0));let a=this.expressions(e,{key:"pivots",sep:"",flat:!0}),o=this.queryModifiers(e,this.wrap(e),r,a);return this.prependCtes(e,o)}qualifySql(e){let t=this.indent(this.sql(e,"this"));return`${this.seg("QUALIFY")}${this.sep()}${t}`}unnestSql(e){let t=this.expressions(e,{flat:!0}),s=e.args.alias,r=e.args.offset;this._constructor.UNNEST_WITH_ORDINALITY&&s&&r instanceof U&&(te(s,ie),s.args.columns?s.args.columns.push(r):s.setArgKey("columns",[r]));let n="";if(s&&this.dialect._constructor.UNNEST_COLUMN_ONLY){te(s,ie);let o=s.columns;n=o[0]?this.sql(o[0]):""}else n=this.sql(s);n=n&&` AS ${n}`;let a="";return this._constructor.UNNEST_WITH_ORDINALITY?a=r?` WITH ORDINALITY${n}`:n:r instanceof A?a=`${n} WITH OFFSET AS ${this.sql(r)}`:r?a=`${n} WITH OFFSET`:a=n,`UNNEST(${t})${a}`}preWhereSql(e){return""}whereSql(e){let t=this.indent(this.sql(e,"this"));return`${this.seg("WHERE")}${this.sep()}${t}`}windowSql(e){let t=this.sql(e,"this"),s=this.partitionBySql(e),r=e.args.order;r&&te(r,fe);let n=r?this.orderSql(r,{flat:!0}):"",a=this.sql(e,"spec"),o=this.sql(e,"alias"),c=this.sql(e,"over")||"OVER";t=`${t} ${e.argKey==="windows"?"AS":c}`;let l=e.args.first,u="";if(l!==void 0&&(u=l?"FIRST":"LAST"),!s&&!n&&!a&&o)return`${t} ${o}`;let h=this.formatArgs([o,u,s,n,a].filter(d=>d),{sep:" "});return`${t} (${h})`}partitionBySql(e){let t=this.expressions(e,{key:"partitionBy",flat:!0});return t?`PARTITION BY ${t}`:""}windowSpecSql(e){let t=this.sql(e,"kind"),s=kf([this.sql(e,"start"),this.sql(e,"startSide")],{sep:" "}),r=kf([this.sql(e,"end"),this.sql(e,"endSide")],{sep:" "})||"CURRENT ROW",n=`${t} BETWEEN ${s} AND ${r}`,a=this.sql(e,"exclude");return a&&(this._constructor.SUPPORTS_WINDOW_EXCLUDE?n+=` EXCLUDE ${a}`:this.unsupported("EXCLUDE clause is not supported in the WINDOW clause")),n}withinGroupSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression");return s=s.substring(1),`${t} WITHIN GROUP (${s})`}betweenSql(e){let t=this.sql(e,"this"),s=this.sql(e,"low"),r=this.sql(e,"high"),n=e.args.symmetric;if(n&&!this._constructor.SUPPORTS_BETWEEN_FLAGS)return`(${t} BETWEEN ${s} AND ${r} OR ${t} BETWEEN ${r} AND ${s})`;let a=n?" SYMMETRIC":n===!1&&this._constructor.SUPPORTS_BETWEEN_FLAGS?" ASYMMETRIC":"";return`${t} BETWEEN${a} ${s} AND ${r}`}bracketOffsetExpressions(e,t={}){let{indexOffset:s}=t,r=(s!==void 0?s:this.dialect._constructor.INDEX_OFFSET)-(e.args.offset||0),n=e.args.this instanceof A?e.args.this:new A({});return TN(n,e.args.expressions||[],r,{dialect:this.dialect})}bracketSql(e){let s=this.bracketOffsetExpressions(e).map(r=>this.sql(r)).join(", ");return`${this.sql(e,"this")}[${s}]`}allSql(e){let t=this.sql(e,"this"),s=e.args.this;return s&&!(s instanceof Ge||s instanceof Oe)&&(t=this.wrap(t)),`ALL ${t}`}anySql(e){let t=this.sql(e,"this"),s=e.args.this;return Er.some(r=>s instanceof r)||s instanceof Oe?(Er.some(r=>s instanceof r)&&(t=this.wrap(t)),`ANY${t}`):`ANY ${t}`}existsSql(e){return`EXISTS${this.wrap(e)}`}caseSql(e){let t=this.sql(e,"this"),s=[t?`CASE ${t}`:"CASE"],r=e.args.ifs;if(r)for(let a of r)s.push(`WHEN ${this.sql(a,"this")}`),s.push(`THEN ${this.sql(a,"true")}`);let n=this.sql(e,"default");return n&&s.push(`ELSE ${n}`),s.push("END"),this.pretty&&this.tooWide(s)?this.indent(s.join(`
11
+ `),{skipFirst:!0,skipLast:!0}):s.join(" ")}constraintSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{flat:!0});return`CONSTRAINT ${t} ${s}`}nextValueForSql(e){let t=e.args.order;t&&te(t,fe);let s=t?` OVER (${this.orderSql(t,{flat:!0})})`:"";return`NEXT VALUE FOR ${this.sql(e,"this")}${s}`}extractSql(e){let t=e.args.this;this._constructor.NORMALIZE_EXTRACT_DATE_PARTS&&(t=P_(t,{dialect:this.dialect})||t);let s=this._constructor.EXTRACT_ALLOWS_QUOTES?this.sql(t):t.name,r=this.sql(e,"expression");return`EXTRACT(${s} FROM ${r})`}trimSql(e){let t=this.sql(e,"position"),s;return t==="LEADING"?s="LtRIM":t==="TRAILING"?s="RTRIM":s="TRIM",this.func(s,[e.args.this,e.args.expression])}convertConcatArgs(e){let t=e.args.expressions||[];if(e instanceof wt&&(t=t.slice(1)),this.dialect._constructor.STRICT_STRING_CONCAT&&e.args.safe&&(t=t.map(s=>j(s,"text",{dialect:this.dialect}))),!this.dialect._constructor.CONCAT_COALESCE&&e.args.coalesce){let s=r=>(r.type||(r=gs(r,{dialect:this.dialect})),r.isString||r.isType("array")?r:new rt({this:r,expressions:[new R({this:"",isString:!0})]}));t=t.map(s)}return t}concatSql(e){if(this.dialect._constructor.CONCAT_COALESCE&&!e.args.coalesce)return C_.call(this,e);let t=this.convertConcatArgs(e);return!this._constructor.SUPPORTS_SINGLE_ARG_CONCAT&&t.length===1?this.sql(t[0]):this.func("CONCAT",t)}concatWsSql(e){let s=(e.args.expressions||[])[0],r=this.convertConcatArgs(e);return this.func("CONCAT_WS",[s,...r])}checkSql(e){return`CHECK (${this.sql(e,"this")})`}foreignKeySql(e){let t=this.expressions(e,{flat:!0});t=t?` (${t})`:"";let s=this.sql(e,"reference");s=s?` ${s}`:"";let r=this.sql(e,"delete");r=r?` ON DELETE ${r}`:"";let n=this.sql(e,"update");n=n?` ON UPDATE ${n}`:"";let a=this.expressions(e,{key:"options",flat:!0,sep:" "});return a=a?` ${a}`:"",`FOREIGN KEY${t}${s}${r}${n}${a}`}primaryKeySql(e){let t=this.sql(e,"this");t=t?` ${t}`:"";let s=this.expressions(e,{flat:!0}),r=this.sql(e,"include"),n=this.expressions(e,{key:"options",flat:!0,sep:" "});return n=n?` ${n}`:"",`PRIMARY KEY${t} (${s})${r}${n}`}ifSql(e){return e.parent instanceof nt?`WHEN ${this.sql(e,"this")} THEN ${this.sql(e,"true")}`:this.caseSql(new nt({ifs:[e],default:e.args.false}))}matchAgainstSql(e){let t=e.args.expressions||[];this._constructor.MATCH_AGAINST_TABLE_PREFIX?t=t.map(n=>n instanceof V?`TABLE ${this.sql(n)}`:n):t=e.args.expressions||[];let s=e.args.modifier,r=s?` ${s}`:"";return`${this.func("MATCH",t)} AGAINST(${this.sql(e,"this")}${r})`}jsonKeyValueSql(e){return`${this.sql(e,"this")}${this._constructor.JSON_KEY_VALUE_PAIR_SEP} ${this.sql(e,"expression")}`}jsonPathSql(e){let t=this.expressions(e,{sep:"",flat:!0}).replace(/^\.+/,"");return e.args.escape&&(t=this.escapeStr(t)),this._constructor.QUOTE_JSON_PATH&&(t=`${this.dialect._constructor.QUOTE_START}${t}${this.dialect._constructor.QUOTE_END}`),t}jsonPathPart(e){if(e===void 0)return"";if(e instanceof dt){let s=this._constructor.TRANSFORMS.get(e._constructor);return typeof s!="function"?(this.unsupported(`Unsupported JsonPathPart type ${e._constructor.name}`),""):s.call(this,e)}return typeof e=="number"?String(e):this.quoteJsonPathKeyUsingBrackets&&this._constructor.JSON_PATH_SINGLE_QUOTE_ESCAPE?`\\'${e.toString().replaceAll("'","\\'")}\\'`:`"${e.toString().replace(/"/g,'\\"')}"`}formatJsonSql(e){return`${this.sql(e,"this")} FORMAT JSON`}formatPhraseSql(e){let t=this.sql(e,"this"),s=this.sql(e,"format");return`${t} (FORMAT ${s})`}jsonObjectSql(e){let t=e.args.nullHandling,s=t?` ${t}`:"",r=e.args.uniqueKeys,n="";r!=null&&(n=` ${r?"WITH":"WITHOUT"} UNIQUE KEYS`);let a=this.sql(e,"returnType"),o=a?` RETURNING ${a}`:"",c=this.sql(e,"encoding"),l=c?` ENCODING ${c}`:"",u=e instanceof Gl?"JSON_OBJECT":"JSON_OBJECTAGG";return this.func(u,e.args.expressions||[],{suffix:`${s}${n}${o}${l})`})}jsonObjectAggSql(e){return this.jsonObjectSql(e)}jsonArraySql(e){let t=e.args.nullHandling,s=t?` ${t}`:"",r=this.sql(e,"returnType"),n=r?` RETURNING ${r}`:"",a=e.args.strict?" STRICT":"";return this.func("JSON_ARRAY",e.args.expressions||[],{suffix:`${s}${n}${a})`})}jsonArrayAggSql(e){let t=this.sql(e,"this"),s=this.sql(e,"order"),r=e.args.nullHandling,n=r?` ${r}`:"",a=this.sql(e,"returnType"),o=a?` RETURNING ${a}`:"",c=e.args.strict?" STRICT":"";return this.func("JSON_ARRAYAGG",[t],{suffix:`${s}${n}${o}${c})`})}jsonColumnDefSql(e){let t=this.sql(e,"path"),s=t?` PATH ${t}`:"",r=this.sql(e,"nestedSchema");if(r)return`NESTED${s} ${r}`;let n=this.sql(e,"this"),a=this.sql(e,"kind"),o=a?` ${a}`:"",c=e.args.ordinality?" FOR ORDINALITY":"";return`${n}${o}${s}${c}`}jsonSchemaSql(e){return this.func("COLUMNS",e.args.expressions||[])}jsonTableSql(e){let t=this.sql(e,"this"),s=this.sql(e,"path"),r=s?`, ${s}`:"",n=e.args.errorHandling,a=n?` ${n}`:"",o=e.args.emptyHandling,c=o?` ${o}`:"",l=this.sql(e,"schema");return this.func("JSON_TABLE",[t],{suffix:`${r}${a}${c} ${l})`})}openJsonColumnDefSql(e){let t=this.sql(e,"this"),s=this.sql(e,"kind"),r=this.sql(e,"path"),n=r?` ${r}`:"",a=e.args.asJson?" AS JSON":"";return`${t} ${s}${n}${a}`}openJsonSql(e){let t=this.sql(e,"this"),s=this.sql(e,"path"),r=s?`, ${s}`:"",n=this.expressions(e),a=n?` WITH (${this.seg(this.indent(n),"")}${this.seg(")","")}`:"";return`OPENJSON(${t}${r})${a}`}inSql(e){let t=e.args.query,s=e.args.unnest,r=e.args.field,n=e.args.isGlobal?" GLOBAL":"",a;if(t)a=this.sql(t);else if(s)a=this.inUnnestOp(s);else if(r)a=this.sql(r);else{let o={dynamic:!0,newLine:!0,skipFirst:!0,skipLast:!0};a=`(${this.expressions(e,o)})`}return`${this.sql(e,"this")}${n} IN ${a}`}inUnnestOp(e){return`(SELECT ${this.sql(e)})`}intervalSql(e){let t=e.args.unit,s=t?this.sql(t):"";this._constructor.INTERVAL_ALLOWS_PLURAL_FORM||(s=this._constructor.TIME_PART_SINGULARS[s]||s);let r=s?` ${s}`:"";if(this._constructor.SINGLE_STRING_INTERVAL){let a=e.args.this instanceof A?e.args.this?.name||"":e.args.this;return a?t instanceof Ks?`INTERVAL '${a}'${r}`:`INTERVAL '${a}${r}'`:`INTERVAL${r}`}let n=this.sql(e,"this");return n&&(n=e.args.this instanceof A&&this._constructor.UNWRAPPED_INTERVAL_VALUES.has(e.args.this._constructor)?` ${n}`:` (${n})`),`INTERVAL${n}${r}`}returnSql(e){return`RETURN ${this.sql(e,"this")}`}referenceSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{flat:!0});s=s?`(${s})`:"";let r=this.expressions(e,{key:"options",flat:!0,sep:" "});return r=r?` ${r}`:"",`REFERENCES ${t}${s}${r}`}anonymousSql(e){let t=e.parent,s=t instanceof Se&&t.args.expression===e;return this.func(this.sql(e,"this"),e.args.expressions||[],{normalize:!s})}parenSql(e){return`(${this.seg(this.indent(this.sql(e,"this")),"")}${this.seg(")","")}`}negSql(e){let t=this.sql(e,"this");return`-${t[0]==="-"?" ":""}${t}`}notSql(e){return`NOT ${this.sql(e,"this")}`}aliasSql(e){let t=this.sql(e,"alias");return t=t?` AS ${t}`:"",`${this.sql(e,"this")}${t}`}pivotAliasSql(e){let t=e.args.alias,s=e.parent,r=s&&s.parent;if(r instanceof yr&&r.unpivot){let n=t instanceof U,a=t instanceof R;n&&!this._constructor.UNPIVOT_ALIASES_ARE_IDENTIFIERS?t.replace(new R({this:t.name,isString:!0})):!n&&a&&this._constructor.UNPIVOT_ALIASES_ARE_IDENTIFIERS&&t.replace(new U({this:t.name}))}return this.aliasSql(e)}aliasesSql(e){return`${this.sql(e,"this")} AS (${this.expressions(e,{flat:!0})})`}atIndexSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression");return`${t} AT ${s}`}atTimeZoneSql(e){let t=this.sql(e,"this"),s=this.sql(e,"zone");return`${t} AT TIME ZONE ${s}`}fromTimeZoneSql(e){let t=this.sql(e,"this"),s=this.sql(e,"zone");return`${t} AT TIME ZONE ${s} AT TIME ZONE 'UTC'`}addSql(e){return this.binary(e,"+")}andSql(e,t){return this.connectorSql(e,"AND",t)}orSql(e,t){return this.connectorSql(e,"OR",t)}xorSql(e,t){return this.connectorSql(e,"XOR",t)}connectorSql(e,t,s){if(s!==void 0){if(e.args.expressions&&0<e.args.expressions.length)s.push(this.expressions(e,{sep:` ${t} `}));else{if(s.push(e.right||""),e.comments&&this.comments)for(let c of e.comments)c&&(t+=` /*${this.sanitizeComment(c)}*/`);s.push(t,e.left||"")}return t}let r=[e],n=[],a=new Set;for(;0<r.length;){let c=r.pop();if(c instanceof Ee){let l=`${c._constructor.key}Sql`,u=this[l];typeof u=="function"&&a.add(u.call(this,c,r))}else{let l=this.sql(c),u=n[n.length-1];0<n.length&&a.has(u)?n[n.length-1]+=` ${l}`:n.push(l)}}let o=this.pretty&&this.tooWide(n)?`
12
+ `:" ";return n.join(o)}bitwiseAndSql(e){return this.binary(e,"&")}bitwiseLeftShiftSql(e){return this.binary(e,"<<")}bitwiseNotSql(e){return`~${this.sql(e,"this")}`}bitwiseOrSql(e){return this.binary(e,"|")}bitwiseRightShiftSql(e){return this.binary(e,">>")}bitwiseXorSql(e){return this.binary(e,"^")}castSql(e,t={}){let{safePrefix:s}=t,r=this.sql(e,"format");r=r?` FORMAT ${r}`:"";let n=this.sql(e,"to");n=n?` ${n}`:"";let a=this.sql(e,"action");a=a?` ${a}`:"";let o=this.sql(e,"default");return o=o?` DEFAULT ${o} ON CONVERSION ERROR`:"",`${s||""}CAST(${this.sql(e,"this")} AS${n}${o}${r}${a})`}strToTimeSql(e){return this.func("STR_TO_TIME",[e.args.this??"",e.args.format])}currentDateSql(e){let t=this.sql(e,"this");return t?`CURRENT_DATE(${t})`:"CURRENT_DATE"}collateSql(e){return this._constructor.COLLATE_IS_FUNC?this.functionFallbackSql(e):this.binary(e,"COLLATE")}commandSql(e){let t=this.sql(e,"this"),s=e.text("expression").trim();return`${t} ${s}`}commentSql(e){let t=this.sql(e,"this"),s=e.args.kind,r=e.args.materialized?" MATERIALIZED":"",n=e.args.exists?" IF EXISTS ":" ",a=this.sql(e,"expression");return`COMMENT${n}ON${r} ${s} ${t} IS ${a}`}mergeTreeTtlActionSql(e){let t=this.sql(e,"this"),s=e.args.delete?" DELETE":"",r=this.sql(e,"recompress"),n=r?` RECOMPRESS ${r}`:"",a=this.sql(e,"toDisk"),o=a?` TO DISK ${a}`:"",c=this.sql(e,"toVolume"),l=c?` TO VOLUME ${c}`:"";return`${t}${s}${n}${o}${l}`}mergeTreeTtlSql(e){let t=this.sql(e,"where"),s=this.sql(e,"group"),r=this.expressions(e,{key:"aggregates"}),n=r?`${this.seg("SET")}${this.seg(r)}`:"";return!t&&!s&&!n&&e.args.expressions?.length===1?`TTL ${this.expressions(e,{flat:!0})}`:`TTL${this.seg(this.expressions(e))}${t}${s}${n}`}transactionSql(e){let t=this.expressions(e,{key:"modes"});return`BEGIN${t?` ${t}`:""}`}commitSql(e){let t=e.args.chain,s="";return t!==void 0&&(s=t?" AND CHAIN":" AND NO CHAIN"),`COMMIT${s}`}rollbackSql(e){let t=e.args.savepoint;return`ROLLBACK${t?` TO ${t}`:""}`}alterColumnSql(e){let t=this.sql(e,"this"),s=this.sql(e,"dtype");if(s){let l=this.sql(e,"collate");l=l?` COLLATE ${l}`:"";let u=this.sql(e,"using");u=u?` USING ${u}`:"";let h=this._constructor.ALTER_SET_TYPE,d=h?`${h} `:"";return`ALTER COLUMN ${t} ${d}${s}${l}${u}`}let r=this.sql(e,"default");if(r)return`ALTER COLUMN ${t} SET DEFAULT ${r}`;let n=this.sql(e,"comment");if(n)return`ALTER COLUMN ${t} COMMENT ${n}`;let a=e.args.visible;if(a)return`ALTER COLUMN ${t} SET ${a}`;let o=e.args.allowNull,c=e.args.drop;return!c&&!o&&this.unsupported("Unsupported ALTER COLUMN syntax"),o!==void 0?`ALTER COLUMN ${t} ${c?"DROP":"SET"} NOT NULL`:`ALTER COLUMN ${t} DROP DEFAULT`}alterIndexSql(e){let t=this.sql(e,"this"),r=e.args.visible?"VISIBLE":"INVISIBLE";return`ALTER INDEX ${t} ${r}`}alterDistStyleSql(e){let t=this.sql(e,"this");return e.args.this instanceof qe||(t=`KEY DISTKEY ${t}`),`ALTER DISTSTYLE ${t}`}alterSortKeySql(e){let t=e.args.compound?" COMPOUND":"",s=this.sql(e,"this"),r=this.expressions(e,{flat:!0});return r=r?`(${r})`:"",`ALTER${t} SORTKEY ${s||r}`}alterRenameSql(e,t={}){let{includeTo:s=!0}=t,r=e;this._constructor.RENAME_TABLE_WITH_DB||(r=e.transform(o=>o instanceof V?new V({this:o.args.this}):o).assertIs(Mr));let n=this.sql(r,"this");return`RENAME${s?" TO":""} ${n}`}renameColumnSql(e){let t=e.args.exists?" IF EXISTS":"",s=this.sql(e,"this"),r=this.sql(e,"to");return`RENAME COLUMN${t} ${s} TO ${r}`}alterSetSql(e){let t=this.expressions(e,{flat:!0});return this._constructor.ALTER_SET_WRAPPED&&(t=`(${t})`),`SET ${t}`}alterSql(e){let t=e.args.actions||[],s;if(!this.dialect._constructor.ALTER_TABLE_ADD_REQUIRED_FOR_EACH_COLUMN&&t[0]instanceof Ie)s=this.expressions(e,{key:"actions",flat:!0}),s=`ADD ${s}`;else{let x=[];for(let f of t){let y=f,I;y instanceof Ie||y instanceof At?I=this.addColumnSql(y):(I=this.sql(y),(y instanceof ee||y instanceof Lr)&&(I=`AS ${I}`)),x.push(I)}s=this.formatArgs(x).replace(/^\n+/,"")}let r=e.args.exists?" IF EXISTS":"",n=this.sql(e,"cluster");n=n?` ${n}`:"";let a=e.args.only?" ONLY":"",o=this.expressions(e,{key:"options"});o=o?`, ${o}`:"";let c=this.sql(e,"kind").toUpperCase(),l=e.args.notValid?" NOT VALID":"",u=e.args.check?" WITH CHECK":"",h=e.args.cascade&&this.dialect._constructor.ALTER_TABLE_SUPPORTS_CASCADE?" CASCADE":"",d=this.sql(e,"this");return d=d?` ${d}`:"",`ALTER ${c}${r}${a}${d}${n}${u}${this.sep()}${s}${l}${o}${h}`}alterSessionSql(e){let t=this.expressions(e,{flat:!0});return`${e.args.unset?"UNSET":"SET"} ${t}`}addColumnSql(e){let t=this.sql(e),s;return e instanceof At?s=" COLUMNS":e instanceof Ie&&this._constructor.ALTER_TABLE_INCLUDE_COLUMN_KEYWORD?s=" COLUMN":s="",`ADD${s} ${t}`}dropPartitionSql(e){let t=this.expressions(e);return`DROP${e.args.exists?" IF EXISTS ":" "}${t}`}addConstraintSql(e){return`ADD ${this.expressions(e,{indent:!1})}`}addPartitionSql(e){let t=e.args.exists?"IF NOT EXISTS ":"",s=this.sql(e,"location");return s=s?` ${s}`:"",`ADD ${t}${this.sql(e,"this")}${s}`}distinctSql(e){let t=this.expressions(e,{flat:!0});if(!this._constructor.MULTI_ARG_DISTINCT&&1<(e.args.expressions?.length??0)){let r=WI();for(let n of e.args.expressions||[])r=r.when(n.is(pe()),pe());t=this.sql(r.else(`(${t})`))}t=t?` ${t}`:"";let s=this.sql(e,"on");return s=s?` ON ${s}`:"",`DISTINCT${t}${s}`}ignoreNullsSql(e){return this.embedIgnoreNulls(e,"IGNORE NULLS")}respectNullsSql(e){return this.embedIgnoreNulls(e,"RESPECT NULLS")}havingMaxSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression"),r=e.args.max?"MAX":"MIN";return`${t} HAVING ${r} ${s}`}intDivSql(e){return this.sql(new X({this:new mt({this:e.args.this,expression:e.args.expression}),to:new O({this:"int"})}))}dPipeSql(e){if(this.dialect._constructor.STRICT_STRING_CONCAT&&e.args.safe){let t=Array.from(e.flatten()).map(s=>j(s,"text",{copy:!1}));return this.func("CONCAT",t)}return this.binary(e,"||")}divSql(e){let t=e.left,s=e.right;if(!this.dialect._constructor.SAFE_DIVISION&&e.args.safe&&s?.replace(new Kl({this:s.copy(),expression:R.number(0)})),this.dialect._constructor.TYPED_DIVISION&&!e.args.typed)!t?.isType(Array.from(O.REAL_TYPES))&&!s?.isType(Array.from(O.REAL_TYPES))&&t?.replace(j(t.copy(),"double"));else if(!this.dialect._constructor.TYPED_DIVISION&&e.args.typed&&t?.isType(Array.from(O.INTEGER_TYPES))&&s?.isType(Array.from(O.INTEGER_TYPES)))return this.sql(j(t.div(s),"bigint"));return this.binary(e,"/")}safeDivideSql(e){let t=Yn(e.args.this,q),s=Yn(e.args.expression,q);return!t||!s?"":this.sql(new le({this:s.neq(0),true:t.div(s),false:pe()}))}overlapsSql(e){return this.binary(e,"OVERLAPS")}distanceSql(e){return this.binary(e,"<->")}dotSql(e){return`${this.sql(e,"this")}.${this.sql(e,"expression")}`}eqSql(e){return this.binary(e,"=")}propertyEqSql(e){return this.binary(e,":=")}escapeSql(e){return this.binary(e,"ESCAPE")}globSql(e){return this.binary(e,"GLOB")}gtSql(e){return this.binary(e,">")}gteSql(e){return this.binary(e,">=")}isSql(e){if(!this._constructor.IS_BOOL_ALLOWED&&e.args.expression instanceof ot){let t=e.args.this;return this.sql(e.args.expression.args.this?t:xr(t instanceof A||typeof t=="string"?t:void 0))}return this.binary(e,"IS")}iLikeSql(e){return this.likeSql(e)}likeSql(e){let t=e.args.this,s=e.args.expression,r,n;if(e instanceof Ut?(r=Ut,n="LIKE"):(r=Us,n="ILIKE"),(s instanceof ys||s instanceof Ct)&&!this._constructor.SUPPORTS_LIKE_QUANTIFIERS){let a,o=s.args.this instanceof A?s.args.this.unnest():void 0;o instanceof Ge?a=o.args.expressions:o?a=[o]:a=[];let c=s instanceof Ct?Kt:Fe,l=new r({this:t,expression:a?.[0]});for(let h=1;h<(a?.length||0);h++)l=c([l,new r({this:t,expression:a?.[h]||0})]);let u=e.parent;return u instanceof ye&&!(u instanceof l._constructor)&&(l=ki(l,{copy:!1})),this.sql(l)}return this.binary(e,n)}matchSql(e){return this.binary(e,"MATCH")}similarToSql(e){return this.binary(e,"SIMILAR TO")}ltSql(e){return this.binary(e,"<")}lteSql(e){return this.binary(e,"<=")}modSql(e){return this.binary(e,"%")}mulSql(e){return this.binary(e,"*")}neqSql(e){return this.binary(e,"<>")}nullSafeEqSql(e){return this.binary(e,"IS NOT DISTINCT FROM")}nullSafeNeqSql(e){return this.binary(e,"IS DISTINCT FROM")}subSql(e){return this.binary(e,"-")}tryCastSql(e){return this.castSql(e,{safePrefix:"TRY_"})}jsonCastSql(e){return this.castSql(e)}trySql(e){return this._constructor.TRY_SUPPORTED?this.func("TRY",[e.args.this]):(this.unsupported("Unsupported TRY function"),this.sql(e,"this"))}logSql(e){let t=e.args.this,s=e.args.expression;if(this.dialect._constructor.LOG_BASE_FIRST===!1)[t,s]=[s,t];else if(this.dialect._constructor.LOG_BASE_FIRST===void 0&&s){if(!t)return"";let r=t.name;if(r==="2"||r==="10")return this.func(`LOG${r}`,[s]);this.unsupported(`Unsupported logarithm with base ${this.sql(t)}`)}return this.func("LOG",[t,s])}useSql(e){let t=this.sql(e,"kind"),s=t?` ${t}`:"",r=this.sql(e,"this")||this.expressions(e,{flat:!0}),n=r?` ${r}`:"";return`USE${s}${n}`}binary(e,t){let s=[],r=[e],n=e._constructor;for(;0<r.length;){let a=r.pop();if(a instanceof q&&a._constructor===n){let o=a.args.operator;o&&(t=`OPERATOR(${this.sql(o)})`),r.push(a.right||""),r.push(` ${this.maybeComment(t,void 0,a.comments)} `),r.push(a.left||"")}else s.push(this.sql(a))}return s.join("")}ceilFloor(e){let t=this.sql(e,"to");return t?`${e._constructor.sqlName}(${this.sql(e,"this")} TO ${t})`:this.functionFallbackSql(e)}functionFallbackSql(e){let t=[];for(let r of e._constructor.availableArgs){let n=e.getArgKey(r);Array.isArray(n)?t.push(...n):t.push(n)}let s;return this.dialect._constructor.PRESERVE_ORIGINAL_NAMES?s=e.meta?.name||e._constructor.sqlName():s=e._constructor.sqlName(),this.func(s,t)}func(e,t,s={}){let{prefix:r="(",suffix:n=")",normalize:a=!0}=s;return`${a?this.normalizeFunc(e):e}${r}${this.formatArgs(t)}${n}`}formatArgs(e,t={}){let{sep:s=", "}=t,r=e.filter(n=>n!==void 0&&typeof n!="boolean").map(n=>this.sql(n)).filter(n=>n!=="");if(this.pretty&&this.tooWide(r)){let n=r.join(`${s.trim()}
13
+ `);return this.indent(`
14
+ ${n}
15
+ `,{skipFirst:!0,skipLast:!0})}return r.join(s)}tooWide(e){let t=e.reduce((s,r)=>s+r.length,0);return this.maxTextWidth<t}expressions(e,t={}){let{flat:s=!1,indent:r=!0,skipFirst:n=!1,skipLast:a=!1,sep:o=", ",prefix:c="",dynamic:l=!1,newLine:u=!1,key:h,sqls:d}=t,x=e?e.getArgKey(h||"expressions"):d;if(!x||Array.isArray(x)&&x.length===0)return"";let f=Array.isArray(x)?x:[x];if(s)return f.map(P=>this.sql(P)).filter(P=>P).join(o);let y=f.length,I=[];for(let P=0;P<y;P++){let k=f[P],_=this.sql(k,void 0,{comment:!1});if(!_)continue;let W=k instanceof A?this.maybeComment("",k):"";if(this.pretty)if(this.leadingComma)I.push(`${0<P?o:""}${c}${_}${W}`);else{let he=P+1<y?W?o.trimEnd():o:"";I.push(`${c}${_}${he}${W}`)}else I.push(`${c}${_}${W}${P+1<y?o:""}`)}let N;return this.pretty&&(!l||this.tooWide(I))?(u&&(I.unshift(""),I.push("")),N=I.map(P=>P.trimEnd()).join(`
16
+ `)):N=I.join(""),r?this.indent(N,{skipFirst:n,skipLast:a}):N}opExpressions(e,t,s={}){let r=(s.flat??!1)||t.parent instanceof Ke,n=this.expressions(t,{flat:r});return r?`${e} ${n}`:`${this.seg(e)}${n?this.sep():""}${n}`}nakedProperty(e){let t=Ke.PROPERTY_TO_NAME[e._constructor.key];return t||this.unsupported(`Unsupported property ${e._constructor.key}`),`${t||""} ${this.sql(e,"this")}`}tagSql(e){let t=e.args.prefix||"",s=e.args.postfix||"";return`${t}${this.sql(e.args.this)}${s}`}tokenSql(e){return this._constructor.TOKEN_MAPPING[e]??e.replace(/([A-Z])/g,"_$1").toUpperCase()}userDefinedFunctionSql(e){let t=this.sql(e,"this"),s=this.noIdentify(this.expressions.bind(this),e);return e.args.wrapped?s=this.wrap(s):s=s?` ${s}`:"",s.trim()!==""?`${t}${s}`:t}joinHintSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{flat:!0});return`${t}(${s})`}kwargSql(e){return this.binary(e,"=>")}whenSql(e){let t=e.args.matched?"MATCHED":"NOT MATCHED",s=this._constructor.MATCHED_BY_SOURCE&&e.args.source?" BY SOURCE":"",r=this.sql(e,"condition"),n=r?` AND ${r}`:"",a=e.args.then,o="";if(a instanceof kt){let c=this.sql(a,"this");c=c?`INSERT ${c}`:"INSERT";let l=this.sql(a,"expression");o=l?`${c} VALUES ${l}`:c}else if(a instanceof Vt)if(a.getArgKey("expressions")instanceof xe)o=`UPDATE ${this.sql(a,"expressions")}`;else{let c=this.expressions(a);o=c?`UPDATE SET${this.sep()}${c}`:"UPDATE"}else o=this.sql(a);return`WHEN ${t}${s}${n} THEN ${o}`}whensSql(e){return this.expressions(e,{sep:" ",indent:!1})}mergeSql(e){let t=e.args.this,s="";if($(t,V)){let u=t.args.hints||[];if(0<u.length&&t.alias&&u[0]instanceof tn){let h=t.args.alias,d=$(h,A)?h.pop():void 0;s=d?` AS ${this.sql(d)}`:""}}let r=this.sql(t),n=`USING ${this.sql(e,"using")}`,a=this.sql(e,"whens"),o=this.sql(e,"on");if(o=o?`ON ${o}`:"",!o){let u=this.expressions(e,{key:"usingCond"});o=u?`USING (${u})`:""}let c=this.sql(e,"returning");c&&(a=`${a}${c}`);let l=this.sep();return this.prependCtes(e,`MERGE INTO ${r}${s}${l}${n}${l}${o}${l}${a}`)}toCharSql(e){return dT.call(this,e,"format"),this.sql(j(e.args.this,"text"))}toNumberSql(e){if(!this._constructor.SUPPORTS_TO_NUMBER)return this.unsupported("Unsupported TO_NUMBER function"),this.sql(j(e.args.this,"double"));let t=e.args.format;return t?this.func("TO_NUMBER",[e.args.this,t]):(this.unsupported("Conversion format is required for TO_NUMBER"),this.sql(j(e.args.this,"double")))}dictPropertySql(e){let t=this.sql(e,"this"),s=this.sql(e,"kind"),r=this.expressions(e,{key:"settings",sep:" "}),n=r?`(${this.sep("")}${r}${this.seg(")","")}`:"()";return`${t}(${s}${n})`}dictRangeSql(e){let t=this.sql(e,"this"),s=this.sql(e,"max"),r=this.sql(e,"min");return`${t}(MIN ${r} MAX ${s})`}dictSubPropertySql(e){return`${this.sql(e,"this")} ${this.sql(e,"value")}`}duplicateKeyPropertySql(e){return`DUPLICATE KEY (${this.expressions(e,{flat:!0})})`}distributedByPropertySql(e){let t=this.expressions(e,{flat:!0});t=t?` ${this.wrap(t)}`:"";let s=this.sql(e,"buckets"),r=this.sql(e,"kind"),n=s?` BUCKETS ${s}`:"",a=this.sql(e,"order");return`DISTRIBUTED BY ${r}${t}${n}${a}`}onClusterSql(e){return""}clusteredByPropertySql(e){let t=this.expressions(e,{key:"expressions",flat:!0}),s=this.expressions(e,{key:"sortedBy",flat:!0});s=s?` SORTED BY (${s})`:"";let r=this.sql(e,"buckets");return`CLUSTERED BY (${t})${s} INTO ${r} BUCKETS`}anyValueSql(e){let t=this.sql(e,"this"),s=this.sql(e,"having");if(s){let r=e.args.max;return this.func("ANY_VALUE",[`${t} HAVING ${r?"MAX":"MIN"} ${s}`])}return this.func("ANY_VALUE",[e.args.this])}queryTransformSql(e){let t=this.func("TRANSFORM",e.args.expressions||[]),s=this.sql(e,"rowFormatBefore");s=s?` ${s}`:"";let r=this.sql(e,"recordWriter");r=r?` RECORDWRITER ${r}`:"";let n=` USING ${this.sql(e,"commandScript")}`,a=this.sql(e,"schema");a=a?` AS ${a}`:"";let o=this.sql(e,"rowFormatAfter");o=o?` ${o}`:"";let c=this.sql(e,"recordReader");return c=c?` RECORDREADER ${c}`:"",`${t}${s}${r}${n}${a}${o}${c}`}indexConstraintOptionSql(e){let t=this.sql(e,"keyBlockSize");if(t)return`KEY_BLOCK_SIZE = ${t}`;let s=this.sql(e,"using");if(s)return`USING ${s}`;let r=this.sql(e,"parser");if(r)return`WITH PARSER ${r}`;let n=this.sql(e,"comment");if(n)return`COMMENT ${n}`;let a=e.args.visible;if(a!==void 0)return a?"VISIBLE":"INVISIBLE";let o=this.sql(e,"engineAttr");if(o)return`ENGINE_ATTRIBUTE = ${o}`;let c=this.sql(e,"secondaryEngineAttr");return c?`SECONDARY_ENGINE_ATTRIBUTE = ${c}`:(this.unsupported("Unsupported index constraint option."),"")}checkColumnConstraintSql(e){let t=e.args.enforced?" ENFORCED":"";return`CHECK (${this.sql(e,"this")})${t}`}indexColumnConstraintSql(e){let t=this.sql(e,"kind"),s=t?`${t} INDEX`:"INDEX",r=this.sql(e,"this");r=r?` ${r}`:"";let n=this.sql(e,"indexType");n=n?` USING ${n}`:"";let a=this.expressions(e,{flat:!0});a=a?` (${a})`:"";let o=this.expressions(e,{key:"options",flat:!0,sep:" "});return o=o?` ${o}`:"",`${s}${r}${n}${a}${o}`}nvl2Sql(e){if(this._constructor.NVL2_SUPPORTED)return this.functionFallbackSql(e);let t=e.args.this;if(!t)return"";let s=new nt({}).when(t.is(pe()).not({copy:!1}),e.args.true??"",{copy:!1}),r=e.args.false;return r&&s.else(r,{copy:!1}),this.sql(s)}comprehensionSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression"),r=this.sql(e,"position"),n=r?`, ${r}`:"",a=this.sql(e,"iterator"),o=this.sql(e,"condition"),c=o?` IF ${o}`:"";return`${t} FOR ${s}${n} IN ${a}${c}`}columnPrefixSql(e){return`${this.sql(e,"this")}(${this.sql(e,"expression")})`}opclassSql(e){return`${this.sql(e,"this")} ${this.sql(e,"expression")}`}mlSql(e,t){let s=`MODEL ${this.sql(e,"this")}`,r=e.args.expression,n;if(r){let o=this.sql(e,"expression");n=r instanceof Te?o:`TABLE ${o}`}let a=this.sql(e,"paramsStruct")||void 0;return this.func(t,[s,n,a])}predictSql(e){return this.mlSql(e,"PREDICT")}generateEmbeddingSql(e){let t=e.args.isText?"GENERATE_TEXT_EMBEDDING":"GENERATE_EMBEDDING";return this.mlSql(e,t)}mlTranslateSql(e){return this.mlSql(e,"TRANSLATE")}mlForecastSql(e){return this.mlSql(e,"FORECAST")}featuresAtTimeSql(e){let t=e.args.this,s=this.sql(e,"this");return t instanceof V&&(s=`TABLE ${s}`),this.func("FEATURES_AT_TIME",[s,e.args.time,...e.args.numRows||[void 0],...e.args.ignoreFeatureNulls||[void 0]])}vectorSearchSql(e){let t=this.sql(e,"this");e.args.this instanceof V&&(t=`TABLE ${t}`);let s=e.args.queryTable,r=s?this.sql(s):void 0;return s instanceof V&&(r=`TABLE ${r}`),this.func("VECTOR_SEARCH",[t,e.args.columnToSearch,r,e.args.queryColumnToSearch,e.args.topK,e.args.distanceType,...e.args.options||[void 0]])}forInSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression");return`FOR ${t} DO ${s}`}refreshSql(e){let t=this.sql(e,"this");return`REFRESH ${e.args.this instanceof R?"":`${e.args.kind||""} `}${t}`}toArraySql(e){let t=e.args.this;if(!t)return"";if(t.type||(t=gs(t,{dialect:this.dialect})),t.isType("array"))return this.sql(t);let s=t.is(pe());return this.sql(jI("IF",s,pe(),CA(t,{copy:!1})))}tsOrDsToTimeSql(e){let t=e.args.this;if(!t)return"";let s=this.formatTime(e);return s?this.sql(j(new tr({this:t,format:e.args.format||s}),"time")):e.args.this instanceof yT||t.isType("time")?this.sql(t):this.sql(j(t,"time"))}tsOrDsToTimestampSql(e){let t=e.args.this;return t?t instanceof CT||t.isType("timestamp")?this.sql(t):this.sql(j(t,"timestamp")):""}tsOrDsToDatetimeSql(e){let t=e.args.this;return t?e.args.this instanceof IT||t.isType("datetime")?this.sql(t):this.sql(j(t,"datetime")):""}tsOrDsToDateSql(e){let t=e.args.this;if(!t)return"";let s=this.formatTime(e),r=e.args.safe;return s&&![this.dialect._constructor.TIME_FORMAT,this.dialect._constructor.DATE_FORMAT].includes(s)?this.sql(j(new tr({this:t,format:s,safe:r}),"date")):e.args.this instanceof Is||t.isType("date")?this.sql(t):r?this.sql(new _t({this:t,to:new O({this:"date"})})):this.sql(j(t,"date"))}unixDateSql(e){let t=j(R.string("1970-01-01"),"date");return this.func("DATEDIFF",[e.args.this,t,"day"])}lastDaySql(e){if(this._constructor.LAST_DAY_SUPPORTS_DATE_PART)return this.functionFallbackSql(e);let t=e.text("unit"),s=t?this.sql(t):"";return s&&s!=="MONTH"&&this.unsupported("Date parts are not supported in LAST_DAY."),this.func("LAST_DAY",[e.args.this])}dateAddSql(e){return this.func("DATE_ADD",[e.args.this,e.args.expression,yN(e)])}arrayAnySql(e){if(this._constructor.CAN_IMPLEMENT_ARRAY_ANY){let t=new dp({this:e.args.this,expression:e.args.expression}),s=new Bn({this:t}).neq(0),r=new Bn({this:e.args.this}).eq(0);return this.sql(ki(r.or(s)))}return this.dialect._constructor===se&&this.unsupported("ARRAY_ANY is unsupported"),this.functionFallbackSql(e)}structSql(e){return e.setArgKey("expressions",(e.args.expressions??[]).map(t=>{if(t instanceof ct){let s=t.args.this,r=xD(s,a=>a instanceof U?a:a.name),n=t.args.expression;return Ye(n instanceof A||typeof n=="string"?n:"",r)}return t})),this.functionFallbackSql(e)}partitionRangeSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression");return`${t} TO ${s}`}truncateTableSql(e){let t=e.args.isDatabase?"DATABASE":"TABLE",s=` ${this.expressions(e)}`,r=e.args.exists?" IF EXISTS":"",n=this.sql(e,"cluster");n=n?` ${n}`:"";let a=this.sql(e,"identity");a=a?` ${a} IDENTITY`:"";let o=this.sql(e,"option");o=o?` ${o}`:"";let c=this.sql(e,"partition");return c=c?` ${c}`:"",`TRUNCATE ${t}${r}${s}${n}${a}${o}${c}`}convertSql(e){let t=e.args.this,s=e.args.expression,r=e.args.style,n=e.args.safe,a=e.getArgKey("strict");if(!t||!s)return"";te(t,O);let o=t;!M(t.args.expressions??[],0)&&this._constructor.PARAMETERIZABLE_TEXT_TYPES.has(t.args.this)&&(o=O.build(t.args.this,{expressions:[R.number(30)],nested:!1})??o);let c,l=a?X:_t;if(r instanceof R&&r.isInteger){let u=r.name,d=se.get("tsql")?.CONVERT_FORMAT_MAPPING?.[u]??"";d||this.unsupported(`Unsupported T-SQL 'style' value: ${u}`);let x=R.string(d);o.args.this==="date"?c=new ba({this:s,format:x}):o.args.this==="datetime"||o.args.this==="datetime2"?c=new tr({this:s,format:x}):this._constructor.PARAMETERIZABLE_TEXT_TYPES.has(o.args.this)?c=new l({this:new Gn({this:s,format:x}),to:o,safe:n}):o.args.this==="text"&&(c=new Gn({this:s,format:x}))}return c||(c=new l({this:s,to:o,safe:n})),this.sql(c)}jsonPathKeySql(e){let t=e.args.this;if(t instanceof Pt){let r=this.jsonPathPart(t);return r?`.${r}`:""}if(typeof t=="string"&&this._constructor.SAFE_JSON_PATH_KEY_RE.test(t))return`.${t}`;let s=this.jsonPathPart(typeof t=="string"?t:t instanceof A?t.name??"":"");return this.quoteJsonPathKeyUsingBrackets&&this._constructor.JSON_PATH_BRACKETED_KEY_SUPPORTED?`[${s}]`:`.${s}`}jsonPathSubscriptSql(e){let t=e.args.this,s=this.jsonPathPart(t);return s?`[${s}]`:""}simplifyUnlessLiteral(e){return e instanceof R||(e=xN(e,{dialect:this.dialect})),e}embedIgnoreNulls(e,t){let s=e.args.this;if(this._constructor.RESPECT_IGNORE_NULLS_UNSUPPORTED_EXPRESSIONS.some(r=>s instanceof r))return this.unsupported(`RESPECT/IGNORE NULLS is not supported for ${s?._constructor.key} in ${this.dialect.constructor.name}`),this.sql(s);if(this._constructor.IGNORE_NULLS_IN_FUNC&&!e.meta?.inline){let r=[...e.findAll([qs,fe,Et])].sort((a,o)=>{let c=l=>l instanceof qs?0:l instanceof fe?1:2;return c(a)-c(o)});if(0<r.length){let a=r[0],o=new e._constructor({this:a.args.this?.copy()});return o.meta={...o.meta,inline:!0},a.args.this?.replace(o),this.sql(e.args.this)}let n=e.find(D);if(n){let a=this.sql(n,void 0,{comment:!1}).slice(0,-1)+` ${t})`;return this.maybeComment(a,void 0,n.comments)}}return`${this.sql(e,"this")} ${t}`}replaceLineBreaks(e){return this.pretty?e.replace(/\n/g,this._constructor.SENTINEL_LINE_BREAK):e}copyParameterSql(e){let t=this.sql(e,"this");if(e.args.expressions&&0<e.args.expressions.length){let n=t.toUpperCase(),a=n==="FILE_FORMAT"?" ":", ",o=n==="COPY_OPTIONS"||n==="FORMAT_OPTIONS"?" ":" = ",c=this.expressions(e,{flat:!0,sep:a});return`${t}${o}(${c})`}let s=this.sql(e,"expression");if(!s)return t;let r=this._constructor.COPY_PARAMS_EQ_REQUIRED?" = ":" ";return`${t}${r}${s}`}credentialsSql(e){let t=e.args.credentials,s="";if(t instanceof R){let d=this.sql(e,"credentials");s=d?`CREDENTIALS ${d}`:""}else{let d=this.expressions(e,{key:"credentials",flat:!0,sep:" "});s=t!=null?`CREDENTIALS = (${d})`:""}let r=this.sql(e,"storage"),n=r?`STORAGE_INTEGRATION = ${r}`:"",a=this.expressions(e,{key:"encryption",flat:!0,sep:" "}),o=a?` ENCRYPTION = (${a})`:"",c=this.sql(e,"iamRole"),l=c?`IAM_ROLE ${c}`:"",u=this.sql(e,"region"),h=u?` REGION ${u}`:"";return`${s}${n}${o}${l}${h}`}copySql(e){let t=this._constructor,s=this.sql(e,"this");s=t.COPY_HAS_INTO_KEYWORD?` INTO ${s}`:` ${s}`;let r=this.sql(e,"credentials");r=r?this.seg(r):"";let n=this.expressions(e,{key:"files",flat:!0}),a=n&&e.args.kind?this.seg("FROM"):n?this.seg("TO"):"",c=this.dialect._constructor.COPY_PARAMS_ARE_CSV||!1?", ":" ",l=this.expressions(e,{key:"params",sep:c,newLine:!0,skipLast:!0,skipFirst:!0,indent:t.COPY_PARAMS_ARE_WRAPPED});return l&&(t.COPY_PARAMS_ARE_WRAPPED?l=` WITH (${l})`:!this.pretty&&(n||r)&&(l=` ${l}`)),`COPY${s}${a} ${n}${r}${l}`}semicolonSql(e){return""}dataDeletionPropertySql(e){let t=e.args.on?"ON":"OFF",s=this.sql(e,"filterColumn"),r=s?`FILTER_COLUMN=${s}`:void 0,n=this.sql(e,"retentionPeriod"),a=n?`RETENTION_PERIOD=${n}`:void 0;return r||a?`DATA_DELETION=${this.func("ON",[r,a])}`:`DATA_DELETION=${t}`}gapFillSql(e){let t=this.sql(e,"this");t=`TABLE ${t}`;let s=Object.entries(e.args).filter(([r])=>r!=="this").map(([r,n])=>n);return this.func("GAP_FILL",[t,...s])}scopeResolution(e,t){return this.func("SCOPE_RESOLUTION",[t||void 0,e])}scopeResolutionSql(e){let t=this.sql(e,"this"),s=e.args.expression,r;if(s instanceof g){let n=this.sql(s,"this"),a=this.formatArgs(s.args.expressions||[]);r=`${n}(${a})`}else r=this.sql(e,"expression");return this.scopeResolution(r,t)}parseJsonSql(e){let t=this._constructor.PARSE_JSON_NAME;return t==null?this.sql(e.args.this):this.func(t,[e.args.this,e.args.expression])}randSql(e){let t=this.sql(e,"lower"),s=this.sql(e,"upper");return t&&s?`(${s} - ${t}) * ${this.func("RAND",[e.args.this])} + ${t}`:this.func("RAND",[e.args.this])}changesSql(e){let s=`INFORMATION => ${this.sql(e,"information")}`,r=this.sql(e,"atBefore"),n=r?`${this.seg("")}${r}`:"",a=this.sql(e,"end"),o=a?`${this.seg("")}${a}`:"";return`CHANGES (${s})${n}${o}`}padSql(e){let t=e.args.isLeft?"L":"R",s=this.sql(e,"fillPattern");return!s&&this._constructor.PAD_FILL_PATTERN_IS_REQUIRED&&(s="' '"),this.func(`${t}PAD`,[e.args.this,e.args.expression,s])}summarizeSql(e){return`SUMMARIZE${e.args.table?" TABLE":""} ${this.sql(e.args.this)}`}explodingGenerateSeriesSql(e){let t=new Fs({...e.args}),s=e.parent;return(s instanceof Re||s instanceof ie)&&(s=s.parent),this._constructor.SUPPORTS_EXPLODING_PROJECTIONS&&!(s instanceof V)&&!(s instanceof ge)?this.sql(new ge({expressions:[t]})):(s instanceof ee&&this.unsupported("GenerateSeries projection unnesting is not supported."),this.sql(t))}convertTimezoneSql(e){if(this._constructor.SUPPORTS_CONVERT_TIMEZONE)return this.functionFallbackSql(e);let t=e.args.sourceTz,s=e.args.targetTz,r=e.args.timestamp;t&&r&&(r=new Wt({this:j(r,"timestampntz"),zone:t}));let n=new Wt({this:r,zone:s});return this.sql(n)}jsonSql(e){let t=this.sql(e,"this"),s=t?` ${t}`:"",r=e.args.with,n="";r==null?n="":r?n=" WITH":n=" WITHOUT";let a=e.args.unique?" UNIQUE KEYS":"";return`JSON${s}${n}${a}`}jsonValueSql(e){let t=this.sql(e,"path"),s=this.sql(e,"returning");s=s?` RETURNING ${s}`:"";let r=this.sql(e,"onCondition");return r=r?` ${r}`:"",this.func("JSON_VALUE",[e.args.this,`${t}${s}${r}`])}conditionalInsertSql(e){let t=e.args.else?"ELSE ":"",s=this.sql(e,"expression"),r=s?`WHEN ${s} THEN `:t,n=this.sql(e,"this").substring(6).trim();return`${r}${n}`}multitableInsertsSql(e){let t=this.sql(e,"kind"),s=this.seg(this.expressions(e,{sep:" "}));return`INSERT ${t}${s}${this.seg(this.sql(e,"source"))}`}onConditionSql(e){let t=e.args.empty,s="";t instanceof A?s=`DEFAULT ${this.sql(t)} ON EMPTY`:s=this.sql(e,"empty");let r=e.args.error,n="";r instanceof A?n=`DEFAULT ${this.sql(r)} ON ERROR`:n=this.sql(e,"error"),n&&s&&(this._constructor.ON_CONDITION_EMPTY_BEFORE_ERROR?n=`${s} ${n}`:n=`${n} ${s}`,s="");let a=this.sql(e,"null");return`${s}${n}${a}`}jsonExtractSql(e){return this.functionFallbackSql(e)}jsonExtractScalarSql(e){return this.functionFallbackSql(e)}jsonbExtractSql(e){return this.functionFallbackSql(e)}jsonbExtractScalarSql(e){return this.functionFallbackSql(e)}jsonExtractQuoteSql(e){let t=e.args.scalar?" ON SCALAR STRING":"";return`${this.sql(e,"option")} QUOTES${t}`}jsonExistsSql(e){let t=this.sql(e,"this"),s=this.sql(e,"path"),r=this.expressions(e,{key:"passing"}),n=r?` PASSING ${r}`:"",a=this.sql(e,"onCondition");return a=a?` ${a}`:"",s=`${s}${n}${a}`,this.func("JSON_EXISTS",[t,s])}addArrayAggNullFilter(e,t,s){if(!(this.dialect._constructor.ARRAY_AGG_INCLUDES_NULLS&&t.args.nullsExcluded))return e;let r=t.parent;if(r instanceof sr){let n=r.args.expression?.args.this;if(!n)return e;n.replace(n.and(s.is(pe()).not()))}else if(s.find(B)){let n=s instanceof We?this.expressions(s):this.sql(s);e=`${e} FILTER(WHERE ${n} IS NOT NULL)`}return e}arrayAggSql(e){let t=this.functionFallbackSql(e),s=e.args.this instanceof A?e.args.this:void 0;return s?this.addArrayAggNullFilter(t,e,s):t}sliceSql(e){let t=this.sql(e,"step"),s=this.sql(typeof e.args.expression=="number"?e.args.expression.toString():e.args.expression),r=this.sql(e.args.this),n=t?`${s}:${t}`:s;return n?`${r}:${n}`:`${r}:`}applySql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression");return`${t} APPLY(${s})`}grantOrRevokeSql(e,t={}){let{keyword:s,preposition:r,grantOptionPrefix:n="",grantOptionSuffix:a=""}=t,o=this.expressions(e,{key:"privileges",flat:!0}),c=this.sql(e,"kind"),l=c?` ${c}`:"",u=this.sql(e,"securable");u=u?` ${u}`:"";let h=this.expressions(e,{key:"principals",flat:!0}),d=n,x=a;e.args.grantOption||(d=x="");let f=this.sql(e,"cascade"),y=f?` ${f}`:"";return`${s} ${d}${o} ON${l}${u} ${r} ${h}${x}${y}`}grantSql(e){return this.grantOrRevokeSql(e,{keyword:"GRANT",preposition:"TO",grantOptionSuffix:" WITH GRANT OPTION"})}revokeSql(e){return this.grantOrRevokeSql(e,{keyword:"REVOKE",preposition:"FROM",grantOptionPrefix:"GRANT OPTION FOR "})}grantPrivilegeSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{flat:!0}),r=s?`(${s})`:"";return`${t}${r}`}grantPrincipalSql(e){let t=this.sql(e,"this"),s=this.sql(e,"kind");return`${s?`${s} `:""}${t}`}columnsSql(e){let t=this.functionFallbackSql(e);return e.args.unpack?`*${t}`:t}overlaySql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression"),r=this.sql(e,"from"),n=this.sql(e,"for"),a=n?` FOR ${n}`:"";return`OVERLAY(${t} PLACING ${s} FROM ${r}${a})`}toDoubleSql(e){dT.call(this,e,"format");let t=e.args.safe?_t:X;return this.sql(new t({this:e.args.this,to:new O({this:"double"})}))}stringSql(e){let t=e.args.this,s=e.args.zone;return s&&(t=new po({sourceTz:new R({this:"UTC",isString:!0}),targetTz:s,timestamp:t})),this.sql(j(t,"VARCHAR",{dialect:this.dialect}))}medianSql(e){return this._constructor.SUPPORTS_MEDIAN?this.functionFallbackSql(e):this.sql(new FA({this:e.args.this,expression:R.number(.5)}))}overflowTruncateBehaviorSql(e){let t=this.sql(e,"this"),s=t?` ${t}`:"",r=e.args.withCount?"WITH COUNT":"WITHOUT COUNT";return`TRUNCATE${s} ${r}`}unixSecondsSql(e){if(this._constructor.SUPPORTS_UNIX_SECONDS)return this.functionFallbackSql(e);let t=j(R.string("1970-01-01 00:00:00+00"),"timestamptz");return this.sql(new Zl({this:e.args.this,expression:t,unit:new qe({this:"SECONDS"})}))}arraySizeSql(e){let t=e.args.expression;return t&&this._constructor.ARRAY_SIZE_DIM_REQUIRED===void 0&&(t.isInteger&&t.name==="1"||this.unsupported("Cannot transpile dimension argument for ARRAY_LENGTH"),t=void 0),this._constructor.ARRAY_SIZE_DIM_REQUIRED&&!t&&(t=new R({this:"1",isString:!1})),this.func(this._constructor.ARRAY_SIZE_NAME,[e.args.this,t])}attachSql(e){let t=this.sql(e,"this"),s=e.args.exists?" IF NOT EXISTS":"",r=this.expressions(e);return r=r?` (${r})`:"",`ATTACH${s} ${t}${r}`}detachSql(e){let t=this.sql(e,"this");return`DETACH${e.args.exists?" DATABASE IF EXISTS":""} ${t}`}attachOptionSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression");return s=s?` ${s}`:"",`${t}${s}`}watermarkColumnConstraintSql(e){return`WATERMARK FOR ${this.sql(e,"this")} AS ${this.sql(e,"expression")}`}encodePropertySql(e){let s=`${e.args.key?"KEY ENCODE":"ENCODE"} ${this.sql(e,"this")}`,r=e.args.properties;return r&&(te(r,Ke),s=`${s} ${this.properties(r)}`),s}includePropertySql(e){let s=`INCLUDE ${this.sql(e,"this")}`,r=this.sql(e,"columnDef");r&&(s=`${s} ${r}`);let n=this.sql(e,"alias");return n&&(s=`${s} AS ${n}`),s}xmlElementSql(e){let s=`${e.args.evalname?"EVALNAME":"NAME"} ${this.sql(e,"this")}`;return this.func("XmlELEMENT",[s,...e.args.expressions||[]])}xmlKeyValueOptionSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression"),r=s?`(${s})`:"";return`${t}${r}`}partitionByRangePropertySql(e){let t=this.expressions(e,{key:"partitionExpressions"}),s=this.expressions(e,{key:"createExpressions"});return`PARTITION BY RANGE ${this.wrap(t)} ${this.wrap(s)}`}partitionByRangePropertyDynamicSql(e){let t=this.sql(e,"start"),s=this.sql(e,"end"),r=e.args.every;r instanceof Ce&&r.args.this?.isString&&r.args.this.replace(R.number(r.name));let n=this.sql(r);return`START(${t}) END(${s}) EVERY(${n})`}unpivotColumnsSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{flat:!0});return`NAME ${t} VALUE ${s}`}analyzeSampleSql(e){let t=this.sql(e,"kind");return`SAMPLE ${this.sql(e,"sample")} ${t}`}analyzeStatisticsSql(e){let t=this.sql(e,"kind"),s=this.sql(e,"option");s=s?` ${s}`:"";let r=this.sql(e,"this");r=r?` ${r}`:"";let n=this.expressions(e);return n=n?` ${n}`:"",`${t}${s} STATISTICS${r}${n}`}analyzeHistogramSql(e){let t=this.sql(e,"this"),s=this.expressions(e),r=this.sql(e,"expression");r=r?` ${r}`:"";let n=this.sql(e,"updateOptions");return n=n?` ${n} UPDATE`:"",`${t} HISTOGRAM ON ${s}${r}${n}`}analyzeDeleteSql(e){let t=this.sql(e,"kind");return t=t?` ${t}`:"",`DELETE${t} STATISTICS`}analyzeListChainedRowsSql(e){return`LIST CHAINED ROWS${this.sql(e,"expression")}`}analyzeValidateSql(e){let t=this.sql(e,"kind"),s=this.sql(e,"this");s=s?` ${s}`:"";let r=this.sql(e,"expression");return`VALIDATE ${t}${s}${r}`}analyzeSql(e){let t=this.expressions(e,{key:"options",sep:" "});t=t?` ${t}`:"";let s=this.sql(e,"kind");s=s?` ${s}`:"";let r=this.sql(e,"this");r=r?` ${r}`:"";let n=this.sql(e,"mode");n=n?` ${n}`:"";let a=this.sql(e,"properties");a=a?` ${a}`:"";let o=this.sql(e,"partition");o=o?` ${o}`:"";let c=this.sql(e,"expression");return c=c?` ${c}`:"",`ANALYZE${t}${s}${r}${n}${a}${o}${c}`}xmlTableSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{key:"namespaces"}),r=s?`XMLNAMESPACES(${s}), `:"",n=this.expressions(e,{key:"passing"}),a=n?`${this.sep()}PASSING${this.seg(n)}`:"",o=this.expressions(e,{key:"columns"}),c=o?`${this.sep()}COLUMNS${this.seg(o)}`:"",l=e.args.byRef?`${this.sep()}RETURNING SEQUENCE BY REF`:"";return`XMLTABLE(${this.sep("")}${this.indent(r+t+a+l+c)}${this.seg(")","")}`}xmlNamespaceSql(e){let t=this.sql(e,"this");return e.args.this instanceof Re?t:`DEFAULT ${t}`}exportSql(e){let t=this.sql(e,"this"),s=this.sql(e,"connection"),r=s?`WITH CONNECTION ${s} `:"",n=this.sql(e,"options");return`EXPORT DATA ${r}${n} AS ${t}`}declareSql(e){return`DECLARE ${this.expressions(e,{flat:!0})}`}declareItemSql(e){let t=this.sql(e,"this"),s=this.sql(e,"default"),r=s?` = ${s}`:"",n=this.sql(e,"kind");return e.args.kind instanceof At&&(n=`TABLE ${n}`),`${t} AS ${n}${r}`}recursiveWithSearchSql(e){let t=this.sql(e,"kind"),s=this.sql(e,"this"),r=this.sql(e,"expression"),n=this.sql(e,"using"),a=n?` USING ${n}`:"";return`${t==="CYCLE"?t:`SEARCH ${t} FIRST BY`} ${s} SET ${r}${a}`}parameterizedAggSql(e){let t=this.expressions(e,{key:"params",flat:!0}),s=e.name||"";return this.func(s,e.args.expressions||[])+`(${t})`}anonymousAggFuncSql(e){let t=e.name||"";return this.func(t,e.args.expressions||[])}combinedAggFuncSql(e){return this.anonymousAggFuncSql(e)}combinedParameterizedAggSql(e){return this.parameterizedAggSql(e)}showSql(e){return this.unsupported("Unsupported SHOW statement"),""}installSql(e){return this.unsupported("Unsupported INSTALL statement"),""}getPutSql(e){let t=e.args.properties;t&&te(t,Ke);let s=t?this.properties(t,{prefix:" ",sep:" ",wrapped:!1}):"",r=this.sql(e,"this"),n=this.sql(e,"target");return e instanceof Da?`PUT ${r} ${n}${s}`:`GET ${n} ${r}${s}`}translateCharactersSql(e){let t=this.sql(e,"this"),s=this.sql(e,"expression"),r=e.args.withError?" WITH ERROR":"";return`TRANSLATE(${t} USING ${s}${r})`}decodeCaseSql(e){if(this._constructor.SUPPORTS_DECODE_CASE)return this.func("DECODE",e.args.expressions??[]);let[t,...s]=e.args.expressions??[],r=[];for(let o=0;o<s.length-1;o+=2){let c=s[o],l=s[o+1];if(c instanceof R)r.push(new le({this:t.eq(c),true:l}));else if(c instanceof Ze)r.push(new le({this:t.is(pe()),true:l}));else{let u=c;u instanceof q&&(u=ki(u));let h=Kt([t.eq(u),Fe([t.is(pe()),u.is(pe())],{copy:!1})],{copy:!1});r.push(new le({this:h,true:l}))}}let n=s.length%2===1?s[s.length-1]:void 0,a=new nt({ifs:r,default:n});return this.sql(a)}semanticViewSql(e){let t=this.sql(e,"this"),s=this.seg(t,""),r=this.expressions(e,{key:"dimensions",dynamic:!0,skipFirst:!0,skipLast:!0}),n=r?this.seg(`DIMENSIONS ${r}`):"",a=this.expressions(e,{key:"metrics",dynamic:!0,skipFirst:!0,skipLast:!0}),o=a?this.seg(`METRICS ${a}`):"",c=this.expressions(e,{key:"facts",dynamic:!0,skipFirst:!0,skipLast:!0}),l=c?this.seg(`FACTS ${c}`):"",u=this.sql(e,"where"),h=u?this.seg(`WHERE ${u}`):"";return`SEMANTIC_VIEW(${this.indent(s+o+n+l+h,{skipFirst:!0})}${this.seg(")","")}`}getExtractSql(e){let t=e.args.this,s=e.args.expression;return t?((!t.type||!e.type)&&(t=gs(t,{dialect:this.dialect})),t.isType(["array","map"])?this.sql(new Dt({this:t,expressions:s?[s]:[]})):this.sql(new js({this:t,expression:this.dialect.toJsonPath(s)}))):""}dateFromUnixDateSql(e){return this.sql(new yt({this:j(R.string("1970-01-01"),"date"),expression:e.args.this,unit:Q("DAY")}))}spaceSql(e){return this.func("REPEAT",[ml(" "),e.args.this])}buildPropertySql(e){return`BUILD ${this.sql(e,"this")}`}refreshTriggerPropertySql(e){let t=this.sql(e,"method"),s=e.args.kind;if(!s)return`REFRESH ${t}`;let r=this.sql(e,"every"),n=this.sql(e,"unit"),a=r?` EVERY ${r} ${n}`:"",o=this.sql(e,"starts");return o=o?` STARTS ${o}`:"",`REFRESH ${t} ON ${s}${a}${o}`}modelAttributeSql(e){return this.unsupported("The model!attribute syntax is not supported"),""}directoryStageSql(e){return this.func("DIRECTORY",[e.args.this])}uuidSql(e){let t=this.func("UUID",[]);return e.args.isString&&!this.dialect._constructor.UUID_IS_STRING_TYPE?this.sql(j(Q(t),"varchar")):t}initcapSql(e){let t=e.args.expression;return t&&(this.dialect._constructor.INITCAP_SUPPORTS_CUSTOM_DELIMITERS?t.isString&&t.args.this===this.dialect._constructor.INITCAP_DEFAULT_DELIMITER_CHARS&&(t=void 0):t=void 0),this.func("INITCAP",[e.args.this,t])}localtimeSql(e){let t=e.args.this;return t?this.func("LOCALTIME",[t]):"LOCALTIME"}localtimestampSql(e){let t=e.args.this;return t?this.func("LOCALTIMESTAMP",[t]):"LOCALTIMESTAMP"}weekStartSql(e){let t=e.args.this,s=t?.name.toUpperCase();return this.dialect._constructor.WEEK_OFFSET===-1&&s==="SUNDAY"?"WEEK":this.func("WEEK",[t])}chrSql(e,t={}){let{name:s="CHR"}=t,r=this.expressions(e),n=this.sql(e,"charset"),a=n?` USING ${n}`:"";return this.func(s,[r+a])}blockSql(e){let t=this.expressions(e,{sep:"; ",flat:!0});return t?`${t}`:""}tableSampleSql(e,t={}){let{tablesampleKeyword:s}=t,r=this.sql(e,"method");r=r&&this._constructor.TABLESAMPLE_WITH_METHOD?`${r} `:"";let n=this.sql(e,"bucketNumerator"),a=this.sql(e,"bucketDenominator"),o=this.sql(e,"bucketField");o=o?` ON ${o}`:"";let c=n?`BUCKET ${n} OUT OF ${a}${o}`:"",l=this.sql(e,"seed");l=l?` ${this._constructor.TABLESAMPLE_SEED_KEYWORD} (${l})`:"";let u=this.sql(e,"size");u&&this._constructor.TABLESAMPLE_SIZE_IS_ROWS&&(u=`${u} ROWS`);let h=this.sql(e,"percent");h&&!this.dialect._constructor.TABLESAMPLE_SIZE_IS_PERCENT&&(h=`${h} PERCENT`);let d=`${c}${h}${u}`;return this._constructor.TABLESAMPLE_REQUIRES_PARENS&&(d=`(${d})`),` ${s||this._constructor.TABLESAMPLE_KEYWORDS} ${r}${d}${l}`}maskingPolicyColumnConstraintSql(e){let t=this.sql(e,"this"),s=this.expressions(e,{flat:!0});return s=s?` USING (${s})`:"",`MASKING POLICY ${t}${s}`}uniqueKeyPropertySql(e,t={}){let{prefix:s="UNIQUE KEY"}=t;return`${s} (${this.expressions(e,{flat:!0})})`}formatTime(e,t,s){let r=this.dialect._constructor,n=t||r.INVERSE_TIME_MAPPING,a=s||r.INVERSE_TIME_TRIE;return Ol(this.sql(e,"format"),n,a)}ceilSql(e){return this.ceilFloor(e)}floorSql(e){return this.ceilFloor(e)}offsetLimitModifiers(e,t,s){let{fetch:r}=t;return[r?this.sql(e,"offset"):this.sql(s),r?this.sql(s):this.sql(e,"offset")]}};Ss=Bt(null),S(Ss,10,"NULL_ORDERING_SUPPORTED",y_,b),S(Ss,10,"SUPPORTED_JSON_PATH_PARTS",I_,b),S(Ss,10,"UNWRAPPED_INTERVAL_VALUES",N_,b),S(Ss,10,"WITH_SEPARATED_COMMENTS",R_,b),S(Ss,10,"EXCLUDE_COMMENTS",O_,b),S(Ss,10,"TYPE_MAPPING",m_,b),S(Ss,10,"UNSUPPORTED_TYPES",S_,b),S(Ss,10,"PARAMETERIZABLE_TEXT_TYPES",T_,b),S(Ss,10,"TOKEN_MAPPING",f_,b),S(Ss,10,"ORIGINAL_TRANSFORMS",x_,b),S(Ss,10,"TRANSFORMS",d_,b),S(Ss,10,"PROPERTIES_LOCATION",A_,b),bt(Ss,b),Lt(Ss,3,b),b.IGNORE_NULLS_IN_FUNC=!1,b.RESPECT_IGNORE_NULLS_UNSUPPORTED_EXPRESSIONS=[],b.LOCKING_READS_SUPPORTED=!1,b.EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE=!0,b.WRAP_DERIVED_VALUES=!0,b.CREATE_FUNCTION_RETURN_AS=!0,b.MATCHED_BY_SOURCE=!0,b.SINGLE_STRING_INTERVAL=!1,b.INTERVAL_ALLOWS_PLURAL_FORM=!0,b.LIMIT_FETCH="ALL",b.LIMIT_ONLY_LITERALS=!1,b.RENAME_TABLE_WITH_DB=!0,b.GROUPINGS_SEP=",",b.INDEX_ON="ON",b.INOUT_SEPARATOR=" ",b.JOIN_HINTS=!0,b.DIRECTED_JOINS=!1,b.TABLE_HINTS=!0,b.QUERY_HINTS=!0,b.QUERY_HINT_SEP=", ",b.IS_BOOL_ALLOWED=!0,b.DUPLICATE_KEY_UPDATE_WITH_SET=!0,b.LIMIT_IS_TOP=!1,b.RETURNING_END=!0,b.EXTRACT_ALLOWS_QUOTES=!0,b.TZ_TO_WITH_TIME_ZONE=!1,b.NVL2_SUPPORTED=!0,b.SELECT_KINDS=["STRUCT","VALUE"],b.VALUES_AS_TABLE=!0,b.ALTER_TABLE_INCLUDE_COLUMN_KEYWORD=!0,b.UNNEST_WITH_ORDINALITY=!0,b.AGGREGATE_FILTER_SUPPORTED=!0,b.SEMI_ANTI_JOIN_WITH_SIDE=!0,b.COMPUTED_COLUMN_WITH_TYPE=!0,b.SUPPORTS_TABLE_COPY=!0,b.TABLESAMPLE_REQUIRES_PARENS=!0,b.TABLESAMPLE_SIZE_IS_ROWS=!0,b.TABLESAMPLE_SIZE_IS_PERCENT=!1,b.TABLESAMPLE_KEYWORDS="TABLESAMPLE",b.TABLESAMPLE_WITH_METHOD=!0,b.TABLESAMPLE_SEED_KEYWORD="SEED",b.COLLATE_IS_FUNC=!1,b.DATA_TYPE_SPECIFIERS_ALLOWED=!1,b.ENSURE_BOOLS=!1,b.CTE_RECURSIVE_KEYWORD_REQUIRED=!0,b.SUPPORTS_SINGLE_ARG_CONCAT=!0,b.LAST_DAY_SUPPORTS_DATE_PART=!0,b.SUPPORTS_TABLE_ALIAS_COLUMNS=!0,b.UNPIVOT_ALIASES_ARE_IDENTIFIERS=!0,b.JSON_KEY_VALUE_PAIR_SEP=":",b.INSERT_OVERWRITE=" OVERWRITE TABLE",b.SUPPORTS_SELECT_INTO=!1,b.SUPPORTS_UNLOGGED_TABLES=!1,b.SUPPORTS_CREATE_TABLE_LIKE=!0,b.LIKE_PROPERTY_INSIDE_SCHEMA=!1,b.MULTI_ARG_DISTINCT=!0,b.JSON_TYPE_REQUIRED_FOR_EXTRACTION=!1,b.JSON_PATH_BRACKETED_KEY_SUPPORTED=!0,b.JSON_PATH_SINGLE_QUOTE_ESCAPE=!1,b.CAN_IMPLEMENT_ARRAY_ANY=!1,b.SUPPORTS_TO_NUMBER=!0,b.SUPPORTS_WINDOW_EXCLUDE=!1,b.SET_OP_MODIFIERS=!0,b.COPY_PARAMS_ARE_WRAPPED=!0,b.COPY_PARAMS_EQ_REQUIRED=!1,b.COPY_HAS_INTO_KEYWORD=!0,b.TRY_SUPPORTED=!0,b.SUPPORTS_UESCAPE=!0,b.UNICODE_SUBSTITUTE=void 0,b.STAR_EXCEPT="EXCEPT",b.HEX_FUNC="HEX",b.WITH_PROPERTIES_PREFIX="WITH",b.QUOTE_JSON_PATH=!0,b.PAD_FILL_PATTERN_IS_REQUIRED=!1,b.SUPPORTS_EXPLODING_PROJECTIONS=!0,b.ARRAY_CONCAT_IS_VAR_LEN=!0,b.SUPPORTS_CONVERT_TIMEZONE=!1,b.SUPPORTS_MEDIAN=!0,b.SUPPORTS_UNIX_SECONDS=!1,b.ALTER_SET_WRAPPED=!1,b.NORMALIZE_EXTRACT_DATE_PARTS=!1,b.PARSE_JSON_NAME="PARSE_JSON",b.ARRAY_SIZE_NAME="ARRAY_LENGTH",b.ALTER_SET_TYPE="SET DATA TYPE",b.ARRAY_SIZE_DIM_REQUIRED=void 0,b.SUPPORTS_DECODE_CASE=!0,b.ON_CONDITION_EMPTY_BEFORE_ERROR=!1,b.SUPPORTS_BETWEEN_FLAGS=!1,b.SUPPORTS_LIKE_QUANTIFIERS=!0,b.MATCH_AGAINST_TABLE_PREFIX=void 0,b.SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD=!1,b.UPDATE_STATEMENT_SUPPORTS_FROM=!0,b.STAR_EXCLUDE_REQUIRES_DERIVED_TABLE=!0,b.AFTER_HAVING_MODIFIER_TRANSFORMS=new Map([["cluster",function(e){return this.sql(e,"cluster")}],["distribute",function(e){return this.sql(e,"distribute")}],["sort",function(e){return this.sql(e,"sort")}],["windows",function(e){return e.getArgKey("windows")?this.seg("WINDOW ")+this.expressions(e,{key:"windows",flat:!0}):""}],["qualify",function(e){return this.sql(e,"qualify")}]]),b.SAFE_JSON_PATH_KEY_RE=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,b.SENTINEL_LINE_BREAK="__SQLGLOT__LB__",b.TIME_PART_SINGULARS={MICROSECONDS:"MICROSECOND",SECONDS:"SECOND",MINUTES:"MINUTE",HOURS:"HOUR",DAYS:"DAY",WEEKS:"WEEK",MONTHS:"MONTH",QUARTERS:"QUARTER",YEARS:"YEAR"},b.STRUCT_DELIMITER=["<",">"],b.PARAMETER_TOKEN="@",b.NAMED_PLACEHOLDER_TOKEN=":",b.RESERVED_KEYWORDS=new Set,b.EXPRESSIONS_WITHOUT_NESTED_CTES=new Set,b.EXPRESSION_PRECEDES_PROPERTIES_CREATABLES=new Set;function U$(i,e){return new b(e).generate(i)}var b_,L_,CN;L_=[m],b_=[m];var su=class su{static get TIMESTAMP_EXPRESSIONS(){return new Set([Na,tr,ou,ru,ES,tm])}static get EXPRESSION_METADATA(){let e=new Map,t=(s,r)=>{for(let n of s)e.set(n,r)};return t([pm,Bn,Em,eu,KS,rm,im,nm],{returns:"BIGINT"}),t([RS,NS],{returns:"BINARY"}),t([ys,Ct,ss,ot,eS,HS,Pi,it,wS,LS,dm,Am,op,Tl],{returns:"BOOLEAN"}),t([$i,La,xS,fS,mS,xp,ba,XS,Is],{returns:"DATE"}),t([tS,rS,fr,_i],{returns:"DATETIME"}),t([LT,wT,PT,bT,$n,MT,DT,um,vl,_T,BT,kT,OS,Im,Hl,Yi,qS,au,$A,vS,FS,BS,qT,UT,Wl,Sm,mm,Om,vT,FT,VT,Rm,Nm,ym],{returns:"DOUBLE"}),t([YT,MS,Oa,iS,PS,bS,Zl,dS,ZS,SS,DS,nu,YS,mr,QS,US],{returns:"INT"}),t([Ce,QT,ZT,KT,gS],{returns:"INTERVAL"}),e.set(Pa,{returns:"Json"}),t([Ra,Fl,jS,iu,AS],{returns:"TIME"}),e.set(am,{returns:"TIMESTAMPLTZ"}),t([sS,om],{returns:"TIMESTAMPTZ"}),su.TIMESTAMP_EXPRESSIONS.forEach(s=>e.set(s,{returns:"TIMESTAMP"})),t([Vn,oS,nS,aS,cS,_S,BA,lS,cm,uS,hS],{returns:"TINYINT"}),t([XT,Gt,wt,ql,Ql,pS,TS,Mt,Ui,$l,Fn,kS,$S,GS,er,zT,Gn,JS,cp,IS,yS,GT,zS,em,sm,jl,pa,WS],{returns:"VARCHAR"}),t([$T,hm,lm,jT,JT,sr,qs,gm,Et,fe,VS,we],{annotator:(s,r)=>s.annotateByArgs(r,["this"])}),t([_l,rt,ya,Vl,xm,fm],{annotator:(s,r)=>s.annotateByArgs(r,["this","expressions"])}),t([HT,WT],{annotator:(s,r)=>s.annotateByArrayElement(r)}),t([yt,ts,bs],{annotator:(s,r)=>s.annotateTimeunit(r)}),t([X,_t],{annotator:(s,r)=>s.setType(r,r.args.to)}),t([io,Ys],{annotator:(s,r)=>s.annotateMap(r)}),e.set(je,{annotator:(s,r)=>s.setType(r,s.schema.getUdfType(r))}),e.set(ue,{annotator:(s,r)=>s.annotateByArgs(r,["expressions"],{array:!0})}),e.set(uo,{annotator:(s,r)=>s.annotateByArgs(r,["this"],{array:!0})}),e.set(Dt,{annotator:(s,r)=>s.annotateBracket(r)}),e.set(nt,{annotator:(s,r)=>s.annotateByArgs(r,[...Rt(r.args.ifs??[],le).flatMap(n=>n.args.true??[]),"default"])}),e.set(Jl,{annotator:(s,r)=>s.setType(r,r.args.bigInt?"bigint":"int")}),e.set(wa,{annotator:(s,r)=>s.setType(r,r.args.bigInt?"bigint":"int")}),e.set(O,{annotator:(s,r)=>s.setType(r,r.copy())}),e.set(mt,{annotator:(s,r)=>s.annotateDiv(r)}),e.set(We,{annotator:(s,r)=>s.annotateByArgs(r,["expressions"])}),e.set(Se,{annotator:(s,r)=>s.annotateDot(r)}),e.set(rs,{annotator:(s,r)=>s.annotateExplode(r)}),e.set(Gi,{annotator:(s,r)=>s.annotateExtract(r)}),e.set(da,{annotator:(s,r)=>s.setType(r,r.args.isInteger?"bigint":"binary")}),e.set(Fs,{annotator:(s,r)=>s.annotateByArgs(r,["start","end","step"],{array:!0})}),e.set(Ia,{annotator:(s,r)=>s.setType(r,O.build("ARRAY<DATE>"))}),e.set(CS,{annotator:(s,r)=>s.setType(r,O.build("ARRAY<TIMESTAMP>"))}),e.set(le,{annotator:(s,r)=>s.annotateByArgs(r,["true","false"])}),e.set(R,{annotator:(s,r)=>s.annotateLiteral(r)}),e.set(Ze,{returns:"NULL"}),e.set(Kl,{annotator:(s,r)=>s.annotateByArgs(r,["this","expression"])}),e.set(ct,{annotator:(s,r)=>s.annotateByArgs(r,["expression"])}),e.set(ks,{annotator:(s,r)=>s.annotateStruct(r)}),e.set(Tm,{annotator:(s,r)=>s.annotateByArgs(r,["this","expressions"],{promote:!0})}),e.set(Xl,{annotator:(s,r)=>s.setType(r,r.args.withTz?"timestamptz":"timestamp")}),e.set(tu,{annotator:(s,r)=>s.annotateToMap(r)}),e.set(ge,{annotator:(s,r)=>s.annotateUnnest(r)}),e.set(Te,{annotator:(s,r)=>s.annotateSubquery(r)}),e.set(be,{annotator:(s,r)=>s.annotateUnary(r)}),e.set(It,{annotator:(s,r)=>s.annotateUnary(r)}),e.set(np,{annotator:(s,r)=>s.annotateUnary(r)}),e.set(Oe,{annotator:(s,r)=>s.annotateUnary(r)}),e.set(Re,{annotator:(s,r)=>s.annotateUnary(r)}),e}};CN=Bt(null),S(CN,10,"TIMESTAMP_EXPRESSIONS",L_,su),S(CN,10,"EXPRESSION_METADATA",b_,su),bt(CN,su),Lt(CN,3,su);var PN=su;var BU={"\\a":"\x07","\\b":"\b","\\f":"\f","\\n":`
17
+ `,"\\r":"\r","\\t":" ","\\v":"\v","\\\\":"\\"};var IN=(de=>(de.DIALECT="",de.ATHENA="athena",de.BIGQUERY="bigquery",de.CLICKHOUSE="clickhouse",de.DATABRICKS="databricks",de.DORIS="doris",de.DREMIO="dremio",de.DRILL="drill",de.DRUID="druid",de.DUCKDB="duckdb",de.DUNE="dune",de.FABRIC="fabric",de.HIVE="hive",de.MATERIALIZE="materialize",de.MYSQL="mysql",de.ORACLE="oracle",de.POSTGRES="postgres",de.PRESTO="presto",de.PRQL="prql",de.REDSHIFT="redshift",de.RISINGWAVE="risingwave",de.SINGLESTORE="singlestore",de.SNOWFLAKE="snowflake",de.SOLR="solr",de.SPARK="spark",de.SPARK2="spark2",de.SQLITE="sqlite",de.STARROCKS="starrocks",de.TABLEAU="tableau",de.TERADATA="teradata",de.TRINO="trino",de.TSQL="tsql",de.EXASOL="exasol",de))(IN||{}),sq=(n=>(n.LOWERCASE="lowercase",n.UPPERCASE="uppercase",n.CASE_SENSITIVE="caseSensitive",n.CASE_INSENSITIVE="caseInsensitive",n.CASE_INSENSITIVE_UPPERCASE="caseInsensitiveUppercase",n))(sq||{}),w_,M_,D_,k_,__,q_,U_,v_,F_,B_,$_,G_,Y_,V_,H_,W_,j_,J_,X_,z_,Q_,Z_,K_,eq,tq,Ue;tq=[m],eq=[m],K_=[m],Z_=[m],Q_=[m],z_=[m],X_=[m],J_=[m],j_=[m],W_=[m],H_=[m],V_=[m],Y_=[m],G_=[m],$_=[m],B_=[m],F_=[m],v_=[m],U_=[m],q_=[m],__=[m],k_=[m],D_=[m],M_=[m],w_=[m];var w=class w{constructor(e={}){this.version=void 0;this.normalizationStrategy=void 0;this.settings=void 0;let{version:t=Number.MAX_SAFE_INTEGER,normalizationStrategy:s}=e,r=t.toString().split(".");for(;r.length<3;)r.push("0");this.version={major:parseInt(r[0]),minor:parseInt(r[1]),patch:parseInt(r[2])},this.normalizationStrategy=ut(sq,s)??this._constructor.NORMALIZATION_STRATEGY,this.settings=e;for(let n of Object.keys(e))this._constructor.SUPPORTED_SETTINGS.has(n)||LI("setting",n,[...this._constructor.SUPPORTED_SETTINGS])}static get SUPPORTS_COLUMN_JOIN_MARKS(){return!!this.tokenizerClass.KEYWORDS["(+)"]}static get NULL_ORDERING(){return"nulls_are_small"}static get TIME_MAPPING(){return{}}static get FORMAT_MAPPING(){return{}}static get UNESCAPED_SEQUENCES(){let e={};return this.STRINGS_SUPPORT_ESCAPED_SEQUENCES||this.BYTE_STRINGS_SUPPORT_ESCAPED_SEQUENCES?e={...BU,...this.ORIGINAL_UNESCAPED_SEQUENCES}:e=this.ORIGINAL_UNESCAPED_SEQUENCES,e}static get PSEUDOCOLUMNS(){return new Set}static get SET_OP_DISTINCT_BY_DEFAULT(){return{except:!0,intersect:!0,union:!0}}static get CREATABLE_KIND_MAPPING(){return{}}static get INITCAP_SUPPORTS_CUSTOM_DELIMITERS(){return["","bigquery","snowflake"].includes(this.DIALECT_NAME)}static get DEFAULT_FUNCTIONS_COLUMN_NAMES(){return new Map}static get DEFAULT_NULL_TYPE(){return"unknown"}static get UNMERGABLE_ARGS(){return new Set(Array.from(ee.availableArgs).filter(e=>!["expressions","from","joins","where","order","hint"].includes(e)))}static get TRY_SUPPORTED(){return["","athena","presto","trino","duckdb"].includes(this.DIALECT_NAME)}static get SUPPORTS_UESCAPE(){return["","athena","presto","trino","duckdb"].includes(this.DIALECT_NAME)}static get tokenizerClass(){let e=this._tokenizerClassCache.get(this);if(e)return e;if(Object.prototype.hasOwnProperty.call(this,"Tokenizer"))return this.Tokenizer;let s=Object.getPrototypeOf(this)?.tokenizerClass;if(!s)return this._tokenizerClassCache.set(this,Qn),Qn;class r extends s{}return this._tokenizerClassCache.set(this,r),r}static get jsonpathTokenizerClass(){let e=this._jsonpathTokenizerClassCache.get(this);if(e)return e;if(Object.prototype.hasOwnProperty.call(this,"JsonPathTokenizer"))return this.JsonPathTokenizer;let s=Object.getPrototypeOf(this)?.JsonPathTokenizer;if(!s)return this._jsonpathTokenizerClassCache.set(this,vt),vt;class r extends s{}return this._jsonpathTokenizerClassCache.set(this,r),r}static get parserClass(){let e=this._parserClassCache.get(this);if(e)return e;if(Object.prototype.hasOwnProperty.call(this,"Parser"))return this.Parser;let s=Object.getPrototypeOf(this)?.parserClass;if(!s)return this._parserClassCache.set(this,Gf),Gf;class r extends s{}return this._parserClassCache.set(this,r),r}static get generatorClass(){let e=this._generatorClassCache.get(this);if(e)return e;if(Object.prototype.hasOwnProperty.call(this,"Generator"))return this.Generator;let s=Object.getPrototypeOf(this)?.generatorClass;if(!s)return this._generatorClassCache.set(this,b),b;class r extends s{}return this._generatorClassCache.set(this,r),r}static get TIME_TRIE(){return is(Object.keys(this.TIME_MAPPING).map(e=>Array.from(e)))}static get FORMAT_TRIE(){let e=0<Object.keys(this.FORMAT_MAPPING).length?this.FORMAT_MAPPING:this.TIME_MAPPING;return is(Object.keys(e).map(t=>Array.from(t)))}static get INVERSE_TIME_MAPPING(){return Object.fromEntries(Object.entries(this.TIME_MAPPING).map(([e,t])=>[t,e]))}static get INVERSE_TIME_TRIE(){return is(Object.keys(this.INVERSE_TIME_MAPPING).map(e=>Array.from(e)))}static get INVERSE_FORMAT_MAPPING(){return Object.fromEntries(Object.entries(this.FORMAT_MAPPING).map(([e,t])=>[t,e]))}static get INVERSE_CREATABLE_KIND_MAPPING(){return Object.fromEntries(Object.entries(this.CREATABLE_KIND_MAPPING).map(([e,t])=>[t,e]))}static get ESCAPED_SEQUENCES(){return Object.fromEntries(Object.entries(this.UNESCAPED_SEQUENCES).map(([e,t])=>[t,e]))}static get QUOTE_START(){return Object.entries(this.tokenizerClass._QUOTES)[0]?.[0]}static get QUOTE_END(){return Object.entries(this.tokenizerClass._QUOTES)[0]?.[1]}static get IDENTIFIER_START(){return Object.entries(this.tokenizerClass._IDENTIFIERS)[0]?.[0]}static get IDENTIFIER_END(){return Object.entries(this.tokenizerClass._IDENTIFIERS)[0]?.[1]}static getStartEnd(e){let t=Object.entries(this.tokenizerClass._FORMAT_STRINGS).find(([s,[r,n]])=>n===e);if(t){let[s,[r]]=t;return[s,r]}return[void 0,void 0]}static get BIT_START(){return this.getStartEnd("bitString")[0]}static get BIT_END(){return this.getStartEnd("bitString")[1]}static get HEX_START(){return this.getStartEnd("hexString")[0]}static get HEX_END(){return this.getStartEnd("hexString")[1]}static get BYTE_START(){return this.getStartEnd("byteString")[0]}static get BYTE_END(){return this.getStartEnd("byteString")[1]}static get UNICODE_START(){return this.getStartEnd("unicodeString")[0]}static get UNICODE_END(){return this.getStartEnd("unicodeString")[1]}static get DATE_PART_MAPPING(){return{Y:"YEAR",YY:"YEAR",YYY:"YEAR",YYYY:"YEAR",YR:"YEAR",YEARS:"YEAR",YRS:"YEAR",MM:"MONTH",MON:"MONTH",MONS:"MONTH",MONTHS:"MONTH",D:"DAY",DD:"DAY",DAYS:"DAY",DAYOFMONTH:"DAY","DAY OF WEEK":"DAYOFWEEK",WEEKDAY:"DAYOFWEEK",DOW:"DAYOFWEEK",DW:"DAYOFWEEK",WEEKDAY_ISO:"DAYOFWEEKISO",DOW_ISO:"DAYOFWEEKISO",DW_ISO:"DAYOFWEEKISO",DAYOFWEEK_ISO:"DAYOFWEEKISO","DAY OF YEAR":"DAYOFYEAR",DOY:"DAYOFYEAR",DY:"DAYOFYEAR",W:"WEEK",WK:"WEEK",WEEKOFYEAR:"WEEK",WOY:"WEEK",WY:"WEEK",WEEK_ISO:"WEEKISO",WEEKOFYEARISO:"WEEKISO",WEEKOFYEAR_ISO:"WEEKISO",Q:"QUARTER",QTR:"QUARTER",QTRS:"QUARTER",QUARTERS:"QUARTER",H:"HOUR",HH:"HOUR",HR:"HOUR",HOURS:"HOUR",HRS:"HOUR",M:"MINUTE",MI:"MINUTE",MIN:"MINUTE",MINUTES:"MINUTE",MINS:"MINUTE",S:"SECOND",SEC:"SECOND",SECONDS:"SECOND",SECS:"SECOND",MS:"MILLISECOND",MSEC:"MILLISECOND",MSECS:"MILLISECOND",MSECOND:"MILLISECOND",MSECONDS:"MILLISECOND",MILLISEC:"MILLISECOND",MILLISECS:"MILLISECOND",MILLISECON:"MILLISECOND",MILLISECONDS:"MILLISECOND",US:"MICROSECOND",USEC:"MICROSECOND",USECS:"MICROSECOND",MICROSEC:"MICROSECOND",MICROSECS:"MICROSECOND",USECOND:"MICROSECOND",USECONDS:"MICROSECOND",MICROSECONDS:"MICROSECOND",NS:"NANOSECOND",NSEC:"NANOSECOND",NANOSEC:"NANOSECOND",NSECOND:"NANOSECOND",NSECONDS:"NANOSECOND",NANOSECS:"NANOSECOND",EPOCH_SECOND:"EPOCH",EPOCH_SECONDS:"EPOCH",EPOCH_MILLISECONDS:"EPOCH_MILLISECOND",EPOCH_MICROSECONDS:"EPOCH_MICROSECOND",EPOCH_NANOSECONDS:"EPOCH_NANOSECOND",TZH:"TIMEZONE_HOUR",TZM:"TIMEZONE_MINUTE",DEC:"DECADE",DECS:"DECADE",DECADES:"DECADE",MIL:"MILLENNIUM",MILS:"MILLENNIUM",MILLENIA:"MILLENNIUM",C:"CENTURY",CENT:"CENTURY",CENTS:"CENTURY",CENTURIES:"CENTURY"}}static get COERCES_TO(){return new Map}static get EXPRESSION_METADATA(){return PN.EXPRESSION_METADATA}static get SUPPORTED_SETTINGS(){return new Set(["normalizationStrategy","version"])}static get QUOTE_DELIMITERS(){return Object.entries(this.tokenizerClass.QUOTES)[0]}static get IDENTIFIER_DELIMITERS(){return Object.entries(this.tokenizerClass.IDENTIFIERS)[0]}static get BASE_VALID_INTERVAL_UNITS(){return new Set}static get VALID_INTERVAL_UNITS(){let e=this.DATE_PART_MAPPING;return new Set([...this.BASE_VALID_INTERVAL_UNITS,...Object.keys(e),...Object.values(e)])}static get STRINGS_SUPPORT_ESCAPED_SEQUENCES(){return this.tokenizerClass.STRING_ESCAPES.includes("\\")}static get BYTE_STRINGS_SUPPORT_ESCAPED_SEQUENCES(){return this.tokenizerClass.BYTE_STRING_ESCAPES.includes("\\")}static equals(e){return this===e?!0:typeof e=="string"?this===this.get(e):e instanceof w?this===e.constructor:!1}static register(e,t){this.registry.set(e,t)}static get(e,t){return this.registry.get(e)||t}static getOrRaise(e){if(!e)return new this;if(typeof e=="function"&&(e===w||e.prototype instanceof w))return new e;if(e instanceof w)return e;if(typeof e=="string"){let t,s={};try{let[n,...a]=e.split(",");t=n.trim();for(let o of a){let c=o.split("="),l=c[0].trim(),u=!0;c.length===2&&(u=c[1].trim()),s[l]=dD(u)??u}}catch{throw new Error(`Invalid dialect format: '${e}'. Please use the correct format: 'dialect [, k1 = v2 [, ...]]'.`)}let r=this.get(t);if(!r){let n=new Set(Object.keys(IN));LI("dialect",t,Array.from(n))}return new r(s)}throw new Error(`Invalid dialect type for '${e}': '${typeof e}'.`)}static formatTime(e){return typeof e=="string"?R.string(Ol(e.slice(1,-1),this.TIME_MAPPING,this.TIME_TRIE)??""):e instanceof A&&e.isString?R.string(Ol(e.args.this,this.TIME_MAPPING,this.TIME_TRIE)??""):e}equals(e){return this===e?!0:e instanceof w?this.constructor===e.constructor:!1}hash(){return this.constructor.name.toLowerCase()}normalizeIdentifier(e){if(e instanceof U&&this.normalizationStrategy!=="caseSensitive"&&(!e.args.quoted||this.normalizationStrategy==="caseInsensitive"||this.normalizationStrategy==="caseInsensitiveUppercase")){let t=this.normalizationStrategy==="uppercase"||this.normalizationStrategy==="caseInsensitiveUppercase",s=e.args.this;if(typeof s=="string"){let r=t?s.toUpperCase():s.toLowerCase();e.setArgKey("this",r)}}return e}caseSensitive(e){if(this.normalizationStrategy==="caseInsensitive")return!1;let t=this.normalizationStrategy==="uppercase"?s=>s===s.toLowerCase()&&s!==s.toUpperCase():s=>s===s.toUpperCase()&&s!==s.toLowerCase();return Array.from(e).some(t)}canQuote(e,t={}){let{identify:s="safe"}=t;if(e.args.quoted)return!0;if(!s)return!1;if(s===!0)return!0;let r=e.name??"",n=!this.caseSensitive(r)&&wm.test(r);if(s==="safe")return n;if(s==="unsafe")return!n;throw new Error(`Unexpected argument for identify: '${s}'`)}quoteIdentifier(e,t={}){let{identify:s=!0}=t;return e instanceof U&&e.setArgKey("quoted",this.canQuote(e,{identify:s||"unsafe"})),e}toJsonPath(e){if(e instanceof R){let t=e.name;e.isNumber&&(t=`[${t}]`);try{return BI(t,{dialect:this})}catch(s){let r=this._constructor.STRICT_JSON_PATH_SYNTAX,n=t.trimStart(),a=n.startsWith("lax")||n.startsWith("strict");r&&!a&&console.warn(`Invalid JSON path syntax. ${s instanceof Error?s.message:String(s)}`)}}return e}parse(e,t){return this.parser(t).parse(this.tokenize(e),e)}parser(e){return new this._constructor.parserClass({dialect:this,...e})}parseIntoTypes(e,t,s){return this.parser(s).parseIntoTypes(e,this.tokenize(t),t)}generate(e,t={}){let{copy:s=!0,...r}=t;return this.generator(r).generate(e,{copy:s})}generator(e={}){return new this._constructor.generatorClass({dialect:this,...e})}tokenize(e,t={}){return this.tokenizer(t).tokenize(e)}tokenizer(e={}){return new this._constructor.tokenizerClass({dialect:this,...e})}jsonpathTokenizer(e={}){return new this._constructor.jsonpathTokenizerClass({dialect:this,...e})}transpile(e,t={}){return this.parse(e,t).map(s=>s?this.generate(s,{copy:!1,...t}):"")}generateValuesAliases(e){let t=e.args.expressions?.[0];return t instanceof A?(t.args.expressions??[]).map((r,n)=>Z(`_col_${n}`)):[]}get _constructor(){return this.constructor}isKind(e){let t=ut(IN,e);return t!==void 0?this._constructor.DIALECT_NAME===t:this._constructor.DIALECT_NAME.toLowerCase()===e.toLowerCase()}};Ue=Bt(null),S(Ue,10,"NULL_ORDERING",tq,w),S(Ue,10,"TIME_MAPPING",eq,w),S(Ue,10,"FORMAT_MAPPING",K_,w),S(Ue,10,"UNESCAPED_SEQUENCES",Z_,w),S(Ue,10,"PSEUDOCOLUMNS",Q_,w),S(Ue,10,"SET_OP_DISTINCT_BY_DEFAULT",z_,w),S(Ue,10,"CREATABLE_KIND_MAPPING",X_,w),S(Ue,10,"DEFAULT_FUNCTIONS_COLUMN_NAMES",J_,w),S(Ue,10,"DEFAULT_NULL_TYPE",j_,w),S(Ue,10,"UNMERGABLE_ARGS",W_,w),S(Ue,10,"TIME_TRIE",H_,w),S(Ue,10,"FORMAT_TRIE",V_,w),S(Ue,10,"INVERSE_TIME_MAPPING",Y_,w),S(Ue,10,"INVERSE_TIME_TRIE",G_,w),S(Ue,10,"INVERSE_FORMAT_MAPPING",$_,w),S(Ue,10,"INVERSE_CREATABLE_KIND_MAPPING",B_,w),S(Ue,10,"ESCAPED_SEQUENCES",F_,w),S(Ue,10,"DATE_PART_MAPPING",v_,w),S(Ue,10,"COERCES_TO",U_,w),S(Ue,10,"EXPRESSION_METADATA",q_,w),S(Ue,10,"SUPPORTED_SETTINGS",__,w),S(Ue,10,"QUOTE_DELIMITERS",k_,w),S(Ue,10,"IDENTIFIER_DELIMITERS",D_,w),S(Ue,10,"BASE_VALID_INTERVAL_UNITS",M_,w),S(Ue,10,"VALID_INTERVAL_UNITS",w_,w),bt(Ue,w),Lt(Ue,3,w),w.DIALECT_NAME="",w.INDEX_OFFSET=0,w.WEEK_OFFSET=0,w.UNNEST_COLUMN_ONLY=!1,w.ALIAS_POST_TABLESAMPLE=!1,w.TABLESAMPLE_SIZE_IS_PERCENT=!1,w.NORMALIZATION_STRATEGY="lowercase",w.IDENTIFIERS_CAN_START_WITH_DIGIT=!1,w.DPIPE_IS_STRING_CONCAT=!0,w.STRICT_STRING_CONCAT=!1,w.SUPPORTS_USER_DEFINED_TYPES=!0,w.SUPPORTS_SEMI_ANTI_JOIN=!0,w.COPY_PARAMS_ARE_CSV=!0,w.NORMALIZE_FUNCTIONS="upper",w.PRESERVE_ORIGINAL_NAMES=!1,w.LOG_BASE_FIRST=!0,w.TYPED_DIVISION=!1,w.SAFE_DIVISION=!1,w.CONCAT_COALESCE=!1,w.HEX_LOWERCASE=!1,w.DATE_FORMAT="'%Y-%m-%d'",w.DATEINT_FORMAT="'%Y%m%d'",w.TIME_FORMAT="'%Y-%m-%d %H:%M:%S'",w.ORIGINAL_UNESCAPED_SEQUENCES={},w.PREFER_CTE_ALIAS_COLUMN=!1,w.FORCE_EARLY_ALIAS_REF_EXPANSION=!1,w.EXPAND_ONLY_GROUP_ALIAS_REF=!1,w.ANNOTATE_ALL_SCOPES=!1,w.DISABLES_ALIAS_REF_EXPANSION=!1,w.SUPPORTS_ALIAS_REFS_IN_JOIN_CONDITIONS=!1,w.SUPPORTS_ORDER_BY_ALL=!1,w.PROJECTION_ALIASES_SHADOW_SOURCE_NAMES=!1,w.TABLES_REFERENCEABLE_AS_COLUMNS=!1,w.SUPPORTS_STRUCT_STAR_EXPANSION=!1,w.EXCLUDES_PSEUDOCOLUMNS_FROM_STAR=!1,w.QUERY_RESULTS_ARE_STRUCTS=!1,w.REQUIRES_PARENTHESIZED_STRUCT_ACCESS=!1,w.SUPPORTS_NULL_TYPE=!1,w.COALESCE_COMPARISON_NON_STANDARD=!1,w.HAS_DISTINCT_ARRAY_CONSTRUCTORS=!1,w.SUPPORTS_FIXED_SIZE_ARRAYS=!1,w.STRICT_JSON_PATH_SYNTAX=!0,w.ON_CONDITION_EMPTY_BEFORE_ERROR=!0,w.ARRAY_AGG_INCLUDES_NULLS=!0,w.ARRAY_FUNCS_PROPAGATES_NULLS=!1,w.PROMOTE_TO_INFERRED_DATETIME_TYPE=!1,w.SUPPORTS_VALUES_DEFAULT=!0,w.NUMBERS_CAN_BE_UNDERSCORE_SEPARATED=!1,w.HEX_STRING_IS_INTEGER_TYPE=!1,w.REGEXP_EXTRACT_DEFAULT_GROUP=0,w.REGEXP_EXTRACT_POSITION_OVERFLOW_RETURNS_NULL=!0,w.ALTER_TABLE_SUPPORTS_CASCADE=!1,w.ALTER_TABLE_ADD_REQUIRED_FOR_EACH_COLUMN=!0,w.TRY_CAST_REQUIRES_STRING=void 0,w.SAFE_TO_ELIMINATE_DOUBLE_NEGATION=!0,w.INITCAP_DEFAULT_DELIMITER_CHARS=`
18
+ \r\f\v!"#$%&'()*+,\\-./:;<=>?@\\[\\]^_\`{|}~`,w.BYTE_STRING_IS_BYTES_TYPE=!1,w.UUID_IS_STRING_TYPE=!1,w.JSON_EXTRACT_SCALAR_SCALAR_ONLY=!1,w.LEAST_GREATEST_IGNORES_NULLS=!0,w.UNNEST_REQUIRES_CROSS_JOIN=!1,w.PRIORITIZE_NON_LITERAL_TYPES=!1,w._tokenizerClassCache=new WeakMap,w._jsonpathTokenizerClassCache=new WeakMap,w._parserClassCache=new WeakMap,w._generatorClassCache=new WeakMap,w.registry=new Map;var se=w;se.register("",se);function JI(i){return function(e){let s=e._constructor.argOrder;if(s&&0<s.length){let a=s.map(o=>e.getArgKey(o)).filter(o=>o!==void 0).reduce((o,c)=>Array.isArray(c)?o.concat(c):o.concat([c]),[]);return this.func(i,a)}let r=Object.values(e.args).filter(n=>n!==void 0);return this.func(i,r)}}function iG(i){return dT.call(this,i,"accuracy"),this.func("APPROX_COUNT_DISTINCT",[i.args.this])}function nG(i="IF",e){return function(t){return t.parent instanceof nt?`WHEN ${this.sql(t,"this")} THEN ${this.sql(t,"true")}`:this.func(i,[t.args.this,t.args.true,t.args.false||e])}}function aG(i){let e=i.args.this;if(this._constructor.JSON_TYPE_REQUIRED_FOR_EXTRACTION&&e instanceof R&&e.isString){let s=new O({this:"json"});e.replace(j(e.copy(),s))}let t=i instanceof js?"->":"->>";return this.binary(i,t)}function $U(i){return`[${this.expressions(i,{dynamic:!0,newLine:!0,skipFirst:!0,skipLast:!0})}]`}function oG(i){let e=M(i.args.expressions??[],0);return e instanceof A&&e?.find?.(z)?this.func("ARRAY",[e]):$U.call(this,i)}function cG(i){let e=new Ut({this:new Fn({this:i.args.this}),expression:new Fn({this:i.args.expression})});return this.likeSql(e)}function pG(i){let e=this.sql(i,"this");return e?`CURRENT_DATE AT TIME ZONE ${e}`:"CURRENT_DATE"}function lG(i){return i.args.recursive&&(this.unsupported("Recursive CTEs are unsupported"),i.setArgKey("recursive",!1)),this.withSql(i)}function uG(i){return this.unsupported("TABLESAMPLE unsupported"),this.sql(i.args.this)}function hG(i){return this.unsupported("PIVOT unsupported"),""}function gG(i){return this.castSql(i)}function EG(i){return this.unsupported("CommentColumnConstraint unsupported"),""}function AG(i){return this.unsupported("MAP_FROM_ENTRIES unsupported"),""}function dG(i){return`${this.propertyName(i,{stringKey:!0})}=${this.sql(i,"value")}`}function xG(i,e={}){let{funcName:t="STRPOS",supportsPosition:s=!1,supportsOccurrence:r=!1,useAnsiPosition:n=!0}=e,a=i.args.this,o=i.args.substr,c=i.args.position,l=i.args.occurrence,u=R.number(0),h=R.number(1);r&&l&&s&&!c&&(c=h);let d=c&&!s;d&&(a=new er({this:a,start:c}));let x;if(t==="POSITION"&&n)x=new je({this:t,expressions:[new it({this:o,field:a})]});else{let f=t==="LOCATE"||t==="CHARINDEX"?[o,a]:[a,o];s&&c!==void 0&&f.push(c),l&&(r?f.push(l):this.unsupported(`${t} does not support the occurrence parameter.`)),x=new je({this:t,expressions:f.filter(y=>y!==void 0)})}if(d){let f=new ke({this:new Le({this:x,expression:c}),expression:h}),y=new le({this:x.eq(u),true:u,false:f});return this.sql(y)}return this.sql(x)}function fG(i){return`${this.sql(i,"this")}.${this.sql(Z(i.args.expression?.name??""))}`}function TG(i,e={}){let{swapParams:t=!1}=e;return function(s){let r=s.args.this,n=s.args.expression,a=t?[n,r]:[r,n],o=this.func(i,a),c=!!s.args.nullPropagation,l=this.dialect._constructor.ARRAY_FUNCS_PROPAGATES_NULLS;if(c===l)return o;if(c)return this.sql(new le({this:new _e({this:r,expression:pe()}),true:pe(),false:o}));let u=r??new ue({expressions:[]});return r=new rt({expressions:[u,new ue({expressions:[]})]}),a=t?[n,r]:[r,n],this.func(i,a)}}function SG(i){function e(t,s){if(this._constructor.ARRAY_CONCAT_IS_VAR_LEN)return this.func(t,s);if(s.length===1)return this.func(t,[s[0],new ue({expressions:[]})]);let r=this.func(t,[s[s.length-2],s[s.length-1]]);for(let n=s.length-3;0<=n;n--)r=`${t}(${this.sql(s[n])}, ${r})`;return r}return function(t){let s=t.args.this,r=t.args.expressions||[],n=[...s?[s]:[],...r],a=!!t.args.nullPropagation,o=this.dialect._constructor.ARRAY_FUNCS_PROPAGATES_NULLS;if(a===o||s instanceof ue||r.length===0)return e.call(this,i,n);if(a){let u=n.map(h=>new _e({this:h.copy(),expression:pe()})).reduce((h,d)=>new ze({this:h,expression:d}));return this.sql(new le({this:u,true:pe(),false:e.call(this,i,n)}))}let c=n.map(l=>new rt({expressions:[l.copy(),new ue({expressions:[]})]}));return e.call(this,i,c)}}function mG(i,e="MAP"){let t=i.args.keys,s=i.args.values;if(!(t instanceof ue)||!(s instanceof ue))return this.unsupported("Cannot convert array columns into map."),this.func(e,[...J(t),...J(s)]);let r=[],n=t.args.expressions,a=s.args.expressions;for(let o=0;o<Math.min(n?.length||0,a?.length||0);o++)r.push(this.sql(n?.[o])),r.push(this.sql(a?.[o]));return this.func(e,r)}function OG(i){let e=i.args.this,t=i.args.expression,s=j(e,"date"),r=j(t,"date"),n=new wa({this:s,expression:r,unit:Q("month")}),a=new Vn({this:s.copy()}),o=new Vn({this:r.copy()}),c=new xp({this:s.copy()}),l=new xp({this:r.copy()}),u=new Vn({this:c}),h=new Vn({this:l}),d=new me({this:a.copy(),expression:u}),x=new me({this:o.copy(),expression:h}),f=new ce({this:d,expression:x}),y=new mt({this:new Oe({this:new ke({this:a.copy(),expression:o.copy()})}),expression:R.number("31.0")}),I=new le({this:f,true:R.number("0"),false:y});return this.sql(new Le({this:n,expression:I}))}function GU(i,e){let{dialect:t,defaultValue:s}=e;return r=>new i({this:M(r,0),format:se.get(t)?.formatTime(M(r,1)||(s===!0?se.get(t)?.TIME_FORMAT:void 0))})}function RG(i){return function(e){let t=this.formatTime(e);return t!==se.getOrRaise(i)?._constructor.TIME_FORMAT?t:void 0}}function kI(i,e,t={}){let{defaultUnit:s="DAY",supportsTimezone:r=!1}=t;return n=>{let a=3<=n.length,o=n.length===4,c=a?n[2]:M(n,0),l;if(a||s){l=a?n[0]:R.string(s);let h=l.name?.toLowerCase();if(e&&h&&e[h]&&(l=Q(e[h])),(l instanceof qe||l instanceof B||l instanceof R)&&!(l instanceof B&&l.parts.length!==1)){let d={D:"DAY",H:"HOUR",M:"MINUTE",MS:"MILLISECOND",NS:"NANOSECOND",Q:"QUARTER",S:"SECOND",US:"MICROSECOND",W:"WEEK",Y:"YEAR"};l=new qe({this:(d[l.name]||l.name).toUpperCase()})}}let u=new i({this:c,expression:M(n,1),unit:l});return r&&o&&u.setArgKey("zone",n[n.length-1]),u}}function NG(i){return e=>{if(e.length<2)throw new Error(`Expected at least 2 arguments but got ${e.length}`);let t=e[1];if(!(t instanceof Ce))throw new Error(`INTERVAL expression expected but got '${t}'`);return new i({this:e[0],expression:t.args.this,unit:yN(t)})}}function IG(i){let e=M(i,0),t=M(i,1);return t instanceof X&&t.isType("date")?new bs({unit:e,this:t}):new ro({this:t,unit:e})}function yG(i,e){return function(t){let s=this.sql(t,"this"),r=new Ce({this:t.args.expression,unit:XI(t)});return`${i}_${e}(${s}, ${this.sql(r)})`}}function CG(i={}){let{func:e="DATE_TRUNC",zone:t=!1}=i;return function(s){let r=[yN(s),s.args.this];return t&&r.push(s.args.zone),this.func(e,r)}}function PG(i){let e=i.args.zone;if(!e){let t=gs(i,{dialect:this.dialect}).type,s=$(t,O)?t:"timestamp";return this.sql(j(i.args.this||"",s))}return MI.has(e.name?.toLowerCase())?this.sql(new Wt({this:j(i.args.this||"","timestamp"),zone:e})):this.func("TIMESTAMP",[i.args.this,e])}function bG(i){let e=j(i.args.this||"","timestamptz"),t=j(new Wt({this:e,zone:i.args.zone}),"time");return this.sql(t)}function LG(i){let e=i.args.this,t=i.args.expression;if(t&&MI.has(t.name?.toLowerCase()||"")){let n=j(e,"timestamptz"),a=j(new Wt({this:n,zone:t}),"timestamp");return this.sql(a)}let s=j(e,"date"),r=j(t||"","time");return this.sql(j(new Le({this:s,expression:r}),"timestamp"))}function wG(i){return this.sql(new er({this:i.args.this,start:R.number(1),length:i.args.expression}))}function MG(i){return this.sql(new er({this:i.args.this,start:new ke({this:new nu({this:i.args.this}),expression:new Oe({this:new ke({this:i.args.expression,expression:R.number(1)})})})}))}function DG(i,e={}){let{includePrecision:t=!1}=e,s=O.build(i.args.zone?"timestamptz":"timestamp");if(i.args.this instanceof R&&t){let r=DD(i.args.this.name);0<r&&s&&(s=O.build(s.args.this,{expressions:new rr({this:R.number(r)})}))}return this.sql(j(i.args.this,s,{dialect:this.dialect}))}function kG(i){let e=i.args.this,t=e instanceof A||typeof e=="string"?e:"";return this.sql(j(t,"date"))}function _G(i,e,t={}){let{replace:s=!0}=t,r=i.args.charset;return r&&!["utf-8","utf8"].includes(r.name?.toLowerCase())&&this.unsupported(`Expected utf-8 character set, got ${r}.`),this.func(e,[i.args.this,s?i.getArgKey("replace"):void 0])}function qG(i){let e=i.args.expressions||[],t=e[0],s=e.slice(1),r=new nt({});for(let n=0;n<s.length-1;n+=2){let a=t,o=s[n],c=new ze({this:new me({this:a,expression:o}),expression:new Oe({this:new ce({this:new _e({this:a,expression:new Ze}),expression:new _e({this:o,expression:new Ze})})})});r.append("ifs",new le({this:c,true:s[n+1]}))}return s.length%2===1&&r.setArgKey("default",s[s.length-1]),this.sql(r)}function UG(i){let e=0<(i.args.expressions?.length??0)?"LEAST":"MIN";return JI(e).call(this,i)}function vG(i){let e=0<(i.args.expressions?.length??0)?"GREATEST":"MAX";return JI(e).call(this,i)}function FG(i){let e=i.args.this;return e instanceof We&&(e=e.args.expressions?.[0],this.unsupported("DISTINCT is not supported when converting COUNT_IF to SUM")),this.func("sum",e?[new le({this:e,true:R.number(1),false:R.number(0)})]:[])}function BG(i,e={}){let{defaultTrimType:t=""}=e,s=this.sql(i,"this"),r=this.sql(i,"position")||t,n=this.sql(i,"expression"),a=this.sql(i,"collation");if(!n)return this.trimSql(i);let o=r?`${r} `:"",c=n?`${n} `:"",l=o||c?"FROM ":"",u=a?` COLLATE ${a}`:"";return`TRIM(${o}${c}${l}${s}${u})`}function $G(i){return this.func("STRPTIME",[i.args.this,this.formatTime(i)])}function C_(i){return this.sql((i.args.expressions??[]).reduce((e,t)=>new Mt({this:e,expression:t})))}function GG(i){let[e,...t]=i.args.expressions??[];return this.sql(t.reduce((s,r)=>new Mt({this:s,expression:new Mt({this:e,expression:r})})))}function YG(i){let e=i.args.group;return e&&e.name===String(this.dialect._constructor.REGEXP_EXTRACT_DEFAULT_GROUP)&&(e=void 0),this.func(i._constructor.sqlName(),[i.args.this,i.args.expression,e])}function VG(i){return this.func("REGEXP_REPLACE",[i.args.this,i.args.expression,i.args.replacement])}function HG(i,e){let{dialect:t}=e,s=[];for(let r of i)if(r instanceof Re)s.push(r.alias);else{let n=r.transform(a=>a instanceof U?new U({this:a.name,quoted:!1}):a);s.push(n.sql({dialect:t,normalizeFunctions:"lower"}))}return s}function WG(i){return e=>new i({this:M(e,0),expression:M(e,1)})}function jG(i){return new ro({this:M(i,1),unit:M(i,0)})}function JG(i,e){let{dialect:t,dateTruncUnabbreviate:s=!0,defaultDateTruncUnit:r,dateTruncRequiresPart:n=!0}=e,a=M(i,0),o=M(i,1);a&&!a.type&&(a=gs(a,{dialect:t})),o&&!o.type&&(o=gs(o,{dialect:t}));let c=a?.isType(O.TEMPORAL_TYPES),l=o?.isType(O.TEXT_TYPES),u=a?.isType(O.NUMERIC_TYPES),h=o?.isType(O.NUMERIC_TYPES);if(a&&c&&(o||r)||o&&l){let d=o||R.string(r??"");return new bs({this:a,unit:d,unabbreviate:s})}return a&&u||o&&h||!n&&!o?new Lm({this:a,decimals:o}):new je({this:"TRUNC",expressions:i})}function XG(i){return this.func("MAX",[i.args.this])}function zG(i){let e=this.sql(i.left),t=this.sql(i.right);return`(${e} AND (NOT ${t})) OR ((NOT ${e}) AND {b})`}function QG(i){return i instanceof Pa||i instanceof X&&i.isType("json")}function ZG(i){return new Oe({this:new _e({this:M(i,0),expression:pe()})})}function KG(i){let e=this.sql(i,"start")||"1",t=this.sql(i,"increment")||"1";return`IDENTITY(${e}, ${t})`}function eY(i){return function(e){return this.func(i,[e.args.this,e.args.expression])}}function YU(i){if(!i.args.this)return i;let e=i.args.this.copy(),t=i.returnType;return te(t,O),t.isType("date")&&(e=j(e,"timestamp")),i.args.this?.replace(j(e,t)),i}function tY(i,e={}){let{cast:t=!1}=e;return function(s){let r=s;return t&&s instanceof cu&&(r=YU(s)),this.func(i,[XI(r),r.args.expression,r.args.this])}}function sY(i={}){let{cast:e=!0}=i;return function(t){let s=t.args.this,r=XI(t),n=t instanceof yt||t instanceof iu||t instanceof ru||t instanceof fr||t instanceof cu?"+":"-",a;if(e)if(t instanceof cu){let l=t.returnType;te(l,O),a=l}else s?.isString&&(a=t instanceof fr||t instanceof _i?"datetime":"date");s=a?j(s,a):s;let o=t.args.expression,c=o instanceof Ce?o:new Ce({this:o,unit:r});return`${this.sql(s)} ${n} ${this.sql(c)}`}}function yN(i,e={}){let{defaultValue:t="DAY"}=e,s=i.args.unit;return s instanceof R,s?s instanceof Ds||!(s instanceof qe||s instanceof R||s instanceof U||s instanceof B)?s:R.string(s.name.toUpperCase()):t?R.string(t):void 0}function XI(i,e={}){let{defaultValue:t="DAY"}=e,s=i.args.unit;if(s instanceof qe||s instanceof Ds||s instanceof B)return s;let r=s?.name.toUpperCase()||t;return r?Q(r):void 0}function P_(i,e={}){let{dialect:t=se}=e;if(i===void 0)return i;let s=i instanceof A?i.name:i,r=i instanceof A&&!(i instanceof B)&&i.parts?.length!==1?se.getOrRaise(t)._constructor.DATE_PART_MAPPING[s.toUpperCase()]:void 0;return r?i instanceof A&&i.isString?R.string(r):typeof i=="string"?R.string(i):Q(r):i instanceof A?i:R.string(i)}function rY(i){let e=new bs({this:i.args.this,unit:Q("MONTH")}),t=new yt({this:e,expression:R.number(1),unit:Q("MONTH")}),s=new ts({this:t,expression:R.number(1),unit:Q("DAY")});return this.sql(j(s,"date"))}function iY(i){let e=i.args.this?.args.alias,t=n=>n?this.dialect.normalizeIdentifier(n).name:void 0,s=i.args.this?.args.this,r=new Set([t($(s,A)?s:void 0)]);$(e,A)&&r.add(typeof e.args.this=="string"?e.args.this:t($(e.args.this,A)?e.args.this:void 0));for(let n of i.args.whens?.args.expressions||[]){if(!$(n,_r))continue;let a=n.args.then;if(a instanceof Vt)for(let o of a.findAll(me)){let c=o.args.this;c instanceof B&&r.has(t(typeof c.args.table=="string"?Z(c.args.table):c.args.table))&&c.replace(new B({this:c.args.this}))}else if(a instanceof kt){let o=a.args.this;if(o instanceof Ge)for(let c of o.args.expressions||[]){if(!(c instanceof A))continue;let l=c,u=l.getArgKey("table");(l.args.this instanceof U||l.args.this instanceof xe)&&u&&r.has(u instanceof A?t(u):u.toString())&&l.replace(new B({this:l.args.this}))}}}return this.mergeSql(i)}function nY(i,e={}){let{zeroBasedIndexing:t=!0,arrowReqJsonType:s=!1,jsonType:r}=e;return n=>{let a=[new cs({})];for(let c of n.slice(1)){if(!(c instanceof R))return i.fromArgList(n);let l=c.name;if(ED(l)&&(!s||!c.isString)){let u=parseInt(l);a.push(new Ts({this:t?u:u-1}))}else a.push(new jt({this:l}))}n.splice(2);let o={this:M(n,0),expression:new bi({expressions:a})};return i.prototype instanceof Yl||(o.onlyJsonTypes=s),r!==void 0&&(o.jsonType=r),new i(o)}}function aY(i,e={}){let{quotedIndex:t=!0,op:s}=e;return function(r){let n=r.args.expression;if(!(n instanceof bi))return JI(i).call(this,r);let a=[];for(let o of n.args.expressions??[]){let c=this.sql(o);c&&(o instanceof dt&&(t||!(o instanceof Ts))&&(n.args.escape&&(c=this.escapeStr(c)),c=`${this.dialect._constructor.QUOTE_START}${c}${this.dialect._constructor.QUOTE_END}`),a.push(c))}return s?[this.sql(r.args.this),...a].join(` ${s} `):this.func(i,[r.args.this,...a])}}function oY(i){return i.args.this instanceof Pt&&this.unsupported("Unsupported wildcard in JsonPathKey expression"),i.name}function cY(i){let e=i.args.expression,t=R.string("_u");if(e instanceof Yt&&(e.args.expressions?.length??0)===1){let n=e.args.expressions?.[0];n&&(t=n),e=e.args.this}else i instanceof kl&&(e=new st({this:t,expression:i.args.expression}));let s=new ge({expressions:[...i.args.this?[i.args.this]:[]]}),r=pt(t).from(Ye(s,void 0,{table:[t]})).where(e);return this.sql(new ue({expressions:[r]}))}function pY(i){let e=new U({this:"_u",quoted:!1}),t=new _e({this:e,expression:pe()}).not();return this.sql(new dp({this:i.args.this,expression:new Yt({this:t,expressions:[e]})}))}function lY(i){let e=new U({this:"_u",quoted:!1}),t=new st({this:e,expression:i.args.expression}),s=this.sql(new dp({this:i.args.this,expression:new Yt({this:t,expressions:[e]})}));if(i.args.nullPropagation&&!this.dialect._constructor.ARRAY_FUNCS_PROPAGATES_NULLS){let r=i.args.expression;return r instanceof R&&!(r instanceof Ze)||r instanceof ue?s:this.sql(new le({this:new _e({this:r,expression:pe()}),true:pe(),false:s}))}return s}function uY(i){return this.func("TO_NUMBER",[i.args.this,i.args.format,i.args.nlsparam])}function hY(i,e){return t=>{if(0<(t.args.expressions?.length??0)||i===void 0)return t;let s=e!==void 0?`${i}, ${e}`:`${i}`;return O.build(`DECIMAL(${s})`)??t}}function gY(i){return this.func(`SHA${i.text("length")||"256"}`,[i.args.this])}function EY(i){return this.func(`SHA${i.text("length")||"256"}`,[i.args.this])}function AY(i){let e=i,t=e.args.start,s=e.args.end,r=e.args.step,n=t instanceof X?t.args.to:s instanceof X?s.args.to:void 0;if(t!==void 0&&s!==void 0&&(Sl(n,["date","timestamp"])&&(te(n,O),t instanceof X&&n===t.to?s=j(s,n):t=j(t,n)),$(e,Fs)&&e.args.isEndExclusive)){let a=r||R.number(1),o=new ke({this:s,expression:a});s=new Oe({this:o});let c=new je({this:"SEQUENCE",expressions:[t,s,...r?[r]:[]]}),l=R.number(0),u=Kt([new me({this:a.copy(),expression:l.copy()}),Fe([new Be({this:a.copy(),expression:l.copy()}),new Me({this:t.copy(),expression:s.copy()})]),Fe([new De({this:a.copy(),expression:l.copy()}),new $e({this:t.copy(),expression:s.copy()})])]),h=new le({this:u,true:new ue({expressions:[]}),false:c});return this.sql(this.simplifyUnlessLiteral(h))}return this.func("SEQUENCE",[t,s,r])}function dY(i,e={}){let{notLike:t=!1}=e;return s=>{let r=new i({this:M(s,0),expression:M(s,1)}),n=M(s,2);return n&&(r=new ma({this:r,expression:n})),t?new be({this:r}):r}}function xY(i){return(e,{dialect:t})=>{let s={this:M(e,0),expression:M(e,1),group:M(e,2)||R.number(t._constructor.REGEXP_EXTRACT_DEFAULT_GROUP),parameters:M(e,3)};return i===Pm&&(s.nullIfPosOverflow=t._constructor.REGEXP_EXTRACT_POSITION_OVERFLOW_RETURNS_NULL),new i(s)}}function fY(i){let e=i.args.this,t=i.args.alias,s;if(e instanceof Ma&&t){te(t,ie);let[r,...n]=t.args.columns||[];te(r,U);let a=n.filter(c=>c instanceof A),o=pt([Ye(r.sub(1),r),...a]).from(new ge({expressions:[...e.args.this?[e.args.this]:[]],offset:!0,alias:new ie({this:t.args.this,columns:[...a,r]})}));s=new St({this:o.subquery()})}else e instanceof rs&&(s=new ge({expressions:[...e.args.this?[e.args.this]:[]],alias:t}));return s?this.sql(new oe({this:s,kind:"cross"})):this.lateralSql(i)}function TY(i){return this.func("TIMESTAMPDIFF",[i.unit,i.args.expression,i.args.this])}function SY(i,e={}){let{sep:t=", "}=e;return`INTERVAL '${Object.entries(i.args).map(([r,n])=>`${n instanceof sp?n.args.expression:n} ${r}`).join(t)}'`}function mY(i){return this.func(i.args.binary?"LENGTH":"CHAR_LENGTH",[i.args.this])}function OY(i,e={}){let{funcName:t="LISTAGG",sep:s=",",withinGroup:r=!0,onOverflow:n=!1}=e,a=i.args.this,o=this.sql(i.args.separator||(s?R.string(s):void 0)),c=n&&this.sql(i,"on_overflow")?` ON OVERFLOW ${this.sql(i,"on_overflow")}`:"",l;a instanceof Et&&(l=a,a=l.args.this?.pop());let u=a?.find(fe);u?.args.this&&(a=u.args.this.pop());let h=[a,o?`${o}${c}`:c||void 0].filter(Boolean).join(", "),d=new je({this:t,expressions:[h]}),x=this.sql(l);return u&&(r?d=new $t({this:d,expression:u}):x=`${this.sql(u)}${x}`),x&&d.setArgKey("expressions",[`${h}${x}`]),this.sql(d)}function RY(i,{dialect:e}){if(i.length===2){let t=i[0];if(t.type||gs(t,{dialect:e}),t.isType(O.TEMPORAL_TYPES)){let s;return typeof e=="string"?s=e:typeof e=="function"?s=e.name.toLowerCase():s=e.constructor.name.toLowerCase(),GU(Gn,{dialect:s,defaultValue:!0})(i)}}return Cm.fromArgList(i)}function NY(i){return new bm({this:M(i,0),expression:M(i,1),replacement:M(i,2)||R.string("")})}function IY(i){let e=i.args.modifiers;return!i.args.singleReplace&&(!i.args.occurrence||i.args.occurrence.isInteger&&i.args.occurrence.toValue()===0)&&(!e||e.isString)?R.string((e?.name||"")+"g"):e}function yY(i){let e=i.args.this,t=i.args.expression;if(!i.args.zeroIsMsb&&i.isType([...O.SIGNED_INTEGER_TYPES,...O.UNSIGNED_INTEGER_TYPES])){let s=new Sa({this:e,expression:t}),r=new Ta({this:s,expression:R.number(1)});return this.sql(r)}return this.func("GET_BIT",[e,t])}var iq="i",nq="k",aq="a",zI="c",Mm="t",QI="o",ZI="m",LN="v",oq="DataType.Type";function KI(i){let e=0,t=[],s=[[i,void 0,void 0,!1]];for(;0<s.length;){let[r,n,a,o]=s.pop(),c={};if(n!==void 0&&(c[iq]=n),a!==void 0&&(c[nq]=a),o&&(c[aq]=o),t.push(c),r instanceof A){if(c[zI]=r.constructor.name,r.type&&(typeof r=="string"?c[Mm]=[r]:typeof r.type=="string"?c[Mm]=[r.type]:c[Mm]=KI(r.type)),r.comments&&0<r.comments.length&&(c[QI]=r.comments),r.meta&&(c[ZI]=r.meta),r.args){let l=Object.entries(r.args).reverse();for(let[u,h]of l)if(Array.isArray(h))for(let d=h.length-1;0<=d;d--)s.push([h[d],e,u,!0]);else h!==void 0&&s.push([h,e,u,!1])}}else r&&typeof r=="object"&&"value"in r?(c[zI]=oq,c[LN]=r.value):c[LN]=r;e++}return t}function ey(i,e){let t={...ty,...e};if(!i||i.length===0)return;let[s,...r]=i,n=rq(s,t);if(!(n instanceof A))return;let a=[n];for(let o of r){let c=rq(o,t);a.push(c);let l=a[o[iq]],u=o[nq];o[aq]?l.append(u,c):l.setArgKey(u,c)}return n}function rq(i,e){let t=i[zI];if(!t)return i[LN];if(t===oq)return ut(ht,i[LN]);let s=e[t];if(!s)throw new Error(`Expression class does not exist: ${t}`);let r=new s({});return i[Mm]&&(r.type=ey(i[Mm])),i[QI]&&(r.comments=i[QI]),i[ZI]&&(r.meta=i[ZI]),r}var pq="sqlglot.meta",qI="sqlglot.anonymous",nw=["this","db","catalog"],lq=["this","table","db","catalog"],uq=["line","col","start","end"];function VU(i){if(typeof i=="boolean")return i;if(typeof i=="string"){let e=i.toLowerCase().trim();return e==="true"||e==="1"||e==="yes"}return!!i}var et=class et{constructor(e={}){this.args={};this.meta={};this.args=e;for(let[t,s]of Object.entries(e))this.setParent(t,s);Object.defineProperty(this,"meta",{value:{},writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(this,"comments",{value:void 0,writable:!0,configurable:!0,enumerable:!1})}*[Symbol.iterator](){if(this.constructor.availableArgs.has("expressions")){if(Array.isArray(this.args.expressions))for(let e of this.args.expressions)yield e;return}}text(e){let t=this.getArgKey(e);return typeof t=="string"?t:t instanceof U||t instanceof R||t instanceof qe?t.args.this?.toString()??"":t instanceof xe||t instanceof Ze?t.name:""}get isString(){return this instanceof R&&this.args.isString===!0}get isNumber(){return this instanceof R&&!this.args.isString||this instanceof It&&this.args.this.isNumber}toValue(){if(this instanceof R){let e=this.args.this;return this.isString?e:typeof e=="string"?Number(e):e}if(this instanceof It){let e=this.args.this.toValue();return typeof e=="number"?-e:e!==void 0?-Number(e):void 0}throw new Error(`${this.constructor.name} cannot be converted to a JavaScript value.`)}get isInteger(){if(!this.isNumber)return!1;if(this instanceof R){let e=String(this.args.this);return!e.includes(".")&&!e.toLowerCase().includes("e")}try{return this.args.this.isInteger}catch{return!1}}get isStar(){return this instanceof xe||this instanceof B&&this.args.this instanceof xe}get alias(){return this.args.alias instanceof ie?this.args.alias.name:this.text("alias")}get aliasColumnNames(){let e=this.args.alias;if(!(e instanceof ie))return[];let t=e.args.columns;return Array.isArray(t)?t.map(s=>s instanceof et?s.name:""):[]}get name(){return this.text("this")}get aliasOrName(){return this.alias||this.name}get sqlKey(){return this.sql()}get outputName(){return""}get type(){return this instanceof X?this._type||this.args.to:this._type}set type(e){e!==void 0&&!(e instanceof O)&&(e=O.build(e)),this._type=e}isType(e,t){return this._type?this._type.isType(J(e)):!1}get isLeaf(){return!Object.values(this.args).some(e=>(e instanceof et||Array.isArray(e))&&e)}copy(){let e=new this.constructor,t=[[this,e]];for(;0<t.length;){let[s,r]=t.pop();s.comments&&(r.comments=[...s.comments]),s._type&&(r._type=s._type.copy()),s.meta&&(r.meta={...s.meta}),s._hash&&(r._hash=s._hash);for(let[n,a]of Object.entries(s.args))if(a instanceof et){let o=new a.constructor;t.push([a,o]),r.setArgKey(n,o)}else if(Array.isArray(a)){r.args[n]=[];for(let o of a)if(o instanceof et){let c=new o.constructor;t.push([o,c]),r.append(n,c)}else r.append(n,o)}else r.args[n]=a}return e}addComments(e,t={}){let{prepend:s=!1}=t;if(this.comments||(this.comments=[]),e){for(let r of e){let[n,...a]=r.split(pq);if(0<a.length)for(let o of a.join("").split(",")){let[c,...l]=o.split("="),u=0<l.length?l[0].trim():void 0,h=hD(c.trim());u===void 0?this.meta[h]=!0:/^(true|false|1|0)$/i.test(u)?this.meta[h]=VU(u):this.meta[h]=u}s||this.comments.push(r)}s&&(this.comments=[...e,...this.comments])}}popComments(){let e=this.comments||[];return this.comments=void 0,e}append(e,t){let s=this.args;Array.isArray(s[e])||(s[e]=[]),this.setParent(e,t);let r=s[e];t instanceof et&&(t.index=r.length),r.push(t)}setArgKey(e,t,s,r){let n=r?.overwrite??!0,a=this;for(;a&&a._hash!==void 0;)a._hash=void 0,a=a.parent;let o=this.args;if(s!==void 0){let c=o[e]||[];if(c[s]===void 0)return;if(t===void 0){c.splice(s,1);for(let l=s;l<c.length;l++){let u=c[l];u instanceof et&&u.index!==void 0&&(u.index=u.index-1)}return}Array.isArray(t)?(c.splice(s,1),c.splice(s,0,...t)):n?c[s]=t:c.splice(s,0,t),t=c}else if(t===void 0){delete o[e];return}o[e]=t,this.setParent(e,t,s)}getArgKey(e){if(e!==void 0)return this.args[e]??void 0}setParent(e,t,s){t instanceof et?(t.parent=this,t.argKey=e,t.index=s):Array.isArray(t)&&t.forEach((r,n)=>{r instanceof et&&(r.parent=this,r.argKey=e,r.index=n)})}get depth(){let e=0,t=this.parent;for(;t;)e++,t=t.parent;return e}*iterExpressions(e){let t=e?.reverse??!1,s=t?Object.values(this.args).reverse():Object.values(this.args);for(let r of s)if(r instanceof et)yield r;else if(Array.isArray(r)){let n=t?[...r].reverse():r;for(let a of n)a instanceof et&&(yield a)}}find(e,t){for(let s of this.findAll(e,t))return s}*findAll(e,t){let s=Array.from(J(e)),r=t?.bfs??!0;for(let n of this.walk({bfs:r}))s.some(a=>n instanceof a)&&(yield n)}findAncestor(...e){let t=this.parent;for(;t;){if(e.some(s=>t instanceof s))return t;t=t.parent}}get parentSelect(){return this.findAncestor(ee)}get sameParent(){return this.parent?.constructor===this.constructor}sameParentAs(e){return this.parent===e.parent}root(){let e=this;for(;e.parent;)e=e.parent;return e}*walk(e){let t=e?.bfs??!0,s=e?.prune;t?yield*this.bfs({prune:s}):yield*this.dfs({prune:s})}*dfs(e){let t=e?.prune,s=[this];for(;0<s.length;){let r=s.pop();if(yield r,!t?.(r))for(let n of r.iterExpressions({reverse:!0}))s.push(n)}}*bfs(e){let t=e?.prune,s=[this];for(;0<s.length;){let r=s.shift();if(yield r,!t?.(r))for(let n of r.iterExpressions())s.push(n)}}unnest(){let e=this;for(;e instanceof Oe;){let t=e.args.this;if(t instanceof et)e=t;else break}return e}unalias(){if(this instanceof Re){let e=this.args.this;if(e instanceof et)return e}return this}unnestOperands(){return Array.from(this.iterExpressions()).map(e=>e.unnest())}*flatten(e){let t=e?.unnest??!0;for(let s of this.dfs({prune:r=>r.parent!==void 0&&r.constructor!==this.constructor}))s.constructor!==this.constructor&&(t&&!(s instanceof Te)?yield s.unnest():yield s)}sql(e={}){let{dialect:t,...s}=e;return se.getOrRaise(t).generate(this,s)}transform(e,t={}){let{copy:s=!0,...r}=t,n,a,o=s?this.copy():this;for(let c of o.dfs({prune:l=>l!==a})){let l=c.parent,u=c.argKey,h=c.index;a=e(c,{...r,copy:s}),n?l&&u&&a!==c&&l.setArgKey(u,a,h):n=a}if(!n)throw new Error("Transform failed: no root node");if(!(n instanceof et))throw new Error("Expected final root to be an Expression");return n}replace(e){let t=this.parent;if(!t||t===e)return e;let s=this.argKey;if(!s)return e;let r=t.getArgKey(s);return Array.isArray(e)&&r instanceof et?r.parent?.replace(e):t.setArgKey(s,e,this.index),e!==this&&(this.parent=void 0,this.argKey=void 0,this.index=void 0),e}pop(){return this.replace(void 0),this}assertIs(e){if(!(this instanceof e))throw new Error(`${this.constructor.name} is not ${e.name}.`);return this}errorMessages(e){let t=[],s=this._constructor;for(let r of s.requiredArgs){let n=this.getArgKey(r);(n===void 0||Array.isArray(n)&&n.length===0)&&t.push(`Required keyword: '${r}' missing for ${this.constructor.name}`)}if(e&&this instanceof g){let r=s.availableArgs.size,n=s.isVarLenArgs||!1;r<e.length&&!n&&t.push(`The number of provided arguments (${e.length}) is greater than the maximum number of supported arguments (${r})`)}return t}dump(){return KI(this)}static load(e){return ey(e)}and(e,t={}){let{copy:s=!0,wrap:r=!0,...n}=t,a=Array.from(J(e));return Fe([this,...a],{...n,copy:s,wrap:r})}or(e,t={}){let{copy:s=!0,wrap:r=!0,...n}=t,a=Array.from(J(e));return Kt([this,...a],{...n,copy:s,wrap:r})}not(e={}){let{copy:t=!0,...s}=e;return xr(this,{...s,copy:t})}updatePositions(e,t){if(!e)this.meta.line=t?.line,this.meta.col=t?.col,this.meta.start=t?.start,this.meta.end=t?.end;else if(e instanceof et)for(let s of uq)this.meta[s]=e.meta[s];else this.meta.line=e.line,this.meta.col=e.col,this.meta.start=e.start,this.meta.end=e.end;return this}as(e,t={}){let{copy:s=!0,...r}=t,n=e instanceof et?e.name:e.toString();return Ye(this,n,{...r,copy:s})}binop(e,t,s){let r=s?.reverse??!1,n=this.copy(),a=Ot(t,{copy:!0});if(!(n instanceof e)&&!(t instanceof e)){let o=Yn(n,q),c=Yn(a,q);o&&(n=o),c&&(a=c)}return r?new e({this:a,expression:n}):new e({this:n,expression:a})}resetHash(){this._hash=void 0}computeHash(){return this.hash()}hash(){if(this._hash!==void 0)return this._hash;let e=[],t=[this];for(;0<t.length;){let s=t.shift();e.push(s);for(let r of s.iterExpressions())r._hash===void 0&&t.push(r)}for(let s=e.length-1;0<=s;s--){let r=e[s],n=this.hashString(r._constructor.key);if(r instanceof R||r instanceof U){let a=Object.entries(r.args).sort();for(let[o,c]of a)c&&(n=this.hashString(n+o+c.toString()))}else{let a=Object.entries(r.args);for(let[o,c]of a)if(Array.isArray(c))for(let l of c)if(l!==void 0&&l!==!1){let u=typeof l=="string"?l.toLowerCase():l;n=this.hashString(n+o+u)}else n=this.hashString(n+o);else if(c!==void 0&&c!==!1){let l=typeof c=="string"?c.toLowerCase():c;n=this.hashString(n+o+l)}}r._hash=n}return this._hash||""}equals(e){return this===e?!0:!(e instanceof et)||this.constructor!==e.constructor?!1:this.hash()===e.hash()}hashString(e){return e.split("").reduce((t,s)=>(t=(t<<5)-t+s.charCodeAt(0),t&t),0).toString()}toString(){return this.sql()}in(e,t,s={}){let{copy:r=!0,unnest:n,...a}=s,o=t?H(t):void 0;return!(o instanceof Te)&&o instanceof z&&(o=o.subquery(void 0,{copy:!1})),new it({this:Ve(this,r),expressions:e?.map(c=>Ot(c,{copy:r})),query:o,unnest:n?new ge({expressions:Array.from(J(n)).map(c=>H(c,{...a,copy:r}))}):void 0})}between(e,t,s={}){let{copy:r=!0,symmetric:n}=s,a=new ss({this:Ve(this,r),low:Ot(e,{copy:r}),high:Ot(t,{copy:r})});return n!==void 0&&a.setArgKey("symmetric",n),a}is(e){return this.binop(_e,e)}like(e){return this.binop(Ut,e)}ilike(e){return this.binop(Us,e)}eq(e){return this.binop(me,e)}neq(e){return this.binop(st,e)}rlike(e){return this.binop(op,e)}div(e,t){let s=this.binop(mt,e);return s.setArgKey("typed",t?.typed??!1),s.setArgKey("safe",t?.safe??!1),s}asc(e={}){let{nullsFirst:t=!0}=e;return new Ht({this:this.copy(),nullsFirst:t?Ot(t):void 0})}desc(e={}){let{nullsFirst:t=!1}=e;return new Ht({this:this.copy(),desc:Ot(!0),nullsFirst:t?Ot(t):void 0})}lt(e){return this.binop(De,e)}lte(e){return this.binop($e,e)}gt(e){return this.binop(Be,e)}gte(e){return this.binop(Me,e)}add(e){return this.binop(Le,e)}radd(e){return this.binop(Le,e,{reverse:!0})}sub(e){return this.binop(ke,e)}rsub(e){return this.binop(ke,e,{reverse:!0})}mul(e){return this.binop(Ns,e)}rmul(e){return this.binop(Ns,e,{reverse:!0})}truediv(e){return this.binop(mt,e)}rtruediv(e){return this.binop(mt,e,{reverse:!0})}floorDiv(e){return this.binop(ha,e)}rfloorDiv(e){return this.binop(ha,e,{reverse:!0})}mod(e){return this.binop(Bi,e)}rmod(e){return this.binop(Bi,e,{reverse:!0})}pow(e){return this.binop(au,e)}rpow(e){return this.binop(au,e,{reverse:!0})}neg(){return new It({this:Yn(this.copy(),q)})}invert(){return xr(this.copy())}getItem(...e){return new Dt({this:this.copy(),expressions:(Array.isArray(e)?e:[e]).map(t=>Ot(t,{copy:!0}))})}get _constructor(){return this.constructor}};et.key="expression",et.requiredArgs=new Set(["this"]),et.availableArgs=new Set(["this"]);var A=et,ye=class extends A{constructor(e={}){super(e)}};ye.key="condition";var Ne=class extends ye{constructor(e={}){super(e)}};Ne.key="predicate",Ne.requiredArgs=new Set(["this"]),Ne.availableArgs=new Set(["this"]);var hr=class extends A{constructor(e={}){super(e)}get selects(){return this.args.this instanceof z?this.args.this.selects:[]}get namedSelects(){return this.selects.map(e=>e.outputName)}};hr.key="derivedTable",hr.requiredArgs=new Set(["this"]),hr.availableArgs=new Set(["this"]);var z=class extends A{constructor(e={}){super(e)}subquery(e,t={}){let{copy:s=!0}=t,r=Ve(this,s),n;return e instanceof ie?n=e:e&&(n=new ie({this:Z(e)})),new Te({this:r,alias:n})}limit(e,t={}){let{copy:s=!0,...r}=t;return sA(e,{instance:this,arg:"limit",into:Et,prefix:"LIMIT",intoArg:"expression",...r,copy:s})}offset(e,t={}){let{copy:s=!0,...r}=t;return sA(e,{instance:this,arg:"offset",into:Rr,prefix:"OFFSET",intoArg:"expression",...r,copy:s})}orderBy(e,t={}){let{append:s=!0,copy:r=!0,...n}=t,a=Array.from(J(e));return Ld(a,{instance:this,arg:"order",prefix:"ORDER BY",into:fe,...n,append:s,copy:r})}get ctes(){let e=this.args.with;return Rt(e?.args.expressions??[],A)}get selects(){throw new Error("Query objects must implement `selects`")}get namedSelects(){throw new Error("Query objects must implement `namedSelects`")}select(e,t={}){throw new Error("Query objects must implement `select`")}where(e,t={}){let{append:s=!0,copy:r=!0,dialect:n,...a}=t;return If(J(e).map(o=>o instanceof at?o.args.this:o),{instance:this,arg:"where",into:at,append:s,copy:r,dialect:n,...a})}with(e,t,s={}){let{recursive:r=!1,append:n=!0,copy:a=!0,...o}=s;return ow({instance:this,alias:e,as:t,...o,recursive:r,append:n,copy:a})}union(e,t={}){return UA([this,...e!==void 0?J(e):[]],{...t,distinct:t.distinct??!0})}intersect(e,t={}){return gq([this,...J(e)],{...t,distinct:t.distinct??!0})}except(e,t={}){return Eq([this,...e!==void 0?Array.from(J(e)):[]],{...t,distinct:t.distinct??!0})}};z.key="query",z.requiredArgs=new Set(["this"]),z.availableArgs=new Set(["this"]);var Nt=class extends hr{constructor(e={}){super(e)}get selects(){let e=this.args.alias;return $(e,ie)?e.columns:[]}};Nt.key="udtf";var go=class extends A{constructor(e={}){super(e)}};go.key="cache",go.requiredArgs=new Set(["this"]),go.availableArgs=new Set(["this","lazy","options","expression"]);var Eo=class extends A{constructor(e={}){super(e)}};Eo.key="uncache",Eo.requiredArgs=new Set(["this"]),Eo.availableArgs=new Set(["this","exists"]);var Ao=class extends A{constructor(e={}){super(e)}};Ao.key="refresh",Ao.requiredArgs=new Set(["this","kind"]),Ao.availableArgs=new Set(["this","kind"]);var gr=class extends A{constructor(e={}){super(e)}get ctes(){let e=this.args.with;return Rt(e?.args.expressions??[],A)}get selects(){let e=this.args.expression;return e instanceof z?e.selects:[]}get namedSelects(){let e=this.args.expression;return e instanceof z?e.namedSelects:[]}};gr.key="ddl",gr.requiredArgs=new Set(["this"]),gr.availableArgs=new Set(["this"]);var GA=class extends A{constructor(e={}){super(e)}};GA.key="lockingStatement",GA.requiredArgs=new Set(["this","expression"]),GA.availableArgs=new Set(["this","expression"]);var ls=class extends A{constructor(e={}){super(e)}returning(e,t={}){let{copy:s=!0,...r}=t;return sA(e,{instance:this,arg:"returning",prefix:"RETURNING",into:Ea,...r,copy:s})}};ls.key="dml",ls.requiredArgs=new Set(["this"]),ls.availableArgs=new Set(["this"]);var qt=class extends gr{constructor(e={}){super(e)}get kind(){return this.args.kind}};qt.key="create",qt.requiredArgs=new Set(["this","kind"]),qt.availableArgs=new Set(["with","this","kind","expression","exists","properties","replace","refresh","unique","indexes","noSchemaBinding","begin","clone","concurrently","clustered"]);var Hs=class extends A{constructor(e={}){super(e)}};Hs.key="sequenceProperties",Hs.requiredArgs=new Set,Hs.availableArgs=new Set(["increment","minvalue","maxvalue","cache","start","owned","options"]);var xo=class extends A{constructor(e={}){super(e)}};xo.key="truncateTable",xo.requiredArgs=new Set(["expressions"]),xo.availableArgs=new Set(["expressions","isDatabase","exists","only","cluster","identity","option","partition"]);var fo=class extends A{constructor(e={}){super(e)}};fo.key="clone",fo.requiredArgs=new Set(["this"]),fo.availableArgs=new Set(["this","shallow","copy"]);var Vi=class extends A{constructor(e={}){super(e)}};Vi.key="describe",Vi.requiredArgs=new Set(["this"]),Vi.availableArgs=new Set(["this","style","kind","expressions","partition","format","asJson"]);var YA=class extends A{constructor(e={}){super(e)}};YA.key="attach",YA.requiredArgs=new Set(["this"]),YA.availableArgs=new Set(["this","exists","expressions"]);var VA=class extends A{constructor(e={}){super(e)}};VA.key="detach",VA.requiredArgs=new Set(["this"]),VA.availableArgs=new Set(["this","exists"]);var HA=class extends A{constructor(e={}){super(e)}};HA.key="install",HA.requiredArgs=new Set(["this"]),HA.availableArgs=new Set(["this","from","force"]);var To=class extends A{constructor(e={}){super(e)}};To.key="summarize",To.requiredArgs=new Set(["this"]),To.availableArgs=new Set(["this","table"]);var So=class extends A{constructor(e={}){super(e)}};So.key="kill",So.requiredArgs=new Set(["this"]),So.availableArgs=new Set(["this","kind"]);var mo=class extends A{constructor(e={}){super(e)}};mo.key="pragma",mo.requiredArgs=new Set(["this"]),mo.availableArgs=new Set(["this"]);var Oo=class extends A{constructor(e={}){super(e)}};Oo.key="declare",Oo.requiredArgs=new Set(["expressions"]),Oo.availableArgs=new Set(["expressions"]);var Ro=class extends A{constructor(e={}){super(e)}};Ro.key="declareItem",Ro.requiredArgs=new Set(["this"]),Ro.availableArgs=new Set(["this","kind","default"]);var Hi=class extends A{constructor(e={}){super(e)}};Hi.key="set",Hi.requiredArgs=new Set,Hi.availableArgs=new Set(["expressions","unset","tag"]);var Kn=class extends A{constructor(e={}){super(e)}};Kn.key="heredoc",Kn.requiredArgs=new Set(["this"]),Kn.availableArgs=new Set(["this","tag"]);var vi=class extends A{constructor(e={}){super(e)}};vi.key="setItem",vi.requiredArgs=new Set,vi.availableArgs=new Set(["this","expressions","kind","collate","global"]);var WA=class extends A{constructor(e={}){super(e)}};WA.key="queryBand",WA.requiredArgs=new Set(["this"]),WA.availableArgs=new Set(["this","scope","update"]);var jA=class extends A{constructor(e={}){super(e)}};jA.key="show",jA.requiredArgs=new Set(["this"]),jA.availableArgs=new Set(["this","history","terse","target","offset","startsWith","limit","from","like","where","db","scope","scopeKind","full","mutex","query","channel","global","log","position","types","privileges","forTable","forGroup","forUser","forRole","intoOutfile","json"]);var No=class extends A{constructor(e={}){super(e)}};No.key="userDefinedFunction",No.requiredArgs=new Set(["this"]),No.availableArgs=new Set(["this","expressions","wrapped"]);var ea=class extends A{constructor(e={}){super(e)}};ea.key="characterSet",ea.requiredArgs=new Set(["this"]),ea.availableArgs=new Set(["this","default"]);var Io=class extends A{constructor(e={}){super(e)}};Io.key="recursiveWithSearch",Io.requiredArgs=new Set(["kind","this","expression"]),Io.availableArgs=new Set(["kind","this","expression","using"]);var tt=class extends A{constructor(e={}){super(e)}get recursive(){return this.args.recursive}};tt.key="with",tt.requiredArgs=new Set(["expressions"]),tt.availableArgs=new Set(["expressions","recursive","search"]);var $t=class extends A{constructor(e={}){super(e)}};$t.key="withinGroup",$t.requiredArgs=new Set(["this"]),$t.availableArgs=new Set(["this","expression"]);var JA=class extends A{constructor(e={}){super(e)}};JA.key="projectionDef",JA.requiredArgs=new Set(["this","expression"]),JA.availableArgs=new Set(["this","expression"]);var ie=class extends A{constructor(e={}){super(e)}get columns(){return this.args.columns||[]}};ie.key="tableAlias",ie.requiredArgs=new Set,ie.availableArgs=new Set(["this","columns"]);var yo=class extends A{constructor(e={}){super(e)}};yo.key="columnPosition",yo.requiredArgs=new Set(["position"]),yo.availableArgs=new Set(["this","position"]);var Ie=class extends A{constructor(e={}){super(e)}get kind(){return this.args.kind}get constraints(){return this.args.constraints||[]}};Ie.key="columnDef",Ie.requiredArgs=new Set(["this"]),Ie.availableArgs=new Set(["this","kind","constraints","exists","position","default","output"]);var as=class extends A{constructor(e={}){super(e)}};as.key="alterColumn",as.requiredArgs=new Set(["this"]),as.availableArgs=new Set(["this","dtype","collate","using","default","drop","comment","allowNull","visible","renameTo"]);var XA=class extends A{constructor(e={}){super(e)}};XA.key="alterIndex",XA.requiredArgs=new Set(["this","visible"]),XA.availableArgs=new Set(["this","visible"]);var ta=class extends A{constructor(e={}){super(e)}};ta.key="alterDistStyle",ta.requiredArgs=new Set(["this"]),ta.availableArgs=new Set(["this"]);var sa=class extends A{constructor(e={}){super(e)}};sa.key="alterSortKey",sa.requiredArgs=new Set,sa.availableArgs=new Set(["this","expressions","compound"]);var Co=class extends A{constructor(e={}){super(e)}};Co.key="alterSet",Co.requiredArgs=new Set,Co.availableArgs=new Set(["expressions","option","tablespace","accessMethod","fileFormat","copyOptions","tag","location","serde"]);var ga=class extends A{constructor(e={}){super(e)}};ga.key="renameColumn",ga.requiredArgs=new Set(["this","to"]),ga.availableArgs=new Set(["this","to","exists"]);var Mr=class extends A{constructor(e={}){super(e)}};Mr.key="alterRename",Mr.requiredArgs=new Set(["this"]),Mr.availableArgs=new Set(["this"]);var Wi=class extends A{constructor(e={}){super(e)}};Wi.key="swapTable",Wi.requiredArgs=new Set(["this"]),Wi.availableArgs=new Set(["this"]);var Po=class extends A{constructor(e={}){super(e)}};Po.key="comment",Po.requiredArgs=new Set(["this","kind","expression"]),Po.availableArgs=new Set(["this","kind","expression","exists","materialized"]);var bo=class extends A{constructor(e={}){super(e)}};bo.key="comprehension",bo.requiredArgs=new Set(["this","expression","iterator"]),bo.availableArgs=new Set(["this","expression","position","iterator","condition"]);var Sr=class extends A{constructor(e={}){super(e)}};Sr.key="mergeTreeTtlAction",Sr.requiredArgs=new Set(["this"]),Sr.availableArgs=new Set(["this","delete","recompress","toDisk","toVolume"]);var Ir=class extends A{constructor(e={}){super(e)}};Ir.key="mergeTreeTtl",Ir.requiredArgs=new Set(["expressions"]),Ir.availableArgs=new Set(["expressions","where","group","aggregates"]);var zA=class extends A{constructor(e={}){super(e)}};zA.key="indexConstraintOption",zA.requiredArgs=new Set,zA.availableArgs=new Set(["keyBlockSize","using","parser","comment","visible","engineAttr","secondaryEngineAttr"]);var Or=class extends A{constructor(e={}){super(e)}get kind(){return this.args.kind}};Or.key="columnConstraint",Or.requiredArgs=new Set(["kind"]),Or.availableArgs=new Set(["this","kind"]);var ae=class extends A{constructor(e={}){super(e)}};ae.key="columnConstraintKind",ae.requiredArgs=new Set(["this"]),ae.availableArgs=new Set(["this"]);var ji=class extends A{constructor(e={}){super(e)}};ji.key="withOperator",ji.requiredArgs=new Set(["this","op"]),ji.availableArgs=new Set(["this","op"]);var QA=class extends A{constructor(e={}){super(e)}};QA.key="watermarkColumnConstraint",QA.requiredArgs=new Set(["this","expression"]),QA.availableArgs=new Set(["this","expression"]);var Lo=class extends A{constructor(e={}){super(e)}};Lo.key="constraint",Lo.requiredArgs=new Set(["this","expressions"]),Lo.availableArgs=new Set(["this","expressions"]);var Js=class extends ls{constructor(e={}){super(e)}delete(e,t={}){let{copy:s=!0,...r}=t;return sA(e,{instance:this,arg:"this",into:V,...r,copy:s})}where(e,t={}){let{append:s=!0,copy:r=!0,...n}=t;return If(Array.from(J(e)),{instance:this,arg:"where",into:at,...n,append:s,copy:r})}};Js.key="delete",Js.requiredArgs=new Set,Js.availableArgs=new Set(["with","this","using","where","returning","order","limit","tables","cluster"]);var Ji=class extends A{constructor(e={}){super(e)}get kind(){return this.args.kind}};Ji.key="drop",Ji.requiredArgs=new Set,Ji.availableArgs=new Set(["this","kind","expressions","exists","temporary","materialized","cascade","constraints","purge","cluster","concurrently"]);var ZA=class extends A{constructor(e={}){super(e)}};ZA.key="export",ZA.requiredArgs=new Set(["this","options"]),ZA.availableArgs=new Set(["this","connection","options"]);var sr=class extends A{constructor(e={}){super(e)}};sr.key="filter",sr.requiredArgs=new Set(["this","expression"]),sr.availableArgs=new Set(["this","expression"]);var KA=class extends A{constructor(e={}){super(e)}};KA.key="check",KA.requiredArgs=new Set(["this"]),KA.availableArgs=new Set(["this"]);var wo=class extends A{constructor(e={}){super(e)}};wo.key="changes",wo.requiredArgs=new Set(["information"]),wo.availableArgs=new Set(["information","atBefore","end"]);var Mo=class extends A{constructor(e={}){super(e)}};Mo.key="connect",Mo.requiredArgs=new Set(["connect"]),Mo.availableArgs=new Set(["start","connect","nocycle"]);var Do=class extends A{constructor(e={}){super(e)}};Do.key="copyParameter",Do.requiredArgs=new Set(["this"]),Do.availableArgs=new Set(["this","expression","expressions"]);var ko=class extends A{constructor(e={}){super(e)}};ko.key="credentials",ko.requiredArgs=new Set,ko.availableArgs=new Set(["credentials","encryption","storage","iamRole","region"]);var _o=class extends A{constructor(e={}){super(e)}};_o.key="prior",_o.requiredArgs=new Set(["this"]),_o.availableArgs=new Set(["this"]);var Xi=class extends A{constructor(e={}){super(e)}};Xi.key="directory",Xi.requiredArgs=new Set(["this"]),Xi.availableArgs=new Set(["this","local","rowFormat"]);var ed=class extends A{constructor(e={}){super(e)}};ed.key="directoryStage",ed.requiredArgs=new Set(["this"]),ed.availableArgs=new Set(["this"]);var qo=class extends A{constructor(e={}){super(e)}};qo.key="foreignKey",qo.requiredArgs=new Set,qo.availableArgs=new Set(["expressions","reference","delete","update","options"]);var td=class extends A{constructor(e={}){super(e)}};td.key="columnPrefix",td.requiredArgs=new Set(["this","expression"]),td.availableArgs=new Set(["this","expression"]);var zi=class extends A{constructor(e={}){super(e)}};zi.key="primaryKey",zi.requiredArgs=new Set(["expressions"]),zi.availableArgs=new Set(["this","expressions","options","include"]);var Qi=class extends A{constructor(e={}){super(e)}};Qi.key="into",Qi.requiredArgs=new Set,Qi.availableArgs=new Set(["this","temporary","unlogged","bulkCollect","expressions"]);var Je=class extends A{constructor(e={}){super(e)}get name(){return this.args.this?.name||""}get aliasOrName(){return this.args.this?.aliasOrName??""}};Je.key="from",Je.requiredArgs=new Set(["this"]),Je.availableArgs=new Set(["this"]);var Zt=class extends A{constructor(e={}){super(e)}};Zt.key="having",Zt.requiredArgs=new Set(["this"]),Zt.availableArgs=new Set(["this"]);var us=class extends A{constructor(e={}){super(e)}};us.key="hint",us.requiredArgs=new Set(["expressions"]),us.availableArgs=new Set(["expressions"]);var ur=class extends A{constructor(e={}){super(e)}};ur.key="joinHint",ur.requiredArgs=new Set(["this","expressions"]),ur.availableArgs=new Set(["this","expressions"]);var U=class extends A{constructor(e={}){super(e)}get outputName(){return this.name}get quoted(){return!!this.args.quoted}};U.key="identifier",U.requiredArgs=new Set(["this"]),U.availableArgs=new Set(["this","quoted","global","temporary"]);var Uo=class extends A{constructor(e={}){super(e)}};Uo.key="opclass",Uo.requiredArgs=new Set(["this","expression"]),Uo.availableArgs=new Set(["this","expression"]);var vo=class extends A{constructor(e={}){super(e)}};vo.key="index",vo.requiredArgs=new Set,vo.availableArgs=new Set(["this","table","unique","primary","amp","params"]);var Fo=class extends A{constructor(e={}){super(e)}};Fo.key="indexParameters",Fo.requiredArgs=new Set,Fo.availableArgs=new Set(["using","include","columns","withStorage","partitionBy","tablespace","where","on"]);var Bo=class extends A{constructor(e={}){super(e)}};Bo.key="conditionalInsert",Bo.requiredArgs=new Set(["this"]),Bo.availableArgs=new Set(["this","expression","else"]);var Zi=class extends A{constructor(e={}){super(e)}};Zi.key="multitableInserts",Zi.requiredArgs=new Set(["expressions","kind","source"]),Zi.availableArgs=new Set(["expressions","kind","source"]);var $o=class extends A{constructor(e={}){super(e)}};$o.key="onConflict",$o.requiredArgs=new Set,$o.availableArgs=new Set(["duplicate","expressions","action","conflictKeys","indexPredicate","constraint","where"]);var Go=class extends A{constructor(e={}){super(e)}};Go.key="onCondition",Go.requiredArgs=new Set,Go.availableArgs=new Set(["error","empty","null"]);var Ea=class extends A{constructor(e={}){super(e)}};Ea.key="returning",Ea.requiredArgs=new Set(["expressions"]),Ea.availableArgs=new Set(["expressions","into"]);var Yo=class extends A{constructor(e={}){super(e)}};Yo.key="introducer",Yo.requiredArgs=new Set(["this","expression"]),Yo.availableArgs=new Set(["this","expression"]);var Vo=class extends A{constructor(e={}){super(e)}};Vo.key="national",Vo.requiredArgs=new Set(["this"]),Vo.availableArgs=new Set(["this"]);var Ho=class extends A{constructor(e={}){super(e)}};Ho.key="loadData",Ho.requiredArgs=new Set(["this","inpath"]),Ho.availableArgs=new Set(["this","local","overwrite","inpath","partition","inputFormat","serde"]);var Wo=class extends A{constructor(e={}){super(e)}};Wo.key="partition",Wo.requiredArgs=new Set(["expressions"]),Wo.availableArgs=new Set(["expressions","subpartition"]);var sd=class extends A{constructor(e={}){super(e)}};sd.key="partitionRange",sd.requiredArgs=new Set(["this"]),sd.availableArgs=new Set(["this","expression","expressions"]);var rd=class extends A{constructor(e={}){super(e)}};rd.key="partitionId",rd.requiredArgs=new Set(["this"]),rd.availableArgs=new Set(["this"]);var _s=class extends A{constructor(e={}){super(e)}};_s.key="fetch",_s.requiredArgs=new Set,_s.availableArgs=new Set(["direction","count","limitOptions"]);var jo=class extends A{constructor(e={}){super(e)}};jo.key="grant",jo.requiredArgs=new Set(["privileges","securable","principals"]),jo.availableArgs=new Set(["privileges","kind","securable","principals","grantOption"]);var Jo=class extends A{constructor(e={}){super(e)}};Jo.key="revoke",Jo.requiredArgs=new Set(["privileges","securable","principals"]),Jo.availableArgs=new Set(["privileges","kind","securable","principals","grantOption","cascade"]);var Xs=class extends A{constructor(e={}){super(e)}};Xs.key="group",Xs.requiredArgs=new Set,Xs.availableArgs=new Set(["expressions","groupingSets","cube","rollup","totals","all"]);var Xo=class extends A{constructor(e={}){super(e)}};Xo.key="cube",Xo.requiredArgs=new Set,Xo.availableArgs=new Set(["expressions"]);var ra=class extends A{constructor(e={}){super(e)}};ra.key="rollup",ra.requiredArgs=new Set,ra.availableArgs=new Set(["expressions"]);var zo=class extends A{constructor(e={}){super(e)}};zo.key="groupingSets",zo.requiredArgs=new Set(["expressions"]),zo.availableArgs=new Set(["expressions"]);var Yt=class extends A{constructor(e={}){super(e)}};Yt.key="lambda",Yt.requiredArgs=new Set(["this","expressions"]),Yt.availableArgs=new Set(["this","expressions","colon"]);var Et=class extends A{constructor(e={}){super(e)}};Et.key="limit",Et.requiredArgs=new Set(["expression"]),Et.availableArgs=new Set(["this","expression","offset","limitOptions","expressions"]);var Qo=class extends A{constructor(e={}){super(e)}};Qo.key="limitOptions",Qo.requiredArgs=new Set,Qo.availableArgs=new Set(["percent","rows","withTies"]);var oe=class extends A{constructor(e={}){super(e)}on(e,t={}){let{append:s,dialect:r,copy:n,...a}=t,o=Array.from(J(e)),c=If(o,{instance:this,arg:"on",append:s,dialect:r,copy:n,...a});return c.args.kind==="cross"&&c.setArgKey("kind",void 0),c}using(e,t={}){let{append:s,dialect:r,copy:n,...a}=t,o=Array.from(J(e)),c=lu(o,{instance:this,arg:"using",append:s,dialect:r,copy:n,...a});return c.args.kind==="cross"&&c.setArgKey("kind",void 0),c}get method(){return this.text("method").toUpperCase()}get kind(){return this.text("kind").toUpperCase()}get side(){return this.text("side").toUpperCase()}get hint(){return this.text("hint").toUpperCase()}get aliasOrName(){return this.args.this?.aliasOrName??""}get isSemiOrAntiJoin(){return this.args.kind!==void 0&&["semi","anti"].includes(this.args.kind)}};oe.key="join",oe.requiredArgs=new Set(["this"]),oe.availableArgs=new Set(["this","on","side","kind","using","method","global","hint","matchCondition","directed","expressions","pivots"]);var Zo=class extends A{constructor(e={}){super(e)}};Zo.key="matchRecognizeMeasure",Zo.requiredArgs=new Set(["this"]),Zo.availableArgs=new Set(["this","windowFrame"]);var Ko=class extends A{constructor(e={}){super(e)}};Ko.key="matchRecognize",Ko.requiredArgs=new Set,Ko.availableArgs=new Set(["partitionBy","order","measures","rows","after","pattern","define","alias"]);var Ka=class extends A{constructor(e={}){super(e)}};Ka.key="final",Ka.requiredArgs=new Set(["this"]),Ka.availableArgs=new Set(["this"]);var Rr=class extends A{constructor(e={}){super(e)}};Rr.key="offset",Rr.requiredArgs=new Set(["expression"]),Rr.availableArgs=new Set(["this","expression","expressions"]);var fe=class extends A{constructor(e={}){super(e)}};fe.key="order",fe.requiredArgs=new Set(["expressions"]),fe.availableArgs=new Set(["this","expressions","siblings"]);var ec=class extends A{constructor(e={}){super(e)}};ec.key="withFill",ec.requiredArgs=new Set,ec.availableArgs=new Set(["from","to","step","interpolate"]);var Ht=class extends A{constructor(e={}){super(e)}get name(){return this.args.this?.name||""}};Ht.key="ordered",Ht.requiredArgs=new Set(["this","nullsFirst"]),Ht.availableArgs=new Set(["this","desc","nullsFirst","withFill"]);var L=class extends A{constructor(e={}){super(e)}};L.key="property",L.requiredArgs=new Set(["this","value"]),L.availableArgs=new Set(["this","value"]);var tc=class extends A{constructor(e={}){super(e)}};tc.key="grantPrivilege",tc.requiredArgs=new Set(["this"]),tc.availableArgs=new Set(["this","expressions"]);var sc=class extends A{constructor(e={}){super(e)}};sc.key="grantPrincipal",sc.requiredArgs=new Set(["this"]),sc.availableArgs=new Set(["this","kind"]);var Dr=class extends A{constructor(e={}){super(e)}};Dr.key="allowedValuesProperty",Dr.requiredArgs=new Set(["expressions"]),Dr.availableArgs=new Set(["expressions"]);var id=class extends A{constructor(e={}){super(e)}};id.key="partitionByRangePropertyDynamic",id.requiredArgs=new Set(["start","end","every"]),id.availableArgs=new Set(["this","start","end","every"]);var nd=class extends A{constructor(e={}){super(e)}};nd.key="rollupIndex",nd.requiredArgs=new Set(["this","expressions"]),nd.availableArgs=new Set(["this","expressions","fromIndex","properties"]);var ad=class extends A{constructor(e={}){super(e)}};ad.key="partitionList",ad.requiredArgs=new Set(["this","expressions"]),ad.availableArgs=new Set(["this","expressions"]);var Ki=class extends A{constructor(e={}){super(e)}};Ki.key="partitionBoundSpec",Ki.requiredArgs=new Set,Ki.availableArgs=new Set(["this","expression","fromExpressions","toExpressions"]);var od=class extends A{constructor(e={}){super(e)}};od.key="queryTransform",od.requiredArgs=new Set(["expressions","commandScript"]),od.availableArgs=new Set(["expressions","commandScript","schema","rowFormatBefore","recordWriter","rowFormatAfter","recordReader"]);var cd=class extends A{constructor(e={}){super(e)}};cd.key="semanticView",cd.requiredArgs=new Set(["this"]),cd.availableArgs=new Set(["this","metrics","dimensions","facts","where"]);var pd=class extends A{constructor(e={}){super(e)}};pd.key="location",pd.requiredArgs=new Set,pd.availableArgs=new Set;var Os=class extends A{constructor(e={}){super(e)}};Os.key="qualify",Os.requiredArgs=new Set(["this"]),Os.availableArgs=new Set(["this"]);var rc=class extends A{constructor(e={}){super(e)}};rc.key="inputOutputFormat",rc.requiredArgs=new Set,rc.availableArgs=new Set(["inputFormat","outputFormat"]);var en=class extends A{constructor(e={}){super(e)}};en.key="return",en.requiredArgs=new Set(["this"]),en.availableArgs=new Set(["this"]);var ic=class extends A{constructor(e={}){super(e)}};ic.key="reference",ic.requiredArgs=new Set(["this"]),ic.availableArgs=new Set(["this","expressions","options"]);var Ge=class extends A{constructor(e={}){super(e)}in(e,t,s={}){let{copy:r=!0,unnest:n,...a}=s;return new it({this:Ve(this,r),expressions:e?.map(o=>Ot(o,{copy:r})),query:t?H(t,{...a,copy:r}):void 0,unnest:n?new ge({expressions:Array.from(J(n)).map(o=>H(o,{...a,copy:r}))}):void 0})}};Ge.key="tuple",Ge.requiredArgs=new Set,Ge.availableArgs=new Set(["expressions"]);var HU={match:!1,laterals:!1,joins:!1,connect:!1,pivots:!1,prewhere:!1,where:!1,group:!1,having:!1,qualify:!1,windows:!1,distribute:!1,sort:!1,cluster:!1,order:!1,limit:!1,offset:!1,locks:!1,sample:!1,settings:!1,format:!1,options:!1},ld=class extends A{constructor(e={}){super(e)}};ld.key="queryOption",ld.requiredArgs=new Set(["this"]),ld.availableArgs=new Set(["this","expression"]);var tn=class extends A{constructor(e={}){super(e)}};tn.key="withTableHint",tn.requiredArgs=new Set(["expressions"]),tn.availableArgs=new Set(["expressions"]);var nc=class extends A{constructor(e={}){super(e)}};nc.key="indexTableHint",nc.requiredArgs=new Set(["this"]),nc.availableArgs=new Set(["this","expressions","target"]);var ac=class extends A{constructor(e={}){super(e)}};ac.key="historicalData",ac.requiredArgs=new Set(["this","kind","expression"]),ac.availableArgs=new Set(["this","kind","expression"]);var Da=class extends A{constructor(e={}){super(e)}};Da.key="put",Da.requiredArgs=new Set(["this","target"]),Da.availableArgs=new Set(["this","target","properties"]);var lp=class extends A{constructor(e={}){super(e)}};lp.key="get",lp.requiredArgs=new Set(["this","target"]),lp.availableArgs=new Set(["this","target","properties"]);var V=class extends A{constructor(e={}){super(e)}get name(){let e=this.args.this;return!e||e instanceof g?"":e instanceof A?e.name||"":e.toString()}get db(){return this.text("db")}get catalog(){return this.text("catalog")}get selects(){return[]}get namedSelects(){return[]}get parts(){let e=[];for(let t of["catalog","db","this"]){let s=this.args[t];s instanceof Se?e.push(...s.flatten()):s instanceof A&&e.push(s)}return e}toColumn(e={}){let{copy:t=!0}=e,s=this.parts,r=s[s.length-1],n;if(r instanceof U){let o=s.slice(0,4).reverse(),c=s.slice(4);n=ho({col:o[0],table:o[1],db:o[2],catalog:o[3]},{fields:c,copy:t})}else n=r;let a=this.args.alias;if(a){let o=a.args.this,c=typeof o=="string"||$(o,U)?o:void 0;n=Ye(n,c,{copy:t})}return n}};V.key="table",V.requiredArgs=new Set,V.availableArgs=new Set(["this","alias","db","catalog","laterals","joins","pivots","hints","systemTime","version","format","pattern","ordinality","when","only","partition","changes","rowsFrom","sample","indexed"]);var qe=class extends A{constructor(e={}){super(e)}};qe.key="var",qe.requiredArgs=new Set(["this"]),qe.availableArgs=new Set(["this"]);var oc=class extends A{constructor(e={}){super(e)}};oc.key="version",oc.requiredArgs=new Set(["this","kind"]),oc.availableArgs=new Set(["this","kind","expression"]);var At=class extends A{constructor(e={}){super(e)}};At.key="schema",At.requiredArgs=new Set,At.availableArgs=new Set(["this","expressions"]);var Aa=class extends A{constructor(e={}){super(e)}};Aa.key="lock",Aa.requiredArgs=new Set(["update"]),Aa.availableArgs=new Set(["update","expressions","wait","key"]);var cc=class extends A{constructor(e={}){super(e)}};cc.key="tableSample",cc.requiredArgs=new Set,cc.availableArgs=new Set(["expressions","method","bucketNumerator","bucketDenominator","bucketField","percent","rows","size","seed"]);var Dm=class extends A{constructor(e={}){super(e)}get this(){return this.args.this}};Dm.key="tag",Dm.availableArgs=new Set(["this","prefix","postfix"]);var yr=class extends A{constructor(e={}){super(e)}get unpivot(){return!!this.args.unpivot}get fields(){return this.args.fields||[]}};yr.key="pivot",yr.requiredArgs=new Set([]),yr.availableArgs=new Set(["this","alias","expressions","fields","unpivot","using","group","columns","includeNulls","defaultOnNull","into","with"]);var pc=class extends A{constructor(e={}){super(e)}};pc.key="unpivotColumns",pc.requiredArgs=new Set(["this","expressions"]),pc.availableArgs=new Set(["this","expressions"]);var lc=class extends A{constructor(e={}){super(e)}};lc.key="windowSpec",lc.requiredArgs=new Set,lc.availableArgs=new Set(["kind","start","startSide","end","endSide","exclude"]);var uc=class extends A{constructor(e={}){super(e)}};uc.key="preWhere",uc.requiredArgs=new Set(["this"]),uc.availableArgs=new Set(["this"]);var at=class extends A{constructor(e={}){super(e)}};at.key="where",at.requiredArgs=new Set(["this"]),at.availableArgs=new Set(["this"]);var xe=class extends A{constructor(e={}){super(e)}get name(){return"*"}get outputName(){return this.name}};xe.key="star",xe.requiredArgs=new Set,xe.availableArgs=new Set(["except","replace","rename"]);var rr=class extends A{constructor(e={}){super(e)}get name(){return this.args.this?.name??""}};rr.key="dataTypeParam",rr.requiredArgs=new Set(["this"]),rr.availableArgs=new Set(["this","expression"]);var Pe=class Pe extends A{constructor(e={}){super(e)}static build(e,t={}){let{udt:s=!1,copy:r=!0,dialect:n,...a}=t,o;if(typeof e=="string"){if(e==="unknown")return new Pe({...a,this:"unknown"});if(Object.values(ht).includes(e))return new Pe({...a,this:e});try{o=_I(e,{read:n,into:Pe,errorLevel:0})}catch(u){if(u instanceof xt){if(s)return new Pe({this:"user-defined",kind:e,...a});throw u}else throw u}}else{if((e instanceof U||e instanceof Se)&&s)return new Pe({...a,this:"user-defined",kind:e});if(e instanceof Pe)return Ve(e,r);throw new Error(`Invalid data type: ${typeof e}. Expected string, DataTypeExprKind, or DataTypeExpr`)}for(let[c,l]of Object.entries(a))o?.setArgKey(c,l);return o}toString(){let e=this.args.this;return e===void 0?super.toString():e instanceof A?e.toString():String(e)}isType(e,t){let s=t?.checkNullable??!1,r=this.args.nullable;for(let n of J(e)){let a=Pe.build(n,{copy:!1,udt:!0}),o=a?.args.nullable,c;if(a?.args.expressions||s&&(r||o)||this.args.this==="user-defined"||a?.args.this==="user-defined"?c=this.equals(a):c=this.args.this===a?.args.this,c)return!0}return!1}};Pe.key="dataType",Pe.requiredArgs=new Set(["this"]),Pe.availableArgs=new Set(["this","expressions","nested","values","prefix","kind","nullable"]),Pe.STRUCT_TYPES=new Set(["file","nested","object","struct","union"]),Pe.ARRAY_TYPES=new Set(["array","list"]),Pe.NESTED_TYPES=new Set([...Pe.STRUCT_TYPES,...Pe.ARRAY_TYPES,"map"]),Pe.TEXT_TYPES=new Set(["char","nchar","nvarchar","text","varchar","name"]),Pe.SIGNED_INTEGER_TYPES=new Set(["bigint","int","int128","int256","mediumint","smallint","tinyint"]),Pe.UNSIGNED_INTEGER_TYPES=new Set(["ubigint","uint","uint128","uint256","umediumint","usmallint","utinyint"]),Pe.INTEGER_TYPES=new Set([...Pe.SIGNED_INTEGER_TYPES,...Pe.UNSIGNED_INTEGER_TYPES,"bit"]),Pe.FLOAT_TYPES=new Set(["double","float"]),Pe.REAL_TYPES=new Set([...Pe.FLOAT_TYPES,"bigdecimal","decimal","decimal32","decimal64","decimal128","decimal256","decfloat","money","smallmoney","udecimal","udouble"]),Pe.NUMERIC_TYPES=new Set([...Pe.INTEGER_TYPES,...Pe.REAL_TYPES]),Pe.TEMPORAL_TYPES=new Set(["date","date32","datetime","datetime2","datetime64","smalldatetime","time","timestamp","timestampntz","timestampltz","timestamptz","timestampMs","timestampNs","timestampS","timetz"]);var O=Pe,ud=class extends A{constructor(e={}){super(e)}};ud.key="type",ud.requiredArgs=new Set,ud.availableArgs=new Set;var Ws=class extends A{constructor(e={}){super(e)}};Ws.key="command",Ws.requiredArgs=new Set(["this"]),Ws.availableArgs=new Set(["this","expression"]);var hc=class extends A{constructor(e={}){super(e)}};hc.key="transaction",hc.requiredArgs=new Set,hc.availableArgs=new Set(["this","modes","mark"]);var gc=class extends A{constructor(e={}){super(e)}};gc.key="commit",gc.requiredArgs=new Set,gc.availableArgs=new Set(["chain","this","durability"]);var Ec=class extends A{constructor(e={}){super(e)}};Ec.key="rollback",Ec.requiredArgs=new Set,Ec.availableArgs=new Set(["savepoint","this"]);var sn=class extends A{constructor(e={}){super(e)}get kind(){let e=this.args.kind;return e?e.toUpperCase():void 0}get actions(){return this.args.actions||[]}};sn.key="alter",sn.requiredArgs=new Set(["kind","actions"]),sn.availableArgs=new Set(["this","kind","actions","exists","only","options","cluster","notValid","check","cascade"]);var ia=class extends A{constructor(e={}){super(e)}};ia.key="alterSession",ia.requiredArgs=new Set(["expressions"]),ia.availableArgs=new Set(["expressions","unset"]);var na=class extends A{constructor(e={}){super(e)}};na.key="analyze",na.requiredArgs=new Set,na.availableArgs=new Set(["kind","this","options","mode","partition","expression","properties"]);var Ac=class extends A{constructor(e={}){super(e)}};Ac.key="analyzeStatistics",Ac.requiredArgs=new Set(["kind"]),Ac.availableArgs=new Set(["kind","option","this","expressions"]);var dc=class extends A{constructor(e={}){super(e)}};dc.key="analyzeHistogram",dc.requiredArgs=new Set(["this","expressions"]),dc.availableArgs=new Set(["this","expressions","expression","updateOptions"]);var xc=class extends A{constructor(e={}){super(e)}};xc.key="analyzeSample",xc.requiredArgs=new Set(["kind","sample"]),xc.availableArgs=new Set(["kind","sample"]);var fc=class extends A{constructor(e={}){super(e)}};fc.key="analyzeListChainedRows",fc.requiredArgs=new Set,fc.availableArgs=new Set(["expression"]);var Tc=class extends A{constructor(e={}){super(e)}};Tc.key="analyzeDelete",Tc.requiredArgs=new Set,Tc.availableArgs=new Set(["kind"]);var rn=class extends A{constructor(e={}){super(e)}};rn.key="analyzeWith",rn.requiredArgs=new Set(["expressions"]),rn.availableArgs=new Set(["expressions"]);var Sc=class extends A{constructor(e={}){super(e)}};Sc.key="analyzeValidate",Sc.requiredArgs=new Set(["kind"]),Sc.availableArgs=new Set(["kind","this","expression"]);var nn=class extends A{constructor(e={}){super(e)}};nn.key="analyzeColumns",nn.requiredArgs=new Set(["this"]),nn.availableArgs=new Set(["this"]);var an=class extends A{constructor(e={}){super(e)}};an.key="usingData",an.requiredArgs=new Set(["this"]),an.availableArgs=new Set(["this"]);var mc=class extends A{constructor(e={}){super(e)}};mc.key="addConstraint",mc.requiredArgs=new Set(["expressions"]),mc.availableArgs=new Set(["expressions"]);var Oc=class extends A{constructor(e={}){super(e)}};Oc.key="addPartition",Oc.requiredArgs=new Set(["this"]),Oc.availableArgs=new Set(["this","exists","location"]);var hd=class extends A{constructor(e={}){super(e)}};hd.key="attachOption",hd.requiredArgs=new Set(["this"]),hd.availableArgs=new Set(["this","expression"]);var Rc=class extends A{constructor(e={}){super(e)}};Rc.key="dropPartition",Rc.requiredArgs=new Set(["expressions"]),Rc.availableArgs=new Set(["expressions","exists"]);var gd=class extends A{constructor(e={}){super(e)}};gd.key="replacePartition",gd.requiredArgs=new Set(["expression","source"]),gd.availableArgs=new Set(["expression","source"]);var Re=class extends A{constructor(e={}){super(e)}get outputName(){return typeof this.args.alias=="string"?this.args.alias:this.args.alias?.name??""}};Re.key="alias",Re.requiredArgs=new Set(["this"]),Re.availableArgs=new Set(["this","alias"]);var Cr=class extends A{constructor(e={}){super(e)}};Cr.key="pivotAny",Cr.requiredArgs=new Set,Cr.availableArgs=new Set(["this"]);var kr=class extends A{constructor(e={}){super(e)}get aliases(){return this.args.expressions??[]}};kr.key="aliases",kr.requiredArgs=new Set(["this","expressions"]),kr.availableArgs=new Set(["this","expressions"]);var Nc=class extends A{constructor(e={}){super(e)}};Nc.key="atIndex",Nc.requiredArgs=new Set(["this","expression"]),Nc.availableArgs=new Set(["this","expression"]);var Wt=class extends A{constructor(e={}){super(e)}};Wt.key="atTimeZone",Wt.requiredArgs=new Set(["this","zone"]),Wt.availableArgs=new Set(["this","zone"]);var Ed=class extends A{constructor(e={}){super(e)}};Ed.key="fromTimeZone",Ed.requiredArgs=new Set(["this","zone"]),Ed.availableArgs=new Set(["this","zone"]);var Ad=class extends A{constructor(e={}){super(e)}};Ad.key="formatPhrase",Ad.requiredArgs=new Set(["this","format"]),Ad.availableArgs=new Set(["this","format"]);var We=class extends A{constructor(e={}){super(e)}};We.key="distinct",We.requiredArgs=new Set,We.availableArgs=new Set(["expressions","on"]);var dd=class extends A{constructor(e={}){super(e)}};dd.key="forIn",dd.requiredArgs=new Set(["this","expression"]),dd.availableArgs=new Set(["this","expression"]);var fp=class fp extends A{static isVarLike(e){return e instanceof qe||e instanceof B||e instanceof R}static initTimeArgs(e){let t=e.unit;if(t&&fp.isVarLike(t)&&!(t instanceof B&&t.parts.length!==1))e.unit=new qe({this:(fp.UNABBREVIATED_UNIT_NAME[t.name]||t.name).toUpperCase()});else if(t instanceof BA){let s=t.args.this;s&&t.setArgKey("this",new qe({this:s.name.toUpperCase()}))}return e}constructor(e={}){super(fp.initTimeArgs(e))}get unit(){return this.args.unit}};fp.key="timeUnit",fp.availableArgs=new Set(["unit"]),fp.UNABBREVIATED_UNIT_NAME={D:"DAY",H:"HOUR",M:"MINUTE",MS:"MILLISECOND",NS:"NANOSECOND",Q:"QUARTER",S:"SECOND",US:"MICROSECOND",W:"WEEK",Y:"YEAR"};var K=fp,aa=class extends A{constructor(e={}){super(e)}};aa.key="ignoreNulls",aa.requiredArgs=new Set(["this"]),aa.availableArgs=new Set(["this"]);var oa=class extends A{constructor(e={}){super(e)}};oa.key="respectNulls",oa.requiredArgs=new Set(["this"]),oa.availableArgs=new Set(["this"]);var qs=class extends A{constructor(e={}){super(e)}};qs.key="havingMax",qs.requiredArgs=new Set(["this","expression","max"]),qs.availableArgs=new Set(["this","expression","max"]);var xd=class extends A{constructor(e={}){super(e)}};xd.key="translateCharacters",xd.requiredArgs=new Set(["this","expression"]),xd.availableArgs=new Set(["this","expression","withError"]);var up=class extends A{constructor(e={}){super(e)}};up.key="positionalColumn",up.requiredArgs=new Set(["this"]),up.availableArgs=new Set(["this"]);var Ic=class extends A{constructor(e={}){super(e)}};Ic.key="overflowTruncateBehavior",Ic.requiredArgs=new Set(["withCount"]),Ic.availableArgs=new Set(["this","withCount"]);var yc=class extends A{constructor(e={}){super(e)}};yc.key="json",yc.requiredArgs=new Set,yc.availableArgs=new Set(["this","with","unique"]);var bi=class extends A{constructor(e={}){super(e)}get outputName(){let t=this.args.expressions?.[this.args.expressions.length-1]?.args.this;return typeof t=="string"?t:""}};bi.key="jsonPath",bi.requiredArgs=new Set(["expressions"]),bi.availableArgs=new Set(["expressions","escape"]);var dt=class extends A{constructor(e={}){super(e)}};dt.key="jsonPathPart",dt.requiredArgs=new Set,dt.availableArgs=new Set;var Cc=class extends A{constructor(e={}){super(e)}};Cc.key="formatJson",Cc.requiredArgs=new Set(["this"]),Cc.availableArgs=new Set(["this"]);var Pc=class extends A{constructor(e={}){super(e)}};Pc.key="jsonKeyValue",Pc.requiredArgs=new Set(["this","expression"]),Pc.availableArgs=new Set(["this","expression"]);var bc=class extends A{constructor(e={}){super(e)}};bc.key="jsonColumnDef",bc.requiredArgs=new Set,bc.availableArgs=new Set(["this","kind","path","nestedSchema","ordinality"]);var Lc=class extends A{constructor(e={}){super(e)}};Lc.key="jsonSchema",Lc.requiredArgs=new Set(["expressions"]),Lc.availableArgs=new Set(["expressions"]);var wc=class extends A{constructor(e={}){super(e)}};wc.key="jsonValue",wc.requiredArgs=new Set(["this","path"]),wc.availableArgs=new Set(["this","path","returning","onCondition"]);var Mc=class extends A{constructor(e={}){super(e)}};Mc.key="openJsonColumnDef",Mc.requiredArgs=new Set(["this","kind"]),Mc.availableArgs=new Set(["this","kind","path","asJson"]);var fd=class extends A{constructor(e={}){super(e)}};fd.key="jsonExtractQuote",fd.requiredArgs=new Set(["option"]),fd.availableArgs=new Set(["option","scalar"]);var ca=class extends A{constructor(e={}){super(e)}};ca.key="scopeResolution",ca.requiredArgs=new Set(["expression"]),ca.availableArgs=new Set(["this","expression"]);var Tr=class extends A{constructor(e={}){super(e)}};Tr.key="slice",Tr.requiredArgs=new Set,Tr.availableArgs=new Set(["this","expression","step"]);var on=class extends A{constructor(e={}){super(e)}};on.key="stream",on.requiredArgs=new Set(["this"]),on.availableArgs=new Set(["this"]);var Td=class extends A{constructor(e={}){super(e)}};Td.key="modelAttribute",Td.requiredArgs=new Set(["this","expression"]),Td.availableArgs=new Set(["this","expression"]);var Sd=class extends A{constructor(e={}){super(e)}};Sd.key="weekStart",Sd.requiredArgs=new Set(["this"]),Sd.availableArgs=new Set(["this"]);var Dc=class extends A{constructor(e={}){super(e)}};Dc.key="xmlNamespace",Dc.requiredArgs=new Set(["this"]),Dc.availableArgs=new Set(["this"]);var md=class extends A{constructor(e={}){super(e)}};md.key="xmlKeyValueOption",md.requiredArgs=new Set(["this"]),md.availableArgs=new Set(["this","expression"]);var kc=class extends A{constructor(e={}){super(e)}};kc.key="use",kc.requiredArgs=new Set,kc.availableArgs=new Set(["this","expressions","kind"]);var _r=class extends A{constructor(e={}){super(e)}};_r.key="when",_r.requiredArgs=new Set(["matched","then"]),_r.availableArgs=new Set(["matched","source","condition","then"]);var cn=class extends A{constructor(e={}){super(e)}};cn.key="whens",cn.requiredArgs=new Set(["expressions"]),cn.availableArgs=new Set(["expressions"]);var _c=class extends A{constructor(e={}){super(e)}};_c.key="semicolon",_c.requiredArgs=new Set,_c.availableArgs=new Set;var Mi=class extends A{constructor(e={}){super(e)}};Mi.key="tableColumn",Mi.requiredArgs=new Set(["this"]),Mi.availableArgs=new Set(["this"]);var hp=class extends A{constructor(e={}){super(e)}};hp.key="variadic",hp.requiredArgs=new Set(["this"]),hp.availableArgs=new Set(["this"]);var Tt=class extends hr{constructor(e={}){super(e)}};Tt.key="cte",Tt.requiredArgs=new Set(["this","alias"]),Tt.availableArgs=new Set(["this","alias","scalar","materialized","keyExpressions"]);var PA=class extends ye{constructor(e={}){super(e)}};PA.key="bitString";var da=class extends ye{constructor(e={}){super(e)}};da.key="hexString",da.availableArgs=new Set(["this","isInteger"]);var Nl=class extends ye{constructor(e={}){super(e)}};Nl.key="byteString",Nl.availableArgs=new Set(["this","isBytes"]);var pa=class extends ye{constructor(e={}){super(e)}};pa.key="rawString";var Il=class extends ye{constructor(e={}){super(e)}};Il.key="unicodeString",Il.availableArgs=new Set(["this","escape"]);var B=class extends ye{constructor(e={}){super(e)}get table(){return this.text("table")}get db(){return this.text("db")}get catalog(){return this.text("catalog")}get outputName(){return this.name}get parts(){let e=[];for(let t of["catalog","db","table","this"]){let s=this.args[t];s&&e.push(s)}return e}toDot(e={}){let{includeDots:t=!0}=e,s=this.parts,r=this.parent;if(t)for(;r instanceof Se&&r.args.expression!==void 0;)s.push(r.args.expression),r=r.parent;return 1<s.length?Se.build(s.map(n=>n.copy())):s[0]}};B.key="column",B.requiredArgs=new Set(["this"]),B.availableArgs=new Set(["this","table","db","catalog","joinMark"]);var lA=class extends B{constructor(e={}){super(e)}};lA.key="pseudocolumn";var bA=class extends ae{constructor(e={}){super(e)}};bA.key="autoIncrementColumnConstraint";var gp=class extends Or{constructor(e={}){super(e)}};gp.key="zeroFillColumnConstraint",gp.requiredArgs=new Set,gp.availableArgs=new Set;var qc=class extends ae{constructor(e={}){super(e)}};qc.key="periodForSystemTimeConstraint",qc.requiredArgs=new Set(["this","expression"]),qc.availableArgs=new Set(["this","expression"]);var Pr=class extends ae{constructor(e={}){super(e)}};Pr.key="caseSpecificColumnConstraint",Pr.requiredArgs=new Set(["not"]),Pr.availableArgs=new Set(["not"]);var Uc=class extends ae{constructor(e={}){super(e)}};Uc.key="characterSetColumnConstraint";var yl=class extends ae{constructor(e={}){super(e)}};yl.key="checkColumnConstraint",yl.availableArgs=new Set(["this","enforced"]);var vc=class extends ae{constructor(e={}){super(e)}};vc.key="clusteredColumnConstraint";var Fc=class extends ae{constructor(e={}){super(e)}};Fc.key="collateColumnConstraint";var Bc=class extends ae{constructor(e={}){super(e)}};Bc.key="commentColumnConstraint";var oo=class extends ae{constructor(e={}){super(e)}};oo.key="compressColumnConstraint",oo.requiredArgs=new Set;var $c=class extends ae{constructor(e={}){super(e)}};$c.key="dateFormatColumnConstraint";var Gc=class extends ae{constructor(e={}){super(e)}};Gc.key="defaultColumnConstraint";var Yc=class extends ae{constructor(e={}){super(e)}};Yc.key="encodeColumnConstraint";var Vc=class extends ae{constructor(e={}){super(e)}};Vc.key="excludeColumnConstraint";var xa=class extends ae{constructor(e={}){super(e)}};xa.key="ephemeralColumnConstraint",xa.requiredArgs=new Set;var Zn=class extends ae{constructor(e={}){super(e)}};Zn.key="generatedAsIdentityColumnConstraint",Zn.availableArgs=new Set(["this","expression","onNull","start","increment","minvalue","maxvalue","cycle","order"]);var Hc=class extends ae{constructor(e={}){super(e)}};Hc.key="generatedAsRowColumnConstraint",Hc.requiredArgs=new Set,Hc.availableArgs=new Set(["start","hidden"]);var Od=class extends ae{constructor(e={}){super(e)}};Od.key="indexColumnConstraint",Od.requiredArgs=new Set,Od.availableArgs=new Set(["this","expressions","kind","indexType","options","expression","granularity"]);var Wc=class extends ae{constructor(e={}){super(e)}};Wc.key="inlineLengthColumnConstraint";var jc=class extends ae{constructor(e={}){super(e)}};jc.key="nonClusteredColumnConstraint";var pn=class extends ae{constructor(e={}){super(e)}};pn.key="notForReplicationColumnConstraint",pn.requiredArgs=new Set,pn.availableArgs=new Set;var km=class extends ae{constructor(e={}){super(e)}};km.key="maskingPolicyColumnConstraint",km.availableArgs=new Set(["this","expressions"]);var la=class extends ae{constructor(e={}){super(e)}};la.key="notNullColumnConstraint",la.requiredArgs=new Set,la.availableArgs=new Set(["allowNull"]);var Jc=class extends ae{constructor(e={}){super(e)}};Jc.key="onUpdateColumnConstraint";var Xc=class extends ae{constructor(e={}){super(e)}};Xc.key="primaryKeyColumnConstraint",Xc.requiredArgs=new Set,Xc.availableArgs=new Set(["desc","options"]);var zc=class extends ae{constructor(e={}){super(e)}};zc.key="titleColumnConstraint";var ln=class extends ae{constructor(e={}){super(e)}};ln.key="uniqueColumnConstraint",ln.requiredArgs=new Set,ln.availableArgs=new Set(["this","indexType","onConflict","nulls","options"]);var un=class extends ae{constructor(e={}){super(e)}};un.key="uppercaseColumnConstraint",un.requiredArgs=new Set,un.availableArgs=new Set;var Qc=class extends ae{constructor(e={}){super(e)}};Qc.key="pathColumnConstraint";var vA=class extends ae{constructor(e={}){super(e)}};vA.key="projectionPolicyColumnConstraint";var Fi=class extends ae{constructor(e={}){super(e)}};Fi.key="computedColumnConstraint",Fi.availableArgs=new Set(["this","persisted","notNull","dataType"]);var Zc=class extends ae{constructor(e={}){super(e)}};Zc.key="inOutColumnConstraint",Zc.requiredArgs=new Set,Zc.availableArgs=new Set(["input","output","variadic"]);var Kc=class extends ls{constructor(e={}){super(e)}};Kc.key="copy",Kc.requiredArgs=new Set(["this","kind"]),Kc.availableArgs=new Set(["this","kind","files","credentials","format","params"]);var kt=class extends G(gr,ls,A){constructor(e={}){super(e)}with(e,t,s={}){let{recursive:r,materialized:n,append:a,dialect:o,copy:c,...l}=s;return ow({instance:this,alias:e,as:t,recursive:r,materialized:n,append:a,dialect:o,copy:c,...l})}};kt.key="insert",kt.requiredArgs=new Set,kt.availableArgs=new Set(["hint","with","isFunction","this","expression","conflict","returning","overwrite","exists","alternative","where","ignore","byName","stored","partition","settings","source","default"]);var Tp=class Tp extends ye{static number(e){let t=new Tp({this:String(e),isString:!1}),s=typeof e=="number"?e:parseFloat(String(e));return!isNaN(s)&&s<0&&(t=new Tp({this:String(Math.abs(s)),isString:!1}),t=new It({this:t})),t}static string(e){return new Tp({this:String(e),isString:!0})}constructor(e={}){super(e)}get outputName(){return this.name}toValue(){if(this.isNumber){let e=parseFloat(this.args.this);if(!isNaN(e))return e}return this.args.this}};Tp.key="literal",Tp.requiredArgs=new Set(["this","isString"]),Tp.availableArgs=new Set(["this","isString"]);var R=Tp,Nr=class extends fe{constructor(e={}){super(e)}};Nr.key="cluster";var LA=class extends fe{constructor(e={}){super(e)}};LA.key="distribute";var co=class extends fe{constructor(e={}){super(e)}};co.key="sort";var qr=class extends L{constructor(e={}){super(e)}};qr.key="algorithmProperty",qr.requiredArgs=new Set(["this"]),qr.availableArgs=new Set(["this"]);var Ur=class extends L{constructor(e={}){super(e)}};Ur.key="autoIncrementProperty",Ur.requiredArgs=new Set(["this"]),Ur.availableArgs=new Set(["this"]);var vr=class extends L{constructor(e={}){super(e)}};vr.key="autoRefreshProperty",vr.requiredArgs=new Set(["this"]),vr.availableArgs=new Set(["this"]);var Fr=class extends L{constructor(e={}){super(e)}};Fr.key="backupProperty",Fr.requiredArgs=new Set(["this"]),Fr.availableArgs=new Set(["this"]);var Rd=class extends L{constructor(e={}){super(e)}};Rd.key="buildProperty",Rd.requiredArgs=new Set(["this"]),Rd.availableArgs=new Set(["this"]);var hn=class extends L{constructor(e={}){super(e)}};hn.key="blockCompressionProperty",hn.requiredArgs=new Set,hn.availableArgs=new Set(["autotemp","always","default","manual","never"]);var ir=class extends L{constructor(e={}){super(e)}get value(){return this.args.value}};ir.key="characterSetProperty",ir.requiredArgs=new Set(["this","default"]),ir.availableArgs=new Set(["this","default"]);var gn=class extends L{constructor(e={}){super(e)}};gn.key="checksumProperty",gn.requiredArgs=new Set,gn.availableArgs=new Set(["on","default"]);var Br=class extends L{constructor(e={}){super(e)}get value(){return this.args.value}};Br.key="collateProperty",Br.requiredArgs=new Set(["this"]),Br.availableArgs=new Set(["this","default"]);var $r=class extends L{constructor(e={}){super(e)}};$r.key="copyGrantsProperty",$r.requiredArgs=new Set,$r.availableArgs=new Set;var En=class extends L{constructor(e={}){super(e)}};En.key="dataBlocksizeProperty",En.requiredArgs=new Set,En.availableArgs=new Set(["size","units","minimum","maximum","default"]);var An=class extends L{constructor(e={}){super(e)}};An.key="dataDeletionProperty",An.requiredArgs=new Set(["on"]),An.availableArgs=new Set(["on","filterColumn","retentionPeriod"]);var Gr=class extends L{constructor(e={}){super(e)}};Gr.key="definerProperty",Gr.requiredArgs=new Set(["this"]),Gr.availableArgs=new Set(["this"]);var Yr=class extends L{constructor(e={}){super(e)}};Yr.key="distKeyProperty",Yr.requiredArgs=new Set(["this"]),Yr.availableArgs=new Set(["this"]);var Vr=class extends L{constructor(e={}){super(e)}get value(){return this.args.value}};Vr.key="distributedByProperty",Vr.requiredArgs=new Set(["kind"]),Vr.availableArgs=new Set(["expressions","kind","buckets","order"]);var Hr=class extends L{constructor(e={}){super(e)}};Hr.key="distStyleProperty",Hr.requiredArgs=new Set(["this"]),Hr.availableArgs=new Set(["this"]);var dn=class extends L{constructor(e={}){super(e)}};dn.key="duplicateKeyProperty",dn.requiredArgs=new Set(["expressions"]),dn.availableArgs=new Set(["expressions"]);var Wr=class extends L{constructor(e={}){super(e)}};Wr.key="engineProperty",Wr.requiredArgs=new Set(["this"]),Wr.availableArgs=new Set(["this"]);var jr=class extends L{constructor(e={}){super(e)}};jr.key="heapProperty",jr.requiredArgs=new Set,jr.availableArgs=new Set;var Jr=class extends L{constructor(e={}){super(e)}};Jr.key="toTableProperty",Jr.requiredArgs=new Set(["this"]),Jr.availableArgs=new Set(["this"]);var Ms=class extends L{constructor(e={}){super(e)}};Ms.key="executeAsProperty",Ms.requiredArgs=new Set(["this"]),Ms.availableArgs=new Set(["this"]);var Xr=class extends L{constructor(e={}){super(e)}};Xr.key="externalProperty",Xr.requiredArgs=new Set,Xr.availableArgs=new Set(["this"]);var xn=class extends L{constructor(e={}){super(e)}};xn.key="fallbackProperty",xn.requiredArgs=new Set(["no"]),xn.availableArgs=new Set(["no","protection"]);var ws=class extends L{constructor(e={}){super(e)}get value(){return this.args.value}};ws.key="fileFormatProperty",ws.requiredArgs=new Set,ws.availableArgs=new Set(["this","expressions","hiveFormat"]);var va=class extends L{constructor(e={}){super(e)}};va.key="credentialsProperty",va.requiredArgs=new Set(["expressions"]),va.availableArgs=new Set(["expressions"]);var fn=class extends L{constructor(e={}){super(e)}};fn.key="freespaceProperty",fn.requiredArgs=new Set(["this"]),fn.availableArgs=new Set(["this","percent"]);var zr=class extends L{constructor(e={}){super(e)}};zr.key="globalProperty",zr.requiredArgs=new Set,zr.availableArgs=new Set;var Qr=class extends L{constructor(e={}){super(e)}};Qr.key="icebergProperty",Qr.requiredArgs=new Set,Qr.availableArgs=new Set;var Zr=class extends L{constructor(e={}){super(e)}};Zr.key="inheritsProperty",Zr.requiredArgs=new Set(["expressions"]),Zr.availableArgs=new Set(["expressions"]);var Kr=class extends L{constructor(e={}){super(e)}};Kr.key="inputModelProperty",Kr.requiredArgs=new Set(["this"]),Kr.availableArgs=new Set(["this"]);var ei=class extends L{constructor(e={}){super(e)}};ei.key="outputModelProperty",ei.requiredArgs=new Set(["this"]),ei.availableArgs=new Set(["this"]);var Tn=class extends L{constructor(e={}){super(e)}};Tn.key="isolatedLoadingProperty",Tn.requiredArgs=new Set,Tn.availableArgs=new Set(["no","concurrent","target"]);var Sn=class extends L{constructor(e={}){super(e)}};Sn.key="journalProperty",Sn.requiredArgs=new Set,Sn.availableArgs=new Set(["no","dual","before","local","after"]);var nr=class extends L{constructor(e={}){super(e)}};nr.key="languageProperty",nr.requiredArgs=new Set(["this"]),nr.availableArgs=new Set(["this"]);var ti=class extends L{constructor(e={}){super(e)}};ti.key="enviromentProperty",ti.requiredArgs=new Set(["expressions"]),ti.availableArgs=new Set(["expressions"]);var si=class extends L{constructor(e={}){super(e)}};si.key="clusteredByProperty",si.requiredArgs=new Set(["expressions","buckets"]),si.availableArgs=new Set(["expressions","sortedBy","buckets"]);var mn=class extends L{constructor(e={}){super(e)}};mn.key="dictProperty",mn.requiredArgs=new Set(["this","kind"]),mn.availableArgs=new Set(["this","kind","settings"]);var wA=class extends L{constructor(e={}){super(e)}};wA.key="dictSubProperty";var On=class extends L{constructor(e={}){super(e)}};On.key="dictRange",On.requiredArgs=new Set(["this","min","max"]),On.availableArgs=new Set(["this","min","max"]);var ri=class extends L{constructor(e={}){super(e)}};ri.key="dynamicProperty",ri.requiredArgs=new Set,ri.availableArgs=new Set;var Nd=class extends L{constructor(e={}){super(e)}};Nd.key="onCluster",Nd.requiredArgs=new Set(["this"]),Nd.availableArgs=new Set(["this"]);var ii=class extends L{constructor(e={}){super(e)}};ii.key="emptyProperty",ii.requiredArgs=new Set,ii.availableArgs=new Set;var Rn=class extends L{constructor(e={}){super(e)}};Rn.key="likeProperty",Rn.requiredArgs=new Set(["this"]),Rn.availableArgs=new Set(["this","expressions"]);var ar=class extends L{constructor(e={}){super(e)}};ar.key="locationProperty",ar.requiredArgs=new Set(["this"]),ar.availableArgs=new Set(["this"]);var Fa=class extends L{constructor(e={}){super(e)}};Fa.key="lockProperty",Fa.requiredArgs=new Set(["this"]),Fa.availableArgs=new Set(["this"]);var Nn=class extends L{constructor(e={}){super(e)}get value(){return this.args.value}};Nn.key="lockingProperty",Nn.requiredArgs=new Set(["kind","lockType"]),Nn.availableArgs=new Set(["this","kind","forOrIn","lockType","override"]);var ni=class extends L{constructor(e={}){super(e)}};ni.key="logProperty",ni.requiredArgs=new Set(["no"]),ni.availableArgs=new Set(["no"]);var ai=class extends L{constructor(e={}){super(e)}};ai.key="materializedProperty",ai.requiredArgs=new Set,ai.availableArgs=new Set(["this"]);var br=class extends L{constructor(e={}){super(e)}get value(){return this.args.value}};br.key="mergeBlockRatioProperty",br.requiredArgs=new Set,br.availableArgs=new Set(["this","no","default","percent"]);var oi=class extends L{constructor(e={}){super(e)}};oi.key="noPrimaryIndexProperty",oi.requiredArgs=new Set,oi.availableArgs=new Set;var zs=class extends L{constructor(e={}){super(e)}};zs.key="onProperty",zs.requiredArgs=new Set(["this"]),zs.availableArgs=new Set(["this"]);var Qs=class extends L{constructor(e={}){super(e)}};Qs.key="onCommitProperty",Qs.requiredArgs=new Set,Qs.availableArgs=new Set(["delete"]);var os=class extends L{constructor(e={}){super(e)}};os.key="partitionedByProperty",os.requiredArgs=new Set(["this"]),os.availableArgs=new Set(["this"]);var In=class extends L{constructor(e={}){super(e)}};In.key="partitionedByBucket",In.requiredArgs=new Set(["this","expression"]),In.availableArgs=new Set(["this","expression"]);var yn=class extends L{constructor(e={}){super(e)}};yn.key="partitionByTruncate",yn.requiredArgs=new Set(["this","expression"]),yn.availableArgs=new Set(["this","expression"]);var Id=class extends L{constructor(e={}){super(e)}};Id.key="partitionByRangeProperty",Id.requiredArgs=new Set(["partitionExpressions","createExpressions"]),Id.availableArgs=new Set(["partitionExpressions","createExpressions"]);var Ep=class extends L{constructor(e={}){super(e)}};Ep.key="rollupProperty",Ep.requiredArgs=new Set(["expressions"]),Ep.availableArgs=new Set(["expressions"]);var yd=class extends L{constructor(e={}){super(e)}};yd.key="partitionByListProperty",yd.requiredArgs=new Set(["partitionExpressions","createExpressions"]),yd.availableArgs=new Set(["partitionExpressions","createExpressions"]);var Ap=class extends L{constructor(e={}){super(e)}};Ap.key="refreshTriggerProperty",Ap.requiredArgs=new Set,Ap.availableArgs=new Set(["method","kind","every","unit","starts"]);var Cd=class extends L{constructor(e={}){super(e)}};Cd.key="uniqueKeyProperty",Cd.requiredArgs=new Set(["expressions"]),Cd.availableArgs=new Set(["expressions"]);var Cn=class extends L{constructor(e={}){super(e)}};Cn.key="partitionedOfProperty",Cn.requiredArgs=new Set(["this","expression"]),Cn.availableArgs=new Set(["this","expression"]);var ci=class extends L{constructor(e={}){super(e)}};ci.key="streamingTableProperty",ci.requiredArgs=new Set,ci.availableArgs=new Set;var pi=class extends L{constructor(e={}){super(e)}};pi.key="remoteWithConnectionModelProperty",pi.requiredArgs=new Set(["this"]),pi.availableArgs=new Set(["this"]);var or=class extends L{constructor(e={}){super(e)}};or.key="returnsProperty",or.requiredArgs=new Set,or.availableArgs=new Set(["this","isTable","table","null"]);var li=class extends L{constructor(e={}){super(e)}};li.key="strictProperty",li.requiredArgs=new Set,li.availableArgs=new Set;var ui=class extends L{constructor(e={}){super(e)}};ui.key="rowFormatProperty",ui.requiredArgs=new Set(["this"]),ui.availableArgs=new Set(["this"]);var Pn=class extends L{constructor(e={}){super(e)}};Pn.key="rowFormatDelimitedProperty",Pn.requiredArgs=new Set,Pn.availableArgs=new Set(["fields","escaped","collectionItems","mapKeys","lines","null","serde"]);var bn=class extends L{constructor(e={}){super(e)}};bn.key="rowFormatSerdeProperty",bn.requiredArgs=new Set(["this"]),bn.availableArgs=new Set(["this","serdeProperties"]);var hi=class extends L{constructor(e={}){super(e)}};hi.key="sampleProperty",hi.requiredArgs=new Set(["this"]),hi.availableArgs=new Set(["this"]);var gi=class extends L{constructor(e={}){super(e)}};gi.key="securityProperty",gi.requiredArgs=new Set(["this"]),gi.availableArgs=new Set(["this"]);var Ei=class extends L{constructor(e={}){super(e)}};Ei.key="schemaCommentProperty",Ei.requiredArgs=new Set(["this"]),Ei.availableArgs=new Set(["this"]);var Ln=class extends L{constructor(e={}){super(e)}};Ln.key="serdeProperties",Ln.requiredArgs=new Set(["expressions"]),Ln.availableArgs=new Set(["expressions","with"]);var Zs=class extends L{constructor(e={}){super(e)}};Zs.key="setProperty",Zs.requiredArgs=new Set(["multi"]),Zs.availableArgs=new Set(["multi"]);var Ai=class extends L{constructor(e={}){super(e)}};Ai.key="sharingProperty",Ai.requiredArgs=new Set,Ai.availableArgs=new Set(["this"]);var ka=class extends L{constructor(e={}){super(e)}};ka.key="setConfigProperty",ka.requiredArgs=new Set(["this"]),ka.availableArgs=new Set(["this"]);var di=class extends L{constructor(e={}){super(e)}};di.key="settingsProperty",di.requiredArgs=new Set(["expressions"]),di.availableArgs=new Set(["expressions"]);var xi=class extends L{constructor(e={}){super(e)}};xi.key="sortKeyProperty",xi.requiredArgs=new Set(["this"]),xi.availableArgs=new Set(["this","compound"]);var Es=class extends L{constructor(e={}){super(e)}};Es.key="sqlReadWriteProperty",Es.requiredArgs=new Set(["this"]),Es.availableArgs=new Set(["this"]);var fi=class extends L{constructor(e={}){super(e)}};fi.key="sqlSecurityProperty",fi.requiredArgs=new Set(["this"]),fi.availableArgs=new Set(["this"]);var As=class extends L{constructor(e={}){super(e)}};As.key="stabilityProperty",As.requiredArgs=new Set(["this"]),As.availableArgs=new Set(["this"]);var wn=class extends L{constructor(e={}){super(e)}};wn.key="storageHandlerProperty",wn.requiredArgs=new Set(["this"]),wn.availableArgs=new Set(["this"]);var ds=class extends L{constructor(e={}){super(e)}};ds.key="temporaryProperty",ds.requiredArgs=new Set,ds.availableArgs=new Set(["this"]);var Ti=class extends L{constructor(e={}){super(e)}};Ti.key="secureProperty",Ti.requiredArgs=new Set,Ti.availableArgs=new Set;var _a=class extends G(ae,L){constructor(e={}){super(e)}};_a.key="tags",_a.requiredArgs=new Set(["expressions"]),_a.availableArgs=new Set(["expressions"]);var Si=class extends L{constructor(e={}){super(e)}};Si.key="transformModelProperty",Si.requiredArgs=new Set(["expressions"]),Si.availableArgs=new Set(["expressions"]);var mi=class extends L{constructor(e={}){super(e)}};mi.key="transientProperty",mi.requiredArgs=new Set,mi.availableArgs=new Set(["this"]);var Oi=class extends L{constructor(e={}){super(e)}};Oi.key="unloggedProperty",Oi.requiredArgs=new Set,Oi.availableArgs=new Set;var qa=class extends L{constructor(e={}){super(e)}};qa.key="usingTemplateProperty",qa.requiredArgs=new Set(["this"]),qa.availableArgs=new Set(["this"]);var Ri=class extends L{constructor(e={}){super(e)}};Ri.key="viewAttributeProperty",Ri.requiredArgs=new Set(["this"]),Ri.availableArgs=new Set(["this"]);var Ni=class extends L{constructor(e={}){super(e)}};Ni.key="volatileProperty",Ni.requiredArgs=new Set,Ni.availableArgs=new Set(["this"]);var Mn=class extends L{constructor(e={}){super(e)}};Mn.key="withDataProperty",Mn.requiredArgs=new Set(["no"]),Mn.availableArgs=new Set(["no","statistics"]);var Ii=class extends L{constructor(e={}){super(e)}};Ii.key="withJournalTableProperty",Ii.requiredArgs=new Set(["this"]),Ii.availableArgs=new Set(["this"]);var yi=class extends L{constructor(e={}){super(e)}};yi.key="withSchemaBindingProperty",yi.requiredArgs=new Set(["this"]),yi.availableArgs=new Set(["this"]);var Dn=class extends L{constructor(e={}){super(e)}};Dn.key="withSystemVersioningProperty",Dn.requiredArgs=new Set(["with"]),Dn.availableArgs=new Set(["on","this","dataConsistency","retentionPeriod","with"]);var Ci=class extends L{constructor(e={}){super(e)}};Ci.key="withProcedureOptions",Ci.requiredArgs=new Set(["expressions"]),Ci.availableArgs=new Set(["expressions"]);var Ba=class extends L{constructor(e={}){super(e)}};Ba.key="encodeProperty",Ba.requiredArgs=new Set(["this"]),Ba.availableArgs=new Set(["this","properties","key"]);var $a=class extends L{constructor(e={}){super(e)}};$a.key="includeProperty",$a.requiredArgs=new Set(["this"]),$a.availableArgs=new Set(["this","alias","columnDef"]);var Ua=class extends L{constructor(e={}){super(e)}};Ua.key="forceProperty",Ua.requiredArgs=new Set,Ua.availableArgs=new Set;var Hn=class Hn extends A{constructor(e={}){super(e)}static fromDict(e){let t=[];for(let[s,r]of Object.entries(e)){let n=Hn.NAME_TO_PROPERTY[s.toUpperCase()];n?t.push(new n({this:Ot(r)})):t.push(new L({this:R.string(s),value:Ot(r)}))}return new Hn({expressions:t})}};Hn.key="properties",Hn.requiredArgs=new Set(["expressions"]),Hn.availableArgs=new Set(["expressions"]),Hn.NAME_TO_PROPERTY={ALGORITHM:qr,AUTO_INCREMENT:Ur,"CHARACTER SET":ir,CLUSTERED_BY:si,COLLATE:Br,COMMENT:Ei,CREDENTIALS:va,DEFINER:Gr,DISTKEY:Yr,DISTRIBUTED_BY:Vr,DISTSTYLE:Hr,ENGINE:Wr,"EXECUTE AS":Ms,FORMAT:ws,LANGUAGE:nr,LOCATION:ar,LOCK:Fa,PARTITIONED_BY:os,RETURNS:or,ROW_FORMAT:ui,SORTKEY:xi,ENCODE:Ba,INCLUDE:$a},Hn.PROPERTY_TO_NAME=Object.fromEntries(Object.entries(Hn.NAME_TO_PROPERTY).map(([e,t])=>[t.key,e]));var Ke=Hn,uu=class uu extends z{constructor(e={}){super(e)}select(e,t={}){let{copy:s=!0,...r}=t,n=Array.from(J(e)),a=Ve(this,s),o=a.args.this;te(o,z),ft(o.unnest(),z)?.select(n,{...r,copy:!1});let c=a.args.expression;return te(c,z),ft(c.unnest(),z)?.select(n,{...r,copy:!1,append:t?.append??!0}),a}get namedSelects(){let e=this;for(;e instanceof uu;){let t=e.args.this?.unnest();te(t,z),e=t}return e.namedSelects}get isStar(){let e=this.args.this?.isStar,t=this.args.expression?.isStar;return e||t||!1}get selects(){let e=this;for(;e instanceof uu;){let t=e.args.this?.unnest();te(t,z),e=t}return e.selects}get left(){return this.args.this}get right(){return this.args.expression}get kind(){return this.args.kind}get side(){return this.text("side").toUpperCase()}};uu.key="setOperation",uu.requiredArgs=new Set(["this","expression"]),uu.availableArgs=new Set(["with","this","expression","distinct","byName","side","kind","on","match","laterals","joins","connect","pivots","prewhere","where","group","having","qualify","windows","distribute","sort","cluster","order","limit","offset","locks","sample","settings","format","options"]);var Xe=uu,Vt=class extends ls{constructor(e={}){super(e)}table(e,t={}){let{dialect:s,copy:r=!0}=t;return sA(e,{instance:this,arg:"this",into:V,prefix:void 0,dialect:s,copy:r})}set(e,t={}){let{append:s=!0,dialect:r,copy:n=!0}=t,a=Array.from(J(e));return lu(a,{instance:this,arg:"expressions",append:s,into:A,prefix:void 0,dialect:r,copy:n})}where(e,t={}){let{append:s=!0,dialect:r,copy:n=!0}=t;return If(e,{instance:this,arg:"where",append:s,into:at,dialect:r,copy:n})}from(e,t={}){let{dialect:s,copy:r=!0}=t;return e?sA(e,{instance:this,arg:"from",into:Je,prefix:"FROM",dialect:s,copy:r}):this}with(e,t,s={}){let{recursive:r=!1,append:n=!0,copy:a=!0,...o}=s;return ow({instance:this,alias:e,as:t,...o,recursive:r,append:n,copy:a})}};Vt.key="update",Vt.requiredArgs=new Set,Vt.availableArgs=new Set(["with","this","expressions","from","where","returning","order","limit","options"]);var wd=class wd extends z{constructor(e={}){super(e)}get namedSelects(){let e=[];for(let t of this.args.expressions||[])t.aliasOrName?e.push(t.outputName):t instanceof kr&&e.push(...t.aliases.map(s=>s.name));return e}get isStar(){return this.args.expressions?.some(e=>typeof e=="object"&&"isStar"in e&&e.isStar)??!1}get selects(){return this.args.expressions||[]}from(e,t={}){let{dialect:s,copy:r=!0,...n}=t;return sA(e,{...n,instance:this,arg:"from",into:Je,prefix:"FROM",dialect:s,copy:r})}groupBy(e,t={}){let{append:s=!0,dialect:r,copy:n=!0,...a}=t,o=Array.from(J(e));return o.length===0?n?this.copy():this:Ld(o,{...a,instance:this,arg:"group",append:s,copy:n,prefix:"GROUP BY",into:Xs,dialect:r})}sortBy(e,t={}){let{append:s=!0,dialect:r,copy:n=!0,...a}=t;return Ld(e,{...a,instance:this,arg:"sort",append:s,copy:n,prefix:"SORT BY",into:co,dialect:r})}clusterBy(e,t={}){let{append:s=!0,dialect:r,copy:n=!0,...a}=t;return Ld(e,{...a,instance:this,arg:"cluster",append:s,copy:n,prefix:"CLUSTER BY",into:Nr,dialect:r})}having(e,t={}){let{append:s=!0,dialect:r=void 0,copy:n=!0,...a}=t;return If(e,{instance:this,arg:"having",append:s,into:Zt,dialect:r,copy:n,...a})}orderBy(e,t={}){let{append:s=!0,dialect:r=void 0,copy:n=!0,...a}=t;return Ld(e,{instance:this,arg:"order",append:s,copy:n,prefix:"ORDER BY",into:fe,dialect:r,...a})}select(e,t={}){let{append:s=!0,dialect:r,copy:n=!0,...a}=t;return lu(e,{instance:this,arg:"expressions",append:s,dialect:r,into:A,copy:n,...a})}lateral(e,t={}){let{append:s=!0,dialect:r,copy:n=!0,...a}=t;return lu(e,{...a,instance:this,arg:"laterals",append:s,into:St,prefix:"LATERAL VIEW",dialect:r,copy:n})}join(e,t={}){let{on:s,using:r,append:n=!0,joinType:a,joinAlias:o,dialect:c,copy:l=!0,...u}=t,h={dialect:c},d;try{d=H(e,{...h,into:oe,prefix:"JOIN"})}catch{try{d=H(e,{...h,into:oe})}catch{d=H(e,{...h})}}let x=d instanceof oe?d:new oe({this:d});x.args.this instanceof wd&&x.args.this?.replace(x.args.this?.subquery());let f={left:"left",right:"right",full:"full"};if(a){let y=f[a]??a,I=H(y,{...h,into:"JOIN_TYPE"});I.args.method&&x.setArgKey("method",I.args.method),I.args.side&&x.setArgKey("side",I.args.side),I.args.kind&&x.setArgKey("kind",I.args.kind)}if(s){let y=Fe(Array.from(J(s)),{dialect:c,copy:l});x.setArgKey("on",y)}return r&&(x=lu(Array.from(J(r)),{instance:x,arg:"using",append:n,copy:l,into:U})),o&&x.setArgKey("this",Ye(x.args.this,o,{table:!0})),lu([x],{instance:this,arg:"joins",append:n,copy:l})}window(e,t={}){let{append:s=!0,dialect:r,copy:n=!0,...a}=t;return lu(e,{...a,instance:this,arg:"windows",append:s,into:we,dialect:r,copy:n})}qualify(e,t={}){let{append:s=!0,dialect:r,copy:n=!0,...a}=t;return If(e,{...a,instance:this,arg:"qualify",append:s,into:Os,dialect:r,copy:n})}distinct(e,t={}){let{distinct:s=!0,copy:r=!0,...n}=t,a=Ve(this,r),c=(e?e.some(u=>u===!1):!1)?!1:s,l=e?e.filter(u=>u!==void 0&&u!==!1&&u!==!0):[];if(0<l.length){let u=l.map(d=>H(d,{copy:r,into:A})),h=new Ge({expressions:u});a.setArgKey("distinct",c?new We({on:h}):void 0)}else a.setArgKey("distinct",c?new We({}):void 0);return a}ctas(e,t={}){let{properties:s,dialect:r,copy:n=!0}=t,a=Ve(this,n),o=H((e instanceof A,e),{dialect:r,into:V}),c;return s&&(c=Ke.fromDict(s)),new qt({this:o,kind:"table",expression:a,properties:c})}lock(e={}){let{update:t=!0,copy:s=!0}=e,r=Ve(this,s);return r.setArgKey("locks",[new Aa({update:new R({this:String(Number(t)),isString:!1})})]),r}hint(e,t={}){let{dialect:s,copy:r=!0}=t,a=(e!==void 0?Array.from(J(e)):[]).map(c=>H(c,{dialect:s,into:A})),o=Ve(this,r);return o.setArgKey("hint",new us({expressions:a})),o}};wd.key="select",wd.requiredArgs=new Set,wd.availableArgs=new Set(["with","kind","expressions","hint","distinct","into","from","operationModifiers","exclude","match","laterals","joins","connect","pivots","prewhere","where","group","having","qualify","windows","distribute","sort","cluster","order","limit","offset","locks","sample","settings","format","options","for"]);var ee=wd,hu=class hu extends G(hr,z){constructor(e={}){super(e)}unnest(){let e=this;for(;e instanceof hu;){let t=e.args.this;if(!t||(e=t,e===this))break}return e}unwrap(){let e=this;for(;e.sameParent&&e.isWrapper;){let t=e.parent;if(!(t instanceof hu))break;e=t}return e}select(e,t={}){let{copy:s=!0,...r}=t,n=Ve(this,s),a=n?.unnest();return a instanceof ee&&a.select(e,{...r,copy:!1}),n}get isWrapper(){return Object.entries(this.args).every(([e,t])=>e==="this"||t===void 0)}get isStar(){let e=this.args.this;return e?e.isStar:!1}get outputName(){return this.alias}};hu.key="subquery",hu.requiredArgs=new Set(["this"]),hu.availableArgs=new Set(["this","alias","with","match","laterals","joins","connect","pivots","prewhere","where","group","having","qualify","windows","distribute","sort","cluster","order","limit","offset","locks","sample","settings","format","options"]);var Te=hu,we=class extends ye{constructor(e={}){super(e)}};we.key="window",we.requiredArgs=new Set(["this"]),we.availableArgs=new Set(["this","partitionBy","order","spec","alias","over","first"]);var Cl=class extends ye{constructor(e={}){super(e)}};Cl.key="parameter",Cl.availableArgs=new Set(["this","expression"]);var Pl=class extends ye{constructor(e={}){super(e)}};Pl.key="sessionParameter",Pl.availableArgs=new Set(["this","kind"]);var Ds=class extends ye{constructor(e={}){super(e)}get name(){return(this.args.this instanceof A?this.args.this.name:this.args.this)||"?"}};Ds.key="placeholder",Ds.requiredArgs=new Set,Ds.availableArgs=new Set(["this","kind","widget","jdbc"]);var Ze=class extends ye{constructor(e={}){super(e)}get name(){return"NULL"}toValue(){}};Ze.key="null",Ze.requiredArgs=new Set,Ze.availableArgs=new Set;var ot=class extends ye{constructor(e={}){super(e)}toValue(){return!!this.args.this}};ot.key="boolean";var bl=class extends O{constructor(e={}){super(e)}};bl.key="pseudoType",bl.availableArgs=new Set(["this"]);var Ll=class extends O{constructor(e={}){super(e)}};Ll.key="objectIdentifier",Ll.availableArgs=new Set(["this"]);var q=class extends ye{constructor(e={}){super(e)}get left(){return this.args.this}get right(){return this.args.expression}};q.key="binary",q.requiredArgs=new Set(["this","expression"]),q.availableArgs=new Set(["this","expression"]);var hs=class extends ye{constructor(e={}){super(e)}};hs.key="unary",hs.requiredArgs=new Set(["this"]),hs.availableArgs=new Set(["this"]);var MA=class extends Re{constructor(e={}){super(e)}};MA.key="pivotAlias";var Dt=class extends ye{constructor(e={}){super(e)}get outputName(){return this.args.expressions?.length===1?this.args.expressions[0].outputName:super.outputName}};Dt.key="bracket",Dt.requiredArgs=new Set,Dt.availableArgs=new Set(["this","expressions","offset","safe","returnsListForMaps"]);var Cs=class extends K{constructor(e={}){super(e)}interval(){return new Ce({this:this.args.expression?.copy(),unit:this.unit?.copy()})}};Cs.key="intervalOp",Cs.requiredArgs=new Set(["expression"]),Cs.availableArgs=new Set(["unit","expression"]);var Ks=class extends A{constructor(e={}){super(e)}};Ks.key="intervalSpan",Ks.requiredArgs=new Set(["this","expression"]),Ks.availableArgs=new Set(["this","expression"]);var Ce=class extends K{constructor(e={}){super(e)}};Ce.key="interval",Ce.requiredArgs=new Set,Ce.availableArgs=new Set(["this","unit"]);var Ga=class Ga extends ye{constructor(e={}){super(e)}static fromArgList(e){let t=this.argOrder;if(t.length===0&&(t=Array.from(this.availableArgs)),this.isVarLenArgs){let s=t.slice(0,-1),r=s.length,n={};for(let a=0;a<s.length;a++)n[s[a]]=e[a];return n[t[t.length-1]]=e.slice(r),new this(n)}else{let s={};for(let r=0;r<t.length;r++)s[t[r]]=e[r];return new this(s)}}static sqlNames(){if(this===Ga)throw new Error("SQL name is only supported by concrete function implementations");if(!Object.hasOwn(this,"_sqlNames")){let t=this.name.replace(/Expr$/,"").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").toUpperCase();this._sqlNames=[t]}return this._sqlNames}static sqlName(){let e=this.sqlNames();if(!e.length)throw new Error(`Expected non-empty 'sql_names' for Func: ${this.name}.`);return e[0]}static defaultParserMappings(){let e={};for(let t of this.sqlNames())e[t]=this.fromArgList.bind(this);return e}static register(){this===Ga||this===D||kD(this)}};Ga.key="func",Ga.requiredArgs=new Set,Ga.isVarLenArgs=!1,Ga.argOrder=[],Ga._sqlNames=[];var g=Ga,D=class extends g{constructor(e={}){super(e)}};D.key="aggFunc",D.argOrder=["this"];var xs=class extends dt{constructor(e={}){super(e)}};xs.key="jsonPathFilter",xs.requiredArgs=new Set(["this"]),xs.availableArgs=new Set(["this"]);var jt=class extends dt{constructor(e={}){super(e)}};jt.key="jsonPathKey",jt.requiredArgs=new Set(["this"]),jt.availableArgs=new Set(["this"]);var cr=class extends dt{constructor(e={}){super(e)}};cr.key="jsonPathRecursive",cr.availableArgs=new Set(["this"]);var cs=class extends dt{constructor(e={}){super(e)}};cs.key="jsonPathRoot",cs.requiredArgs=new Set,cs.availableArgs=new Set;var fs=class extends dt{constructor(e={}){super(e)}};fs.key="jsonPathScript",fs.requiredArgs=new Set(["this"]),fs.availableArgs=new Set(["this"]);var pr=class extends dt{constructor(e={}){super(e)}};pr.key="jsonPathSlice",pr.availableArgs=new Set(["start","end","step"]);var lr=class extends dt{constructor(e={}){super(e)}};lr.key="jsonPathSelector",lr.requiredArgs=new Set(["this"]),lr.availableArgs=new Set(["this"]);var Ts=class extends dt{constructor(e={}){super(e)}};Ts.key="jsonPathSubscript",Ts.requiredArgs=new Set(["this"]),Ts.availableArgs=new Set(["this"]);var vs=class extends dt{constructor(e={}){super(e)}};vs.key="jsonPathUnion",vs.requiredArgs=new Set(["expressions"]),vs.availableArgs=new Set(["expressions"]);var Pt=class extends dt{constructor(e={}){super(e)}};Pt.key="jsonPathWildcard",Pt.requiredArgs=new Set,Pt.availableArgs=new Set;var fa=class extends ls{constructor(e={}){super(e)}};fa.key="merge",fa.requiredArgs=new Set(["this","using","whens"]),fa.availableArgs=new Set(["this","using","on","usingCond","whens","with","returning"]);var St=class extends Nt{constructor(e={}){super(e)}};St.key="lateral",St.availableArgs=new Set(["this","view","outer","alias","crossApply","ordinality"]);var zn=class extends Nt{constructor(e={}){super(e)}};zn.key="tableFromRows",zn.availableArgs=new Set(["this","alias","joins","pivots","sample"]);var Lr=class extends Xe{constructor(e={}){super(e)}};Lr.key="union";var wr=class extends Xe{constructor(e={}){super(e)}};wr.key="except";var kn=class extends Xe{constructor(e={}){super(e)}};kn.key="intersect";var Ls=class extends Nt{constructor(e={}){super(e)}};Ls.key="values",Ls.requiredArgs=new Set(["expressions"]),Ls.availableArgs=new Set(["expressions","alias","order","limit","offset"]);var $s=class extends Ne{constructor(e={}){super(e)}};$s.key="subqueryPredicate";var Le=class extends q{constructor(e={}){super(e)}};Le.key="add";var Ee=class extends q{constructor(e={}){super(e)}};Ee.key="connector";var Ta=class extends q{constructor(e={}){super(e)}};Ta.key="bitwiseAnd",Ta.availableArgs=new Set(["this","expression","padside"]);var wl=class extends q{constructor(e={}){super(e)}};wl.key="bitwiseLeftShift",wl.availableArgs=new Set(["this","expression","requiresInt128"]);var Ml=class extends q{constructor(e={}){super(e)}};Ml.key="bitwiseOr",Ml.availableArgs=new Set(["this","expression","padside"]);var Sa=class extends q{constructor(e={}){super(e)}};Sa.key="bitwiseRightShift",Sa.availableArgs=new Set(["this","expression","requiresInt128"]);var Dl=class extends q{constructor(e={}){super(e)}};Dl.key="bitwiseXor",Dl.availableArgs=new Set(["this","expression","padside"]);var mt=class extends q{constructor(e={}){super(e)}get left(){return this.args.this}get right(){return this.args.expression}};mt.key="div",mt.availableArgs=new Set(["this","expression","typed","safe"]);var DA=class extends q{constructor(e={}){super(e)}};DA.key="overlaps";var ep=class extends q{constructor(e={}){super(e)}};ep.key="extendsLeft";var tp=class extends q{constructor(e={}){super(e)}};tp.key="extendsRight";var kN=class kN extends q{constructor(e={}){super(e)}get isStar(){return this.args.expression?.isStar??!1}get name(){return this.args.expression?.name??""}get outputName(){return this.name}static build(e){if(e.length<2)throw new Error("Dot requires >= 2 expressions.");return e.reduce((t,s)=>new kN({this:t,expression:s}))}get parts(){let[e,...t]=this.flatten(),s=[...t];s.reverse();for(let r of lq){let n=e.args[r];n instanceof A&&s.push(n)}return s.reverse(),s}};kN.key="dot";var Se=kN,Mt=class extends q{constructor(e={}){super(e)}};Mt.key="dPipe",Mt.availableArgs=new Set(["this","expression","safe"]);var me=class extends G(q,Ne){constructor(e={}){super(e)}};me.key="eq",me.requiredArgs=new Set(["this","expression"]),me.availableArgs=new Set(["this","expression"]);var Ps=class extends G(q,Ne){constructor(e={}){super(e)}};Ps.key="nullSafeEq",Ps.requiredArgs=new Set(["this","expression"]),Ps.availableArgs=new Set(["this","expression"]);var Gs=class extends G(q,Ne){constructor(e={}){super(e)}};Gs.key="nullSafeNeq",Gs.requiredArgs=new Set(["this","expression"]),Gs.availableArgs=new Set(["this","expression"]);var ct=class extends q{constructor(e={}){super(e)}};ct.key="propertyEq";var kA=class extends q{constructor(e={}){super(e)}};kA.key="distance";var ma=class extends q{constructor(e={}){super(e)}};ma.key="escape";var ua=class extends G(q,Ne){constructor(e={}){super(e)}};ua.key="glob",ua.requiredArgs=new Set(["this","expression"]),ua.availableArgs=new Set(["this","expression"]);var Be=class extends G(q,Ne){constructor(e={}){super(e)}};Be.key="gt",Be.requiredArgs=new Set(["this","expression"]),Be.availableArgs=new Set(["this","expression"]);var Me=class extends G(q,Ne){constructor(e={}){super(e)}};Me.key="gte",Me.requiredArgs=new Set(["this","expression"]),Me.availableArgs=new Set(["this","expression"]);var Us=class extends G(q,Ne){constructor(e={}){super(e)}};Us.key="iLike",Us.requiredArgs=new Set(["this","expression"]),Us.availableArgs=new Set(["this","expression"]);var ha=class extends q{constructor(e={}){super(e)}};ha.key="intDiv";var _e=class extends G(q,Ne){constructor(e={}){super(e)}};_e.key="is",_e.requiredArgs=new Set(["this","expression"]),_e.availableArgs=new Set(["this","expression"]);var sp=class extends q{constructor(e={}){super(e)}};sp.key="kwarg";var Ut=class extends G(q,Ne){constructor(e={}){super(e)}};Ut.key="like",Ut.requiredArgs=new Set(["this","expression"]),Ut.availableArgs=new Set(["this","expression"]);var Pd=class extends G(q,Ne){constructor(e={}){super(e)}};Pd.key="match",Pd.requiredArgs=new Set(["this","expression"]),Pd.availableArgs=new Set(["this","expression"]);var De=class extends G(q,Ne){constructor(e={}){super(e)}};De.key="lt",De.requiredArgs=new Set(["this","expression"]),De.availableArgs=new Set(["this","expression"]);var $e=class extends G(q,Ne){constructor(e={}){super(e)}};$e.key="lte",$e.requiredArgs=new Set(["this","expression"]),$e.availableArgs=new Set(["this","expression"]);var Bi=class extends q{constructor(e={}){super(e)}};Bi.key="mod";var Ns=class extends q{constructor(e={}){super(e)}};Ns.key="mul";var st=class extends G(q,Ne){constructor(e={}){super(e)}};st.key="neq",st.requiredArgs=new Set(["this","expression"]),st.availableArgs=new Set(["this","expression"]);var _n=class extends q{constructor(e={}){super(e)}};_n.key="operator",_n.requiredArgs=new Set(["this","operator","expression"]),_n.availableArgs=new Set(["this","operator","expression"]);var rp=class extends G(q,Ne){constructor(e={}){super(e)}};rp.key="similarTo",rp.requiredArgs=new Set(["this","expression"]),rp.availableArgs=new Set(["this","expression"]);var ke=class extends q{constructor(e={}){super(e)}};ke.key="sub";var ip=class extends q{constructor(e={}){super(e)}};ip.key="adjacent";var np=class extends hs{constructor(e={}){super(e)}};np.key="bitwiseNot";var be=class extends hs{constructor(e={}){super(e)}};be.key="not";var Oe=class extends hs{constructor(e={}){super(e)}get outputName(){return this.args.this?.name??""}};Oe.key="paren";var It=class extends hs{constructor(e={}){super(e)}toValue(){return this.isNumber?(this.args.this?.toValue()??0)*-1:super.toValue()}};It.key="neg";var ss=class extends Ne{constructor(e={}){super(e)}};ss.key="between",ss.requiredArgs=new Set(["this","low","high"]),ss.availableArgs=new Set(["this","low","high","symmetric"]);var it=class extends Ne{constructor(e={}){super(e)}};it.key="in",it.availableArgs=new Set(["this","expressions","query","unnest","field","isGlobal"]);var _m=class _m extends g{constructor(e={}){super(e)}};_m.key="safeFunc",_m.argOrder=["this"],_m.register();var xT=_m,qm=class qm extends g{constructor(e={}){super(e)}};qm.key="typeof",qm.argOrder=["this"],qm.register();var sy=qm,Um=class Um extends g{constructor(e={}){super(e)}};Um.key="acos",Um.argOrder=["this"],Um.register();var PT=Um,vm=class vm extends g{constructor(e={}){super(e)}};vm.key="acosh",vm.argOrder=["this"],vm.register();var bT=vm,Fm=class Fm extends g{constructor(e={}){super(e)}};Fm.key="asin",Fm.argOrder=["this"],Fm.register();var LT=Fm,Bm=class Bm extends g{constructor(e={}){super(e)}};Bm.key="asinh",Bm.argOrder=["this"],Bm.register();var wT=Bm,Md=class Md extends g{constructor(e={}){super(e)}};Md.key="atan",Md.availableArgs=new Set(["this","expression"]),Md.argOrder=["this","expression"],Md.register();var MT=Md,$m=class $m extends g{constructor(e={}){super(e)}};$m.key="atanh",$m.argOrder=["this"],$m.register();var DT=$m,gu=class gu extends g{constructor(e={}){super(e)}};gu.key="atan2",gu.requiredArgs=new Set(["this","expression"]),gu.availableArgs=new Set(["this","expression"]),gu.argOrder=["this","expression"],gu.register();var ry=gu,Gm=class Gm extends g{constructor(e={}){super(e)}};Gm.key="cot",Gm.argOrder=["this"],Gm.register();var kT=Gm,Ym=class Ym extends g{constructor(e={}){super(e)}};Ym.key="coth",Ym.argOrder=["this"],Ym.register();var iy=Ym,Vm=class Vm extends g{constructor(e={}){super(e)}};Vm.key="cos",Vm.argOrder=["this"],Vm.register();var _T=Vm,Hm=class Hm extends g{constructor(e={}){super(e)}};Hm.key="csc",Hm.argOrder=["this"],Hm.register();var ny=Hm,Wm=class Wm extends g{constructor(e={}){super(e)}};Wm.key="csch",Wm.argOrder=["this"],Wm.register();var ay=Wm,jm=class jm extends g{constructor(e={}){super(e)}};jm.key="sec",jm.argOrder=["this"],jm.register();var oy=jm,Jm=class Jm extends g{constructor(e={}){super(e)}};Jm.key="sech",Jm.argOrder=["this"],Jm.register();var cy=Jm,Xm=class Xm extends g{constructor(e={}){super(e)}};Xm.key="sin",Xm.argOrder=["this"],Xm.register();var qT=Xm,zm=class zm extends g{constructor(e={}){super(e)}};zm.key="sinh",zm.argOrder=["this"],zm.register();var UT=zm,Qm=class Qm extends g{constructor(e={}){super(e)}};Qm.key="tan",Qm.argOrder=["this"],Qm.register();var vT=Qm,Zm=class Zm extends g{constructor(e={}){super(e)}};Zm.key="tanh",Zm.argOrder=["this"],Zm.register();var FT=Zm,Km=class Km extends g{constructor(e={}){super(e)}};Km.key="degrees",Km.argOrder=["this"],Km.register();var py=Km,eO=class eO extends g{constructor(e={}){super(e)}};eO.key="cosh",eO.argOrder=["this"],eO.register();var BT=eO,Eu=class Eu extends g{constructor(e={}){super(e)}};Eu.key="cosineDistance",Eu.requiredArgs=new Set(["this","expression"]),Eu.availableArgs=new Set(["this","expression"]),Eu.argOrder=["this","expression"],Eu.register();var ly=Eu,Au=class Au extends g{constructor(e={}){super(e)}};Au.key="dotProduct",Au.requiredArgs=new Set(["this","expression"]),Au.availableArgs=new Set(["this","expression"]),Au.argOrder=["this","expression"],Au.register();var uy=Au,du=class du extends g{constructor(e={}){super(e)}};du.key="euclideanDistance",du.requiredArgs=new Set(["this","expression"]),du.availableArgs=new Set(["this","expression"]),du.argOrder=["this","expression"],du.register();var hy=du,xu=class xu extends g{constructor(e={}){super(e)}};xu.key="manhattanDistance",xu.requiredArgs=new Set(["this","expression"]),xu.availableArgs=new Set(["this","expression"]),xu.argOrder=["this","expression"],xu.register();var gy=xu,fu=class fu extends g{constructor(e={}){super(e)}};fu.key="jarowinklerSimilarity",fu.requiredArgs=new Set(["this","expression"]),fu.availableArgs=new Set(["this","expression","caseInsensitive"]),fu.argOrder=["this","expression"],fu.register();var Ey=fu,tO=class tO extends g{constructor(e={}){super(e)}};tO.key="bitwiseCount",tO.argOrder=["this"],tO.register();var Ay=tO,sO=class sO extends g{constructor(e={}){super(e)}};sO.key="bitmapBucketNumber",sO.argOrder=["this"],sO.register();var dy=sO,rO=class rO extends g{constructor(e={}){super(e)}};rO.key="bitmapCount",rO.argOrder=["this"],rO.register();var xy=rO,iO=class iO extends g{constructor(e={}){super(e)}};iO.key="bitmapBitPosition",iO.argOrder=["this"],iO.register();var fy=iO,nO=class nO extends g{constructor(e={}){super(e)}};nO.key="byteLength",nO.argOrder=["this"],nO.register();var Ty=nO,Dd=class Dd extends g{constructor(e={}){super(e)}};Dd.key="boolnot",Dd.availableArgs=new Set(["this","roundInput"]),Dd.argOrder=["this","roundInput"],Dd.register();var Sy=Dd,Tu=class Tu extends g{constructor(e={}){super(e)}};Tu.key="booland",Tu.requiredArgs=new Set(["this","expression"]),Tu.availableArgs=new Set(["this","expression","roundInput"]),Tu.argOrder=["this","expression","roundInput"],Tu.register();var my=Tu,Su=class Su extends g{constructor(e={}){super(e)}};Su.key="boolor",Su.requiredArgs=new Set(["this","expression"]),Su.availableArgs=new Set(["this","expression","roundInput"]),Su.argOrder=["this","expression","roundInput"],Su.register();var Oy=Su,aO=class aO extends g{constructor(e={}){super(e)}};aO.key="jsonBool",aO.argOrder=["this"],aO.register();var Ry=aO,mu=class mu extends g{constructor(e={}){super(e)}};mu.key="arrayRemove",mu.requiredArgs=new Set(["this","expression"]),mu.availableArgs=new Set(["this","expression","nullPropagation"]),mu.argOrder=["this","expression","nullPropagation"],mu.register();var kl=mu,oO=class oO extends g{constructor(e={}){super(e)}};oO.key="abs",oO.argOrder=["this"],oO.register();var $T=oO,kd=class kd extends g{constructor(e={}){super(e)}};kd.key="approxTopKEstimate",kd.availableArgs=new Set(["this","expression"]),kd.argOrder=["this","expression"],kd.register();var Ny=kd,Ya=class Ya extends g{constructor(e={}){super(e)}};Ya.key="farmFingerprint",Ya.isVarLenArgs=!0,Ya._sqlNames=["FARM_FINGERPRINT","FARMFINGERPRINT64"],Ya.requiredArgs=new Set(["expressions"]),Ya.availableArgs=new Set(["expressions"]),Ya.argOrder=["expressions"],Ya.register();var Iy=Ya,cO=class cO extends g{constructor(e={}){super(e)}};cO.key="flatten",cO.argOrder=["this"],cO.register();var yy=cO,_d=class _d extends g{constructor(e={}){super(e)}};_d.key="float64",_d.availableArgs=new Set(["this","expression"]),_d.argOrder=["this","expression"],_d.register();var Cy=_d,Ou=class Ou extends g{constructor(e={}){super(e)}};Ou.key="transform",Ou.requiredArgs=new Set(["this","expression"]),Ou.availableArgs=new Set(["this","expression"]),Ou.argOrder=["this","expression"],Ou.register();var Py=Ou,Ru=class Ru extends g{constructor(e={}){super(e)}};Ru.key="translate",Ru.requiredArgs=new Set(["this","from","to"]),Ru.availableArgs=new Set(["this","from","to"]),Ru.argOrder=["this","from","to"],Ru.register();var GT=Ru,Nu=class Nu extends g{constructor(e={}){super(e)}get name(){let e=this.args.this;return e===void 0?"":e instanceof A?e.name:e.toString()}};Nu.key="anonymous",Nu.isVarLenArgs=!0,Nu.availableArgs=new Set(["this","expressions"]),Nu.argOrder=["this","expressions"],Nu.register();var je=Nu,Iu=class Iu extends g{constructor(e={}){super(e)}};Iu.key="apply",Iu.requiredArgs=new Set(["this","expression"]),Iu.availableArgs=new Set(["this","expression"]),Iu.argOrder=["this","expression"],Iu.register();var by=Iu,Sp=class Sp extends g{constructor(e={}){super(e)}};Sp.key="array",Sp.isVarLenArgs=!0,Sp.requiredArgs=new Set,Sp.availableArgs=new Set(["expressions","bracketNotation","structNameInheritance"]),Sp.argOrder=["expressions","bracketNotation","structNameInheritance"],Sp.register();var ue=Sp,pO=class pO extends g{constructor(e={}){super(e)}};pO.key="ascii",pO.argOrder=["this"],pO.register();var YT=pO,lO=class lO extends g{constructor(e={}){super(e)}};lO.key="toArray",lO.argOrder=["this"],lO.register();var Ly=lO,qd=class qd extends g{constructor(e={}){super(e)}};qd.key="toBoolean",qd.availableArgs=new Set(["this","safe"]),qd.argOrder=["this","safe"],qd.register();var wy=qd,mp=class mp extends g{constructor(e={}){super(e)}};mp.key="list",mp.requiredArgs=new Set,mp.isVarLenArgs=!0,mp.availableArgs=new Set(["expressions"]),mp.argOrder=["expressions"],mp.register();var Yf=mp,yu=class yu extends g{constructor(e={}){super(e)}};yu.key="pad",yu.requiredArgs=new Set(["this","expression","isLeft"]),yu.availableArgs=new Set(["this","expression","fillPattern","isLeft"]),yu.argOrder=["this","expression","fillPattern","isLeft"],yu.register();var Vf=yu,Ud=class Ud extends g{constructor(e={}){super(e)}};Ud.key="toChar",Ud.availableArgs=new Set(["this","format","nlsparam","isNumeric"]),Ud.argOrder=["this","format","nlsparam","isNumeric"],Ud.register();var Cm=Ud,uO=class uO extends g{constructor(e={}){super(e)}};uO.key="toCodePoints",uO.argOrder=["this"],uO.register();var My=uO,vd=class vd extends g{constructor(e={}){super(e)}};vd.key="toNumber",vd.availableArgs=new Set(["this","format","nlsparam","precision","scale","safe","safeName"]),vd.argOrder=["this","format","nlsparam","precision","scale","safe","safeName"],vd.register();var Dy=vd,Fd=class Fd extends g{constructor(e={}){super(e)}};Fd.key="toDouble",Fd.availableArgs=new Set(["this","format","safe"]),Fd.argOrder=["this","format","safe"],Fd.register();var VT=Fd,Bd=class Bd extends g{constructor(e={}){super(e)}};Bd.key="toDecfloat",Bd.availableArgs=new Set(["this","format"]),Bd.argOrder=["this","format"],Bd.register();var ky=Bd,$d=class $d extends g{constructor(e={}){super(e)}};$d.key="tryToDecfloat",$d.availableArgs=new Set(["this","format"]),$d.argOrder=["this","format"],$d.register();var _y=$d,Gd=class Gd extends g{constructor(e={}){super(e)}};Gd.key="toFile",Gd.availableArgs=new Set(["this","path","safe"]),Gd.argOrder=["this","path","safe"],Gd.register();var qy=Gd,hO=class hO extends g{constructor(e={}){super(e)}};hO.key="codePointsToBytes",hO.argOrder=["this"],hO.register();var Uy=hO,Yd=class Yd extends g{constructor(e={}){super(e)}};Yd.key="columns",Yd.availableArgs=new Set(["this","unpack"]),Yd.argOrder=["this","unpack"],Yd.register();var Hf=Yd,Cu=class Cu extends g{constructor(e={}){super(e)}};Cu.key="convert",Cu.requiredArgs=new Set(["this","expression"]),Cu.availableArgs=new Set(["this","expression","style","safe"]),Cu.argOrder=["this","expression","style","safe"],Cu.register();var vy=Cu,Pu=class Pu extends g{constructor(e={}){super(e)}};Pu.key="convertToCharset",Pu.requiredArgs=new Set(["this","dest"]),Pu.availableArgs=new Set(["this","dest","source"]),Pu.argOrder=["this","dest","source"],Pu.register();var fT=Pu,bu=class bu extends g{constructor(e={}){super(e)}};bu.key="convertTimezone",bu.requiredArgs=new Set(["targetTz","timestamp"]),bu.availableArgs=new Set(["sourceTz","targetTz","timestamp","options"]),bu.argOrder=["sourceTz","targetTz","timestamp","options"],bu.register();var po=bu,gO=class gO extends g{constructor(e={}){super(e)}};gO.key="codePointsToString",gO.argOrder=["this"],gO.register();var Fy=gO,Lu=class Lu extends g{constructor(e={}){super(e)}};Lu.key="generateSeries",Lu.requiredArgs=new Set(["start","end"]),Lu.availableArgs=new Set(["start","end","step","isEndExclusive"]),Lu.argOrder=["start","end","step","isEndExclusive"],Lu.register();var Fs=Lu,wu=class wu extends G(g,Nt){constructor(e={}){super(e)}};wu.key="generator",wu.argOrder=["rowcount","timelimit"],wu.requiredArgs=new Set,wu.availableArgs=new Set(["rowcount","timelimit"]),wu.register();var By=wu,Op=class Op extends g{constructor(e={}){super(e)}};Op.key="aiClassify",Op._sqlNames=["AI_CLASSIFY"],Op.requiredArgs=new Set(["this","categories"]),Op.availableArgs=new Set(["this","categories","config"]),Op.argOrder=["this","categories","config"],Op.register();var $y=Op,Mu=class Mu extends g{constructor(e={}){super(e)}};Mu.key="arrayAll",Mu.requiredArgs=new Set(["this","expression"]),Mu.availableArgs=new Set(["this","expression"]),Mu.argOrder=["this","expression"],Mu.register();var Gy=Mu,Du=class Du extends g{constructor(e={}){super(e)}};Du.key="arrayAny",Du.requiredArgs=new Set(["this","expression"]),Du.availableArgs=new Set(["this","expression"]),Du.argOrder=["this","expression"],Du.register();var Yy=Du,ku=class ku extends g{constructor(e={}){super(e)}};ku.key="arrayAppend",ku.requiredArgs=new Set(["this","expression"]),ku.availableArgs=new Set(["this","expression","nullPropagation"]),ku.argOrder=["this","expression","nullPropagation"],ku.register();var Wf=ku,_u=class _u extends g{constructor(e={}){super(e)}};_u.key="arrayPrepend",_u.requiredArgs=new Set(["this","expression"]),_u.availableArgs=new Set(["this","expression","nullPropagation"]),_u.argOrder=["this","expression","nullPropagation"],_u.register();var jf=_u,Rp=class Rp extends g{constructor(e={}){super(e)}};Rp.key="arrayConcat",Rp._sqlNames=["ARRAY_CONCAT","ARRAY_CAT"],Rp.isVarLenArgs=!0,Rp.availableArgs=new Set(["this","expressions","nullPropagation"]),Rp.argOrder=["this","expressions","nullPropagation"],Rp.register();var _l=Rp,EO=class EO extends g{constructor(e={}){super(e)}};EO.key="arrayCompact",EO.argOrder=["this"],EO.register();var Vy=EO,qu=class qu extends g{constructor(e={}){super(e)}};qu.key="arrayInsert",qu.requiredArgs=new Set(["this","position","expression"]),qu.availableArgs=new Set(["this","position","expression","offset"]),qu.argOrder=["this","position","expression","offset"],qu.register();var Hy=qu,Uu=class Uu extends g{constructor(e={}){super(e)}};Uu.key="arrayRemoveAt",Uu.requiredArgs=new Set(["this","position"]),Uu.availableArgs=new Set(["this","position"]),Uu.argOrder=["this","position"],Uu.register();var Wy=Uu,Np=class Np extends g{constructor(e={}){super(e)}};Np.key="arrayConstructCompact",Np.requiredArgs=new Set,Np.isVarLenArgs=!0,Np.availableArgs=new Set(["expressions"]),Np.argOrder=["expressions"],Np.register();var jy=Np,Ip=class Ip extends G(q,g){constructor(e={}){super(e)}};Ip.key="arrayContains",Ip._sqlNames=["ARRAY_CONTAINS","ARRAY_HAS"],Ip.argOrder=["this","expression"],Ip.requiredArgs=new Set(["this","expression"]),Ip.availableArgs=new Set(["this","expression","ensureVariant","checkNull"]),Ip.register();var Jy=Ip,vu=class vu extends G(q,g){constructor(e={}){super(e)}};vu.key="arrayContainsAll",vu._sqlNames=["ARRAY_CONTAINS_ALL","ARRAY_HAS_ALL"],vu.requiredArgs=new Set(["this","expression"]),vu.availableArgs=new Set(["this","expression"]),vu.register();var lo=vu,yp=class yp extends g{constructor(e={}){super(e)}};yp.key="arrayFilter",yp._sqlNames=["FILTER","ARRAY_FILTER"],yp.requiredArgs=new Set(["this","expression"]),yp.availableArgs=new Set(["this","expression"]),yp.argOrder=["this","expression"],yp.register();var dp=yp,AO=class AO extends g{constructor(e={}){super(e)}};AO.key="arrayFirst",AO.argOrder=["this"],AO.register();var HT=AO,dO=class dO extends g{constructor(e={}){super(e)}};dO.key="arrayLast",dO.argOrder=["this"],dO.register();var WT=dO,xO=class xO extends g{constructor(e={}){super(e)}};xO.key="arrayReverse",xO.argOrder=["this"],xO.register();var jT=xO,Fu=class Fu extends g{constructor(e={}){super(e)}};Fu.key="arraySlice",Fu.requiredArgs=new Set(["this","start"]),Fu.availableArgs=new Set(["this","start","end","step"]),Fu.argOrder=["this","start","end","step"],Fu.register();var JT=Fu,Cp=class Cp extends g{constructor(e={}){super(e)}};Cp.key="arrayToString",Cp._sqlNames=["ARRAY_TO_STRING","ARRAY_JOIN"],Cp.requiredArgs=new Set(["this","expression"]),Cp.availableArgs=new Set(["this","expression","null"]),Cp.argOrder=["this","expression","null"],Cp.register();var XT=Cp,Va=class Va extends g{constructor(e={}){super(e)}};Va.key="arrayIntersect",Va.isVarLenArgs=!0,Va._sqlNames=["ARRAY_INTERSECT","ARRAY_INTERSECTION"],Va.requiredArgs=new Set(["expressions"]),Va.availableArgs=new Set(["expressions"]),Va.argOrder=["expressions"],Va.register();var Xy=Va,Pp=class Pp extends g{constructor(e={}){super(e)}};Pp.key="stPoint",Pp._sqlNames=["ST_POINT","ST_MAKEPOINT"],Pp.requiredArgs=new Set(["this","expression"]),Pp.availableArgs=new Set(["this","expression","null"]),Pp.argOrder=["this","expression","null"],Pp.register();var zy=Pp,Bu=class Bu extends g{constructor(e={}){super(e)}};Bu.key="stDistance",Bu.requiredArgs=new Set(["this","expression"]),Bu.availableArgs=new Set(["this","expression","useSpheroid"]),Bu.argOrder=["this","expression","useSpheroid"],Bu.register();var Qy=Bu,Vd=class Vd extends g{constructor(e={}){super(e)}};Vd.key="string",Vd.availableArgs=new Set(["this","zone"]),Vd.argOrder=["this","zone"],Vd.register();var zT=Vd,$u=class $u extends g{constructor(e={}){super(e)}};$u.key="stringToArray",$u._sqlNames=["STRING_TO_ARRAY","SPLIT_BY_STRING","STRTOK_TO_ARRAY"],$u.availableArgs=new Set(["this","expression","null"]),$u.argOrder=["this","expression","null"],$u.register();var Zy=$u,Hd=class Hd extends G(q,g){constructor(e={}){super(e)}};Hd.key="arrayOverlaps",Hd.requiredArgs=new Set(["this","expression"]),Hd.availableArgs=new Set(["this","expression"]),Hd.register();var TT=Hd,Gu=class Gu extends g{constructor(e={}){super(e)}};Gu.key="arraySize",Gu._sqlNames=["ARRAY_SIZE","ARRAY_LENGTH"],Gu.availableArgs=new Set(["this","expression"]),Gu.argOrder=["this","expression"],Gu.register();var Bn=Gu,Wd=class Wd extends g{constructor(e={}){super(e)}};Wd.key="arraySort",Wd.availableArgs=new Set(["this","expression"]),Wd.argOrder=["this","expression"],Wd.register();var Ky=Wd,jd=class jd extends g{constructor(e={}){super(e)}};jd.key="arraySum",jd.availableArgs=new Set(["this","expression"]),jd.argOrder=["this","expression"],jd.register();var eC=jd,bp=class bp extends g{constructor(e={}){super(e)}};bp.key="arraysZip",bp.requiredArgs=new Set,bp.isVarLenArgs=!0,bp.availableArgs=new Set(["expressions"]),bp.argOrder=["expressions"],bp.register();var tC=bp,Yu=class Yu extends g{constructor(e={}){super(e)}when(e,t,s={}){let{copy:r=!0}=s,n=Ve(this,r);return n.append("ifs",new le({this:H(e,s),true:H(t,s)})),n}else(e,t={}){let{copy:s=!0}=t,r=Ve(this,s);return r.setArgKey("default",H(e,t)),r}};Yu.key="case",Yu.requiredArgs=new Set(["ifs"]),Yu.availableArgs=new Set(["this","ifs","default"]),Yu.argOrder=["this","ifs","default"],Yu.register();var nt=Yu,Vu=class Vu extends g{constructor(e={}){super(e)}get name(){return this.args.this.name||""}get to(){return this.args.to}get outputName(){return this.name}isType(e,t={}){let s=this.args.to;return s&&s instanceof O?s.isType(e):!1}};Vu.key="cast",Vu.requiredArgs=new Set(["this","to"]),Vu.availableArgs=new Set(["this","to","format","safe","action","default"]),Vu.argOrder=["this","to","format","safe","action","default"],Vu.register();var X=Vu,fO=class fO extends g{constructor(e={}){super(e)}};fO.key="justifyDays",fO.argOrder=["this"],fO.register();var QT=fO,TO=class TO extends g{constructor(e={}){super(e)}};TO.key="justifyHours",TO.argOrder=["this"],TO.register();var ZT=TO,SO=class SO extends g{constructor(e={}){super(e)}};SO.key="justifyInterval",SO.argOrder=["this"],SO.register();var KT=SO,mO=class mO extends g{constructor(e={}){super(e)}};mO.key="try",mO.argOrder=["this"],mO.register();var sC=mO,Hu=class Hu extends g{constructor(e={}){super(e)}};Hu.key="castToStrType",Hu.requiredArgs=new Set(["this","to"]),Hu.availableArgs=new Set(["this","to"]),Hu.argOrder=["this","to"],Hu.register();var Jf=Hu,OO=class OO extends g{constructor(e={}){super(e)}};OO.key="checkJson",OO.argOrder=["this"],OO.register();var rC=OO,Jd=class Jd extends g{constructor(e={}){super(e)}};Jd.key="checkXml",Jd.availableArgs=new Set(["this","disableAutoConvert"]),Jd.argOrder=["this","disableAutoConvert"],Jd.register();var iC=Jd,Xd=class Xd extends G(q,g){constructor(e={}){super(e)}};Xd.key="collate",Xd.requiredArgs=new Set(["this","expression"]),Xd.availableArgs=new Set(["this","expression"]),Xd.register();var RA=Xd,RO=class RO extends g{constructor(e={}){super(e)}};RO.key="collation",RO.argOrder=["this"],RO.register();var nC=RO,Wu=class Wu extends g{constructor(e={}){super(e)}};Wu.key="ceil",Wu._sqlNames=["CEIL","CEILING"],Wu.availableArgs=new Set(["this","decimals","to"]),Wu.argOrder=["this","decimals","to"],Wu.register();var Oa=Wu,Lp=class Lp extends g{constructor(e={}){super(e)}};Lp.key="coalesce",Lp._sqlNames=["COALESCE","IFNULL","NVL"],Lp.isVarLenArgs=!0,Lp.availableArgs=new Set(["this","expressions","isNvl","isNull"]),Lp.argOrder=["this","expressions","isNvl","isNull"],Lp.register();var rt=Lp,Ha=class Ha extends g{constructor(e={}){super(e)}};Ha.key="chr",Ha._sqlNames=["CHR","CHAR"],Ha.isVarLenArgs=!0,Ha.requiredArgs=new Set(["expressions"]),Ha.availableArgs=new Set(["expressions","charset"]),Ha.argOrder=["expressions","charset"],Ha.register();var ql=Ha,wp=class wp extends g{constructor(e={}){super(e)}};wp.key="concat",wp.isVarLenArgs=!0,wp.requiredArgs=new Set(["expressions"]),wp.availableArgs=new Set(["expressions","safe","coalesce"]),wp.argOrder=["expressions","safe","coalesce"],wp.register();var Gt=wp,ju=class ju extends g{constructor(e={}){super(e)}};ju.key="contains",ju.requiredArgs=new Set(["this","expression"]),ju.availableArgs=new Set(["this","expression","jsonScope"]),ju.argOrder=["this","expression","jsonScope"],ju.register();var eS=ju,NO=class NO extends g{constructor(e={}){super(e)}};NO.key="connectByRoot",NO.argOrder=["this"],NO.register();var Ul=NO,IO=class IO extends g{constructor(e={}){super(e)}};IO.key="cbrt",IO.argOrder=["this"],IO.register();var vl=IO,Ju=class Ju extends g{constructor(e={}){super(e)}};Ju.key="currentAccount",Ju.requiredArgs=new Set,Ju.availableArgs=new Set,Ju.argOrder=["this"],Ju.register();var aC=Ju,Xu=class Xu extends g{constructor(e={}){super(e)}};Xu.key="currentAccountName",Xu.requiredArgs=new Set,Xu.availableArgs=new Set,Xu.argOrder=["this"],Xu.register();var oC=Xu,zu=class zu extends g{constructor(e={}){super(e)}};zu.key="currentAvailableRoles",zu.requiredArgs=new Set,zu.availableArgs=new Set,zu.argOrder=["this"],zu.register();var cC=zu,Qu=class Qu extends g{constructor(e={}){super(e)}};Qu.key="currentClient",Qu.requiredArgs=new Set,Qu.availableArgs=new Set,Qu.argOrder=["this"],Qu.register();var pC=Qu,Zu=class Zu extends g{constructor(e={}){super(e)}};Zu.key="currentIpAddress",Zu.requiredArgs=new Set,Zu.availableArgs=new Set,Zu.argOrder=["this"],Zu.register();var lC=Zu,Ku=class Ku extends g{constructor(e={}){super(e)}};Ku.key="currentDatabase",Ku.requiredArgs=new Set,Ku.availableArgs=new Set,Ku.argOrder=["this"],Ku.register();var uC=Ku,zd=class zd extends g{constructor(e={}){super(e)}};zd.key="currentSchemas",zd.requiredArgs=new Set,zd.argOrder=["this"],zd.register();var hC=zd,eh=class eh extends g{constructor(e={}){super(e)}};eh.key="currentSecondaryRoles",eh.requiredArgs=new Set,eh.availableArgs=new Set,eh.argOrder=["this"],eh.register();var gC=eh,th=class th extends g{constructor(e={}){super(e)}};th.key="currentSession",th.requiredArgs=new Set,th.availableArgs=new Set,th.argOrder=["this"],th.register();var EC=th,sh=class sh extends g{constructor(e={}){super(e)}};sh.key="currentStatement",sh.requiredArgs=new Set,sh.availableArgs=new Set,sh.argOrder=["this"],sh.register();var AC=sh,rh=class rh extends g{constructor(e={}){super(e)}};rh.key="currentVersion",rh.requiredArgs=new Set,rh.availableArgs=new Set,rh.argOrder=["this"],rh.register();var dC=rh,ih=class ih extends g{constructor(e={}){super(e)}};ih.key="currentTransaction",ih.requiredArgs=new Set,ih.availableArgs=new Set,ih.argOrder=["this"],ih.register();var xC=ih,nh=class nh extends g{constructor(e={}){super(e)}};nh.key="currentWarehouse",nh.requiredArgs=new Set,nh.availableArgs=new Set,nh.argOrder=["this"],nh.register();var fC=nh,Qd=class Qd extends g{constructor(e={}){super(e)}};Qd.key="currentDate",Qd.requiredArgs=new Set,Qd.argOrder=["this"],Qd.register();var $i=Qd,Zd=class Zd extends g{constructor(e={}){super(e)}};Zd.key="currentDatetime",Zd.requiredArgs=new Set,Zd.argOrder=["this"],Zd.register();var tS=Zd,Kd=class Kd extends g{constructor(e={}){super(e)}};Kd.key="currentTime",Kd.requiredArgs=new Set,Kd.argOrder=["this"],Kd.register();var Ra=Kd,ex=class ex extends g{constructor(e={}){super(e)}};ex.key="localtime",ex.requiredArgs=new Set,ex.argOrder=["this"],ex.register();var Fl=ex,tx=class tx extends g{constructor(e={}){super(e)}};tx.key="localtimestamp",tx.requiredArgs=new Set,tx.argOrder=["this"],tx.register();var Xf=tx,sx=class sx extends g{constructor(e={}){super(e)}};sx.key="systimestamp",sx.requiredArgs=new Set,sx.argOrder=["this"],sx.register();var TC=sx,Mp=class Mp extends g{constructor(e={}){super(e)}};Mp.key="currentTimestamp",Mp._sqlNames=["CURRENT_TIMESTAMP"],Mp.requiredArgs=new Set,Mp.availableArgs=new Set(["this","sysdate"]),Mp.argOrder=["this","sysdate"],Mp.register();var Na=Mp,ah=class ah extends g{constructor(e={}){super(e)}};ah.key="currentTimestampLtz",ah.requiredArgs=new Set,ah.availableArgs=new Set,ah.argOrder=["this"],ah.register();var sS=ah,oh=class oh extends g{constructor(e={}){super(e)}};oh.key="currentTimezone",oh.requiredArgs=new Set,oh.availableArgs=new Set,oh.argOrder=["this"],oh.register();var SC=oh,ch=class ch extends g{constructor(e={}){super(e)}};ch.key="currentOrganizationName",ch.requiredArgs=new Set,ch.availableArgs=new Set,ch.argOrder=["this"],ch.register();var mC=ch,rx=class rx extends g{constructor(e={}){super(e)}};rx.key="currentSchema",rx.requiredArgs=new Set,rx.argOrder=["this"],rx.register();var OC=rx,ix=class ix extends g{constructor(e={}){super(e)}};ix.key="currentUser",ix.requiredArgs=new Set,ix.argOrder=["this"],ix.register();var zf=ix,ph=class ph extends g{constructor(e={}){super(e)}};ph.key="currentCatalog",ph.requiredArgs=new Set,ph.availableArgs=new Set,ph.argOrder=["this"],ph.register();var Ql=ph,lh=class lh extends g{constructor(e={}){super(e)}};lh.key="currentRegion",lh.requiredArgs=new Set,lh.availableArgs=new Set,lh.argOrder=["this"],lh.register();var RC=lh,uh=class uh extends g{constructor(e={}){super(e)}};uh.key="currentRole",uh.requiredArgs=new Set,uh.availableArgs=new Set,uh.argOrder=["this"],uh.register();var Qf=uh,hh=class hh extends g{constructor(e={}){super(e)}};hh.key="currentRoleType",hh.requiredArgs=new Set,hh.availableArgs=new Set,hh.argOrder=["this"],hh.register();var NC=hh,gh=class gh extends g{constructor(e={}){super(e)}};gh.key="currentOrganizationUser",gh.requiredArgs=new Set,gh.availableArgs=new Set,gh.argOrder=["this"],gh.register();var IC=gh,Eh=class Eh extends g{constructor(e={}){super(e)}};Eh.key="sessionUser",Eh.requiredArgs=new Set,Eh.availableArgs=new Set,Eh.argOrder=["this"],Eh.register();var ST=Eh,Ah=class Ah extends g{constructor(e={}){super(e)}};Ah.key="utcDate",Ah.requiredArgs=new Set,Ah.availableArgs=new Set,Ah.argOrder=["this"],Ah.register();var mT=Ah,nx=class nx extends g{constructor(e={}){super(e)}};nx.key="utcTime",nx.requiredArgs=new Set,nx.argOrder=["this"],nx.register();var OT=nx,ax=class ax extends g{constructor(e={}){super(e)}};ax.key="utcTimestamp",ax.requiredArgs=new Set,ax.argOrder=["this"],ax.register();var RT=ax,dh=class dh extends G(g,Cs){constructor(e={}){super(K.initTimeArgs(e))}};dh.key="dateAdd",dh.argOrder=["this","expression","unit"],dh.requiredArgs=new Set(["this","expression"]),dh.availableArgs=new Set(["this","expression","unit"]),dh.register();var yt=dh,xh=class xh extends G(g,Cs){constructor(e={}){super(K.initTimeArgs(e))}};xh.key="dateBin",xh.argOrder=["this","expression","unit","zone","origin"],xh.requiredArgs=new Set(["this","expression"]),xh.availableArgs=new Set(["this","expression","unit","zone","origin"]),xh.register();var yC=xh,fh=class fh extends G(g,Cs){constructor(e={}){super(K.initTimeArgs(e))}};fh.key="dateSub",fh.argOrder=["this","expression","unit"],fh.requiredArgs=new Set(["this","expression"]),fh.availableArgs=new Set(["this","expression","unit"]),fh.register();var ts=fh,Dp=class Dp extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};Dp.key="dateDiff",Dp.argOrder=["this","expression","unit","zone","bigInt","datePartBoundary"],Dp._sqlNames=["DATEDIFF","DATE_DIFF"],Dp.requiredArgs=new Set(["this","expression"]),Dp.availableArgs=new Set(["this","expression","unit","zone","bigInt","datePartBoundary"]),Dp.register();var wa=Dp,kp=class kp extends g{constructor(e={}){let t=e.unabbreviate??!0,s=e.unit;if(K.isVarLike(s)&&!(s instanceof B&&s.parts.length!==1)){let r=s.name.toUpperCase();t&&r in K.UNABBREVIATED_UNIT_NAME&&(r=K.UNABBREVIATED_UNIT_NAME[r]),e.unit=R.string(r)}delete e.unabbreviate,super(e)}get unit(){return this.args.unit}};kp.key="dateTrunc",kp._sqlNames=["DATE_TRUNC"],kp.requiredArgs=new Set(["unit","this"]),kp.availableArgs=new Set(["unit","this","zone","inputTypePreserved"]),kp.argOrder=["unit","this","zone","inputTypePreserved"],kp.register();var bs=kp,ox=class ox extends g{constructor(e={}){super(e)}};ox.key="datetime",ox.availableArgs=new Set(["this","expression"]),ox.argOrder=["this","expression"],ox.register();var rS=ox,Th=class Th extends G(g,Cs){constructor(e={}){super(K.initTimeArgs(e))}};Th.key="datetimeAdd",Th.argOrder=["this","expression","unit"],Th.requiredArgs=new Set(["this","expression"]),Th.availableArgs=new Set(["this","expression","unit"]),Th.register();var fr=Th,Sh=class Sh extends G(g,Cs){constructor(e={}){super(K.initTimeArgs(e))}};Sh.key="datetimeSub",Sh.argOrder=["this","expression","unit"],Sh.requiredArgs=new Set(["this","expression"]),Sh.availableArgs=new Set(["this","expression","unit"]),Sh.register();var _i=Sh,mh=class mh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};mh.key="datetimeDiff",mh.argOrder=["this","expression","unit"],mh.requiredArgs=new Set(["this","expression"]),mh.availableArgs=new Set(["this","expression","unit"]),mh.register();var iS=mh,Oh=class Oh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};Oh.key="datetimeTrunc",Oh.argOrder=["this","unit","zone"],Oh.requiredArgs=new Set(["this","unit"]),Oh.availableArgs=new Set(["this","unit","zone"]),Oh.register();var CC=Oh,yO=class yO extends g{constructor(e={}){super(e)}};yO.key="dateFromUnixDate",yO.argOrder=["this"],yO.register();var PC=yO,cx=class cx extends g{constructor(e={}){super(e)}};cx.key="dayOfWeek",cx._sqlNames=["DAY_OF_WEEK","DAYOFWEEK"],cx.argOrder=["this"],cx.register();var nS=cx,CO=class CO extends g{constructor(e={}){super(e)}};CO.key="dayOfWeekIso",CO.argOrder=["this"],CO.register();var aS=CO,px=class px extends g{constructor(e={}){super(e)}};px.key="dayOfMonth",px.argOrder=["this"],px._sqlNames=["DAY_OF_MONTH","DAYOFMONTH"],px.register();var oS=px,lx=class lx extends g{constructor(e={}){super(e)}};lx.key="dayOfYear",lx.argOrder=["this"],lx._sqlNames=["DAY_OF_YEAR","DAYOFYEAR"],lx.register();var cS=lx,ux=class ux extends g{constructor(e={}){super(e)}};ux.key="dayname",ux.availableArgs=new Set(["this","abbreviated"]),ux.argOrder=["this","abbreviated"],ux.register();var pS=ux,PO=class PO extends g{constructor(e={}){super(e)}};PO.key="toDays",PO.argOrder=["this"],PO.register();var bC=PO,bO=class bO extends g{constructor(e={}){super(e)}};bO.key="weekOfYear",bO.argOrder=["this"],bO.register();var lS=bO,hx=class hx extends g{constructor(e={}){super(e)}};hx.key="yearOfWeek",hx.argOrder=["this"],hx._sqlNames=["YEAR_OF_WEEK","YEAROFWEEK"],hx.register();var uS=hx,gx=class gx extends g{constructor(e={}){super(e)}};gx.key="yearOfWeekIso",gx.argOrder=["this"],gx._sqlNames=["YEAR_OF_WEEK_ISO","YEAROFWEEKISO"],gx.register();var hS=gx,Rh=class Rh extends g{constructor(e={}){super(e)}};Rh.key="monthsBetween",Rh.requiredArgs=new Set(["this","expression"]),Rh.availableArgs=new Set(["this","expression","roundoff"]),Rh.argOrder=["this","expression","roundoff"],Rh.register();var LC=Rh,Nh=class Nh extends g{constructor(e={}){super(e)}};Nh.key="makeInterval",Nh.requiredArgs=new Set,Nh.availableArgs=new Set(["year","month","week","day","hour","minute","second"]),Nh.argOrder=["year","month","week","day","hour","minute","second"],Nh.register();var gS=Nh,_p=class _p extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};_p.key="lastDay",_p._sqlNames=["LAST_DAY","LAST_DAY_OF_MONTH"],_p.argOrder=["this","unit"],_p.requiredArgs=new Set(["this"]),_p.availableArgs=new Set(["this","unit"]),_p.register();var xp=_p,Ih=class Ih extends g{constructor(e={}){super(e)}};Ih.key="previousDay",Ih.requiredArgs=new Set(["this","expression"]),Ih.availableArgs=new Set(["this","expression"]),Ih.argOrder=["this","expression"],Ih.register();var wC=Ih,LO=class LO extends g{constructor(e={}){super(e)}};LO.key="laxBool",LO.argOrder=["this"],LO.register();var MC=LO,wO=class wO extends g{constructor(e={}){super(e)}};wO.key="laxFloat64",wO.argOrder=["this"],wO.register();var DC=wO,MO=class MO extends g{constructor(e={}){super(e)}};MO.key="laxInt64",MO.argOrder=["this"],MO.register();var kC=MO,DO=class DO extends g{constructor(e={}){super(e)}};DO.key="laxString",DO.argOrder=["this"],DO.register();var _C=DO,yh=class yh extends g{constructor(e={}){super(e)}};yh.key="extract",yh.requiredArgs=new Set(["this","expression"]),yh.availableArgs=new Set(["this","expression"]),yh.argOrder=["this","expression"],yh.register();var Gi=yh,Ch=class Ch extends G(g,$s){constructor(e={}){super(e)}};Ch.key="exists",Ch.argOrder=["this","expression"],Ch.requiredArgs=new Set(["this"]),Ch.availableArgs=new Set(["this","expression"]),Ch.register();var Pi=Ch,qp=class qp extends g{constructor(e={}){super(e)}};qp.key="elt",qp.isVarLenArgs=!0,qp.requiredArgs=new Set(["this","expressions"]),qp.availableArgs=new Set(["this","expressions"]),qp.argOrder=["this","expressions"],qp.register();var qC=qp,Ph=class Ph extends g{constructor(e={}){super(e)}};Ph.key="timestamp",Ph.requiredArgs=new Set,Ph.availableArgs=new Set(["this","zone","withTz"]),Ph.argOrder=["this","zone","withTz"],Ph.register();var Xl=Ph,bh=class bh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};bh.key="timestampAdd",bh.argOrder=["this","expression","unit"],bh.requiredArgs=new Set(["this","expression"]),bh.availableArgs=new Set(["this","expression","unit"]),bh.register();var ru=bh,Lh=class Lh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};Lh.key="timestampSub",Lh.argOrder=["this","expression","unit"],Lh.requiredArgs=new Set(["this","expression"]),Lh.availableArgs=new Set(["this","expression","unit"]),Lh.register();var ES=Lh,wh=class wh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};wh.key="timestampDiff",wh.argOrder=["this","expression","unit"],wh.requiredArgs=new Set(["this","expression"]),wh.availableArgs=new Set(["this","expression","unit"]),wh.register();var Zl=wh,Mh=class Mh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};Mh.key="timestampTrunc",Mh.argOrder=["this","unit","zone","inputTypePreserved"],Mh.requiredArgs=new Set(["this","unit"]),Mh.availableArgs=new Set(["this","unit","zone","inputTypePreserved"]),Mh.register();var ro=Mh,Dh=class Dh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};Dh.key="timeSlice",Dh.argOrder=["this","expression","unit","kind"],Dh.requiredArgs=new Set(["this","expression","unit"]),Dh.availableArgs=new Set(["this","expression","unit","kind"]),Dh.register();var UC=Dh,kh=class kh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};kh.key="timeAdd",kh.argOrder=["this","expression","unit"],kh.requiredArgs=new Set(["this","expression"]),kh.availableArgs=new Set(["this","expression","unit"]),kh.register();var iu=kh,_h=class _h extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};_h.key="timeSub",_h.argOrder=["this","expression","unit"],_h.requiredArgs=new Set(["this","expression"]),_h.availableArgs=new Set(["this","expression","unit"]),_h.register();var AS=_h,qh=class qh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};qh.key="timeDiff",qh.argOrder=["this","expression","unit"],qh.requiredArgs=new Set(["this","expression"]),qh.availableArgs=new Set(["this","expression","unit"]),qh.register();var dS=qh,Uh=class Uh extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};Uh.key="timeTrunc",Uh.argOrder=["this","unit","zone"],Uh.requiredArgs=new Set(["this","unit"]),Uh.availableArgs=new Set(["this","unit","zone"]),Uh.register();var vC=Uh,Up=class Up extends g{constructor(e={}){super(e)}};Up.key="dateFromParts",Up._sqlNames=["DATE_FROM_PARTS","DATEFROMPARTS"],Up.requiredArgs=new Set(["year"]),Up.availableArgs=new Set(["year","month","day","allowOverflow"]),Up.argOrder=["year","month","day","allowOverflow"],Up.register();var xS=Up,vh=class vh extends g{constructor(e={}){super(e)}};vh.key="timeFromParts",vh.requiredArgs=new Set(["hour","min","sec"]),vh.availableArgs=new Set(["hour","min","sec","nano","fractions","precision","overflow"]),vh.argOrder=["hour","min","sec","nano","fractions","precision","overflow"],vh.register();var FC=vh,kO=class kO extends g{constructor(e={}){super(e)}};kO.key="dateStrToDate",kO.argOrder=["this"],kO.register();var fS=kO,_O=class _O extends g{constructor(e={}){super(e)}};_O.key="dateToDateStr",_O.argOrder=["this"],_O.register();var TS=_O,qO=class qO extends g{constructor(e={}){super(e)}};qO.key="dateToDi",qO.argOrder=["this"],qO.register();var SS=qO,vp=class vp extends g{constructor(e={}){super(e)}};vp.key="date",vp.requiredArgs=new Set,vp.isVarLenArgs=!0,vp.availableArgs=new Set(["this","zone","expressions"]),vp.argOrder=["this","zone","expressions"],vp.register();var La=vp,UO=class UO extends g{constructor(e={}){super(e)}};UO.key="day",UO.argOrder=["this"],UO.register();var Vn=UO,Fh=class Fh extends g{constructor(e={}){super(e)}};Fh.key="decode",Fh.requiredArgs=new Set(["this","charset"]),Fh.availableArgs=new Set(["this","charset","replace"]),Fh.argOrder=["this","charset","replace"],Fh.register();var Zf=Fh,Fp=class Fp extends g{constructor(e={}){super(e)}};Fp.key="decodeCase",Fp.isVarLenArgs=!0,Fp.requiredArgs=new Set(["expressions"]),Fp.availableArgs=new Set(["expressions"]),Fp.argOrder=["expressions"],Fp.register();var Kf=Fp,Bh=class Bh extends g{constructor(e={}){super(e)}};Bh.key="decrypt",Bh.requiredArgs=new Set(["this","passphrase"]),Bh.availableArgs=new Set(["this","passphrase","aad","encryptionMethod","safe"]),Bh.argOrder=["this","passphrase","aad","encryptionMethod","safe"],Bh.register();var BC=Bh,$h=class $h extends g{constructor(e={}){super(e)}};$h.key="decryptRaw",$h.requiredArgs=new Set(["this","key","iv"]),$h.availableArgs=new Set(["this","key","iv","aad","encryptionMethod","aead","safe"]),$h.argOrder=["this","key","iv","aad","encryptionMethod","aead","safe"],$h.register();var $C=$h,vO=class vO extends g{constructor(e={}){super(e)}};vO.key="diToDate",vO.argOrder=["this"],vO.register();var mS=vO,Gh=class Gh extends g{constructor(e={}){super(e)}};Gh.key="encode",Gh.requiredArgs=new Set(["this","charset"]),Gh.availableArgs=new Set(["this","charset"]),Gh.argOrder=["this","charset"],Gh.register();var GC=Gh,Yh=class Yh extends g{constructor(e={}){super(e)}};Yh.key="encrypt",Yh.requiredArgs=new Set(["this","passphrase"]),Yh.availableArgs=new Set(["this","passphrase","aad","encryptionMethod"]),Yh.argOrder=["this","passphrase","aad","encryptionMethod"],Yh.register();var YC=Yh,Vh=class Vh extends g{constructor(e={}){super(e)}};Vh.key="encryptRaw",Vh.requiredArgs=new Set(["this","key","iv"]),Vh.availableArgs=new Set(["this","key","iv","aad","encryptionMethod"]),Vh.argOrder=["this","key","iv","aad","encryptionMethod"],Vh.register();var VC=Vh,Hh=class Hh extends g{constructor(e={}){super(e)}};Hh.key="equalNull",Hh.requiredArgs=new Set(["this","expression"]),Hh.availableArgs=new Set(["this","expression"]),Hh.argOrder=["this","expression"],Hh.register();var HC=Hh,FO=class FO extends g{constructor(e={}){super(e)}};FO.key="exp",FO.argOrder=["this"],FO.register();var OS=FO,BO=class BO extends g{constructor(e={}){super(e)}};BO.key="factorial",BO.argOrder=["this"],BO.register();var WC=BO,Bp=class Bp extends G(g,Nt){constructor(e={}){super(e)}};Bp.key="explode",Bp.argOrder=["this","expressions"],Bp.isVarLenArgs=!0,Bp.requiredArgs=new Set(["this"]),Bp.availableArgs=new Set(["this","expressions"]),Bp.register();var rs=Bp,$O=class $O extends g{constructor(e={}){super(e)}};$O.key="inline",$O.argOrder=["this"],$O.register();var ET=$O,Wh=class Wh extends G(g,Nt){constructor(e={}){super(e)}get selects(){let e=super.selects,t=this.args.offset;if(t){let s=t===!0?Z("offset"):t;return[...e,s]}return e}};Wh.key="unnest",Wh.argOrder=["expressions","alias","offset","explodeArray"],Wh.requiredArgs=new Set(["expressions"]),Wh.availableArgs=new Set(["expressions","alias","offset","explodeArray"]),Wh.register();var ge=Wh,Ex=class Ex extends g{constructor(e={}){super(e)}};Ex.key="floor",Ex.availableArgs=new Set(["this","decimals","to"]),Ex.argOrder=["this","decimals","to"],Ex.register();var Bl=Ex,GO=class GO extends g{constructor(e={}){super(e)}};GO.key="fromBase32",GO.argOrder=["this"],GO.register();var RS=GO,YO=class YO extends g{constructor(e={}){super(e)}};YO.key="fromBase64",YO.argOrder=["this"],YO.register();var NS=YO,VO=class VO extends g{constructor(e={}){super(e)}};VO.key="toBase32",VO.argOrder=["this"],VO.register();var IS=VO,HO=class HO extends g{constructor(e={}){super(e)}};HO.key="toBase64",HO.argOrder=["this"],HO.register();var yS=HO,Ax=class Ax extends g{constructor(e={}){super(e)}};Ax.key="toBinary",Ax.availableArgs=new Set(["this","format","safe"]),Ax.argOrder=["this","format","safe"],Ax.register();var jC=Ax,dx=class dx extends g{constructor(e={}){super(e)}};dx.key="base64DecodeBinary",dx.availableArgs=new Set(["this","alphabet"]),dx.argOrder=["this","alphabet"],dx.register();var JC=dx,xx=class xx extends g{constructor(e={}){super(e)}};xx.key="base64DecodeString",xx.availableArgs=new Set(["this","alphabet"]),xx.argOrder=["this","alphabet"],xx.register();var XC=xx,fx=class fx extends g{constructor(e={}){super(e)}};fx.key="base64Encode",fx.availableArgs=new Set(["this","maxLineLength","alphabet"]),fx.argOrder=["this","maxLineLength","alphabet"],fx.register();var zC=fx,Tx=class Tx extends g{constructor(e={}){super(e)}};Tx.key="tryBase64DecodeBinary",Tx.availableArgs=new Set(["this","alphabet"]),Tx.argOrder=["this","alphabet"],Tx.register();var QC=Tx,Sx=class Sx extends g{constructor(e={}){super(e)}};Sx.key="tryBase64DecodeString",Sx.availableArgs=new Set(["this","alphabet"]),Sx.argOrder=["this","alphabet"],Sx.register();var ZC=Sx,WO=class WO extends g{constructor(e={}){super(e)}};WO.key="tryHexDecodeBinary",WO.argOrder=["this"],WO.register();var KC=WO,jO=class jO extends g{constructor(e={}){super(e)}};jO.key="tryHexDecodeString",jO.argOrder=["this"],jO.register();var eP=jO,mx=class mx extends g{constructor(e={}){super(e)}};mx.key="fromIso8601Timestamp",mx.argOrder=["this"],mx._sqlNames=["FROM_ISO8601_TIMESTAMP"],mx.register();var tP=mx,jh=class jh extends g{constructor(e={}){super(e)}};jh.key="gapFill",jh.requiredArgs=new Set(["this","tsColumn","bucketWidth"]),jh.availableArgs=new Set(["this","tsColumn","bucketWidth","partitioningColumns","valueColumns","origin","ignoreNulls"]),jh.argOrder=["tsColumn","bucketWidth","partitioningColumns","valueColumns","origin","ignoreNulls"],jh.register();var eT=jh,Jh=class Jh extends g{constructor(e={}){super(e)}};Jh.key="generateDateArray",Jh.requiredArgs=new Set(["start","end"]),Jh.availableArgs=new Set(["start","end","step"]),Jh.argOrder=["start","end","step"],Jh.register();var Ia=Jh,Xh=class Xh extends g{constructor(e={}){super(e)}};Xh.key="generateTimestampArray",Xh.requiredArgs=new Set(["start","end","step"]),Xh.availableArgs=new Set(["start","end","step"]),Xh.argOrder=["start","end","step"],Xh.register();var CS=Xh,zh=class zh extends g{constructor(e={}){super(e)}};zh.key="getExtract",zh.requiredArgs=new Set(["this","expression"]),zh.availableArgs=new Set(["this","expression"]),zh.argOrder=["this","expression"],zh.register();var sP=zh,Qh=class Qh extends g{constructor(e={}){super(e)}};Qh.key="getbit",Qh.requiredArgs=new Set(["this","expression"]),Qh.availableArgs=new Set(["this","expression","zeroIsMsb"]),Qh.argOrder=["this","expression","zeroIsMsb"],Qh.register();var PS=Qh,$p=class $p extends g{constructor(e={}){super(e)}};$p.key="greatest",$p.isVarLenArgs=!0,$p.requiredArgs=new Set(["this","ignoreNulls"]),$p.availableArgs=new Set(["this","expressions","ignoreNulls"]),$p.argOrder=["this","expressions","ignoreNulls"],$p.register();var ya=$p,JO=class JO extends g{constructor(e={}){super(e)}};JO.key="hex",JO.argOrder=["this"],JO.register();var ap=JO,XO=class XO extends g{constructor(e={}){super(e)}};XO.key="hexDecodeString",XO.argOrder=["this"],XO.register();var rP=XO,Ox=class Ox extends g{constructor(e={}){super(e)}};Ox.key="hexEncode",Ox.availableArgs=new Set(["this","case"]),Ox.argOrder=["this","case"],Ox.register();var iP=Ox,zO=class zO extends g{constructor(e={}){super(e)}};zO.key="hour",zO.argOrder=["this"],zO.register();var bS=zO,QO=class QO extends g{constructor(e={}){super(e)}};QO.key="minute",QO.argOrder=["this"],QO.register();var nP=QO,ZO=class ZO extends g{constructor(e={}){super(e)}};ZO.key="second",ZO.argOrder=["this"],ZO.register();var aP=ZO,Rx=class Rx extends g{constructor(e={}){super(e)}};Rx.key="compress",Rx.availableArgs=new Set(["this","method"]),Rx.argOrder=["this","method"],Rx.register();var oP=Rx,Zh=class Zh extends g{constructor(e={}){super(e)}};Zh.key="decompressBinary",Zh.requiredArgs=new Set(["this","method"]),Zh.availableArgs=new Set(["this","method"]),Zh.argOrder=["this","method"],Zh.register();var cP=Zh,Kh=class Kh extends g{constructor(e={}){super(e)}};Kh.key="decompressString",Kh.requiredArgs=new Set(["this","method"]),Kh.availableArgs=new Set(["this","method"]),Kh.argOrder=["this","method"],Kh.register();var pP=Kh,Gp=class Gp extends g{constructor(e={}){super(e)}};Gp.key="if",Gp._sqlNames=["IF","IIF"],Gp.requiredArgs=new Set(["this","true"]),Gp.availableArgs=new Set(["this","true","false"]),Gp.argOrder=["this","true","false"],Gp.register();var le=Gp,eg=class eg extends g{constructor(e={}){super(e)}};eg.key="nullif",eg.requiredArgs=new Set(["this","expression"]),eg.availableArgs=new Set(["this","expression"]),eg.argOrder=["this","expression"],eg.register();var Kl=eg,Nx=class Nx extends g{constructor(e={}){super(e)}};Nx.key="initcap",Nx.availableArgs=new Set(["this","expression"]),Nx.argOrder=["this","expression"],Nx.register();var $l=Nx,KO=class KO extends g{constructor(e={}){super(e)}};KO.key="isAscii",KO.argOrder=["this"],KO.register();var lP=KO,Ix=class Ix extends g{constructor(e={}){super(e)}};Ix.key="isNan",Ix.argOrder=["this"],Ix._sqlNames=["IS_NAN","ISNAN"],Ix.register();var LS=Ix,eR=class eR extends g{constructor(e={}){super(e)}};eR.key="int64",eR.argOrder=["this"],eR.register();var eu=eR,yx=class yx extends g{constructor(e={}){super(e)}};yx.key="isInf",yx.argOrder=["this"],yx._sqlNames=["IS_INF","ISINF"],yx.register();var wS=yx,tR=class tR extends g{constructor(e={}){super(e)}};tR.key="isNullValue",tR.argOrder=["this"],tR.register();var uP=tR,sR=class sR extends g{constructor(e={}){super(e)}};sR.key="isArray",sR.argOrder=["this"],sR.register();var hP=sR,tg=class tg extends g{constructor(e={}){super(e)}};tg.key="format",tg.isVarLenArgs=!0,tg.availableArgs=new Set(["this","expressions"]),tg.argOrder=["this","expressions"],tg.register();var gP=tg,sg=class sg extends g{constructor(e={}){super(e)}};sg.key="jsonKeys",sg.isVarLenArgs=!0,sg.availableArgs=new Set(["this","expression","expressions"]),sg.argOrder=["this","expression","expressions"],sg.register();var tT=sg,Cx=class Cx extends g{constructor(e={}){super(e)}};Cx.key="jsonKeysAtDepth",Cx.availableArgs=new Set(["this","expression","mode"]),Cx.argOrder=["this","expression","mode"],Cx.register();var EP=Cx,Px=class Px extends g{constructor(e={}){super(e)}};Px.key="jsonObject",Px.availableArgs=new Set(["expressions","nullHandling","uniqueKeys","returnType","encoding"]),Px.argOrder=["nullHandling","uniqueKeys","returnType","encoding"],Px.register();var Gl=Px,bx=class bx extends g{constructor(e={}){super(e)}};bx.key="jsonArray",bx.availableArgs=new Set(["expressions","nullHandling","returnType","strict"]),bx.argOrder=["nullHandling","returnType","strict"],bx.register();var AP=bx,rg=class rg extends g{constructor(e={}){super(e)}};rg.key="jsonExists",rg.requiredArgs=new Set(["this","path"]),rg.availableArgs=new Set(["this","path","passing","onCondition","fromDcolonqmark"]),rg.argOrder=["path","passing","onCondition","fromDcolonqmark"],rg.register();var dP=rg,Wa=class Wa extends g{constructor(e={}){super(e)}};Wa.key="jsonSet",Wa.isVarLenArgs=!0,Wa._sqlNames=["JSON_SET"],Wa.requiredArgs=new Set(["this","expressions"]),Wa.availableArgs=new Set(["this","expressions"]),Wa.argOrder=["this","expressions"],Wa.register();var xP=Wa,ig=class ig extends g{constructor(e={}){super(e)}};ig.key="jsonStripNulls",ig._sqlNames=["JSON_STRIP_NULLS"],ig.availableArgs=new Set(["this","expression","includeArrays","removeEmpty"]),ig.argOrder=["this","expression","includeArrays","removeEmpty"],ig.register();var fP=ig,Lx=class Lx extends g{constructor(e={}){super(e)}};Lx.key="jsonValueArray",Lx.availableArgs=new Set(["this","expression"]),Lx.argOrder=["this","expression"],Lx.register();var TP=Lx,ja=class ja extends g{constructor(e={}){super(e)}};ja.key="jsonRemove",ja.isVarLenArgs=!0,ja._sqlNames=["JSON_REMOVE"],ja.requiredArgs=new Set(["this","expressions"]),ja.availableArgs=new Set(["this","expressions"]),ja.argOrder=["this","expressions"],ja.register();var SP=ja,ng=class ng extends g{constructor(e={}){super(e)}};ng.key="jsonTable",ng.requiredArgs=new Set(["this","schema"]),ng.availableArgs=new Set(["this","schema","path","errorHandling","emptyHandling"]),ng.argOrder=["this","schema","path","errorHandling","emptyHandling"],ng.register();var sT=ng,ag=class ag extends g{constructor(e={}){super(e)}};ag.key="jsontype",ag._sqlNames=["JSON_TYPE"],ag.availableArgs=new Set(["this","expression"]),ag.argOrder=["this","expression"],ag.register();var mP=ag,og=class og extends g{constructor(e={}){super(e)}};og.key="objectInsert",og.requiredArgs=new Set(["this","key","value"]),og.availableArgs=new Set(["this","key","value","updateFlag"]),og.argOrder=["this","key","value","updateFlag"],og.register();var OP=og,wx=class wx extends g{constructor(e={}){super(e)}};wx.key="openJson",wx.availableArgs=new Set(["this","path","expressions"]),wx.argOrder=["this","path","expressions"],wx.register();var rT=wx,Ca=class extends G(q,g){constructor(e={}){super(e)}};Ca.key="jsonbContains",Ca._sqlNames=["JSONB_CONTAINS"],Ca.requiredArgs=new Set(["this","expression"]),Ca.availableArgs=new Set(["this","expression"]);var qn=class extends G(q,g){constructor(e={}){super(e)}};qn.key="jsonbContainsAnyTopKeys",qn.requiredArgs=new Set(["this","expression"]),qn.availableArgs=new Set(["this","expression"]);var Un=class extends G(q,g){constructor(e={}){super(e)}};Un.key="jsonbContainsAllTopKeys",Un.requiredArgs=new Set(["this","expression"]),Un.availableArgs=new Set(["this","expression"]);var Yp=class Yp extends g{constructor(e={}){super(e)}};Yp.key="jsonbExists",Yp._sqlNames=["JSONB_EXISTS"],Yp.requiredArgs=new Set(["this","path"]),Yp.availableArgs=new Set(["this","path"]),Yp.argOrder=["this","path"],Yp.register();var RP=Yp,vn=class extends G(q,g){constructor(e={}){super(e)}};vn.key="jsonbDeleteAtPath",vn.requiredArgs=new Set(["this","expression"]),vn.availableArgs=new Set(["this","expression"]);var Vp=class Vp extends G(q,g){constructor(e={}){super(e)}get outputName(){return this.args.expressions?"":this.args.expression?.outputName??""}};Vp.key="jsonExtract",Vp.isVarLenArgs=!0,Vp._sqlNames=["JSON_EXTRACT"],Vp.requiredArgs=new Set(["this","expression"]),Vp.availableArgs=new Set(["this","expression","onlyJsonTypes","expressions","variantExtract","jsonQuery","option","quote","onCondition","requiresJson"]),Vp.register();var js=Vp,cg=class cg extends g{constructor(e={}){super(e)}};cg.key="jsonExtractArray",cg._sqlNames=["JSON_EXTRACT_ARRAY"],cg.availableArgs=new Set(["this","expression"]),cg.argOrder=["this","expression"],cg.register();var NP=cg,Hp=class Hp extends G(q,g){constructor(e={}){super(e)}get outputName(){return this.args.expression?.outputName??""}};Hp.key="jsonExtractScalar",Hp.isVarLenArgs=!0,Hp._sqlNames=["JSON_EXTRACT_SCALAR"],Hp.requiredArgs=new Set(["this","expression"]),Hp.availableArgs=new Set(["this","expression","onlyJsonTypes","expressions","jsonType","scalarOnly"]),Hp.register();var ao=Hp,pg=class pg extends G(q,g){constructor(e={}){super(e)}};pg.key="jsonbExtract",pg._sqlNames=["JSONB_EXTRACT"],pg.requiredArgs=new Set(["this","expression"]),pg.availableArgs=new Set(["this","expression"]),pg.register();var Yl=pg,lg=class lg extends G(q,g){constructor(e={}){super(e)}};lg.key="jsonbExtractScalar",lg._sqlNames=["JSONB_EXTRACT_SCALAR"],lg.requiredArgs=new Set(["this","expression"]),lg.availableArgs=new Set(["this","expression","jsonType"]),lg.register();var iT=lg,ug=class ug extends g{constructor(e={}){super(e)}};ug.key="jsonFormat",ug._sqlNames=["JSON_FORMAT"],ug.availableArgs=new Set(["this","options","isJson","toJson"]),ug.argOrder=["this","options","isJson","toJson"],ug.register();var IP=ug,Ja=class Ja extends g{constructor(e={}){super(e)}};Ja.key="jsonArrayAppend",Ja.isVarLenArgs=!0,Ja._sqlNames=["JSON_ARRAY_APPEND"],Ja.requiredArgs=new Set(["this","expressions"]),Ja.availableArgs=new Set(["this","expressions"]),Ja.argOrder=["this","expressions"],Ja.register();var yP=Ja,pu=class extends G(q,Ne,g){constructor(e={}){super(e)}};pu.key="jsonArrayContains",pu._sqlNames=["JSON_ARRAY_CONTAINS"],pu.requiredArgs=new Set(["this","expression"]),pu.availableArgs=new Set(["this","expression","jsonType"]);var Xa=class Xa extends g{constructor(e={}){super(e)}};Xa.key="jsonArrayInsert",Xa.isVarLenArgs=!0,Xa._sqlNames=["JSON_ARRAY_INSERT"],Xa.requiredArgs=new Set(["this","expressions"]),Xa.availableArgs=new Set(["this","expressions"]),Xa.argOrder=["this","expressions"],Xa.register();var CP=Xa,rR=class rR extends g{constructor(e={}){super(e)}};rR.key="parseBignumeric",rR.argOrder=["this"],rR.register();var PP=rR,iR=class iR extends g{constructor(e={}){super(e)}};iR.key="parseNumeric",iR.argOrder=["this"],iR.register();var bP=iR,hg=class hg extends g{constructor(e={}){super(e)}};hg.key="parseJson",hg._sqlNames=["PARSE_JSON","JSON_PARSE"],hg.availableArgs=new Set(["this","expression","safe"]),hg.argOrder=["this","expression","safe"],hg.register();var Pa=hg,Mx=class Mx extends g{constructor(e={}){super(e)}};Mx.key="parseUrl",Mx.availableArgs=new Set(["this","partToExtract","key","permissive"]),Mx.argOrder=["this","partToExtract","key","permissive"],Mx.register();var LP=Mx,gg=class gg extends g{constructor(e={}){super(e)}};gg.key="parseIp",gg.requiredArgs=new Set(["this","type"]),gg.availableArgs=new Set(["this","type","permissive"]),gg.argOrder=["this","type","permissive"],gg.register();var wP=gg,Eg=class Eg extends g{constructor(e={}){super(e)}};Eg.key="parseTime",Eg.requiredArgs=new Set(["this","format"]),Eg.availableArgs=new Set(["this","format"]),Eg.argOrder=["this","format"],Eg.register();var MP=Eg,Dx=class Dx extends g{constructor(e={}){super(e)}};Dx.key="parseDatetime",Dx.availableArgs=new Set(["this","format","zone"]),Dx.argOrder=["this","format","zone"],Dx.register();var DP=Dx,Wp=class Wp extends g{constructor(e={}){super(e)}};Wp.key="least",Wp.isVarLenArgs=!0,Wp.requiredArgs=new Set(["this","ignoreNulls"]),Wp.availableArgs=new Set(["this","expressions","ignoreNulls"]),Wp.argOrder=["this","expressions","ignoreNulls"],Wp.register();var Vl=Wp,Ag=class Ag extends g{constructor(e={}){super(e)}};Ag.key="left",Ag.requiredArgs=new Set(["this","expression"]),Ag.availableArgs=new Set(["this","expression"]),Ag.argOrder=["this","expression"],Ag.register();var kP=Ag,dg=class dg extends g{constructor(e={}){super(e)}};dg.key="right",dg.requiredArgs=new Set(["this","expression"]),dg.availableArgs=new Set(["this","expression"]),dg.argOrder=["this","expression"],dg.register();var _P=dg,nR=class nR extends g{constructor(e={}){super(e)}};nR.key="reverse",nR.argOrder=["this"],nR.register();var qP=nR,xg=class xg extends g{constructor(e={}){super(e)}};xg.key="length",xg._sqlNames=["LENGTH","LEN","CHAR_LENGTH","CHARACTER_LENGTH"],xg.availableArgs=new Set(["this","binary","encoding"]),xg.argOrder=["this","binary","encoding"],xg.register();var nu=xg,aR=class aR extends g{constructor(e={}){super(e)}};aR.key="rtrimmedLength",aR.argOrder=["this"],aR.register();var UP=aR,oR=class oR extends g{constructor(e={}){super(e)}};oR.key="bitLength",oR.argOrder=["this"],oR.register();var MS=oR,kx=class kx extends g{constructor(e={}){super(e)}};kx.key="levenshtein",kx.availableArgs=new Set(["this","expression","insCost","delCost","subCost","maxDist"]),kx.argOrder=["this","expression","insCost","delCost","subCost","maxDist"],kx.register();var DS=kx,cR=class cR extends g{constructor(e={}){super(e)}};cR.key="ln",cR.argOrder=["this"],cR.register();var Hl=cR,_x=class _x extends g{constructor(e={}){super(e)}};_x.key="log",_x.availableArgs=new Set(["this","expression"]),_x.argOrder=["this","expression"],_x.register();var Yi=_x,qx=class qx extends g{constructor(e={}){super(e)}};qx.key="lower",qx.argOrder=["this"],qx._sqlNames=["LOWER","LCASE"],qx.register();var Fn=qx,fg=class fg extends g{constructor(e={}){super(e)}get keys(){return this.args.keys?.args?.expressions||[]}get values(){return this.args.values?.args?.expressions||[]}};fg.key="map",fg.requiredArgs=new Set,fg.availableArgs=new Set(["keys","values"]),fg.argOrder=["keys","values"],fg.register();var io=fg,pR=class pR extends g{constructor(e={}){super(e)}};pR.key="toMap",pR.argOrder=["this"],pR.register();var tu=pR,lR=class lR extends g{constructor(e={}){super(e)}};lR.key="mapFromEntries",lR.argOrder=["this"],lR.register();var vP=lR,Tg=class Tg extends g{constructor(e={}){super(e)}};Tg.key="mapCat",Tg.requiredArgs=new Set(["this","expression"]),Tg.availableArgs=new Set(["this","expression"]),Tg.argOrder=["this","expression"],Tg.register();var FP=Tg,Sg=class Sg extends g{constructor(e={}){super(e)}};Sg.key="mapContainsKey",Sg.requiredArgs=new Set(["this","key"]),Sg.availableArgs=new Set(["this","key"]),Sg.argOrder=["this","key"],Sg.register();var BP=Sg,jp=class jp extends g{constructor(e={}){super(e)}};jp.key="mapDelete",jp.isVarLenArgs=!0,jp.requiredArgs=new Set(["this","expressions"]),jp.availableArgs=new Set(["this","expressions"]),jp.argOrder=["this","expressions"],jp.register();var $P=jp,mg=class mg extends g{constructor(e={}){super(e)}};mg.key="mapInsert",mg.requiredArgs=new Set(["this","value"]),mg.availableArgs=new Set(["this","key","value","updateFlag"]),mg.argOrder=["this","key","value","updateFlag"],mg.register();var GP=mg,uR=class uR extends g{constructor(e={}){super(e)}};uR.key="mapkeys",uR.argOrder=["this"],uR.register();var YP=uR,Jp=class Jp extends g{constructor(e={}){super(e)}};Jp.key="mapPick",Jp.isVarLenArgs=!0,Jp.requiredArgs=new Set(["this","expressions"]),Jp.availableArgs=new Set(["this","expressions"]),Jp.argOrder=["this","expressions"],Jp.register();var VP=Jp,hR=class hR extends g{constructor(e={}){super(e)}};hR.key="mapSize",hR.argOrder=["this"],hR.register();var HP=hR,gR=class gR extends g{constructor(e={}){super(e)}};gR.key="starMap",gR.argOrder=["this"],gR.register();var nT=gR,Xp=class Xp extends g{constructor(e={}){super(e)}get keys(){return this.args.keys?.args.expressions??[]}get values(){return this.args.values?.args.expressions??[]}};Xp.key="varMap",Xp.isVarLenArgs=!0,Xp.requiredArgs=new Set(["keys","values"]),Xp.availableArgs=new Set(["keys","values"]),Xp.argOrder=["keys","values"],Xp.register();var Ys=Xp,Og=class Og extends g{constructor(e={}){super(e)}};Og.key="matchAgainst",Og.requiredArgs=new Set(["this","expressions"]),Og.availableArgs=new Set(["this","expressions","modifier"]),Og.argOrder=["this","expressions","modifier"],Og.register();var aT=Og,Ux=class Ux extends g{constructor(e={}){super(e)}};Ux.key="md5",Ux._sqlNames=["MD5"],Ux.argOrder=["this"],Ux.register();var kS=Ux,zp=class zp extends g{constructor(e={}){super(e)}};zp.key="md5Digest",zp.isVarLenArgs=!0,zp._sqlNames=["MD5_DIGEST"],zp.availableArgs=new Set(["this","expressions"]),zp.argOrder=["this","expressions"],zp.register();var WP=zp,ER=class ER extends g{constructor(e={}){super(e)}};ER.key="md5NumberLower64",ER.argOrder=["this"],ER.register();var jP=ER,AR=class AR extends g{constructor(e={}){super(e)}};AR.key="md5NumberUpper64",AR.argOrder=["this"],AR.register();var JP=AR,dR=class dR extends g{constructor(e={}){super(e)}};dR.key="month",dR.argOrder=["this"],dR.register();var _S=dR,vx=class vx extends g{constructor(e={}){super(e)}};vx.key="monthname",vx.availableArgs=new Set(["this","abbreviated"]),vx.argOrder=["this","abbreviated"],vx.register();var XP=vx,Rg=class Rg extends g{constructor(e={}){super(e)}};Rg.key="addMonths",Rg.requiredArgs=new Set(["this","expression"]),Rg.availableArgs=new Set(["this","expression","preserveEndOfMonth"]),Rg.argOrder=["this","expression","preserveEndOfMonth"],Rg.register();var zP=Rg,Ng=class Ng extends g{constructor(e={}){super(e)}};Ng.key="nvl2",Ng.requiredArgs=new Set(["this","true"]),Ng.availableArgs=new Set(["this","true","false"]),Ng.argOrder=["this","true","false"],Ng.register();var QP=Ng,Fx=class Fx extends g{constructor(e={}){super(e)}};Fx.key="normalize",Fx.availableArgs=new Set(["this","form","isCasefold"]),Fx.argOrder=["this","form","isCasefold"],Fx.register();var oT=Fx,Ig=class Ig extends g{constructor(e={}){super(e)}};Ig.key="normal",Ig.requiredArgs=new Set(["this","stddev","gen"]),Ig.availableArgs=new Set(["this","stddev","gen"]),Ig.argOrder=["this","stddev","gen"],Ig.register();var ZP=Ig,xR=class xR extends g{constructor(e={}){super(e)}};xR.key="netFunc",xR.argOrder=["this"],xR.register();var NT=xR,fR=class fR extends g{constructor(e={}){super(e)}};fR.key="host",fR.argOrder=["this"],fR.register();var KP=fR,TR=class TR extends g{constructor(e={}){super(e)}};TR.key="regDomain",TR.argOrder=["this"],TR.register();var eb=TR,yg=class yg extends g{constructor(e={}){super(e)}};yg.key="overlay",yg.requiredArgs=new Set(["this","expression","from"]),yg.availableArgs=new Set(["this","expression","from","for"]),yg.argOrder=["this","expression","from","for"],yg.register();var cT=yg,Cg=class Cg extends g{constructor(e={}){super(e)}};Cg.key="predict",Cg.requiredArgs=new Set(["this","expression"]),Cg.availableArgs=new Set(["this","expression","paramsStruct"]),Cg.argOrder=["this","expression","paramsStruct"],Cg.register();var tb=Cg,Pg=class Pg extends g{constructor(e={}){super(e)}};Pg.key="mlTranslate",Pg.requiredArgs=new Set(["this","expression","paramsStruct"]),Pg.availableArgs=new Set(["this","expression","paramsStruct"]),Pg.argOrder=["this","expression","paramsStruct"],Pg.register();var sb=Pg,Bx=class Bx extends g{constructor(e={}){super(e)}};Bx.key="featuresAtTime",Bx.availableArgs=new Set(["this","time","numRows","ignoreFeatureNulls"]),Bx.argOrder=["this","time","numRows","ignoreFeatureNulls"],Bx.register();var rb=Bx,bg=class bg extends g{constructor(e={}){super(e)}};bg.key="generateEmbedding",bg.requiredArgs=new Set(["this","expression"]),bg.availableArgs=new Set(["this","expression","paramsStruct","isText"]),bg.argOrder=["this","expression","paramsStruct","isText"],bg.register();var ib=bg,$x=class $x extends g{constructor(e={}){super(e)}};$x.key="mlForecast",$x.availableArgs=new Set(["this","expression","paramsStruct"]),$x.argOrder=["this","expression","paramsStruct"],$x.register();var nb=$x,Lg=class Lg extends g{constructor(e={}){super(e)}};Lg.key="vectorSearch",Lg.requiredArgs=new Set(["this","columnToSearch","queryTable"]),Lg.availableArgs=new Set(["this","columnToSearch","queryTable","queryColumnToSearch","topK","distanceType","options"]),Lg.argOrder=["columnToSearch","queryTable","queryColumnToSearch","topK","distanceType","options"],Lg.register();var ab=Lg,wg=class wg extends g{constructor(e={}){super(e)}};wg.key="pi",wg.requiredArgs=new Set,wg.availableArgs=new Set,wg.argOrder=["this"],wg.register();var qS=wg,Qp=class Qp extends G(q,g){constructor(e={}){super(e)}};Qp.key="pow",Qp._sqlNames=["POWER","POW"],Qp.argOrder=["this","expression"],Qp.requiredArgs=new Set(["this","expression"]),Qp.availableArgs=new Set(["this","expression"]),Qp.register();var au=Qp,Mg=class Mg extends g{constructor(e={}){super(e)}};Mg.key="approxPercentileEstimate",Mg.requiredArgs=new Set(["this","percentile"]),Mg.availableArgs=new Set(["this","percentile"]),Mg.argOrder=["this","percentile"],Mg.register();var ob=Mg,SR=class SR extends g{constructor(e={}){super(e)}};SR.key="quarter",SR.argOrder=["this"],SR.register();var US=SR,Dg=class Dg extends g{constructor(e={}){super(e)}};Dg.key="rand",Dg._sqlNames=["RAND","RANDOM"],Dg.availableArgs=new Set(["this","lower","upper"]),Dg.argOrder=["this","lower","upper"],Dg.register();var fl=Dg,Gx=class Gx extends g{constructor(e={}){super(e)}};Gx.key="randn",Gx.requiredArgs=new Set,Gx.argOrder=["this"],Gx.register();var Df=Gx,Yx=class Yx extends g{constructor(e={}){super(e)}};Yx.key="randstr",Yx.availableArgs=new Set(["this","generator"]),Yx.argOrder=["this","generator"],Yx.register();var cb=Yx,kg=class kg extends g{constructor(e={}){super(e)}};kg.key="rangeN",kg.requiredArgs=new Set(["this","expressions"]),kg.availableArgs=new Set(["this","expressions","each"]),kg.argOrder=["this","expressions","each"],kg.register();var pb=kg,_g=class _g extends g{constructor(e={}){super(e)}};_g.key="rangeBucket",_g.requiredArgs=new Set(["this","expression"]),_g.availableArgs=new Set(["this","expression"]),_g.argOrder=["this","expression"],_g.register();var lb=_g,Zp=class Zp extends g{constructor(e={}){super(e)}};Zp.key="readCsv",Zp.isVarLenArgs=!0,Zp._sqlNames=["READ_CSV"],Zp.availableArgs=new Set(["this","expressions"]),Zp.argOrder=["this","expressions"],Zp.register();var ub=Zp,Kp=class Kp extends g{constructor(e={}){super(e)}};Kp.key="readParquet",Kp.isVarLenArgs=!0,Kp.requiredArgs=new Set(["expressions"]),Kp.availableArgs=new Set(["expressions"]),Kp.argOrder=["expressions"],Kp.register();var hb=Kp,qg=class qg extends g{constructor(e={}){super(e)}};qg.key="reduce",qg.requiredArgs=new Set(["this","initial","merge"]),qg.availableArgs=new Set(["this","initial","merge","finish"]),qg.argOrder=["this","initial","merge","finish"],qg.register();var gb=qg,Ug=class Ug extends g{constructor(e={}){super(e)}};Ug.key="regexpExtract",Ug.requiredArgs=new Set(["this","expression"]),Ug.availableArgs=new Set(["this","expression","position","occurrence","parameters","group","nullIfPosOverflow"]),Ug.argOrder=["this","expression","position","occurrence","parameters","group","nullIfPosOverflow"],Ug.register();var Pm=Ug,vg=class vg extends g{constructor(e={}){super(e)}};vg.key="regexpExtractAll",vg.requiredArgs=new Set(["this","expression"]),vg.availableArgs=new Set(["this","expression","group","parameters","position","occurrence"]),vg.argOrder=["group","parameters","position","occurrence"],vg.register();var Eb=vg,Fg=class Fg extends g{constructor(e={}){super(e)}};Fg.key="regexpReplace",Fg.requiredArgs=new Set(["this","expression"]),Fg.availableArgs=new Set(["this","expression","replacement","position","occurrence","modifiers","singleReplace"]),Fg.argOrder=["this","expression","replacement","position","occurrence","modifiers","singleReplace"],Fg.register();var Ab=Fg,Bg=class Bg extends G(q,g){constructor(e={}){super(e)}};Bg.key="regexpLike",Bg.argOrder=["this","expression"],Bg.requiredArgs=new Set(["this","expression"]),Bg.availableArgs=new Set(["this","expression","flag","fullMatch"]),Bg.register();var op=Bg,$g=class $g extends G(q,g){constructor(e={}){super(e)}};$g.key="regexpIlike",$g.argOrder=["this","expression"],$g.requiredArgs=new Set(["this","expression"]),$g.availableArgs=new Set(["this","expression","flag"]),$g.register();var pT=$g,Gg=class Gg extends G(q,g){constructor(e={}){super(e)}};Gg.key="regexpFullMatch",Gg.argOrder=["this","expression","options"],Gg.requiredArgs=new Set(["this","expression"]),Gg.availableArgs=new Set(["this","expression","options"]),Gg.register();var db=Gg,Yg=class Yg extends g{constructor(e={}){super(e)}};Yg.key="regexpInstr",Yg.requiredArgs=new Set(["this","expression"]),Yg.availableArgs=new Set(["this","expression","position","occurrence","option","parameters","group"]),Yg.argOrder=["this","expression","position","occurrence","option","parameters","group"],Yg.register();var xb=Yg,Vg=class Vg extends g{constructor(e={}){super(e)}};Vg.key="regexpSplit",Vg.requiredArgs=new Set(["this","expression"]),Vg.availableArgs=new Set(["this","expression","limit"]),Vg.argOrder=["this","expression","limit"],Vg.register();var fb=Vg,Hg=class Hg extends g{constructor(e={}){super(e)}};Hg.key="regexpCount",Hg.requiredArgs=new Set(["this","expression"]),Hg.availableArgs=new Set(["this","expression","position","parameters"]),Hg.argOrder=["this","expression","position","parameters"],Hg.register();var Tb=Hg,Wg=class Wg extends g{constructor(e={}){super(e)}};Wg.key="repeat",Wg.requiredArgs=new Set(["this","times"]),Wg.availableArgs=new Set(["this","times"]),Wg.argOrder=["this","times"],Wg.register();var Sb=Wg,jg=class jg extends g{constructor(e={}){super(e)}};jg.key="replace",jg.requiredArgs=new Set(["this","expression"]),jg.availableArgs=new Set(["this","expression","replacement"]),jg.argOrder=["this","expression","replacement"],jg.register();var bm=jg,mR=class mR extends g{constructor(e={}){super(e)}};mR.key="radians",mR.argOrder=["this"],mR.register();var vS=mR,Vx=class Vx extends g{constructor(e={}){super(e)}};Vx.key="round",Vx.availableArgs=new Set(["this","decimals","truncate","castsNonIntegerDecimals"]),Vx.argOrder=["this","decimals","truncate","castsNonIntegerDecimals"],Vx.register();var FS=Vx,Jg=class Jg extends g{constructor(e={}){super(e)}};Jg.key="trunc",Jg._sqlNames=["TRUNC","TRUNCATE"],Jg.availableArgs=new Set(["this","decimals"]),Jg.argOrder=["this","decimals"],Jg.register();var Lm=Jg,Xg=class Xg extends g{constructor(e={}){super(e)}};Xg.key="rowNumber",Xg.argOrder=["this"],Xg.requiredArgs=new Set,Xg.availableArgs=new Set(["this"]),Xg.register();var AT=Xg,zg=class zg extends g{constructor(e={}){super(e)}};zg.key="seq1",zg.argOrder=["this"],zg.requiredArgs=new Set,zg.availableArgs=new Set(["this"]),zg.register();var mb=zg,Qg=class Qg extends g{constructor(e={}){super(e)}};Qg.key="seq2",Qg.argOrder=["this"],Qg.requiredArgs=new Set,Qg.availableArgs=new Set(["this"]),Qg.register();var Ob=Qg,Zg=class Zg extends g{constructor(e={}){super(e)}};Zg.key="seq4",Zg.argOrder=["this"],Zg.requiredArgs=new Set,Zg.availableArgs=new Set(["this"]),Zg.register();var Rb=Zg,Kg=class Kg extends g{constructor(e={}){super(e)}};Kg.key="seq8",Kg.argOrder=["this"],Kg.requiredArgs=new Set,Kg.availableArgs=new Set(["this"]),Kg.register();var Nb=Kg,eE=class eE extends g{constructor(e={}){super(e)}};eE.key="safeAdd",eE.requiredArgs=new Set(["this","expression"]),eE.availableArgs=new Set(["this","expression"]),eE.argOrder=["this","expression"],eE.register();var Ib=eE,tE=class tE extends g{constructor(e={}){super(e)}};tE.key="safeDivide",tE.requiredArgs=new Set(["this","expression"]),tE.availableArgs=new Set(["this","expression"]),tE.argOrder=["this","expression"],tE.register();var BS=tE,sE=class sE extends g{constructor(e={}){super(e)}};sE.key="safeMultiply",sE.requiredArgs=new Set(["this","expression"]),sE.availableArgs=new Set(["this","expression"]),sE.argOrder=["this","expression"],sE.register();var yb=sE,OR=class OR extends g{constructor(e={}){super(e)}};OR.key="safeNegate",OR.argOrder=["this"],OR.register();var Cb=OR,rE=class rE extends g{constructor(e={}){super(e)}};rE.key="safeSubtract",rE.requiredArgs=new Set(["this","expression"]),rE.availableArgs=new Set(["this","expression"]),rE.argOrder=["this","expression"],rE.register();var Pb=rE,RR=class RR extends g{constructor(e={}){super(e)}};RR.key="safeConvertBytesToString",RR.argOrder=["this"],RR.register();var bb=RR,Hx=class Hx extends g{constructor(e={}){super(e)}};Hx.key="sha",Hx.argOrder=["this"],Hx._sqlNames=["SHA","Sha1"],Hx.register();var $S=Hx,iE=class iE extends g{constructor(e={}){super(e)}};iE.key="sha2",iE._sqlNames=["Sha2"],iE.availableArgs=new Set(["this","length"]),iE.argOrder=["this","length"],iE.register();var GS=iE,NR=class NR extends g{constructor(e={}){super(e)}};NR.key="sha1Digest",NR.argOrder=["this"],NR.register();var Lb=NR,Wx=class Wx extends g{constructor(e={}){super(e)}};Wx.key="sha2Digest",Wx.availableArgs=new Set(["this","length"]),Wx.argOrder=["this","length"],Wx.register();var wb=Wx,jx=class jx extends g{constructor(e={}){super(e)}};jx.key="sign",jx.argOrder=["this"],jx._sqlNames=["SIGN","SIGNUM"],jx.register();var YS=jx,Jx=class Jx extends g{constructor(e={}){super(e)}};Jx.key="sortArray",Jx.availableArgs=new Set(["this","asc","nullsFirst"]),Jx.argOrder=["this","asc","nullsFirst"],Jx.register();var VS=Jx,IR=class IR extends g{constructor(e={}){super(e)}};IR.key="soundex",IR.argOrder=["this"],IR.register();var Mb=IR,yR=class yR extends g{constructor(e={}){super(e)}};yR.key="soundexP123",yR.argOrder=["this"],yR.register();var Db=yR,nE=class nE extends g{constructor(e={}){super(e)}};nE.key="split",nE.requiredArgs=new Set(["this","expression"]),nE.availableArgs=new Set(["this","expression","limit"]),nE.argOrder=["this","expression","limit"],nE.register();var kb=nE,Xx=class Xx extends g{constructor(e={}){super(e)}};Xx.key="splitPart",Xx.availableArgs=new Set(["this","delimiter","partIndex"]),Xx.argOrder=["this","delimiter","partIndex"],Xx.register();var _b=Xx,aE=class aE extends g{constructor(e={}){super(e)}};aE.key="substring",aE._sqlNames=["SUBSTRING","SUBSTR"],aE.availableArgs=new Set(["this","start","length"]),aE.argOrder=["this","start","length"],aE.register();var er=aE,oE=class oE extends g{constructor(e={}){super(e)}};oE.key="substringIndex",oE.requiredArgs=new Set(["this","delimiter","count"]),oE.availableArgs=new Set(["this","delimiter","count"]),oE.argOrder=["this","delimiter","count"],oE.register();var qb=oE,zx=class zx extends g{constructor(e={}){super(e)}};zx.key="standardHash",zx.availableArgs=new Set(["this","expression"]),zx.argOrder=["this","expression"],zx.register();var Ub=zx,el=class el extends g{constructor(e={}){super(e)}};el.key="startswith",el._sqlNames=["STARTS_WITH","STARTSWITH"],el.requiredArgs=new Set(["this","expression"]),el.availableArgs=new Set(["this","expression"]),el.argOrder=["this","expression"],el.register();var Tl=el,tl=class tl extends g{constructor(e={}){super(e)}};tl.key="endsWith",tl._sqlNames=["ENDS_WITH","ENDSWITH"],tl.requiredArgs=new Set(["this","expression"]),tl.availableArgs=new Set(["this","expression"]),tl.argOrder=["this","expression"],tl.register();var HS=tl,cE=class cE extends g{constructor(e={}){super(e)}};cE.key="strPosition",cE.requiredArgs=new Set(["this","substr"]),cE.availableArgs=new Set(["this","substr","position","occurrence"]),cE.argOrder=["this","substr","position","occurrence"],cE.register();var mr=cE,pE=class pE extends g{constructor(e={}){super(e)}};pE.key="search",pE.requiredArgs=new Set(["this","expression"]),pE.availableArgs=new Set(["this","expression","jsonScope","analyzer","analyzerOptions","searchMode"]),pE.argOrder=["this","expression","jsonScope","analyzer","analyzerOptions","searchMode"],pE.register();var vb=pE,lE=class lE extends g{constructor(e={}){super(e)}};lE.key="searchIp",lE.requiredArgs=new Set(["this","expression"]),lE.availableArgs=new Set(["this","expression"]),lE.argOrder=["this","expression"],lE.register();var Fb=lE,Qx=class Qx extends g{constructor(e={}){super(e)}};Qx.key="strToDate",Qx.availableArgs=new Set(["this","format","safe"]),Qx.argOrder=["this","format","safe"],Qx.register();var ba=Qx,uE=class uE extends g{constructor(e={}){super(e)}};uE.key="strToTime",uE.requiredArgs=new Set(["this","format"]),uE.availableArgs=new Set(["this","format","zone","safe","targetType"]),uE.argOrder=["this","format","zone","safe","targetType"],uE.register();var tr=uE,hE=class hE extends g{constructor(e={}){super(e)}};hE.key="strToUnix",hE.requiredArgs=new Set,hE.availableArgs=new Set(["this","format"]),hE.argOrder=["format","this"],hE.register();var Bb=hE,Zx=class Zx extends g{constructor(e={}){super(e)}};Zx.key="strToMap",Zx.availableArgs=new Set(["this","pairDelim","keyValueDelim","duplicateResolutionCallback"]),Zx.argOrder=["this","pairDelim","keyValueDelim","duplicateResolutionCallback"],Zx.register();var $b=Zx,gE=class gE extends g{constructor(e={}){super(e)}};gE.key="numberToStr",gE.requiredArgs=new Set(["this","format"]),gE.availableArgs=new Set(["this","format","culture"]),gE.argOrder=["this","format","culture"],gE.register();var Gb=gE,EE=class EE extends g{constructor(e={}){super(e)}};EE.key="fromBase",EE.requiredArgs=new Set(["this","expression"]),EE.availableArgs=new Set(["this","expression"]),EE.argOrder=["this","expression"],EE.register();var Yb=EE,CR=class CR extends g{constructor(e={}){super(e)}};CR.key="space",CR.argOrder=["this"],CR.register();var WS=CR,sl=class sl extends g{constructor(e={}){super(e)}};sl.key="struct",sl.isVarLenArgs=!0,sl.requiredArgs=new Set([]),sl.availableArgs=new Set(["expressions"]),sl.argOrder=["expressions"],sl.register();var ks=sl,AE=class AE extends g{constructor(e={}){super(e)}};AE.key="structExtract",AE.requiredArgs=new Set(["this","expression"]),AE.availableArgs=new Set(["this","expression"]),AE.argOrder=["this","expression"],AE.register();var Vb=AE,rl=class rl extends g{constructor(e={}){super(e)}};rl.key="stuff",rl._sqlNames=["STUFF","INSERT"],rl.requiredArgs=new Set(["this","start","length","expression"]),rl.availableArgs=new Set(["this","start","length","expression"]),rl.argOrder=["this","start","length","expression"],rl.register();var Hb=rl,PR=class PR extends g{constructor(e={}){super(e)}};PR.key="sqrt",PR.argOrder=["this"],PR.register();var Wl=PR,dE=class dE extends g{constructor(e={}){super(e)}};dE.key="time",dE.requiredArgs=new Set,dE.availableArgs=new Set(["this","zone"]),dE.argOrder=["zone","this"],dE.register();var jS=dE,xE=class xE extends g{constructor(e={}){super(e)}};xE.key="timeToStr",xE.requiredArgs=new Set(["this","format"]),xE.availableArgs=new Set(["this","format","culture","zone"]),xE.argOrder=["this","format","culture","zone"],xE.register();var Gn=xE,bR=class bR extends g{constructor(e={}){super(e)}};bR.key="timeToTimeStr",bR.argOrder=["this"],bR.register();var JS=bR,LR=class LR extends g{constructor(e={}){super(e)}};LR.key="timeToUnix",LR.argOrder=["this"],LR.register();var Wb=LR,wR=class wR extends g{constructor(e={}){super(e)}};wR.key="timeStrToDate",wR.argOrder=["this"],wR.register();var XS=wR,Kx=class Kx extends g{constructor(e={}){super(e)}};Kx.key="timeStrToTime",Kx.availableArgs=new Set(["this","zone"]),Kx.argOrder=["zone","this"],Kx.register();var ou=Kx,MR=class MR extends g{constructor(e={}){super(e)}};MR.key="timeStrToUnix",MR.argOrder=["this"],MR.register();var jb=MR,ef=class ef extends g{constructor(e={}){super(e)}};ef.key="trim",ef.availableArgs=new Set(["this","expression","position","collation"]),ef.argOrder=["this","expression","position","collation"],ef.register();var cp=ef,fE=class fE extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}get returnType(){let e=this.args.returnType;return e instanceof O?e:O.build("date")}};fE.key="tsOrDsAdd",fE.argOrder=["this","expression","unit","returnType"],fE.requiredArgs=new Set(["this","expression"]),fE.availableArgs=new Set(["this","expression","unit","returnType"]),fE.register();var cu=fE,TE=class TE extends G(g,K){constructor(e={}){super(K.initTimeArgs(e))}};TE.key="tsOrDsDiff",TE.argOrder=["this","expression","unit"],TE.requiredArgs=new Set(["this","expression"]),TE.availableArgs=new Set(["this","expression","unit"]),TE.register();var Jb=TE,DR=class DR extends g{constructor(e={}){super(e)}};DR.key="tsOrDsToDateStr",DR.argOrder=["this"],DR.register();var zS=DR,tf=class tf extends g{constructor(e={}){super(e)}};tf.key="tsOrDsToDate",tf.availableArgs=new Set(["this","format","safe"]),tf.argOrder=["this","format","safe"],tf.register();var Is=tf,kR=class kR extends g{constructor(e={}){super(e)}};kR.key="tsOrDsToDatetime",kR.argOrder=["this"],kR.register();var IT=kR,sf=class sf extends g{constructor(e={}){super(e)}};sf.key="tsOrDsToTime",sf.availableArgs=new Set(["this","format","safe"]),sf.argOrder=["format","safe","this"],sf.register();var yT=sf,_R=class _R extends g{constructor(e={}){super(e)}};_R.key="tsOrDsToTimestamp",_R.argOrder=["this"],_R.register();var CT=_R,qR=class qR extends g{constructor(e={}){super(e)}};qR.key="tsOrDiToDi",qR.argOrder=["this"],qR.register();var QS=qR,rf=class rf extends g{constructor(e={}){super(e)}};rf.key="unhex",rf.availableArgs=new Set(["this","expression"]),rf.argOrder=["this","expression"],rf.register();var Xb=rf,UR=class UR extends g{constructor(e={}){super(e)}};UR.key="unicode",UR.argOrder=["this"],UR.register();var ZS=UR,SE=class SE extends g{constructor(e={}){super(e)}};SE.key="uniform",SE.requiredArgs=new Set(["this","expression"]),SE.availableArgs=new Set(["this","expression","gen","seed"]),SE.argOrder=["this","expression","gen","seed"],SE.register();var zb=SE,vR=class vR extends g{constructor(e={}){super(e)}};vR.key="unixDate",vR.argOrder=["this"],vR.register();var KS=vR,nf=class nf extends g{constructor(e={}){super(e)}};nf.key="unixToStr",nf.availableArgs=new Set(["this","format"]),nf.argOrder=["format","this"],nf.register();var em=nf,Jt=class Jt extends g{constructor(e={}){super(e)}};Jt.key="unixToTime",Jt.availableArgs=new Set(["this","scale","zone","hours","minutes","format","targetType"]),Jt.argOrder=["this","scale","zone","hours","minutes","format","targetType"],Jt.SECONDS=R.number(0),Jt.DECIS=R.number(1),Jt.CENTIS=R.number(2),Jt.MILLIS=R.number(3),Jt.DECIMILLIS=R.number(4),Jt.CENTIMILLIS=R.number(5),Jt.MICROS=R.number(6),Jt.DECIMICROS=R.number(7),Jt.CENTIMICROS=R.number(8),Jt.NANOS=R.number(9),Jt.register();var tm=Jt,FR=class FR extends g{constructor(e={}){super(e)}};FR.key="unixToTimeStr",FR.argOrder=["this"],FR.register();var sm=FR,BR=class BR extends g{constructor(e={}){super(e)}};BR.key="unixSeconds",BR.argOrder=["this"],BR.register();var rm=BR,$R=class $R extends g{constructor(e={}){super(e)}};$R.key="unixMicros",$R.argOrder=["this"],$R.register();var im=$R,GR=class GR extends g{constructor(e={}){super(e)}};GR.key="unixMillis",GR.argOrder=["this"],GR.register();var nm=GR,mE=class mE extends g{constructor(e={}){super(e)}};mE.key="uuid",mE._sqlNames=["UUID","GEN_RANDOM_UUID","GENERATE_UUID","UUID_STRING"],mE.availableArgs=new Set(["this","name","isString"]),mE.argOrder=["name","isString","this"],mE.register();var NA=mE,WU={year:!1,month:!1,day:!1,hour:!1,min:!1,sec:!1,nano:!1},il=class il extends g{constructor(e={}){super(e)}};il.key="timestampFromParts",il._sqlNames=["TIMESTAMP_FROM_PARTS","TIMESTAMPFROMPARTS"],il.requiredArgs=new Set,il.availableArgs=new Set(["year","month","day","hour","min","sec","nano","zone","milli","this","expression"]),il.argOrder=["year","month","day","hour","min","sec","nano","zone","milli","this","expression"],il.register();var bN=il,OE=class OE extends g{constructor(e={}){super(e)}};OE.key="timestampLtzFromParts",OE.argOrder=["year","month","day","hour","min","sec","nano"],OE._sqlNames=["TIMESTAMP_LTZ_FROM_PARTS","TIMESTAMPLTZFROMPARTS"],OE.availableArgs=new Set(["year","month","day","hour","min","sec","nano"]),OE.register();var am=OE,RE=class RE extends g{constructor(e={}){super(e)}};RE.key="timestampTzFromParts",RE._sqlNames=["TIMESTAMP_TZ_FROM_PARTS","TIMESTAMPTZFROMPARTS"],RE.availableArgs=new Set(["year","month","day","hour","min","sec","nano","zone"]),RE.argOrder=["zone"],RE.register();var om=RE,af=class af extends g{constructor(e={}){super(e)}};af.key="upper",af.argOrder=["this"],af._sqlNames=["UPPER","UCASE"],af.register();var jl=af,NE=class NE extends G(q,D){constructor(e={}){super(e)}};NE.key="corr",NE.requiredArgs=new Set(["this","expression"]),NE.availableArgs=new Set(["this","expression","nullOnZeroVariance"]),NE.argOrder=["this","expression","nullOnZeroVariance"],NE.register();var Qb=NE,of=class of extends g{constructor(e={}){super(e)}};of.key="widthBucket",of.availableArgs=new Set(["this","minValue","maxValue","numBuckets","threshold"]),of.argOrder=["this","minValue","maxValue","numBuckets","threshold"],of.register();var Zb=of,IE=class IE extends g{constructor(e={}){super(e)}};IE.key="week",IE.requiredArgs=new Set,IE.availableArgs=new Set(["this","mode"]),IE.argOrder=["this","mode"],IE.register();var BA=IE,yE=class yE extends g{constructor(e={}){super(e)}};yE.key="nextDay",yE.requiredArgs=new Set(["this","expression"]),yE.availableArgs=new Set(["this","expression"]),yE.argOrder=["this","expression"],yE.register();var Kb=yE,CE=class CE extends g{constructor(e={}){super(e)}};CE.key="xmlElement",CE._sqlNames=["XmlELEMENT"],CE.availableArgs=new Set(["this","expressions","evalname"]),CE.argOrder=["evalname","this","expressions"],CE.register();var lT=CE,nl=class nl extends g{constructor(e={}){super(e)}};nl.key="xmlGet",nl._sqlNames=["XmlGET"],nl.requiredArgs=new Set(["this","expression"]),nl.availableArgs=new Set(["this","expression","instance"]),nl.argOrder=["this","expression","instance"],nl.register();var eL=nl,cf=class cf extends g{constructor(e={}){super(e)}};cf.key="xmlTable",cf.availableArgs=new Set(["this","namespaces","passing","columns","byRef"]),cf.argOrder=["this","namespaces","passing","columns","byRef"],cf.register();var uT=cf,YR=class YR extends g{constructor(e={}){super(e)}};YR.key="year",YR.argOrder=["this"],YR.register();var cm=YR,PE=class PE extends g{constructor(e={}){super(e)}};PE.key="zipf",PE.requiredArgs=new Set(["this","elementcount","gen"]),PE.availableArgs=new Set(["this","elementcount","gen"]),PE.argOrder=["elementcount","gen","this"],PE.register();var tL=PE,pf=class pf extends g{constructor(e={}){super(e)}};pf.key="nextValueFor",pf.availableArgs=new Set(["this","order"]),pf.argOrder=["order","this"],pf.register();var hT=pf,ys=class extends $s{constructor(e={}){super(e)}};ys.key="all";var Ct=class extends $s{constructor(e={}){super(e)}};Ct.key="any";var _N=class _N extends D{constructor(e={}){super(e)}};_N.key="bitwiseAndAgg",_N.register();var sL=_N,qN=class qN extends D{constructor(e={}){super(e)}};qN.key="bitwiseOrAgg",qN.register();var rL=qN,UN=class UN extends D{constructor(e={}){super(e)}};UN.key="bitwiseXorAgg",UN.register();var iL=UN,vN=class vN extends D{constructor(e={}){super(e)}};vN.key="boolxorAgg",vN.register();var nL=vN,FN=class FN extends D{constructor(e={}){super(e)}};FN.key="bitmapConstructAgg",FN.register();var aL=FN,BN=class BN extends D{constructor(e={}){super(e)}};BN.key="bitmapOrAgg",BN.register();var oL=BN,bE=class bE extends D{constructor(e={}){super(e)}};bE.key="parameterizedAgg",bE.argOrder=["this","expressions","params"],bE.requiredArgs=new Set(["this","expressions","params"]),bE.availableArgs=new Set(["this","expressions","params"]),bE.register();var wN=bE,al=class al extends D{constructor(e={}){super(e)}};al.key="argMax",al.argOrder=["this","expression","count"],al._sqlNames=["ARG_MAX","ARGMAX","MAX_BY"],al.requiredArgs=new Set(["this","expression"]),al.availableArgs=new Set(["this","expression","count"]),al.register();var IA=al,ol=class ol extends D{constructor(e={}){super(e)}};ol.key="argMin",ol.argOrder=["this","expression","count"],ol._sqlNames=["ARG_MIN","ARGMIN","MIN_BY"],ol.requiredArgs=new Set(["this","expression"]),ol.availableArgs=new Set(["this","expression","count"]),ol.register();var yA=ol,lf=class lf extends D{constructor(e={}){super(e)}};lf.key="approxTopK",lf.argOrder=["this","expression","counters"],lf.availableArgs=new Set(["this","expression","counters"]),lf.register();var cL=lf,uf=class uf extends D{constructor(e={}){super(e)}};uf.key="approxTopKAccumulate",uf.argOrder=["this","expression"],uf.availableArgs=new Set(["this","expression"]),uf.register();var pL=uf,hf=class hf extends D{constructor(e={}){super(e)}};hf.key="approxTopKCombine",hf.argOrder=["this","expression"],hf.availableArgs=new Set(["this","expression"]),hf.register();var lL=hf,LE=class LE extends D{constructor(e={}){super(e)}};LE.key="approxTopSum",LE.argOrder=["this","expression","count"],LE.requiredArgs=new Set(["this","expression","count"]),LE.availableArgs=new Set(["this","expression","count"]),LE.register();var uL=LE,gf=class gf extends D{constructor(e={}){super(e)}};gf.key="approxQuantiles",gf.argOrder=["this","expression"],gf.availableArgs=new Set(["this","expression"]),gf.register();var hL=gf,$N=class $N extends D{constructor(e={}){super(e)}};$N.key="approxPercentileCombine",$N.register();var gL=$N,cl=class cl extends D{constructor(e={}){super(e)}};cl.key="minhash",cl.argOrder=["this","expressions"],cl.isVarLenArgs=!0,cl.requiredArgs=new Set(["this","expressions"]),cl.availableArgs=new Set(["this","expressions"]),cl.register();var EL=cl,GN=class GN extends D{constructor(e={}){super(e)}};GN.key="minhashCombine",GN.register();var AL=GN,VR=class VR extends D{constructor(e={}){super(e)}};VR.key="approximateSimilarity",VR._sqlNames=["APPROXIMATE_SIMILARITY","APPROXIMATE_JACCARD_INDEX"],VR.register();var dL=VR,pl=class pl extends D{constructor(e={}){super(e)}};pl.key="grouping",pl.isVarLenArgs=!0,pl.argOrder=["expressions"],pl.requiredArgs=new Set(["expressions"]),pl.availableArgs=new Set(["expressions"]),pl.register();var xL=pl,wE=class wE extends D{constructor(e={}){super(e)}};wE.key="groupingId",wE.requiredArgs=new Set,wE.isVarLenArgs=!0,wE.availableArgs=new Set(["expressions"]),wE.register();var fL=wE,ME=class ME extends D{constructor(e={}){super(e)}};ME.key="anonymousAggFunc",ME.argOrder=["this","expressions"],ME.isVarLenArgs=!0,ME.availableArgs=new Set(["this","expressions"]),ME.register();var MN=ME,DE=class DE extends D{constructor(e={}){super(e)}};DE.key="hashAgg",DE.argOrder=["this","expressions"],DE.isVarLenArgs=!0,DE.availableArgs=new Set(["this","expressions"]),DE.register();var TL=DE,kE=class kE extends D{constructor(e={}){super(e)}};kE.key="hll",kE.argOrder=["this","expressions"],kE.isVarLenArgs=!0,kE.availableArgs=new Set(["this","expressions"]),kE.register();var SL=kE,_E=class _E extends D{constructor(e={}){super(e)}};_E.key="approxDistinct",_E.argOrder=["this","accuracy"],_E._sqlNames=["APPROX_DISTINCT","APPROX_COUNT_DISTINCT"],_E.availableArgs=new Set(["this","accuracy"]),_E.register();var pm=_E,YN=class YN extends Fs{};YN.key="explodingGenerateSeries",YN.register();var mL=YN,Ef=class Ef extends D{constructor(e={}){super(e)}};Ef.key="arrayAgg",Ef.argOrder=["this","nullsExcluded"],Ef.availableArgs=new Set(["this","nullsExcluded"]),Ef.register();var uo=Ef,VN=class VN extends D{constructor(e={}){super(e)}};VN.key="arrayUniqueAgg",VN.register();var OL=VN,ll=class ll extends D{constructor(e={}){super(e)}};ll.key="aiAgg",ll.argOrder=["this","expression"],ll._sqlNames=["AI_AGG"],ll.requiredArgs=new Set(["this","expression"]),ll.availableArgs=new Set(["this","expression"]),ll.register();var RL=ll,HR=class HR extends D{constructor(e={}){super(e)}};HR.key="aiSummarizeAgg",HR._sqlNames=["AI_SUMMARIZE_AGG"],HR.register();var NL=HR,HN=class HN extends D{constructor(e={}){super(e)}};HN.key="arrayConcatAgg",HN.register();var lm=HN,WN=class WN extends D{constructor(e={}){super(e)}};WN.key="arrayUnionAgg",WN.register();var IL=WN,jN=class jN extends D{constructor(e={}){super(e)}};jN.key="avg",jN.register();var um=jN,JN=class JN extends D{constructor(e={}){super(e)}};JN.key="anyValue",JN.register();var hm=JN,Af=class Af extends D{constructor(e={}){super(e)}};Af.key="lag",Af.argOrder=["this","offset","default"],Af.availableArgs=new Set(["this","offset","default"]),Af.register();var yL=Af,df=class df extends D{constructor(e={}){super(e)}};df.key="lead",df.argOrder=["this","offset","default"],df.availableArgs=new Set(["this","offset","default"]),df.register();var CL=df,xf=class xf extends D{constructor(e={}){super(e)}};xf.key="first",xf.argOrder=["this","expression"],xf.availableArgs=new Set(["this","expression"]),xf.register();var PL=xf,ff=class ff extends D{constructor(e={}){super(e)}};ff.key="last",ff.argOrder=["this","expression"],ff.availableArgs=new Set(["this","expression"]),ff.register();var bL=ff,XN=class XN extends D{constructor(e={}){super(e)}};XN.key="firstValue",XN.register();var LL=XN,zN=class zN extends D{constructor(e={}){super(e)}};zN.key="lastValue",zN.register();var gm=zN,qE=class qE extends D{constructor(e={}){super(e)}};qE.key="nthValue",qE.argOrder=["this","offset","fromFirst"],qE.requiredArgs=new Set(["this","offset"]),qE.availableArgs=new Set(["this","offset","fromFirst"]),qE.register();var wL=qE,UE=class UE extends D{constructor(e={}){super(e)}};UE.key="objectAgg",UE.argOrder=["this","expression"],UE.requiredArgs=new Set(["this","expression"]),UE.availableArgs=new Set(["this","expression"]),UE.register();var ML=UE,_t=class extends X{constructor(e={}){super(e)}};_t.key="tryCast",_t.requiredArgs=new Set,_t.availableArgs=new Set(["this","to","format","safe","action","default","requiresString"]);var _A=class extends X{constructor(e={}){super(e)}};_A.key="jsonCast";var wt=class extends Gt{constructor(e={}){super(e)}};wt.key="concatWs",wt._sqlNames=["CONCAT_WS"];var ul=class ul extends D{constructor(e={}){super(e)}};ul.key="count",ul.argOrder=["this","expressions","bigInt"],ul.requiredArgs=new Set,ul.isVarLenArgs=!0,ul.availableArgs=new Set(["this","expressions","bigInt"]),ul.register();var Jl=ul,WR=class WR extends D{constructor(e={}){super(e)}};WR.key="countIf",WR._sqlNames=["COUNT_IF","COUNTIF"],WR.register();var Em=WR,hl=class hl extends D{constructor(e={}){super(e)}};hl.key="denseRank",hl.argOrder=[],hl.requiredArgs=new Set,hl.isVarLenArgs=!0,hl.availableArgs=new Set(["expressions"]),hl.register();var DL=hl,zl=class extends rs{constructor(e={}){super(e)}};zl.key="explodeOuter";var QN=class QN extends rs{constructor(e={}){super(e)}};QN.key="posexplode",QN.register();var Ma=QN,Tf=class Tf extends D{constructor(e={}){super(e)}};Tf.key="groupConcat",Tf.argOrder=["this","separator","onOverflow"],Tf.availableArgs=new Set(["this","separator","onOverflow"]),Tf.register();var Ui=Tf,pp=class extends ap{constructor(e={}){super(e)}};pp.key="lowerHex";var ce=class extends G(Ee,g){constructor(e={}){super(e)}};ce.key="and",ce.requiredArgs=new Set(["this","expression"]),ce.availableArgs=new Set(["this","expression"]);var ze=class extends G(Ee,g){constructor(e={}){super(e)}};ze.key="or",ze.requiredArgs=new Set(["this","expression"]),ze.availableArgs=new Set(["this","expression"]);var qi=class extends G(Ee,g){constructor(e={}){super(e)}};qi.key="xor",qi.requiredArgs=new Set,qi.isVarLenArgs=!0,qi.availableArgs=new Set(["this","expression","expressions","roundInput"]);var Sf=class Sf extends D{constructor(e={}){super(e)}};Sf.key="jsonObjectAgg",Sf.argOrder=["expressions","nullHandling","uniqueKeys","returnType","encoding"],Sf.availableArgs=new Set(["expressions","nullHandling","uniqueKeys","returnType","encoding"]),Sf.register();var gT=Sf,vE=class vE extends D{constructor(e={}){super(e)}};vE.key="jsonbObjectAgg",vE.argOrder=["this","expression"],vE.requiredArgs=new Set(["this","expression"]),vE.availableArgs=new Set(["this","expression"]),vE.register();var kL=vE,mf=class mf extends D{constructor(e={}){super(e)}};mf.key="jsonArrayAgg",mf.argOrder=["this","order","nullHandling","returnType","strict"],mf.availableArgs=new Set(["this","order","nullHandling","returnType","strict"]),mf.register();var _L=mf,jR=class jR extends D{constructor(e={}){super(e)}};jR.key="logicalOr",jR._sqlNames=["LOGICAL_OR","BOOL_OR","BOOLOR_AGG"],jR.register();var Am=jR,JR=class JR extends D{constructor(e={}){super(e)}};JR.key="logicalAnd",JR._sqlNames=["LOGICAL_AND","BOOL_AND","BOOLAND_AGG"],JR.register();var dm=JR,FE=class FE extends D{constructor(e={}){super(e)}};FE.key="max",FE.argOrder=["this","expressions"],FE.isVarLenArgs=!0,FE.availableArgs=new Set(["this","expressions"]),FE.register();var xm=FE,ZN=class ZN extends D{constructor(e={}){super(e)}};ZN.key="median",ZN.register();var qL=ZN,BE=class BE extends D{constructor(e={}){super(e)}};BE.key="mode",BE.argOrder=["this","deterministic"],BE.requiredArgs=new Set,BE.availableArgs=new Set(["this","deterministic"]),BE.register();var UL=BE,$E=class $E extends D{constructor(e={}){super(e)}};$E.key="min",$E.argOrder=["this","expressions"],$E.isVarLenArgs=!0,$E.availableArgs=new Set(["this","expressions"]),$E.register();var fm=$E,XR=class XR extends D{constructor(e={}){super(e)}};XR.key="ntile",XR.requiredArgs=new Set,XR.register();var vL=XR,Of=class Of extends D{constructor(e={}){super(e)}};Of.key="percentileCont",Of.argOrder=["this","expression"],Of.availableArgs=new Set(["this","expression"]),Of.register();var FA=Of,Rf=class Rf extends D{constructor(e={}){super(e)}};Rf.key="percentileDisc",Rf.argOrder=["this","expression"],Rf.availableArgs=new Set(["this","expression"]),Rf.register();var DN=Rf,gl=class gl extends D{constructor(e={}){super(e)}};gl.key="percentRank",gl.argOrder=[],gl.requiredArgs=new Set,gl.isVarLenArgs=!0,gl.availableArgs=new Set(["expressions"]),gl.register();var FL=gl,GE=class GE extends D{constructor(e={}){super(e)}};GE.key="quantile",GE.argOrder=["this","quantile"],GE.requiredArgs=new Set(["this","quantile"]),GE.availableArgs=new Set(["this","quantile"]),GE.register();var $A=GE,KN=class KN extends D{constructor(e={}){super(e)}};KN.key="approxPercentileAccumulate",KN.register();var BL=KN,El=class El extends D{constructor(e={}){super(e)}};El.key="rank",El.argOrder=[],El.requiredArgs=new Set,El.isVarLenArgs=!0,El.availableArgs=new Set(["expressions"]),El.register();var $L=El,YE=class YE extends D{constructor(e={}){super(e)}};YE.key="regrValx",YE.argOrder=["this","expression"],YE.requiredArgs=new Set(["this","expression"]),YE.availableArgs=new Set(["this","expression"]),YE.register();var GL=YE,VE=class VE extends D{constructor(e={}){super(e)}};VE.key="regrValy",VE.argOrder=["this","expression"],VE.requiredArgs=new Set(["this","expression"]),VE.availableArgs=new Set(["this","expression"]),VE.register();var YL=VE,HE=class HE extends D{constructor(e={}){super(e)}};HE.key="regrAvgy",HE.argOrder=["this","expression"],HE.requiredArgs=new Set(["this","expression"]),HE.availableArgs=new Set(["this","expression"]),HE.register();var VL=HE,WE=class WE extends D{constructor(e={}){super(e)}};WE.key="regrAvgx",WE.argOrder=["this","expression"],WE.requiredArgs=new Set(["this","expression"]),WE.availableArgs=new Set(["this","expression"]),WE.register();var HL=WE,jE=class jE extends D{constructor(e={}){super(e)}};jE.key="regrCount",jE.argOrder=["this","expression"],jE.requiredArgs=new Set(["this","expression"]),jE.availableArgs=new Set(["this","expression"]),jE.register();var WL=jE,JE=class JE extends D{constructor(e={}){super(e)}};JE.key="regrIntercept",JE.argOrder=["this","expression"],JE.requiredArgs=new Set(["this","expression"]),JE.availableArgs=new Set(["this","expression"]),JE.register();var jL=JE,XE=class XE extends D{constructor(e={}){super(e)}};XE.key="regrR2",XE.argOrder=["this","expression"],XE.requiredArgs=new Set(["this","expression"]),XE.availableArgs=new Set(["this","expression"]),XE.register();var JL=XE,zE=class zE extends D{constructor(e={}){super(e)}};zE.key="regrSxx",zE.argOrder=["this","expression"],zE.requiredArgs=new Set(["this","expression"]),zE.availableArgs=new Set(["this","expression"]),zE.register();var XL=zE,QE=class QE extends D{constructor(e={}){super(e)}};QE.key="regrSxy",QE.argOrder=["this","expression"],QE.requiredArgs=new Set(["this","expression"]),QE.availableArgs=new Set(["this","expression"]),QE.register();var zL=QE,ZE=class ZE extends D{constructor(e={}){super(e)}};ZE.key="regrSyy",ZE.argOrder=["this","expression"],ZE.requiredArgs=new Set(["this","expression"]),ZE.availableArgs=new Set(["this","expression"]),ZE.register();var QL=ZE,KE=class KE extends D{constructor(e={}){super(e)}};KE.key="regrSlope",KE.argOrder=["this","expression"],KE.requiredArgs=new Set(["this","expression"]),KE.availableArgs=new Set(["this","expression"]),KE.register();var ZL=KE,eI=class eI extends D{constructor(e={}){super(e)}};eI.key="sum",eI.register();var Tm=eI,zR=class zR extends D{constructor(e={}){super(e)}};zR.key="stddev",zR._sqlNames=["STDDEV","STDEV"],zR.register();var Sm=zR,tI=class tI extends D{constructor(e={}){super(e)}};tI.key="stddevPop",tI.register();var mm=tI,sI=class sI extends D{constructor(e={}){super(e)}};sI.key="stddevSamp",sI.register();var Om=sI,Al=class Al extends D{constructor(e={}){super(e)}};Al.key="cumeDist",Al.argOrder=[],Al.requiredArgs=new Set,Al.isVarLenArgs=!0,Al.availableArgs=new Set(["expressions"]),Al.register();var KL=Al,QR=class QR extends D{constructor(e={}){super(e)}};QR.key="variance",QR._sqlNames=["VARIANCE","VARIANCE_SAMP","VAR_SAMP"],QR.register();var Rm=QR,ZR=class ZR extends D{constructor(e={}){super(e)}};ZR.key="variancePop",ZR._sqlNames=["VARIANCE_POP","VAR_POP"],ZR.register();var Nm=ZR,rI=class rI extends D{constructor(e={}){super(e)}};rI.key="kurtosis",rI.register();var Im=rI,iI=class iI extends D{constructor(e={}){super(e)}};iI.key="skewness",iI.register();var ym=iI,eA=class eA extends D{constructor(e={}){super(e)}};eA.key="covarSamp",eA.argOrder=["this","expression"],eA.requiredArgs=new Set(["this","expression"]),eA.availableArgs=new Set(["this","expression"]),eA.register();var ew=eA,tA=class tA extends D{constructor(e={}){super(e)}};tA.key="covarPop",tA.argOrder=["this","expression"],tA.requiredArgs=new Set(["this","expression"]),tA.availableArgs=new Set(["this","expression"]),tA.register();var tw=tA,nI=class nI extends MN{constructor(e={}){super(e)}};nI.key="combinedAggFunc",nI.register();var sw=nI,aI=class aI extends wN{constructor(e={}){super(e)}};aI.key="combinedParameterizedAgg",aI.register();var rw=aI,bd=class extends G(Ma,zl){constructor(e={}){super(e)}};bd.key="posexplodeOuter",bd.requiredArgs=new Set(["this"]),bd.availableArgs=new Set(["this","expressions"]);var $n=class extends $A{constructor(e={}){super(e)}};$n.key="approxQuantile",$n.argOrder=["this","quantile","accuracy","weight","errorTolerance"],$n.availableArgs=new Set(["this","quantile","accuracy","weight","errorTolerance"]);function ho(i,e={}){let{col:t,table:s,db:r,catalog:n}=i,{fields:a,quoted:o,copy:c=!0}=e,l;t instanceof xe?l=t:l=Z(t,{quoted:o,copy:c});let u=new B({this:l,table:s!==void 0?Z(s,{quoted:o,copy:c}):void 0,db:r!==void 0?Z(r,{quoted:o,copy:c}):void 0,catalog:n!==void 0?Z(n,{quoted:o,copy:c}):void 0});if(a&&0<a.length){let h=a.map(d=>Z(d,{quoted:o,copy:c})).filter(d=>d!==void 0);return Se.build([u,...h])}return u}function jU(i,e={}){let{db:t,catalog:s,quoted:r,alias:n}=e;return new V({this:i?Z(i,{quoted:r}):void 0,db:t?Z(t,{quoted:r}):void 0,catalog:s?Z(s,{quoted:r}):void 0,alias:n?new ie({this:Z(n)}):void 0})}function hq(i,e,t){let s={this:new U({this:i})};return e&&(s.db=new U({this:e})),t&&(s.catalog=new U({this:t})),new V(s)}function Fe(i,e={}){let{dialect:t,copy:s=!0,wrap:r=!0,...n}=e;return qA(i,ce,{dialect:t,copy:s,wrap:r,...n})}function Kt(i,e={}){let{dialect:t,copy:s=!0,wrap:r=!0,...n}=e;return qA(i,ze,{dialect:t,copy:s,wrap:r,...n})}function CI(i,e={}){let{dialect:t,copy:s=!0,wrap:r=!0,...n}=e;return qA(i,qi,{dialect:t,copy:s,wrap:r,...n})}function xr(i,e={}){let t=Aq(i,e);return new be({this:Yn(t,Ee)||t})}function ki(i,e={}){let{copy:t=!0,...s}=e;return new Oe({this:H(i,{copy:t,...s})})}var wm=/^[_a-zA-Z][\w]*$/;function Z(i,e={}){let{quoted:t,copy:s=!0}=e;if(i!==void 0)return i instanceof U?Ve(i,s):new U({this:i,quoted:t!==void 0?t:!wm.test(i.toString())})}function Bf(i,e={}){let{dialect:t,...s}=e;try{return H(i,{dialect:t,into:U,...s})}catch{return Z(i)}}var UI=/\s*(-?[0-9]+(?:\.[0-9]+)?)\s*([a-zA-Z]+)\s*/,vI=/\s*-?\s*\d+(?:\.\d+)?\s+(?:-?(?:\d+:)?\d+:\d+(?:\.\d+)?|-?(?:\d+:){1,2}|:)\s*/;function JU(i){let e;if(i instanceof R){if(!i.args.isString)throw new Error("Invalid interval string.");e=i.args.this}else e=i;let t=H(`INTERVAL ${e}`);if(!(t instanceof Ce))throw new Error("Failed to parse interval expression");return t}function Ye(i,e,t={}){let{table:s,quoted:r,dialect:n,copy:a=!0,...o}=t,c=H(i,{dialect:n,copy:a,...o}),l=e!==void 0?Z(e instanceof U?e:e.toString(),{quoted:r}):void 0;if(s){let u=new ie({this:l});if(c.setArgKey("alias",u),Array.isArray(s))for(let h of s){let d=Z(h,{quoted:r});d&&u.append("columns",d)}return c}return c._constructor.availableArgs.has("alias")&&!(c instanceof we)?(l&&c.setArgKey("alias",l),c):new Re({this:c,alias:l})}function HI(i,e,t={}){let{dialect:s,...r}=t,n=H(i,{dialect:s,...r});if(!(n instanceof z))throw new Error("The input sql is not a QueryExpr");let a=n.subquery(e,r);return new ee({}).from(a,{dialect:s,...r})}function pt(i,e={}){return new ee().select(i,e)}function XU(i,e={}){return new ee({}).from(i,e)}function WI(i,e={}){let t;return i!==void 0&&(t=H(i,e)),new nt({this:t,ifs:[]})}function j(i,e,t={}){let{copy:s=!0,dialect:r,...n}=t,a=H(i,{copy:s,dialect:r,...n}),o=O.build(e,{copy:s,dialect:r,...n});if(a instanceof X){let u=se.getOrRaise(r)._constructor.generatorClass.TYPE_MAPPING,h=a.args.to?.args.this,d=o?.args.this,x=h!=null&&(u.get(h.toString())||h)===(u.get(d?.toString()??"")||d);if(o!==void 0&&a.isType([o])||x)return a}let c=new X({this:a,to:o});return c.type=o,c}function zU(i,e={}){let{alias:t,columns:s}=e;if(s&&!t)throw new Error("Alias is required when providing columns");let r=i.map(a=>new Ge({expressions:a.map(o=>Ot(o))})),n;return s?n=new ie({this:t!==void 0?Z(t):void 0,columns:s.map(a=>Z(a)).filter(a=>a!==void 0)}):t&&(n=new ie({this:Z(t)})),new Ls({expressions:r,alias:n})}function jI(i,...e){let t=e.map(r=>typeof r=="string"?H(r):Ot(r)),s=Rl.get(i.toUpperCase());return s?s.fromArgList(t):new je({this:i,expressions:t})}function aw(i,e,t={}){let{distinct:s=!0,dialect:r,copy:n=!0,...a}=t;return i?.map(c=>H(c,{dialect:r,copy:n,...a}))?.reduce((c,l)=>new e({this:c,expression:l,distinct:s,...a}))}function UA(i,e={}){let t=Array.from(J(i)).filter(s=>s!==void 0);if(t.length<2)throw new Error("At least two expressions are required by `union`.");return aw(t,Lr,e)}function gq(i,e={}){let t=Array.from(J(i)).filter(s=>s!==void 0);if(t.length<2)throw new Error("At least two expressions are required by `intersect`.");return aw(t,kn,e)}function Eq(i,e={}){let t=Array.from(J(i)).filter(s=>s!==void 0);if(t.length<2)throw new Error("At least two expressions are required by `except`.");return aw(t,wr,e)}function QU(i,e,t={}){let{columns:s,overwrite:r,returning:n,dialect:a,copy:o=!0,...c}=t,l=H(i,{dialect:a,copy:o,...c}),u=H(e,{into:V,dialect:a,copy:o,...c});s&&(u=new At({this:u,expressions:s.map(d=>typeof d=="string"?Z(d):d)}));let h=new kt({this:u,expression:l,overwrite:r});return n&&(h=h.returning(n,{dialect:a,copy:!1,...c})),h}function ZU(i,e={}){let{where:t,returning:s,dialect:r,...n}=e,a=new Js({}).delete(i,{dialect:r,copy:!1,...n});return t&&(a=a.where(t,{dialect:r,copy:!1,...n})),s&&(a=a.returning(s,{dialect:r,copy:!1,...n})),a}function KU(i,e,t={}){let{where:s,from:r,with:n,dialect:a,...o}=t,c=new Vt({this:H(i,{into:V,dialect:a})});if(e&&c.setArgKey("expressions",Object.entries(e).map(([l,u])=>new me({this:H(l,{dialect:a,...o}),expression:Ot(u)}))),r&&c.setArgKey("from",H(r,{into:Je,dialect:a,prefix:"FROM",...o})),s){let l=s;s instanceof ye&&(l=new at({this:s})),c.setArgKey("where",H(l,{into:at,dialect:a,prefix:"WHERE",...o}))}if(n){let l=Object.entries(n).map(([u,h])=>Ye(new Tt({this:H(h,{dialect:a,...o})}),u,{table:!0}));c.setArgKey("with",new tt({expressions:l}))}return c}function ev(i,e={}){let{into:t,using:s,on:r,returning:n,dialect:a,copy:o=!0,...c}=e,l=i!==void 0?Array.from(J(i)):[],u=[];for(let x of l){let f=H(x,{dialect:a,copy:o,into:cn,...c});f instanceof _r?u.push(f):u.push(...f.args.expressions)}let h=new fa({this:H(t,{dialect:a,copy:o,...c}),using:H(s,{dialect:a,copy:o,...c}),on:H(r,{dialect:a,copy:o,...c}),whens:new cn({expressions:u})});n&&(h=h.returning(n,{dialect:a,copy:!1,...c}));let d=h.args.using;if(d instanceof Re){let x=d.args.alias,f=typeof x=="string"||$(x,U)?x:void 0;d.replace(Ye(d.args.this,f,{table:!0}))}return h}function Aq(i,e={}){return H(i,{into:ye,...e})}function H(i,e){if(i instanceof A)return e?.copy?i.copy():i;if(i===void 0)throw new xt("SQL cannot be null or undefined");let t=String(i);e?.prefix&&(t=`${e.prefix} ${t}`);let{dialect:s,...r}=e||{};return _I(t,{...r,read:s||r.read})}function Nf(i,e={}){let{dialect:t,copy:s=!0,...r}=e;if(i instanceof V)return Ve(i,s);try{let n=H(i,{into:V,dialect:t,...r});for(let[a,o]of Object.entries(r))n.setArgKey(a,o);return n}catch{let[n,a,o]=AD(i,".",3);if(!o)throw new Error(`Invalid table path: ${i}`);let c=hq(o,a,n);for(let[l,u]of Object.entries(r))c.setArgKey(l,u);return c}}function iw(i,e={}){let{quoted:t,dialect:s,copy:r=!0,...n}=e;if(i instanceof B)return Ve(i,r);try{let a=H(i,{into:B,dialect:s,...n});for(let[o,c]of Object.entries(n))a.setArgKey(o,c);if(t)for(let o of a.findAll(U))o.setArgKey("quoted",!0);return a}catch{let a=i.split(".").reverse(),[o,c]=a,l={this:Z(o,{quoted:t})};c&&(l.table=Z(c,{quoted:t}));let u=new B(l);for(let[h,d]of Object.entries(n))u.setArgKey(h,d);return u}}function tv(i){let e=new Set;for(let t of cA(i))for(let s of t.tables)s.name&&!t.cteSources.has(s.name)&&e.add(s);return e}function Ve(i,e=!0){return e&&i?i.copy():i}function dq(i,e){return i instanceof A&&!(i instanceof e)}function sA(i,e){let{instance:t,arg:s,copy:r=!0,prefix:n,into:a,dialect:o,intoArg:c="this",...l}=e;a&&dq(i,a)&&(i=new a({[c]:i}));let u=Ve(t,r),h=H(i,{prefix:n,into:a,dialect:o,...l});return s!==void 0&&u.setArgKey(s,h),u}function Ld(i,e={}){let{instance:t,arg:s,append:r=!0,copy:n=!0,prefix:a,into:o,dialect:c,properties:l,...u}=e,h=Ve(t,n),d=[],x=l||{},f=J(i);for(let P of f){if(P===void 0)continue;let k=P;o&&dq(k,o)&&(k=new o({expressions:[k]}));let _=H(k,{into:o,dialect:c,prefix:a,...u});for(let[W,he]of Object.entries(_.args))W==="expressions"?d.push(...he):x[W]=he}let y=h.getArgKey(s),I=d;r&&y&&y.args.expressions&&(I=[...y.args.expressions,...d]);let N=o?new o({expressions:I}):new A({expressions:I});for(let[P,k]of Object.entries(x))N.setArgKey(P,k);return s!==void 0&&h.setArgKey(s,N),h}function lu(i,e){let{instance:t,arg:s,append:r=!0,copy:n=!0,prefix:a,into:o,dialect:c,...l}=e,u=Ve(t,n),d=J(i).filter(f=>f!==void 0).map(f=>H(f,{into:o,prefix:a,dialect:c,...l})),x=u?.getArgKey(s);return s!==void 0&&(r&&x?u?.setArgKey(s,[...x,...d]):u?.setArgKey(s,d)),u}function If(i,e={}){let{instance:t,arg:s,into:r,append:n=!0,copy:a=!0,dialect:o,...c}=e,u=Array.from(J(i)).filter(N=>N!==void 0&&N!=="");if(u.length===0)return t;let h=Ve(t,a),d=h.getArgKey(s),x=[...u];n&&d instanceof A&&(x=[r&&"this"in d.args?d.args.this:d,...u]);let f=N=>N instanceof Ee?new Oe({this:N}):N,y;if(0<x.length){let N=x.map(W=>H(W,{dialect:o,copy:a,...c})),[P,...k]=N,_=P;0<k.length&&(_=f(P)),y=k.reduce((W,he)=>new ce({this:W,expression:f(he)}),_)}let I=r&&y?new r({this:y}):y;return I&&s!==void 0&&h.setArgKey(s,I),h}function ow(i){let{instance:e,alias:t,as:s,recursive:r,materialized:n,append:a=!0,dialect:o,copy:c=!0,scalar:l,...u}=i,h=H(t,{dialect:o,into:ie,...u}),d=H(s,{dialect:o,copy:c,...u});l&&!(d instanceof Te)&&(d=new Te({this:d}));let x=new Tt({this:d,alias:h,materialized:n,scalar:l});return Ld([x],{instance:e,arg:"with",append:a,copy:c,into:tt,properties:r?{recursive:r}:{}})}function qA(i,e,t={}){let{dialect:s,copy:r=!0,wrap:n=!0,...a}=t,c=Array.from(J(i)).filter(d=>d!==void 0&&d!=="").map(d=>H(d,{dialect:s,copy:r,...a})),[l,...u]=c,h=l;0<u.length&&n&&(h=Yn(h,Ee)||h);for(let d of u)h=new e({this:h,expression:n&&Yn(d,Ee)||d});return h}function Yn(i,e){return i instanceof e?new Oe({this:i}):i}function ml(i){return typeof i=="string"?R.string(i):typeof i=="number"?R.number(i):R.string(String(i))}function pe(){return new Ze({})}function Qe(){return new ot({this:!0})}function gt(){return new ot({this:!1})}function Ot(i,e={}){let{copy:t=!1}=e;if(i instanceof A){let s=Ve(i,t);if(s)return s}if(typeof i=="string")return R.string(i);if(typeof i=="boolean")return new ot({this:i});if(i===void 0||typeof i=="number"&&isNaN(i))return pe();if(typeof i=="number")return R.number(i);if(cq.isDateTime(i)){let s=i.toFormat("yyyy-MM-dd HH:mm:ss"),r=R.string(s),n;return i.zoneName&&i.zoneName!=="UTC"&&(n=R.string(i.zoneName)),new ou({this:r,zone:n})}if(i instanceof Date){let r=cq.fromJSDate(i).toFormat("yyyy-MM-dd HH:mm:ss"),n=R.string(r);return new ou({this:n,zone:void 0})}if(Array.isArray(i))return new ue({expressions:i.map(s=>Ot(s,{copy:t}))});if(i!==null&&typeof i=="object"){let s=Object.entries(i);return new io({keys:new ue({expressions:s.map(([r])=>R.string(r))}),values:new ue({expressions:s.map(([,r])=>Ot(r,{copy:t}))})})}throw new Error(`Cannot convert ${i}`)}function Q(i){if(!i)throw new Error("Cannot convert empty name into var.");return i instanceof A&&(i=i.name),new qe({this:i})}function CA(i,e={}){let{copy:t=!0,dialect:s,...r}=e,n=Array.from(J(i));return new ue({expressions:n.map(a=>H(a,{copy:t,dialect:s,...r}))})}function sv(i,e={}){let{copy:t=!0,dialect:s,...r}=e,n=Array.from(J(i));return new Ge({expressions:n.map(a=>H(a,{copy:t,dialect:s,...r}))})}function rv(i,e,t={}){let{dialect:s}=t,r=Nf(i,{dialect:s}),n=Nf(e,{dialect:s});return new sn({this:r,kind:"table",actions:[new Mr({this:n})]})}function iv(i,e,t,s={}){let{exists:r,dialect:n}=s,a=Nf(i,{dialect:n}),o=iw(e,{dialect:n}),c=iw(t,{dialect:n});return new sn({this:a,kind:"table",actions:[new ga({this:o,to:c,exists:r})]})}function RN(i,e={}){let{exclude:t=""}=e,s=new Set;for(let r of i.findAll(B)){let n=r.table;n&&n!==t&&s.add(n)}return s}function nv(i,e={}){let{dialect:t,identify:s=!1}=e,r=H(i,{into:V,dialect:t});if(!r)throw new Error(`Cannot parse ${i}`);return r.parts.map(n=>s||!wm.test(n.name)?n.sql({dialect:t,identify:!0,copy:!1,comments:!1}):n.name).join(".")}function hN(i,e,...t){for(let[s,r]of Object.entries(i.args)){let n=Array.isArray(r),a=n?r:[r],o=[];for(let c of a)if(c instanceof A){let l=e(c,...t),u=Array.isArray(l)?l:[l];o.push(...u)}else o.push(c);n?i.setArgKey(s,o):i.setArgKey(s,o[0])}}function av(i,e,t){let s=Array.from(i.dfs({prune:t})),r=i;for(;0<s.length;){let n=s.pop();r=e(n),r!==n&&(n.replace(r),r instanceof A&&s.push(r))}return r}function KR(i,e={}){let{dialect:t,copy:s=!0}=e;return Ff(Nf(i,{dialect:t,copy:s}),{dialect:t}).parts.map(r=>r.name).join(".")}function ov(i,e,t={}){let{dialect:s,copy:r=!0}=t,n={};for(let[o,c]of Object.entries(e))n[KR(o,{dialect:s})]=c;function a(o){if(o instanceof V&&o.meta.replace!==!1){let c=KR(o,{dialect:s}),l=n[c];if(l){let u=Nf(l,{dialect:s});for(let[h,d]of Object.entries(o.args))["this","db","catalog"].includes(h)||u.setArgKey(h,d);return u.addComments([c]),u}}return o}return i.transform(a,{copy:r})}function cv(i,e=[],t={}){let s=0;function r(n){if(n instanceof Ds){if(typeof n.args.this=="string"){let a=t[n.args.this];if(a!==void 0)return Ot(a)}else if(s<e.length)return Ot(e[s++])}return n}return i.transform(r)}function pv(i,e,t={}){let{dialect:s,copy:r=!0}=t,n={};for(let[o,c]of Object.entries(e))n[KR(o,{dialect:s})]=c;function a(o){if(o instanceof V){let c=KR(o,{dialect:s}),l=n[c];if(l){let u=typeof l=="function"?l():l,h=o.alias||c,d=u.subquery(h);return d.comments=[`source: ${c}`],d.transform(a,{copy:!1})}}return o}return i.transform(a,{copy:r})}var Er=[ee,Xe],NN=[FA,DN],PI=[R,ot],bI=[R,ot,Ze],lv=new Set([xs,jt,cr,cs,fs,pr,Ts,vs,Pt]);function Sl(i,e){if(!$(i,"string",A)||i===void 0)return!1;if(i instanceof A)return i.isType(e);let t=typeof e!="string"&&Pf(e)?e:[e];for(let r of t)if(r.toLowerCase()===i.toLowerCase())return!0;let s=ut(ht,i.toString());if(s===void 0)return!1;for(let r of t)if(r===s)return!0;return!1}function rA(i,e,t=[]){let s=[],r=e??TA(i)-1;for(let[n,a]of Object.entries(i))r===1||typeof a!="object"||a===void 0?s.push([...t,n]):2<=r&&s.push(...rA(a,r-1,[...t,n]));return s}function tN(i,e,t={}){let{raiseOnMissing:s=!0}=t,r=i;for(let[n,a]of e){if(typeof r!="object"||r===void 0){if(s)throw new ms(`Unknown ${n==="this"?"table":n}: ${a}`);return}let o=r[a];if(o===void 0||o===void 0){if(s)throw new ms(`Unknown ${n==="this"?"table":n}: ${a}`);return}r=o}return r}function cw(i,e,t){if(!e.length)return i;if(e.length===1)return i[e[0]]=t,i;let s=i;for(let r=0;r<e.length-1;r++)(!(e[r]in s)||typeof s[e[r]]!="object"||s[e[r]]===void 0)&&(s[e[r]]={}),s=s[e[r]];return s[e[e.length-1]]=t,i}function uv(i){if(i==null)return{};if(typeof i=="object"&&!Array.isArray(i))return i;if(typeof i=="string")return Object.fromEntries(i.split(",").map(e=>{let[t,s]=e.split(":").map(r=>r.trim());return[t,s]}));if(Array.isArray(i))return Object.fromEntries(i.map(e=>[e.trim(),void 0]));throw new Error(`Invalid mapping provided: ${typeof i}`)}function eN(i,e={}){let{dialect:t,isTable:s=!1,normalize:r=!0}=e,n=typeof i=="string"?Bf(i,{dialect:t}):i.copy();return r?(n.meta.isTable=s,se.getOrRaise(t).normalizeIdentifier(n)):n}var sN=class{get dialect(){}get empty(){return!0}hasColumn(e,t,s){let r=typeof t=="string"?t:t.name;return this.columnNames(e,s).includes(r)}getUdfType(e,t){return O.build("unknown")}},pw=class extends sN{constructor(e,t){super(),this.mapping=e||{},this.udfMapping=t||{},this.mappingTrie=is(rA(this.mapping,this.depth()).map(s=>[...s].reverse())),this.udfTrie=is(rA(this.udfMapping,this.udfDepth()).map(s=>[...s].reverse()))}get empty(){return Object.keys(this.mapping).length===0}depth(){return TA(this.mapping)}udfDepth(){return TA(this.udfMapping)}get supportedTableArgs(){if(!this._supportedTableArgs&&!this.empty){let e=this.depth();if(!e)this._supportedTableArgs=[];else if(1<=e&&e<=3)this._supportedTableArgs=nw.slice(0,e);else throw new ms(`Invalid mapping shape. Depth: ${e}`)}return this._supportedTableArgs||[]}tableParts(e){return[...e.parts].reverse().map(t=>t.name)}udfParts(e){let t=e.parent;return[...t instanceof Se?[...t.flatten()].map(r=>r.name):[e.name]].reverse().slice(0,this.udfDepth())}findInTrie(e,t,s){let{raiseOnMissing:r}=s,[n,a]=no(t,e);if(n!==0){if(n===1){let o=rA(a);if(o.length===1)e.push(...o[0]);else{if(r){let c=e.join("."),l=o.map(u=>u.join(".")).join(", ");throw new ms(`Ambiguous mapping for ${c}: ${l}.`)}return}}return e}}find(e,t={}){let{raiseOnMissing:s=!0}=t,r=this.tableParts(e).slice(0,this.supportedTableArgs.length),n=this.findInTrie(r,this.mappingTrie,{raiseOnMissing:s});if(n)return this.nestedGet(n,void 0,{raiseOnMissing:s})}findUdf(e,t={}){let{raiseOnMissing:s=!1}=t,r=this.udfParts(e),n=this.findInTrie(r,this.udfTrie,{raiseOnMissing:s});if(!n)return;let a=[...n].reverse();return tN(this.udfMapping,n.map((o,c)=>[o,a[c]]),{raiseOnMissing:s})}nestedGet(e,t,s={}){let{raiseOnMissing:r=!0}=s,n=[...e].reverse();return tN(t||this.mapping,this.supportedTableArgs.map((a,o)=>[a,n[o]]),{raiseOnMissing:r})}},Uf=class i extends G(pw,sN){constructor(t,s={}){let r,n,a,o,c;if(t&&("schema"in t||"udfMapping"in t||"visible"in t||"dialect"in t||"normalize"in t)){let h=t;r=h.schema||{},n=h.visible,a=h.dialect,o=h.normalize??!0,c=h.udfMapping}else r=t||{},{visible:n,dialect:a,normalize:o=!0,udfMapping:c}=s;let l=a?se.getOrRaise(a):new se,u=c||{};super(o?i.normalizeSchemaStatic(r,l,{normalize:o}):r,o?i.normalizeUdfsStatic(u,l,{normalize:o}):u);this._typeCache={};this._depth=0;this.visible=n||{},this.normalize=o,this._dialect=l}static fromMappingSchema(t){return new i(t.mapping,{visible:t.visible,dialect:t.dialect,normalize:t.normalize,udfMapping:t.udfMapping})}get dialect(){return this._dialect}depth(){return!this.empty&&!this._depth&&(this._depth=super.depth()-1),this._depth}copy(t={}){return new i(t.schema??{...this.mapping},{visible:t.visible??{...this.visible},dialect:t.dialect??this.dialect,normalize:t.normalize??this.normalize,udfMapping:t.udfMapping??{...this.udfMapping}})}find(t,s={}){let{ensureDataTypes:r=!1}=s,n=super.find(t,s);return!r||typeof n!="object"||n===null?n:Object.fromEntries(Object.entries(n).map(([a,o])=>[a,typeof o=="string"?this.toDataType(o):o]))}addTable(t,s,r={}){let{dialect:n,normalize:a,matchDepth:o=!0}=r,c=this.normalizeTable(t,n,a);if(o&&!this.empty&&c.parts.length!==this.depth())throw new ms(`Table ${c.sql()} must match the schema's nesting level: ${this.depth()}.`);let l=Object.fromEntries(Object.entries(uv(s)).map(([d,x])=>[this.normalizeName(d,n,{isTable:!1,normalize:a}),x]));if(this.find(c,{raiseOnMissing:!1})&&!Object.keys(l).length)return;let h=this.tableParts(c);cw(this.mapping,[...h].reverse(),l),is([h],this.mappingTrie)}columnNames(t,s={}){let{onlyVisible:r=!1,dialect:n,normalize:a}=s,o=this.normalizeTable(t,n,a),c=this.find(o);if(!c||typeof c!="object")return[];let l=Object.keys(c);if(!r||!Object.keys(this.visible).length)return l;let u=this.nestedGet(this.tableParts(o),this.visible,{raiseOnMissing:!1}),h=u instanceof Set?u:u||[];return l.filter(d=>h instanceof Set?h.has(d):h.includes(d))}getColumnType(t,s,r={}){let{dialect:n,normalize:a}=r,o=this.normalizeTable(t,n,a),c=this.normalizeName(typeof s=="string"?s:s.args.this,n,{isTable:!1,normalize:a}),l=this.find(o,{raiseOnMissing:!1});if(l&&typeof l=="object"){let u=l[c];if(u instanceof O)return u;if(typeof u=="string")return this.toDataType(u,n)}return O.build("unknown")}hasColumn(t,s,r){let{dialect:n,normalize:a}=r||{},o=this.normalizeTable(t,n,a),c=this.normalizeName(typeof s=="string"?s:s.args.this,n,{isTable:!1,normalize:a}),l=this.find(o,{raiseOnMissing:!1});return l?c in l:!1}getUdfType(t,s={}){let{dialect:r,normalize:n}=s,a=this.normalizeUdf(t,r,n),o=this.findInTrie(a,this.udfTrie,{raiseOnMissing:!1});if(!o)return O.build("unknown");let c=[...o].reverse(),l=tN(this.udfMapping,o.map((u,h)=>[u,c[h]]),{raiseOnMissing:!1});return l instanceof O?l:typeof l=="string"?this.toDataType(l,r):O.build("unknown")}normalizeUdf(t,s,r){let n=s?se.getOrRaise(s):this._dialect,a=r??this.normalize,o;if(typeof t=="string"){let l=H(t,{dialect:n});if(l instanceof je)o=l;else if(l instanceof Se){let u=[...l.flatten()],h=u[u.length-1];if(!(h instanceof je))throw new ms(`Unable to parse UDF from: ${JSON.stringify(t)}`);o=h}else throw new ms(`Unable to parse UDF from: ${JSON.stringify(t)}`)}else o=t;let c=this.udfParts(o);return a?c.map(l=>this.normalizeName(l,s,{isTable:!0,normalize:r})):c}toDataType(t,s){if(!this._typeCache[t]){let r=s?se.getOrRaise(s):this._dialect,n=O.build(t,{dialect:r,udt:r._constructor.SUPPORTS_USER_DEFINED_TYPES});n?.transform(a=>r.normalizeIdentifier(a),{copy:!1}),this._typeCache[t]=n}return this._typeCache[t]}normalizeTable(t,s,r){let n=s?se.getOrRaise(s):this._dialect,a=r??this.normalize,o=H(t,{into:V,dialect:n,copy:a});if(a)for(let c of o.parts)c instanceof U&&c.replace(eN(c,{dialect:n,isTable:!0,normalize:a}));return o}normalizeName(t,s,r={}){let{isTable:n=!1,normalize:a}=r,o=s?se.getOrRaise(s):this._dialect;return eN(t,{dialect:o,isTable:n,normalize:a??this.normalize}).name}static normalizeSchemaStatic(t,s,r){let{normalize:n}=r;if(!n||!Object.keys(t).length)return t;let a={},o=rA(t);if(!o.length)return t;for(let c of o){let l=tN(t,c.map(x=>[x,x]),{raiseOnMissing:!1});if(typeof l!="object"||l===void 0)throw new ms(`Table ${c.slice(0,-1).join(".")} must match the schema's nesting level: ${o[0].length}.`);let u=Object.entries(l);if(!u.length)throw new ms(`Table ${c.slice(0,-1).join(".")} must have at least one column`);let h=u[0][1];if(h!=null&&typeof h=="object"&&!(h instanceof A)){let x=rA(l);throw new ms(`Table ${[...c,...x[0]||[]].join(".")} must match the schema's nesting level: ${o[0].length}.`)}let d=c.map(x=>eN(x,{dialect:s,isTable:!0,normalize:n}).name);for(let[x,f]of u)cw(a,[...d,eN(x,{dialect:s,normalize:n}).name],f)}return a}static normalizeUdfsStatic(t,s,r){let{normalize:n}=r;if(!n||!Object.keys(t).length)return t;let a={};for(let o of rA(t,TA(t))){let c=tN(t,o.map(u=>[u,u]),{raiseOnMissing:!1}),l=o.map(u=>eN(u,{dialect:s,isTable:!0,normalize:n}).name);cw(a,l,c)}return a}};function dN(i,e={}){return i instanceof sN?i:new Uf(i,e)}export{Bt as a,bt as b,Lt as c,S as d,iN as e,za as f,Wn as g,xt as h,iA as i,dl as j,Aw as k,dw as l,nA as m,$ as n,te as o,ft as p,Rt as q,m as r,bq as s,Lq as t,wq as u,Mq as v,Dq as w,kq as x,_q as y,qq as z,Uq as A,vq as B,Fq as C,Bq as D,kw as E,$q as F,Gq as G,Yq as H,Vq as I,Hq as J,Wq as K,rA as L,tN as M,cw as N,eN as O,sN as P,Uf as Q,dN as R,wi as S,cA as T,hF as U,pA as V,jn as W,Xq as X,gs as Y,xl as Z,TF as _,lN as $,xN as aa,zq as ba,M as ca,J as da,Za as ea,ED as fa,fN as ga,AD as ha,TA as ia,mA as ja,lD as ka,TN as la,SN as ma,Ol as na,Ff as oa,$f as pa,xB as qa,_I as ra,xU as sa,ns as ta,DI as ua,RU as va,UD as wa,NU as xa,FD as ya,Gf as za,KI as Aa,ey as Ba,A as Ca,ye as Da,Ne as Ea,z as Fa,Nt as Ga,gr as Ha,GA as Ia,qt as Ja,Hs as Ka,Vi as La,YA as Ma,VA as Na,HA as Oa,Ro as Pa,Hi as Qa,vi as Ra,WA as Sa,jA as Ta,No as Ua,tt as Va,$t as Wa,JA as Xa,ie as Ya,Ie as Za,as as _a,XA as $a,ga as ab,Mr as bb,zA as cb,Or as db,QA as eb,Js as fb,Ji as gb,ZA as hb,sr as ib,_o as jb,ed as kb,qo as lb,td as mb,zi as nb,Qi as ob,Je as pb,Zt as qb,U as rb,$o as sb,Vo as tb,Wo as ub,sd as vb,rd as wb,_s as xb,Xs as yb,Yt as zb,Et as Ab,oe as Bb,Ko as Cb,Ka as Db,Rr as Eb,fe as Fb,Ht as Gb,L as Hb,id as Ib,nd as Jb,ad as Kb,od as Lb,cd as Mb,rc as Nb,en as Ob,Ge as Pb,ld as Qb,Da as Rb,lp as Sb,V as Tb,qe as Ub,At as Vb,cc as Wb,Dm as Xb,yr as Yb,at as Zb,xe as _b,rr as $b,O as ac,hc as bc,gc as cc,Ec as dc,sn as ec,hd as fc,gd as gc,Re as hc,Cr as ic,kr as jc,Wt as kc,Ed as lc,Ad as mc,We as nc,dd as oc,aa as pc,oa as qc,qs as rc,xd as sc,up as tc,bi as uc,Pc as vc,fd as wc,ca as xc,Tr as yc,Td as zc,Sd as Ac,md as Bc,kc as Cc,Mi as Dc,hp as Ec,Tt as Fc,da as Gc,Nl as Hc,B as Ic,lA as Jc,bA as Kc,gp as Lc,vc as Mc,Bc as Nc,oo as Oc,Zn as Pc,Od as Qc,jc as Rc,pn as Sc,km as Tc,la as Uc,Xc as Vc,ln as Wc,vA as Xc,Fi as Yc,Zc,kt as _c,R as $c,Ur as ad,Rd as bd,ir as cd,Br as dd,$r as ed,Yr as fd,Hr as gd,Wr as hd,Jr as id,Xr as jd,ws as kd,va as ld,Qr as md,Nd as nd,Rn as od,ar as pd,Fa as qd,ai as rd,zs as sd,Qs as td,os as ud,In as vd,yn as wd,Id as xd,Ep as yd,yd as zd,Ap as Ad,Cd as Bd,or as Cd,Ei as Dd,Ln as Ed,Zs as Fd,ka as Gd,xi as Hd,As as Id,wn as Jd,ds as Kd,_a as Ld,mi as Md,qa as Nd,Ni as Od,Mn as Pd,Ba as Qd,$a as Rd,Ua as Sd,Ke as Td,Xe as Ud,Vt as Vd,ee as Wd,Te as Xd,we as Yd,Cl as Zd,Ds as _d,Ze as $d,ot as ae,q as be,hs as ce,Dt as de,Ks as ee,Ce as fe,g as ge,D as he,jt as ie,cs as je,Ts as ke,Pt as le,fa as me,St as ne,zn as oe,Lr as pe,wr as qe,kn as re,Ls as se,Le as te,Ta as ue,wl as ve,Ml as we,Sa as xe,Dl as ye,mt as ze,Se as Ae,Mt as Be,me as Ce,Ps as De,Gs as Ee,ct as Fe,Be as Ge,Me as He,Us as Ie,ha as Je,_e as Ke,sp as Le,Ut as Me,Pd as Ne,$e as Oe,Bi as Pe,Ns as Qe,st as Re,ke as Se,np as Te,be as Ue,Oe as Ve,It as We,ss as Xe,it as Ye,xT as Ze,sy as _e,PT as $e,LT as af,MT as bf,ry as cf,kT as df,iy as ef,_T as ff,ny as gf,ay as hf,oy as if,cy as jf,qT as kf,vT as lf,FT as mf,py as nf,ly as of,uy as pf,hy as qf,gy as rf,Ey as sf,Ay as tf,dy as uf,xy as vf,fy as wf,Ty as xf,Sy as yf,my as zf,Oy as Af,Ry as Bf,kl as Cf,$T as Df,Ny as Ef,Iy as Ff,yy as Gf,Cy as Hf,Py as If,GT as Jf,je as Kf,by as Lf,ue as Mf,Ly as Nf,wy as Of,Vf as Pf,Cm as Qf,My as Rf,Dy as Sf,VT as Tf,ky as Uf,_y as Vf,qy as Wf,Uy as Xf,Hf as Yf,vy as Zf,fT as _f,po as $f,Fy as ag,Fs as bg,By as cg,$y as dg,Yy as eg,Wf as fg,jf as gg,_l as hg,Vy as ig,Hy as jg,Wy as kg,jy as lg,Jy as mg,dp as ng,jT as og,JT as pg,XT as qg,Xy as rg,zy as sg,Qy as tg,zT as ug,Zy as vg,TT as wg,Bn as xg,Ky as yg,eC as zg,tC as Ag,nt as Bg,X as Cg,Jf as Dg,rC as Eg,iC as Fg,RA as Gg,nC as Hg,Oa as Ig,rt as Jg,ql as Kg,Gt as Lg,eS as Mg,vl as Ng,aC as Og,oC as Pg,cC as Qg,pC as Rg,lC as Sg,uC as Tg,hC as Ug,gC as Vg,EC as Wg,AC as Xg,dC as Yg,xC as Zg,fC as _g,$i as $g,tS as ah,Ra as bh,Fl as ch,Xf as dh,TC as eh,Na as fh,sS as gh,SC as hh,mC as ih,OC as jh,zf as kh,Ql as lh,RC as mh,Qf as nh,NC as oh,IC as ph,ST as qh,mT as rh,OT as sh,RT as th,yt as uh,yC as vh,ts as wh,wa as xh,bs as yh,rS as zh,fr as Ah,_i as Bh,iS as Ch,CC as Dh,PC as Eh,nS as Fh,aS as Gh,oS as Hh,cS as Ih,pS as Jh,bC as Kh,lS as Lh,uS as Mh,hS as Nh,LC as Oh,gS as Ph,xp as Qh,wC as Rh,MC as Sh,DC as Th,kC as Uh,_C as Vh,Gi as Wh,Pi as Xh,qC as Yh,Xl as Zh,ru as _h,ES as $h,Zl as ai,ro as bi,UC as ci,iu as di,AS as ei,dS as fi,vC as gi,xS as hi,FC as ii,fS as ji,SS as ki,La as li,Vn as mi,Zf as ni,Kf as oi,BC as pi,$C as qi,mS as ri,GC as si,YC as ti,VC as ui,HC as vi,OS as wi,WC as xi,rs as yi,ET as zi,ge as Ai,Bl as Bi,NS as Ci,yS as Di,jC as Ei,JC as Fi,XC as Gi,zC as Hi,QC as Ii,ZC as Ji,KC as Ki,eP as Li,Ia as Mi,CS as Ni,sP as Oi,PS as Pi,ya as Qi,ap as Ri,rP as Si,iP as Ti,bS as Ui,nP as Vi,aP as Wi,oP as Xi,cP as Yi,pP as Zi,le as _i,Kl as $i,$l as aj,lP as bj,LS as cj,eu as dj,wS as ej,uP as fj,hP as gj,gP as hj,tT as ij,EP as jj,Gl as kj,AP as lj,dP as mj,xP as nj,fP as oj,TP as pj,SP as qj,mP as rj,Ca as sj,RP as tj,js as uj,NP as vj,ao as wj,Yl as xj,iT as yj,IP as zj,yP as Aj,pu as Bj,CP as Cj,PP as Dj,bP as Ej,Pa as Fj,LP as Gj,wP as Hj,MP as Ij,DP as Jj,Vl as Kj,kP as Lj,_P as Mj,qP as Nj,nu as Oj,UP as Pj,MS as Qj,DS as Rj,Hl as Sj,Yi as Tj,Fn as Uj,io as Vj,tu as Wj,vP as Xj,FP as Yj,BP as Zj,$P as _j,GP as $j,YP as ak,VP as bk,HP as ck,nT as dk,Ys as ek,aT as fk,kS as gk,WP as hk,jP as ik,JP as jk,_S as kk,XP as lk,zP as mk,oT as nk,ZP as ok,NT as pk,KP as qk,eb as rk,cT as sk,tb as tk,sb as uk,rb as vk,ib as wk,nb as xk,ab as yk,au as zk,ob as Ak,US as Bk,fl as Ck,Df as Dk,cb as Ek,pb as Fk,lb as Gk,gb as Hk,Pm as Ik,Eb as Jk,Ab as Kk,op as Lk,pT as Mk,db as Nk,xb as Ok,fb as Pk,Tb as Qk,Sb as Rk,bm as Sk,vS as Tk,FS as Uk,Lm as Vk,AT as Wk,mb as Xk,Ob as Yk,Rb as Zk,Nb as _k,Ib as $k,BS as al,yb as bl,Cb as cl,Pb as dl,bb as el,$S as fl,GS as gl,Lb as hl,wb as il,YS as jl,VS as kl,Mb as ll,Db as ml,kb as nl,_b as ol,er as pl,qb as ql,Tl as rl,HS as sl,mr as tl,vb as ul,Fb as vl,ba as wl,tr as xl,Bb as yl,$b as zl,Gb as Al,Yb as Bl,ks as Cl,Vb as Dl,Hb as El,Wl as Fl,jS as Gl,Gn as Hl,Wb as Il,XS as Jl,ou as Kl,jb as Ll,cp as Ml,cu as Nl,Jb as Ol,Is as Pl,IT as Ql,yT as Rl,CT as Sl,QS as Tl,Xb as Ul,ZS as Vl,zb as Wl,KS as Xl,em as Yl,tm as Zl,sm as _l,rm as $l,im as am,nm as bm,NA as cm,bN as dm,jl as em,Qb as fm,Zb as gm,BA as hm,Kb as im,eL as jm,cm as km,tL as lm,ys as mm,Ct as nm,sL as om,rL as pm,iL as qm,nL as rm,aL as sm,oL as tm,wN as um,IA as vm,yA as wm,cL as xm,pL as ym,lL as zm,uL as Am,hL as Bm,gL as Cm,EL as Dm,AL as Em,dL as Fm,xL as Gm,fL as Hm,MN as Im,TL as Jm,SL as Km,pm as Lm,mL as Mm,uo as Nm,OL as Om,RL as Pm,NL as Qm,lm as Rm,IL as Sm,um as Tm,hm as Um,yL as Vm,CL as Wm,PL as Xm,bL as Ym,LL as Zm,gm as _m,wL as $m,ML as an,_t as bn,_A as cn,wt as dn,Jl as en,Em as fn,DL as gn,Ma as hn,Ui as in,pp as jn,ce as kn,ze as ln,qi as mn,gT as nn,kL as on,_L as pn,Am as qn,dm as rn,xm as sn,qL as tn,UL as un,fm as vn,vL as wn,FA as xn,DN as yn,FL as zn,$A as An,BL as Bn,$L as Cn,GL as Dn,YL as En,VL as Fn,HL as Gn,WL as Hn,jL as In,JL as Jn,XL as Kn,zL as Ln,QL as Mn,ZL as Nn,Tm as On,Sm as Pn,KL as Qn,Rm as Rn,Nm as Sn,Im as Tn,ym as Un,ew as Vn,tw as Wn,sw as Xn,rw as Yn,$n as Zn,ho as _n,hq as $n,Fe as ao,Kt as bo,xr as co,ki as do,Z as eo,Bf as fo,JU as go,Ye as ho,HI as io,pt as jo,XU as ko,WI as lo,j as mo,jI as no,UA as oo,gq as po,Eq as qo,QU as ro,ZU as so,ev as to,Aq as uo,H as vo,Nf as wo,iw as xo,tv as yo,Yn as zo,ml as Ao,pe as Bo,Qe as Co,Ot as Do,Q as Eo,CA as Fo,RN as Go,cv as Ho,pv as Io,Er as Jo,bI as Ko,Sl as Lo,vt as Mo,$B as No,WB as Oo,t$ as Po,s$ as Qo,r$ as Ro,i$ as So,n$ as To,a$ as Uo,o$ as Vo,c$ as Wo,p$ as Xo,l$ as Yo,u$ as Zo,h$ as _o,g$ as $o,E$ as ap,A$ as bp,d$ as cp,x$ as dp,f$ as ep,T$ as fp,S$ as gp,m$ as hp,O$ as ip,R$ as jp,dT as kp,b as lp,U$ as mp,PN as np,se as op,JI as pp,iG as qp,nG as rp,aG as sp,$U as tp,oG as up,cG as vp,pG as wp,lG as xp,uG as yp,hG as zp,gG as Ap,EG as Bp,AG as Cp,dG as Dp,xG as Ep,fG as Fp,TG as Gp,SG as Hp,mG as Ip,OG as Jp,GU as Kp,RG as Lp,kI as Mp,NG as Np,IG as Op,yG as Pp,CG as Qp,PG as Rp,bG as Sp,LG as Tp,wG as Up,MG as Vp,DG as Wp,kG as Xp,_G as Yp,qG as Zp,UG as _p,vG as $p,FG as aq,BG as bq,$G as cq,C_ as dq,GG as eq,YG as fq,VG as gq,HG as hq,WG as iq,jG as jq,JG as kq,XG as lq,zG as mq,QG as nq,ZG as oq,KG as pq,eY as qq,YU as rq,tY as sq,sY as tq,yN as uq,XI as vq,P_ as wq,rY as xq,iY as yq,nY as zq,aY as Aq,oY as Bq,cY as Cq,pY as Dq,lY as Eq,uY as Fq,hY as Gq,gY as Hq,EY as Iq,AY as Jq,dY as Kq,xY as Lq,fY as Mq,TY as Nq,SY as Oq,mY as Pq,OY as Qq,RY as Rq,NY as Sq,IY as Tq,yY as Uq,OA as Vq,vf as Wq,Qn as Xq};
19
+ //# sourceMappingURL=chunk-KCNOE4DZ.js.map