@uwdata/mosaic-sql 0.12.1 → 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.
- package/README.md +1 -1
- package/dist/types/ast/column-param.d.ts +6 -0
- package/dist/types/ast/query.d.ts +59 -14
- package/dist/types/ast/with.d.ts +11 -1
- package/dist/types/functions/aggregate.d.ts +6 -0
- package/dist/types/functions/cte.d.ts +13 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/transforms/bin-linear-1d.d.ts +2 -1
- package/dist/types/transforms/bin-linear-2d.d.ts +2 -2
- package/dist/types/types.d.ts +3 -1
- package/package.json +9 -9
- package/src/ast/column-param.js +9 -0
- package/src/ast/literal.js +1 -1
- package/src/ast/query.js +102 -33
- package/src/ast/with.js +16 -2
- package/src/functions/aggregate.js +9 -0
- package/src/functions/cte.js +16 -0
- package/src/index.js +3 -2
- package/src/transforms/bin-linear-1d.js +4 -3
- package/src/transforms/bin-linear-2d.js +2 -2
- package/src/transforms/m4.js +12 -3
- package/src/types.ts +6 -1
- package/src/visit/visitors.js +2 -2
- package/vitest.config.ts +3 -0
- package/dist/mosaic-sql.js +0 -2606
- package/dist/mosaic-sql.min.js +0 -1
package/dist/mosaic-sql.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var nt="COLUMN_REF",Gt="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",it="WINDOW",or="WINDOW_DEF",nr="WINDOW_FRAME",zr="EXPRESSION",st="FRAGMENT",ir="VERBATIM",ut="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 $r(this.value)}};function $r(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 $=class extends u{constructor(r){super(ut),this.param=r}get value(){return this.param.value}toString(){return $r(this.value)}};function Cr(t){return t.split(".")}function C(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 ct(t){return t instanceof pt}var pt=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=>C(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 f(t,...r){return new G(t,ht(r).map(p))}function c(t,...r){return new Et(t,ht(r).map(p))}function w(t,...r){return new k(new gt(t,ht(r).map(p)))}function R(t,r=p){return t.flat().filter(e=>e!=null).map(e=>r(e))}function ht(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 Nt(t){return Array.isArray(t)}function M(t){return t&&typeof t.addEventListener=="function"&&t.dynamic!==!1&&"value"in t}var At=class extends d{constructor(r,e){super(pr),this.name=r,this.def=e}toString(){return`${C(this.name)} AS ${this.def}`}},k=class t extends u{constructor(r,e=new V){super(it),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}`}},gt=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 _t(this,{name:r})}partitionby(...r){return _t(this,{partition:R(r)})}orderby(...r){return _t(this,{order:R(r)})}rows(r){return _t(this,{frame:new Rt(r)})}range(r){return _t(this,{frame:new Rt(r,!0)})}toString(){let{name:r,partition:e,order:o,frame:n}=this,i=r&&C(r),s=[i,e?.length&&`PARTITION BY ${e.join(", ")}`,o?.length&&`ORDER BY ${o.join(", ")}`,n].filter(a=>a);return i&&s.length<2?i:`(${s.join(" ")})`}},Rt=class extends d{constructor(r,e=!1,o=void 0){super(nr),this.extent=M(r)?new $(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,a=Zr(i,"PRECEDING"),m=Zr(s,"FOLLOWING");return`${n} BETWEEN ${a} AND ${m}${e?` ${e}`:""}`}};function _t(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==="*"?"*":C(r);return(o?o+".":"")+n}},St=class extends P{constructor(r,e){super(nt,e),this.name=r}get column(){return this.name}};var yt=class extends P{constructor(r,e){super(Gt,e),this.param=r}get column(){return`${this.param.value}`}};function Ur(t,r){let e=wt(r);return M(t)?new yt(new $(t),e):new St(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 pt(r):void 0}function p(t){return O(t)?me(t):z(t)}function X(t){return O(t)?te(t):z(t)}function z(t){return t instanceof u?t:M(t)?new $(t):v(t)}function wt(t){return O(t)?le(t):Nt(t)?lr(t):t}function me(t){let r=Cr(t);return Ur(r.pop(),lr(r))}function le(t){return lr(Cr(t))}function qr(){return new V}var Et=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(", "):"*",a=n?` FILTER (WHERE ${n})`:"";return`${r}(${i}${s})${a}`}},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]})`:""}},Ot=class extends xr{constructor(r,e){super(Kt,r,e)}toString(){return super.toSQL("BETWEEN")}},Tt=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 ft=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 at(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"}},at=class extends d{constructor(r,e){super(Xt),this.when=r,this.then=e}toString(){return`WHEN ${this.when} THEN ${this.then}`}};var Lt=class extends u{constructor(r,e){super(Vt),this.expr=r,this.cast=e}toString(){return`(${this.expr})::${this.cast}`}};var It=class extends u{constructor(r){super(st),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 Ct=class extends d{constructor(r,e){super(sr),this.expr=r,this.alias=e}toString(){let{expr:r,alias:e}=this;return!e||xe(r,e)?`${r}`:`${r} AS ${C(e)}`}};function xe(t,r){return t instanceof P&&t.table==null&&t.column===r}var Ft=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 de(t){return t instanceof K}function he(t){return t instanceof Ut}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 Ut(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(ct(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 Ft(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 Ct(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(Nt(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 qt(wt(n),mr(i)));return r.flat().forEach(n=>{if(n!=null)if(O(n))o(n,n);else if(ct(n))o(n,n.name);else if(y(n))o(n);else if(Nt(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 At(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:a,_having:m,_window:T,_qualify:b,_orderby:L,_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}`),a.length&&N.push(`GROUP BY ${a.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(", ")}`),b.length){let I=b.map(String).filter(W=>W).join(" AND ");I&&N.push(`QUALIFY ${I}`)}return L.length&&N.push(`ORDER BY ${L.join(", ")}`),Number.isFinite(U)&&N.push(`LIMIT ${U}`),Number.isFinite(D)&&N.push(`OFFSET ${D}`),N.join(" ")}},Ut=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 qt=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&&!(ct(r)&&r.table.join(".")===e)?`${o} AS ${C(e)}`:`${o}`}};var Dt=class extends u{constructor(r,e){super(rr),this.expr=r,this.values=e}toString(){return`(${this.expr} IN (${this.values.join(", ")}))`}};var Mt=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} `)})`}},Pt=class extends hr{constructor(r){super("AND",r)}},Wt=class extends hr{constructor(r){super("OR",r)}};var mt=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}},vt=class extends gr{constructor(r,e){super(zt,r,e)}toString(){return`(${this.op} ${this.expr})`}},Bt=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 ge(t){return c("array_agg",t)}function Ee(t){return c("avg",t)}function Ne(t,r){return c("corr",t,r)}function _r(t){return c("count",t)}function _e(t,r){return c("covar_samp",t,r)}function Ae(t,r){return c("covar_pop",t,r)}function Re(t){return c("entropy",t)}function Se(t){return c("first",t)}function ye(t){return c("kurtosis",t)}function we(t){return c("mad",t)}function Z(t){return c("max",t)}function Oe(t){return c("median",t)}function Ar(t){return c("min",t)}function Te(t){return c("mode",t)}function be(t){return c("last",t)}function Le(t){return c("product",t)}function Ie(t,r){return c("quantile",t,r)}function $e(t,r){return c("regr_avgx",t,r)}function Ce(t,r){return c("regr_avgy",t,r)}function Fe(t,r){return c("regr_count",t,r)}function Ue(t,r){return c("regr_intercept",t,r)}function qe(t,r){return c("regr_r2",t,r)}function De(t,r){return c("regr_sxx",t,r)}function Me(t,r){return c("regr_sxy",t,r)}function Pe(t,r){return c("regr_syy",t,r)}function We(t,r){return c("regr_slope",t,r)}function ve(t){return c("skewness",t)}function Be(t){return c("stddev",t)}function je(t){return c("stddev_pop",t)}function Ye(t){return c("string_agg",t)}function tt(t){return c("sum",t)}function Qe(t){return c("var_samp",t)}function Ge(t){return c("var_pop",t)}function ke(t,r,e){return t?new ft(void 0,[new at(p(t),p(r))],p(e)):new ft}function Rr(t,r){return new Lt(p(t),r)}function g(t){return Rr(t,"INTEGER")}function Ve(t){return Rr(t,"FLOAT")}function jt(t){return Rr(t,"DOUBLE")}function ee(t,r){return new Mt(t,r)}function Dr(t){return f("epoch_ms",t)}function He(t,r,e=1){return f("time_bucket",ee(r,e),t)}function Xe(t){return f("make_date",2012,f("month",t),1)}function ze(t){let r=p(t);return f("make_date",2012,f("month",r),f("day",r))}function Je(t){return f("make_date",2012,1,f("day",t))}function Ke(t){return f("isnan",t)}function Ze(t){return f("isfinite",t)}function to(t){return f("isinf",t)}function Mr(...t){return f("greatest",...t)}function ro(...t){return f("least",...t)}function Sr(t){return f("exp",t)}function Pr(t){return f("log",t)}function lt(t){return f("ln",t)}function F(t){return f("sign",t)}function A(t){return f("abs",t)}function Wr(t){return f("sqrt",t)}function eo(t){return f("ceil",t)}function S(t){return f("floor",t)}function yr(t,r){return f("round",t,r)}function oo(t){return f("trunc",t)}function oe(t,r){return new vt(t,p(r))}function ne(t,r){return new Bt(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?Tt:Ot;return new o(p(t),r?.map(p))}function no(...t){return new Pt(R(t))}function xt(...t){return new Wt(R(t))}function io(t){return oe("NOT",t)}function vr(t){return ne("IS NULL",t)}function so(t){return ne("IS NOT NULL",t)}function uo(t){return oe("~",t)}function po(t,r){return E("&",t,r)}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 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 mo(t,r){return E("//",t,r)}function lo(t,r){return E("%",t,r)}function rt(t,r){return E("**",t,r)}function xo(t,r){return E("=",t,r)}function Yt(t,r){return E("<>",t,r)}function q(t,r){return E("<",t,r)}function et(t,r){return E(">",t,r)}function Qt(t,r){return E("<=",t,r)}function ho(t,r){return E(">=",t,r)}function go(t,r){return E("IS DISTINCT FROM",t,r)}function Eo(t,r){return E("IS NOT DISTINCT FROM",t,r)}function No(t,r){return ie(t,r,!1)}function _o(t,r){return ie(t,r,!0)}function Ao(t,r){return new Dt(p(t),r.map(p))}function Br(t,r){return new mt(p(t),!1,r)}function Ro(t,r){return new mt(p(t),!0,r)}function So(t){return f("st_asgeojson",t)}function se(t){return f("st_x",t)}function ue(t){return f("st_y",t)}function jr(t){return f("st_centroid",t)}function yo(t){return se(jr(t))}function wo(t){return ue(jr(t))}function Yr(t,...r){return new It(Oo(t,r))}function Oo(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 $(s):e[i]+=O(s)?s:v(s);let a=t[++n];y(e[i])?e[++i]=a:e[i]+=a}return e.filter(n=>n).map(n=>O(n)?new H(n):n)}function ot(t,r,...e){return f(t,r,...ht(e).map(z))}function To(t,r,e){return ot("regexp_matches",t,r,e)}function bo(t,r){return ot("contains",t,r)}function Lo(t,r){return ot("starts_with",t,r)}function Io(t,r){return ot("ends_with",t,r)}function $o(t){return ot("lower",t)}function Co(t){return ot("upper",t)}function Fo(t){return ot("length",t)}function Uo(){return w("row_number")}function qo(){return w("rank")}function Do(){return w("dense_rank")}function Mo(){return w("percent_rank")}function Po(){return w("cume_dist")}function Wo(t){return w("ntile",t)}function vo(t,r,e){return w("lag",t,r,e)}function wr(t,r,e){return w("lead",t,r,e)}function Bo(t){return w("first_value",t)}function jo(t){return w("last_value",t)}function Yo(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"],[Gt]:["param","table"],[nt]:["table"],[fr]:["query"],[zr]:["node"],[st]:["spans"],[ur]:["expr"],[er]:["args"],[rr]:["expr","values"],[tr]:["clauses"],[Zt]:["expr","extent"],[kt]:["expr"],[ut]:["value"],[sr]:["expr"],[cr]:["_with","_select","_from","_where","_sample","_groupby","_having","_window","_qualify","_orderby"],[ar]:["subqueries","_orderby"],[zt]:["expr"],[Xt]:["when","then"],[it]:["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 a=s.length;for(let m=0;m<a;++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 a=s.length;for(let m=0;m<a;++m)if(s[m]&&+j(s[m],r)<0)return e}else if(s&&+j(s,r)<0)return-1}}var Qo=new RegExp(`^(${re.join("|")})$`),Go=/(\\'|\\"|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\w+\()/g;function ko(t){return t.split(Go).some(r=>r.endsWith("(")&&Qo.test(r.slice(0,-1)))}function Vo(t){let r=0;return j(t,e=>{switch(e.type){case it:return-1;case Y:return r|=1,-1;case st:case ir:{let o=`${e}`.toLowerCase(),n=o.indexOf("(select ");return n>=0&&(o=o.slice(0,n)),o.includes(") over ")?-1:ko(o)?(r|=2,-1):1}}}),r}function Ho(t){let r=new Set;return j(t,e=>{e.type===Y&&r.add(e)}),Array.from(r)}function Xo(t){let r={};return j(t,e=>{e.type===nt&&(r[e]=e)}),Object.values(r)}function zo(t){let r=new Set;return j(t,e=>{e.type===ut&&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 Jo(t,{strict:r=!1}={}){return"CREATE SCHEMA "+(r?"":"IF NOT EXISTS ")+t}function Ko(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 br(t,r,e,o={},n={}){let{select:i=["*"],where:s,view:a,temp:m,replace:T,...b}=o,L=nn({...n,...b}),U=`${t}('${e}'${L?", "+L:""})`,D=s?` WHERE ${s}`:"",N=`SELECT ${i.join(", ")} FROM ${U}${D}`;return Tr(r,N,{view:a,temp:m,replace:T})}function Zo(t,r,e){return br("read_csv",t,r,e,{auto_detect:!0,sample_size:-1})}function tn(t,r,e){return br("read_json",t,r,e,{auto_detect:!0,format:"auto"})}function rn(t,r,e){return br("read_parquet",t,r,e)}function en(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,a])=>`${s}=${a}`).join(", ");Object.assign(n,{open_options:i.toUpperCase()})}return br("st_read",t,r,n)}function on(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 nn(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 sn(t,r,e,o,n){let i=n?_(e,jt(t)):_(jt(t),r),s=e===r?0:o/(e-r);return s?l(i,jt(s)):i}function un(t,r,e,o,n,i){return t.select({index:h(g(S(r)),l(g(S(e)),n)),...o}).groupby("index",i)}function pn(t,r,e){let o=e?s=>l(s,e):s=>s,n=S(r),i=h(n,1);return x.from(x.unionAll(t.clone().select({i:g(n),w:o(_(i,r))}),t.clone().select({i:g(i),w:o(_(r,n))}))).select({index:"i",density:tt("w")}).groupby("index").having(Yt("density",0))}function cn(t){return t}function fn(t,r,e,o,n,i){let s=o?dt=>l(dt,o):cn,a=(dt,Ir)=>t.clone().select({xp:r,yp:e,i:dt,w:Ir}),m=(dt,Ir)=>h(dt,l(Ir,n)),T=g(S(r)),b=g(S(e)),L=h(T,1),U=h(b,1),D=_(r,T),N=_(L,r),I=_(e,b),W=_(U,e);return x.from(x.unionAll(a(m(T,b),s(l(N,W))),a(m(T,U),s(l(N,I))),a(m(L,b),s(l(D,W))),a(m(L,U),s(l(D,I))))).select({index:"i",density:tt("w")},i).groupby("index",i).having(Yt("density",0))}function an(t,r,e,o,n,i,s=[],a=!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([xt(q("x0",n),q(h("x0","dx"),n)),xt(q("y0",i),q(h("y0","dy"),i)),xt(et("x0",0),et(h("x0","dx"),0)),xt(et("y0",0),et(h("y0","dy"),0))]),b=x.select({x:Mr(Z(A("dx")),Z(A("dy")))}).from("pairs"),L=x.select({i:g(Yr`UNNEST(range((${b})))`)}),U=x.unionAll(x.select(m,{x:h("x0","i"),y:h("y0",g(yr(B(l("i","dy"),"dx"))))}).from("pairs","indices").where([Qt(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",a?{w:B(1,_r().partitionby(["x"].concat(m)))}:null).where([Qt(0,"x"),q("x",n),Qt(0,"y"),q("y",i)]);return x.with({pairs:T,indices:L,raster:U,points:D}).from("points").select(s,{index:h("x",l("y",g(n))),density:a?tt("w"):_r()}).groupby("index",s)}function mn(t,r,e,o,n=[]){let i=g(S(r)),s=a=>x.from(t).select(a).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 Lr=t=>t;function ce(){return{apply:Lr,invert:Lr,sqlApply:p,sqlInvert:Lr}}function ln({base:t=null}={}){if(t==null||t===Math.E)return{apply:Math.log,invert:Math.exp,sqlApply:r=>lt(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(lt(e),lt(r)),sqlInvert:e=>rt(r,e)}}}function xn({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),lt(h(r,A(e))))),sqlInvert:e=>l(F(e),_(Sr(A(e)),r))}}function dn(){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 hn({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):Nn(t)?v(+t.value):Dr(t),sqlInvert:Lr}}var gn={identity:ce,linear:ce,log:ln,symlog:xn,sqrt:dn,pow:hn,time:fe,utc:fe};function En(t){let r=gn[t.type];return r?{...t,...r(t)}:null}function Nn(t){return t instanceof Q&&t.value instanceof Date}export{Et as AggregateNode,Pt as AndNode,Ot as BetweenOpNode,bt as BinaryOpNode,ft as CaseNode,Lt as CastNode,St as ColumnNameRefNode,yt as ColumnParamNode,P as ColumnRefNode,Ut as DescribeQuery,u as ExprNode,It as FragmentNode,qt as FromClauseNode,G as FunctionNode,Dt as InOpNode,Mt as IntervalNode,Q as LiteralNode,Tt as NotBetweenOpNode,Wt as OrNode,mt as OrderByNode,$ as ParamNode,x as Query,d as SQLNode,$t as SampleClauseNode,Ct as SelectClauseNode,K as SelectQuery,J as SetOperation,pt as TableRefNode,vt as UnaryOpNode,Bt as UnaryPosftixOpNode,H as VerbatimNode,at as WhenNode,At as WindowClauseNode,V as WindowDefNode,Rt as WindowFrameNode,gt as WindowFunctionNode,k as WindowNode,Ft as WithClauseNode,A as abs,h as add,no as and,Er as argmax,Nr as argmin,ge as arrayAgg,z as asLiteral,p as asNode,wt as asTableRef,X as asVerbatim,Br as asc,Ee as avg,sn as bin1d,un as bin2d,pn as binLinear1d,fn as binLinear2d,po as bitAnd,fo as bitLeft,uo as bitNot,co as bitOr,ao as bitRight,Rr as cast,eo as ceil,jr as centroid,yo as centroidX,wo as centroidY,Ho as collectAggregates,Xo as collectColumns,zo as collectParams,Ur as column,ke as cond,bo as contains,Ne as corr,_r as count,Ae as covarPop,_e as covariance,Jo as createSchema,Tr as createTable,Po as cume_dist,He as dateBin,Je as dateDay,Xe as dateMonth,ze as dateMonthDay,Do as dense_rank,Ro as desc,B as div,Re as entropy,Dr as epoch_ms,xo as eq,Sr as exp,Se as first,Bo as first_value,Ve as float32,jt as float64,S as floor,So as geojson,Mr as greatest,et as gt,ho as gte,mo as idiv,g as int32,ee as interval,Vo as isAggregateExpression,No as isBetween,Fr as isColumnRef,he as isDescribeQuery,go as isDistinct,Ze as isFinite,Ao as isIn,to as isInfinite,Ke as isNaN,y as isNode,_o as isNotBetween,Eo as isNotDistinct,so as isNotNull,vr as isNull,M as isParamLike,dr as isQuery,de as isSelectQuery,ct as isTableRef,ye as kurtosis,vo as lag,be as last,jo as last_value,wr as lead,ro as least,Fo as length,an as lineDensity,v as literal,lt as ln,Zo as loadCSV,Ko as loadExtension,tn as loadJSON,on as loadObjects,rn as loadParquet,en as loadSpatial,Pr as log,$o as lower,q as lt,Qt as lte,mn as m4,we as mad,Z as max,Oe as median,Ar as min,lo as mod,Te as mode,l as mul,Yt as neq,io as not,Yo as nth_value,Wo as ntile,xt as or,qr as over,Mo as percent_rank,rt as pow,Lo as prefix,Le as product,Ie as quantile,qo as rank,To as regexp_matches,$e as regrAvgX,Ce as regrAvgY,Fe as regrCount,Ue as regrIntercept,qe as regrR2,De as regrSXX,Me as regrSXY,Pe as regrSYY,We as regrSlope,Qr as rewrite,yr as round,Uo as row_number,En as scaleTransform,F as sign,ve as skewness,Yr as sql,Wr as sqrt,Be as stddev,je as stddevPop,Ye as stringAgg,_ as sub,Io as suffix,tt as sum,oo as trunc,Co as upper,Ge as varPop,Qe as variance,j as walk,se as x,ue as y};
|