sqlingo 0.11.2 → 0.12.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.
- package/CHANGELOG.md +6 -0
- package/dist/chunk-2H6QT5P4.cjs +2 -0
- package/dist/{chunk-3NY73AG6.cjs.map → chunk-2H6QT5P4.cjs.map} +1 -1
- package/dist/{chunk-OUVPP5P3.js → chunk-3XORKTWN.js} +2 -2
- package/dist/chunk-3YE276IG.cjs +2 -0
- package/dist/{chunk-MYSFSGYF.cjs.map → chunk-3YE276IG.cjs.map} +1 -1
- package/dist/chunk-4LF2YOFP.cjs +2 -0
- package/dist/{chunk-ADYA6YNL.cjs.map → chunk-4LF2YOFP.cjs.map} +1 -1
- package/dist/{chunk-QGM3ALG2.js → chunk-4VYQDKUM.js} +2 -2
- package/dist/{chunk-LH2F5QN4.js → chunk-7J2IHWOT.js} +2 -2
- package/dist/chunk-AVUHE5YK.cjs +2 -0
- package/dist/{chunk-HUMCE7OS.cjs.map → chunk-AVUHE5YK.cjs.map} +1 -1
- package/dist/chunk-AYLIJEXS.cjs +2 -0
- package/dist/{chunk-ZP4YOUOR.cjs.map → chunk-AYLIJEXS.cjs.map} +1 -1
- package/dist/chunk-BHN6NQKC.cjs +2 -0
- package/dist/{chunk-CO6DYSIN.cjs.map → chunk-BHN6NQKC.cjs.map} +1 -1
- package/dist/{chunk-5AKAN2I7.js → chunk-BQ4CDEDR.js} +2 -2
- package/dist/{chunk-5T2NZX3J.js → chunk-BURLX5CB.js} +2 -2
- package/dist/{chunk-BB2NJ5Z5.js → chunk-DVX6223T.js} +2 -2
- package/dist/{chunk-LGVPUDSN.js → chunk-E5NMASTN.js} +2 -2
- package/dist/{chunk-TDHUEJMV.js → chunk-EBJLPELF.js} +2 -2
- package/dist/{chunk-CNQXTBAR.js → chunk-FU46WFXM.js} +13 -13
- package/dist/{chunk-CNQXTBAR.js.map → chunk-FU46WFXM.js.map} +1 -1
- package/dist/chunk-G3SMRR6L.cjs +2 -0
- package/dist/{chunk-YHYAYLA2.cjs.map → chunk-G3SMRR6L.cjs.map} +1 -1
- package/dist/chunk-GCZXPOCP.cjs +2 -0
- package/dist/{chunk-KJABXPMW.cjs.map → chunk-GCZXPOCP.cjs.map} +1 -1
- package/dist/chunk-JBVAM4OC.cjs +2 -0
- package/dist/{chunk-HGX7B6SE.cjs.map → chunk-JBVAM4OC.cjs.map} +1 -1
- package/dist/chunk-KTGMYT4V.cjs +2 -0
- package/dist/{chunk-I346N252.cjs.map → chunk-KTGMYT4V.cjs.map} +1 -1
- package/dist/chunk-NG7VOB44.cjs +2 -0
- package/dist/{chunk-QMTVNC6S.cjs.map → chunk-NG7VOB44.cjs.map} +1 -1
- package/dist/{chunk-Y2BKXUW3.js → chunk-NQGKQUUD.js} +2 -2
- package/dist/chunk-PJWEY6A6.cjs +4 -0
- package/dist/{chunk-YLWTJCZO.cjs.map → chunk-PJWEY6A6.cjs.map} +1 -1
- package/dist/{chunk-IOCNJOGM.js → chunk-Q7SWBN6Z.js} +2 -2
- package/dist/{chunk-XQFP2APL.js → chunk-QBLOOHY2.js} +2 -2
- package/dist/chunk-QDPEEKQT.cjs +2 -0
- package/dist/{chunk-7UY2GD7U.cjs.map → chunk-QDPEEKQT.cjs.map} +1 -1
- package/dist/{chunk-35GMMRT3.js → chunk-RJXOZQWF.js} +2 -2
- package/dist/{chunk-CWTDCJNP.js → chunk-SELHDL3F.js} +2 -2
- package/dist/{chunk-6VHNVAGL.js → chunk-SH4MSGSQ.js} +2 -2
- package/dist/{chunk-SK5E25IR.js → chunk-SOD4YEVS.js} +2 -2
- package/dist/{chunk-M6VUHVCA.cjs → chunk-T354W3XY.cjs} +14 -14
- package/dist/chunk-T354W3XY.cjs.map +1 -0
- package/dist/{chunk-DZ36JJ2K.js → chunk-TE5PVYWN.js} +2 -2
- package/dist/{chunk-OL2ZR42U.js → chunk-V2UO4NDE.js} +2 -2
- package/dist/chunk-WCHVGFME.cjs +2 -0
- package/dist/{chunk-JWY7HB5W.cjs.map → chunk-WCHVGFME.cjs.map} +1 -1
- package/dist/{chunk-46ZYFFUB.cjs → chunk-WHSHFARN.cjs} +2 -2
- package/dist/{chunk-46ZYFFUB.cjs.map → chunk-WHSHFARN.cjs.map} +1 -1
- package/dist/chunk-X37FNPMF.cjs +2 -0
- package/dist/{chunk-FAV7YXGM.cjs.map → chunk-X37FNPMF.cjs.map} +1 -1
- package/dist/{chunk-24VN32FG.js → chunk-XXX4AZ7O.js} +2 -2
- package/dist/chunk-YCMON6GN.cjs +3 -0
- package/dist/{chunk-LMYBRBST.cjs.map → chunk-YCMON6GN.cjs.map} +1 -1
- package/dist/chunk-ZLD5Q5S4.cjs +2 -0
- package/dist/{chunk-C27ZLT7L.cjs.map → chunk-ZLD5Q5S4.cjs.map} +1 -1
- package/dist/dialects/athena.cjs +1 -1
- package/dist/dialects/athena.d.cts +1 -1
- package/dist/dialects/athena.d.ts +1 -1
- package/dist/dialects/athena.js +1 -1
- package/dist/dialects/bigquery.cjs +1 -1
- package/dist/dialects/bigquery.d.cts +1 -1
- package/dist/dialects/bigquery.d.ts +1 -1
- package/dist/dialects/bigquery.js +1 -1
- package/dist/dialects/clickhouse.cjs +1 -1
- package/dist/dialects/clickhouse.cjs.map +1 -1
- package/dist/dialects/clickhouse.d.cts +1 -1
- package/dist/dialects/clickhouse.d.ts +1 -1
- package/dist/dialects/clickhouse.js +1 -1
- package/dist/dialects/clickhouse.js.map +1 -1
- package/dist/dialects/databricks.cjs +1 -1
- package/dist/dialects/databricks.d.cts +1 -1
- package/dist/dialects/databricks.d.ts +1 -1
- package/dist/dialects/databricks.js +1 -1
- package/dist/dialects/doris.cjs +1 -1
- package/dist/dialects/doris.d.cts +1 -1
- package/dist/dialects/doris.d.ts +1 -1
- package/dist/dialects/doris.js +1 -1
- package/dist/dialects/dremio.cjs +1 -1
- package/dist/dialects/dremio.d.cts +1 -1
- package/dist/dialects/dremio.d.ts +1 -1
- package/dist/dialects/dremio.js +1 -1
- package/dist/dialects/drill.cjs +1 -1
- package/dist/dialects/drill.d.cts +1 -1
- package/dist/dialects/drill.d.ts +1 -1
- package/dist/dialects/drill.js +1 -1
- package/dist/dialects/druid.cjs +1 -1
- package/dist/dialects/druid.d.cts +1 -1
- package/dist/dialects/druid.d.ts +1 -1
- package/dist/dialects/druid.js +1 -1
- package/dist/dialects/duckdb.cjs +13 -13
- package/dist/dialects/duckdb.d.cts +2 -2
- package/dist/dialects/duckdb.d.ts +2 -2
- package/dist/dialects/duckdb.js +1 -1
- package/dist/dialects/dune.cjs +1 -1
- package/dist/dialects/dune.d.cts +1 -1
- package/dist/dialects/dune.d.ts +1 -1
- package/dist/dialects/dune.js +1 -1
- package/dist/dialects/exasol.cjs +1 -1
- package/dist/dialects/exasol.d.cts +1 -1
- package/dist/dialects/exasol.d.ts +1 -1
- package/dist/dialects/exasol.js +1 -1
- package/dist/dialects/fabric.cjs +1 -1
- package/dist/dialects/fabric.d.cts +1 -1
- package/dist/dialects/fabric.d.ts +1 -1
- package/dist/dialects/fabric.js +1 -1
- package/dist/dialects/hive.cjs +1 -1
- package/dist/dialects/hive.d.cts +2 -2
- package/dist/dialects/hive.d.ts +2 -2
- package/dist/dialects/hive.js +1 -1
- package/dist/dialects/materialize.cjs +1 -1
- package/dist/dialects/materialize.d.cts +1 -1
- package/dist/dialects/materialize.d.ts +1 -1
- package/dist/dialects/materialize.js +1 -1
- package/dist/dialects/mysql.cjs +1 -1
- package/dist/dialects/mysql.d.cts +1 -1
- package/dist/dialects/mysql.d.ts +1 -1
- package/dist/dialects/mysql.js +1 -1
- package/dist/dialects/oracle.cjs +1 -1
- package/dist/dialects/oracle.d.cts +1 -1
- package/dist/dialects/oracle.d.ts +1 -1
- package/dist/dialects/oracle.js +1 -1
- package/dist/dialects/postgres.cjs +1 -1
- package/dist/dialects/postgres.d.cts +1 -1
- package/dist/dialects/postgres.d.ts +1 -1
- package/dist/dialects/postgres.js +1 -1
- package/dist/dialects/presto.cjs +1 -1
- package/dist/dialects/presto.d.cts +1 -1
- package/dist/dialects/presto.d.ts +1 -1
- package/dist/dialects/presto.js +1 -1
- package/dist/dialects/prql.cjs +1 -1
- package/dist/dialects/prql.d.cts +1 -1
- package/dist/dialects/prql.d.ts +1 -1
- package/dist/dialects/prql.js +1 -1
- package/dist/dialects/redshift.cjs +1 -1
- package/dist/dialects/redshift.d.cts +1 -1
- package/dist/dialects/redshift.d.ts +1 -1
- package/dist/dialects/redshift.js +1 -1
- package/dist/dialects/risingwave.cjs +1 -1
- package/dist/dialects/risingwave.d.cts +1 -1
- package/dist/dialects/risingwave.d.ts +1 -1
- package/dist/dialects/risingwave.js +1 -1
- package/dist/dialects/singlestore.cjs +1 -1
- package/dist/dialects/singlestore.d.cts +1 -1
- package/dist/dialects/singlestore.d.ts +1 -1
- package/dist/dialects/singlestore.js +1 -1
- package/dist/dialects/snowflake.cjs +1 -1
- package/dist/dialects/snowflake.d.cts +1 -1
- package/dist/dialects/snowflake.d.ts +1 -1
- package/dist/dialects/snowflake.js +1 -1
- package/dist/dialects/solr.cjs +1 -1
- package/dist/dialects/solr.d.cts +1 -1
- package/dist/dialects/solr.d.ts +1 -1
- package/dist/dialects/solr.js +1 -1
- package/dist/dialects/spark.cjs +1 -1
- package/dist/dialects/spark.d.cts +1 -1
- package/dist/dialects/spark.d.ts +1 -1
- package/dist/dialects/spark.js +1 -1
- package/dist/dialects/spark2.cjs +1 -1
- package/dist/dialects/spark2.d.cts +1 -1
- package/dist/dialects/spark2.d.ts +1 -1
- package/dist/dialects/spark2.js +1 -1
- package/dist/dialects/sqlite.cjs +1 -1
- package/dist/dialects/sqlite.d.cts +1 -1
- package/dist/dialects/sqlite.d.ts +1 -1
- package/dist/dialects/sqlite.js +1 -1
- package/dist/dialects/starrocks.cjs +1 -1
- package/dist/dialects/starrocks.d.cts +1 -1
- package/dist/dialects/starrocks.d.ts +1 -1
- package/dist/dialects/starrocks.js +1 -1
- package/dist/dialects/tableau.cjs +1 -1
- package/dist/dialects/tableau.d.cts +1 -1
- package/dist/dialects/tableau.d.ts +1 -1
- package/dist/dialects/tableau.js +1 -1
- package/dist/dialects/teradata.cjs +1 -1
- package/dist/dialects/teradata.d.cts +1 -1
- package/dist/dialects/teradata.d.ts +1 -1
- package/dist/dialects/teradata.js +1 -1
- package/dist/dialects/trino.cjs +1 -1
- package/dist/dialects/trino.d.cts +1 -1
- package/dist/dialects/trino.d.ts +1 -1
- package/dist/dialects/trino.js +1 -1
- package/dist/dialects/tsql.cjs +1 -1
- package/dist/dialects/tsql.d.cts +2 -2
- package/dist/dialects/tsql.d.ts +2 -2
- package/dist/dialects/tsql.js +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{tokens-BSc93AMH.d.ts → tokens-CbZte-co.d.cts} +11 -1
- package/dist/{tokens-BSc93AMH.d.cts → tokens-CbZte-co.d.ts} +11 -1
- package/package.json +1 -1
- package/dist/chunk-3NY73AG6.cjs +0 -2
- package/dist/chunk-7UY2GD7U.cjs +0 -2
- package/dist/chunk-ADYA6YNL.cjs +0 -2
- package/dist/chunk-C27ZLT7L.cjs +0 -2
- package/dist/chunk-CO6DYSIN.cjs +0 -2
- package/dist/chunk-FAV7YXGM.cjs +0 -2
- package/dist/chunk-HGX7B6SE.cjs +0 -2
- package/dist/chunk-HUMCE7OS.cjs +0 -2
- package/dist/chunk-I346N252.cjs +0 -2
- package/dist/chunk-JWY7HB5W.cjs +0 -2
- package/dist/chunk-KJABXPMW.cjs +0 -2
- package/dist/chunk-LMYBRBST.cjs +0 -3
- package/dist/chunk-M6VUHVCA.cjs.map +0 -1
- package/dist/chunk-MYSFSGYF.cjs +0 -2
- package/dist/chunk-QMTVNC6S.cjs +0 -2
- package/dist/chunk-YHYAYLA2.cjs +0 -2
- package/dist/chunk-YLWTJCZO.cjs +0 -4
- package/dist/chunk-ZP4YOUOR.cjs +0 -2
- /package/dist/{chunk-OUVPP5P3.js.map → chunk-3XORKTWN.js.map} +0 -0
- /package/dist/{chunk-QGM3ALG2.js.map → chunk-4VYQDKUM.js.map} +0 -0
- /package/dist/{chunk-LH2F5QN4.js.map → chunk-7J2IHWOT.js.map} +0 -0
- /package/dist/{chunk-5AKAN2I7.js.map → chunk-BQ4CDEDR.js.map} +0 -0
- /package/dist/{chunk-5T2NZX3J.js.map → chunk-BURLX5CB.js.map} +0 -0
- /package/dist/{chunk-BB2NJ5Z5.js.map → chunk-DVX6223T.js.map} +0 -0
- /package/dist/{chunk-LGVPUDSN.js.map → chunk-E5NMASTN.js.map} +0 -0
- /package/dist/{chunk-TDHUEJMV.js.map → chunk-EBJLPELF.js.map} +0 -0
- /package/dist/{chunk-Y2BKXUW3.js.map → chunk-NQGKQUUD.js.map} +0 -0
- /package/dist/{chunk-IOCNJOGM.js.map → chunk-Q7SWBN6Z.js.map} +0 -0
- /package/dist/{chunk-XQFP2APL.js.map → chunk-QBLOOHY2.js.map} +0 -0
- /package/dist/{chunk-35GMMRT3.js.map → chunk-RJXOZQWF.js.map} +0 -0
- /package/dist/{chunk-CWTDCJNP.js.map → chunk-SELHDL3F.js.map} +0 -0
- /package/dist/{chunk-6VHNVAGL.js.map → chunk-SH4MSGSQ.js.map} +0 -0
- /package/dist/{chunk-SK5E25IR.js.map → chunk-SOD4YEVS.js.map} +0 -0
- /package/dist/{chunk-DZ36JJ2K.js.map → chunk-TE5PVYWN.js.map} +0 -0
- /package/dist/{chunk-OL2ZR42U.js.map → chunk-V2UO4NDE.js.map} +0 -0
- /package/dist/{chunk-24VN32FG.js.map → chunk-XXX4AZ7O.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{$f as k,$i as Z,$o as Or,$w as qe,Ac as d,Aq as Pr,Ar as Fr,Aw as Ce,Bi as X,Bn as fr,Bp as Et,Bw as me,Cr as br,Er as Jr,Fl as ir,Fm as st,Fr as ut,Gi as W,Gr as Yr,Hj as G,Hp as _r,Ii as vt,Ij as Qt,In as nt,Iq as qr,Iw as De,Jf as Jt,Jm as Tr,Jn as Ir,Jv as P,Jw as ge,Km as cr,Lf as Yt,Lm as ur,Ls as J,Lw as _e,Ma as yt,Mv as pe,Mw as Le,Nu as Ot,Or as Hr,Pj as Zt,Pv as u,Qm as Sr,Ri as U,Rl as ar,Rp as Lr,Ru as ie,Rw as Me,Sa as S,Sh as kt,Sr as b,Ts as Vr,Tt as ee,Tv as Te,Uc as qt,Uf as Ht,Um as lr,Ut as se,Vc as Ut,Vi as j,Vk as tr,Wj as zt,Wl as Er,Wm as Ar,Wq as M,Wv as ce,Xi as Q,Xl as C,Xm as Rr,Xr as $r,Xw as ye,Yj as tt,Yq as Ur,Yw as Pe,Zc as Gt,Zn as it,Zr as St,Zv as ue,Zw as q,_v as Se,_w as mt,a,ae as wt,al as rr,at as Kr,aw as le,ax as Ue,b as m,c as D,cj as Xt,cp as dr,cs as lt,cw as Ae,d as g,dw as Re,e as o,ep as B,er as Gr,et as vr,ew as Ct,fw as he,fx as Ge,gg as V,gm as or,gp as w,gw as xe,gx as Be,he as Ft,hp as Cr,hv as ae,ib as Pt,ip as mr,it as Xr,jr as Br,jw as Y,kc as L,li as Vt,lq as ot,lv as y,mr as pt,ms as kr,mt as Wr,nl as er,nr as Tt,ns as At,nt as xt,ob as R,oe as h,og as $t,on as hr,oq as Mr,os as Rt,ot as ft,ou as Nt,ox as we,pg as K,pi as Kt,po as Nr,pp as Dr,ps as ht,pt as It,pv as Ee,pw as fe,qj as z,qt as jr,rj as Wt,rt as Qr,ru as ne,rx as Fe,s as p,sg as f,sl as sr,so as at,st as Zr,sx as be,tl as rt,ul as nr,un as xr,ur as wr,vf as bt,vj as jt,vt as zr,vv as dt,vw as Ie,vx as H,wb as _,wd as Bt,wm as et,ww as Ne,xh as v,xt as te,yp as gr,yq as F,yr as ct,yt as re,yw as Oe,zm as pr,zq as yr,zv as oe,zw as de}from"./chunk-CNQXTBAR.js";var ds={MICROSECOND:" * 1000000",MILLISECOND:" * 1000",SECOND:"",MINUTE:" / 60",HOUR:" / 3600",DAY:" / 86400"};function Dt(e){return function(i){let t=i;t instanceof ut&&(t=Me(t));let r=this.sql(t,"this"),s=t.args.unit,n=t.args.expression&&this.simplifyUnlessLiteral(t.args.expression);if(n instanceof f)n.setArgKey("isString",!0);else if(n&&n.isNumber)n=f.string(n.toValue());else{let T=f.number(1),N=new Zt({this:new U({this:T,unit:s}),expression:n});return`${r} ${e} ${this.sql(N)}`}return`${r} ${e} ${this.sql(new U({this:n,unit:s}))}`}}a(Dt,"dateAddSql");function Je(e){let i=e.text("unit").toUpperCase(),t=ds[i],r=`CAST(${this.sql(e,"this")} AS TIMESTAMP)`,s=`CAST(${this.sql(e,"expression")} AS TIMESTAMP)`;if(t!==void 0)return`CAST(EXTRACT(epoch FROM ${r} - ${s})${t} AS BIGINT)`;let n=`AGE(${r}, ${s})`,T;return i==="WEEK"?T=`EXTRACT(days FROM (${r} - ${s})) / 7`:i==="MONTH"?T=`EXTRACT(year FROM ${n}) * 12 + EXTRACT(month FROM ${n})`:i==="QUARTER"?T=`EXTRACT(year FROM ${n}) * 4 + EXTRACT(month FROM ${n}) / 3`:i==="YEAR"?T=`EXTRACT(year FROM ${n})`:T=n,`CAST(${T} AS BIGINT)`}a(Je,"dateDiffSql");function Cs(e){let i=this.sql(e,"this"),t=this.sql(e,"start"),r=this.sql(e,"length"),s=t?` FROM ${t}`:"",n=r?` FOR ${r}`:"";return`SUBSTRING(${i}${s}${n})`}a(Cs,"substringSql");function ms(e){let i=e.find(Yt);if(i&&e instanceof L){let t=e.args.constraints||[];e.setArgKey("constraints",t.filter(s=>s!==i.parent));let r=e.args.kind;r instanceof h&&(r.isType("int")?r.replace(new h({this:"serial"})):r.isType("smallint")?r.replace(new h({this:"smallserial"})):r.isType("bigint")&&r.replace(new h({this:"bigserial"})))}return e}a(ms,"autoIncrementToSerial");function Ds(e){if(!(e instanceof L))return e;let i=e.args.kind;if(!(i instanceof h))return e;let t;if(i.isType("serial")?t=new h({this:"int"}):i.isType("smallserial")?t=new h({this:"smallint"}):i.isType("bigserial")&&(t=new h({this:"bigint"})),t){i.replace(t);let r=e.args.constraints||[],s=new d({kind:new k({this:!1})}),n=new d({kind:new V({})});r.some(T=>T instanceof d&&T.args.kind instanceof V)||r.unshift(n),r.some(T=>T instanceof d&&T.args.kind instanceof k)||r.unshift(s),e.setArgKey("constraints",r)}return e}a(Ds,"serialToGenerated");function gs(e){let i=S(e,2);return i&&(i instanceof f&&i.isString?e[2]=Nt(i.args.this):i instanceof U&&!i.args.unit&&(e[2]=Nt(i.args.this?.args.this))),J.fromArgList(e)}a(gs,"buildGenerateSeries");function _s(e){return e.length===1?b.fromArgList(e):Y(Tt,{dialect:"postgres"})(e)}a(_s,"buildToTimestamp");function Ye(e,i){return function(t){return t.args.onlyJsonTypes?mt(e,{quotedIndex:!1,op:i}).call(this,t):mt(e).call(this,t)}}a(Ye,"jsonExtractSql");function Ls(e){let i;if(3<e.length){let t=e[e.length-1];t instanceof f&&t.isNumber||t instanceof f&&t.isString&&(i=F.fromArgList(e.slice(0,-1)),i.setArgKey("modifiers",t))}return i=i||F.fromArgList(e),i.setArgKey("singleReplace",!0),i}a(Ls,"buildRegexpReplace");function Ms(e){let i=e.args.scale,t=e.args.this;if(i===void 0||i?.toValue()===b.SECONDS.toValue())return this.func("TO_TIMESTAMP",[t,this.formatTime(e)]);let r=new Wt({this:t?.copy(),expression:new ot({this:f.number(10),expression:i?.copy()})});return this.func("TO_TIMESTAMP",[r,this.formatTime(e)])}a(Ms,"unixToTimeSql");function ys(e){let i=e.pop();return new Et({this:S(e,0),expression:S(e,1),insCost:S(e,2),delCost:S(e,3),subCost:S(e,4),maxDist:i})}a(ys,"buildLevenshteinLessEqual");function Ps(e){let i=e.args.maxDist?"LEVENSHTEIN_LESS_EQUAL":"LEVENSHTEIN";return u(i).call(this,e)}a(Ps,"levenshteinSql");function qs(e){return this.dialect.version.major<16?_e.call(this,e):u("ANY_VALUE").call(this,e)}a(qs,"versionedAnyValueSql");function Us(e){let i=this.sql(e,"this"),t=this.sql(e,"decimals");if(!t)return this.func("ROUND",[i]);let r=i;if(e.args.this instanceof _&&e.args.this.isType("double")){let s=h.build("decimal",{expressions:e.args.expressions});r=this.sql(new C({this:i,to:s}))}return this.func("ROUND",[r,t])}a(Us,"roundSql");var $e,ke,Ve,Ke,ve,Xe,We,je,Qe,I,x=class x extends(Qe=H,je=[p],We=[p],Xe=[p],ve=[p],Ke=[p],Ve=[p],ke=[p],$e=[p],Qe){static get BIT_STRINGS(){return[["b'","'"],["B'","'"],"0b"]}static get HEX_STRINGS(){return[["x'","'"],["X'","'"],"0x"]}static get BYTE_STRINGS(){return[["e'","'"],["E'","'"]]}static get BYTE_STRING_ESCAPES(){return["'","\\"]}static get HEREDOC_STRINGS(){return["$"]}static get ORIGINAL_KEYWORDS(){let{"/*+":t,DIV:r,...s}=H.KEYWORDS;return{...s,"~":"rlike","@@":"dat","@>":"atGt","<@":"ltAt","?&":"qmarkAmp","?|":"qmarkPipe","#-":"hashDash","|/":"pipeSlash","||/":"dpipeSlash",BEGIN:"begin",BIGSERIAL:"bigserial",CSTRING:"pseudoType",DECLARE:"command",DO:"command",EXEC:"command",HSTORE:"hstore",INT8:"bigint",MONEY:"money",NAME:"name",OID:"objectIdentifier",ONLY:"only",POINT:"point",REFRESH:"command",REINDEX:"command",RESET:"command",SERIAL:"serial",SMALLSERIAL:"smallserial",TEMP:"temporary",TYPE:"type",REGCLASS:"objectIdentifier",REGCOLLATION:"objectIdentifier",REGCONFIG:"objectIdentifier",REGDICTIONARY:"objectIdentifier",REGNAMESPACE:"objectIdentifier",REGOPER:"objectIdentifier",REGOPERATOR:"objectIdentifier",REGPROC:"objectIdentifier",REGPROCEDURE:"objectIdentifier",REGROLE:"objectIdentifier",REGTYPE:"objectIdentifier",FLOAT:"double",XML:"xml",VARIADIC:"variadic",INOUT:"inout"}}static get SINGLE_TOKENS(){return{...H.SINGLE_TOKENS,$:"heredocString"}}static get VAR_SINGLE_TOKENS(){return new Set(["$"])}};I=m(Qe),o(I,10,"BIT_STRINGS",je,x),o(I,10,"HEX_STRINGS",We,x),o(I,10,"BYTE_STRINGS",Xe,x),o(I,10,"BYTE_STRING_ESCAPES",ve,x),o(I,10,"HEREDOC_STRINGS",Ke,x),o(I,10,"ORIGINAL_KEYWORDS",Ve,x),o(I,10,"SINGLE_TOKENS",ke,x),o(I,10,"VAR_SINGLE_TOKENS",$e,x),D(I,x),g(I,3,x),a(x,"PostgresTokenizer"),x.HEREDOC_TAG_IS_IDENTIFIER=!0,x.HEREDOC_STRING_ALTERNATIVE="parameter";var gt=x,Ze,ze,ts,rs,es,ss,ns,is,as,Es,os,ps,Ts,cs,us,Ss,l,c=class c extends(Ss=R,us=[p],cs=[p],Ts=[p],ps=[p],os=[p],Es=[p],as=[p],is=[p],ns=[p],ss=[p],es=[p],rs=[p],ts=[p],ze=[p],Ze=[p],Ss){static get NO_PAREN_FUNCTIONS(){let t={...R.NO_PAREN_FUNCTIONS};return t.currentSchema=Tr,t.sessionUser=Sr,t.currentCatalog=ur,t}static get PROPERTY_PARSERS(){return(()=>{let t={...R.PROPERTY_PARSERS,SET:a(function(){return this.expression(kt,{this:this.parseSet()})},"SET")};return delete t.INPUT,t})()}static get PLACEHOLDER_PARSERS(){return{...R.PLACEHOLDER_PARSERS,placeholder:function(){return this.expression(W,{jdbc:!0})},mod:function(){return this.parseQueryParameter()}}}static get FUNCTIONS(){return{...R.FUNCTIONS,ARRAY_PREPEND:a(t=>new rt({this:S(t,1),expression:S(t,0)}),"ARRAY_PREPEND"),BIT_AND:a(t=>At.fromArgList(t),"BIT_AND"),BIT_OR:a(t=>Rt.fromArgList(t),"BIT_OR"),BIT_XOR:a(t=>ht.fromArgList(t),"BIT_XOR"),VERSION:a(t=>et.fromArgList(t),"VERSION"),DATE_TRUNC:ge,DIV:a(t=>new C({this:De(G)(t),to:h.build("decimal")}),"DIV"),GENERATE_SERIES:gs,GET_BIT:a(t=>new at({this:S(t,0),expression:S(t,1),zeroIsMsb:!0}),"GET_BIT"),JSON_EXTRACT_PATH:q(B),JSON_EXTRACT_PATH_TEXT:q(w),LENGTH:a(t=>new gr({this:S(t,0),encoding:S(t,1)}),"LENGTH"),MAKE_TIME:a(t=>nt.fromArgList(t),"MAKE_TIME"),MAKE_TIMESTAMP:a(t=>St.fromArgList(t),"MAKE_TIMESTAMP"),NOW:a(t=>st.fromArgList(t),"NOW"),REGEXP_REPLACE:Ls,TO_CHAR:Y(ct,{dialect:"postgres"}),TO_DATE:Y(pt,{dialect:"postgres"}),TO_TIMESTAMP:_s,UNNEST:a(t=>it.fromArgList(t),"UNNEST"),SHA256:a(t=>new M({this:S(t,0),length:f.number(256)}),"SHA256"),SHA384:a(t=>new M({this:S(t,0),length:f.number(384)}),"SHA384"),SHA512:a(t=>new M({this:S(t,0),length:f.number(512)}),"SHA512"),LEVENSHTEIN_LESS_EQUAL:ys,JSON_OBJECT_AGG:a(t=>xt.fromArgList(t),"JSON_OBJECT_AGG"),JSONB_OBJECT_AGG:a(t=>ft.fromArgList(t),"JSONB_OBJECT_AGG"),WIDTH_BUCKET:a(t=>t.length===2?new lt({this:S(t,0),threshold:S(t,1)}):lt.fromArgList(t),"WIDTH_BUCKET")}}static get NO_PAREN_FUNCTION_PARSERS(){return{...R.NO_PAREN_FUNCTION_PARSERS,VARIADIC:a(function(){return this.expression(bt,{this:this.parseBitwise()})},"VARIADIC")}}static get FUNCTION_PARSERS(){return{...R.FUNCTION_PARSERS,DATE_PART:a(function(){return this.parseDatePart()},"DATE_PART"),JSON_AGG:a(function(){return this.expression(It,{this:this.parseLambda(),order:this.parseOrder()})},"JSON_AGG"),JSONB_EXISTS:a(function(){return this.parseJsonbExists()},"JSONB_EXISTS")}}static get BITWISE(){return{...R.BITWISE,hash:z}}static get EXPONENT(){return{caret:ot}}static get RANGE_PARSERS(){return{...R.RANGE_PARSERS,damp:Pt(ar),dat:function(t){return this.expression(Lr,{this:this.parseBitwise(),expressions:[t]})}}}static get STATEMENT_PARSERS(){return{...R.STATEMENT_PARSERS,end:function(){return this.parseCommitOrRollback()}}}static get UNARY_PARSERS(){return{...R.UNARY_PARSERS,rlike:function(){return this.expression(zt,{this:this.parseUnary()})}}}static get COLUMN_OPERATORS(){return{...R.COLUMN_OPERATORS,arrow:function(t,r){return this.validateExpression(q(B,{arrowReqJsonType:this.constructor.JSON_ARROWS_REQUIRE_JSON_TYPE})([t,r]))},darrow:function(t,r){return this.validateExpression(q(w,{arrowReqJsonType:this.constructor.JSON_ARROWS_REQUIRE_JSON_TYPE})([t,r]))}}}static get ARG_MODE_TOKENS(){return new Set(["in","out","inout","variadic"])}parseParameterMode(){if(!this.matchSet(this.constructor.ARG_MODE_TOKENS,{advance:!1})||!this.next)return;let t=this.curr;if(this.tryParse(()=>(this.advance(),this.parseTypes({checkFunc:!1,allowIdentifiers:!1})),{retreat:!0})||!this.next||!this.constructor.ID_VAR_TOKENS.has(this.next.tokenType))return;if(this.tryParse(()=>(this.advance(2),this.parseTypes({checkFunc:!1,allowIdentifiers:!0})),{retreat:!0}))return t?.tokenType}createModeConstraint(t){return this.expression(K,{input:t==="in"||t==="inout",output:t==="out"||t==="inout",variadic:t==="variadic"})}parseFunctionParameter(){let t=this.parseParameterMode();t&&this.advance();let r=this.parseIdVar(),s=this.parseColumnDef(r,{computedColumn:!1});if(t&&s instanceof L){let n=this.createModeConstraint(t);s.args.constraints||s.setArgKey("constraints",[]),s.args.constraints?.unshift(new d({kind:n}))}return s}parseQueryParameter(){let t=this.match("lParen",{advance:!1})?this.parseWrapped(()=>this.parseIdVar()):void 0;return this.matchTextSeq("S"),this.expression(W,{this:t})}parseDatePart(){let t=this.parseType();this.match("comma");let r=this.parseBitwise();return t&&(t instanceof Jt||t instanceof f)&&(t=ie(t.name)),this.expression(xr,{this:t,expression:r})}parseUniqueKey(){}parseJsonbExists(){return this.expression(dr,{this:this.parseBitwise(),path:this.match("comma")&&this.dialect.toJsonPath(this.parseBitwise())})}parseGeneratedAsIdentity(){let t=super.parseGeneratedAsIdentity();return this.matchTextSeq("STORED")&&(t=this.expression($t,{this:t.args.expression})),t}parseUserDefinedType(t){let r=t;for(;this.match("dot");){let s=this.parseIdVar();s&&(r=new jt({this:r,expression:s}))}return h.build(r,{udt:!0})}static get ID_VAR_TOKENS(){return new Set([...R.ID_VAR_TOKENS,"straightJoin"])}static get TABLE_ALIAS_TOKENS(){return new Set([...R.TABLE_ALIAS_TOKENS,"straightJoin"])}};l=m(Ss),o(l,10,"NO_PAREN_FUNCTIONS",us,c),o(l,10,"PROPERTY_PARSERS",cs,c),o(l,10,"PLACEHOLDER_PARSERS",Ts,c),o(l,10,"FUNCTIONS",ps,c),o(l,10,"NO_PAREN_FUNCTION_PARSERS",os,c),o(l,10,"FUNCTION_PARSERS",Es,c),o(l,10,"BITWISE",as,c),o(l,10,"EXPONENT",is,c),o(l,10,"RANGE_PARSERS",ns,c),o(l,10,"STATEMENT_PARSERS",ss,c),o(l,10,"UNARY_PARSERS",es,c),o(l,10,"COLUMN_OPERATORS",rs,c),o(l,10,"ARG_MODE_TOKENS",ts,c),o(l,10,"ID_VAR_TOKENS",ze,c),o(l,10,"TABLE_ALIAS_TOKENS",Ze,c),D(l,c),g(l,3,c),a(c,"PostgresParser"),c.SUPPORTS_OMITTED_INTERVAL_SPAN_UNIT=!0,c.JSON_ARROWS_REQUIRE_JSON_TYPE=!0;var _t=c,ls,As,Rs,hs,xs,fs,O,E=class E extends(fs=P,xs=[p],hs=[p],Rs=[p],As=[p],ls=[p],fs){static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let t=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(r=>t.delete(r)),t}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([j,Q,Z])}static get TYPE_MAPPING(){return new Map([...P.TYPE_MAPPING,["tinyint","SMALLINT"],["float","REAL"],["double","DOUBLE PRECISION"],["binary","BYTEA"],["varbinary","BYTEA"],["rowversion","BYTEA"],["datetime","TIMESTAMP"],["timestampntz","TIMESTAMP"],["blob","BYTEA"]])}lateralSql(t){let r=super.lateralSql(t);return t.args.crossApply!==void 0&&(r=`${r} ON TRUE`),r}jsonbExtractSql(t){return this.binary(t,"#>")}jsonbExtractScalarSql(t){return this.binary(t,"#>>")}explodeSql(t){return this.func("UNNEST",[t.args.this,...t.args.expressions||[]])}static get ORIGINAL_TRANSFORMS(){let t=new Map([...P.TRANSFORMS,[Vr,qs],[nr,xe("ARRAY_CAT")],[ir,Ue],[sr,Ct("ARRAY_APPEND")],[rt,Ct("ARRAY_PREPEND",{swapParams:!0})],[At,u("BIT_AND")],[Rt,u("BIT_OR")],[z,function(r){return this.binary(r,"#")}],[ht,u("BIT_XOR")],[L,y([ms,Ds])],[pr,ce],[st,()=>"CURRENT_TIMESTAMP"],[cr,()=>"CURRENT_USER"],[et,u("VERSION")],[lr,Dt("+")],[Rr,Je],[Ir,Ne],[Ar,Dt("-")],[it,u("UNNEST")],[J,u("GENERATE_SERIES")],[at,be],[Xr,function(r){return we.call(this,r,{funcName:"STRING_AGG",withinGroup:!1})}],[G,u("DIV")],[It,function(r){let s=this.sql(r,"this"),n=this.sql(r,"order");return`JSON_AGG(${n?`${s}${n}`:s})`}],[B,Ye("JSON_EXTRACT_PATH","->")],[w,Ye("JSON_EXTRACT_PATH_TEXT","->>")],[Cr,function(r){return this.binary(r,"#>")}],[mr,function(r){return this.binary(r,"#>>")}],[Or,function(r){return this.binary(r,"?")}],[Dr,function(r){return this.sql(new C({this:r.args.this,to:h.build("json")}))}],[j,qe],[Q,()=>""],[Z,function(r){return this.jsonPathPart(r.args.this)}],[hr,ye],[jr,u("BOOL_OR")],[Qr,u("BOOL_AND")],[Zr,de],[_r,le],[zr,Oe],[Xt,Pe],[v,function(r){return`PARTITION BY ${this.sql(r,"this")}`}],[te,y([dt])],[re,y([dt])],[Ft,ue],[Mr,u("RANDOM")],[yr,function(r){return this.binary(r,"~")}],[Pr,function(r){return this.binary(r,"~*")}],[F,function(r){return this.func("REGEXP_REPLACE",[r.args.this,r.args.expression,r.args.replacement,r.args.position,r.args.occurrence,Fe(r)])}],[qr,Us],[X,y([oe,Ee])],[M,Ge],[Ur,Be],[Br,function(r){return Ae.call(this,r,{funcName:"POSITION"})}],[pt,function(r){return this.func("TO_DATE",[r.args.this,this.formatTime(r)])}],[Tt,function(r){return this.func("TO_TIMESTAMP",[r.args.this,this.formatTime(r)])}],[wr,Re],[Gr,Cs],[nt,u("MAKE_TIME")],[St,u("MAKE_TIMESTAMP")],[fr,fe({zone:!0})],[br,Ie],[ct,function(r){return typeof r.args.format=="string"||r.args.format?.isString?this.func("TO_CHAR",[r.args.this,this.formatTime(r)]):this.func("TO_CHAR",[r.args.this,r.args.format])}],[rr,function(r){return r.args.format?this.functionFallbackSql(r):this.toCharSql(r)}],[Jr,me],[Kr,Se],[ut,Dt("+")],[Yr,Je],[b,Ms],[$r,()=>"GEN_RANDOM_UUID()"],[Fr,function(r){return this.func("DATE_PART",[f.string("epoch"),r.args.this])}],[se,u("VAR_POP")],[ee,u("VAR_SAMP")],[Wr,Le],[Hr,u("ASCII")],[Et,Ps],[xt,u("JSON_OBJECT_AGG")],[ft,u("JSONB_OBJECT_AGG")],[vr,Ce],[qt,function(r){r.args.expressions&&0<r.args.expressions.length&&this.unsupported("Oracle-style SELECT INTO with variables is not supported in PostgreSQL");let s=r.args.temporary?" TEMPORARY":"",n=r.args.unlogged?" UNLOGGED":"",T=s||n;return`${this.seg("INTO")}${T} ${this.sql(r,"this")}`}]]);return t.delete(Ht),t}static get PROPERTIES_LOCATION(){let t=new Map(P.PROPERTIES_LOCATION);return t.set(v,"postSchema"),t.set(Vt,"unsupported"),t.set(Kt,"unsupported"),t}schemaCommentPropertySql(t){return this.unsupported("Table comments are not supported in the CREATE statement"),""}commentColumnConstraintSql(t){return this.unsupported("Column comments are not supported in the CREATE statement"),""}columnDefSql(t,r={}){let{sep:s=" "}=r,n=t.find(K);if(n){let T=this.sql(n);n.pop();let N=super.columnDefSql(t,{sep:s});return`${T} ${N}`}return super.columnDefSql(t,{sep:s})}unnestSql(t){if(t.args.expressions?.length===1){let r=t.args.expressions[0];if(r instanceof Nr){let n=new er({...r.args});return(t.parent instanceof Ut||t.parent instanceof Bt)&&(n=ne("value::date").from(new wt({this:n}).as("_t",{table:["value"]})).subquery(t.args.alias instanceof _||typeof t.args.alias=="string"?t.args.alias:"_unnested_generate_series")),this.sql(n)}let s=r instanceof _?yt(r,{dialect:this.dialect}):r;if(ae(s,"array<json>")){let n=s;for(;n instanceof C;){let Mt=n.args.this;if(Mt instanceof _)n=Mt;else break}let T=this.sql(new C({this:n,to:h.build("json")})),N=this.sql(t,"alias");return N=N?` AS ${N}`:"",t.args.offset&&this.unsupported("Unsupported JSON_ARRAY_ELEMENTS with offset"),`JSON_ARRAY_ELEMENTS(${T})${N}`}}return super.unnestSql(t)}bracketSql(t){return t.args.this instanceof tr&&t.setArgKey("this",new tt({this:t.args.this})),super.bracketSql(t)}matchAgainstSql(t){let r=this.sql(t,"this"),s=(t.args.expressions??[]).map(T=>`${this.sql(T)} @@ ${r}`),n=s.join(" OR ");return 1<s.length?`(${n})`:n}alterSetSql(t){let r=this.expressions(t,{flat:!0});r=r?`(${r})`:"";let s=this.sql(t,"accessMethod");s=s?`ACCESS METHOD ${s}`:"";let n=this.sql(t,"tablespace");n=n?`TABLESPACE ${n}`:"";let T=this.sql(t,"option");return`SET ${r}${s}${n}${T}`}dataTypeSql(t){if(t.isType("array")){if(t.args.expressions&&0<t.args.expressions.length){let r=this.expressions(t,{key:"values",flat:!0});return`${this.expressions(t,{flat:!0})}[${r}]`}return"ARRAY"}return t.isType("enum")?`ENUM (${this.expressions(t,{flat:!0})})`:t.isType(["double","float"])&&t.args.expressions&&0<t.args.expressions.length?`FLOAT(${this.expressions(t,{flat:!0})})`:super.dataTypeSql(t)}castSql(t,r={}){let{safePrefix:s}=r,n=t.args.this;return n instanceof G&&t.args.to instanceof h&&t.args.to.isType("decimal")&&!t.args.to.args.expressions?.length?this.sql(n):super.castSql(t,{safePrefix:s})}arraySql(t){let r=t.args.expressions||[],s=this.normalizeFunc("ARRAY");return r[0]instanceof X?`${s}(${this.sql(r[0])})`:`${s}${Te.call(this,t)}`}computedColumnConstraintSql(t){return`GENERATED ALWAYS AS (${this.sql(t,"this")}) STORED`}isAsciiSql(t){return`(${this.sql(t.args.this)} ~ '^[[:ascii:]]*$')`}ignoreNullsSql(t){return this.unsupported("PostgreSQL does not support IGNORE NULLS."),this.sql(t.args.this)}respectNullsSql(t){return this.unsupported("PostgreSQL does not support RESPECT NULLS."),this.sql(t.args.this)}currentSchemaSql(t){return t.args.this&&this.unsupported("Unsupported arg 'this' for CURRENT_SCHEMA"),"CURRENT_SCHEMA"}intervalSql(t){let r=t.text("unit").toLowerCase(),s=t.args.this;return r.startsWith("quarter")&&s instanceof f&&(s.setArgKey("this",(parseInt(s.args.this??"0")*3).toString()),t.args.unit?.replace(new Gt({this:"MONTH"}))),super.intervalSql(t)}placeholderSql(t){if(t.args.jdbc)return"?";let r=t.args.this?`(${t.name})`:"";return`${this.constructor.NAMED_PLACEHOLDER_TOKEN}${r}s`}arrayContainsSql(t){let r=t.args.expression,s=t.args.this;if(!r)return"";let n=new or({this:r.eq(new kr({this:new tt({this:s})})),expressions:[new vt({this:!1})]}),T=new Er({ifs:[]}).when(new Qt({this:r,expression:Ot()}),Ot()).else(n);return this.sql(T)}generateSeriesSql(t){return he("GENERATE_SERIES").call(this,t)}};O=m(fs),o(O,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",xs,E),o(O,10,"SUPPORTED_JSON_PATH_PARTS",hs,E),o(O,10,"TYPE_MAPPING",Rs,E),o(O,10,"ORIGINAL_TRANSFORMS",As,E),o(O,10,"PROPERTIES_LOCATION",ls,E),D(O,E),g(O,3,E),a(E,"PostgresGenerator"),E.SUPPORTS_DECODE_CASE=!1,E.SELECT_KINDS=[],E.TRY_SUPPORTED=!1,E.SUPPORTS_UESCAPE=!1,E.SINGLE_STRING_INTERVAL=!0,E.RENAME_TABLE_WITH_DB=!1,E.LOCKING_READS_SUPPORTED=!0,E.JOIN_HINTS=!1,E.TABLE_HINTS=!1,E.QUERY_HINTS=!1,E.NVL2_SUPPORTED=!1,E.PARAMETER_TOKEN="$",E.NAMED_PLACEHOLDER_TOKEN="%",E.TABLESAMPLE_SIZE_IS_ROWS=!1,E.TABLESAMPLE_SEED_KEYWORD="REPEATABLE",E.SUPPORTS_SELECT_INTO=!0,E.JSON_TYPE_REQUIRED_FOR_EXTRACTION=!0,E.SUPPORTS_UNLOGGED_TABLES=!0,E.LIKE_PROPERTY_INSIDE_SCHEMA=!0,E.MULTI_ARG_DISTINCT=!1,E.CAN_IMPLEMENT_ARRAY_ANY=!0,E.SUPPORTS_WINDOW_EXCLUDE=!0,E.COPY_HAS_INTO_KEYWORD=!1,E.ARRAY_CONCAT_IS_VAR_LEN=!1,E.SUPPORTS_MEDIAN=!1,E.ARRAY_SIZE_DIM_REQUIRED=!0,E.SUPPORTS_BETWEEN_FLAGS=!0,E.INOUT_SEPARATOR="";var Lt=E,Is,Ns,Os,$,A=class A extends(Os=pe,Ns=[p],Is=[p],Os){static get NULL_ORDERING(){return"nulls_are_large"}static get DEFAULT_FUNCTIONS_COLUMN_NAMES(){return new Map([[J.name,"generate_series"]])}static get TIME_MAPPING(){return{d:"%u",D:"%u",dd:"%d",DD:"%d",ddd:"%j",DDD:"%j",FMDD:"%-d",FMDDD:"%-j",FMHH12:"%-I",FMHH24:"%-H",FMMI:"%-M",FMMM:"%-m",FMSS:"%-S",HH12:"%I",HH24:"%H",mi:"%M",MI:"%M",mm:"%m",MM:"%m",OF:"%z",ss:"%S",SS:"%S",TMDay:"%A",TMDy:"%a",TMMon:"%b",TMMonth:"%B",TZ:"%Z",US:"%f",ww:"%U",WW:"%U",yy:"%y",YY:"%y",yyyy:"%Y",YYYY:"%Y"}}};$=m(Os),o($,10,"DEFAULT_FUNCTIONS_COLUMN_NAMES",Ns,A),o($,10,"TIME_MAPPING",Is,A),D($,A),g($,3,A),a(A,"Postgres"),A.DIALECT_NAME="postgres",A.INDEX_OFFSET=1,A.TYPED_DIVISION=!0,A.CONCAT_COALESCE=!0,A.TIME_FORMAT="'YYYY-MM-DD HH24:MI:SS'",A.TABLESAMPLE_SIZE_IS_PERCENT=!0,A.TABLES_REFERENCEABLE_AS_COLUMNS=!0,A.Tokenizer=gt,A.Parser=_t,A.Generator=Lt;var He=A;export{gt as a,He as b};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{$v as Se,$w as mt,Am as pr,Aq as yr,Av as oe,Aw as de,Bc as d,Bq as Pr,Br as Fr,Bw as Ce,Ci as X,Cn as fr,Cp as Et,Cw as me,Dr as br,Fr as Jr,Gl as ir,Gm as st,Gr as ut,Hi as W,Hr as Yr,Ij as G,Ip as _r,Ji as vt,Jj as Qt,Jn as nt,Jq as qr,Jw as De,Kf as Jt,Km as Tr,Kn as Ir,Kv as P,Kw as ge,Lm as cr,Ma as yt,Mf as Yt,Mm as ur,Ms as J,Mw as _e,Nv as pe,Nw as Le,Ou as Ot,Pr as Hr,Qj as Zt,Qv as u,Rm as Sr,Sa as S,Si as U,Sl as ar,Sp as Lr,Su as ie,Sw as Me,Th as kt,Tr as b,Us as Vr,Ut as ee,Uv as Te,Vc as qt,Vf as Ht,Vm as lr,Vt as se,Wc as Ut,Wi as j,Wk as tr,Xj as zt,Xl as Er,Xm as Ar,Xq as M,Xv as ce,Yi as Q,Yl as C,Ym as Rr,Yr as $r,Yw as ye,Zj as tt,Zq as Ur,Zw as Pe,_c as Gt,_n as it,_r as St,_v as ue,_w as q,a,ag as k,aj as Z,ap as Or,ax as qe,b as m,be as wt,bl as rr,bt as Kr,bw as le,bx as Ue,c as D,d as g,dj as Xt,dp as dr,ds as lt,dw as Ae,e as o,ew as Re,fp as B,fr as Gr,ft as vr,fw as Ct,gw as he,gx as Ge,hg as V,hm as or,hp as w,hw as xe,hx as Be,ie as Ft,ip as Cr,iv as ae,jb as Pt,jp as mr,jt as Xr,kr as Br,kw as Y,lc as L,mi as Vt,mq as ot,mv as y,nr as pt,ns as kr,nt as Wr,ol as er,or as Tt,os as At,ot as xt,pb as R,pe as h,pg as $t,pn as hr,pq as Mr,ps as Rt,pt as ft,pu as Nt,px as we,qg as K,qi as Kt,qo as Nr,qp as Dr,qs as ht,qt as It,qv as Ee,qw as fe,rj as z,rt as jr,s as p,sj as Wt,st as Qr,su as ne,sx as Fe,tg as f,tl as sr,to as at,tt as Zr,tx as be,ul as rt,vl as nr,vn as xr,vr as wr,wf as bt,wj as jt,wt as zr,wv as dt,ww as Ie,wx as H,xb as _,xd as Bt,xm as et,xw as Ne,yh as v,yt as te,zp as gr,zq as F,zr as ct,zt as re,zw as Oe}from"./chunk-FU46WFXM.js";var ds={MICROSECOND:" * 1000000",MILLISECOND:" * 1000",SECOND:"",MINUTE:" / 60",HOUR:" / 3600",DAY:" / 86400"};function Dt(e){return function(i){let t=i;t instanceof ut&&(t=Me(t));let r=this.sql(t,"this"),s=t.args.unit,n=t.args.expression&&this.simplifyUnlessLiteral(t.args.expression);if(n instanceof f)n.setArgKey("isString",!0);else if(n&&n.isNumber)n=f.string(n.toValue());else{let T=f.number(1),N=new Zt({this:new U({this:T,unit:s}),expression:n});return`${r} ${e} ${this.sql(N)}`}return`${r} ${e} ${this.sql(new U({this:n,unit:s}))}`}}a(Dt,"dateAddSql");function Je(e){let i=e.text("unit").toUpperCase(),t=ds[i],r=`CAST(${this.sql(e,"this")} AS TIMESTAMP)`,s=`CAST(${this.sql(e,"expression")} AS TIMESTAMP)`;if(t!==void 0)return`CAST(EXTRACT(epoch FROM ${r} - ${s})${t} AS BIGINT)`;let n=`AGE(${r}, ${s})`,T;return i==="WEEK"?T=`EXTRACT(days FROM (${r} - ${s})) / 7`:i==="MONTH"?T=`EXTRACT(year FROM ${n}) * 12 + EXTRACT(month FROM ${n})`:i==="QUARTER"?T=`EXTRACT(year FROM ${n}) * 4 + EXTRACT(month FROM ${n}) / 3`:i==="YEAR"?T=`EXTRACT(year FROM ${n})`:T=n,`CAST(${T} AS BIGINT)`}a(Je,"dateDiffSql");function Cs(e){let i=this.sql(e,"this"),t=this.sql(e,"start"),r=this.sql(e,"length"),s=t?` FROM ${t}`:"",n=r?` FOR ${r}`:"";return`SUBSTRING(${i}${s}${n})`}a(Cs,"substringSql");function ms(e){let i=e.find(Yt);if(i&&e instanceof L){let t=e.args.constraints||[];e.setArgKey("constraints",t.filter(s=>s!==i.parent));let r=e.args.kind;r instanceof h&&(r.isType("int")?r.replace(new h({this:"serial"})):r.isType("smallint")?r.replace(new h({this:"smallserial"})):r.isType("bigint")&&r.replace(new h({this:"bigserial"})))}return e}a(ms,"autoIncrementToSerial");function Ds(e){if(!(e instanceof L))return e;let i=e.args.kind;if(!(i instanceof h))return e;let t;if(i.isType("serial")?t=new h({this:"int"}):i.isType("smallserial")?t=new h({this:"smallint"}):i.isType("bigserial")&&(t=new h({this:"bigint"})),t){i.replace(t);let r=e.args.constraints||[],s=new d({kind:new k({this:!1})}),n=new d({kind:new V({})});r.some(T=>T instanceof d&&T.args.kind instanceof V)||r.unshift(n),r.some(T=>T instanceof d&&T.args.kind instanceof k)||r.unshift(s),e.setArgKey("constraints",r)}return e}a(Ds,"serialToGenerated");function gs(e){let i=S(e,2);return i&&(i instanceof f&&i.isString?e[2]=Nt(i.args.this):i instanceof U&&!i.args.unit&&(e[2]=Nt(i.args.this?.args.this))),J.fromArgList(e)}a(gs,"buildGenerateSeries");function _s(e){return e.length===1?b.fromArgList(e):Y(Tt,{dialect:"postgres"})(e)}a(_s,"buildToTimestamp");function Ye(e,i){return function(t){return t.args.onlyJsonTypes?mt(e,{quotedIndex:!1,op:i}).call(this,t):mt(e).call(this,t)}}a(Ye,"jsonExtractSql");function Ls(e){let i;if(3<e.length){let t=e[e.length-1];t instanceof f&&t.isNumber||t instanceof f&&t.isString&&(i=F.fromArgList(e.slice(0,-1)),i.setArgKey("modifiers",t))}return i=i||F.fromArgList(e),i.setArgKey("singleReplace",!0),i}a(Ls,"buildRegexpReplace");function Ms(e){let i=e.args.scale,t=e.args.this;if(i===void 0||i?.toValue()===b.SECONDS.toValue())return this.func("TO_TIMESTAMP",[t,this.formatTime(e)]);let r=new Wt({this:t?.copy(),expression:new ot({this:f.number(10),expression:i?.copy()})});return this.func("TO_TIMESTAMP",[r,this.formatTime(e)])}a(Ms,"unixToTimeSql");function ys(e){let i=e.pop();return new Et({this:S(e,0),expression:S(e,1),insCost:S(e,2),delCost:S(e,3),subCost:S(e,4),maxDist:i})}a(ys,"buildLevenshteinLessEqual");function Ps(e){let i=e.args.maxDist?"LEVENSHTEIN_LESS_EQUAL":"LEVENSHTEIN";return u(i).call(this,e)}a(Ps,"levenshteinSql");function qs(e){return this.dialect.version.major<16?_e.call(this,e):u("ANY_VALUE").call(this,e)}a(qs,"versionedAnyValueSql");function Us(e){let i=this.sql(e,"this"),t=this.sql(e,"decimals");if(!t)return this.func("ROUND",[i]);let r=i;if(e.args.this instanceof _&&e.args.this.isType("double")){let s=h.build("decimal",{expressions:e.args.expressions});r=this.sql(new C({this:i,to:s}))}return this.func("ROUND",[r,t])}a(Us,"roundSql");var $e,ke,Ve,Ke,ve,Xe,We,je,Qe,I,x=class x extends(Qe=H,je=[p],We=[p],Xe=[p],ve=[p],Ke=[p],Ve=[p],ke=[p],$e=[p],Qe){static get BIT_STRINGS(){return[["b'","'"],["B'","'"],"0b"]}static get HEX_STRINGS(){return[["x'","'"],["X'","'"],"0x"]}static get BYTE_STRINGS(){return[["e'","'"],["E'","'"]]}static get BYTE_STRING_ESCAPES(){return["'","\\"]}static get HEREDOC_STRINGS(){return["$"]}static get ORIGINAL_KEYWORDS(){let{"/*+":t,DIV:r,...s}=H.KEYWORDS;return{...s,"~":"rlike","@@":"dat","@>":"atGt","<@":"ltAt","?&":"qmarkAmp","?|":"qmarkPipe","#-":"hashDash","|/":"pipeSlash","||/":"dpipeSlash",BEGIN:"begin",BIGSERIAL:"bigserial",CSTRING:"pseudoType",DECLARE:"command",DO:"command",EXEC:"command",HSTORE:"hstore",INT8:"bigint",MONEY:"money",NAME:"name",OID:"objectIdentifier",ONLY:"only",POINT:"point",REFRESH:"command",REINDEX:"command",RESET:"command",SERIAL:"serial",SMALLSERIAL:"smallserial",TEMP:"temporary",TYPE:"type",REGCLASS:"objectIdentifier",REGCOLLATION:"objectIdentifier",REGCONFIG:"objectIdentifier",REGDICTIONARY:"objectIdentifier",REGNAMESPACE:"objectIdentifier",REGOPER:"objectIdentifier",REGOPERATOR:"objectIdentifier",REGPROC:"objectIdentifier",REGPROCEDURE:"objectIdentifier",REGROLE:"objectIdentifier",REGTYPE:"objectIdentifier",FLOAT:"double",XML:"xml",VARIADIC:"variadic",INOUT:"inout"}}static get SINGLE_TOKENS(){return{...H.SINGLE_TOKENS,$:"heredocString"}}static get VAR_SINGLE_TOKENS(){return new Set(["$"])}};I=m(Qe),o(I,10,"BIT_STRINGS",je,x),o(I,10,"HEX_STRINGS",We,x),o(I,10,"BYTE_STRINGS",Xe,x),o(I,10,"BYTE_STRING_ESCAPES",ve,x),o(I,10,"HEREDOC_STRINGS",Ke,x),o(I,10,"ORIGINAL_KEYWORDS",Ve,x),o(I,10,"SINGLE_TOKENS",ke,x),o(I,10,"VAR_SINGLE_TOKENS",$e,x),D(I,x),g(I,3,x),a(x,"PostgresTokenizer"),x.HEREDOC_TAG_IS_IDENTIFIER=!0,x.HEREDOC_STRING_ALTERNATIVE="parameter";var gt=x,Ze,ze,ts,rs,es,ss,ns,is,as,Es,os,ps,Ts,cs,us,Ss,l,c=class c extends(Ss=R,us=[p],cs=[p],Ts=[p],ps=[p],os=[p],Es=[p],as=[p],is=[p],ns=[p],ss=[p],es=[p],rs=[p],ts=[p],ze=[p],Ze=[p],Ss){static get NO_PAREN_FUNCTIONS(){let t={...R.NO_PAREN_FUNCTIONS};return t.currentSchema=Tr,t.sessionUser=Sr,t.currentCatalog=ur,t}static get PROPERTY_PARSERS(){return(()=>{let t={...R.PROPERTY_PARSERS,SET:a(function(){return this.expression(kt,{this:this.parseSet()})},"SET")};return delete t.INPUT,t})()}static get PLACEHOLDER_PARSERS(){return{...R.PLACEHOLDER_PARSERS,placeholder:function(){return this.expression(W,{jdbc:!0})},mod:function(){return this.parseQueryParameter()}}}static get FUNCTIONS(){return{...R.FUNCTIONS,ARRAY_PREPEND:a(t=>new rt({this:S(t,1),expression:S(t,0)}),"ARRAY_PREPEND"),BIT_AND:a(t=>At.fromArgList(t),"BIT_AND"),BIT_OR:a(t=>Rt.fromArgList(t),"BIT_OR"),BIT_XOR:a(t=>ht.fromArgList(t),"BIT_XOR"),VERSION:a(t=>et.fromArgList(t),"VERSION"),DATE_TRUNC:ge,DIV:a(t=>new C({this:De(G)(t),to:h.build("decimal")}),"DIV"),GENERATE_SERIES:gs,GET_BIT:a(t=>new at({this:S(t,0),expression:S(t,1),zeroIsMsb:!0}),"GET_BIT"),JSON_EXTRACT_PATH:q(B),JSON_EXTRACT_PATH_TEXT:q(w),LENGTH:a(t=>new gr({this:S(t,0),encoding:S(t,1)}),"LENGTH"),MAKE_TIME:a(t=>nt.fromArgList(t),"MAKE_TIME"),MAKE_TIMESTAMP:a(t=>St.fromArgList(t),"MAKE_TIMESTAMP"),NOW:a(t=>st.fromArgList(t),"NOW"),REGEXP_REPLACE:Ls,TO_CHAR:Y(ct,{dialect:"postgres"}),TO_DATE:Y(pt,{dialect:"postgres"}),TO_TIMESTAMP:_s,UNNEST:a(t=>it.fromArgList(t),"UNNEST"),SHA256:a(t=>new M({this:S(t,0),length:f.number(256)}),"SHA256"),SHA384:a(t=>new M({this:S(t,0),length:f.number(384)}),"SHA384"),SHA512:a(t=>new M({this:S(t,0),length:f.number(512)}),"SHA512"),LEVENSHTEIN_LESS_EQUAL:ys,JSON_OBJECT_AGG:a(t=>xt.fromArgList(t),"JSON_OBJECT_AGG"),JSONB_OBJECT_AGG:a(t=>ft.fromArgList(t),"JSONB_OBJECT_AGG"),WIDTH_BUCKET:a(t=>t.length===2?new lt({this:S(t,0),threshold:S(t,1)}):lt.fromArgList(t),"WIDTH_BUCKET")}}static get NO_PAREN_FUNCTION_PARSERS(){return{...R.NO_PAREN_FUNCTION_PARSERS,VARIADIC:a(function(){return this.expression(bt,{this:this.parseBitwise()})},"VARIADIC")}}static get FUNCTION_PARSERS(){return{...R.FUNCTION_PARSERS,DATE_PART:a(function(){return this.parseDatePart()},"DATE_PART"),JSON_AGG:a(function(){return this.expression(It,{this:this.parseLambda(),order:this.parseOrder()})},"JSON_AGG"),JSONB_EXISTS:a(function(){return this.parseJsonbExists()},"JSONB_EXISTS")}}static get BITWISE(){return{...R.BITWISE,hash:z}}static get EXPONENT(){return{caret:ot}}static get RANGE_PARSERS(){return{...R.RANGE_PARSERS,damp:Pt(ar),dat:function(t){return this.expression(Lr,{this:this.parseBitwise(),expressions:[t]})}}}static get STATEMENT_PARSERS(){return{...R.STATEMENT_PARSERS,end:function(){return this.parseCommitOrRollback()}}}static get UNARY_PARSERS(){return{...R.UNARY_PARSERS,rlike:function(){return this.expression(zt,{this:this.parseUnary()})}}}static get COLUMN_OPERATORS(){return{...R.COLUMN_OPERATORS,arrow:function(t,r){return this.validateExpression(q(B,{arrowReqJsonType:this.constructor.JSON_ARROWS_REQUIRE_JSON_TYPE})([t,r]))},darrow:function(t,r){return this.validateExpression(q(w,{arrowReqJsonType:this.constructor.JSON_ARROWS_REQUIRE_JSON_TYPE})([t,r]))}}}static get ARG_MODE_TOKENS(){return new Set(["in","out","inout","variadic"])}parseParameterMode(){if(!this.matchSet(this.constructor.ARG_MODE_TOKENS,{advance:!1})||!this.next)return;let t=this.curr;if(this.tryParse(()=>(this.advance(),this.parseTypes({checkFunc:!1,allowIdentifiers:!1})),{retreat:!0})||!this.next||!this.constructor.ID_VAR_TOKENS.has(this.next.tokenType))return;if(this.tryParse(()=>(this.advance(2),this.parseTypes({checkFunc:!1,allowIdentifiers:!0})),{retreat:!0}))return t?.tokenType}createModeConstraint(t){return this.expression(K,{input:t==="in"||t==="inout",output:t==="out"||t==="inout",variadic:t==="variadic"})}parseFunctionParameter(){let t=this.parseParameterMode();t&&this.advance();let r=this.parseIdVar(),s=this.parseColumnDef(r,{computedColumn:!1});if(t&&s instanceof L){let n=this.createModeConstraint(t);s.args.constraints||s.setArgKey("constraints",[]),s.args.constraints?.unshift(new d({kind:n}))}return s}parseQueryParameter(){let t=this.match("lParen",{advance:!1})?this.parseWrapped(()=>this.parseIdVar()):void 0;return this.matchTextSeq("S"),this.expression(W,{this:t})}parseDatePart(){let t=this.parseType();this.match("comma");let r=this.parseBitwise();return t&&(t instanceof Jt||t instanceof f)&&(t=ie(t.name)),this.expression(xr,{this:t,expression:r})}parseUniqueKey(){}parseJsonbExists(){return this.expression(dr,{this:this.parseBitwise(),path:this.match("comma")&&this.dialect.toJsonPath(this.parseBitwise())})}parseGeneratedAsIdentity(){let t=super.parseGeneratedAsIdentity();return this.matchTextSeq("STORED")&&(t=this.expression($t,{this:t.args.expression})),t}parseUserDefinedType(t){let r=t;for(;this.match("dot");){let s=this.parseIdVar();s&&(r=new jt({this:r,expression:s}))}return h.build(r,{udt:!0})}static get ID_VAR_TOKENS(){return new Set([...R.ID_VAR_TOKENS,"straightJoin"])}static get TABLE_ALIAS_TOKENS(){return new Set([...R.TABLE_ALIAS_TOKENS,"straightJoin"])}};l=m(Ss),o(l,10,"NO_PAREN_FUNCTIONS",us,c),o(l,10,"PROPERTY_PARSERS",cs,c),o(l,10,"PLACEHOLDER_PARSERS",Ts,c),o(l,10,"FUNCTIONS",ps,c),o(l,10,"NO_PAREN_FUNCTION_PARSERS",os,c),o(l,10,"FUNCTION_PARSERS",Es,c),o(l,10,"BITWISE",as,c),o(l,10,"EXPONENT",is,c),o(l,10,"RANGE_PARSERS",ns,c),o(l,10,"STATEMENT_PARSERS",ss,c),o(l,10,"UNARY_PARSERS",es,c),o(l,10,"COLUMN_OPERATORS",rs,c),o(l,10,"ARG_MODE_TOKENS",ts,c),o(l,10,"ID_VAR_TOKENS",ze,c),o(l,10,"TABLE_ALIAS_TOKENS",Ze,c),D(l,c),g(l,3,c),a(c,"PostgresParser"),c.SUPPORTS_OMITTED_INTERVAL_SPAN_UNIT=!0,c.JSON_ARROWS_REQUIRE_JSON_TYPE=!0;var _t=c,ls,As,Rs,hs,xs,fs,O,E=class E extends(fs=P,xs=[p],hs=[p],Rs=[p],As=[p],ls=[p],fs){static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let t=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(r=>t.delete(r)),t}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([j,Q,Z])}static get TYPE_MAPPING(){return new Map([...P.TYPE_MAPPING,["tinyint","SMALLINT"],["float","REAL"],["double","DOUBLE PRECISION"],["binary","BYTEA"],["varbinary","BYTEA"],["rowversion","BYTEA"],["datetime","TIMESTAMP"],["timestampntz","TIMESTAMP"],["blob","BYTEA"]])}lateralSql(t){let r=super.lateralSql(t);return t.args.crossApply!==void 0&&(r=`${r} ON TRUE`),r}jsonbExtractSql(t){return this.binary(t,"#>")}jsonbExtractScalarSql(t){return this.binary(t,"#>>")}explodeSql(t){return this.func("UNNEST",[t.args.this,...t.args.expressions||[]])}static get ORIGINAL_TRANSFORMS(){let t=new Map([...P.TRANSFORMS,[Vr,qs],[nr,xe("ARRAY_CAT")],[ir,Ue],[sr,Ct("ARRAY_APPEND")],[rt,Ct("ARRAY_PREPEND",{swapParams:!0})],[At,u("BIT_AND")],[Rt,u("BIT_OR")],[z,function(r){return this.binary(r,"#")}],[ht,u("BIT_XOR")],[L,y([ms,Ds])],[pr,ce],[st,()=>"CURRENT_TIMESTAMP"],[cr,()=>"CURRENT_USER"],[et,u("VERSION")],[lr,Dt("+")],[Rr,Je],[Ir,Ne],[Ar,Dt("-")],[it,u("UNNEST")],[J,u("GENERATE_SERIES")],[at,be],[Xr,function(r){return we.call(this,r,{funcName:"STRING_AGG",withinGroup:!1})}],[G,u("DIV")],[It,function(r){let s=this.sql(r,"this"),n=this.sql(r,"order");return`JSON_AGG(${n?`${s}${n}`:s})`}],[B,Ye("JSON_EXTRACT_PATH","->")],[w,Ye("JSON_EXTRACT_PATH_TEXT","->>")],[Cr,function(r){return this.binary(r,"#>")}],[mr,function(r){return this.binary(r,"#>>")}],[Or,function(r){return this.binary(r,"?")}],[Dr,function(r){return this.sql(new C({this:r.args.this,to:h.build("json")}))}],[j,qe],[Q,()=>""],[Z,function(r){return this.jsonPathPart(r.args.this)}],[hr,ye],[jr,u("BOOL_OR")],[Qr,u("BOOL_AND")],[Zr,de],[_r,le],[zr,Oe],[Xt,Pe],[v,function(r){return`PARTITION BY ${this.sql(r,"this")}`}],[te,y([dt])],[re,y([dt])],[Ft,ue],[Mr,u("RANDOM")],[yr,function(r){return this.binary(r,"~")}],[Pr,function(r){return this.binary(r,"~*")}],[F,function(r){return this.func("REGEXP_REPLACE",[r.args.this,r.args.expression,r.args.replacement,r.args.position,r.args.occurrence,Fe(r)])}],[qr,Us],[X,y([oe,Ee])],[M,Ge],[Ur,Be],[Br,function(r){return Ae.call(this,r,{funcName:"POSITION"})}],[pt,function(r){return this.func("TO_DATE",[r.args.this,this.formatTime(r)])}],[Tt,function(r){return this.func("TO_TIMESTAMP",[r.args.this,this.formatTime(r)])}],[wr,Re],[Gr,Cs],[nt,u("MAKE_TIME")],[St,u("MAKE_TIMESTAMP")],[fr,fe({zone:!0})],[br,Ie],[ct,function(r){return typeof r.args.format=="string"||r.args.format?.isString?this.func("TO_CHAR",[r.args.this,this.formatTime(r)]):this.func("TO_CHAR",[r.args.this,r.args.format])}],[rr,function(r){return r.args.format?this.functionFallbackSql(r):this.toCharSql(r)}],[Jr,me],[Kr,Se],[ut,Dt("+")],[Yr,Je],[b,Ms],[$r,()=>"GEN_RANDOM_UUID()"],[Fr,function(r){return this.func("DATE_PART",[f.string("epoch"),r.args.this])}],[se,u("VAR_POP")],[ee,u("VAR_SAMP")],[Wr,Le],[Hr,u("ASCII")],[Et,Ps],[xt,u("JSON_OBJECT_AGG")],[ft,u("JSONB_OBJECT_AGG")],[vr,Ce],[qt,function(r){r.args.expressions&&0<r.args.expressions.length&&this.unsupported("Oracle-style SELECT INTO with variables is not supported in PostgreSQL");let s=r.args.temporary?" TEMPORARY":"",n=r.args.unlogged?" UNLOGGED":"",T=s||n;return`${this.seg("INTO")}${T} ${this.sql(r,"this")}`}]]);return t.delete(Ht),t}static get PROPERTIES_LOCATION(){let t=new Map(P.PROPERTIES_LOCATION);return t.set(v,"postSchema"),t.set(Vt,"unsupported"),t.set(Kt,"unsupported"),t}schemaCommentPropertySql(t){return this.unsupported("Table comments are not supported in the CREATE statement"),""}commentColumnConstraintSql(t){return this.unsupported("Column comments are not supported in the CREATE statement"),""}columnDefSql(t,r={}){let{sep:s=" "}=r,n=t.find(K);if(n){let T=this.sql(n);n.pop();let N=super.columnDefSql(t,{sep:s});return`${T} ${N}`}return super.columnDefSql(t,{sep:s})}unnestSql(t){if(t.args.expressions?.length===1){let r=t.args.expressions[0];if(r instanceof Nr){let n=new er({...r.args});return(t.parent instanceof Ut||t.parent instanceof Bt)&&(n=ne("value::date").from(new wt({this:n}).as("_t",{table:["value"]})).subquery(t.args.alias instanceof _||typeof t.args.alias=="string"?t.args.alias:"_unnested_generate_series")),this.sql(n)}let s=r instanceof _?yt(r,{dialect:this.dialect}):r;if(ae(s,"array<json>")){let n=s;for(;n instanceof C;){let Mt=n.args.this;if(Mt instanceof _)n=Mt;else break}let T=this.sql(new C({this:n,to:h.build("json")})),N=this.sql(t,"alias");return N=N?` AS ${N}`:"",t.args.offset&&this.unsupported("Unsupported JSON_ARRAY_ELEMENTS with offset"),`JSON_ARRAY_ELEMENTS(${T})${N}`}}return super.unnestSql(t)}bracketSql(t){return t.args.this instanceof tr&&t.setArgKey("this",new tt({this:t.args.this})),super.bracketSql(t)}matchAgainstSql(t){let r=this.sql(t,"this"),s=(t.args.expressions??[]).map(T=>`${this.sql(T)} @@ ${r}`),n=s.join(" OR ");return 1<s.length?`(${n})`:n}alterSetSql(t){let r=this.expressions(t,{flat:!0});r=r?`(${r})`:"";let s=this.sql(t,"accessMethod");s=s?`ACCESS METHOD ${s}`:"";let n=this.sql(t,"tablespace");n=n?`TABLESPACE ${n}`:"";let T=this.sql(t,"option");return`SET ${r}${s}${n}${T}`}dataTypeSql(t){if(t.isType("array")){if(t.args.expressions&&0<t.args.expressions.length){let r=this.expressions(t,{key:"values",flat:!0});return`${this.expressions(t,{flat:!0})}[${r}]`}return"ARRAY"}return t.isType("enum")?`ENUM (${this.expressions(t,{flat:!0})})`:t.isType(["double","float"])&&t.args.expressions&&0<t.args.expressions.length?`FLOAT(${this.expressions(t,{flat:!0})})`:super.dataTypeSql(t)}castSql(t,r={}){let{safePrefix:s}=r,n=t.args.this;return n instanceof G&&t.args.to instanceof h&&t.args.to.isType("decimal")&&!t.args.to.args.expressions?.length?this.sql(n):super.castSql(t,{safePrefix:s})}arraySql(t){let r=t.args.expressions||[],s=this.normalizeFunc("ARRAY");return r[0]instanceof X?`${s}(${this.sql(r[0])})`:`${s}${Te.call(this,t)}`}computedColumnConstraintSql(t){return`GENERATED ALWAYS AS (${this.sql(t,"this")}) STORED`}isAsciiSql(t){return`(${this.sql(t.args.this)} ~ '^[[:ascii:]]*$')`}ignoreNullsSql(t){return this.unsupported("PostgreSQL does not support IGNORE NULLS."),this.sql(t.args.this)}respectNullsSql(t){return this.unsupported("PostgreSQL does not support RESPECT NULLS."),this.sql(t.args.this)}currentSchemaSql(t){return t.args.this&&this.unsupported("Unsupported arg 'this' for CURRENT_SCHEMA"),"CURRENT_SCHEMA"}intervalSql(t){let r=t.text("unit").toLowerCase(),s=t.args.this;return r.startsWith("quarter")&&s instanceof f&&(s.setArgKey("this",(parseInt(s.args.this??"0")*3).toString()),t.args.unit?.replace(new Gt({this:"MONTH"}))),super.intervalSql(t)}placeholderSql(t){if(t.args.jdbc)return"?";let r=t.args.this?`(${t.name})`:"";return`${this.constructor.NAMED_PLACEHOLDER_TOKEN}${r}s`}arrayContainsSql(t){let r=t.args.expression,s=t.args.this;if(!r)return"";let n=new or({this:r.eq(new kr({this:new tt({this:s})})),expressions:[new vt({this:!1})]}),T=new Er({ifs:[]}).when(new Qt({this:r,expression:Ot()}),Ot()).else(n);return this.sql(T)}generateSeriesSql(t){return he("GENERATE_SERIES").call(this,t)}};O=m(fs),o(O,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",xs,E),o(O,10,"SUPPORTED_JSON_PATH_PARTS",hs,E),o(O,10,"TYPE_MAPPING",Rs,E),o(O,10,"ORIGINAL_TRANSFORMS",As,E),o(O,10,"PROPERTIES_LOCATION",ls,E),D(O,E),g(O,3,E),a(E,"PostgresGenerator"),E.SUPPORTS_DECODE_CASE=!1,E.SELECT_KINDS=[],E.TRY_SUPPORTED=!1,E.SUPPORTS_UESCAPE=!1,E.SINGLE_STRING_INTERVAL=!0,E.RENAME_TABLE_WITH_DB=!1,E.LOCKING_READS_SUPPORTED=!0,E.JOIN_HINTS=!1,E.TABLE_HINTS=!1,E.QUERY_HINTS=!1,E.NVL2_SUPPORTED=!1,E.PARAMETER_TOKEN="$",E.NAMED_PLACEHOLDER_TOKEN="%",E.TABLESAMPLE_SIZE_IS_ROWS=!1,E.TABLESAMPLE_SEED_KEYWORD="REPEATABLE",E.SUPPORTS_SELECT_INTO=!0,E.JSON_TYPE_REQUIRED_FOR_EXTRACTION=!0,E.SUPPORTS_UNLOGGED_TABLES=!0,E.LIKE_PROPERTY_INSIDE_SCHEMA=!0,E.MULTI_ARG_DISTINCT=!1,E.CAN_IMPLEMENT_ARRAY_ANY=!0,E.SUPPORTS_WINDOW_EXCLUDE=!0,E.COPY_HAS_INTO_KEYWORD=!1,E.ARRAY_CONCAT_IS_VAR_LEN=!1,E.SUPPORTS_MEDIAN=!1,E.ARRAY_SIZE_DIM_REQUIRED=!0,E.SUPPORTS_BETWEEN_FLAGS=!0,E.INOUT_SEPARATOR="";var Lt=E,Is,Ns,Os,$,A=class A extends(Os=pe,Ns=[p],Is=[p],Os){static get NULL_ORDERING(){return"nulls_are_large"}static get DEFAULT_FUNCTIONS_COLUMN_NAMES(){return new Map([[J.name,"generate_series"]])}static get TIME_MAPPING(){return{d:"%u",D:"%u",dd:"%d",DD:"%d",ddd:"%j",DDD:"%j",FMDD:"%-d",FMDDD:"%-j",FMHH12:"%-I",FMHH24:"%-H",FMMI:"%-M",FMMM:"%-m",FMSS:"%-S",HH12:"%I",HH24:"%H",mi:"%M",MI:"%M",mm:"%m",MM:"%m",OF:"%z",ss:"%S",SS:"%S",TMDay:"%A",TMDy:"%a",TMMon:"%b",TMMonth:"%B",TZ:"%Z",US:"%f",ww:"%U",WW:"%U",yy:"%y",YY:"%y",yyyy:"%Y",YYYY:"%Y"}}};$=m(Os),o($,10,"DEFAULT_FUNCTIONS_COLUMN_NAMES",Ns,A),o($,10,"TIME_MAPPING",Is,A),D($,A),g($,3,A),a(A,"Postgres"),A.DIALECT_NAME="postgres",A.INDEX_OFFSET=1,A.TYPED_DIVISION=!0,A.CONCAT_COALESCE=!0,A.TIME_FORMAT="'YYYY-MM-DD HH24:MI:SS'",A.TABLESAMPLE_SIZE_IS_PERCENT=!0,A.TABLES_REFERENCEABLE_AS_COLUMNS=!0,A.Tokenizer=gt,A.Parser=_t,A.Generator=Lt;var He=A;export{gt as a,He as b};
|
|
2
|
+
//# sourceMappingURL=chunk-Q7SWBN6Z.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as bi}from"./chunk-Y2BKXUW3.js";import{c as Mt}from"./chunk-35GMMRT3.js";import{j as Lt}from"./chunk-QGM3ALG2.js";import{Aj as nr,Ar as B,At as ai,Bi as P,Bm as lr,Bn as Or,Bp as ut,Br as kr,Bv as hi,Cr as Xr,Dl as at,Do as Cr,Dr as Yr,Fd as Z,Fm as ot,Fo as Mr,Fr as $r,Fw as _t,Gj as ar,Gr as Kr,Gv as fi,Hv as xi,Ii as Qt,Ir as Vr,Iv as Ri,Iw as X,Jf as z,Jn as mr,Jq as qr,Jv as w,Ka as Ft,Kl as Et,Km as Sr,Ks as zr,Ll as pr,Ln as Dr,Ma as y,Mr as vr,Mv as mt,Mw as Ui,Nr as Rt,Ns as It,Nv as Ii,Oh as vt,Oi as jt,On as pt,Pe as Xt,Pj as Er,Pv as T,Qe as Yt,Rr as Jr,Rv as gi,Rw as wi,Sa as a,Si as zt,Sl as ur,Sn as Nr,Sr as N,Tn as G,Tp as lt,Tr as Zr,Ts as gt,Um as Tt,Ut as Ei,Uw as q,Vi as tr,Vk as st,Vq as Pr,Vv as Oi,Wg as $t,Wh as Jt,Wj as et,Wm as Ar,Wq as H,Ws as ti,Xl as f,Xm as ct,Xq as Fr,Xs as ri,Yq as Gr,Zc as Wt,Zn as b,Zv as mi,_n as _r,_q as br,a as e,ae as Q,al as or,at as ii,au as U,b as C,c as M,cw as Di,d as L,de as j,dj as rr,dn as hr,dw as Ni,e as l,en as F,fc as Gt,fx as qi,gc as bt,gn as fr,gx as Pi,he as kt,hv as oi,hx as dt,ic as J,jn as xr,jp as Lr,jr as ht,jw as k,jx as Ct,kc as Ht,kx as Fi,lv as R,mj as tt,mr as Hr,mt as ei,nj as ir,nl as nt,nr as ft,nv as Ti,nw as _i,ob as m,oe as D,oh as Kt,oj as rt,on as Rr,ov as ci,pi as Zt,pj as er,po as dr,pr as xt,pv as pi,pw as di,q as v,qj as it,qt as si,qw as Ci,qx as Gi,rl as Tr,rt as ni,s as S,sg as h,tr as Wr,tw as Mi,ul as cr,ur as Br,us as Qr,uv as ui,uw as Li,vj as sr,vp as yr,vs as jr,vw as Dt,vx as Y,wb as A,wp as Ur,wq as St,wv as li,ww as yi,xh as Vt,xn as Ir,xq as At,xv as Si,xw as Nt,yd as Bt,yn as gr,yq as wr,yr as W,yv as Ot,zv as Ai}from"./chunk-CNQXTBAR.js";function Ee(r){let s=r.args.expression;return s&&!(s.isString&&s.args.this===this.dialect._constructor.INITCAP_DEFAULT_DELIMITER_CHARS)&&this.unsupported("INITCAP does not support custom delimiters in Presto."),`REGEXP_REPLACE(${this.sql(r,"this")}, '(\\w)(\\w*)', x -> UPPER(x[1]) || LOWER(x[2]))`}e(Ee,"initcapSql");function oe(r){let s;return r.args.asc instanceof Qt&&!r.args.asc.args.this&&(s="(a, b) -> CASE WHEN a < b THEN 1 WHEN a > b THEN -1 ELSE 0 END"),this.func("ARRAY_SORT",[r.args.this,s])}e(oe,"noSortArray");function Te(r){if(r.parent instanceof Vt){r.transform(t=>t instanceof Wt?t.name:t,{copy:!1});let s=r.args.expressions?.map(t=>t instanceof zt||t instanceof Z?this.sql(t):this.sql(t,"this"))||[];return this.sql(new st({expressions:s.map(t=>new h({this:t,isString:!0}))}))}if(r.parent){let s=r.parent.findAll(j);for(let t of s){if(t===r)continue;let i=[...t.findAll(Ht)];0<i.length&&t.parent instanceof Z&&r.args.expressions?.push(...i)}}return this.schemaSql(r)}e(Te,"schemaSql");function ce(r){return this.unsupported("Presto does not support exact quantiles; using APPROX_PERCENTILE."),this.func("APPROX_PERCENTILE",[r.args.this,r.args.quantile])}e(ce,"quantileSql");function Ut(r){return this.func("DATE_PARSE",[r.args.this,this.formatTime(r)])}e(Ut,"strToTimeSql");function pe(r){let s=this.formatTime(r);if(s&&s!==K.TIME_FORMAT&&s!==K.DATE_FORMAT){let t=Ut.call(this,r);return this.sql(new f({this:t,to:"date".toUpperCase()}))}return this.sql(new f({this:new f({this:r.args.this,to:"timestamp".toUpperCase()}),to:"date".toUpperCase()}))}e(pe,"tsOrDsToDateSql");function ue(r){let s=wi(r),t=q(s);return this.func("DATE_ADD",[t,s.args.expression,s.args.this])}e(ue,"tsOrDsAddSql");function le(r){let s=new f({this:r.args.this,to:"timestamp".toUpperCase()}),t=new f({this:r.args.expression,to:"timestamp".toUpperCase()}),i=q(r);return this.func("DATE_DIFF",[i,t,s])}e(le,"tsOrDsDiffSql");function Se(r){return r.length===4?new U({this:a(r,0),weight:a(r,1),quantile:a(r,2),accuracy:a(r,3)}):r.length===3?new U({this:a(r,0),quantile:a(r,1),accuracy:a(r,2)}):U.fromArgList(r)}e(Se,"buildApproxPercentile");function Ae(r){return r.length===3?new N({this:a(r,0),hours:a(r,1),minutes:a(r,2)}):r.length===2?new N({this:a(r,0),zone:a(r,1)}):N.fromArgList(r)}e(Ae,"buildFromUnixtime");function Hi(r){return r.findAncestor(Bt,P)?this.functionFallbackSql(r):T("ARBITRARY").call(this,r)}e(Hi,"firstLastSql");function he(r){let s=r.args.scale,t=this.sql(r,"this");return!s||s.toValue()===N.SECONDS.toValue()?T("FROM_UNIXTIME").call(this,r):`FROM_UNIXTIME(CAST(${t} AS DOUBLE) / POW(10, ${this.sql(s)}))`}e(he,"unixToTimeSql");function fe(r){return r.type||y(r,{dialect:this.dialect}),r.type instanceof A&&!D.INTEGER_TYPES.has(r.type.args.this)?new f({this:r,to:"bigint".toUpperCase()}):r}e(fe,"toInt");function xe(r){let s=a(r,1);return s instanceof h&&s.setArgKey("this",(s.args.this??"").toUpperCase()),k(W,{dialect:"teradata"})(r)}e(xe,"buildToChar");function yt(r,s={}){let{negateInterval:t=!1}=s;return function(i){let n=i.args.expression?fe.call(this,i.args.expression):new h({this:"0",isString:!1}),o=t?n.mul(-1):n;return this.func(r,[q(i),this.sql(o),this.sql(i,"this")])}}e(yt,"dateDeltaSql");function Re(r){let s=r.args.this;if(s instanceof b){let t=s.args.this instanceof A?s.args.this.type:s.args.this,i=r.args.alias;if(i instanceof J&&t instanceof D&&t.isType("array")&&0<(t.args.expressions?.length||0)&&t.args.expressions?.[0].isType("struct")){let n=t.args.expressions[0].args.expressions;i.setArgKey("columns",n?.flatMap(o=>o instanceof A&&o.args.this instanceof A?o.args.this.copy():[]))}}else s instanceof _r&&s.replace(new b({this:s.args.this instanceof A?s.args.this.copy():s.args.this?.toString()??""}));return Fi.call(this,r)}e(Re,"explodeToUnnestSqlPresto");function Ie(r){if(r instanceof P&&r.type){let s=r.args.laterals||[];for(let t of s){let i=t.args.alias;if(!(t.args.this instanceof b)||!(i instanceof J)||i.args.columns?.length!==1)continue;let n=i.args.this,o=i.args.columns[0]instanceof A?i.args.columns[0].name.toLowerCase():i.args.columns[0];for(let c of Ft(r,[z])){let u=c.args.db?.toString().toLowerCase(),d=c.args.table?.toString().toLowerCase(),V=c.name.toLowerCase();u===o?c.setArgKey("table",c.args.db instanceof A?c.args.db.pop():c.args.db):d===o?c.setArgKey("table",n instanceof A?n.copy():n):V===o&&c.parent instanceof sr&&c.parent.replace(new z({this:c.parent.args.expression,table:v(n,"string",A)}))}}}return r}e(Ie,"amendExplodedColumnTable");var Wi,Bi,ki,$,g=class g extends(ki=Y,Bi=[S],Wi=[S],ki){static get HEX_STRINGS(){return[["x'","'"],["X'","'"]]}static get UNICODE_STRINGS(){let t=["U&","u&"],i=Y.QUOTES,n=[];for(let o of i)for(let c of t)n.push([c+o,o]);return n}static get ORIGINAL_KEYWORDS(){let t={...Y.KEYWORDS,"DEALLOCATE PREPARE":"command","DESCRIBE INPUT":"command","DESCRIBE OUTPUT":"command","RESET SESSION":"command",START:"begin",MATCH_RECOGNIZE:"matchRecognize",ROW:"struct",IPADDRESS:"ipaddress",IPPREFIX:"ipprefix",TDIGEST:"tdigest",HYPERLOGLOG:"hllsketch"};return delete t["/*+"],delete t.QUALIFY,t}};$=C(ki),l($,10,"UNICODE_STRINGS",Bi,g),l($,10,"ORIGINAL_KEYWORDS",Wi,g),M($,g),L($,3,g),e(g,"PrestoTokenizer"),g.NESTED_COMMENTS=!1;var wt=g,Xi,Yi,$i,Ki,Vi,_,x=class x extends(Vi=m,Ki=[S],$i=[S],Yi=[S],Xi=[S],Vi){static get ID_VAR_TOKENS(){return new Set([...m.ID_VAR_TOKENS,"sessionUser","currentCatalog","straightJoin"])}static get FUNCTIONS(){return{...m.FUNCTIONS,ARBITRARY:e(t=>gt.fromArgList(t),"ARBITRARY"),APPROX_DISTINCT:e(t=>zr.fromArgList(t),"APPROX_DISTINCT"),APPROX_PERCENTILE:Se,BITWISE_AND:X(tt),BITWISE_NOT:e(t=>new et({this:a(t,0)}),"BITWISE_NOT"),BITWISE_OR:X(rt),BITWISE_XOR:X(it),CARDINALITY:e(t=>ur.fromArgList(t),"CARDINALITY"),CONTAINS:e(t=>at.fromArgList(t),"CONTAINS"),DATE_ADD:e(t=>new Tt({this:a(t,2),expression:a(t,1),unit:a(t,0)}),"DATE_ADD"),DATE_DIFF:e(t=>new ct({this:a(t,2),expression:a(t,1),unit:a(t,0)}),"DATE_DIFF"),DATE_FORMAT:k(W,{dialect:"presto"}),DATE_PARSE:k(ft,{dialect:"presto"}),DATE_TRUNC:_i,DAY_OF_WEEK:e(t=>F.fromArgList(t),"DAY_OF_WEEK"),DOW:e(t=>F.fromArgList(t),"DOW"),DOY:e(t=>fr.fromArgList(t),"DOY"),ELEMENT_AT:e(t=>new jt({this:a(t,0),expressions:[t[1]],offset:1,safe:!0}),"ELEMENT_AT"),FROM_HEX:e(t=>Rt.fromArgList(t),"FROM_HEX"),FROM_UNIXTIME:Ae,FROM_UTF8:e(t=>new pt({this:a(t,0),replace:a(t,1),charset:new h({this:"utf-8",isString:!0})}),"FROM_UTF8"),JSON_FORMAT:e(t=>new Lr({this:a(t,0),options:a(t,1),isJson:!0}),"JSON_FORMAT"),LEVENSHTEIN_DISTANCE:e(t=>ut.fromArgList(t),"LEVENSHTEIN_DISTANCE"),NOW:e(t=>ot.fromArgList(t),"NOW"),REGEXP_EXTRACT:Ct(St),REGEXP_EXTRACT_ALL:Ct(At),REGEXP_REPLACE:e(t=>new wr({this:a(t,0),expression:a(t,1),replacement:a(t,2)||h.string("")}),"REGEXP_REPLACE"),REPLACE:Gi,ROW:e(t=>Wr.fromArgList(t),"ROW"),SEQUENCE:e(t=>nt.fromArgList(t),"SEQUENCE"),SET_AGG:e(t=>It.fromArgList(t),"SET_AGG"),SPLIT_TO_MAP:e(t=>xt.fromArgList(t),"SPLIT_TO_MAP"),STRPOS:e(t=>new ht({this:a(t,0),substr:a(t,1),occurrence:a(t,2)}),"STRPOS"),SLICE:e(t=>Et.fromArgList(t),"SLICE"),TO_CHAR:xe,TO_UNIXTIME:e(t=>B.fromArgList(t),"TO_UNIXTIME"),TO_UTF8:e(t=>new G({this:a(t,0),charset:new h({this:"utf-8",isString:!0})}),"TO_UTF8"),MD5:e(t=>lt.fromArgList(t),"MD5"),SHA256:e(t=>new H({this:a(t,0),length:new h({this:"256",isString:!1})}),"SHA256"),SHA512:e(t=>new H({this:a(t,0),length:new h({this:"512",isString:!1})}),"SHA512"),WEEK:e(t=>xr.fromArgList(t),"WEEK")}}static get FUNCTION_PARSERS(){let t={...m.FUNCTION_PARSERS};return delete t.TRIM,t}static get TABLE_ALIAS_TOKENS(){return new Set([...m.TABLE_ALIAS_TOKENS,"straightJoin"])}};_=C(Vi),l(_,10,"ID_VAR_TOKENS",Ki,x),l(_,10,"FUNCTIONS",$i,x),l(_,10,"FUNCTION_PARSERS",Yi,x),l(_,10,"TABLE_ALIAS_TOKENS",Xi,x),M(_,x),L(_,3,x),e(x,"PrestoParser"),x.VALUES_FOLLOWED_BY_PAREN=!1,x.ZONE_AWARE_TIMESTAMP_CONSTRUCTOR=!0;var qt=x,vi,Ji,Zi,Qi,ji,zi,te,I,E=class E extends(te=w,zi=[S],ji=[S],Qi=[S],Zi=[S],Ji=[S],vi=[S],te){static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let t=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(i=>t.delete(i)),t}static get STRUCT_DELIMITER(){return["(",")"]}static get PROPERTIES_LOCATION(){return new Map([...w.PROPERTIES_LOCATION,[Kt,"unsupported"],[Zt,"unsupported"]])}static get TYPE_MAPPING(){return new Map([...w.TYPE_MAPPING,["binary","VARBINARY"],["bit","BOOLEAN"],["datetime","TIMESTAMP"],["datetime64","TIMESTAMP"],["float","REAL"],["hllsketch","HYPERLOGLOG"],["int","INTEGER"],["struct","ROW"],["text","VARCHAR"],["timestamptz","TIMESTAMP"],["timestampntz","TIMESTAMP"],["timetz","TIME"]])}static get ORIGINAL_TRANSFORMS(){return new Map([...w.TRANSFORMS,[gt,T("ARBITRARY")],[U,function(t){return this.func("APPROX_PERCENTILE",[t.args.this,t.args.weight,t.args.quantile,t.args.accuracy])}],[Qr,T("MAX_BY")],[jr,T("MIN_BY")],[st,R([xi],function(t){return`ARRAY[${this.expressions(t,{flat:!0})}]`})],[Tr,T("ANY_MATCH")],[cr,T("CONCAT")],[at,T("CONTAINS")],[pr,T("ARRAY_JOIN")],[It,T("SET_AGG")],[Et,T("SLICE")],[Xt,T("AT_TIMEZONE")],[tt,function(t){return this.func("BITWISE_AND",[t.args.this,t.args.expression])}],[ir,function(t){return this.func("BITWISE_ARITHMETIC_SHIFT_LEFT",[t.args.this,t.args.expression])}],[et,function(t){return this.func("BITWISE_NOT",[t.args.this])}],[rt,function(t){return this.func("BITWISE_OR",[t.args.this,t.args.expression])}],[er,function(t){return this.func("BITWISE_ARITHMETIC_SHIFT_RIGHT",[t.args.this,t.args.expression])}],[it,function(t){return this.func("BITWISE_XOR",[t.args.this,t.args.expression])}],[f,R([Ot])],[lr,()=>"CURRENT_TIME"],[ot,()=>"CURRENT_TIMESTAMP"],[Sr,()=>"CURRENT_USER"],[Tt,yt("DATE_ADD")],[ct,function(t){return this.func("DATE_DIFF",[q(t),t.args.expression,t.args.this])}],[mr,yi],[Dr,function(t){return`CAST(DATE_FORMAT(${this.sql(t,"this")}, ${this.dialect._constructor.DATEINT_FORMAT}) AS INT)`}],[Ar,yt("DATE_ADD",{negateInterval:!0})],[hr,function(t){return`((${this.func("DAY_OF_WEEK",[t.args.this])} % 7) + 1)`}],[F,T("DAY_OF_WEEK")],[pt,function(t){return Nt.call(this,t,"FROM_UTF8")}],[Nr,function(t){return`CAST(DATE_PARSE(CAST(${this.sql(t,"this")} AS VARCHAR), ${this.dialect._constructor.DATEINT_FORMAT}) AS DATE)`}],[G,function(t){return Nt.call(this,t,"TO_UTF8")}],[$t,function(t){return`format=${this.sql(new h({this:t.name,isString:!0}))}`}],[ti,Hi],[Yt,function(t){return`WITH_TIMEZONE(${this.sql(t,"this")}, ${this.sql(t,"zone")}) AT TIME ZONE 'UTC'`}],[nt,dt],[dr,dt],[Cr,gi()],[ar,Oi],[Mr,Ee],[ri,Hi],[Rr,function(t){return this.func("LAST_DAY_OF_MONTH",[t.args.this])}],[rr,Re],[yr,Mi],[ut,function(t){return Ri.call(this,t,"insCost","delCost","subCost","maxDist"),T("LEVENSHTEIN_DISTANCE").call(this,t)}],[ni,T("BOOL_AND")],[si,T("BOOL_OR")],[kt,mi],[ai,ce],[St,_t],[At,_t],[Ur,Li],[j,Te],[vt,function(t){return this.nakedProperty(t)}],[P,R([fi,pi,ci,ui(1),Ai,Ie])],[br,oe],[Jt,function(t){return`SECURITY ${this.sql(t,"this")}`}],[ht,function(t){return Di.call(this,t,{supportsOccurrence:!0})}],[Hr,function(t){return`CAST(${Ut.call(this,t)} AS DATE)`}],[xt,T("SPLIT_TO_MAP")],[ft,Ut],[Br,Ni],[Q,R([Ti])],[Ir,Ci],[gr,yt("DATE_ADD")],[Or,di()],[kr,Dt],[Xr,Dt],[Yr,function(t){return this.func("TO_UNIXTIME",[this.func("DATE_PARSE",[t.args.this,this.dialect._constructor.TIME_FORMAT])])}],[W,function(t){return this.func("DATE_FORMAT",[t.args.this,this.formatTime(t)])}],[B,T("TO_UNIXTIME")],[or,function(t){return this.func("DATE_FORMAT",[t.args.this,this.formatTime(t)])}],[ii,R([Ot])],[vr,function(t){return`CAST(SUBSTR(REPLACE(CAST(${this.sql(t,"this")} AS VARCHAR), '-', ''), 1, 8) AS INT)`}],[$r,ue],[Kr,le],[Vr,pe],[Rt,T("FROM_HEX")],[Jr,function(t){return`DATE_FORMAT(FROM_UNIXTIME(${this.sql(t,"this")}), ${this.formatTime(t)})`}],[N,he],[Zr,function(t){return`CAST(FROM_UNIXTIME(${this.sql(t,"this")}) AS VARCHAR)`}],[Ei,T("VAR_POP")],[Gt,R([Si])],[bt,R([li])],[qr,T("TRUNCATE")],[ei,Ui],[lt,T("MD5")],[Pr,T("SHA1")],[Fr,T("SHA1")],[H,qi],[Gr,Pi]])}static get RESERVED_KEYWORDS(){return new Set(["alter","and","as","between","by","case","cast","constraint","create","cross","current_time","current_timestamp","deallocate","delete","describe","distinct","drop","else","end","escape","except","execute","exists","extract","false","for","from","full","group","having","in","inner","insert","intersect","into","is","join","left","like","natural","not","undefined","on","or","order","outer","prepare","right","select","table","then","true","union","using","values","when","where","with"])}extractSql(t){let i=t.name.toUpperCase();if(!i.startsWith("EPOCH"))return super.extractSql(t);let n;i==="EPOCH_MILLISECOND"?n=10**3:i==="EPOCH_MICROSECOND"?n=10**6:i==="EPOCH_NANOSECOND"&&(n=10**9);let o=t.args.expression,c=new f({this:o,to:D.build("timestamp")}),u=new B({this:c});return n&&(u=new Er({this:u,expression:new h({this:n.toString(),isString:!1})})),this.sql(u)}jsonFormatSql(t){let i=t.args.this,n=t.args.isJson;if(i&&!(n||i.type)&&(i=y(i,{dialect:this.dialect})),!(n||i?.isType("json"))){let o=new f({to:"json".toUpperCase()});i?.replace(o),o.setArgKey("this",i)}return this.functionFallbackSql(t)}md5Sql(t){let i=t.args.this;return!i?.type&&i&&(i=y(i,{dialect:this.dialect})),i?.isType(D.TEXT_TYPES)&&(i=new G({this:i,charset:new h({this:"utf-8",isString:!0})})),this.func("LOWER",[this.func("TO_HEX",[this.func("MD5",[this.sql(i)])])])}strToUnixSql(t){let i=t.args.this,n=new f({this:i,to:"VARCHAR"}),o=i?.args.isString?new f({this:i,to:"timestamp".toUpperCase()}):i,c=this.func("DATE_PARSE",[n,this.formatTime(t)]),u=this.func("DATE_FORMAT",[o,this.formatTime(t)]),d=this.func("PARSE_DATETIME",[u,this.formatTime(t,Mt.INVERSE_TIME_MAPPING,Mt.INVERSE_TIME_TRIE)]),V=this.func("COALESCE",[this.func("TRY",[c]),d]);return this.func("TO_UNIXTIME",[V])}bracketSql(t){return t.args.safe?Ii.call(this,t):super.bracketSql(t)}structSql(t){t.type||y(t,{dialect:this.dialect});let i=[],n=[],o=!1;for(let u of t.args.expressions||[])if(u instanceof nr){if(oi(u.type,"unknown"))o=!0;else{let d=typeof u.type=="string"?new D({this:u.type}):u.type;n.push(`${this.sql(u,"this")} ${this.sql(d)}`)}i.push(this.sql(u,"expression"))}else i.push(this.sql(u));let c=t.args.expressions?.length;return!c||n.length!==c?(o&&this.unsupported("Cannot convert untyped key-value definitions (try annotate_types)."),this.func("ROW",i)):`CAST(ROW(${i.join(", ")}) AS ROW(${n.join(", ")}))`}offsetLimitModifiers(t,i,n){return[this.sql(t,"offset"),this.sql(n)]}intervalSql(t){let i=t.text("unit").toUpperCase();return t.args.this&&i.startsWith("WEEK")?`(${t.args.this.name} * INTERVAL '7' DAY)`:super.intervalSql(t)}transactionSql(t){let i=t.args.modes;return`START TRANSACTION${i?` ${i.join(", ")}`:""}`}createSql(t){let i=t.args.this instanceof A?t.args.this:void 0;return t.args.kind==="view"&&i?.args.expressions&&i.setArgKey("expressions",void 0),super.createSql(t)}deleteSql(t){let i=t.args.tables||[t.args.this];if(1<i.length)return super.deleteSql(t);let n=i[0];if(t.setArgKey("this",n),t.setArgKey("tables",void 0),n instanceof Q){let o=n.args.alias;o&&(o.pop(),t=t.transform(hi))}return super.deleteSql(t)}jsonExtractSql(t){let i=this.dialect.settings.variantExtractIsJsonExtract??!0;if(!t.args.variantExtract||i)return this.func("JSON_EXTRACT",[t.args.this,t.args.expression,...t.args.expressions||[]]);let n=this.sql(t,"this"),o=[];for(let c of v(t.args.expression,A)?.args.expressions?.slice(1)||[]){if(!(c instanceof tr)){this.unsupported(`Cannot transpile JSONPath segment '${c}' to ROW access`);continue}let u=c.args.this?.toString();/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u??"")||(u=`"${u}"`),o.push(`.${u}`)}return`${n}${o.join("")}`}groupConcatSql(t){return this.func("ARRAY_JOIN",[this.func("ARRAY_AGG",[t.args.this]),t.args.separator])}};I=C(te),l(I,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",zi,E),l(I,10,"STRUCT_DELIMITER",ji,E),l(I,10,"PROPERTIES_LOCATION",Qi,E),l(I,10,"TYPE_MAPPING",Zi,E),l(I,10,"ORIGINAL_TRANSFORMS",Ji,E),l(I,10,"RESERVED_KEYWORDS",vi,E),M(I,E),L(I,3,E),e(E,"PrestoGenerator"),E.SUPPORTS_DECODE_CASE=!1,E.SELECT_KINDS=[],E.INTERVAL_ALLOWS_PLURAL_FORM=!1,E.JOIN_HINTS=!1,E.TABLE_HINTS=!1,E.QUERY_HINTS=!1,E.IS_BOOL_ALLOWED=!1,E.TZ_TO_WITH_TIME_ZONE=!0,E.NVL2_SUPPORTED=!1,E.LIMIT_ONLY_LITERALS=!0,E.SUPPORTS_SINGLE_ARG_CONCAT=!1,E.LIKE_PROPERTY_INSIDE_SCHEMA=!0,E.MULTI_ARG_DISTINCT=!1,E.SUPPORTS_TO_NUMBER=!1,E.HEX_FUNC="TO_HEX",E.PARSE_JSON_NAME="JSON_PARSE",E.PAD_FILL_PATTERN_IS_REQUIRED=!0,E.EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE=!1,E.SUPPORTS_MEDIAN=!1,E.ARRAY_SIZE_NAME="CARDINALITY";var Pt=E,re,ie,ee,se,ne,ae,O,p=class p extends(ae=mt,ne=[S],se=[S],ee=[S],ie=[S],re=[S],ae){static get NULL_ORDERING(){return"nulls_are_last"}static get EXPRESSION_METADATA(){return new Map(bi.EXPRESSION_METADATA)}static get TIME_FORMAT(){return Lt.TIME_FORMAT}static get TIME_MAPPING(){return Lt.TIME_MAPPING}static get NORMALIZATION_STRATEGY(){return"caseInsensitive"}static get SUPPORTED_SETTINGS(){return new Set([...mt.SUPPORTED_SETTINGS,"variantExtractIsJsonExtract"])}};O=C(ae),l(O,10,"NULL_ORDERING",ne,p),l(O,10,"TIME_FORMAT",se,p),l(O,10,"TIME_MAPPING",ee,p),l(O,10,"NORMALIZATION_STRATEGY",ie,p),l(O,10,"SUPPORTED_SETTINGS",re,p),M(O,p),L(O,3,p),e(p,"Presto"),p.DIALECT_NAME="presto",p.UNNEST_REQUIRES_CROSS_JOIN=!0,p.INDEX_OFFSET=1,p.STRICT_STRING_CONCAT=!0,p.SUPPORTS_SEMI_ANTI_JOIN=!1,p.TYPED_DIVISION=!0,p.TABLESAMPLE_SIZE_IS_PERCENT=!0,p.LOG_BASE_FIRST=void 0,p.SUPPORTS_VALUES_DEFAULT=!1,p.LEAST_GREATEST_IGNORES_NULLS=!1,p.Tokenizer=wt,p.Parser=qt,p.Generator=Pt;var K=p;export{Ee as a,oe as b,Te as c,ce as d,Ut as e,pe as f,ue as g,le as h,Se as i,Ae as j,Hi as k,he as l,xe as m,yt as n,Re as o,Ie as p,K as q};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as bi}from"./chunk-NQGKQUUD.js";import{c as Mt}from"./chunk-RJXOZQWF.js";import{j as Lt}from"./chunk-4VYQDKUM.js";import{$n as _r,$q as br,Av as Ai,Bj as nr,Br as B,Bt as ai,Ci as P,Cm as lr,Cn as Or,Cp as ut,Cr as kr,Cv as hi,Dr as Xr,El as at,Eo as Cr,Er as Yr,Gd as Z,Gm as ot,Go as Mr,Gr as $r,Gw as _t,Hj as ar,Hr as Kr,Hv as fi,Iv as xi,Ji as Qt,Jr as Vr,Jv as Ri,Jw as X,Ka as Ft,Kf as z,Kn as mr,Kq as qr,Kv as w,Ll as Et,Lm as Sr,Ls as zr,Ma as y,Ml as pr,Mn as Dr,Nr as vr,Nv as mt,Nw as Ui,Or as Rt,Os as It,Ov as Ii,Ph as vt,Pi as jt,Pn as pt,Qe as Xt,Qj as Er,Qv as T,Re as Yt,Sa as a,Sr as Jr,Sv as gi,Sw as wi,Ti as zt,Tl as ur,Tn as Nr,Tr as N,Un as G,Up as lt,Ur as Zr,Us as gt,Vm as Tt,Vt as Ei,Vw as q,Wi as tr,Wk as st,Wq as Pr,Wv as Oi,Xg as $t,Xh as Jt,Xj as et,Xm as Ar,Xq as H,Xs as ti,Yl as f,Ym as ct,Yq as Fr,Ys as ri,Zq as Gr,_c as Wt,_n as b,_v as mi,a as e,b as C,be as Q,bl as or,bt as ii,bu as U,c as M,d as L,dw as Di,e as l,ee as j,ej as rr,en as hr,ew as Ni,fn as F,gc as Gt,gx as qi,hc as bt,hn as fr,hx as Pi,ie as kt,iv as oi,ix as dt,jc as J,kn as xr,kp as Lr,kr as ht,kw as k,kx as Ct,lc as Ht,lx as Fi,mv as R,nj as tt,nr as Hr,nt as ei,oj as ir,ol as nt,or as ft,ov as Ti,ow as _i,pb as m,pe as D,ph as Kt,pj as rt,pn as Rr,pv as ci,q as v,qi as Zt,qj as er,qo as dr,qr as xt,qv as pi,qw as di,rj as it,rt as si,rw as Ci,rx as Gi,s as S,sl as Tr,st as ni,tg as h,ur as Wr,uw as Mi,vl as cr,vr as Br,vs as Qr,vv as ui,vw as Li,wj as sr,wp as yr,ws as jr,ww as Dt,wx as Y,xb as A,xp as Ur,xq as St,xv as li,xw as yi,yh as Vt,yn as Ir,yq as At,yv as Si,yw as Nt,zd as Bt,zn as gr,zq as wr,zr as W,zv as Ot}from"./chunk-FU46WFXM.js";function Ee(r){let s=r.args.expression;return s&&!(s.isString&&s.args.this===this.dialect._constructor.INITCAP_DEFAULT_DELIMITER_CHARS)&&this.unsupported("INITCAP does not support custom delimiters in Presto."),`REGEXP_REPLACE(${this.sql(r,"this")}, '(\\w)(\\w*)', x -> UPPER(x[1]) || LOWER(x[2]))`}e(Ee,"initcapSql");function oe(r){let s;return r.args.asc instanceof Qt&&!r.args.asc.args.this&&(s="(a, b) -> CASE WHEN a < b THEN 1 WHEN a > b THEN -1 ELSE 0 END"),this.func("ARRAY_SORT",[r.args.this,s])}e(oe,"noSortArray");function Te(r){if(r.parent instanceof Vt){r.transform(t=>t instanceof Wt?t.name:t,{copy:!1});let s=r.args.expressions?.map(t=>t instanceof zt||t instanceof Z?this.sql(t):this.sql(t,"this"))||[];return this.sql(new st({expressions:s.map(t=>new h({this:t,isString:!0}))}))}if(r.parent){let s=r.parent.findAll(j);for(let t of s){if(t===r)continue;let i=[...t.findAll(Ht)];0<i.length&&t.parent instanceof Z&&r.args.expressions?.push(...i)}}return this.schemaSql(r)}e(Te,"schemaSql");function ce(r){return this.unsupported("Presto does not support exact quantiles; using APPROX_PERCENTILE."),this.func("APPROX_PERCENTILE",[r.args.this,r.args.quantile])}e(ce,"quantileSql");function Ut(r){return this.func("DATE_PARSE",[r.args.this,this.formatTime(r)])}e(Ut,"strToTimeSql");function pe(r){let s=this.formatTime(r);if(s&&s!==K.TIME_FORMAT&&s!==K.DATE_FORMAT){let t=Ut.call(this,r);return this.sql(new f({this:t,to:"date".toUpperCase()}))}return this.sql(new f({this:new f({this:r.args.this,to:"timestamp".toUpperCase()}),to:"date".toUpperCase()}))}e(pe,"tsOrDsToDateSql");function ue(r){let s=wi(r),t=q(s);return this.func("DATE_ADD",[t,s.args.expression,s.args.this])}e(ue,"tsOrDsAddSql");function le(r){let s=new f({this:r.args.this,to:"timestamp".toUpperCase()}),t=new f({this:r.args.expression,to:"timestamp".toUpperCase()}),i=q(r);return this.func("DATE_DIFF",[i,t,s])}e(le,"tsOrDsDiffSql");function Se(r){return r.length===4?new U({this:a(r,0),weight:a(r,1),quantile:a(r,2),accuracy:a(r,3)}):r.length===3?new U({this:a(r,0),quantile:a(r,1),accuracy:a(r,2)}):U.fromArgList(r)}e(Se,"buildApproxPercentile");function Ae(r){return r.length===3?new N({this:a(r,0),hours:a(r,1),minutes:a(r,2)}):r.length===2?new N({this:a(r,0),zone:a(r,1)}):N.fromArgList(r)}e(Ae,"buildFromUnixtime");function Hi(r){return r.findAncestor(Bt,P)?this.functionFallbackSql(r):T("ARBITRARY").call(this,r)}e(Hi,"firstLastSql");function he(r){let s=r.args.scale,t=this.sql(r,"this");return!s||s.toValue()===N.SECONDS.toValue()?T("FROM_UNIXTIME").call(this,r):`FROM_UNIXTIME(CAST(${t} AS DOUBLE) / POW(10, ${this.sql(s)}))`}e(he,"unixToTimeSql");function fe(r){return r.type||y(r,{dialect:this.dialect}),r.type instanceof A&&!D.INTEGER_TYPES.has(r.type.args.this)?new f({this:r,to:"bigint".toUpperCase()}):r}e(fe,"toInt");function xe(r){let s=a(r,1);return s instanceof h&&s.setArgKey("this",(s.args.this??"").toUpperCase()),k(W,{dialect:"teradata"})(r)}e(xe,"buildToChar");function yt(r,s={}){let{negateInterval:t=!1}=s;return function(i){let n=i.args.expression?fe.call(this,i.args.expression):new h({this:"0",isString:!1}),o=t?n.mul(-1):n;return this.func(r,[q(i),this.sql(o),this.sql(i,"this")])}}e(yt,"dateDeltaSql");function Re(r){let s=r.args.this;if(s instanceof b){let t=s.args.this instanceof A?s.args.this.type:s.args.this,i=r.args.alias;if(i instanceof J&&t instanceof D&&t.isType("array")&&0<(t.args.expressions?.length||0)&&t.args.expressions?.[0].isType("struct")){let n=t.args.expressions[0].args.expressions;i.setArgKey("columns",n?.flatMap(o=>o instanceof A&&o.args.this instanceof A?o.args.this.copy():[]))}}else s instanceof _r&&s.replace(new b({this:s.args.this instanceof A?s.args.this.copy():s.args.this?.toString()??""}));return Fi.call(this,r)}e(Re,"explodeToUnnestSqlPresto");function Ie(r){if(r instanceof P&&r.type){let s=r.args.laterals||[];for(let t of s){let i=t.args.alias;if(!(t.args.this instanceof b)||!(i instanceof J)||i.args.columns?.length!==1)continue;let n=i.args.this,o=i.args.columns[0]instanceof A?i.args.columns[0].name.toLowerCase():i.args.columns[0];for(let c of Ft(r,[z])){let u=c.args.db?.toString().toLowerCase(),d=c.args.table?.toString().toLowerCase(),V=c.name.toLowerCase();u===o?c.setArgKey("table",c.args.db instanceof A?c.args.db.pop():c.args.db):d===o?c.setArgKey("table",n instanceof A?n.copy():n):V===o&&c.parent instanceof sr&&c.parent.replace(new z({this:c.parent.args.expression,table:v(n,"string",A)}))}}}return r}e(Ie,"amendExplodedColumnTable");var Wi,Bi,ki,$,g=class g extends(ki=Y,Bi=[S],Wi=[S],ki){static get HEX_STRINGS(){return[["x'","'"],["X'","'"]]}static get UNICODE_STRINGS(){let t=["U&","u&"],i=Y.QUOTES,n=[];for(let o of i)for(let c of t)n.push([c+o,o]);return n}static get ORIGINAL_KEYWORDS(){let t={...Y.KEYWORDS,"DEALLOCATE PREPARE":"command","DESCRIBE INPUT":"command","DESCRIBE OUTPUT":"command","RESET SESSION":"command",START:"begin",MATCH_RECOGNIZE:"matchRecognize",ROW:"struct",IPADDRESS:"ipaddress",IPPREFIX:"ipprefix",TDIGEST:"tdigest",HYPERLOGLOG:"hllsketch"};return delete t["/*+"],delete t.QUALIFY,t}};$=C(ki),l($,10,"UNICODE_STRINGS",Bi,g),l($,10,"ORIGINAL_KEYWORDS",Wi,g),M($,g),L($,3,g),e(g,"PrestoTokenizer"),g.NESTED_COMMENTS=!1;var wt=g,Xi,Yi,$i,Ki,Vi,_,x=class x extends(Vi=m,Ki=[S],$i=[S],Yi=[S],Xi=[S],Vi){static get ID_VAR_TOKENS(){return new Set([...m.ID_VAR_TOKENS,"sessionUser","currentCatalog","straightJoin"])}static get FUNCTIONS(){return{...m.FUNCTIONS,ARBITRARY:e(t=>gt.fromArgList(t),"ARBITRARY"),APPROX_DISTINCT:e(t=>zr.fromArgList(t),"APPROX_DISTINCT"),APPROX_PERCENTILE:Se,BITWISE_AND:X(tt),BITWISE_NOT:e(t=>new et({this:a(t,0)}),"BITWISE_NOT"),BITWISE_OR:X(rt),BITWISE_XOR:X(it),CARDINALITY:e(t=>ur.fromArgList(t),"CARDINALITY"),CONTAINS:e(t=>at.fromArgList(t),"CONTAINS"),DATE_ADD:e(t=>new Tt({this:a(t,2),expression:a(t,1),unit:a(t,0)}),"DATE_ADD"),DATE_DIFF:e(t=>new ct({this:a(t,2),expression:a(t,1),unit:a(t,0)}),"DATE_DIFF"),DATE_FORMAT:k(W,{dialect:"presto"}),DATE_PARSE:k(ft,{dialect:"presto"}),DATE_TRUNC:_i,DAY_OF_WEEK:e(t=>F.fromArgList(t),"DAY_OF_WEEK"),DOW:e(t=>F.fromArgList(t),"DOW"),DOY:e(t=>fr.fromArgList(t),"DOY"),ELEMENT_AT:e(t=>new jt({this:a(t,0),expressions:[t[1]],offset:1,safe:!0}),"ELEMENT_AT"),FROM_HEX:e(t=>Rt.fromArgList(t),"FROM_HEX"),FROM_UNIXTIME:Ae,FROM_UTF8:e(t=>new pt({this:a(t,0),replace:a(t,1),charset:new h({this:"utf-8",isString:!0})}),"FROM_UTF8"),JSON_FORMAT:e(t=>new Lr({this:a(t,0),options:a(t,1),isJson:!0}),"JSON_FORMAT"),LEVENSHTEIN_DISTANCE:e(t=>ut.fromArgList(t),"LEVENSHTEIN_DISTANCE"),NOW:e(t=>ot.fromArgList(t),"NOW"),REGEXP_EXTRACT:Ct(St),REGEXP_EXTRACT_ALL:Ct(At),REGEXP_REPLACE:e(t=>new wr({this:a(t,0),expression:a(t,1),replacement:a(t,2)||h.string("")}),"REGEXP_REPLACE"),REPLACE:Gi,ROW:e(t=>Wr.fromArgList(t),"ROW"),SEQUENCE:e(t=>nt.fromArgList(t),"SEQUENCE"),SET_AGG:e(t=>It.fromArgList(t),"SET_AGG"),SPLIT_TO_MAP:e(t=>xt.fromArgList(t),"SPLIT_TO_MAP"),STRPOS:e(t=>new ht({this:a(t,0),substr:a(t,1),occurrence:a(t,2)}),"STRPOS"),SLICE:e(t=>Et.fromArgList(t),"SLICE"),TO_CHAR:xe,TO_UNIXTIME:e(t=>B.fromArgList(t),"TO_UNIXTIME"),TO_UTF8:e(t=>new G({this:a(t,0),charset:new h({this:"utf-8",isString:!0})}),"TO_UTF8"),MD5:e(t=>lt.fromArgList(t),"MD5"),SHA256:e(t=>new H({this:a(t,0),length:new h({this:"256",isString:!1})}),"SHA256"),SHA512:e(t=>new H({this:a(t,0),length:new h({this:"512",isString:!1})}),"SHA512"),WEEK:e(t=>xr.fromArgList(t),"WEEK")}}static get FUNCTION_PARSERS(){let t={...m.FUNCTION_PARSERS};return delete t.TRIM,t}static get TABLE_ALIAS_TOKENS(){return new Set([...m.TABLE_ALIAS_TOKENS,"straightJoin"])}};_=C(Vi),l(_,10,"ID_VAR_TOKENS",Ki,x),l(_,10,"FUNCTIONS",$i,x),l(_,10,"FUNCTION_PARSERS",Yi,x),l(_,10,"TABLE_ALIAS_TOKENS",Xi,x),M(_,x),L(_,3,x),e(x,"PrestoParser"),x.VALUES_FOLLOWED_BY_PAREN=!1,x.ZONE_AWARE_TIMESTAMP_CONSTRUCTOR=!0;var qt=x,vi,Ji,Zi,Qi,ji,zi,te,I,E=class E extends(te=w,zi=[S],ji=[S],Qi=[S],Zi=[S],Ji=[S],vi=[S],te){static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let t=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(i=>t.delete(i)),t}static get STRUCT_DELIMITER(){return["(",")"]}static get PROPERTIES_LOCATION(){return new Map([...w.PROPERTIES_LOCATION,[Kt,"unsupported"],[Zt,"unsupported"]])}static get TYPE_MAPPING(){return new Map([...w.TYPE_MAPPING,["binary","VARBINARY"],["bit","BOOLEAN"],["datetime","TIMESTAMP"],["datetime64","TIMESTAMP"],["float","REAL"],["hllsketch","HYPERLOGLOG"],["int","INTEGER"],["struct","ROW"],["text","VARCHAR"],["timestamptz","TIMESTAMP"],["timestampntz","TIMESTAMP"],["timetz","TIME"]])}static get ORIGINAL_TRANSFORMS(){return new Map([...w.TRANSFORMS,[gt,T("ARBITRARY")],[U,function(t){return this.func("APPROX_PERCENTILE",[t.args.this,t.args.weight,t.args.quantile,t.args.accuracy])}],[Qr,T("MAX_BY")],[jr,T("MIN_BY")],[st,R([xi],function(t){return`ARRAY[${this.expressions(t,{flat:!0})}]`})],[Tr,T("ANY_MATCH")],[cr,T("CONCAT")],[at,T("CONTAINS")],[pr,T("ARRAY_JOIN")],[It,T("SET_AGG")],[Et,T("SLICE")],[Xt,T("AT_TIMEZONE")],[tt,function(t){return this.func("BITWISE_AND",[t.args.this,t.args.expression])}],[ir,function(t){return this.func("BITWISE_ARITHMETIC_SHIFT_LEFT",[t.args.this,t.args.expression])}],[et,function(t){return this.func("BITWISE_NOT",[t.args.this])}],[rt,function(t){return this.func("BITWISE_OR",[t.args.this,t.args.expression])}],[er,function(t){return this.func("BITWISE_ARITHMETIC_SHIFT_RIGHT",[t.args.this,t.args.expression])}],[it,function(t){return this.func("BITWISE_XOR",[t.args.this,t.args.expression])}],[f,R([Ot])],[lr,()=>"CURRENT_TIME"],[ot,()=>"CURRENT_TIMESTAMP"],[Sr,()=>"CURRENT_USER"],[Tt,yt("DATE_ADD")],[ct,function(t){return this.func("DATE_DIFF",[q(t),t.args.expression,t.args.this])}],[mr,yi],[Dr,function(t){return`CAST(DATE_FORMAT(${this.sql(t,"this")}, ${this.dialect._constructor.DATEINT_FORMAT}) AS INT)`}],[Ar,yt("DATE_ADD",{negateInterval:!0})],[hr,function(t){return`((${this.func("DAY_OF_WEEK",[t.args.this])} % 7) + 1)`}],[F,T("DAY_OF_WEEK")],[pt,function(t){return Nt.call(this,t,"FROM_UTF8")}],[Nr,function(t){return`CAST(DATE_PARSE(CAST(${this.sql(t,"this")} AS VARCHAR), ${this.dialect._constructor.DATEINT_FORMAT}) AS DATE)`}],[G,function(t){return Nt.call(this,t,"TO_UTF8")}],[$t,function(t){return`format=${this.sql(new h({this:t.name,isString:!0}))}`}],[ti,Hi],[Yt,function(t){return`WITH_TIMEZONE(${this.sql(t,"this")}, ${this.sql(t,"zone")}) AT TIME ZONE 'UTC'`}],[nt,dt],[dr,dt],[Cr,gi()],[ar,Oi],[Mr,Ee],[ri,Hi],[Rr,function(t){return this.func("LAST_DAY_OF_MONTH",[t.args.this])}],[rr,Re],[yr,Mi],[ut,function(t){return Ri.call(this,t,"insCost","delCost","subCost","maxDist"),T("LEVENSHTEIN_DISTANCE").call(this,t)}],[ni,T("BOOL_AND")],[si,T("BOOL_OR")],[kt,mi],[ai,ce],[St,_t],[At,_t],[Ur,Li],[j,Te],[vt,function(t){return this.nakedProperty(t)}],[P,R([fi,pi,ci,ui(1),Ai,Ie])],[br,oe],[Jt,function(t){return`SECURITY ${this.sql(t,"this")}`}],[ht,function(t){return Di.call(this,t,{supportsOccurrence:!0})}],[Hr,function(t){return`CAST(${Ut.call(this,t)} AS DATE)`}],[xt,T("SPLIT_TO_MAP")],[ft,Ut],[Br,Ni],[Q,R([Ti])],[Ir,Ci],[gr,yt("DATE_ADD")],[Or,di()],[kr,Dt],[Xr,Dt],[Yr,function(t){return this.func("TO_UNIXTIME",[this.func("DATE_PARSE",[t.args.this,this.dialect._constructor.TIME_FORMAT])])}],[W,function(t){return this.func("DATE_FORMAT",[t.args.this,this.formatTime(t)])}],[B,T("TO_UNIXTIME")],[or,function(t){return this.func("DATE_FORMAT",[t.args.this,this.formatTime(t)])}],[ii,R([Ot])],[vr,function(t){return`CAST(SUBSTR(REPLACE(CAST(${this.sql(t,"this")} AS VARCHAR), '-', ''), 1, 8) AS INT)`}],[$r,ue],[Kr,le],[Vr,pe],[Rt,T("FROM_HEX")],[Jr,function(t){return`DATE_FORMAT(FROM_UNIXTIME(${this.sql(t,"this")}), ${this.formatTime(t)})`}],[N,he],[Zr,function(t){return`CAST(FROM_UNIXTIME(${this.sql(t,"this")}) AS VARCHAR)`}],[Ei,T("VAR_POP")],[Gt,R([Si])],[bt,R([li])],[qr,T("TRUNCATE")],[ei,Ui],[lt,T("MD5")],[Pr,T("SHA1")],[Fr,T("SHA1")],[H,qi],[Gr,Pi]])}static get RESERVED_KEYWORDS(){return new Set(["alter","and","as","between","by","case","cast","constraint","create","cross","current_time","current_timestamp","deallocate","delete","describe","distinct","drop","else","end","escape","except","execute","exists","extract","false","for","from","full","group","having","in","inner","insert","intersect","into","is","join","left","like","natural","not","undefined","on","or","order","outer","prepare","right","select","table","then","true","union","using","values","when","where","with"])}extractSql(t){let i=t.name.toUpperCase();if(!i.startsWith("EPOCH"))return super.extractSql(t);let n;i==="EPOCH_MILLISECOND"?n=10**3:i==="EPOCH_MICROSECOND"?n=10**6:i==="EPOCH_NANOSECOND"&&(n=10**9);let o=t.args.expression,c=new f({this:o,to:D.build("timestamp")}),u=new B({this:c});return n&&(u=new Er({this:u,expression:new h({this:n.toString(),isString:!1})})),this.sql(u)}jsonFormatSql(t){let i=t.args.this,n=t.args.isJson;if(i&&!(n||i.type)&&(i=y(i,{dialect:this.dialect})),!(n||i?.isType("json"))){let o=new f({to:"json".toUpperCase()});i?.replace(o),o.setArgKey("this",i)}return this.functionFallbackSql(t)}md5Sql(t){let i=t.args.this;return!i?.type&&i&&(i=y(i,{dialect:this.dialect})),i?.isType(D.TEXT_TYPES)&&(i=new G({this:i,charset:new h({this:"utf-8",isString:!0})})),this.func("LOWER",[this.func("TO_HEX",[this.func("MD5",[this.sql(i)])])])}strToUnixSql(t){let i=t.args.this,n=new f({this:i,to:"VARCHAR"}),o=i?.args.isString?new f({this:i,to:"timestamp".toUpperCase()}):i,c=this.func("DATE_PARSE",[n,this.formatTime(t)]),u=this.func("DATE_FORMAT",[o,this.formatTime(t)]),d=this.func("PARSE_DATETIME",[u,this.formatTime(t,Mt.INVERSE_TIME_MAPPING,Mt.INVERSE_TIME_TRIE)]),V=this.func("COALESCE",[this.func("TRY",[c]),d]);return this.func("TO_UNIXTIME",[V])}bracketSql(t){return t.args.safe?Ii.call(this,t):super.bracketSql(t)}structSql(t){t.type||y(t,{dialect:this.dialect});let i=[],n=[],o=!1;for(let u of t.args.expressions||[])if(u instanceof nr){if(oi(u.type,"unknown"))o=!0;else{let d=typeof u.type=="string"?new D({this:u.type}):u.type;n.push(`${this.sql(u,"this")} ${this.sql(d)}`)}i.push(this.sql(u,"expression"))}else i.push(this.sql(u));let c=t.args.expressions?.length;return!c||n.length!==c?(o&&this.unsupported("Cannot convert untyped key-value definitions (try annotate_types)."),this.func("ROW",i)):`CAST(ROW(${i.join(", ")}) AS ROW(${n.join(", ")}))`}offsetLimitModifiers(t,i,n){return[this.sql(t,"offset"),this.sql(n)]}intervalSql(t){let i=t.text("unit").toUpperCase();return t.args.this&&i.startsWith("WEEK")?`(${t.args.this.name} * INTERVAL '7' DAY)`:super.intervalSql(t)}transactionSql(t){let i=t.args.modes;return`START TRANSACTION${i?` ${i.join(", ")}`:""}`}createSql(t){let i=t.args.this instanceof A?t.args.this:void 0;return t.args.kind==="view"&&i?.args.expressions&&i.setArgKey("expressions",void 0),super.createSql(t)}deleteSql(t){let i=t.args.tables||[t.args.this];if(1<i.length)return super.deleteSql(t);let n=i[0];if(t.setArgKey("this",n),t.setArgKey("tables",void 0),n instanceof Q){let o=n.args.alias;o&&(o.pop(),t=t.transform(hi))}return super.deleteSql(t)}jsonExtractSql(t){let i=this.dialect.settings.variantExtractIsJsonExtract??!0;if(!t.args.variantExtract||i)return this.func("JSON_EXTRACT",[t.args.this,t.args.expression,...t.args.expressions||[]]);let n=this.sql(t,"this"),o=[];for(let c of v(t.args.expression,A)?.args.expressions?.slice(1)||[]){if(!(c instanceof tr)){this.unsupported(`Cannot transpile JSONPath segment '${c}' to ROW access`);continue}let u=c.args.this?.toString();/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u??"")||(u=`"${u}"`),o.push(`.${u}`)}return`${n}${o.join("")}`}groupConcatSql(t){return this.func("ARRAY_JOIN",[this.func("ARRAY_AGG",[t.args.this]),t.args.separator])}};I=C(te),l(I,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",zi,E),l(I,10,"STRUCT_DELIMITER",ji,E),l(I,10,"PROPERTIES_LOCATION",Qi,E),l(I,10,"TYPE_MAPPING",Zi,E),l(I,10,"ORIGINAL_TRANSFORMS",Ji,E),l(I,10,"RESERVED_KEYWORDS",vi,E),M(I,E),L(I,3,E),e(E,"PrestoGenerator"),E.SUPPORTS_DECODE_CASE=!1,E.SELECT_KINDS=[],E.INTERVAL_ALLOWS_PLURAL_FORM=!1,E.JOIN_HINTS=!1,E.TABLE_HINTS=!1,E.QUERY_HINTS=!1,E.IS_BOOL_ALLOWED=!1,E.TZ_TO_WITH_TIME_ZONE=!0,E.NVL2_SUPPORTED=!1,E.LIMIT_ONLY_LITERALS=!0,E.SUPPORTS_SINGLE_ARG_CONCAT=!1,E.LIKE_PROPERTY_INSIDE_SCHEMA=!0,E.MULTI_ARG_DISTINCT=!1,E.SUPPORTS_TO_NUMBER=!1,E.HEX_FUNC="TO_HEX",E.PARSE_JSON_NAME="JSON_PARSE",E.PAD_FILL_PATTERN_IS_REQUIRED=!0,E.EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE=!1,E.SUPPORTS_MEDIAN=!1,E.ARRAY_SIZE_NAME="CARDINALITY";var Pt=E,re,ie,ee,se,ne,ae,O,p=class p extends(ae=mt,ne=[S],se=[S],ee=[S],ie=[S],re=[S],ae){static get NULL_ORDERING(){return"nulls_are_last"}static get EXPRESSION_METADATA(){return new Map(bi.EXPRESSION_METADATA)}static get TIME_FORMAT(){return Lt.TIME_FORMAT}static get TIME_MAPPING(){return Lt.TIME_MAPPING}static get NORMALIZATION_STRATEGY(){return"caseInsensitive"}static get SUPPORTED_SETTINGS(){return new Set([...mt.SUPPORTED_SETTINGS,"variantExtractIsJsonExtract"])}};O=C(ae),l(O,10,"NULL_ORDERING",ne,p),l(O,10,"TIME_FORMAT",se,p),l(O,10,"TIME_MAPPING",ee,p),l(O,10,"NORMALIZATION_STRATEGY",ie,p),l(O,10,"SUPPORTED_SETTINGS",re,p),M(O,p),L(O,3,p),e(p,"Presto"),p.DIALECT_NAME="presto",p.UNNEST_REQUIRES_CROSS_JOIN=!0,p.INDEX_OFFSET=1,p.STRICT_STRING_CONCAT=!0,p.SUPPORTS_SEMI_ANTI_JOIN=!1,p.TYPED_DIVISION=!0,p.TABLESAMPLE_SIZE_IS_PERCENT=!0,p.LOG_BASE_FIRST=void 0,p.SUPPORTS_VALUES_DEFAULT=!1,p.LEAST_GREATEST_IGNORES_NULLS=!1,p.Tokenizer=wt,p.Parser=qt,p.Generator=Pt;var K=p;export{Ee as a,oe as b,Te as c,ce as d,Ut as e,pe as f,ue as g,le as h,Se as i,Ae as j,Hi as k,he as l,xe as m,yt as n,Re as o,Ie as p,K as q};
|
|
2
|
+
//# sourceMappingURL=chunk-QBLOOHY2.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkAYLIJEXScjs = require('./chunk-AYLIJEXS.cjs');var _chunkT354W3XYcjs = require('./chunk-T354W3XY.cjs');var O,p;O=[_chunkT354W3XYcjs.s];var t=class t{static get EXPRESSION_METADATA(){let r=new Map(_chunkAYLIJEXScjs.a.EXPRESSION_METADATA),o=_chunkT354W3XYcjs.a.call(void 0, (s,n)=>{for(let z of s)r.set(z,n)},"extend");return o([_chunkT354W3XYcjs.pk],{returns:"double"}),o([_chunkT354W3XYcjs.fm,_chunkT354W3XYcjs.Im,_chunkT354W3XYcjs.rq],{returns:"varchar"}),o([_chunkT354W3XYcjs.wl,_chunkT354W3XYcjs.Bl,_chunkT354W3XYcjs.os,_chunkT354W3XYcjs.ps,_chunkT354W3XYcjs.qs,_chunkT354W3XYcjs.eq],{annotator:_chunkT354W3XYcjs.a.call(void 0, (s,n)=>s.annotateByArgs(n,["this"]),"annotator")}),r.set(_chunkT354W3XYcjs.Ek,{returns:"bigint"}),r.set(_chunkT354W3XYcjs.Em,{returns:"timestampntz"}),r.set(_chunkT354W3XYcjs.go,{returns:"binary"}),r.set(_chunkT354W3XYcjs.dn,{returns:"date"}),r.set(_chunkT354W3XYcjs.Tl,{returns:"int"}),r}};p=_chunkT354W3XYcjs.b.call(void 0, null),_chunkT354W3XYcjs.e.call(void 0, p,10,"EXPRESSION_METADATA",O,t),_chunkT354W3XYcjs.c.call(void 0, p,t),_chunkT354W3XYcjs.d.call(void 0, p,3,t),_chunkT354W3XYcjs.a.call(void 0, t,"SparkTyping");var C=t;exports.a = C;
|
|
2
|
+
//# sourceMappingURL=chunk-QDPEEKQT.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/huydna/projects/sqlingo.js/packages/sqlingo/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/huydna/projects/sqlingo.js/packages/sqlingo/dist/chunk-QDPEEKQT.cjs","../src/typing/spark.ts"],"names":["_EXPRESSION_METADATA_dec","_init","cache","_SparkTyping","map","Spark2Typing","extend","__name","types","data","type","SecExpr","CollationExpr","CurrentTimezoneExpr","RandstrExpr","ArrayCompactExpr","ArrayInsertExpr","BitwiseAndAggExpr","BitwiseOrAggExpr","BitwiseXorAggExpr","OverlayExpr","e","BitmapCountExpr","LocaltimestampExpr","ToBinaryExpr","DateFromUnixDateExpr","ArraySizeExpr","__decoratorStart","__decorateElement","__decoratorMetadata","__runInitializers","SparkTyping"],"mappings":"AAAA,iIAAwC,wDAAoM,ICA5OA,CAAAA,CAAAC,CAAAA,CAqCED,CAAAA,CAAA,CAACE,mBAAAA,CAAAA,CADI,IAAMC,CAAAA,CAAN,MAAMA,CAAY,CAEvB,OAAA,IAAW,mBAAA,CAAA,CAA2C,CAEpD,IAAMC,CAAAA,CAA0B,IAAI,GAAA,CAAIC,mBAAAA,CAAa,mBAAmB,CAAA,CAElEC,CAAAA,CAASC,iCAAAA,CAACC,CAAAA,CAA8BC,CAAAA,CAAAA,EAAkC,CAC9E,GAAA,CAAA,IAAWC,EAAAA,GAAQF,CAAAA,CAAOJ,CAAAA,CAAI,GAAA,CAAIM,CAAAA,CAAMD,CAAI,CAC9C,CAAA,CAFe,QAAA,CAAA,CAIf,OAAAH,CAAAA,CAAO,CAACK,oBAAO,CAAA,CAAG,CAChB,OAAA,CAAA,QACF,CAAC,CAAA,CAEDL,CAAAA,CAAO,CACLM,oBAAAA,CACAC,oBAAAA,CACAC,oBACF,CAAA,CAAG,CACD,OAAA,CAAA,SACF,CAAC,CAAA,CAEDR,CAAAA,CAAO,CACLS,oBAAAA,CACAC,oBAAAA,CACAC,oBAAAA,CACAC,oBAAAA,CACAC,oBAAAA,CACAC,oBACF,CAAA,CAAG,CACD,SAAA,CAAWb,iCAAAA,CAAC,CAAA,CAAkBc,CAAAA,CAAAA,EAAkB,CAAA,CAAE,cAAA,CAAeA,CAAAA,CAAG,CAAC,MAAM,CAAC,CAAA,CAAjE,WAAA,CACb,CAAC,CAAA,CAEDjB,CAAAA,CAAI,GAAA,CAAIkB,oBAAAA,CAAiB,CACvB,OAAA,CAAA,QACF,CAAC,CAAA,CACDlB,CAAAA,CAAI,GAAA,CAAImB,oBAAAA,CAAoB,CAC1B,OAAA,CAAA,cACF,CAAC,CAAA,CACDnB,CAAAA,CAAI,GAAA,CAAIoB,oBAAAA,CAAc,CACpB,OAAA,CAAA,QACF,CAAC,CAAA,CACDpB,CAAAA,CAAI,GAAA,CAAIqB,oBAAAA,CAAsB,CAC5B,OAAA,CAAA,MACF,CAAC,CAAA,CACDrB,CAAAA,CAAI,GAAA,CAAIsB,oBAAAA,CAAe,CACrB,OAAA,CAAA,KACF,CAAC,CAAA,CAEMtB,CACT,CACF,CAAA,CAnDOH,CAAAA,CAAA0B,iCAAAA,IAAA,CAAA,CAELC,iCAAAA,CAAA3B,CAAA,EAAA,CAAW,qBAAA,CADXD,CAAAA,CADWG,CAAAA,CAAAA,CAAN0B,iCAAAA,CAAA5B,CAAME,CAAAA,CAAAA,CAAN2B,iCAAAA,CAAA7B,CAAA,CAAA,CAAME,CAAAA,CAAAA,CAAYI,iCAAAA,CAAAJ,CAAA,aAAA,CAAA,CAAlB,IAAM4B,CAAAA,CAAN5B,CAAAA,CAAAA,cAAAA","file":"/home/huydna/projects/sqlingo.js/packages/sqlingo/dist/chunk-QDPEEKQT.cjs","sourcesContent":[null,"import type {\n Expression,\n} from '../expressions/expressions';\nimport {\n cache,\n} from '../port_internals';\nimport {\n DataTypeExprKind,\n} from '../expressions/types';\nimport {\n SecExpr,\n ArrayCompactExpr,\n ArrayInsertExpr,\n BitwiseAndAggExpr,\n BitwiseOrAggExpr,\n BitwiseXorAggExpr,\n CollationExpr,\n CurrentTimezoneExpr,\n RandstrExpr,\n BitmapCountExpr,\n LocaltimestampExpr,\n ToBinaryExpr,\n DateFromUnixDateExpr,\n ArraySizeExpr,\n OverlayExpr,\n} from '../expressions/expressions';\nimport type {\n TypeAnnotator,\n} from '../optimizer';\nimport {\n Spark2Typing,\n} from './spark2';\nimport type {\n ExpressionMetadata,\n} from './dialect';\n\nexport class SparkTyping {\n @cache\n static get EXPRESSION_METADATA (): ExpressionMetadata {\n // Clone the Spark 2 base metadata to apply specific overrides\n const map: ExpressionMetadata = new Map(Spark2Typing.EXPRESSION_METADATA);\n\n const extend = (types: (typeof Expression)[], data: Record<string, unknown>) => {\n for (const type of types) map.set(type, data);\n };\n\n extend([SecExpr], {\n returns: DataTypeExprKind.DOUBLE,\n });\n\n extend([\n CollationExpr,\n CurrentTimezoneExpr,\n RandstrExpr,\n ], {\n returns: DataTypeExprKind.VARCHAR,\n });\n\n extend([\n ArrayCompactExpr,\n ArrayInsertExpr,\n BitwiseAndAggExpr,\n BitwiseOrAggExpr,\n BitwiseXorAggExpr,\n OverlayExpr,\n ], {\n annotator: (s: TypeAnnotator, e: Expression) => s.annotateByArgs(e, ['this']),\n });\n\n map.set(BitmapCountExpr, {\n returns: DataTypeExprKind.BIGINT,\n });\n map.set(LocaltimestampExpr, {\n returns: DataTypeExprKind.TIMESTAMPNTZ,\n });\n map.set(ToBinaryExpr, {\n returns: DataTypeExprKind.BINARY,\n });\n map.set(DateFromUnixDateExpr, {\n returns: DataTypeExprKind.DATE,\n });\n map.set(ArraySizeExpr, {\n returns: DataTypeExprKind.INT,\n });\n\n return map;\n }\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as Zs}from"./chunk-OUVPP5P3.js";import{$b as Bt,$i as Rr,Aj as Q,Ar as ns,At as ft,Bd as Xt,Bi as W,Bn as H,Bp as Kr,Br as is,Bw as Ks,Ci as lr,Cr as B,Cv as Ps,Do as $r,Dq as ot,Dr as as,Dv as gs,Ed as bt,Ei as hr,Er as Es,Ev as Ms,Fd as Vt,Fm as _r,Fp as Wr,Fr as C,Fw as Pt,Gj as Or,Gr as os,Gw as Ws,Hj as Ir,Ho as Xr,Hv as Cs,Ib as Gt,Ii as Ar,Ir as I,Iv as mt,Jf as jt,Jn as wr,Jv as _,Ks as ls,Ll as Pr,Ln as Gr,Mr as ps,Ms as hs,Mv as _s,Na as wt,Nd as Jt,Nn as z,Ns as ct,Nw as ks,Oh as Er,Or as Ts,Ou as Ns,Ph as or,Pj as mr,Pp as et,Pv as S,Qp as nt,Qv as ys,Qw as gt,Rd as Kt,Rk as dr,Rr as Tt,Ru as Ot,Rv as Ls,Sa as u,Se as Qt,Sf as Ht,Sl as gr,Sn as Br,Sr as ut,Tl as Mr,Tp as kr,Tr as us,Ts as As,Um as yr,Uw as Qs,Ve as Zt,Vi as xr,Vk as w,Vv as Fs,Wg as er,Wm as j,Wp as it,Ws as lt,Xi as fr,Xl as Cr,Xm as G,Xs as ht,Xv as Us,Yh as pr,Ys as At,Zs as xt,_v as qs,a as i,ae as Wt,at as xs,au as Rt,b as P,be as kt,bj as k,br as jr,bw as ws,c as g,co as v,cw as Gs,d as M,dg as zt,dn as Lr,dw as Bs,e as o,eg as vt,eo as tt,ep as br,fc as Yt,fn as Fr,gg as tr,gp as rt,hd as $t,hw as dt,hx as Mt,ig as rr,is as St,iv as It,jn as Ur,jp as st,jr as Hr,jw as F,jx as Ct,ku as Nt,kw as Dt,lc as V,lv as L,mn as qr,mr as zr,ne as J,nl as Z,nr as vr,nv as Os,ob as f,oe as A,or as pt,ov as Is,pi as Tr,po as Yr,pr as ts,pv as ms,qi as ur,qr as rs,rg as sr,s as p,sg as R,st as fs,sv as ds,tv as Ds,tw as Ys,ul as Dr,ur as ss,us as Ss,uw as $s,vh as nr,vp as Vr,vs as cs,vt as Rs,vw as Xs,vx as Y,wb as b,wp as Jr,wq as at,ww as bs,xh as K,xj as Nr,xq as Et,yh as ir,yi as Sr,yq as Qr,yr as es,yw as Vs,zh as ar,zi as cr,zq as Zr,zw as Js}from"./chunk-CNQXTBAR.js";var Pe={YEAR:["ADD_MONTHS",12],MONTH:["ADD_MONTHS",1],QUARTER:["ADD_MONTHS",3],WEEK:["DATE_ADD",7],DAY:["DATE_ADD",1]},Me={MILLISECOND:" * 1000",SECOND:"",MINUTE:" / 60",HOUR:" / 3600"},Ce=new Set(["YEAR","QUARTER","MONTH"]);function _t(e){if(e instanceof C&&!e.args.unit)return this.func("DATE_ADD",[e.args.this,e.args.expression]);let n=e.text("unit").toUpperCase(),[t,r]=Pe[n]||["DATE_ADD",1];e instanceof j&&(r*=-1);let s=e.args.expression;if(s instanceof R){let E=s.isNumber?parseFloat(s.args.this??"0"):parseInt(s.args.this??"0");s=R.number(E*r)}else r!==1&&(s=new mr({this:s,expression:R.number(r)}));return this.func(t,[e.args.this,s])}i(_t,"addDateSql");function js(e){let n=e.text("unit").toUpperCase(),t=Me[n];if(t!==void 0){let D=this.sql(e,"this"),X=this.sql(e,"expression"),q=`UNIX_TIMESTAMP(${D}) - UNIX_TIMESTAMP(${X})`;return t?`(${q})${t}`:q}let r=Ce.has(n),s=r?"MONTHS_BETWEEN":"DATEDIFF",E=Pe[n]?.[1]||1,h=1<E?` / ${E}`:"",l=`${s}(${this.formatArgs([e.args.this,e.args.expression])})`;return(r||h)&&(l=`CAST(${l}${h} AS INT)`),l}i(js,"dateDiffSql");function _e(e){let n=e.args.this;if(n&&ks(n)){if(n.args.this instanceof R&&n.args.this.isString){let t=R.string(`[${n.args.this.args.this}]`),r=this.func("FROM_JSON",[t,this.func("SCHEMA_OF_JSON",[t])]),s=this.func("TO_JSON",[r]);return this.func("REGEXP_EXTRACT",[s,"'^.(.*).$'","1"])}return this.sql(n)}return this.func("TO_JSON",[n,e.args.options])}i(_e,"jsonFormatSql");function ye(e){return e.args.expression&&this.unsupported("Unsupported arg 'expression' for ArraySort"),this.func("SORT_ARRAY",[e.args.this])}i(ye,"arraySortSql");function Le(e){return this.func("UNIX_TIMESTAMP",[e.args.this,Dt("hive").call(this,e)])}i(Le,"strToUnixSql");function Fe(e){let n=this.sql(e,"this"),t=e.args.scale;return t===void 0||t.toValue()===ut.SECONDS.toValue()?S("FROM_UNIXTIME").call(this,e):`FROM_UNIXTIME(${n} / POW(10, ${t}))`}i(Fe,"unixToTimeSql");function Ue(e){let n=this.sql(e,"this"),t=this.formatTime(e);return t!=null&&![O.TIME_FORMAT,O.DATE_FORMAT].includes(t)&&(n=`FROM_UNIXTIME(UNIX_TIMESTAMP(${n}, ${t}))`),`CAST(${n} AS DATE)`}i(Ue,"strToDateSql");function qe(e){let n=this.sql(e,"this"),t=this.formatTime(e);return t!=null&&![O.TIME_FORMAT,O.DATE_FORMAT].includes(t)&&(n=`FROM_UNIXTIME(UNIX_TIMESTAMP(${n}, ${t}))`),`CAST(${n} AS TIMESTAMP)`}i(qe,"strToTimeSql");function we(e){let n=this.formatTime(e);return n&&![O.TIME_FORMAT,O.DATE_FORMAT].includes(n)?this.func("TO_DATE",[e.args.this,n]):e.parent instanceof b&&this._constructor.TS_OR_DS_EXPRESSIONS.has(e.parent._constructor)?this.sql(e,"this"):this.func("TO_DATE",[e.args.this])}i(we,"toDateSql");function $(e){return n=>{let t=new e({this:u(n,0)});return u(n,1)instanceof Ar&&u(n,1)?.args.this===!0?new Zt({this:t}):t}}i($,"buildWithIgnoreNulls");function Ge(e){let n=F(I,{dialect:"hive"})(e);return n.setArgKey("safe",!0),n}i(Ge,"buildToDate");function Be(e){let n=u(e,1);return n&&(n=n.mul(-1)),new C({this:u(e,0),expression:n,unit:Ot("DAY")})}i(Be,"buildDateAdd");var Hs,zs,yt,y=class y extends(zs=It,Hs=[p],zs){static get VAR_TOKENS(){return new Set([...It.VAR_TOKENS,"dash"])}};yt=P(zs),o(yt,10,"VAR_TOKENS",Hs,y),g(yt,y),M(yt,3,y),i(y,"HiveJsonPathTokenizer");var Lt=y,vs,te,re,se,ee,ne,ie,m,x=class x extends(ie=Y,ne=[p],ee=[p],se=[p],re=[p],te=[p],vs=[p],ie){static get QUOTES(){return["'",'"']}static get IDENTIFIERS(){return["`"]}static get STRING_ESCAPES(){return["\\"]}static get SINGLE_TOKENS(){return{...Y.SINGLE_TOKENS,$:"parameter"}}static get ORIGINAL_KEYWORDS(){return{...Y.KEYWORDS,"ADD ARCHIVE":"command","ADD ARCHIVES":"command","ADD FILE":"command","ADD FILES":"command","ADD JAR":"command","ADD JARS":"command",MINUS:"except","MSCK REPAIR":"command",REFRESH:"refresh","TIMESTAMP AS OF":"timestampSnapshot","VERSION AS OF":"versionSnapshot",SERDEPROPERTIES:"serdeProperties"}}static get NUMERIC_LITERALS(){return{L:"BIGINT",S:"SMALLINT",Y:"TINYINT",D:"DOUBLE",F:"FLOAT",BD:"DECIMAL"}}};m=P(ie),o(m,10,"QUOTES",ne,x),o(m,10,"IDENTIFIERS",ee,x),o(m,10,"STRING_ESCAPES",se,x),o(m,10,"SINGLE_TOKENS",re,x),o(m,10,"ORIGINAL_KEYWORDS",te,x),o(m,10,"NUMERIC_LITERALS",vs,x),g(m,x),M(m,3,x),i(x,"HiveTokenizer");var Ft=x,ae,Ee,oe,pe,Te,ue,Se,ce,le,N,c=class c extends(le=f,ce=[p],Se=[p],ue=[p],Te=[p],pe=[p],oe=[p],Ee=[p],ae=[p],le){static get ID_VAR_TOKENS(){return new Set([...f.ID_VAR_TOKENS,"sessionUser","currentCatalog","straightJoin"])}static get NO_PAREN_FUNCTIONS(){let t={...f.NO_PAREN_FUNCTIONS};return delete t.currentTime,delete t.localtime,delete t.localtimestamp,t}static get FUNCTION_PARSERS(){return{...f.FUNCTION_PARSERS,PERCENTILE:i(function(){return this.parseQuantileFunction(ft)},"PERCENTILE"),PERCENTILE_APPROX:i(function(){return this.parseQuantileFunction(Rt)},"PERCENTILE_APPROX")}}static get FUNCTIONS(){return{...f.FUNCTIONS,ADD_MONTHS:i(t=>new C({this:u(t,0),expression:u(t,1),unit:Ot("MONTH")}),"ADD_MONTHS"),BASE64:i(t=>tt.fromArgList(t),"BASE64"),COLLECT_LIST:i(t=>new hs({this:u(t,0),nullsExcluded:!0}),"COLLECT_LIST"),COLLECT_SET:i(t=>ct.fromArgList(t),"COLLECT_SET"),DATE_ADD:i(t=>new C({this:u(t,0),expression:u(t,1),unit:new kt({this:"DAY"})}),"DATE_ADD"),DATE_FORMAT:i(t=>F(es,{dialect:"hive"})([new B({this:u(t,0)}),u(t,1)]),"DATE_FORMAT"),DATE_SUB:Be,DATEDIFF:i(t=>new G({this:new I({this:u(t,0)}),expression:new I({this:u(t,1)})}),"DATEDIFF"),DAY:i(t=>new z({this:new I({this:u(t,0)})}),"DAY"),FIRST:$(lt),FIRST_VALUE:$(At),FROM_UNIXTIME:F(Tt,{dialect:"hive",defaultValue:!0}),GET_JSON_OBJECT:i((t,{dialect:r})=>new rt({this:u(t,0),expression:r.toJsonPath(u(t,1))}),"GET_JSON_OBJECT"),LAST:$(ht),LAST_VALUE:$(xt),MAP:i(t=>{if(t.length===1&&t[0].isStar)return new et({this:t[0]});let r=[],s=[];for(let E=0;E<t.length;E+=2)r.push(t[E]),t[E+1]&&s.push(t[E+1]);return new nt({keys:new w({expressions:r}),values:new w({expressions:s})})},"MAP"),MONTH:i(t=>new it({this:new I({this:u(t,0)})}),"MONTH"),REGEXP_EXTRACT:Ct(at),REGEXP_EXTRACT_ALL:Ct(Et),SEQUENCE:i(t=>Z.fromArgList(t),"SEQUENCE"),SIZE:i(t=>gr.fromArgList(t),"SIZE"),SPLIT:i(t=>ot.fromArgList(t),"SPLIT"),STR_TO_MAP:i(t=>new ts({this:u(t,0),pairDelim:u(t,1)||R.string(","),keyValueDelim:u(t,2)||R.string(":")}),"STR_TO_MAP"),TO_DATE:Ge,TO_JSON:i(t=>st.fromArgList(t),"TO_JSON"),TRUNC:i(t=>H.fromArgList(t),"TRUNC"),UNBASE64:i(t=>v.fromArgList(t),"UNBASE64"),UNIX_TIMESTAMP:i(t=>F(pt,{dialect:"hive",defaultValue:!0})(0<t.length?t:[new _r({})]),"UNIX_TIMESTAMP"),YEAR:i(t=>new St({this:new I({this:u(t,0)})}),"YEAR")}}static get NO_PAREN_FUNCTION_PARSERS(){return{...f.NO_PAREN_FUNCTION_PARSERS,TRANSFORM:i(function(){return this.parseTransform()},"TRANSFORM")}}static get PROPERTY_PARSERS(){return{...f.PROPERTY_PARSERS,SERDEPROPERTIES:i(function(){return new or({expressions:this.parseWrappedCsv(()=>this.parseProperty())})},"SERDEPROPERTIES")}}static get ALTER_PARSERS(){return{...f.ALTER_PARSERS,CHANGE:i(function(){return this.parseAlterTableChange()},"CHANGE")}}parseTransform(){if(!this.match("lParen",{advance:!1})){this.retreat(this.index-1);return}let t=this.parseWrappedCsv(()=>this.parseLambda()),r=this.parseRowFormat({matchRow:!0}),s;if(this.matchTextSeq("RECORDWRITER")&&(s=this.parseString()),!this.match("using"))return dr.fromArgList(t);let E=this.parseString();this.match("alias");let h=this.parseSchema(),l=this.parseRowFormat({matchRow:!0}),D;return this.matchTextSeq("RECORDREADER")&&(D=this.parseString()),this.expression(Jt,{expressions:t,commandScript:E,schema:h,rowFormatBefore:r,recordWriter:s,rowFormatAfter:l,recordReader:D})}parseQuantileFunction(t){let r;this.match("distinct")?r=this.expression(Qt,{expressions:[this.parseLambda()]}):(this.match("all"),r=this.parseLambda());let s=[r];return this.match("comma")&&s.push(...this.parseFunctionArgs()),t.fromArgList(s)}parseTypes(t={}){let{checkFunc:r=!1,schema:s=!1,allowIdentifiers:E=!0}=t,h=super.parseTypes({checkFunc:r,schema:s,allowIdentifiers:E});return h&&!s?h.transform((l,D)=>l instanceof A&&l.isType(["char","varchar"])?l.replace(A.build("text")):l,{copy:!1}):h}parseAlterTableChange(){this.match("column");let t=this.parseField({anyToken:!0});if(this.constructor.CHANGE_COLUMN_ALTER_SYNTAX&&this.matchTextSeq("TYPE"))return this.expression(V,{this:t,dtype:this.parseTypes({schema:!0})});let r=this.parseField({anyToken:!0}),s=this.parseTypes({schema:!0}),E=this.match("comment")&&this.parseString();return(!t||!r||!s)&&this.raiseError("Expected 'CHANGE COLUMN' to be followed by 'column_name' 'column_name' 'data_type'"),this.expression(V,{this:t,renameTo:r,dtype:s,comment:E})}parsePartitionAndOrder(){return[this.matchSet(["partitionBy","distributeBy"])?this.parseCsv(()=>this.parseAssignment()):[],super.parseOrder({skipOrderToken:this.match("sortBy")})??void 0]}parseParameter(){this.match("lBrace");let t=this.parseIdentifier()||this.parsePrimaryOrVar(),r=this.match("colon")&&(this.parseIdentifier()||this.parsePrimaryOrVar());return this.match("rBrace"),this.expression(hr,{this:t,expression:r})}toPropEq(t,r){if(t.isStar)return t;let s;return t instanceof jt?s=t.args.this??Nt(`col${r+1}`):s=Nt(`col${r+1}`),this.expression(Q,{this:s,expression:t})}static get TABLE_ALIAS_TOKENS(){return new Set([...f.TABLE_ALIAS_TOKENS,"straightJoin"])}};N=P(le),o(N,10,"ID_VAR_TOKENS",ce,c),o(N,10,"NO_PAREN_FUNCTIONS",Se,c),o(N,10,"FUNCTION_PARSERS",ue,c),o(N,10,"FUNCTIONS",Te,c),o(N,10,"NO_PAREN_FUNCTION_PARSERS",pe,c),o(N,10,"PROPERTY_PARSERS",oe,c),o(N,10,"ALTER_PARSERS",Ee,c),o(N,10,"TABLE_ALIAS_TOKENS",ae,c),g(N,c),M(N,3,c),i(c,"HiveParser"),c.LOG_DEFAULTS_TO_LN=!0,c.STRICT_CAST=!1,c.VALUES_FOLLOWED_BY_PAREN=!1,c.JOINS_HAVE_EQUAL_PRECEDENCE=!0,c.ADD_JOIN_ON_TRUE=!0,c.ALTER_TABLE_PARTITIONS=!0,c.CHANGE_COLUMN_ALTER_SYNTAX=!1;var Ut=c,he,Ae,xe,fe,Re,Ne,Oe,d,a=class a extends(Oe=_,Ne=[p],Re=[p],fe=[p],xe=[p],Ae=[p],he=[p],Oe){static get EXPRESSIONS_WITHOUT_NESTED_CTES(){return new Set([sr,W,lr,cr])}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([xr,fr,Rr,k])}static get TYPE_MAPPING(){return new Map([..._.TYPE_MAPPING,["bit","BOOLEAN"],["blob","BINARY"],["datetime","TIMESTAMP"],["rowversion","BINARY"],["text","STRING"],["time","TIMESTAMP"],["timestampntz","TIMESTAMP"],["timestamptz","TIMESTAMP"],["utinyint","SMALLINT"],["varbinary","BINARY"]])}static get ORIGINAL_TRANSFORMS(){return new Map([..._.TRANSFORMS,[Vt,ws],[As,S("FIRST")],[ls,ys],[Ss,gt("MAX_BY")],[cs,gt("MIN_BY")],[w,L([Cs])],[Dr,S("CONCAT")],[Pr,function(r){return this.func("CONCAT_WS",[r.args.expression,r.args.this])}],[Mr,function(r){return ye.call(this,r)}],[Yt,Us],[yr,function(r){return _t.call(this,r)}],[G,function(r){return js.call(this,r)}],[wr,bs],[j,function(r){return _t.call(this,r)}],[Gr,function(r){return`CAST(DATE_FORMAT(${this.sql(r,"this")}, ${O.DATEINT_FORMAT}) AS INT)`}],[Br,function(r){return`TO_DATE(CAST(${this.sql(r,"this")} AS STRING), ${O.DATEINT_FORMAT})`}],[pr,function(r){return`STORED BY ${this.sql(r,"this")}`}],[v,S("UNBASE64")],[Z,Mt],[Yr,Mt],[$r,Ls()],[Or,Fs],[Ir,function(r){return this.binary(r,"DIV")}],[Xr,S("ISNAN")],[br,function(r){return this.func("GET_JSON_OBJECT",[r.args.this,r.args.expression])}],[rt,function(r){return this.func("GET_JSON_OBJECT",[r.args.this,r.args.expression])}],[st,function(r){return _e.call(this,r)}],[Vr,Ys],[Wr,dt],[fs,Js],[kr,function(r){return this.func("UNHEX",[this.func("MD5",[r.args.this])])}],[Rs,Vs],[qr,function(r){return this.func("MONTHS_BETWEEN",[r.args.this,r.args.expression])}],[tr,function(r){return r.args.allowNull?"":"NOT NULL"}],[nt,dt],[Gt,L([Ps,gs,Ms])],[ft,S("PERCENTILE")],[Rt,S("PERCENTILE_APPROX")],[at,Pt],[Et,Pt],[Qr,Ws],[Zr,function(r){return this.binary(r,"RLIKE")}],[ot,S("SPLIT")],[Jr,$s],[Er,function(r){return this.nakedProperty(r)}],[ct,S("COLLECT_SET")],[jr,function(r){return this.func("SPLIT",[r.args.this,this.func("CONCAT",[R.string("\\Q"),r.args.expression,R.string("\\E")])])}],[W,L([ms,Is,r=>ds(r,{unnestUsingArraysZip:!1}),Ds])],[Hr,function(r){return Gs.call(this,r,{funcName:"LOCATE",supportsPosition:!0})}],[zr,function(r){return Ue.call(this,r)}],[vr,function(r){return qe.call(this,r)}],[pt,function(r){return Le.call(this,r)}],[ss,Bs],[et,S("MAP")],[Wt,L([Os])],[is,S("TO_DATE")],[B,Xs],[as,S("UNIX_TIMESTAMP")],[H,function(r){return this.func("TRUNC",[r.args.this,Qs(r)])}],[ns,S("UNIX_TIMESTAMP")],[tt,S("BASE64")],[ps,function(r){return`CAST(SUBSTR(REPLACE(CAST(${this.sql(r,"this")} AS STRING), '-', ''), 1, 8) AS INT)`}],[C,function(r){return _t.call(this,r)}],[os,function(r){return js.call(this,r)}],[I,function(r){return we.call(this,r)}],[xs,qs],[Es,Ks],[Ts,S("ASCII")],[Tt,function(r){return this.func("FROM_UNIXTIME",[r.args.this,Dt("hive").call(this,r)])}],[ut,function(r){return Fe.call(this,r)}],[us,S("FROM_UNIXTIME")],[K,function(r){return`PARTITIONED BY ${this.sql(r,"this")}`}],[rs,S("FORMAT_NUMBER")],[$t,function(r){return this.nationalSql(r,{prefix:""})}],[Ht,function(r){return`(${this.expressions(r,{key:"this",indent:!1})})`}],[zt,function(r){return`(${this.expressions(r,{key:"this",indent:!1})})`}],[vt,()=>""],[nr,()=>""],[ir,function(r){return this.func("BUCKET",[r.args.expression,r.args.this])}],[ar,function(r){return this.func("TRUNCATE",[r.args.expression,r.args.this])}],[rr,()=>"PRIMARY KEY"],[Ur,S("WEEKOFYEAR")],[Fr,S("DAYOFMONTH")],[Lr,S("DAYOFWEEK")],[Kr,function(r){return mt.call(this,r,"insCost","delCost","subCost","maxDist"),S("LEVENSHTEIN").call(this,r)}]])}static get PROPERTIES_LOCATION(){return new Map([..._.PROPERTIES_LOCATION,[er,"postSchema"],[K,"postSchema"],[Tr,"unsupported"],[ur,"unsupported"]])}static get TS_OR_DS_EXPRESSIONS(){return new Set([G,z,it,St])}ignoreNullsSql(t){let r=t.args.this;return this._constructor.IGNORE_NULLS_FUNCS.some(s=>r instanceof s)?this.func(r._constructor.sqlNames()[0],[r.args.this,Ns()]):super.ignoreNullsSql(t)}unnestSql(t){return S("EXPLODE").call(this,t)}jsonPathKeySql(t){return t.args.this instanceof k?(this.unsupported("Unsupported wildcard in JSONPathKey expression"),""):super.jsonPathKeySql(t)}parameterSql(t){let r=this.sql(t,"this"),s=this.sql(t,"expression"),E=t.parent;return r=s?`${r}:${s}`:r,E instanceof Nr&&E.parent instanceof Bt?r:`\${${r}}`}schemaSql(t){for(let r of t.findAll(bt))r.args.desc===!1&&r.setArgKey("desc",void 0);return super.schemaSql(t)}constraintSql(t){for(let E of Array.from(t.findAll(Sr)))E.pop();let r=this.sql(t,"this"),s=this.expressions(t,{sep:" ",flat:!0});return`CONSTRAINT ${r} ${s}`}rowFormatSerdePropertySql(t){let r=this.sql(t,"serdeProperties");return r=r?` ${r}`:"",`ROW FORMAT SERDE ${this.sql(t,"this")}${r}`}arrayAggSql(t){return this.func("COLLECT_LIST",[t.args.this instanceof Xt?t.args.this.args.this:t.args.this])}truncSql(t){return mt.call(this,t,"decimals"),this.sql(new Cr({this:t.args.this,to:A.build("bigint")}))}dataTypeSql(t){if(t.isType(_.PARAMETERIZABLE_TEXT_TYPES)&&(!t.args.expressions||t.args.expressions[0].name==="MAX"))t=A.build("text")??t;else if(t.isType("text")&&t.args.expressions)t.setArgKey("this","varchar");else if(t.isType(A.TEMPORAL_TYPES))t=A.build(t.args.this)??t;else if(t.isType("float")){let r=t.find(J);r instanceof J&&(t=(parseInt(r.args.this?.args.this?.toString()??"0")<=32?A.build("float"):A.build("double"))??t)}return super.dataTypeSql(t)}versionSql(t){return super.versionSql(t).replace("FOR ","")}structSql(t){let r=[];return t.args.expressions?.forEach(s=>{if(s instanceof Q){this.unsupported("Hive does not support named structs.");let E=s.args.expression;r.push(E instanceof b||typeof E=="string"?E:"")}else r.push(s)}),this.func("STRUCT",r)}columnDefSql(t,r={}){let{sep:s=" "}=r;return super.columnDefSql(t,{sep:t.parent instanceof A&&t.parent.isType("struct")?": ":s})}alterColumnSql(t){let r=this.sql(t,"this"),s=this.sql(t,"renameTo")||r,E=this.sql(t,"dtype"),h=this.sql(t,"comment"),l=h?` COMMENT ${h}`:"",D=this.sql(t,"default"),X=t.args.visible,q=t.args.allowNull,ge=t.args.drop;return(D||ge||X||q)&&this.unsupported("Unsupported CHANGE COLUMN syntax"),E||this.unsupported("CHANGE COLUMN without a type is not supported"),`CHANGE COLUMN ${r} ${s} ${E}${l}`}renameColumnSql(t){return this.unsupported("Cannot rename columns without data type defined in Hive"),""}alterSetSql(t){let r=this.expressions(t,{flat:!0});r=r?` ${r}`:"";let s=this.sql(t,"location");s=s?` LOCATION ${s}`:"";let E=this.expressions(t,{key:"fileFormat",flat:!0,sep:" "});E=E?` FILEFORMAT ${E}`:"";let h=this.sql(t,"serde");h=h?` SERDE ${h}`:"";let l=this.expressions(t,{key:"tag",flat:!0,sep:""});return l=l?` TAGS ${l}`:"",`SET${h}${r}${s}${E}${l}`}serdePropertiesSql(t){let r=t.args.with?"WITH ":"",s=this.expressions(t,{flat:!0});return`${r}SERDEPROPERTIES (${s})`}existsSql(t){return t.args.expression?this.functionFallbackSql(t):super.existsSql(t)}timeToStrSql(t){let r=t.args.this;return r instanceof B&&(r=r.args.this),this.func("DATE_FORMAT",[r,this.formatTime(t)])}fileFormatPropertySql(t){let r;return t.args.this instanceof Kt?r=this.sql(t,"this"):r=t.name.toUpperCase(),`STORED AS ${r}`}};d=P(Oe),o(d,10,"EXPRESSIONS_WITHOUT_NESTED_CTES",Ne,a),o(d,10,"SUPPORTED_JSON_PATH_PARTS",Re,a),o(d,10,"TYPE_MAPPING",fe,a),o(d,10,"ORIGINAL_TRANSFORMS",xe,a),o(d,10,"PROPERTIES_LOCATION",Ae,a),o(d,10,"TS_OR_DS_EXPRESSIONS",he,a),g(d,a),M(d,3,a),i(a,"HiveGenerator"),a.SUPPORTS_DECODE_CASE=!1,a.SELECT_KINDS=[],a.TRY_SUPPORTED=!1,a.SUPPORTS_UESCAPE=!1,a.LIMIT_FETCH="LIMIT",a.TABLESAMPLE_WITH_METHOD=!1,a.JOIN_HINTS=!1,a.TABLE_HINTS=!1,a.QUERY_HINTS=!1,a.INDEX_ON="ON TABLE",a.EXTRACT_ALLOWS_QUOTES=!1,a.NVL2_SUPPORTED=!1,a.LAST_DAY_SUPPORTS_DATE_PART=!1,a.JSON_PATH_SINGLE_QUOTE_ESCAPE=!0,a.SAFE_JSON_PATH_KEY_RE=/^[_\-a-zA-Z][\-\w]*$/,a.SUPPORTS_TO_NUMBER=!1,a.WITH_PROPERTIES_PREFIX="TBLPROPERTIES",a.PARSE_JSON_NAME=void 0,a.PAD_FILL_PATTERN_IS_REQUIRED=!0,a.SUPPORTS_MEDIAN=!1,a.ARRAY_SIZE_NAME="SIZE",a.ALTER_SET_TYPE="",a.IGNORE_NULLS_FUNCS=[lt,ht,At,xt];var qt=a,Ie,me,de,De,U,T=class T extends(De=_s,de=[p],me=[p],Ie=[p],De){static get EXPRESSION_METADATA(){return new Map(Zs.EXPRESSION_METADATA)}static get COERCES_TO(){let t=new Map(wt.COERCES_TO);for(let r of[...A.NUMERIC_TYPES,...A.TEMPORAL_TYPES,"interval"]){let s=t.get(r)??new Set;t.set(r,new Set([...s,...A.TEXT_TYPES]))}return t}static get NORMALIZATION_STRATEGY(){return"caseInsensitive"}static get TIME_MAPPING(){return{y:"%Y",Y:"%Y",YYYY:"%Y",yyyy:"%Y",YY:"%y",yy:"%y",MMMM:"%B",MMM:"%b",MM:"%m",M:"%-m",dd:"%d",d:"%-d",HH:"%H",H:"%-H",hh:"%I",h:"%-I",mm:"%M",m:"%-M",ss:"%S",s:"%-S",SSSSSS:"%f",a:"%p",DD:"%j",D:"%-j",E:"%a",EE:"%a",EEE:"%a",EEEE:"%A",z:"%Z",Z:"%z"}}};U=P(De),o(U,10,"COERCES_TO",de,T),o(U,10,"NORMALIZATION_STRATEGY",me,T),o(U,10,"TIME_MAPPING",Ie,T),g(U,T),M(U,3,T),i(T,"Hive"),T.DIALECT_NAME="hive",T.ALIAS_POST_TABLESAMPLE=!0,T.IDENTIFIERS_CAN_START_WITH_DIGIT=!0,T.SUPPORTS_USER_DEFINED_TYPES=!1,T.JsonPathTokenizer=Lt,T.SAFE_DIVISION=!0,T.ARRAY_AGG_INCLUDES_NULLS=void 0,T.REGEXP_EXTRACT_DEFAULT_GROUP=1,T.ALTER_TABLE_SUPPORTS_CASCADE=!0,T.INITCAP_DEFAULT_DELIMITER_CHARS=`
|
|
1
|
+
import{a as Zs}from"./chunk-3XORKTWN.js";import{$v as qs,Ah as ar,Ai as cr,Aq as Zr,Aw as Js,Bj as Q,Br as ns,Bt as ft,Cd as Xt,Ci as W,Cn as H,Cp as Kr,Cr as is,Cw as Ks,Di as lr,Dr as B,Dv as Ps,Eo as $r,Eq as ot,Er as as,Ev as gs,Fd as bt,Fi as hr,Fr as Es,Fv as Ms,Gd as Vt,Gm as _r,Gp as Wr,Gr as C,Gw as Pt,Hj as Or,Hr as os,Hw as Ws,Ij as Ir,Io as Xr,Iv as Cs,Jb as Gt,Ji as Ar,Jr as I,Jv as mt,Kf as jt,Kn as wr,Kv as _,Ls as ls,Ml as Pr,Mn as Gr,Na as wt,Nr as ps,Ns as hs,Nv as _s,Od as Jt,On as z,Os as ct,Ow as ks,Ph as Er,Pr as Ts,Pu as Ns,Qh as or,Qj as mr,Qp as et,Qv as S,Rp as nt,Rv as ys,Rw as gt,Sa as u,Sd as Kt,Sk as dr,Sr as Tt,Su as Ot,Sv as Ls,Te as Qt,Tf as Ht,Tl as gr,Tn as Br,Tr as ut,Ul as Mr,Up as kr,Ur as us,Us as As,Vm as yr,Vw as Qs,We as Zt,Wi as xr,Wk as w,Wv as Fs,Xg as er,Xm as j,Xp as it,Xs as lt,Yi as fr,Yl as Cr,Ym as G,Ys as ht,Yv as Us,Zh as pr,Zs as At,_s as xt,a as i,ac as Bt,aj as Rr,b as P,be as Wt,bt as xs,bu as Rt,c as g,ce as kt,cj as k,cr as jr,cw as ws,d as M,do as v,dw as Gs,e as o,eg as zt,en as Lr,ew as Bs,fg as vt,fo as tt,fp as br,gc as Yt,gn as Fr,hg as tr,hp as rt,id as $t,iw as dt,ix as Mt,jg as rr,js as St,jv as It,kn as Ur,kp as st,kr as Hr,kw as F,kx as Ct,lu as Nt,lw as Dt,mc as V,mv as L,nn as qr,nr as zr,oe as J,ol as Z,or as vr,ov as Os,pb as f,pe as A,pr as pt,pv as Is,qi as Tr,qo as Yr,qr as ts,qv as ms,ri as ur,rr as rs,s as p,sg as sr,tg as R,tt as fs,tv as ds,uv as Ds,uw as Ys,vl as Dr,vr as ss,vs as Ss,vw as $s,wh as nr,wp as Vr,ws as cs,wt as Rs,ww as Xs,wx as Y,xb as b,xp as Jr,xq as at,xw as bs,yh as K,yj as Nr,yq as Et,zh as ir,zi as Sr,zq as Qr,zr as es,zw as Vs}from"./chunk-FU46WFXM.js";var Pe={YEAR:["ADD_MONTHS",12],MONTH:["ADD_MONTHS",1],QUARTER:["ADD_MONTHS",3],WEEK:["DATE_ADD",7],DAY:["DATE_ADD",1]},Me={MILLISECOND:" * 1000",SECOND:"",MINUTE:" / 60",HOUR:" / 3600"},Ce=new Set(["YEAR","QUARTER","MONTH"]);function _t(e){if(e instanceof C&&!e.args.unit)return this.func("DATE_ADD",[e.args.this,e.args.expression]);let n=e.text("unit").toUpperCase(),[t,r]=Pe[n]||["DATE_ADD",1];e instanceof j&&(r*=-1);let s=e.args.expression;if(s instanceof R){let E=s.isNumber?parseFloat(s.args.this??"0"):parseInt(s.args.this??"0");s=R.number(E*r)}else r!==1&&(s=new mr({this:s,expression:R.number(r)}));return this.func(t,[e.args.this,s])}i(_t,"addDateSql");function js(e){let n=e.text("unit").toUpperCase(),t=Me[n];if(t!==void 0){let D=this.sql(e,"this"),X=this.sql(e,"expression"),q=`UNIX_TIMESTAMP(${D}) - UNIX_TIMESTAMP(${X})`;return t?`(${q})${t}`:q}let r=Ce.has(n),s=r?"MONTHS_BETWEEN":"DATEDIFF",E=Pe[n]?.[1]||1,h=1<E?` / ${E}`:"",l=`${s}(${this.formatArgs([e.args.this,e.args.expression])})`;return(r||h)&&(l=`CAST(${l}${h} AS INT)`),l}i(js,"dateDiffSql");function _e(e){let n=e.args.this;if(n&&ks(n)){if(n.args.this instanceof R&&n.args.this.isString){let t=R.string(`[${n.args.this.args.this}]`),r=this.func("FROM_JSON",[t,this.func("SCHEMA_OF_JSON",[t])]),s=this.func("TO_JSON",[r]);return this.func("REGEXP_EXTRACT",[s,"'^.(.*).$'","1"])}return this.sql(n)}return this.func("TO_JSON",[n,e.args.options])}i(_e,"jsonFormatSql");function ye(e){return e.args.expression&&this.unsupported("Unsupported arg 'expression' for ArraySort"),this.func("SORT_ARRAY",[e.args.this])}i(ye,"arraySortSql");function Le(e){return this.func("UNIX_TIMESTAMP",[e.args.this,Dt("hive").call(this,e)])}i(Le,"strToUnixSql");function Fe(e){let n=this.sql(e,"this"),t=e.args.scale;return t===void 0||t.toValue()===ut.SECONDS.toValue()?S("FROM_UNIXTIME").call(this,e):`FROM_UNIXTIME(${n} / POW(10, ${t}))`}i(Fe,"unixToTimeSql");function Ue(e){let n=this.sql(e,"this"),t=this.formatTime(e);return t!=null&&![O.TIME_FORMAT,O.DATE_FORMAT].includes(t)&&(n=`FROM_UNIXTIME(UNIX_TIMESTAMP(${n}, ${t}))`),`CAST(${n} AS DATE)`}i(Ue,"strToDateSql");function qe(e){let n=this.sql(e,"this"),t=this.formatTime(e);return t!=null&&![O.TIME_FORMAT,O.DATE_FORMAT].includes(t)&&(n=`FROM_UNIXTIME(UNIX_TIMESTAMP(${n}, ${t}))`),`CAST(${n} AS TIMESTAMP)`}i(qe,"strToTimeSql");function we(e){let n=this.formatTime(e);return n&&![O.TIME_FORMAT,O.DATE_FORMAT].includes(n)?this.func("TO_DATE",[e.args.this,n]):e.parent instanceof b&&this._constructor.TS_OR_DS_EXPRESSIONS.has(e.parent._constructor)?this.sql(e,"this"):this.func("TO_DATE",[e.args.this])}i(we,"toDateSql");function $(e){return n=>{let t=new e({this:u(n,0)});return u(n,1)instanceof Ar&&u(n,1)?.args.this===!0?new Zt({this:t}):t}}i($,"buildWithIgnoreNulls");function Ge(e){let n=F(I,{dialect:"hive"})(e);return n.setArgKey("safe",!0),n}i(Ge,"buildToDate");function Be(e){let n=u(e,1);return n&&(n=n.mul(-1)),new C({this:u(e,0),expression:n,unit:Ot("DAY")})}i(Be,"buildDateAdd");var Hs,zs,yt,y=class y extends(zs=It,Hs=[p],zs){static get VAR_TOKENS(){return new Set([...It.VAR_TOKENS,"dash"])}};yt=P(zs),o(yt,10,"VAR_TOKENS",Hs,y),g(yt,y),M(yt,3,y),i(y,"HiveJsonPathTokenizer");var Lt=y,vs,te,re,se,ee,ne,ie,m,x=class x extends(ie=Y,ne=[p],ee=[p],se=[p],re=[p],te=[p],vs=[p],ie){static get QUOTES(){return["'",'"']}static get IDENTIFIERS(){return["`"]}static get STRING_ESCAPES(){return["\\"]}static get SINGLE_TOKENS(){return{...Y.SINGLE_TOKENS,$:"parameter"}}static get ORIGINAL_KEYWORDS(){return{...Y.KEYWORDS,"ADD ARCHIVE":"command","ADD ARCHIVES":"command","ADD FILE":"command","ADD FILES":"command","ADD JAR":"command","ADD JARS":"command",MINUS:"except","MSCK REPAIR":"command",REFRESH:"refresh","TIMESTAMP AS OF":"timestampSnapshot","VERSION AS OF":"versionSnapshot",SERDEPROPERTIES:"serdeProperties"}}static get NUMERIC_LITERALS(){return{L:"BIGINT",S:"SMALLINT",Y:"TINYINT",D:"DOUBLE",F:"FLOAT",BD:"DECIMAL"}}};m=P(ie),o(m,10,"QUOTES",ne,x),o(m,10,"IDENTIFIERS",ee,x),o(m,10,"STRING_ESCAPES",se,x),o(m,10,"SINGLE_TOKENS",re,x),o(m,10,"ORIGINAL_KEYWORDS",te,x),o(m,10,"NUMERIC_LITERALS",vs,x),g(m,x),M(m,3,x),i(x,"HiveTokenizer");var Ft=x,ae,Ee,oe,pe,Te,ue,Se,ce,le,N,c=class c extends(le=f,ce=[p],Se=[p],ue=[p],Te=[p],pe=[p],oe=[p],Ee=[p],ae=[p],le){static get ID_VAR_TOKENS(){return new Set([...f.ID_VAR_TOKENS,"sessionUser","currentCatalog","straightJoin"])}static get NO_PAREN_FUNCTIONS(){let t={...f.NO_PAREN_FUNCTIONS};return delete t.currentTime,delete t.localtime,delete t.localtimestamp,t}static get FUNCTION_PARSERS(){return{...f.FUNCTION_PARSERS,PERCENTILE:i(function(){return this.parseQuantileFunction(ft)},"PERCENTILE"),PERCENTILE_APPROX:i(function(){return this.parseQuantileFunction(Rt)},"PERCENTILE_APPROX")}}static get FUNCTIONS(){return{...f.FUNCTIONS,ADD_MONTHS:i(t=>new C({this:u(t,0),expression:u(t,1),unit:Ot("MONTH")}),"ADD_MONTHS"),BASE64:i(t=>tt.fromArgList(t),"BASE64"),COLLECT_LIST:i(t=>new hs({this:u(t,0),nullsExcluded:!0}),"COLLECT_LIST"),COLLECT_SET:i(t=>ct.fromArgList(t),"COLLECT_SET"),DATE_ADD:i(t=>new C({this:u(t,0),expression:u(t,1),unit:new kt({this:"DAY"})}),"DATE_ADD"),DATE_FORMAT:i(t=>F(es,{dialect:"hive"})([new B({this:u(t,0)}),u(t,1)]),"DATE_FORMAT"),DATE_SUB:Be,DATEDIFF:i(t=>new G({this:new I({this:u(t,0)}),expression:new I({this:u(t,1)})}),"DATEDIFF"),DAY:i(t=>new z({this:new I({this:u(t,0)})}),"DAY"),FIRST:$(lt),FIRST_VALUE:$(At),FROM_UNIXTIME:F(Tt,{dialect:"hive",defaultValue:!0}),GET_JSON_OBJECT:i((t,{dialect:r})=>new rt({this:u(t,0),expression:r.toJsonPath(u(t,1))}),"GET_JSON_OBJECT"),LAST:$(ht),LAST_VALUE:$(xt),MAP:i(t=>{if(t.length===1&&t[0].isStar)return new et({this:t[0]});let r=[],s=[];for(let E=0;E<t.length;E+=2)r.push(t[E]),t[E+1]&&s.push(t[E+1]);return new nt({keys:new w({expressions:r}),values:new w({expressions:s})})},"MAP"),MONTH:i(t=>new it({this:new I({this:u(t,0)})}),"MONTH"),REGEXP_EXTRACT:Ct(at),REGEXP_EXTRACT_ALL:Ct(Et),SEQUENCE:i(t=>Z.fromArgList(t),"SEQUENCE"),SIZE:i(t=>gr.fromArgList(t),"SIZE"),SPLIT:i(t=>ot.fromArgList(t),"SPLIT"),STR_TO_MAP:i(t=>new ts({this:u(t,0),pairDelim:u(t,1)||R.string(","),keyValueDelim:u(t,2)||R.string(":")}),"STR_TO_MAP"),TO_DATE:Ge,TO_JSON:i(t=>st.fromArgList(t),"TO_JSON"),TRUNC:i(t=>H.fromArgList(t),"TRUNC"),UNBASE64:i(t=>v.fromArgList(t),"UNBASE64"),UNIX_TIMESTAMP:i(t=>F(pt,{dialect:"hive",defaultValue:!0})(0<t.length?t:[new _r({})]),"UNIX_TIMESTAMP"),YEAR:i(t=>new St({this:new I({this:u(t,0)})}),"YEAR")}}static get NO_PAREN_FUNCTION_PARSERS(){return{...f.NO_PAREN_FUNCTION_PARSERS,TRANSFORM:i(function(){return this.parseTransform()},"TRANSFORM")}}static get PROPERTY_PARSERS(){return{...f.PROPERTY_PARSERS,SERDEPROPERTIES:i(function(){return new or({expressions:this.parseWrappedCsv(()=>this.parseProperty())})},"SERDEPROPERTIES")}}static get ALTER_PARSERS(){return{...f.ALTER_PARSERS,CHANGE:i(function(){return this.parseAlterTableChange()},"CHANGE")}}parseTransform(){if(!this.match("lParen",{advance:!1})){this.retreat(this.index-1);return}let t=this.parseWrappedCsv(()=>this.parseLambda()),r=this.parseRowFormat({matchRow:!0}),s;if(this.matchTextSeq("RECORDWRITER")&&(s=this.parseString()),!this.match("using"))return dr.fromArgList(t);let E=this.parseString();this.match("alias");let h=this.parseSchema(),l=this.parseRowFormat({matchRow:!0}),D;return this.matchTextSeq("RECORDREADER")&&(D=this.parseString()),this.expression(Jt,{expressions:t,commandScript:E,schema:h,rowFormatBefore:r,recordWriter:s,rowFormatAfter:l,recordReader:D})}parseQuantileFunction(t){let r;this.match("distinct")?r=this.expression(Qt,{expressions:[this.parseLambda()]}):(this.match("all"),r=this.parseLambda());let s=[r];return this.match("comma")&&s.push(...this.parseFunctionArgs()),t.fromArgList(s)}parseTypes(t={}){let{checkFunc:r=!1,schema:s=!1,allowIdentifiers:E=!0}=t,h=super.parseTypes({checkFunc:r,schema:s,allowIdentifiers:E});return h&&!s?h.transform((l,D)=>l instanceof A&&l.isType(["char","varchar"])?l.replace(A.build("text")):l,{copy:!1}):h}parseAlterTableChange(){this.match("column");let t=this.parseField({anyToken:!0});if(this.constructor.CHANGE_COLUMN_ALTER_SYNTAX&&this.matchTextSeq("TYPE"))return this.expression(V,{this:t,dtype:this.parseTypes({schema:!0})});let r=this.parseField({anyToken:!0}),s=this.parseTypes({schema:!0}),E=this.match("comment")&&this.parseString();return(!t||!r||!s)&&this.raiseError("Expected 'CHANGE COLUMN' to be followed by 'column_name' 'column_name' 'data_type'"),this.expression(V,{this:t,renameTo:r,dtype:s,comment:E})}parsePartitionAndOrder(){return[this.matchSet(["partitionBy","distributeBy"])?this.parseCsv(()=>this.parseAssignment()):[],super.parseOrder({skipOrderToken:this.match("sortBy")})??void 0]}parseParameter(){this.match("lBrace");let t=this.parseIdentifier()||this.parsePrimaryOrVar(),r=this.match("colon")&&(this.parseIdentifier()||this.parsePrimaryOrVar());return this.match("rBrace"),this.expression(hr,{this:t,expression:r})}toPropEq(t,r){if(t.isStar)return t;let s;return t instanceof jt?s=t.args.this??Nt(`col${r+1}`):s=Nt(`col${r+1}`),this.expression(Q,{this:s,expression:t})}static get TABLE_ALIAS_TOKENS(){return new Set([...f.TABLE_ALIAS_TOKENS,"straightJoin"])}};N=P(le),o(N,10,"ID_VAR_TOKENS",ce,c),o(N,10,"NO_PAREN_FUNCTIONS",Se,c),o(N,10,"FUNCTION_PARSERS",ue,c),o(N,10,"FUNCTIONS",Te,c),o(N,10,"NO_PAREN_FUNCTION_PARSERS",pe,c),o(N,10,"PROPERTY_PARSERS",oe,c),o(N,10,"ALTER_PARSERS",Ee,c),o(N,10,"TABLE_ALIAS_TOKENS",ae,c),g(N,c),M(N,3,c),i(c,"HiveParser"),c.LOG_DEFAULTS_TO_LN=!0,c.STRICT_CAST=!1,c.VALUES_FOLLOWED_BY_PAREN=!1,c.JOINS_HAVE_EQUAL_PRECEDENCE=!0,c.ADD_JOIN_ON_TRUE=!0,c.ALTER_TABLE_PARTITIONS=!0,c.CHANGE_COLUMN_ALTER_SYNTAX=!1;var Ut=c,he,Ae,xe,fe,Re,Ne,Oe,d,a=class a extends(Oe=_,Ne=[p],Re=[p],fe=[p],xe=[p],Ae=[p],he=[p],Oe){static get EXPRESSIONS_WITHOUT_NESTED_CTES(){return new Set([sr,W,lr,cr])}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([xr,fr,Rr,k])}static get TYPE_MAPPING(){return new Map([..._.TYPE_MAPPING,["bit","BOOLEAN"],["blob","BINARY"],["datetime","TIMESTAMP"],["rowversion","BINARY"],["text","STRING"],["time","TIMESTAMP"],["timestampntz","TIMESTAMP"],["timestamptz","TIMESTAMP"],["utinyint","SMALLINT"],["varbinary","BINARY"]])}static get ORIGINAL_TRANSFORMS(){return new Map([..._.TRANSFORMS,[Vt,ws],[As,S("FIRST")],[ls,ys],[Ss,gt("MAX_BY")],[cs,gt("MIN_BY")],[w,L([Cs])],[Dr,S("CONCAT")],[Pr,function(r){return this.func("CONCAT_WS",[r.args.expression,r.args.this])}],[Mr,function(r){return ye.call(this,r)}],[Yt,Us],[yr,function(r){return _t.call(this,r)}],[G,function(r){return js.call(this,r)}],[wr,bs],[j,function(r){return _t.call(this,r)}],[Gr,function(r){return`CAST(DATE_FORMAT(${this.sql(r,"this")}, ${O.DATEINT_FORMAT}) AS INT)`}],[Br,function(r){return`TO_DATE(CAST(${this.sql(r,"this")} AS STRING), ${O.DATEINT_FORMAT})`}],[pr,function(r){return`STORED BY ${this.sql(r,"this")}`}],[v,S("UNBASE64")],[Z,Mt],[Yr,Mt],[$r,Ls()],[Or,Fs],[Ir,function(r){return this.binary(r,"DIV")}],[Xr,S("ISNAN")],[br,function(r){return this.func("GET_JSON_OBJECT",[r.args.this,r.args.expression])}],[rt,function(r){return this.func("GET_JSON_OBJECT",[r.args.this,r.args.expression])}],[st,function(r){return _e.call(this,r)}],[Vr,Ys],[Wr,dt],[fs,Js],[kr,function(r){return this.func("UNHEX",[this.func("MD5",[r.args.this])])}],[Rs,Vs],[qr,function(r){return this.func("MONTHS_BETWEEN",[r.args.this,r.args.expression])}],[tr,function(r){return r.args.allowNull?"":"NOT NULL"}],[nt,dt],[Gt,L([Ps,gs,Ms])],[ft,S("PERCENTILE")],[Rt,S("PERCENTILE_APPROX")],[at,Pt],[Et,Pt],[Qr,Ws],[Zr,function(r){return this.binary(r,"RLIKE")}],[ot,S("SPLIT")],[Jr,$s],[Er,function(r){return this.nakedProperty(r)}],[ct,S("COLLECT_SET")],[jr,function(r){return this.func("SPLIT",[r.args.this,this.func("CONCAT",[R.string("\\Q"),r.args.expression,R.string("\\E")])])}],[W,L([ms,Is,r=>ds(r,{unnestUsingArraysZip:!1}),Ds])],[Hr,function(r){return Gs.call(this,r,{funcName:"LOCATE",supportsPosition:!0})}],[zr,function(r){return Ue.call(this,r)}],[vr,function(r){return qe.call(this,r)}],[pt,function(r){return Le.call(this,r)}],[ss,Bs],[et,S("MAP")],[Wt,L([Os])],[is,S("TO_DATE")],[B,Xs],[as,S("UNIX_TIMESTAMP")],[H,function(r){return this.func("TRUNC",[r.args.this,Qs(r)])}],[ns,S("UNIX_TIMESTAMP")],[tt,S("BASE64")],[ps,function(r){return`CAST(SUBSTR(REPLACE(CAST(${this.sql(r,"this")} AS STRING), '-', ''), 1, 8) AS INT)`}],[C,function(r){return _t.call(this,r)}],[os,function(r){return js.call(this,r)}],[I,function(r){return we.call(this,r)}],[xs,qs],[Es,Ks],[Ts,S("ASCII")],[Tt,function(r){return this.func("FROM_UNIXTIME",[r.args.this,Dt("hive").call(this,r)])}],[ut,function(r){return Fe.call(this,r)}],[us,S("FROM_UNIXTIME")],[K,function(r){return`PARTITIONED BY ${this.sql(r,"this")}`}],[rs,S("FORMAT_NUMBER")],[$t,function(r){return this.nationalSql(r,{prefix:""})}],[Ht,function(r){return`(${this.expressions(r,{key:"this",indent:!1})})`}],[zt,function(r){return`(${this.expressions(r,{key:"this",indent:!1})})`}],[vt,()=>""],[nr,()=>""],[ir,function(r){return this.func("BUCKET",[r.args.expression,r.args.this])}],[ar,function(r){return this.func("TRUNCATE",[r.args.expression,r.args.this])}],[rr,()=>"PRIMARY KEY"],[Ur,S("WEEKOFYEAR")],[Fr,S("DAYOFMONTH")],[Lr,S("DAYOFWEEK")],[Kr,function(r){return mt.call(this,r,"insCost","delCost","subCost","maxDist"),S("LEVENSHTEIN").call(this,r)}]])}static get PROPERTIES_LOCATION(){return new Map([..._.PROPERTIES_LOCATION,[er,"postSchema"],[K,"postSchema"],[Tr,"unsupported"],[ur,"unsupported"]])}static get TS_OR_DS_EXPRESSIONS(){return new Set([G,z,it,St])}ignoreNullsSql(t){let r=t.args.this;return this._constructor.IGNORE_NULLS_FUNCS.some(s=>r instanceof s)?this.func(r._constructor.sqlNames()[0],[r.args.this,Ns()]):super.ignoreNullsSql(t)}unnestSql(t){return S("EXPLODE").call(this,t)}jsonPathKeySql(t){return t.args.this instanceof k?(this.unsupported("Unsupported wildcard in JSONPathKey expression"),""):super.jsonPathKeySql(t)}parameterSql(t){let r=this.sql(t,"this"),s=this.sql(t,"expression"),E=t.parent;return r=s?`${r}:${s}`:r,E instanceof Nr&&E.parent instanceof Bt?r:`\${${r}}`}schemaSql(t){for(let r of t.findAll(bt))r.args.desc===!1&&r.setArgKey("desc",void 0);return super.schemaSql(t)}constraintSql(t){for(let E of Array.from(t.findAll(Sr)))E.pop();let r=this.sql(t,"this"),s=this.expressions(t,{sep:" ",flat:!0});return`CONSTRAINT ${r} ${s}`}rowFormatSerdePropertySql(t){let r=this.sql(t,"serdeProperties");return r=r?` ${r}`:"",`ROW FORMAT SERDE ${this.sql(t,"this")}${r}`}arrayAggSql(t){return this.func("COLLECT_LIST",[t.args.this instanceof Xt?t.args.this.args.this:t.args.this])}truncSql(t){return mt.call(this,t,"decimals"),this.sql(new Cr({this:t.args.this,to:A.build("bigint")}))}dataTypeSql(t){if(t.isType(_.PARAMETERIZABLE_TEXT_TYPES)&&(!t.args.expressions||t.args.expressions[0].name==="MAX"))t=A.build("text")??t;else if(t.isType("text")&&t.args.expressions)t.setArgKey("this","varchar");else if(t.isType(A.TEMPORAL_TYPES))t=A.build(t.args.this)??t;else if(t.isType("float")){let r=t.find(J);r instanceof J&&(t=(parseInt(r.args.this?.args.this?.toString()??"0")<=32?A.build("float"):A.build("double"))??t)}return super.dataTypeSql(t)}versionSql(t){return super.versionSql(t).replace("FOR ","")}structSql(t){let r=[];return t.args.expressions?.forEach(s=>{if(s instanceof Q){this.unsupported("Hive does not support named structs.");let E=s.args.expression;r.push(E instanceof b||typeof E=="string"?E:"")}else r.push(s)}),this.func("STRUCT",r)}columnDefSql(t,r={}){let{sep:s=" "}=r;return super.columnDefSql(t,{sep:t.parent instanceof A&&t.parent.isType("struct")?": ":s})}alterColumnSql(t){let r=this.sql(t,"this"),s=this.sql(t,"renameTo")||r,E=this.sql(t,"dtype"),h=this.sql(t,"comment"),l=h?` COMMENT ${h}`:"",D=this.sql(t,"default"),X=t.args.visible,q=t.args.allowNull,ge=t.args.drop;return(D||ge||X||q)&&this.unsupported("Unsupported CHANGE COLUMN syntax"),E||this.unsupported("CHANGE COLUMN without a type is not supported"),`CHANGE COLUMN ${r} ${s} ${E}${l}`}renameColumnSql(t){return this.unsupported("Cannot rename columns without data type defined in Hive"),""}alterSetSql(t){let r=this.expressions(t,{flat:!0});r=r?` ${r}`:"";let s=this.sql(t,"location");s=s?` LOCATION ${s}`:"";let E=this.expressions(t,{key:"fileFormat",flat:!0,sep:" "});E=E?` FILEFORMAT ${E}`:"";let h=this.sql(t,"serde");h=h?` SERDE ${h}`:"";let l=this.expressions(t,{key:"tag",flat:!0,sep:""});return l=l?` TAGS ${l}`:"",`SET${h}${r}${s}${E}${l}`}serdePropertiesSql(t){let r=t.args.with?"WITH ":"",s=this.expressions(t,{flat:!0});return`${r}SERDEPROPERTIES (${s})`}existsSql(t){return t.args.expression?this.functionFallbackSql(t):super.existsSql(t)}timeToStrSql(t){let r=t.args.this;return r instanceof B&&(r=r.args.this),this.func("DATE_FORMAT",[r,this.formatTime(t)])}fileFormatPropertySql(t){let r;return t.args.this instanceof Kt?r=this.sql(t,"this"):r=t.name.toUpperCase(),`STORED AS ${r}`}};d=P(Oe),o(d,10,"EXPRESSIONS_WITHOUT_NESTED_CTES",Ne,a),o(d,10,"SUPPORTED_JSON_PATH_PARTS",Re,a),o(d,10,"TYPE_MAPPING",fe,a),o(d,10,"ORIGINAL_TRANSFORMS",xe,a),o(d,10,"PROPERTIES_LOCATION",Ae,a),o(d,10,"TS_OR_DS_EXPRESSIONS",he,a),g(d,a),M(d,3,a),i(a,"HiveGenerator"),a.SUPPORTS_DECODE_CASE=!1,a.SELECT_KINDS=[],a.TRY_SUPPORTED=!1,a.SUPPORTS_UESCAPE=!1,a.LIMIT_FETCH="LIMIT",a.TABLESAMPLE_WITH_METHOD=!1,a.JOIN_HINTS=!1,a.TABLE_HINTS=!1,a.QUERY_HINTS=!1,a.INDEX_ON="ON TABLE",a.EXTRACT_ALLOWS_QUOTES=!1,a.NVL2_SUPPORTED=!1,a.LAST_DAY_SUPPORTS_DATE_PART=!1,a.JSON_PATH_SINGLE_QUOTE_ESCAPE=!0,a.SAFE_JSON_PATH_KEY_RE=/^[_\-a-zA-Z][\-\w]*$/,a.SUPPORTS_TO_NUMBER=!1,a.WITH_PROPERTIES_PREFIX="TBLPROPERTIES",a.PARSE_JSON_NAME=void 0,a.PAD_FILL_PATTERN_IS_REQUIRED=!0,a.SUPPORTS_MEDIAN=!1,a.ARRAY_SIZE_NAME="SIZE",a.ALTER_SET_TYPE="",a.IGNORE_NULLS_FUNCS=[lt,ht,At,xt];var qt=a,Ie,me,de,De,U,T=class T extends(De=_s,de=[p],me=[p],Ie=[p],De){static get EXPRESSION_METADATA(){return new Map(Zs.EXPRESSION_METADATA)}static get COERCES_TO(){let t=new Map(wt.COERCES_TO);for(let r of[...A.NUMERIC_TYPES,...A.TEMPORAL_TYPES,"interval"]){let s=t.get(r)??new Set;t.set(r,new Set([...s,...A.TEXT_TYPES]))}return t}static get NORMALIZATION_STRATEGY(){return"caseInsensitive"}static get TIME_MAPPING(){return{y:"%Y",Y:"%Y",YYYY:"%Y",yyyy:"%Y",YY:"%y",yy:"%y",MMMM:"%B",MMM:"%b",MM:"%m",M:"%-m",dd:"%d",d:"%-d",HH:"%H",H:"%-H",hh:"%I",h:"%-I",mm:"%M",m:"%-M",ss:"%S",s:"%-S",SSSSSS:"%f",a:"%p",DD:"%j",D:"%-j",E:"%a",EE:"%a",EEE:"%a",EEEE:"%A",z:"%Z",Z:"%z"}}};U=P(De),o(U,10,"COERCES_TO",de,T),o(U,10,"NORMALIZATION_STRATEGY",me,T),o(U,10,"TIME_MAPPING",Ie,T),g(U,T),M(U,3,T),i(T,"Hive"),T.DIALECT_NAME="hive",T.ALIAS_POST_TABLESAMPLE=!0,T.IDENTIFIERS_CAN_START_WITH_DIGIT=!0,T.SUPPORTS_USER_DEFINED_TYPES=!1,T.JsonPathTokenizer=Lt,T.SAFE_DIVISION=!0,T.ARRAY_AGG_INCLUDES_NULLS=void 0,T.REGEXP_EXTRACT_DEFAULT_GROUP=1,T.ALTER_TABLE_SUPPORTS_CASCADE=!0,T.INITCAP_DEFAULT_DELIMITER_CHARS=`
|
|
2
2
|
\r\f\v`,T.DATE_FORMAT="'yyyy-MM-dd'",T.DATEINT_FORMAT="'yyyyMMdd'",T.TIME_FORMAT="'yyyy-MM-dd HH:mm:ss'",T.Tokenizer=Ft,T.Parser=Ut,T.Generator=qt;var O=T;export{$ as a,Lt as b,O as c};
|
|
3
|
-
//# sourceMappingURL=chunk-
|
|
3
|
+
//# sourceMappingURL=chunk-RJXOZQWF.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{$a as gs,$j as pe,$n as te,Ab as Ae,Ad as Xe,Aj as ws,Bd as hs,Bi as w,Ci as P,Df as es,Di as le,Eu as qs,Fa as H,Fb as Es,Fu as Rs,Ga as q,Ha as D,Ia as V,Ja as Qe,Jf as O,Kf as As,La as re,Le as Z,Li as ee,Ma as Ge,Mi as Cs,Ms as vs,Mv as $,Na as He,Nd as se,Ne as Ss,Nu as Je,Oa as ms,Ou as B,Pa as de,Qa as Re,Qj as Ns,Ra as ds,Sa as L,Se as ys,Si as ge,Ta as Ye,Ti as M,Va as be,Vc as z,Wc as ae,Wu as oe,Xa as _e,Yj as Ne,Zc as Q,Zn as Ue,a as h,ae as U,bu as R,cb as ie,dj as Ts,dt as ss,du as ns,eu as Fe,fc as Y,fu as Is,fv as _s,gm as xe,he as we,hv as Ks,ic as F,ij as Me,iu as ke,jv as js,k as J,kc as Ke,kt as Pe,ku as _,kv as Ms,le as X,ls as De,lt as Le,lu as ts,m as Be,me as Ze,ms as he,n as fs,o as j,oe as je,p as me,pd as Ce,pu as I,q as ps,r as qe,ru as ue,s as us,sg as ce,st as Oe,tr as Os,ud as Te,uf as bs,vj as fe,vn as Ee,wb as T,wd as N,xb as xs,xj as W,yb as Ve,zi as ne}from"./chunk-CNQXTBAR.js";function Us(e){let t=V(e);if(t){let a=t.refCount(),s=[];for(let o of t.traverse())s.push(o);for(let o=s.length-1;0<=o;o--){let r=s[o];if(r.isCte){let c=r;if((a.get(c)||0)<=0){let n=r.expression.parent;if(!n)continue;let l=n.parent;if(n.pop(),l){let f=l.args.expressions;(!f||f.length===0)&&l.pop()}for(let[,f]of Object.entries(r.selectedSources)){let[,p]=f;if(p instanceof q){let m=a.get(p)||0;a.set(p,m-1)}}}}}}return e}h(Us,"eliminateCtes");function os(e){for(let t of D(e)){if(0<t.unqualifiedColumns.length)continue;let a=t.expression.args.joins;if(a)for(let s=a.length-1;0<=s;s--){let o=a[s];if(me(o,N),o.isSemiOrAntiJoin)continue;let r=o.aliasOrName;r&&hn(t,o,r)&&(o.pop(),t.removeSource(r))}}return e}h(os,"eliminateJoins");function hn(e,t,a){let s=e.sources.get(a);if(!(s instanceof q)||Sn(e,t,a))return!1;let o=t.args.side,r=t.args.on;return o==="left"&&yn(s,t)||!r&&Ps(s)}h(hn,"shouldEliminateJoin");function Sn(e,t,a){let s=t.args.on,o=new Set;if(s)for(let c of s.findAll(O))o.add(c);return e.sourceColumns(a).some(c=>!o.has(c))}h(Sn,"joinIsUsed");function yn(e,t){let a=bn(e);if(!a||a.size===0)return!1;let{joinKeys:s}=Ls(t),o=new Set(s.map(r=>r.name));for(let r of a)if(!o.has(r))return!1;return!0}h(yn,"isJoinedOnAllUniqueOutputs");function bn(e){let t=e.expression;if(!(t instanceof w))return;let a=t;if(a.args.distinct)return new Set(a.namedSelects);let s=a.args.group;if(s){let o=new Set((s.args.expressions??[]).filter(n=>n instanceof T).map(n=>n.sql())),r=new Set,c=new Set;for(let n of a.selects){if(!(n instanceof T))continue;let l=n.unalias().sql();o.has(l)&&(r.add(l),c.add(n.aliasOrName))}return[...o].every(n=>r.has(n))?c:new Set}return Ps(e)?new Set(a.namedSelects):new Set}h(bn,"uniqueOutputs");function Ps(e){let t=e.expression;if(!(t instanceof w))return!1;let a=t;return!!(!a.args.from||a.selects.every(o=>o instanceof T?o.unalias()instanceof M:!1)||An(e))}h(Ps,"hasSingleOutputRow");function An(e){let t=e.expression.getArgKey("limit");return t instanceof Te?t.args.expression?.args.this==="1":!1}h(An,"isLimit1");function Ls(e){let t=e.aliasOrName,s=(e.args.on||B()).copy(),o=[],r=[];function c(i){let[n,l]=i.unnestOperands();if(!n||!l)return;let f=Ds(n),p=Ds(l);t&&f.has(t)&&!p.has(t)?(r.push(n),o.push(l),i.replace(B())):t&&p.has(t)&&!f.has(t)&&(r.push(l),o.push(n),i.replace(B()))}if(h(c,"extractCondition"),de(s)){let i=s instanceof Pe?s:Fe([s,B()],{copy:!1});for(let n of i.flatten())n instanceof W&&c(n)}else if(de(s,{dnf:!0})){let i;for(let n of s.flatten()){let l=Array.from(n.flatten()).filter(f=>f instanceof W);if(i===void 0)i=l;else{let f=[];for(let p of l){let m=i.filter(d=>p.sql()===d.sql());0<m.length&&(f.push(p),f.push(...m))}i=f}}if(i)for(let n of i)c(n)}return{sourceKeys:o,joinKeys:r,on:s}}h(Ls,"joinCondition");function Ds(e){let t=new Set;for(let a of e.findAll(O))a.table&&t.add(a.table);return t}h(Ds,"columnTableNames");function rs(e){if(e instanceof P&&e.args.this)return rs(e.args.this),e;let t=V(e);if(!t)return e;let a=new Map;for(let n of t.cteScopes){let l=n.expression.parent;l&&a.set(l.alias,n)}for(let n of t.traverse())for(let[,l]of n.sources)l instanceof U&&a.set(l.name,l);let s=new Map,o=t.expression.args.with,r=!1;if(o){me(o,Y),r=!!o.args.recursive;for(let n of o.args.expressions??[])j(n,es)&&n.args.this&&n.args.this&&s.set(n.args.this.sqlKey,n.alias)}let c=[];for(let n of t.cteScopes){for(let f of n.traverse()){if(f===n)continue;let p=Fs(f,s,a);p&&c.push(p)}let l=n.expression.parent;l&&c.push(l)}let i=[...t.unionScopes,...t.subqueryScopes,...t.tableScopes];for(let n of i)for(let l of n.traverse()){let f=Fs(l,s,a);f&&c.push(f)}return 0<c.length&&(e instanceof Es?e.args.expression:e)?.setArgKey("with",new Y({expressions:c,recursive:r})),e}h(rs,"eliminateSubqueries");function Fs(e,t,a){if(e.isDerivedTable)return Cn(e,t,a);if(e.isCte)return Tn(e,t,a)}h(Fs,"eliminate");function Cn(e,t,a){if(e.parent&&(0<e.parent.pivots.length||e.parent.expression instanceof Ts))return;let s=e.expression.parent;if(!s)return;s instanceof P&&(s=s.unwrap());let[o,r]=ks(e,t,a),c=I(ns(o),s.alias||o,{copy:!1}),n=s.args.joins;return n&&Array.isArray(n)&&c.setArgKey("joins",n),s.replace(c),r}h(Cn,"eliminateDerivedTable");function Tn(e,t,a){let s=e.expression.parent;if(!s)return;let[o,r]=ks(e,t,a),c=s.parent;if(s.pop(),c){let i=c.args.expressions;(!i||i.length===0)&&c.pop()}if(e.parent)for(let i of e.parent.traverse())for(let[,n]of Object.entries(i.selectedSources)){let[l,f]=n;if(f===e){let p=I(ns(o),l.aliasOrName,{copy:!1});l.replace(p)}}return r}h(Tn,"eliminateCte");function ks(e,t,a){let s=t.get(e.expression.sqlKey),r=e.expression.parent?.alias||"";r||(r=be(Array.from(a.keys()),"cte")),s?r=s:a.has(r)&&(r=be(Array.from(a.keys()),r)),a.set(r,e);let c;return s||(t.set(e.expression.sqlKey,r),c=new es({this:e.expression,alias:new F({this:_(r)})})),[r,c]}h(ks,"newCte");function Js(e,t={}){let{leaveTablesIsolated:a=!1}=t;return e=Nn(e,{leaveTablesIsolated:a}),e=On(e,{leaveTablesIsolated:a}),e}h(Js,"mergeSubqueries");var wn=us(()=>[O,W,ge,Ns,Ne]);function Nn(e,t){let{leaveTablesIsolated:a}=t,s=Array.from(D(e)),o=new Map;for(let c of s)for(let[,i]of Object.entries(c.selectedSources)){let[n,l]=i;if(l instanceof q&&l.isCte){let f=o.get(l);f||(f=[],o.set(l,f)),f.push([c,l,n])}}let r=[];for(let[,c]of o)c.length===1&&r.push(c[0]);for(let[c,i,n]of r){let l=n.findAncestor(z,N);if(l&&zs(c,i,{leaveTablesIsolated:a},l)){let f=n.aliasOrName;$s(c,i,f),Ws(c,i,n,f),Qs(c,i,f),Hs(c,i),Bs(c,i,l),Gs(c,i,l),Ys(c,i),vn(i),c.clearCache()}}return e}h(Nn,"mergeCtes");function On(e,t){let{leaveTablesIsolated:a}=t;for(let s of D(e))for(let o of s.derivedTables){let r=o.findAncestor(z,N),c=o.aliasOrName,i=s.sources.get(c);i instanceof q&&r&&zs(s,i,{leaveTablesIsolated:a},r)&&($s(s,i,c),Ws(s,i,o,c),Qs(s,i,c),Hs(s,i),Bs(s,i,r),Gs(s,i,r),Ys(s,i),s.clearCache())}return e}h(On,"mergeDerivedTables");function zs(e,t,a,s){let{leaveTablesIsolated:o}=a,r=t.expression.unnest();function c(){let u=new Set;if(!(r instanceof w))return!1;let g=r;for(let b of g.selects)b instanceof T&&b.find(le)&&u.add(b.aliasOrName);let A=s.aliasOrName,x=[];for(let b of e.columns)b.findAncestor(X,Ce,hs,N,ae,M)!==void 0&&x.push(b);return 0<x.filter(b=>b.table===A&&u.has(b.name)).length}h(c,"isWindowExpressionInUnmergableOperation");function i(){if(!(s instanceof N))return!1;let u=s.aliasOrName,g=s.args.on;if(!g)return!1;let A=Array.from(g.findAll(O)).filter(S=>S.table===u).map(S=>S.name),x=t.expression.getArgKey("from");if(!x)return!1;let E=x.aliasOrName;if(!(t.expression instanceof w))return!1;let b=t.expression,y=new Map;for(let S of b.selects)S instanceof T&&y.set(S.aliasOrName,S);return A.some(S=>{let C=y.get(S);return C?Array.from(C.findAll(O)).some(K=>K.table!==E):!1})}h(i,"outerSelectJoinsOnInnerSelectJoin");function n(){let u=t.expression.parent,g=e.expression.parent;for(;g;){if(g===u)return!0;g=g.parent}return!1}if(h(n,"isRecursive"),!(e.expression instanceof w))return!1;let l=e.expression;if(l.isStar||!(r instanceof w))return!1;let f=r;for(let u of $.UNMERGABLE_ARGS)if(f.getArgKey(u))return!1;if(!f.args.from||0<e.pivots.length)return!1;for(let u of f.args.expressions??[])if(u instanceof T&&(u.find(M)||u.find(w)||u.find(Ue)))return!1;if(o&&1<Object.keys(e.selectedSources).length||s instanceof N&&f.args.joins&&0<f.args.joins.length)return!1;let p=s instanceof N?s.args.side:void 0;if(s instanceof N&&f.args.where&&(p==="full"||p==="left"||p==="right"))return!1;let m=l.args.joins;return!(s instanceof z&&f.args.where&&m&&m.some(u=>j(u,N)&&(u.args.side==="full"||u.args.side==="right"))||i()||c()||n()||f.args.order&&e.isUnion||L(f.args.expressions??[],0)instanceof se)}h(zs,"mergeable");function $s(e,t,a){let s=new Set(Object.keys(t.selectedSources)),o=new Set(Object.keys(e.selectedSources)),r=new Set(Array.from(s).filter(i=>o.has(i)));r.delete(a);let c=new Set([...o,...s]);for(let i of r){let n=be(Array.from(c),i),l=t.selectedSources[i];if(!l)continue;let[f]=l,p=_(n);f instanceof U?f.alias?f.setArgKey("alias",p):f.replace(I(f,p,{copy:!1})):f?.parent instanceof P&&f.parent.setArgKey("alias",new F({this:p}));for(let m of t.sourceColumns(i))m.setArgKey("table",_(n));t.renameSource(i,n),c.add(n)}}h($s,"renameInnerSources");function Ws(e,t,a,s){let r=t.expression.getArgKey("from").args.this;r.setArgKey("joins",a.args.joins),a.replace(r);for(let i of e.joinHints){let n=Array.from(i.findAll(U));for(let l of n)l.aliasOrName===a.aliasOrName&&l.setArgKey("this",_(r.aliasOrName))}e.removeSource(s);let c=t.sources.get(r.aliasOrName);c!==void 0&&e.addSource(r.aliasOrName,c)}h(Ws,"mergeFrom");function Bs(e,t,a){let s=[],o=t.expression.getArgKey("joins");if(o)for(let r of o){s.push(r);let c=t.sources.get(r.aliasOrName);c&&e.addSource(r.aliasOrName,c)}if(0<s.length){let r=e.expression.getArgKey("joins")||[],c;a instanceof z?c=0:c=r.indexOf(a)+1,r.splice(c,0,...s),e.expression.setArgKey("joins",r)}}h(Bs,"mergeJoins");function Qs(e,t,a){let s=new Map;for(let r of e.columns)if(r.table===a){let c=r.name,i=s.get(c);i||(i=[],s.set(c,i)),i.push(r)}if(!(t.expression instanceof w))return;let o=t.expression;for(let r of o.args.expressions??[]){if(!(r instanceof T))continue;let c=r.aliasOrName;if(!c)continue;let i=s.get(c)||[],n=r.unalias(),l=!wn().some(p=>n instanceof p),f=n.isNumber;for(let p of i){let m=p.parent;if(f&&m instanceof Ce){p.replace(_(p.name));continue}let d=n;m&&(m instanceof Cs||m instanceof ee)&&l&&(d=ke(d,{copy:!1})),m instanceof w&&p.name!==d.name&&(d=I(d,p.name,{copy:!1})),p.replace(d.copy())}}}h(Qs,"mergeExpressions");function Gs(e,t,a){let s=t.expression.getArgKey("where");if(!s)return;let o=s.args.this;if(!(o instanceof T))return;let r=e.expression;if(a instanceof N){let c=r.args.from,i=new Set;c&&i.add(c.aliasOrName);let n=r.args.joins;if(n)for(let p of n){let m=p.aliasOrName;if(i.add(m),m===a.aliasOrName)break}let l=oe(o);if(Array.from(l).every(p=>i.has(p))){a.on(o,{copy:!1});return}}r.where(o,{copy:!1})}h(Gs,"mergeWhere");function Hs(e,t){let a=e.expression;a.args.group||a.args.distinct||a.args.having||a.args.order||Object.keys(e.selectedSources).length!==1||a.args.expressions?.some(o=>o instanceof T?o.find(M)!==void 0:!1)||a.setArgKey("order",t.expression.getArgKey("order"))}h(Hs,"mergeOrder");function Ys(e,t){let a=t.expression.getArgKey("hint");if(!a)return;let s=e.expression,o=s.args.hint;if(o){let r=a.args.expressions;for(let c of r??[])c instanceof T&&o.append("expressions",c)}else s.setArgKey("hint",a)}h(Ys,"mergeHints");function vn(e){let t=e.expression.parent;if(!t)return;let a=t.parent;if(!a)return;a.args.expressions?.length===1?a.pop():t.pop()}h(vn,"popCte");function Xs(e,t={}){let{dialect:a}=t,s=V(e),o=$.getOrRaise(a),r=o.constructor.UNNEST_REQUIRES_CROSS_JOIN;if(s){let c=s.refCount();for(let i of Array.from(s.traverse()).reverse()){let n=i.expression,l=n.getArgKey("where");if(l){let p=i.selectedSources,m=n.getArgKey("joins"),d=new Map;m&&m.forEach((g,A)=>{let x=g.aliasOrName;x&&d.set(x,A)});let u=!0;for(let[g,A]of Object.entries(p)){let[x]=A;if(!x)continue;let E=x.findAncestor(N,z);if(E instanceof N){if(E.args.side==="right"){p={[g]:A};break}if(x instanceof te&&r){u=!1;break}}}if(u){let g=l.args.this;g instanceof T&&Vs(g,p,c,o,d)}}let f=n.getArgKey("joins");if(f)for(let p of f){let m=p.aliasOrName;if(m&&m in i.selectedSources){let d=p.args.on;Vs(d,{[m]:i.selectedSources[m]},c,o)}}}}return e}h(Xs,"pushdownPredicates");function Vs(e,t,a,s,o){if(!e)return;let r=Re(e,{dialect:s});e=e.replace(r);let c=de(e)||!de(e,{dnf:!0}),i=(c?e instanceof Pe:e instanceof Le)?Array.from(e.flatten()):[e];c?In(i,t,a,o):qn(i,t,a,o)}h(Vs,"pushdown");function In(e,t,a,s){for(let o of e){let r=Zs(o,t,a);for(let[c,i]of Object.entries(r))if(i instanceof N){let n=oe(o,{exclude:c});if(s){let l=s.get(c)??-1;if(Array.from(n).every(p=>(s.get(p)??-1)<l)){o.replace(B()),i.on(o,{copy:!1});break}}}else if(i instanceof w){o.replace(B());let n=en(i,o);re(n,M)?i.having(n,{copy:!1}):i.where(n,{copy:!1})}}}h(In,"pushdownCnf");function qn(e,t,a,s){let o=new Set;for(let i of e){let n=oe(i);for(let l of e){let f=oe(l);n=new Set(Array.from(n).filter(p=>f.has(p)))}for(let l of n)o.add(l)}let r=new Map,c={};for(let i of Array.from(o).sort()){for(let n of e){if(c=Zs(n,t,a),!(i in c))continue;let l=r.get(i);r.set(i,l?Is([l,n]):n)}for(let[n,l]of Object.entries(c)){let f=r.get(n);if(f){if(l instanceof N){if(s){let p=s.get(n)??-1,m=oe(f,{exclude:n});if(!Array.from(m).every(d=>(s.get(d)??-1)<p))continue}l.on(f,{copy:!1})}else if(l instanceof w){let p=en(l,f);re(p,M)?l.having(p,{copy:!1}):l.where(p,{copy:!1})}}}}}h(qn,"pushdownDnf");function Zs(e,t,a){let s={},o=oe(e),r=e.findAncestor(N,X)instanceof X;for(let c of Array.from(o).sort()){let i=t[c];if(!i)continue;let n=i[0],[,l]=i;if(n&&r&&(n=n.findAncestor(N,z)),n instanceof z&&!(l instanceof U)){let f=ps((l instanceof q?l.parent:l.parent?.args)?.expression,T)?.getArgKey("with");if(f instanceof Y&&f?.recursive)return{};n=l instanceof q?l.expression:l.args.expression}if(n instanceof N){let f=n.side;if(f&&f!=="right")return{};s[c]=n}else if(n instanceof w&&o.size===1){let f=n.selects.some(d=>d instanceof T?d.find(le)!==void 0:!1),p=!!n.args.group,m=a.get(l)||0;!p&&m<2&&!f&&(s[c]=n)}}return s}h(Zs,"nodesForPredicate");function en(e,t){let a=new Map;for(let o of e.selects)if(o instanceof T)if(o instanceof Z){let r=o.args.this;r instanceof T&&a.set(o.alias,r)}else a.set(o.name,o);function s(o){if(o instanceof O){let r=a.get(o.name);if(r)return r.copy()}return o}return h(s,"replaceAlias"),t.transform(s)}h(en,"replaceAliases");var $e=class $e{constructor(t,a,s={}){let{inferSchema:o=!0}=s;this.scope=t,this.schema=a,this.dialect=a.dialect||new $,this.inferSchema=o,this.getSourceColumnsCache=new fs}getTable(t){let a=typeof t=="string"?t:t.name,s=this.getTableNameFromSources(a);if(!s&&typeof t!="string"){let i=this.getColumnJoinContext(t);if(i)try{let n=this.getAvailableSourceColumns(i);s=this.getTableNameFromSources(a,n)}catch(n){if(!(n instanceof J))throw n}}if(!s&&this.inferSchema){let i=this.getAllSourceColumns(),n=[];for(let[l,f]of i)(!f||f.length===0||f.includes("*"))&&n.push(l);n.length===1&&(s=n[0])}if(!s)return;let o=this.scope.selectedSources[s];if(!o)return _(s);let[r]=o,c=r;if(c instanceof Ae)for(;c&&c.alias!==s;)c=c.parent;if(c){let i=c.getArgKey("alias");if(i instanceof T&&(i.args.this instanceof Q||typeof i.args.this=="string"))return _(i.args.this)}return _(s)}get allColumns(){if(!this.allColumnsCache){this.allColumnsCache=new Set;for(let t of this.getAllSourceColumns().values())for(let a of t)this.allColumnsCache.add(a)}return this.allColumnsCache}getSourceColumnsFromSetOp(t){if(t instanceof w)return t.namedSelects;if(t instanceof P){let c=t.args.this;if(c instanceof ne)return this.getSourceColumnsFromSetOp(c)}if(!(t instanceof ne))throw new Error(`Unknown set operation: ${t}`);let a=t,s=a.args.on;if(s)return s.map(c=>c.name);let o=a.args.side,r=a.args.kind;if(o||r){let c=a.args.this,i=a.args.expression;if(!c||!i)return[];let n=this.getSourceColumnsFromSetOp(c),l=this.getSourceColumnsFromSetOp(i);if(o==="left")return n;if(o==="full"){let f=[...n,...l];return Array.from(new Set(f))}else if(r==="inner"){let f=new Set(n),p=new Set(l);return Array.from(f).filter(m=>p.has(m))}}return t.namedSelects}getSourceColumns(t,a={}){let{onlyVisible:s=!1}=a;if(this.getSourceColumnsCache.has(t,s))return this.getSourceColumnsCache.get(t,s)??[];let o=this.scope.sources.get(t);if(!o)throw new J(`Unknown table: ${t}`);let r=[];if(o instanceof U)r=this.schema.columnNames?.(o,{onlyVisible:s})||[];else if(o instanceof q){let n=o.expression;if(n instanceof Me||n instanceof te){if(r=n.namedSelects,this.dialect._constructor.UNNEST_COLUMN_ONLY&&n instanceof te){let l=n;if(!l.type||Ks(l.type,"unknown")){let f=l.args.expressions,p=L(f??[],0);if(p instanceof O&&this.scope.parent){let m=this.getUnnestColumnType(p);if(m?.isType("array")){let d=m.args.expressions;d&&0<d.length?l.type=d[0].copy():l.type=m.copy()}}}if(l.isType("struct"))for(let f of(l.type instanceof T?l.type.args.expressions:void 0)||[])j(f,T)&&r.push(f.name)}}else if(n instanceof ne)r=this.getSourceColumnsFromSetOp(n);else{let l=L(n.args.expressions??[],0);if(l instanceof se){let f=l.args.schema;r=f?f.args.expressions?.map(p=>p instanceof T?p.name:String(p))??[]:["key","value"]}else r=n.namedSelects}}let[c]=this.scope.selectedSources[t]||[void 0,void 0],i;if(c instanceof q?i=c.expression.aliasColumnNames:c instanceof T?i=c.aliasColumnNames:i=[],i.length){let n=[];for(let l=0;l<Math.max(r.length,i.length);l++){let f=L(i,l),p=L(r,l);n.push(f||p||"")}r=n}return this.getSourceColumnsCache.set(t,s,r),r}getAllSourceColumns(){if(!this.sourceColumns){this.sourceColumns=new Map;let t={...this.scope.selectedSources,...Object.fromEntries(this.scope.lateralSources.entries())};for(let a of Object.keys(t))this.sourceColumns.set(a,this.getSourceColumns(a))}return this.sourceColumns}getTableNameFromSources(t,a){let s;return a?s=this.getUnambiguousColumns(a):(this.unambiguousColumns||(this.unambiguousColumns=this.getUnambiguousColumns(this.getAllSourceColumns())),s=this.unambiguousColumns),s.get(t)}getColumnJoinContext(t){if(!this.scope.expression.args.joins||this.scope.expression.getArgKey("laterals")||this.scope.expression.getArgKey("pivots"))return;let s=t.findAncestor(N,w);if(s instanceof N&&Object.keys(this.scope.selectedSources).includes(s.aliasOrName))return s}getAvailableSourceColumns(t){let{from:a,joins:s}=this.scope.expression.args;if(!a||!s)return new Map;let o=new Map,r=a instanceof T?a.aliasOrName:a;r&&o.set(r,this.getSourceColumns(r));for(let c of s.slice(0,s.indexOf(t)+1)){let i=c.aliasOrName;i&&o.set(i,this.getSourceColumns(i))}return o}getUnambiguousColumns(t){if(t.size===0)return new Map;let a=Array.from(t.entries()),[s,o]=a[0];if(a.length===1)return new gs(o,s);let r=new Map;if(this.dialect._constructor.UNNEST_COLUMN_ONLY){for(let[n,l]of this.scope.sources)if(l instanceof q&&l.expression instanceof te){let f=l.expression.args.alias;j(f,F)&&f.columns.length&&r.set(f.columns[0].name,n)}}let c=new Map;for(let n of o)c.set(n,s);let i=new Set(o);for(let[n,l]of a.slice(1)){let f=new Set(l),p=new Set([...i].filter(m=>f.has(m)));for(let m of l)i.add(m);for(let m of p){let d=r.get(m);if(d!==void 0){c.set(m,d);continue}c.delete(m)}for(let m of f)p.has(m)||c.set(m,n)}return c}getUnnestColumnType(t){let a=this.scope.parent;if(!a)return;let s;if(t.table)s=t.table;else{let c=new $e(a,this.schema,{inferSchema:this.inferSchema}).getTable(t);if(!c)return;s=c.name}let o=a.sources.get(s);return o?this.getColumnTypeFromScope(o,t):void 0}getColumnTypeFromScope(t,a){if(t instanceof U){let s=this.schema.getColumnType?.(t,a);if(s&&(typeof s.args.this=="string"?s.args.this:"unknown")!=="unknown")return s}else if(t instanceof q)for(let[,s]of t.sources){let o=this.getColumnTypeFromScope(s,a);if(o&&(typeof o.args.this=="string"?o.args.this:"unknown")!=="unknown")return o}}};h($e,"Resolver");var Se=$e;var ve=Symbol("SELECT_ALL");function _n(e){let{isAgg:t}=e;return I(t?new Oe({this:ce.number(1)}):"1","_")}h(_n,"defaultSelection");function sn(e,t={}){let{schema:a,removeUnusedSelections:s=!0,dialect:o}=t,r=H(a,{dialect:o}),c=new Map,i=new Map,n=Array.from(D(e));for(let l=n.length-1;0<=l;l--){let f=n[l],p=i.get(f)||new Set([ve]),m=c.get(f)||0,d=f.expression;if(d.getArgKey("distinct")&&(p=new Set([ve])),d instanceof ne){let u=d.args.kind,g=d.args.side;if(!u&&!g){let[A,x]=f.unionScopes;if(A.expression.selects.length!==x.expression.selects.length)throw new Error(`Invalid set operation due to column mismatch: ${f.expression.sql({dialect:o})}.`);if(i.set(A,p),x.expression.selects.some(E=>E instanceof T&&E.isStar))i.set(x,p);else if(!A.expression.selects.some(E=>E instanceof T&&E.isStar))if(d.args.byName)i.set(x,i.get(A)||new Set);else{let E=new Set;i.set(x,E);for(let b=0;b<A.expression.selects.length;b++){let y=A.expression.selects[b];if(y instanceof T&&(p.has(ve)||p.has(y.aliasOrName))){let S=x.expression.selects[b];S instanceof T&&E.add(S.aliasOrName)}}}}}if(d instanceof w){if(s&&Kn(f,p,r,m),d.isStar)continue;let u=new Map;for(let g of f.columns){let A=g.table||"",x=g.name,E=u.get(A);E||(E=new Set,u.set(A,E)),E.add(x)}for(let[g,A]of Object.entries(f.selectedSources)){let[x,E]=A;if(E instanceof q){let y=L(E.expression.selects,0),S;0<f.pivots.length||y instanceof se?S=new Set([ve]):S=u.get(g)||new Set;let C=i.get(E);C||(C=new Set,i.set(E,C));for(let v of S)C.add(v)}let b=x.aliasColumnNames;b&&0<b.length&&c.set(E,b.length)}}}return e}h(sn,"pushdownProjections");function Kn(e,t,a,s){let r=e.expression.args.order,c=new Set;if(r)for(let u of r.findAll(O))u.table||c.add(u.name);let i=[],n=!1,l=!1,f=!1,p=s,m=t.has(ve),d=e.expression;for(let u of d.selects){if(typeof u=="string"||typeof u=="number"||typeof u=="boolean")continue;let g=u,A=g.aliasOrName;m||t.has(A)||c.has(A)||0<p?(i.push(g),p-=1):(g.isStar&&(l=!0),n=!0),!f&&g.find(M)&&(f=!0)}if(l){let u=new Se(e,a,{}),g=new Set(i.map(x=>x.aliasOrName)),A=Array.from(t).filter(x=>typeof x=="string").sort();for(let x of A)if(!g.has(x)){let E=u.getTable(x);i.push(I(R({col:x,table:E?.aliasOrName}),x,{copy:!1}))}}i.length===0&&i.push(_n({isAgg:f})),d.select(i,{append:!1,copy:!1}),n&&e.clearCache()}h(Kn,"removeUnusedSelections_");function nn(e,t={}){let{schema:a,dialect:s}=t,o=H(a,{dialect:s});for(let r of D(e))if(Object.keys(r.selectedSources).length!==1)for(let[,c]of Object.entries(r.selectedSources)){let[i,n]=c;if(!(n instanceof U))continue;let l=i;if(!l.parent)continue;let f=o.columnNames?.(n);if(!f||f.length===0||l.parent instanceof P||l.parent?.parent instanceof U)continue;if(!l.alias)throw new J("Tables require an alias. Run qualify_tables optimization.");let m=l.aliasOrName,d=ue("*").from(I(l,m,{table:!0}),{copy:!1}).subquery(m,{copy:!1});l.replace(d)}return e}h(nn,"isolateTableSelects");function ln(e,t={}){let{schema:a,expandAliasRefs:s=!0,expandStars:o=!0,inferSchema:r,allowPartialQualification:c=!1,dialect:i}=t,n=H(a,{dialect:i}),l=new He({schema:n}),f=r??!!n.empty,p=n.dialect||new $,m=p._constructor,d=m.PSEUDOCOLUMNS;for(let u of D(e)){m.PREFER_CTE_ALIAS_COLUMN&&$n(u);let A=u.expression instanceof w;jn(u,d);let x=new Se(u,n,{inferSchema:f});tn(u.ctes),tn(u.derivedTables);let E=Mn(u,x);(n.empty||m.FORCE_EARLY_ALIAS_REF_EXPANSION)&&s&&on(u,x,p,{expandOnlyGroupby:m.EXPAND_ONLY_GROUP_ALIAS_REF}),Un(u,x),Dn(u,x,{allowPartialQualification:c}),!n.empty&&s&&on(u,x,p,{expandOnlyGroupby:!1}),A&&(o&&Fn(u,x,E,d,l),kn(u)),Jn(u,p),zn(u,x),m.ANNOTATE_ALL_SCOPES&&l.annotateScope(u)}return e}h(ln,"qualifyColumns");function fn(e,t){let a=[];for(let s of D(e)){if(!(s.expression instanceof w))continue;let o=s.unqualifiedColumns;if(0<s.externalColumns.length&&!s.isCorrelatedSubquery&&s.pivots.length===0){let r=s.externalColumns[0],c=r.table?` for table: '${r.table}'`:"",i=r.args.this?.meta?.line,n=r.args.this?.meta?.col,l=r.args.this?.meta?.start,f=r.args.this?.meta?.end,p=`Column '${r.name}' could not be resolved${c}.`;if(i&&n&&(p+=` Line: ${i}, Col: ${n}`),t&&l!==void 0&&f!==void 0){let{formattedSql:m}=Be({sql:t,positions:[[l,f]]});p+=`
|
|
1
|
+
import{$a as gs,Ai as ne,Bb as Ae,Bd as Xe,Bj as ws,Cd as hs,Ci as w,Di as P,Ef as es,Ei as le,Fa as H,Fu as qs,Ga as q,Gb as Es,Gu as Rs,Ha as D,Ia as V,Ja as Qe,Kf as O,La as re,Lf as As,Ma as Ge,Me as Z,Mi as ee,Na as He,Ni as Cs,Ns as vs,Nv as $,Oa as ms,Od as se,Oe as Ss,Ou as Je,Pa as de,Pu as B,Qa as Re,Ra as ds,Rj as Ns,Sa as L,Ta as Ye,Te as ys,Ti as ge,Ui as M,Va as be,Wc as z,Xa as _e,Xc as ae,Xu as oe,Zj as Ne,_c as Q,_n as Ue,a as h,ak as pe,ao as te,be as U,cb as ie,cu as R,ej as Ts,et as ss,eu as ns,fu as Fe,gc as Y,gu as Is,gv as _s,hm as xe,ie as we,iv as Ks,jc as F,jj as Me,ju as ke,k as J,kv as js,lc as Ke,lt as Pe,lu as _,lv as Ms,m as Be,me as X,ms as De,mt as Le,mu as ts,n as fs,ne as Ze,ns as he,o as j,p as me,pe as je,q as ps,qd as Ce,qu as I,r as qe,s as us,su as ue,tg as ce,tt as Oe,ur as Os,vd as Te,vf as bs,wj as fe,wn as Ee,xb as T,xd as N,yb as xs,yj as W,zb as Ve}from"./chunk-FU46WFXM.js";function Us(e){let t=V(e);if(t){let a=t.refCount(),s=[];for(let o of t.traverse())s.push(o);for(let o=s.length-1;0<=o;o--){let r=s[o];if(r.isCte){let c=r;if((a.get(c)||0)<=0){let n=r.expression.parent;if(!n)continue;let l=n.parent;if(n.pop(),l){let f=l.args.expressions;(!f||f.length===0)&&l.pop()}for(let[,f]of Object.entries(r.selectedSources)){let[,p]=f;if(p instanceof q){let m=a.get(p)||0;a.set(p,m-1)}}}}}}return e}h(Us,"eliminateCtes");function os(e){for(let t of D(e)){if(0<t.unqualifiedColumns.length)continue;let a=t.expression.args.joins;if(a)for(let s=a.length-1;0<=s;s--){let o=a[s];if(me(o,N),o.isSemiOrAntiJoin)continue;let r=o.aliasOrName;r&&hn(t,o,r)&&(o.pop(),t.removeSource(r))}}return e}h(os,"eliminateJoins");function hn(e,t,a){let s=e.sources.get(a);if(!(s instanceof q)||Sn(e,t,a))return!1;let o=t.args.side,r=t.args.on;return o==="left"&&yn(s,t)||!r&&Ps(s)}h(hn,"shouldEliminateJoin");function Sn(e,t,a){let s=t.args.on,o=new Set;if(s)for(let c of s.findAll(O))o.add(c);return e.sourceColumns(a).some(c=>!o.has(c))}h(Sn,"joinIsUsed");function yn(e,t){let a=bn(e);if(!a||a.size===0)return!1;let{joinKeys:s}=Ls(t),o=new Set(s.map(r=>r.name));for(let r of a)if(!o.has(r))return!1;return!0}h(yn,"isJoinedOnAllUniqueOutputs");function bn(e){let t=e.expression;if(!(t instanceof w))return;let a=t;if(a.args.distinct)return new Set(a.namedSelects);let s=a.args.group;if(s){let o=new Set((s.args.expressions??[]).filter(n=>n instanceof T).map(n=>n.sql())),r=new Set,c=new Set;for(let n of a.selects){if(!(n instanceof T))continue;let l=n.unalias().sql();o.has(l)&&(r.add(l),c.add(n.aliasOrName))}return[...o].every(n=>r.has(n))?c:new Set}return Ps(e)?new Set(a.namedSelects):new Set}h(bn,"uniqueOutputs");function Ps(e){let t=e.expression;if(!(t instanceof w))return!1;let a=t;return!!(!a.args.from||a.selects.every(o=>o instanceof T?o.unalias()instanceof M:!1)||An(e))}h(Ps,"hasSingleOutputRow");function An(e){let t=e.expression.getArgKey("limit");return t instanceof Te?t.args.expression?.args.this==="1":!1}h(An,"isLimit1");function Ls(e){let t=e.aliasOrName,s=(e.args.on||B()).copy(),o=[],r=[];function c(i){let[n,l]=i.unnestOperands();if(!n||!l)return;let f=Ds(n),p=Ds(l);t&&f.has(t)&&!p.has(t)?(r.push(n),o.push(l),i.replace(B())):t&&p.has(t)&&!f.has(t)&&(r.push(l),o.push(n),i.replace(B()))}if(h(c,"extractCondition"),de(s)){let i=s instanceof Pe?s:Fe([s,B()],{copy:!1});for(let n of i.flatten())n instanceof W&&c(n)}else if(de(s,{dnf:!0})){let i;for(let n of s.flatten()){let l=Array.from(n.flatten()).filter(f=>f instanceof W);if(i===void 0)i=l;else{let f=[];for(let p of l){let m=i.filter(d=>p.sql()===d.sql());0<m.length&&(f.push(p),f.push(...m))}i=f}}if(i)for(let n of i)c(n)}return{sourceKeys:o,joinKeys:r,on:s}}h(Ls,"joinCondition");function Ds(e){let t=new Set;for(let a of e.findAll(O))a.table&&t.add(a.table);return t}h(Ds,"columnTableNames");function rs(e){if(e instanceof P&&e.args.this)return rs(e.args.this),e;let t=V(e);if(!t)return e;let a=new Map;for(let n of t.cteScopes){let l=n.expression.parent;l&&a.set(l.alias,n)}for(let n of t.traverse())for(let[,l]of n.sources)l instanceof U&&a.set(l.name,l);let s=new Map,o=t.expression.args.with,r=!1;if(o){me(o,Y),r=!!o.args.recursive;for(let n of o.args.expressions??[])j(n,es)&&n.args.this&&n.args.this&&s.set(n.args.this.sqlKey,n.alias)}let c=[];for(let n of t.cteScopes){for(let f of n.traverse()){if(f===n)continue;let p=Fs(f,s,a);p&&c.push(p)}let l=n.expression.parent;l&&c.push(l)}let i=[...t.unionScopes,...t.subqueryScopes,...t.tableScopes];for(let n of i)for(let l of n.traverse()){let f=Fs(l,s,a);f&&c.push(f)}return 0<c.length&&(e instanceof Es?e.args.expression:e)?.setArgKey("with",new Y({expressions:c,recursive:r})),e}h(rs,"eliminateSubqueries");function Fs(e,t,a){if(e.isDerivedTable)return Cn(e,t,a);if(e.isCte)return Tn(e,t,a)}h(Fs,"eliminate");function Cn(e,t,a){if(e.parent&&(0<e.parent.pivots.length||e.parent.expression instanceof Ts))return;let s=e.expression.parent;if(!s)return;s instanceof P&&(s=s.unwrap());let[o,r]=ks(e,t,a),c=I(ns(o),s.alias||o,{copy:!1}),n=s.args.joins;return n&&Array.isArray(n)&&c.setArgKey("joins",n),s.replace(c),r}h(Cn,"eliminateDerivedTable");function Tn(e,t,a){let s=e.expression.parent;if(!s)return;let[o,r]=ks(e,t,a),c=s.parent;if(s.pop(),c){let i=c.args.expressions;(!i||i.length===0)&&c.pop()}if(e.parent)for(let i of e.parent.traverse())for(let[,n]of Object.entries(i.selectedSources)){let[l,f]=n;if(f===e){let p=I(ns(o),l.aliasOrName,{copy:!1});l.replace(p)}}return r}h(Tn,"eliminateCte");function ks(e,t,a){let s=t.get(e.expression.sqlKey),r=e.expression.parent?.alias||"";r||(r=be(Array.from(a.keys()),"cte")),s?r=s:a.has(r)&&(r=be(Array.from(a.keys()),r)),a.set(r,e);let c;return s||(t.set(e.expression.sqlKey,r),c=new es({this:e.expression,alias:new F({this:_(r)})})),[r,c]}h(ks,"newCte");function Js(e,t={}){let{leaveTablesIsolated:a=!1}=t;return e=Nn(e,{leaveTablesIsolated:a}),e=On(e,{leaveTablesIsolated:a}),e}h(Js,"mergeSubqueries");var wn=us(()=>[O,W,ge,Ns,Ne]);function Nn(e,t){let{leaveTablesIsolated:a}=t,s=Array.from(D(e)),o=new Map;for(let c of s)for(let[,i]of Object.entries(c.selectedSources)){let[n,l]=i;if(l instanceof q&&l.isCte){let f=o.get(l);f||(f=[],o.set(l,f)),f.push([c,l,n])}}let r=[];for(let[,c]of o)c.length===1&&r.push(c[0]);for(let[c,i,n]of r){let l=n.findAncestor(z,N);if(l&&zs(c,i,{leaveTablesIsolated:a},l)){let f=n.aliasOrName;$s(c,i,f),Ws(c,i,n,f),Qs(c,i,f),Hs(c,i),Bs(c,i,l),Gs(c,i,l),Ys(c,i),vn(i),c.clearCache()}}return e}h(Nn,"mergeCtes");function On(e,t){let{leaveTablesIsolated:a}=t;for(let s of D(e))for(let o of s.derivedTables){let r=o.findAncestor(z,N),c=o.aliasOrName,i=s.sources.get(c);i instanceof q&&r&&zs(s,i,{leaveTablesIsolated:a},r)&&($s(s,i,c),Ws(s,i,o,c),Qs(s,i,c),Hs(s,i),Bs(s,i,r),Gs(s,i,r),Ys(s,i),s.clearCache())}return e}h(On,"mergeDerivedTables");function zs(e,t,a,s){let{leaveTablesIsolated:o}=a,r=t.expression.unnest();function c(){let u=new Set;if(!(r instanceof w))return!1;let g=r;for(let b of g.selects)b instanceof T&&b.find(le)&&u.add(b.aliasOrName);let A=s.aliasOrName,x=[];for(let b of e.columns)b.findAncestor(X,Ce,hs,N,ae,M)!==void 0&&x.push(b);return 0<x.filter(b=>b.table===A&&u.has(b.name)).length}h(c,"isWindowExpressionInUnmergableOperation");function i(){if(!(s instanceof N))return!1;let u=s.aliasOrName,g=s.args.on;if(!g)return!1;let A=Array.from(g.findAll(O)).filter(S=>S.table===u).map(S=>S.name),x=t.expression.getArgKey("from");if(!x)return!1;let E=x.aliasOrName;if(!(t.expression instanceof w))return!1;let b=t.expression,y=new Map;for(let S of b.selects)S instanceof T&&y.set(S.aliasOrName,S);return A.some(S=>{let C=y.get(S);return C?Array.from(C.findAll(O)).some(K=>K.table!==E):!1})}h(i,"outerSelectJoinsOnInnerSelectJoin");function n(){let u=t.expression.parent,g=e.expression.parent;for(;g;){if(g===u)return!0;g=g.parent}return!1}if(h(n,"isRecursive"),!(e.expression instanceof w))return!1;let l=e.expression;if(l.isStar||!(r instanceof w))return!1;let f=r;for(let u of $.UNMERGABLE_ARGS)if(f.getArgKey(u))return!1;if(!f.args.from||0<e.pivots.length)return!1;for(let u of f.args.expressions??[])if(u instanceof T&&(u.find(M)||u.find(w)||u.find(Ue)))return!1;if(o&&1<Object.keys(e.selectedSources).length||s instanceof N&&f.args.joins&&0<f.args.joins.length)return!1;let p=s instanceof N?s.args.side:void 0;if(s instanceof N&&f.args.where&&(p==="full"||p==="left"||p==="right"))return!1;let m=l.args.joins;return!(s instanceof z&&f.args.where&&m&&m.some(u=>j(u,N)&&(u.args.side==="full"||u.args.side==="right"))||i()||c()||n()||f.args.order&&e.isUnion||L(f.args.expressions??[],0)instanceof se)}h(zs,"mergeable");function $s(e,t,a){let s=new Set(Object.keys(t.selectedSources)),o=new Set(Object.keys(e.selectedSources)),r=new Set(Array.from(s).filter(i=>o.has(i)));r.delete(a);let c=new Set([...o,...s]);for(let i of r){let n=be(Array.from(c),i),l=t.selectedSources[i];if(!l)continue;let[f]=l,p=_(n);f instanceof U?f.alias?f.setArgKey("alias",p):f.replace(I(f,p,{copy:!1})):f?.parent instanceof P&&f.parent.setArgKey("alias",new F({this:p}));for(let m of t.sourceColumns(i))m.setArgKey("table",_(n));t.renameSource(i,n),c.add(n)}}h($s,"renameInnerSources");function Ws(e,t,a,s){let r=t.expression.getArgKey("from").args.this;r.setArgKey("joins",a.args.joins),a.replace(r);for(let i of e.joinHints){let n=Array.from(i.findAll(U));for(let l of n)l.aliasOrName===a.aliasOrName&&l.setArgKey("this",_(r.aliasOrName))}e.removeSource(s);let c=t.sources.get(r.aliasOrName);c!==void 0&&e.addSource(r.aliasOrName,c)}h(Ws,"mergeFrom");function Bs(e,t,a){let s=[],o=t.expression.getArgKey("joins");if(o)for(let r of o){s.push(r);let c=t.sources.get(r.aliasOrName);c&&e.addSource(r.aliasOrName,c)}if(0<s.length){let r=e.expression.getArgKey("joins")||[],c;a instanceof z?c=0:c=r.indexOf(a)+1,r.splice(c,0,...s),e.expression.setArgKey("joins",r)}}h(Bs,"mergeJoins");function Qs(e,t,a){let s=new Map;for(let r of e.columns)if(r.table===a){let c=r.name,i=s.get(c);i||(i=[],s.set(c,i)),i.push(r)}if(!(t.expression instanceof w))return;let o=t.expression;for(let r of o.args.expressions??[]){if(!(r instanceof T))continue;let c=r.aliasOrName;if(!c)continue;let i=s.get(c)||[],n=r.unalias(),l=!wn().some(p=>n instanceof p),f=n.isNumber;for(let p of i){let m=p.parent;if(f&&m instanceof Ce){p.replace(_(p.name));continue}let d=n;m&&(m instanceof Cs||m instanceof ee)&&l&&(d=ke(d,{copy:!1})),m instanceof w&&p.name!==d.name&&(d=I(d,p.name,{copy:!1})),p.replace(d.copy())}}}h(Qs,"mergeExpressions");function Gs(e,t,a){let s=t.expression.getArgKey("where");if(!s)return;let o=s.args.this;if(!(o instanceof T))return;let r=e.expression;if(a instanceof N){let c=r.args.from,i=new Set;c&&i.add(c.aliasOrName);let n=r.args.joins;if(n)for(let p of n){let m=p.aliasOrName;if(i.add(m),m===a.aliasOrName)break}let l=oe(o);if(Array.from(l).every(p=>i.has(p))){a.on(o,{copy:!1});return}}r.where(o,{copy:!1})}h(Gs,"mergeWhere");function Hs(e,t){let a=e.expression;a.args.group||a.args.distinct||a.args.having||a.args.order||Object.keys(e.selectedSources).length!==1||a.args.expressions?.some(o=>o instanceof T?o.find(M)!==void 0:!1)||a.setArgKey("order",t.expression.getArgKey("order"))}h(Hs,"mergeOrder");function Ys(e,t){let a=t.expression.getArgKey("hint");if(!a)return;let s=e.expression,o=s.args.hint;if(o){let r=a.args.expressions;for(let c of r??[])c instanceof T&&o.append("expressions",c)}else s.setArgKey("hint",a)}h(Ys,"mergeHints");function vn(e){let t=e.expression.parent;if(!t)return;let a=t.parent;if(!a)return;a.args.expressions?.length===1?a.pop():t.pop()}h(vn,"popCte");function Xs(e,t={}){let{dialect:a}=t,s=V(e),o=$.getOrRaise(a),r=o.constructor.UNNEST_REQUIRES_CROSS_JOIN;if(s){let c=s.refCount();for(let i of Array.from(s.traverse()).reverse()){let n=i.expression,l=n.getArgKey("where");if(l){let p=i.selectedSources,m=n.getArgKey("joins"),d=new Map;m&&m.forEach((g,A)=>{let x=g.aliasOrName;x&&d.set(x,A)});let u=!0;for(let[g,A]of Object.entries(p)){let[x]=A;if(!x)continue;let E=x.findAncestor(N,z);if(E instanceof N){if(E.args.side==="right"){p={[g]:A};break}if(x instanceof te&&r){u=!1;break}}}if(u){let g=l.args.this;g instanceof T&&Vs(g,p,c,o,d)}}let f=n.getArgKey("joins");if(f)for(let p of f){let m=p.aliasOrName;if(m&&m in i.selectedSources){let d=p.args.on;Vs(d,{[m]:i.selectedSources[m]},c,o)}}}}return e}h(Xs,"pushdownPredicates");function Vs(e,t,a,s,o){if(!e)return;let r=Re(e,{dialect:s});e=e.replace(r);let c=de(e)||!de(e,{dnf:!0}),i=(c?e instanceof Pe:e instanceof Le)?Array.from(e.flatten()):[e];c?In(i,t,a,o):qn(i,t,a,o)}h(Vs,"pushdown");function In(e,t,a,s){for(let o of e){let r=Zs(o,t,a);for(let[c,i]of Object.entries(r))if(i instanceof N){let n=oe(o,{exclude:c});if(s){let l=s.get(c)??-1;if(Array.from(n).every(p=>(s.get(p)??-1)<l)){o.replace(B()),i.on(o,{copy:!1});break}}}else if(i instanceof w){o.replace(B());let n=en(i,o);re(n,M)?i.having(n,{copy:!1}):i.where(n,{copy:!1})}}}h(In,"pushdownCnf");function qn(e,t,a,s){let o=new Set;for(let i of e){let n=oe(i);for(let l of e){let f=oe(l);n=new Set(Array.from(n).filter(p=>f.has(p)))}for(let l of n)o.add(l)}let r=new Map,c={};for(let i of Array.from(o).sort()){for(let n of e){if(c=Zs(n,t,a),!(i in c))continue;let l=r.get(i);r.set(i,l?Is([l,n]):n)}for(let[n,l]of Object.entries(c)){let f=r.get(n);if(f){if(l instanceof N){if(s){let p=s.get(n)??-1,m=oe(f,{exclude:n});if(!Array.from(m).every(d=>(s.get(d)??-1)<p))continue}l.on(f,{copy:!1})}else if(l instanceof w){let p=en(l,f);re(p,M)?l.having(p,{copy:!1}):l.where(p,{copy:!1})}}}}}h(qn,"pushdownDnf");function Zs(e,t,a){let s={},o=oe(e),r=e.findAncestor(N,X)instanceof X;for(let c of Array.from(o).sort()){let i=t[c];if(!i)continue;let n=i[0],[,l]=i;if(n&&r&&(n=n.findAncestor(N,z)),n instanceof z&&!(l instanceof U)){let f=ps((l instanceof q?l.parent:l.parent?.args)?.expression,T)?.getArgKey("with");if(f instanceof Y&&f?.recursive)return{};n=l instanceof q?l.expression:l.args.expression}if(n instanceof N){let f=n.side;if(f&&f!=="right")return{};s[c]=n}else if(n instanceof w&&o.size===1){let f=n.selects.some(d=>d instanceof T?d.find(le)!==void 0:!1),p=!!n.args.group,m=a.get(l)||0;!p&&m<2&&!f&&(s[c]=n)}}return s}h(Zs,"nodesForPredicate");function en(e,t){let a=new Map;for(let o of e.selects)if(o instanceof T)if(o instanceof Z){let r=o.args.this;r instanceof T&&a.set(o.alias,r)}else a.set(o.name,o);function s(o){if(o instanceof O){let r=a.get(o.name);if(r)return r.copy()}return o}return h(s,"replaceAlias"),t.transform(s)}h(en,"replaceAliases");var $e=class $e{constructor(t,a,s={}){let{inferSchema:o=!0}=s;this.scope=t,this.schema=a,this.dialect=a.dialect||new $,this.inferSchema=o,this.getSourceColumnsCache=new fs}getTable(t){let a=typeof t=="string"?t:t.name,s=this.getTableNameFromSources(a);if(!s&&typeof t!="string"){let i=this.getColumnJoinContext(t);if(i)try{let n=this.getAvailableSourceColumns(i);s=this.getTableNameFromSources(a,n)}catch(n){if(!(n instanceof J))throw n}}if(!s&&this.inferSchema){let i=this.getAllSourceColumns(),n=[];for(let[l,f]of i)(!f||f.length===0||f.includes("*"))&&n.push(l);n.length===1&&(s=n[0])}if(!s)return;let o=this.scope.selectedSources[s];if(!o)return _(s);let[r]=o,c=r;if(c instanceof Ae)for(;c&&c.alias!==s;)c=c.parent;if(c){let i=c.getArgKey("alias");if(i instanceof T&&(i.args.this instanceof Q||typeof i.args.this=="string"))return _(i.args.this)}return _(s)}get allColumns(){if(!this.allColumnsCache){this.allColumnsCache=new Set;for(let t of this.getAllSourceColumns().values())for(let a of t)this.allColumnsCache.add(a)}return this.allColumnsCache}getSourceColumnsFromSetOp(t){if(t instanceof w)return t.namedSelects;if(t instanceof P){let c=t.args.this;if(c instanceof ne)return this.getSourceColumnsFromSetOp(c)}if(!(t instanceof ne))throw new Error(`Unknown set operation: ${t}`);let a=t,s=a.args.on;if(s)return s.map(c=>c.name);let o=a.args.side,r=a.args.kind;if(o||r){let c=a.args.this,i=a.args.expression;if(!c||!i)return[];let n=this.getSourceColumnsFromSetOp(c),l=this.getSourceColumnsFromSetOp(i);if(o==="left")return n;if(o==="full"){let f=[...n,...l];return Array.from(new Set(f))}else if(r==="inner"){let f=new Set(n),p=new Set(l);return Array.from(f).filter(m=>p.has(m))}}return t.namedSelects}getSourceColumns(t,a={}){let{onlyVisible:s=!1}=a;if(this.getSourceColumnsCache.has(t,s))return this.getSourceColumnsCache.get(t,s)??[];let o=this.scope.sources.get(t);if(!o)throw new J(`Unknown table: ${t}`);let r=[];if(o instanceof U)r=this.schema.columnNames?.(o,{onlyVisible:s})||[];else if(o instanceof q){let n=o.expression;if(n instanceof Me||n instanceof te){if(r=n.namedSelects,this.dialect._constructor.UNNEST_COLUMN_ONLY&&n instanceof te){let l=n;if(!l.type||Ks(l.type,"unknown")){let f=l.args.expressions,p=L(f??[],0);if(p instanceof O&&this.scope.parent){let m=this.getUnnestColumnType(p);if(m?.isType("array")){let d=m.args.expressions;d&&0<d.length?l.type=d[0].copy():l.type=m.copy()}}}if(l.isType("struct"))for(let f of(l.type instanceof T?l.type.args.expressions:void 0)||[])j(f,T)&&r.push(f.name)}}else if(n instanceof ne)r=this.getSourceColumnsFromSetOp(n);else{let l=L(n.args.expressions??[],0);if(l instanceof se){let f=l.args.schema;r=f?f.args.expressions?.map(p=>p instanceof T?p.name:String(p))??[]:["key","value"]}else r=n.namedSelects}}let[c]=this.scope.selectedSources[t]||[void 0,void 0],i;if(c instanceof q?i=c.expression.aliasColumnNames:c instanceof T?i=c.aliasColumnNames:i=[],i.length){let n=[];for(let l=0;l<Math.max(r.length,i.length);l++){let f=L(i,l),p=L(r,l);n.push(f||p||"")}r=n}return this.getSourceColumnsCache.set(t,s,r),r}getAllSourceColumns(){if(!this.sourceColumns){this.sourceColumns=new Map;let t={...this.scope.selectedSources,...Object.fromEntries(this.scope.lateralSources.entries())};for(let a of Object.keys(t))this.sourceColumns.set(a,this.getSourceColumns(a))}return this.sourceColumns}getTableNameFromSources(t,a){let s;return a?s=this.getUnambiguousColumns(a):(this.unambiguousColumns||(this.unambiguousColumns=this.getUnambiguousColumns(this.getAllSourceColumns())),s=this.unambiguousColumns),s.get(t)}getColumnJoinContext(t){if(!this.scope.expression.args.joins||this.scope.expression.getArgKey("laterals")||this.scope.expression.getArgKey("pivots"))return;let s=t.findAncestor(N,w);if(s instanceof N&&Object.keys(this.scope.selectedSources).includes(s.aliasOrName))return s}getAvailableSourceColumns(t){let{from:a,joins:s}=this.scope.expression.args;if(!a||!s)return new Map;let o=new Map,r=a instanceof T?a.aliasOrName:a;r&&o.set(r,this.getSourceColumns(r));for(let c of s.slice(0,s.indexOf(t)+1)){let i=c.aliasOrName;i&&o.set(i,this.getSourceColumns(i))}return o}getUnambiguousColumns(t){if(t.size===0)return new Map;let a=Array.from(t.entries()),[s,o]=a[0];if(a.length===1)return new gs(o,s);let r=new Map;if(this.dialect._constructor.UNNEST_COLUMN_ONLY){for(let[n,l]of this.scope.sources)if(l instanceof q&&l.expression instanceof te){let f=l.expression.args.alias;j(f,F)&&f.columns.length&&r.set(f.columns[0].name,n)}}let c=new Map;for(let n of o)c.set(n,s);let i=new Set(o);for(let[n,l]of a.slice(1)){let f=new Set(l),p=new Set([...i].filter(m=>f.has(m)));for(let m of l)i.add(m);for(let m of p){let d=r.get(m);if(d!==void 0){c.set(m,d);continue}c.delete(m)}for(let m of f)p.has(m)||c.set(m,n)}return c}getUnnestColumnType(t){let a=this.scope.parent;if(!a)return;let s;if(t.table)s=t.table;else{let c=new $e(a,this.schema,{inferSchema:this.inferSchema}).getTable(t);if(!c)return;s=c.name}let o=a.sources.get(s);return o?this.getColumnTypeFromScope(o,t):void 0}getColumnTypeFromScope(t,a){if(t instanceof U){let s=this.schema.getColumnType?.(t,a);if(s&&(typeof s.args.this=="string"?s.args.this:"unknown")!=="unknown")return s}else if(t instanceof q)for(let[,s]of t.sources){let o=this.getColumnTypeFromScope(s,a);if(o&&(typeof o.args.this=="string"?o.args.this:"unknown")!=="unknown")return o}}};h($e,"Resolver");var Se=$e;var ve=Symbol("SELECT_ALL");function _n(e){let{isAgg:t}=e;return I(t?new Oe({this:ce.number(1)}):"1","_")}h(_n,"defaultSelection");function sn(e,t={}){let{schema:a,removeUnusedSelections:s=!0,dialect:o}=t,r=H(a,{dialect:o}),c=new Map,i=new Map,n=Array.from(D(e));for(let l=n.length-1;0<=l;l--){let f=n[l],p=i.get(f)||new Set([ve]),m=c.get(f)||0,d=f.expression;if(d.getArgKey("distinct")&&(p=new Set([ve])),d instanceof ne){let u=d.args.kind,g=d.args.side;if(!u&&!g){let[A,x]=f.unionScopes;if(A.expression.selects.length!==x.expression.selects.length)throw new Error(`Invalid set operation due to column mismatch: ${f.expression.sql({dialect:o})}.`);if(i.set(A,p),x.expression.selects.some(E=>E instanceof T&&E.isStar))i.set(x,p);else if(!A.expression.selects.some(E=>E instanceof T&&E.isStar))if(d.args.byName)i.set(x,i.get(A)||new Set);else{let E=new Set;i.set(x,E);for(let b=0;b<A.expression.selects.length;b++){let y=A.expression.selects[b];if(y instanceof T&&(p.has(ve)||p.has(y.aliasOrName))){let S=x.expression.selects[b];S instanceof T&&E.add(S.aliasOrName)}}}}}if(d instanceof w){if(s&&Kn(f,p,r,m),d.isStar)continue;let u=new Map;for(let g of f.columns){let A=g.table||"",x=g.name,E=u.get(A);E||(E=new Set,u.set(A,E)),E.add(x)}for(let[g,A]of Object.entries(f.selectedSources)){let[x,E]=A;if(E instanceof q){let y=L(E.expression.selects,0),S;0<f.pivots.length||y instanceof se?S=new Set([ve]):S=u.get(g)||new Set;let C=i.get(E);C||(C=new Set,i.set(E,C));for(let v of S)C.add(v)}let b=x.aliasColumnNames;b&&0<b.length&&c.set(E,b.length)}}}return e}h(sn,"pushdownProjections");function Kn(e,t,a,s){let r=e.expression.args.order,c=new Set;if(r)for(let u of r.findAll(O))u.table||c.add(u.name);let i=[],n=!1,l=!1,f=!1,p=s,m=t.has(ve),d=e.expression;for(let u of d.selects){if(typeof u=="string"||typeof u=="number"||typeof u=="boolean")continue;let g=u,A=g.aliasOrName;m||t.has(A)||c.has(A)||0<p?(i.push(g),p-=1):(g.isStar&&(l=!0),n=!0),!f&&g.find(M)&&(f=!0)}if(l){let u=new Se(e,a,{}),g=new Set(i.map(x=>x.aliasOrName)),A=Array.from(t).filter(x=>typeof x=="string").sort();for(let x of A)if(!g.has(x)){let E=u.getTable(x);i.push(I(R({col:x,table:E?.aliasOrName}),x,{copy:!1}))}}i.length===0&&i.push(_n({isAgg:f})),d.select(i,{append:!1,copy:!1}),n&&e.clearCache()}h(Kn,"removeUnusedSelections_");function nn(e,t={}){let{schema:a,dialect:s}=t,o=H(a,{dialect:s});for(let r of D(e))if(Object.keys(r.selectedSources).length!==1)for(let[,c]of Object.entries(r.selectedSources)){let[i,n]=c;if(!(n instanceof U))continue;let l=i;if(!l.parent)continue;let f=o.columnNames?.(n);if(!f||f.length===0||l.parent instanceof P||l.parent?.parent instanceof U)continue;if(!l.alias)throw new J("Tables require an alias. Run qualify_tables optimization.");let m=l.aliasOrName,d=ue("*").from(I(l,m,{table:!0}),{copy:!1}).subquery(m,{copy:!1});l.replace(d)}return e}h(nn,"isolateTableSelects");function ln(e,t={}){let{schema:a,expandAliasRefs:s=!0,expandStars:o=!0,inferSchema:r,allowPartialQualification:c=!1,dialect:i}=t,n=H(a,{dialect:i}),l=new He({schema:n}),f=r??!!n.empty,p=n.dialect||new $,m=p._constructor,d=m.PSEUDOCOLUMNS;for(let u of D(e)){m.PREFER_CTE_ALIAS_COLUMN&&$n(u);let A=u.expression instanceof w;jn(u,d);let x=new Se(u,n,{inferSchema:f});tn(u.ctes),tn(u.derivedTables);let E=Mn(u,x);(n.empty||m.FORCE_EARLY_ALIAS_REF_EXPANSION)&&s&&on(u,x,p,{expandOnlyGroupby:m.EXPAND_ONLY_GROUP_ALIAS_REF}),Un(u,x),Dn(u,x,{allowPartialQualification:c}),!n.empty&&s&&on(u,x,p,{expandOnlyGroupby:!1}),A&&(o&&Fn(u,x,E,d,l),kn(u)),Jn(u,p),zn(u,x),m.ANNOTATE_ALL_SCOPES&&l.annotateScope(u)}return e}h(ln,"qualifyColumns");function fn(e,t){let a=[];for(let s of D(e)){if(!(s.expression instanceof w))continue;let o=s.unqualifiedColumns;if(0<s.externalColumns.length&&!s.isCorrelatedSubquery&&s.pivots.length===0){let r=s.externalColumns[0],c=r.table?` for table: '${r.table}'`:"",i=r.args.this?.meta?.line,n=r.args.this?.meta?.col,l=r.args.this?.meta?.start,f=r.args.this?.meta?.end,p=`Column '${r.name}' could not be resolved${c}.`;if(i&&n&&(p+=` Line: ${i}, Col: ${n}`),t&&l!==void 0&&f!==void 0){let{formattedSql:m}=Be({sql:t,positions:[[l,f]]});p+=`
|
|
2
2
|
${m}`}throw new J(p)}if(0<o.length&&0<s.pivots.length&&s.pivots[0].unpivot){let r=new Set(pn(s.pivots[0]));o=o.filter(c=>!r.has(c))}a.push(...o)}if(0<a.length){let s=a[0],o=s.args.this,r=j(o,T)?o.meta.line:void 0,c=j(o,T)?o.meta.col:void 0,i=j(o,T)?o.meta.start:void 0,n=j(o,T)?o.meta.end:void 0,l=`Ambiguous column '${s.name}'`;if(r&&c&&(l+=` (Line: ${r}, Col: ${c})`),t&&i!==void 0&&n!==void 0){let{formattedSql:f}=Be({sql:t,positions:[[i,n]]});l+=`
|
|
3
3
|
${f}`}throw new J(l)}return e}h(fn,"validateQualifyColumns");function jn(e,t){if(t.size===0)return;let a=!1,s=e.expression;for(let o of e.columns){let r=o.name.toUpperCase();t.has(r)&&(r!=="LEVEL"||s instanceof w&&s.args.connect)&&(o.replace(new As({...o.args})),a=!0)}a&&e.clearCache()}h(jn,"separatePseudocolumns");function pn(e){let a=(e.args.fields||[]).filter(o=>o instanceof pe&&o.args.this instanceof O).map(o=>o.args.this),s=[];for(let o of e.args.expressions)for(let r of o.findAll(O))s.push(r);return[...a,...s]}h(pn,"unpivotColumns");function tn(e){for(let t of e){if(t.parent instanceof Y&&t.parent.args.recursive)continue;let a=t.getArgKey("alias");a instanceof F&&a.setArgKey("columns",void 0)}}h(tn,"popTableColumnAliases");function Mn(e,t){let a=e.expression.args.joins||[];if(a.length===0)return new Map;let s=new Set(a.map(n=>n.aliasOrName)),o=Object.keys(e.selectedSources).filter(n=>!s.has(n));if(0<s.size&&o.length===0)throw new J(`Joins ${[...s].join(",")} missing source table ${e.expression}`);let r={},c=h(n=>{for(let l of t.getSourceColumns(n))l in r||(r[l]=n)},"updateSourceColumns");for(let n of o)c(n);let i=new Map;for(let n=0;n<a.length;n++){let l=a[n];me(l,N);let f=o[o.length-1];f&&c(f);let p=l.aliasOrName;o.push(p);let m=l.args.using;if(!m)continue;let d=t.getSourceColumns(p),u=[],g=m.length,A=l.isSemiOrAntiJoin;for(let x of m){let E=x.name,b=r[E];if((!b||!d.includes(E))&&0<Object.keys(r).length&&!("*"in r)&&0<d.length)throw new J(`Cannot automatically join: ${E}`);b=b||f;let y;if(n===0||g===1)y=R({col:E,table:b});else{let S=o.slice(0,-1).filter(C=>t.getSourceColumns(C).includes(E)).map(C=>R({col:E,table:C}));1<S.length?y=new xe({this:S[0],expressions:S.slice(1)}):y=R({col:E,table:b})}if(u.push(y.eq(R({col:E,table:p}))),!A){let S=i.get(E);S||(S=[],i.set(E,S)),S.includes(b)||S.push(b),S.includes(p)||S.push(p)}}l.setArgKey("using",void 0),l.setArgKey("on",Fe(u,{copy:!1}))}if(0<i.size)for(let n of e.columns){let l=n.table?void 0:i.get(n.name);if(l!==void 0){let f=l.map(m=>R({col:n.name,table:m})),p=new xe({this:f[0],expressions:f.slice(1)});n.parent instanceof w?p=I(p,n.name,{copy:!1}):n.parent instanceof Os&&(p=new ws({this:_(n.name),expression:p})),e.replace(n,p)}}return i}h(Mn,"expandUsing");function on(e,t,a,s){let{expandOnlyGroupby:o}=s,r=e.expression,c=a._constructor;if(!(r instanceof w)||c.DISABLES_ALIAS_REF_EXPANSION)return;let i=new Map,n=new Set(r.selects.map(d=>d.aliasOrName)),l=!1,f=h((d,u={})=>{let{resolveTable:g=!1,literalIndex:A=!1}=u,x=d instanceof Ce,E=d instanceof ae;if(!(!d||o&&!x))for(let b of Qe(d,{prune:h(y=>y.isStar,"prune")})){if(!(b instanceof O)||o&&x&&b.parent!==d)continue;let y=!1,S=g&&!b.table?t.getTable(b.name):void 0,C=i.get(b.name),v=C?C[0]:void 0,K=C?C[1]:1;if(v)y=!!(v.find(M)&&b.findAncestor(M)&&!(b.findAncestor(le,w)instanceof le)),E&&c.PROJECTION_ALIASES_SHADOW_SOURCE_NAMES&&(y=y||Array.from(v.findAll(O)).some(k=>n.has(k.parts[0]?.name||"")));else if(c.PROJECTION_ALIASES_SHADOW_SOURCE_NAMES&&(x||E)){let k=S?S.name:b.table;if(k&&n.has(k)){b.replace(_(b.name)),l=!0;continue}}if(S&&(!v||y))b.setArgKey("table",S);else if(!b.table&&v&&!y)if((v instanceof ce||v.isNumber)&&(A||g))A&&(b.replace(ce.number(K)),l=!0);else{l=!0;let k=b.replace(ke(v)),ye=ds(k,a);ye!==k&&k.replace(ye)}}},"replaceColumns");for(let d=0;d<r.selects.length;d++){let u=r.selects[d];f(u),u instanceof Z&&i.set(u.alias,[u.args.this,d+1])}let p=e,m=!1;for(;p&&!p.isCte;)p.isUnion&&p.parent&&(m=p.parent.expression.args.expression===p.expression),p=p.parent;if(p&&m){let d=p.expression.parent;if(d&&d.findAncestor(Y)?.args.recursive){let g=d.args.alias,A=g instanceof F?g.columns:[],x=0<A.length?A:d.args.this?.selects||[];for(let E of x)E instanceof T&&i.delete(E.outputName)}}if(f(r.args.where),f(r.args.group,{literalIndex:!0}),f(r.args.having,{resolveTable:!0}),f(r.args.qualify,{resolveTable:!0}),c.SUPPORTS_ALIAS_REFS_IN_JOIN_CONDITIONS)for(let d of r.args.joins||[])f(d);l&&e.clearCache()}h(on,"expandAliasRefs_");function Un(e,t){let a=!1,s=[...e.columns,...e.stars];for(let o of s){if(o instanceof fe)continue;let r=o.table,c=o.meta.dotParts||[];if(delete o.meta.dotParts,r&&!e.sources.has(r)&&(!e.parent||!e.parent.sources.has(r)||!e.isCorrelatedSubquery)){let i=o.parts;if(i.length<2)continue;let n=i[0],l=i.slice(1);if(!n)continue;let f,p,m,d;if(e.sources.has(n.name)){if(l.length===0)continue;m=n,f=l[0],p=l.slice(1),d=!0}else m=t.getTable(n.name),f=n,p=l,d=!1;if(m){a=!0;let u=R({col:f,table:m});0<c.length&&(u.meta.dotParts=c.slice(d?2:1)),0<p.length?o.replace(fe.build([u,...p])):o.replace(u)}}}a&&e.clearCache()}h(Un,"convertColumnsToDots");function Dn(e,t,a){let{allowPartialQualification:s}=a,o=t.dialect._constructor;for(let r of e.columns){let c=r.table,i=r.name;if(c&&e.sources.has(c)){let n=t.getSourceColumns(c);if(!s&&0<n.length&&!n.includes(i)&&!n.includes("*"))throw new J(`Unknown column: ${i}`)}if(!c){if(0<e.pivots.length&&!r.findAncestor(we)){r.setArgKey("table",_(e.pivots[0].alias));continue}let n=t.getTable(r);if(n){let l=e.sources.get(n.name);if(l instanceof q&&l.columnIndex.has(r))continue}if(n)r.setArgKey("table",n);else if(o.TABLES_REFERENCEABLE_AS_COLUMNS&&r.parts.length===1&&i in e.selectedSources){let l=r.args.this;e.replace(r,new bs({this:j(l,T)?l:void 0}))}}}for(let r of e.pivots)if(r instanceof we){for(let c of r.findAll(O))if(!c.table&&t.allColumns.has(c.name)){let i=t.getTable(c.name);i&&c.setArgKey("table",i)}}}h(Dn,"qualifyColumnsInScope");function rn(e,t,a){let s=e.getArgKey("except")??e.getArgKey("except");if(!s)return;let o=Array.isArray(s)?s:[s],r=new Set(o.filter(c=>c instanceof T).map(c=>c.name));for(let c of t)a.set(c,r)}h(rn,"addExceptColumns");function an(e,t,a){let s=e.getArgKey("rename");if(!s||s.length===0)return;let o={};for(let r of s)if(r instanceof T){let c=r.args.this;c instanceof T&&(o[c.name]=r.alias)}for(let r of t)a.set(r,o)}h(an,"addRenameColumns");function cn(e,t,a){let s=e.getArgKey("replace");if(!s||s.length===0)return;let o={};for(let r of s)r instanceof Z&&(o[r.alias]=r);for(let r of t)a.set(r,o)}h(cn,"addReplaceColumns");function Pn(e){let t=e.find(O);if(!(t instanceof O)||!t.isType("struct"))return[];let a=t.copy(),s=a.type,o=j(s,je)?s:void 0,r=e.parts.slice(1,-1);e:for(let n of r.slice(1)){let l=o?.args.expressions||[];for(let f of l){if(!(f.args.this instanceof Q))return[];if(!j(f,Ke))return[];let p=f.args.kind,m=j(p,je)?p:void 0;if(f.name===n.name&&m?.isType("struct")){o=m;break e}}return[]}let c=new Set,i=[];for(let n of o?.args.expressions||[]){let l=n.name,f=n.args.this;if(c.has(l)||!(f instanceof Q))return[];c.add(l);let p=f.copy(),m=[...r.map(A=>A.copy()),p],[d,...u]=m,g=R({col:d,table:a.args.table},{fields:u});i.push(I(g,p,{copy:!1}))}return i}h(Pn,"expandStructStarsNoParens");function Ln(e){if(!(e.args.this instanceof Ne))return[];let t=e.find(O);if(!(t instanceof O)||!t.isType("struct"))return[];let a=t.parent,s=t.type,o=j(s,je)?s:void 0;for(;a!==void 0;){if(a instanceof Ne){a=a.parent;continue}if(!(a instanceof fe))return[];let n=a.right;if(n instanceof Ze)break;if(!(n instanceof Q))return[];let l=!1,f=qe(o.args.expressions||[],Ke);for(let p of f)if(p.name===n.name){l=!0,o=p.args.kind;break}if(!l)return[];a=a.parent}let r=[],c=e.args.this,i=qe(o.args.expressions||[],Ke);for(let n of i){let l=n.args.this instanceof Q?n.args.this.copy():new Q({this:n.args.this?.toString()}),f=fe.build([c.copy(),l]),p=I(f,l,{copy:!1});r.push(p)}return r}h(Ln,"expandStructStarsWithParens");function Fn(e,t,a,s,o){let r=[],c=new Map,i=new Map,n=new Map,l=new Set,f=t.dialect._constructor,p,m=new Set,d=L(e.pivots,0);if(d instanceof we&&!d.aliasColumnNames.length)if(d.unpivot){p=pn(d).map(u=>u.outputName);for(let u of d.args.fields||[])if(u instanceof pe)for(let g of u.args.expressions)for(let A of g.findAll(O))m.add(A.outputName)}else{for(let g of d.findAll(O))m.add(g.outputName);p=(d.getArgKey("columns")||[]).map(g=>g.outputName),p.length||(p=d.args.expressions.map(g=>g.aliasOrName))}f.SUPPORTS_STRUCT_STAR_EXPANSION&&e.stars.some(u=>u instanceof fe)&&o.annotateScope(e);for(let u of e.expression.selects){let g=[];if(u instanceof Ze)g.push(...Object.keys(e.selectedSources)),rn(u,g,c),cn(u,g,i),an(u,g,n);else if(u.isStar)if(u instanceof fe){if(f.SUPPORTS_STRUCT_STAR_EXPANSION&&!f.REQUIRES_PARENTHESIZED_STRUCT_ACCESS){let A=Pn(u);if(0<A.length){r.push(...A);continue}}else if(f.REQUIRES_PARENTHESIZED_STRUCT_ACCESS){let A=Ln(u);if(0<A.length){r.push(...A);continue}}}else{let A=u instanceof O?u.table:"";A&&g.push(A);let x=u.args.this;x instanceof T&&(rn(x,g,c),cn(x,g,i),an(x,g,n))}if(g.length===0){r.push(u);continue}for(let A of g){if(!e.sources.has(A))throw new J(`Unknown table: ${A}`);let x=t.getSourceColumns(A,{onlyVisible:!0});if(x.length||(x=e.outerColumns),0<s.size&&f.EXCLUDES_PSEUDOCOLUMNS_FROM_STAR&&(x=x.filter(S=>!s.has(S.toUpperCase()))),!x.length||x.includes("*"))return;let E=c.get(A)||new Set,b=n.get(A)||{},y=i.get(A)||{};if(d instanceof we){let S;if(p&&0<m.size?(S=x.filter(C=>!m.has(C)),S.push(...p)):S=d.aliasColumnNames,0<S.length){for(let C of S)E.has(C)||r.push(I(R({col:C,table:d.alias}),C,{copy:!1}));continue}}for(let S of x){if(E.has(S)||l.has(S))continue;let C=a.get(S);if(C?.includes(A)){l.add(S);let v=C.map(K=>R({col:S,table:K}));r.push(I(new xe({this:v[0],expressions:v.slice(1)}),S,{copy:!1}))}else{let v=b[S]??S,K=y[S]||R({col:S,table:A});r.push(v!==S?I(K,v,{copy:!1}):K)}}}}0<r.length&&e.expression instanceof w&&e.expression.setArgKey("expressions",r)}h(Fn,"expandStars_");function kn(e){let t;if(e instanceof q)t=e;else{let c=V(e);if(!(c instanceof q))return;t=c}if(!(t.expression instanceof w))return;let a=t.expression.selects,s=t.outerColumns,o=[],r=Math.max(a.length,s.length);for(let c=0;c<r;c++){let i=a[c],n=s[c];if(!i||i instanceof se)break;i instanceof P?i.outputName||i.setArgKey("alias",new F({this:_(`_col_${c}`)})):!(i instanceof Z)&&!(i instanceof Ss)&&!i.isStar&&(i=I(i,i.outputName||`_col_${c}`,{copy:!1})),n&&i.setArgKey("alias",_(n)),o.push(i)}0<o.length&&t.expression instanceof w&&t.expression.setArgKey("expressions",o)}h(kn,"qualifyOutputs");function un(e,t){let a=Number(t.args.this)-1,s=e.expression.selects[a];if(!(s instanceof Z))throw new J(`Unknown output column: ${t.name}`);return s}h(un,"selectByPos");function mn(e,t,a,s={}){let{alias:o=!1}=s,r=a._constructor,c=[],i;for(let n of t)if(n.isInteger){let l=un(e,n);if(o){let f=l.alias;c.push(f?R({col:f}):n)}else{let f=l.args.this,p=!1;r.PROJECTION_ALIASES_SHADOW_SOURCE_NAMES&&(i===void 0&&(i=new Set(e.expression.selects.map(m=>m.aliasOrName).filter(m=>m in e.selectedSources))),p=Array.from(f.findAll(O)).some(m=>i?.has(m.parts[0]?.name||""))),_s.some(m=>f instanceof m)||f.isNumber||f.find(Ue)||f.find(te)||p?c.push(n):c.push(f.copy())}}else c.push(n);return c}h(mn,"expandPositionalReferences");function Jn(e,t){let a=e.expression.args.group;if(!a)return;let s=qe(a.args.expressions||[],T);a.setArgKey("expressions",mn(e,s,t)),e.expression.setArgKey("group",a)}h(Jn,"expandGroupBy");function zn(e,t){for(let a of["order","distinct"]){let s=e.expression.getArgKey(a);if(s instanceof ys&&(s=s.args.on),!(s instanceof T))continue;let o=s.args.expressions;a==="order"&&(o=o.map(c=>c.args.this));let r=mn(e,o,t.dialect,{alias:!0});for(let c=0;c<o.length;c++){let i=o[c],n=r[c];for(let l of i.findAll(M))for(let f of l.findAll(O))if(!f.table){let p=t.getTable(f.name);p&&f.setArgKey("table",p)}i.replace(n)}if(e.expression.getArgKey("group")){let c=new Map(e.expression.selects.filter(i=>i instanceof Z).map(i=>[i.args.this.sql(),R({col:i.aliasOrName})]));for(let i of o)if(i.isInteger)i.replace(_(un(e,i).alias));else{let n=c.get(i.sql());n&&i.replace(n)}}}}h(zn,"expandOrderByAndDistinctOn");function We(e,t={}){let{dialect:a,identify:s=!0}=t,o=$.getOrRaise(a);return e.transform(o.quoteIdentifier.bind(o),{identify:s,copy:!1})}h(We,"quoteIdentifiers");function $n(e){for(let t of e.ctes){let a=t.aliasColumnNames;if(0<a.length&&t.args.this instanceof w){let s=t.args.this,o=s.args.expressions||[],r=[];for(let c=0;c<a.length;c++){let i=a[c],n=o[c];if(!n)break;let l;n instanceof Z?(n.setArgKey("alias",_(i)),l=n):l=I(n,i),r.push(l)}s.setArgKey("expressions",r)}}}h($n,"pushdownCteAliasColumns");function dn(e,t={}){let{db:a,catalog:s,onQualify:o,dialect:r,canonicalizeTableAliases:c=!1}=t,i=$.getOrRaise(r),n=_e("_"),l;a&&(l=ts(a,{dialect:i}),l.meta.isTable=!0,l=ie(l,{dialect:i}));let f;s&&(f=ts(s,{dialect:i}),f.meta.isTable=!0,f=ie(f,{dialect:i}));let p=h(d=>{d.args.this instanceof Q&&(l&&!d.args.db&&d.setArgKey("db",l.copy()),f&&!d.args.catalog&&d.args.db&&d.setArgKey("catalog",f.copy()))},"qualify");if((l||f)&&!(e instanceof Ae)){let u=e.getArgKey("with")||new Y({expressions:[]}),g=new Set((u.args.expressions||[]).map(A=>A.aliasOrName));for(let A of e.walk({prune:h(x=>x instanceof Ae,"prune")}))A instanceof U&&(g.has(A.name)||p(A))}let m=h((d,u,g={})=>{let{targetAlias:A,scope:x,normalize:E=!1,columns:b}=g,y=d.getArgKey("alias");y||(y=new F({}));let S;if(c)S=n(),u.set(y.name||A||"",S);else if(!y.name)S=A||n(),E&&A&&(S=ie(S,{dialect:i}).name);else return;y.setArgKey("this",_(S)),b&&y.setArgKey("columns",b.map(C=>_(C))),d.setArgKey("alias",y),x&&x.renameSource("",S)},"setAlias");for(let d of D(e)){let u=d.localColumns,g=new Map;for(let x of d.subqueries){let E=x.parent;E&&E instanceof P&&E.unwrap().replace(E)}for(let x of d.derivedTables){let E=x.unnest();if(E instanceof U){let y=E.args.joins;E.setArgKey("joins",void 0);let S=x.args.this;if(S instanceof T){let C=ue("*").from(E.copy(),{copy:!1});S.replace(C),C.setArgKey("joins",y)}}m(x,g,{scope:d});let b=L(x.getArgKey("pivots")||[],0);b&&m(b,g)}let A=new Map;for(let[x,E]of d.sources)if(E instanceof U){let b=!!x,y=E.args.pivots,S=y?L(y,0):void 0,C=x;S&&(C=E.name);let v=E.args.this,K=E.args.alias,k=[];if(v&&v instanceof ge){let cs=v.constructor.name;if(K)K instanceof F&&K.args.columns?.length?k=K.columns:i._constructor.DEFAULT_FUNCTIONS_COLUMN_NAMES.has(cs)&&(k=Array.from(Ye(E.aliasOrName)),E.setArgKey("alias",void 0),C="");else{let ls=i._constructor.DEFAULT_FUNCTIONS_COLUMN_NAMES.get(cs);k=ls?Array.from(Ye(ls)):[]}}m(E,g,{targetAlias:C||E.name||void 0,normalize:!0,columns:k});let ye=E.parts?.map(Ie=>Ie.name).join("."),as=E.args.alias?.args.this,En=K&&K.name;if(as instanceof Q&&(!En||!A.has(ye))&&A.set(ye,as.copy()),S){let Ie=S.getArgKey("unpivot")?E.alias:void 0;if(m(S,g,{targetAlias:Ie,normalize:!0}),d.sources.get(E.aliasOrName)instanceof q)continue}b&&(p(E),o&&o(E))}else if(E instanceof q&&E.isUdtf){let b=E.expression;if(m(b,g),b instanceof Me){let y=b.getArgKey("alias");y instanceof F&&!y.args.columns?.length&&y.setArgKey("columns",i.generateValuesAliases(b).map(S=>ie(S,{dialect:i})))}}for(let x of d.tables)if(!x.alias&&x.parent){let E=x.parent;(E instanceof z||E instanceof N)&&m(x,g,{targetAlias:x.name})}for(let x of u){let E=x.table;if(x.args.db){let b=x.parts.slice(0,-1).map(S=>S.name).join("."),y=A.get(b);y&&(x.setArgKey("table",void 0),x.setArgKey("db",void 0),x.setArgKey("catalog",void 0),x.setArgKey("table",y.copy()))}else if(0<g.size&&E){let b=g.get(E);b&&b!==x.table&&x.setArgKey("table",_(b))}}}return e}h(dn,"qualifyTables");function gn(e,t={}){let{dialect:a,db:s,catalog:o,schema:r,expandAliasRefs:c=!0,expandStars:i=!0,inferSchema:n,isolateTables:l=!1,qualifyColumns:f=!0,allowPartialQualification:p=!1,validateQualifyColumns:m=!0,quoteIdentifiers:d=!0,identify:u=!0,canonicalizeTableAliases:g=!1,onQualify:A,sql:x}=t,E=H(r,{dialect:a}),b=$.getOrRaise(a);return e=ie(e,{dialect:b,storeOriginalColumnIdentifiers:!0}),e=dn(e,{db:s,catalog:o,dialect:b,onQualify:A,canonicalizeTableAliases:g}),l&&(e=nn(e,{schema:E,dialect:b})),f&&(e=ln(e,{schema:E,expandAliasRefs:c,expandStars:i,inferSchema:n,allowPartialQualification:p})),d&&(e=We(e,{dialect:b,identify:u})),m&&fn(e,x),e}h(gn,"qualify");function xn(e){let t=_e("_u_");for(let a of D(e)){let s=a.expression,o=s.parentSelect;if(!o||!j(o,w)||!j(s,w))continue;let r=s;0<a.externalColumns.length?Qn(r,o,a.externalColumns,t):a.scopeType==="subquery"&&Bn(r,o,t)}return e}h(xn,"unnestSubqueries");function Bn(e,t,a){if(1<e.selects.length)return;let s=e.findAncestor(xs);if(!s||s instanceof ge&&(s.parent instanceof U||s.parent instanceof z||s.parent instanceof N)||t!==s.parentSelect||!t.args.from)return;let o=e;e instanceof ne&&(o=ue(e.selects).from(e.subquery(a()),{copy:!1}));let r=a(),c=s.findAncestor(ae,X,N);if(!(s instanceof pe||s instanceof he)){let u=R({col:o.selects[0].aliasOrName,table:r}),g=c?.parentSelect;if(c instanceof ae&&g===t||(!c||g!==t)&&(t.args.group||t.selects.some(E=>re(E,M))))u=new Oe({this:u});else if(!(e.parent instanceof P))return;let A="cross",x;s instanceof Ee&&(u=u.is(Je()).not(),A="left",x=B()),G(e.parent,u),t.join(o,{on:x,joinType:A,joinAlias:r,copy:!1});return}if(o.find([Te,Xe]))return;let i=s;if(s instanceof he){let u=s.findAncestor(W);if(!u||t!==u.parentSelect)return;i=u}let n=is(i),l=o.selects[0],f=l.args.this;if(!(f instanceof T))return;let p=R({col:l.alias,table:r}),m=p.is(Je()).not();c instanceof N?(G(i,B()),t.where(m,{copy:!1})):G(i,m);let d=o.args.group;if(d){let u=new Set((d.args.expressions??[]).map(g=>g instanceof T?g.sql():String(g)));(u.size!==1||!u.has(l.args.this.sql()))&&(o=ue(I(R({col:l.alias,table:"_q"}),l.alias,{copy:!1})).from(o.subquery("_q",{copy:!1}),{copy:!1}).groupBy(R({col:l.alias,table:"_q"}),{copy:!1}))}else re(f,M)||(o=o.groupBy(f,{copy:!1}));n&&t.join(o,{on:n.eq(p),joinType:"left",joinAlias:r,copy:!1})}h(Bn,"unnest");function Qn(e,t,a,s){let o=e.args.where;if(!o||o.find(Le)||e.find([Te,Xe]))return;let r=s(),c=[];for(let y of a){if(y.findAncestor(X)!==o)return;let S=y.findAncestor(Ve);if(!S||S.findAncestor(X)!==o)return;let C;if(S instanceof ee)C=Array.from(S.left?.walk()||[]).some(v=>v===y)?S.right:S.left;else return;if(!C)return;c.push([C,y,S])}if(!c.some(([,,y])=>y instanceof W))return;let i=t.selects.map(y=>y.unalias()).some(y=>y instanceof P&&y===e.parent),n=e.selects[0],l=n.args.this;if(!(l instanceof T))return;let f=new Map,p=new Map,m=new Set,d=[],u=h(y=>m.has(y.sql()),"exprInGroupBy");for(let[y,,S]of c){let C=y.sql();C===l.sql()?(f.set(C,n.alias),p.set(C,y),m.has(C)||(m.add(C),d.push(y))):(f.has(C)||(f.set(C,s()),p.set(C,y)),S instanceof W&&!m.has(C)&&(m.add(C),d.push(y)))}let g=e.findAncestor(Ve);if(g===void 0&&!i)return;let A=i?Oe:vs;!n.find(M)&&!u(l)&&e.select(I(new A({this:l}),n.alias,{quoted:!1}),{append:!1,copy:!1}),g instanceof Ee&&e.setArgKey("expressions",[]);for(let[y,S]of f){let C=p.get(y);m.has(y)?(g instanceof Ee||y!==n.args.this.sql())&&e.select(`${C} AS ${S}`,{copy:!1}):e.select(I(new A({this:C.copy()}),S,{quoted:!1}),{copy:!1})}let x=R({col:n.alias,table:r}),E=is(g),b=g?.parent?._constructor;if(g instanceof Ee)x=R({col:Array.from(f.values())[0],table:r}),g=G(g,`NOT ${x} IS NULL`);else if(g instanceof De){if(!b||!(b.prototype instanceof ee||b===ee))return;let y=new b({this:E,expression:R({col:"_x"})});g.parent&&(g=G(g.parent,`ARRAY_ALL(${x}, _x -> ${y})`))}else if(g instanceof he){if(!b||!(b.prototype instanceof ee||b===ee))return;if(u(n.args.this)){let y=new b({this:E,expression:x});g.parent&&(g=G(g.parent,y))}else{let y=new b({this:E,expression:R({col:"_x"})});g=G(g,`ARRAY_ANY(${x}, _x -> ${y})`)}}else if(g instanceof pe)u(n.args.this)?g=G(g,`${E} = ${x}`):g=G(g,`ARRAY_ANY(${x}, _x -> _x = ${g.args.this})`);else{if(i&&e.parent?.alias&&(x=I(x,e.parent.alias,{copy:!1})),n.find(ss)){let y=h(S=>S instanceof ss?ce.number(0):S instanceof M?Je():S,"removeAggs");x=new xe({this:x,expressions:[n.args.this.transform(y)]})}e.parent?.replace(x)}for(let[y,S,C]of c){C.replace(B());let v=f.get(y.sql());if(!v)continue;let K=R({col:v,table:r});if(i){y.replace(K),C instanceof W||t.where(C,{copy:!1});continue}u(y)?y.replace(K):C instanceof W?g&&(g=G(g,`(${g} AND ARRAY_CONTAINS(${K}, ${S}))`)):(y.replace(_("_x")),g&&(g=G(g,`(${g} AND ARRAY_ANY(${K}, _x -> ${C}))`)))}t.join(e.groupBy(d,{copy:!1}),{on:c.filter(([,,y])=>y instanceof W).map(([,,y])=>y),joinType:"left",joinAlias:r,copy:!1})}h(Qn,"decorrelate");function G(e,t){return e.replace(qs(t))}h(G,"replace");function is(e){if(e instanceof pe)return e.args.this;if(e instanceof he||e instanceof De)return is(e.parent);if(e instanceof ee)return e.left instanceof P||e.left instanceof he||e.left instanceof Ee||e.left instanceof De?e.right:e.left}h(is,"otherOperand");var Gn=[gn,sn,ms,xn,Xs,Ms,rs,Js,os,Us,We,Ge,js,Re];function $o(e,t={}){let{schema:a,db:s,catalog:o,dialect:r,rules:c=Gn,sql:i,isolateTables:n=!0,quoteIdentifiers:l=!1,...f}=t,p=H(a,{dialect:r}),m={db:s,catalog:o,schema:p,dialect:r,sql:i,isolateTables:n,quoteIdentifiers:l,...f},d=Rs(e,{dialect:r,copy:!0});for(let u of c)d=u(d,m);return d}h($o,"optimize");export{gn as a,Ls as b,$o as c};
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
4
|
+
//# sourceMappingURL=chunk-SELHDL3F.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{Ao as N,Bk as A,Bp as F,Br as H,Em as T,Jn as R,Mv as Y,No as D,On as S,Wm as y,Xp as W,Ym as M,Zn as h,a as o,b as E,c as n,d as x,e as i,en as I,es as U,fn as c,ft as X,gn as d,hn as u,jk as f,jn as l,js as V,oq as C,s as m,vn as O,yo as B,yp as P,zo as L,zp as w}from"./chunk-FU46WFXM.js";var v,s;v=[m];var t=class t{static get EXPRESSION_METADATA(){let r=new Map(Y.EXPRESSION_METADATA),e=o((p,a)=>{for(let z of p)r.set(z,a)},"extend");return e([F,M,S,d,I,c,u,O,B,w,L,W,C,N,U,V],{returns:"bigint"}),e([X,h],{returns:"int128"}),e([f,A,H],{returns:"double"}),e([D,P],{returns:"varchar"}),r.set(y,{annotator:o((p,a)=>p.annotateByArgs(a,["expression"]),"annotator")}),r.set(T,{returns:"timestamp"}),r.set(l,{returns:"interval"}),r.set(R,{returns:"time"}),r}};s=E(null),i(s,10,"EXPRESSION_METADATA",v,t),n(s,t),x(s,3,t),o(t,"DuckDbTyping");var g=t;export{g as a};
|
|
2
|
+
//# sourceMappingURL=chunk-SH4MSGSQ.js.map
|