@uwdata/mosaic-sql 0.12.2 → 0.13.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.
@@ -1 +0,0 @@
1
- var nt="COLUMN_REF",it="COLUMN_PARAM",kr="TABLE_REF",Vr="LITERAL",Hr="INTERVAL",kt="ORDER_BY",Vt="CAST",Ht="CASE",Xt="WHEN",zt="UNARY",Xr="UNARY_POSTFIX",Jt="BINARY",Kt="BETWEEN",Zt="NOT_BETWEEN",tr="LOGICAL_OPERATOR",rr="IN",er="FUNCTION",Y="AGGREGATE",st="WINDOW",or="WINDOW_DEF",nr="WINDOW_FRAME",zr="EXPRESSION",ut="FRAGMENT",ir="VERBATIM",pt="PARAM",Jr="WITH_CLAUSE",sr="SELECT_CLAUSE",ur="FROM_CLAUSE";var Kr="SAMPLE_CLAUSE";var pr="WINDOW_CLAUSE";var cr="SELECT_QUERY",fr="DESCRIBE_QUERY",ar="SET_OPERATION";function y(t){return t instanceof d}var d=class{constructor(r){this.type=r}},u=class extends d{};var Q=class extends u{constructor(r){super(Vr),this.value=r}toString(){return Cr(this.value)}};function Cr(t){switch(typeof t){case"number":return Number.isFinite(t)?`${t}`:"NULL";case"string":return`'${t.replace("'","''")}'`;case"boolean":return t?"TRUE":"FALSE";default:if(t==null)return"NULL";if(t instanceof Date){let r=+t;if(Number.isNaN(r))return"NULL";let e=t.getUTCFullYear(),o=t.getUTCMonth(),n=t.getUTCDate();return r===Date.UTC(e,o,n)?`DATE '${e}-${o+1}-${n}'`:`epoch_ms(${r})`}else return t instanceof RegExp?`'${t.source}'`:`${t}`}}var C=class extends u{constructor(r){super(pt),this.param=r}get value(){return this.param.value}toString(){return Cr(this.value)}};function $r(t){return t.split(".")}function $(t){return`"${t}"`}function mr(t){return t&&ae(t)?t.slice(1,-1):t}function ae(t){return t[0]==='"'&&t[t.length-1]==='"'}function ft(t){return t instanceof ct}var ct=class extends u{constructor(r){super(kr),this.table=[r].flat()}get name(){return this.table[this.table.length-1]}toString(){return this.table.map(r=>$(r)).join(".")}};var G=class extends u{constructor(r,e=[]){super(er),this.name=r,this.args=e}toString(){let{name:r,args:e}=this;return`${r}(${e.join(", ")})`}};function a(t,...r){return new G(t,Et(r).map(p))}function c(t,...r){return new _t(t,Et(r).map(p))}function w(t,...r){return new k(new Nt(t,Et(r).map(p)))}function R(t,r=p){return t.flat().filter(e=>e!=null).map(e=>r(e))}function Et(t){let r=t.length,e=r;for(;e>0&&t[e-1]===void 0;--e);return e<r?t.slice(0,e):t}function O(t){return typeof t=="string"}function At(t){return Array.isArray(t)}function M(t){return t&&typeof t.addEventListener=="function"&&t.dynamic!==!1&&"value"in t}var St=class extends d{constructor(r,e){super(pr),this.name=r,this.def=e}toString(){return`${$(this.name)} AS ${this.def}`}},k=class t extends u{constructor(r,e=new V){super(st),this.func=r,this.def=e}over(r){return new t(this.func,this.def.over(r))}partitionby(...r){return new t(this.func,this.def.partitionby(...r))}orderby(...r){return new t(this.func,this.def.orderby(...r))}rows(r){return new t(this.func,this.def.rows(r))}range(r){return new t(this.func,this.def.range(r))}toString(){return`${this.func} OVER ${this.def}`}},Nt=class extends G{constructor(r,e){super(r,e)}},V=class extends d{constructor(r,e,o,n){super(or),this.name=r,this.partition=e,this.order=o,this.frame=n}over(r){return Rt(this,{name:r})}partitionby(...r){return Rt(this,{partition:R(r)})}orderby(...r){return Rt(this,{order:R(r)})}rows(r){return Rt(this,{frame:new yt(r)})}range(r){return Rt(this,{frame:new yt(r,!0)})}toString(){let{name:r,partition:e,order:o,frame:n}=this,i=r&&$(r),s=[i,e?.length&&`PARTITION BY ${e.join(", ")}`,o?.length&&`ORDER BY ${o.join(", ")}`,n].filter(f=>f);return i&&s.length<2?i:`(${s.join(" ")})`}},yt=class extends d{constructor(r,e=!1,o=void 0){super(nr),this.extent=M(r)?new C(r):r,this.range=e,this.exclude=o}toString(){let{range:r,exclude:e,extent:o}=this,n=r?"RANGE":"ROWS",[i,s]=y(o)?o.value:o,f=Zr(i,"PRECEDING"),m=Zr(s,"FOLLOWING");return`${n} BETWEEN ${f} AND ${m}${e?` ${e}`:""}`}};function Rt(t,r){return new V(r.name??t.name,r.partition??t.partition,r.order??t.order,r.frame??t.frame)}function Zr(t,r){return t===0?"CURRENT ROW":Number.isFinite(t)?`${Math.abs(t)} ${r}`:`UNBOUNDED ${r}`}function Fr(t){return t instanceof P}var P=class extends u{constructor(r,e){super(r),this.table=e}get column(){return null}toString(){let{column:r,table:e}=this,o=`${e??""}`,n=r==="*"?"*":$(r);return(o?o+".":"")+n}},wt=class extends P{constructor(r,e){super(nt,e),this.name=r}get column(){return this.name}};function me(t){return t instanceof at}var at=class extends P{constructor(r,e){super(it,e),this.param=r}get column(){return`${this.param.value}`}};function Ur(t,r){let e=Ot(r);return M(t)?new at(new C(t),e):new wt(t,e)}var H=class extends u{constructor(r){super(ir),this.value=r}toString(){return this.value}};function v(t){return new Q(t)}function te(t){return new H(t)}function lr(...t){let r=R(t,String);return r?.length?new ct(r):void 0}function p(t){return O(t)?le(t):z(t)}function X(t){return O(t)?te(t):z(t)}function z(t){return t instanceof u?t:M(t)?new C(t):v(t)}function Ot(t){return O(t)?xe(t):At(t)?lr(t):t}function le(t){let r=$r(t);return Ur(r.pop(),lr(r))}function xe(t){return lr($r(t))}function qr(){return new V}var _t=class t extends u{constructor(r,e,o,n){super(Y),this.name=r,this.args=e,this.isDistinct=o,this.filter=n}distinct(r=!0){return new t(this.name,this.args,r,this.filter)}where(r){return O(r)&&(r=X(r)),new t(this.name,this.args,this.isDistinct,r)}window(){return new k(this)}partitionby(...r){return this.window().partitionby(...r)}orderby(...r){return this.window().orderby(...r)}toString(){let{name:r,args:e,isDistinct:o,filter:n}=this,i=o?"DISTINCT ":"",s=e?.length?e.join(", "):"*",f=n?` FILTER (WHERE ${n})`:"";return`${r}(${i}${s})${f}`}},re=["any_value","approx_count_distinct","approx_quantile","arbitrary","arg_max","arg_max_null","arg_min","arg_min_null","array_agg","avg","bit_and","bit_or","bit_xor","bitstring_agg","bool_and","bool_or","corr","count","covar_pop","covar_samp","entropy","favg","first","fsum","geomean","kurtosis_pop","kurtosis","last","mad","max","max_by","median","min","min_by","mode","product","quantile","quantile_cont","quantile_disc","regr_avgx","regr_avgy","regr_count","regr_intercept","regr_r2","regr_sxx","regr_sxy","regr_syy","regr_slope","reservoir_quantile","skewness","stddev","stddev_pop","stddev_samp","string_agg","sum","variance","var_pop","var_samp"];var xr=class extends u{constructor(r,e,o){super(r),this.expr=e,this.extent=o}toSQL(r){let{extent:e,expr:o}=this;return e?`(${o} ${r} ${e[0]} AND ${e[1]})`:""}},Tt=class extends xr{constructor(r,e){super(Kt,r,e)}toString(){return super.toSQL("BETWEEN")}},Lt=class extends xr{constructor(r,e){super(Zt,r,e)}toString(){return super.toSQL("NOT BETWEEN")}};var bt=class extends u{constructor(r,e,o){super(Jt),this.op=r,this.left=e,this.right=o}toString(){return`(${this.left} ${this.op} ${this.right})`}};var mt=class t extends u{constructor(r=void 0,e=[],o=void 0){super(Ht),this.expr=r,this._when=e,this._else=o}when(r,e){return new t(this.expr,this._when.concat(new lt(p(r),p(e))),this._else)}else(r){return new t(this.expr,this._when,p(r))}toString(){return"CASE "+(this.expr?`${this.expr} `:"")+this._when.join(" ")+(this._else?` ELSE ${this._else}`:"")+" END"}},lt=class extends d{constructor(r,e){super(Xt),this.when=r,this.then=e}toString(){return`WHEN ${this.when} THEN ${this.then}`}};var It=class extends u{constructor(r,e){super(Vt),this.expr=r,this.cast=e}toString(){return`(${this.expr})::${this.cast}`}};var Ct=class extends u{constructor(r){super(ut),this.spans=r}toString(){return this.spans.join("")}};var $t=class extends d{constructor(r,e=!1,o=void 0,n=void 0){super(Kr),this.size=r,this.perc=e,this.method=o,this.seed=n}toString(){let{size:r,perc:e,method:o,seed:n}=this,i=e?"%":" ROWS",s=n!=null?`, ${n}`:"";return`${r}${i}${o?` (${o}${s})`:""}`}};var Ft=class extends d{constructor(r,e){super(sr),this.expr=r,this.alias=e}toString(){let{expr:r,alias:e}=this;return!e||de(r,e)?`${r}`:`${r} AS ${$(e)}`}};function de(t,r){return t instanceof P&&t.table==null&&t.column===r}var Ut=class extends d{constructor(r,e){super(Jr),this.name=r,this.query=e}toString(){return`"${this.name}" AS (${this.query})`}};function dr(t){return t instanceof x}function he(t){return t instanceof K}function ge(t){return t instanceof qt}var x=class extends u{static select(...r){return new K().select(...r)}static from(...r){return new K().from(...r)}static with(...r){return new K().with(...r)}static union(...r){return new J("UNION",r.flat())}static unionAll(...r){return new J("UNION ALL",r.flat())}static intersect(...r){return new J("INTERSECT",r.flat())}static except(...r){return new J("EXCEPT",r.flat())}static describe(r){return new qt(r)}constructor(r){super(r),this._orderby=[],this._limit=void 0,this._offset=void 0,this.cteFor=null}get subqueries(){return[]}clone(){return this}orderby(...r){return this._orderby=this._orderby.concat(R(r)),this}limit(r){return this._limit=Number.isFinite(r)?r:void 0,this}offset(r){return this._offset=Number.isFinite(r)?r:void 0,this}},K=class t extends x{constructor(){super(cr),this._with=[],this._select=[],this._from=[],this._where=[],this._sample=void 0,this._groupby=[],this._having=[],this._window=[],this._qualify=[]}get subqueries(){let r=this.cteFor||this,o=(r instanceof t?r._with:[]).reduce((i,s)=>(i[s.name]=s.query,i),{}),n=[];return this._from.forEach(({expr:i})=>{if(dr(i))n.push(i);else if(ft(i)){let s=o[i.name];s&&n.push(s)}}),n}clone(){return Object.assign(new t,this)}with(...r){let e=[],o=(n,i)=>{let s=i.clone();s.cteFor=this,e.push(new Ut(n,s))};return r.flat().forEach(n=>{if(n!=null)for(let i in n)o(i,n[i])}),this._with=this._with.concat(e),this}select(...r){let e=[],o=(i,s)=>e.push(new Ft(i==null?i:p(i),mr(s)));r.flat().forEach(i=>{if(i!=null)if(O(i))o(i,i);else if(Fr(i))o(i,i.column);else if(At(i))o(i[1],i[0]);else for(let s in i)o(i[s],s)});let n=new Set(e.map(i=>i.alias));return this._select=this._select.filter(i=>!n.has(i.alias)).concat(e.filter(i=>i.expr)),this}setSelect(...r){return this._select=[],this.select(...r)}distinct(r=!0){return this._distinct=!!r,this}from(...r){let e=[],o=(n,i)=>e.push(new Dt(Ot(n),mr(i)));return r.flat().forEach(n=>{if(n!=null)if(O(n))o(n,n);else if(ft(n))o(n,n.name);else if(y(n))o(n);else if(At(n))o(n[1],n[0]);else for(let i in n)o(n[i],i)}),this._from=this._from.concat(e),this}setFrom(...r){return this._from=[],this.from(...r)}sample(r,e,o){let n;if(typeof r=="number"){let i=r>0&&r<1,s=i?r*100:Math.floor(r);n=new $t(s,i,e,o)}else n=r;return this._sample=n,this}where(...r){return this._where=this._where.concat(R(r,X)),this}setWhere(...r){return this._where=[],this.where(...r)}groupby(...r){return this._groupby=this._groupby.concat(R(r)),this}setGroupby(...r){return this._groupby=[],this.groupby(...r)}having(...r){return this._having=this._having.concat(R(r,X)),this}window(...r){let e=[];return r.flat().forEach(o=>{if(o!=null)for(let n in o)e.push(new St(mr(n),o[n]))}),this._window=this._window.concat(e),this}qualify(...r){return this._qualify=this._qualify.concat(R(r,X)),this}toString(){let{_with:r,_select:e,_distinct:o,_from:n,_sample:i,_where:s,_groupby:f,_having:m,_window:T,_qualify:L,_orderby:b,_limit:U,_offset:D}=this,N=[];if(r.length&&N.push(`WITH ${r.join(", ")}`),N.push(`SELECT${o?" DISTINCT":""} ${e.join(", ")}`),n.length&&N.push(`FROM ${n.join(", ")}`),s.length){let I=s.map(String).filter(W=>W).join(" AND ");I&&N.push(`WHERE ${I}`)}if(i&&N.push(`USING SAMPLE ${i}`),f.length&&N.push(`GROUP BY ${f.join(", ")}`),m.length){let I=m.map(String).filter(W=>W).join(" AND ");I&&N.push(`HAVING ${I}`)}if(T.length&&N.push(`WINDOW ${T.join(", ")}`),L.length){let I=L.map(String).filter(W=>W).join(" AND ");I&&N.push(`QUALIFY ${I}`)}return b.length&&N.push(`ORDER BY ${b.join(", ")}`),Number.isFinite(U)&&N.push(`LIMIT ${U}`),Number.isFinite(D)&&N.push(`OFFSET ${D}`),N.join(" ")}},qt=class t extends d{constructor(r){super(fr),this.query=r}clone(){return new t(this.query.clone())}toString(){return`DESCRIBE ${this.query}`}},J=class t extends x{constructor(r,e){super(ar),this.op=r,this.queries=e}get subqueries(){let{queries:r,cteFor:e}=this;return e&&r.forEach(o=>o.cteFor=e),r}clone(){let{op:r,queries:e,...o}=this;return Object.assign(new t(r,e),o)}toString(){let{op:r,queries:e,_orderby:o,_limit:n,_offset:i}=this,s=[e.join(` ${r} `)];return o.length&&s.push(`ORDER BY ${o.join(", ")}`),Number.isFinite(n)&&s.push(`LIMIT ${n}`),Number.isFinite(i)&&s.push(`OFFSET ${i}`),s.join(" ")}};var Dt=class extends d{constructor(r,e){super(ur),this.expr=r,this.alias=e}toString(){let{expr:r,alias:e}=this,o=dr(r)?`(${r})`:`${r}`;return e&&!(ft(r)&&r.table.join(".")===e)?`${o} AS ${$(e)}`:`${o}`}};var Mt=class extends u{constructor(r,e){super(rr),this.expr=r,this.values=e}toString(){return`(${this.expr} IN (${this.values.join(", ")}))`}};var Pt=class extends u{constructor(r,e=1){super(Hr),this.name=r,this.steps=e}toString(){return`INTERVAL ${this.steps} ${this.name}`}};var hr=class extends u{constructor(r,e){super(tr),this.op=r,this.clauses=e}toString(){let r=this.clauses;return r.length===0?"":r.length===1?`${r[0]}`:`(${r.join(` ${this.op} `)})`}},Wt=class extends hr{constructor(r){super("AND",r)}},vt=class extends hr{constructor(r){super("OR",r)}};var xt=class extends u{constructor(r,e,o){super(kt),this.expr=r,this.desc=e,this.nullsFirst=o}toString(){let{expr:r,desc:e,nullsFirst:o}=this;return`${r}${e?" DESC":e===!1?" ASC":""}${o?" NULLS FIRST":o===!1?" NULLS LAST":""}`}};var gr=class extends u{constructor(r,e,o){super(r),this.op=e,this.expr=o}},Bt=class extends gr{constructor(r,e){super(zt,r,e)}toString(){return`(${this.op} ${this.expr})`}},jt=class extends gr{constructor(r,e){super(Xr,r,e)}toString(){return`(${this.expr} ${this.op})`}};function Er(t,r){return c("arg_max",t,r)}function Nr(t,r){return c("arg_min",t,r)}function Ee(t){return c("array_agg",t)}function Ne(t){return c("avg",t)}function _e(t,r){return c("corr",t,r)}function _r(t){return c("count",t)}function Ae(t,r){return c("covar_samp",t,r)}function Re(t,r){return c("covar_pop",t,r)}function Se(t){return c("entropy",t)}function ye(t){return c("first",t)}function we(t){return c("kurtosis",t)}function Oe(t){return c("mad",t)}function Z(t){return c("max",t)}function Te(t){return c("median",t)}function Ar(t){return c("min",t)}function Le(t){return c("mode",t)}function be(t){return c("last",t)}function Ie(t){return c("product",t)}function Ce(t,r){return c("quantile",t,r)}function $e(t,r){return c("regr_avgx",t,r)}function Fe(t,r){return c("regr_avgy",t,r)}function Ue(t,r){return c("regr_count",t,r)}function qe(t,r){return c("regr_intercept",t,r)}function De(t,r){return c("regr_r2",t,r)}function Me(t,r){return c("regr_sxx",t,r)}function Pe(t,r){return c("regr_sxy",t,r)}function We(t,r){return c("regr_syy",t,r)}function ve(t,r){return c("regr_slope",t,r)}function Be(t){return c("skewness",t)}function je(t){return c("stddev",t)}function Ye(t){return c("stddev_pop",t)}function Qe(t){return c("string_agg",t)}function tt(t){return c("sum",t)}function Ge(t){return c("var_samp",t)}function ke(t){return c("var_pop",t)}function Ve(t,r,e){return t?new mt(void 0,[new lt(p(t),p(r))],p(e)):new mt}function Rr(t,r){return new It(p(t),r)}function g(t){return Rr(t,"INTEGER")}function He(t){return Rr(t,"FLOAT")}function Yt(t){return Rr(t,"DOUBLE")}function ee(t,r){return new Pt(t,r)}function Dr(t){return a("epoch_ms",t)}function Xe(t,r,e=1){return a("time_bucket",ee(r,e),t)}function ze(t){return a("make_date",2012,a("month",t),1)}function Je(t){let r=p(t);return a("make_date",2012,a("month",r),a("day",r))}function Ke(t){return a("make_date",2012,1,a("day",t))}function Ze(t){return a("isnan",t)}function to(t){return a("isfinite",t)}function ro(t){return a("isinf",t)}function Mr(...t){return a("greatest",...t)}function eo(...t){return a("least",...t)}function Sr(t){return a("exp",t)}function Pr(t){return a("log",t)}function dt(t){return a("ln",t)}function F(t){return a("sign",t)}function A(t){return a("abs",t)}function Wr(t){return a("sqrt",t)}function oo(t){return a("ceil",t)}function S(t){return a("floor",t)}function yr(t,r){return a("round",t,r)}function no(t){return a("trunc",t)}function oe(t,r){return new Bt(t,p(r))}function ne(t,r){return new jt(t,p(r))}function E(t,r,e){return new bt(t,p(r),p(e))}function ie(t,r,e=!1){let o=e?Lt:Tt;return new o(p(t),r?.map(p))}function io(...t){return new Wt(R(t))}function ht(...t){return new vt(R(t))}function so(t){return oe("NOT",t)}function vr(t){return ne("IS NULL",t)}function uo(t){return ne("IS NOT NULL",t)}function po(t){return oe("~",t)}function co(t,r){return E("&",t,r)}function fo(t,r){return E("|",t,r)}function ao(t,r){return E("<<",t,r)}function mo(t,r){return E(">>",t,r)}function h(t,r){return E("+",t,r)}function _(t,r){return E("-",t,r)}function l(t,r){return E("*",t,r)}function B(t,r){return E("/",t,r)}function lo(t,r){return E("//",t,r)}function xo(t,r){return E("%",t,r)}function rt(t,r){return E("**",t,r)}function ho(t,r){return E("=",t,r)}function Qt(t,r){return E("<>",t,r)}function q(t,r){return E("<",t,r)}function et(t,r){return E(">",t,r)}function Gt(t,r){return E("<=",t,r)}function go(t,r){return E(">=",t,r)}function Eo(t,r){return E("IS DISTINCT FROM",t,r)}function No(t,r){return E("IS NOT DISTINCT FROM",t,r)}function _o(t,r){return ie(t,r,!1)}function Ao(t,r){return ie(t,r,!0)}function Ro(t,r){return new Mt(p(t),r.map(p))}function Br(t,r){return new xt(p(t),!1,r)}function So(t,r){return new xt(p(t),!0,r)}function yo(t){return a("st_asgeojson",t)}function se(t){return a("st_x",t)}function ue(t){return a("st_y",t)}function jr(t){return a("st_centroid",t)}function wo(t){return se(jr(t))}function Oo(t){return ue(jr(t))}function Yr(t,...r){return new Ct(To(t,r))}function To(t,r){let e=[t[0]],o=r.length;for(let n=0,i=0;n<o;){let s=r[n];y(s)?e[++i]=s:M(s)?e[++i]=new C(s):e[i]+=O(s)?s:v(s);let f=t[++n];y(e[i])?e[++i]=f:e[i]+=f}return e.filter(n=>n).map(n=>O(n)?new H(n):n)}function ot(t,r,...e){return a(t,r,...Et(e).map(z))}function Lo(t,r,e){return ot("regexp_matches",t,r,e)}function bo(t,r){return ot("contains",t,r)}function Io(t,r){return ot("starts_with",t,r)}function Co(t,r){return ot("ends_with",t,r)}function $o(t){return ot("lower",t)}function Fo(t){return ot("upper",t)}function Uo(t){return ot("length",t)}function qo(){return w("row_number")}function Do(){return w("rank")}function Mo(){return w("dense_rank")}function Po(){return w("percent_rank")}function Wo(){return w("cume_dist")}function vo(t){return w("ntile",t)}function Bo(t,r,e){return w("lag",t,r,e)}function wr(t,r,e){return w("lead",t,r,e)}function jo(t){return w("first_value",t)}function Yo(t){return w("last_value",t)}function Qo(t,r){return w("nth_value",t,r)}var Or={[Y]:["args","filter"],[Kt]:["expr","extent"],[Jt]:["left","right"],[Ht]:["expr","_when","_else"],[Vt]:["expr"],[it]:["param","table"],[nt]:["table"],[fr]:["query"],[zr]:["node"],[ut]:["spans"],[ur]:["expr"],[er]:["args"],[rr]:["expr","values"],[tr]:["clauses"],[Zt]:["expr","extent"],[kt]:["expr"],[pt]:["value"],[sr]:["expr"],[cr]:["_with","_select","_from","_where","_sample","_groupby","_having","_window","_qualify","_orderby"],[ar]:["subqueries","_orderby"],[zt]:["expr"],[Xt]:["when","then"],[st]:["func","def"],[pr]:["def"],[or]:["partition","order","frame"],[nr]:["extent"]};function Qr(t,r){if(r.has(t))return r.get(t);if(y(t)){let e=Or[t.type],o=e?.length??0;for(let n=0;n<o;++n){let i=e[n],s=t[i];if(Array.isArray(s)){let f=s.length;for(let m=0;m<f;++m)s[m]=Qr(s[m],r)}else s&&(t[i]=Qr(s,r))}}return t}function j(t,r){if(!y(t))return;let e=r(t);if(e)return e;let o=Or[t.type],n=o?.length??0;for(let i=0;i<n;++i){let s=t[o[i]];if(Array.isArray(s)){let f=s.length;for(let m=0;m<f;++m)if(s[m]&&+j(s[m],r)<0)return e}else if(s&&+j(s,r)<0)return-1}}var Go=new RegExp(`^(${re.join("|")})$`),ko=/(\\'|\\"|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\w+\()/g;function Vo(t){return t.split(ko).some(r=>r.endsWith("(")&&Go.test(r.slice(0,-1)))}function Ho(t){let r=0;return j(t,e=>{switch(e.type){case st:return-1;case Y:return r|=1,-1;case ut:case ir:{let o=`${e}`.toLowerCase(),n=o.indexOf("(select ");return n>=0&&(o=o.slice(0,n)),o.includes(") over ")?-1:Vo(o)?(r|=2,-1):1}}}),r}function Xo(t){let r=new Set;return j(t,e=>{e.type===Y&&r.add(e)}),Array.from(r)}function zo(t){let r={};return j(t,e=>{(e.type===nt||e.type===it)&&(r[e]=e)}),Object.values(r)}function Jo(t){let r=new Set;return j(t,e=>{e.type===pt&&r.add(e.param)}),Array.from(r)}function Tr(t,r,{replace:e=!1,temp:o=!1,view:n=!1}={}){return"CREATE"+(e?" OR REPLACE ":" ")+(o?"TEMP ":"")+(n?"VIEW":"TABLE")+(e?" ":" IF NOT EXISTS ")+t+" AS "+r}function Ko(t,{strict:r=!1}={}){return"CREATE SCHEMA "+(r?"":"IF NOT EXISTS ")+t}function Zo(t){return`INSTALL ${t}; LOAD ${t}`}function pe(t,{columns:r=Object.keys(t?.[0]||{})}={}){let e=[];if(Array.isArray(r)?(e=r,r=e.reduce((n,i)=>(n[i]=i,n),{})):r&&(e=Object.keys(r)),!e.length)throw new Error("Can not create table from empty column set.");let o=[];for(let n of t){let i=e.map(s=>`${z(n[s])} AS "${r[s]}"`);o.push(`(SELECT ${i.join(", ")})`)}return o.join(" UNION ALL ")}function Lr(t,r,e,o={},n={}){let{select:i=["*"],where:s,view:f,temp:m,replace:T,...L}=o,b=sn({...n,...L}),U=`${t}('${e}'${b?", "+b:""})`,D=s?` WHERE ${s}`:"",N=`SELECT ${i.join(", ")} FROM ${U}${D}`;return Tr(r,N,{view:f,temp:m,replace:T})}function tn(t,r,e){return Lr("read_csv",t,r,e,{auto_detect:!0,sample_size:-1})}function rn(t,r,e){return Lr("read_json",t,r,e,{auto_detect:!0,format:"auto"})}function en(t,r,e){return Lr("read_parquet",t,r,e)}function on(t,r,e={}){let{options:o,...n}=e;if(o){let i=Array.isArray(o)?o.join(", "):typeof o=="string"?o:Object.entries(o).map(([s,f])=>`${s}=${f}`).join(", ");Object.assign(n,{open_options:i.toUpperCase()})}return Lr("st_read",t,r,n)}function nn(t,r,e={}){let{select:o=["*"],...n}=e,i=pe(r),s=o.length===1&&o[0]==="*"?i:`SELECT ${o} FROM ${i}`;return Tr(t,s,n)}function sn(t){return Object.entries(t).map(([r,e])=>`${r}=${Gr(e)}`).join(", ")}function Gr(t){switch(typeof t){case"boolean":return String(t);case"string":return`'${t}'`;case"undefined":case"object":return t==null?"NULL":Array.isArray(t)?"["+t.map(r=>Gr(r)).join(", ")+"]":"{"+Object.entries(t).map(([r,e])=>`'${r}': ${Gr(e)}`).join(", ")+"}";default:return t}}function un(t,r,e,o,n){let i=n?_(e,Yt(t)):_(Yt(t),r),s=e===r?0:o/(e-r);return s?l(i,Yt(s)):i}function pn(t,r,e,o,n,i){return t.select({index:h(g(S(r)),l(g(S(e)),n)),...o}).groupby("index",i)}function cn(t,r,e=void 0,o=[]){let n=e?f=>l(f,e):f=>f,i=S(r),s=h(i,1);return x.from(x.unionAll(t.clone().select({i:g(i),w:n(_(s,r))}),t.clone().select({i:g(s),w:n(_(r,i))}))).select({index:"i",density:tt("w")},o).groupby("index",o).having(Qt("density",0))}function fn(t){return t}function an(t,r,e,o,n,i=[]){let s=o?gt=>l(gt,o):fn,f=(gt,Ir)=>t.clone().select({xp:r,yp:e,i:gt,w:Ir}),m=(gt,Ir)=>h(gt,l(Ir,n)),T=g(S(r)),L=g(S(e)),b=h(T,1),U=h(L,1),D=_(r,T),N=_(b,r),I=_(e,L),W=_(U,e);return x.from(x.unionAll(f(m(T,L),s(l(N,W))),f(m(T,U),s(l(N,I))),f(m(b,L),s(l(D,W))),f(m(b,U),s(l(D,I))))).select({index:"i",density:tt("w")},i).groupby("index",i).having(Qt("density",0))}function mn(t,r,e,o,n,i,s=[],f=!0){t.select({x:g(S(r)),y:g(S(e))});let m=s.concat(o),T=x.from(t).select(m,{x0:"x",y0:"y",dx:_(wr("x").over("sw"),"x"),dy:_(wr("y").over("sw"),"y")}).window({sw:qr().partitionby(m).orderby(Br("x"))}).qualify([ht(q("x0",n),q(h("x0","dx"),n)),ht(q("y0",i),q(h("y0","dy"),i)),ht(et("x0",0),et(h("x0","dx"),0)),ht(et("y0",0),et(h("y0","dy"),0))]),L=x.select({x:Mr(Z(A("dx")),Z(A("dy")))}).from("pairs"),b=x.select({i:g(Yr`UNNEST(range((${L})))`)}),U=x.unionAll(x.select(m,{x:h("x0","i"),y:h("y0",g(yr(B(l("i","dy"),"dx"))))}).from("pairs","indices").where([Gt(A("dy"),A("dx")),q("i",A("dx"))]),x.select(m,{x:h("x0",g(yr(B(l(l(F("dy"),"i"),"dx"),"dy")))),y:h("y0",l(F("dy"),"i"))}).from("pairs","indices").where([et(A("dy"),A("dx")),q("i",A("dy"))]),x.select(m,{x:"x0",y:"y0"}).from("pairs").where(vr("dx"))),D=x.from("raster").select(m,"x","y",f?{w:B(1,_r().partitionby(["x"].concat(m)))}:null).where([Gt(0,"x"),q("x",n),Gt(0,"y"),q("y",i)]);return x.with({pairs:T,indices:b,raster:U,points:D}).from("points").select(s,{index:h("x",l("y",g(n))),density:f?tt("w"):_r()}).groupby("index",s)}function ln(t,r,e,o,n=[]){let i=g(S(r)),s=f=>x.from(t).select(f).groupby(i,n);return x.union(s([{[e]:Ar(e),[o]:Nr(o,e)},...n]),s([{[e]:Z(e),[o]:Er(o,e)},...n]),s([{[e]:Nr(e,o),[o]:Ar(o)},...n]),s([{[e]:Er(e,o),[o]:Z(o)},...n])).orderby(n,e)}var br=t=>t;function ce(){return{apply:br,invert:br,sqlApply:p,sqlInvert:br}}function xn({base:t=null}={}){if(t==null||t===Math.E)return{apply:Math.log,invert:Math.exp,sqlApply:r=>dt(r),sqlInvert:r=>Sr(r)};if(t===10)return{apply:Math.log10,invert:r=>Math.pow(10,r),sqlApply:r=>Pr(r),sqlInvert:r=>rt(10,r)};{let r=+t;return{apply:e=>Math.log(e)/Math.log(r),invert:e=>Math.pow(r,e),sqlApply:e=>B(dt(e),dt(r)),sqlInvert:e=>rt(r,e)}}}function dn({constant:t=1}={}){let r=+t;return{apply:e=>Math.sign(e)*Math.log1p(Math.abs(e)),invert:e=>Math.sign(e)*Math.exp(Math.abs(e)-r),sqlApply:e=>(e=p(e),l(F(e),dt(h(r,A(e))))),sqlInvert:e=>l(F(e),_(Sr(A(e)),r))}}function hn(){return{apply:t=>Math.sign(t)*Math.sqrt(Math.abs(t)),invert:t=>Math.sign(t)*t*t,sqlApply:t=>(t=p(t),l(F(t),Wr(A(t)))),sqlInvert:t=>l(F(t),rt(t,2))}}function gn({exponent:t=1}={}){let r=+t;return{apply:e=>Math.sign(e)*Math.pow(Math.abs(e),r),invert:e=>Math.sign(e)*Math.pow(Math.abs(e),1/r),sqlApply:e=>(e=p(e),l(F(e),rt(A(e),r))),sqlInvert:e=>l(F(e),rt(A(e),B(1,r)))}}function fe(){return{apply:t=>+t,invert:t=>new Date(t),sqlApply:t=>t instanceof Date?v(+t):_n(t)?v(+t.value):Dr(t),sqlInvert:br}}var En={identity:ce,linear:ce,log:xn,symlog:dn,sqrt:hn,pow:gn,time:fe,utc:fe};function Nn(t){let r=En[t.type];return r?{...t,...r(t)}:null}function _n(t){return t instanceof Q&&t.value instanceof Date}export{_t as AggregateNode,Wt as AndNode,Tt as BetweenOpNode,bt as BinaryOpNode,mt as CaseNode,It as CastNode,wt as ColumnNameRefNode,at as ColumnParamNode,P as ColumnRefNode,qt as DescribeQuery,u as ExprNode,Ct as FragmentNode,Dt as FromClauseNode,G as FunctionNode,Mt as InOpNode,Pt as IntervalNode,Q as LiteralNode,Lt as NotBetweenOpNode,vt as OrNode,xt as OrderByNode,C as ParamNode,x as Query,d as SQLNode,$t as SampleClauseNode,Ft as SelectClauseNode,K as SelectQuery,J as SetOperation,ct as TableRefNode,Bt as UnaryOpNode,jt as UnaryPosftixOpNode,H as VerbatimNode,lt as WhenNode,St as WindowClauseNode,V as WindowDefNode,yt as WindowFrameNode,Nt as WindowFunctionNode,k as WindowNode,Ut as WithClauseNode,A as abs,h as add,io as and,Er as argmax,Nr as argmin,Ee as arrayAgg,z as asLiteral,p as asNode,Ot as asTableRef,X as asVerbatim,Br as asc,Ne as avg,un as bin1d,pn as bin2d,cn as binLinear1d,an as binLinear2d,co as bitAnd,ao as bitLeft,po as bitNot,fo as bitOr,mo as bitRight,Rr as cast,oo as ceil,jr as centroid,wo as centroidX,Oo as centroidY,Xo as collectAggregates,zo as collectColumns,Jo as collectParams,Ur as column,Ve as cond,bo as contains,_e as corr,_r as count,Re as covarPop,Ae as covariance,Ko as createSchema,Tr as createTable,Wo as cume_dist,Xe as dateBin,Ke as dateDay,ze as dateMonth,Je as dateMonthDay,Mo as dense_rank,So as desc,B as div,Se as entropy,Dr as epoch_ms,ho as eq,Sr as exp,ye as first,jo as first_value,He as float32,Yt as float64,S as floor,yo as geojson,Mr as greatest,et as gt,go as gte,lo as idiv,g as int32,ee as interval,Ho as isAggregateExpression,_o as isBetween,me as isColumnParam,Fr as isColumnRef,ge as isDescribeQuery,Eo as isDistinct,to as isFinite,Ro as isIn,ro as isInfinite,Ze as isNaN,y as isNode,Ao as isNotBetween,No as isNotDistinct,uo as isNotNull,vr as isNull,M as isParamLike,dr as isQuery,he as isSelectQuery,ft as isTableRef,we as kurtosis,Bo as lag,be as last,Yo as last_value,wr as lead,eo as least,Uo as length,mn as lineDensity,v as literal,dt as ln,tn as loadCSV,Zo as loadExtension,rn as loadJSON,nn as loadObjects,en as loadParquet,on as loadSpatial,Pr as log,$o as lower,q as lt,Gt as lte,ln as m4,Oe as mad,Z as max,Te as median,Ar as min,xo as mod,Le as mode,l as mul,Qt as neq,so as not,Qo as nth_value,vo as ntile,ht as or,qr as over,Po as percent_rank,rt as pow,Io as prefix,Ie as product,Ce as quantile,Do as rank,Lo as regexp_matches,$e as regrAvgX,Fe as regrAvgY,Ue as regrCount,qe as regrIntercept,De as regrR2,Me as regrSXX,Pe as regrSXY,We as regrSYY,ve as regrSlope,Qr as rewrite,yr as round,qo as row_number,Nn as scaleTransform,F as sign,Be as skewness,Yr as sql,Wr as sqrt,je as stddev,Ye as stddevPop,Qe as stringAgg,_ as sub,Co as suffix,tt as sum,no as trunc,Fo as upper,ke as varPop,Ge as variance,j as walk,se as x,ue as y};