@uwdata/mosaic-sql 0.12.0 → 0.12.2
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 +2 -0
- package/dist/mosaic-sql.js +8 -4
- package/dist/mosaic-sql.min.js +1 -1
- package/dist/types/ast/column-param.d.ts +6 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/transforms/bin-linear-1d.d.ts +2 -1
- package/dist/types/transforms/bin-linear-2d.d.ts +2 -2
- package/package.json +2 -2
- package/src/ast/column-param.js +9 -0
- package/src/index.js +1 -1
- package/src/transforms/bin-linear-1d.js +4 -3
- package/src/transforms/bin-linear-2d.js +2 -2
- package/src/visit/visitors.js +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# mosaic-sql
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@uwdata/mosaic-sql)
|
|
4
|
+
|
|
3
5
|
An API for convenient construction and analysis of SQL queries. Query objects then coerce to SQL query strings.
|
|
4
6
|
|
|
5
7
|
Many `mosaic-sql` utilities are included as part of the [vgplot](https://github.com/uwdata/mosaic/tree/main/packages/vgplot) API.
|
package/dist/mosaic-sql.js
CHANGED
|
@@ -463,6 +463,9 @@ var ColumnNameRefNode = class extends ColumnRefNode {
|
|
|
463
463
|
};
|
|
464
464
|
|
|
465
465
|
// src/ast/column-param.js
|
|
466
|
+
function isColumnParam(value) {
|
|
467
|
+
return value instanceof ColumnParamNode;
|
|
468
|
+
}
|
|
466
469
|
var ColumnParamNode = class extends ColumnRefNode {
|
|
467
470
|
/**
|
|
468
471
|
* Instantiate a column param node.
|
|
@@ -2099,7 +2102,7 @@ function collectAggregates(root) {
|
|
|
2099
2102
|
function collectColumns(root) {
|
|
2100
2103
|
const cols = {};
|
|
2101
2104
|
walk(root, (node) => {
|
|
2102
|
-
if (node.type === COLUMN_REF) {
|
|
2105
|
+
if (node.type === COLUMN_REF || node.type === COLUMN_PARAM) {
|
|
2103
2106
|
cols[node] = node;
|
|
2104
2107
|
}
|
|
2105
2108
|
});
|
|
@@ -2230,21 +2233,21 @@ function bin2d(q, xp, yp, aggs, xn, groupby) {
|
|
|
2230
2233
|
}
|
|
2231
2234
|
|
|
2232
2235
|
// src/transforms/bin-linear-1d.js
|
|
2233
|
-
function binLinear1d(query, x2, weight) {
|
|
2236
|
+
function binLinear1d(query, x2, weight = void 0, groupby = []) {
|
|
2234
2237
|
const w = weight ? (x3) => mul(x3, weight) : (x3) => x3;
|
|
2235
2238
|
const p0 = floor(x2);
|
|
2236
2239
|
const p1 = add(p0, 1);
|
|
2237
2240
|
return Query.from(Query.unionAll(
|
|
2238
2241
|
query.clone().select({ i: int32(p0), w: w(sub(p1, x2)) }),
|
|
2239
2242
|
query.clone().select({ i: int32(p1), w: w(sub(x2, p0)) })
|
|
2240
|
-
)).select({ index: "i", density: sum("w") }).groupby("index").having(neq("density", 0));
|
|
2243
|
+
)).select({ index: "i", density: sum("w") }, groupby).groupby("index", groupby).having(neq("density", 0));
|
|
2241
2244
|
}
|
|
2242
2245
|
|
|
2243
2246
|
// src/transforms/bin-linear-2d.js
|
|
2244
2247
|
function identity(x2) {
|
|
2245
2248
|
return x2;
|
|
2246
2249
|
}
|
|
2247
|
-
function binLinear2d(q, xp, yp, weight, xn, groupby) {
|
|
2250
|
+
function binLinear2d(q, xp, yp, weight, xn, groupby = []) {
|
|
2248
2251
|
const w = weight ? (x2) => mul(x2, weight) : identity;
|
|
2249
2252
|
const subq = (i, w2) => q.clone().select({ xp, yp, i, w: w2 });
|
|
2250
2253
|
const index = (x2, y2) => add(x2, mul(y2, xn));
|
|
@@ -2516,6 +2519,7 @@ export {
|
|
|
2516
2519
|
interval,
|
|
2517
2520
|
isAggregateExpression,
|
|
2518
2521
|
isBetween,
|
|
2522
|
+
isColumnParam,
|
|
2519
2523
|
isColumnRef,
|
|
2520
2524
|
isDescribeQuery,
|
|
2521
2525
|
isDistinct,
|
package/dist/mosaic-sql.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
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};
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a value is a dynamic column reference node.
|
|
3
|
+
* @param {*} value The value to check.
|
|
4
|
+
* @returns {value is ColumnParamNode}
|
|
5
|
+
*/
|
|
6
|
+
export function isColumnParam(value: any): value is ColumnParamNode;
|
|
1
7
|
export class ColumnParamNode extends ColumnRefNode {
|
|
2
8
|
/**
|
|
3
9
|
* Instantiate a column param node.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { AggregateNode } from "./ast/aggregate.js";
|
|
2
2
|
export { BinaryOpNode } from "./ast/binary-op.js";
|
|
3
3
|
export { CastNode } from "./ast/cast.js";
|
|
4
|
-
export { ColumnParamNode } from "./ast/column-param.js";
|
|
5
4
|
export { FragmentNode } from "./ast/fragment.js";
|
|
6
5
|
export { FromClauseNode } from "./ast/from.js";
|
|
7
6
|
export { FunctionNode } from "./ast/function.js";
|
|
@@ -31,6 +30,7 @@ export { scaleTransform } from "./transforms/scales.js";
|
|
|
31
30
|
export { isParamLike } from "./util/type-check.js";
|
|
32
31
|
export { BetweenOpNode, NotBetweenOpNode } from "./ast/between-op.js";
|
|
33
32
|
export { CaseNode, WhenNode } from "./ast/case.js";
|
|
33
|
+
export { ColumnParamNode, isColumnParam } from "./ast/column-param.js";
|
|
34
34
|
export { ColumnRefNode, ColumnNameRefNode, isColumnRef } from "./ast/column-ref.js";
|
|
35
35
|
export { AndNode, OrNode } from "./ast/logical-op.js";
|
|
36
36
|
export { SQLNode, ExprNode, isNode } from "./ast/node.js";
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* @param {import('../ast/query.js').SelectQuery} query The base query to bin.
|
|
4
4
|
* @param {import('../types.js').ExprValue} x The expression to bin.
|
|
5
5
|
* @param {import('../types.js').ExprValue} [weight] The expression to weight by.
|
|
6
|
+
* @param {string[]} [groupby] Group by expressions.
|
|
6
7
|
* @returns {Query}
|
|
7
8
|
*/
|
|
8
|
-
export function binLinear1d(query: import("../ast/query.js").SelectQuery, x: import("../types.js").ExprValue, weight?: import("../types.js").ExprValue): Query;
|
|
9
|
+
export function binLinear1d(query: import("../ast/query.js").SelectQuery, x: import("../types.js").ExprValue, weight?: import("../types.js").ExprValue, groupby?: string[]): Query;
|
|
9
10
|
import { Query } from '../ast/query.js';
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* @param {import('../types.js').ExprValue} yp The y grid bin expression
|
|
11
11
|
* @param {import('../types.js').ExprValue | undefined} weight Point weights.
|
|
12
12
|
* @param {number} xn The number of x grid bins.
|
|
13
|
-
* @param {string[]} groupby Group by expressions.
|
|
13
|
+
* @param {string[]} [groupby] Group by expressions.
|
|
14
14
|
* @returns {SelectQuery} A linear binning query for bin `index` and
|
|
15
15
|
* aggregate `density` columns, in addition to any group by expressions.
|
|
16
16
|
*/
|
|
17
|
-
export function binLinear2d(q: SelectQuery, xp: import("../types.js").ExprValue, yp: import("../types.js").ExprValue, weight: import("../types.js").ExprValue | undefined, xn: number, groupby
|
|
17
|
+
export function binLinear2d(q: SelectQuery, xp: import("../types.js").ExprValue, yp: import("../types.js").ExprValue, weight: import("../types.js").ExprValue | undefined, xn: number, groupby?: string[]): SelectQuery;
|
|
18
18
|
import { SelectQuery } from '../ast/query.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uwdata/mosaic-sql",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "SQL query construction and analysis.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sql",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"test": "vitest run && tsc -p jsconfig.json",
|
|
28
28
|
"prepublishOnly": "npm run test && npm run lint && npm run build"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "0ca741d840b98039255f26a5ceedf10be66f790e"
|
|
31
31
|
}
|
package/src/ast/column-param.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { COLUMN_PARAM } from '../constants.js';
|
|
2
2
|
import { ColumnRefNode } from './column-ref.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Check if a value is a dynamic column reference node.
|
|
6
|
+
* @param {*} value The value to check.
|
|
7
|
+
* @returns {value is ColumnParamNode}
|
|
8
|
+
*/
|
|
9
|
+
export function isColumnParam(value) {
|
|
10
|
+
return value instanceof ColumnParamNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
export class ColumnParamNode extends ColumnRefNode {
|
|
5
14
|
/**
|
|
6
15
|
* Instantiate a column param node.
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { BetweenOpNode, NotBetweenOpNode } from './ast/between-op.js'
|
|
|
3
3
|
export { BinaryOpNode } from './ast/binary-op.js';
|
|
4
4
|
export { CaseNode, WhenNode } from './ast/case.js';
|
|
5
5
|
export { CastNode } from './ast/cast.js';
|
|
6
|
-
export { ColumnParamNode } from './ast/column-param.js';
|
|
6
|
+
export { ColumnParamNode, isColumnParam } from './ast/column-param.js';
|
|
7
7
|
export { ColumnRefNode, ColumnNameRefNode, isColumnRef } from './ast/column-ref.js';
|
|
8
8
|
export { FragmentNode } from './ast/fragment.js';
|
|
9
9
|
export { FromClauseNode } from './ast/from.js';
|
|
@@ -9,9 +9,10 @@ import { add, mul, neq, sub } from '../functions/operators.js';
|
|
|
9
9
|
* @param {import('../ast/query.js').SelectQuery} query The base query to bin.
|
|
10
10
|
* @param {import('../types.js').ExprValue} x The expression to bin.
|
|
11
11
|
* @param {import('../types.js').ExprValue} [weight] The expression to weight by.
|
|
12
|
+
* @param {string[]} [groupby] Group by expressions.
|
|
12
13
|
* @returns {Query}
|
|
13
14
|
*/
|
|
14
|
-
export function binLinear1d(query, x, weight) {
|
|
15
|
+
export function binLinear1d(query, x, weight = undefined, groupby = []) {
|
|
15
16
|
const w = weight ? (x => mul(x, weight)) : (x => x);
|
|
16
17
|
const p0 = floor(x);
|
|
17
18
|
const p1 = add(p0, 1);
|
|
@@ -20,7 +21,7 @@ export function binLinear1d(query, x, weight) {
|
|
|
20
21
|
query.clone().select({ i: int32(p0), w: w(sub(p1, x)) }),
|
|
21
22
|
query.clone().select({ i: int32(p1), w: w(sub(x, p0)) })
|
|
22
23
|
))
|
|
23
|
-
.select({ index: 'i', density: sum('w') })
|
|
24
|
-
.groupby('index')
|
|
24
|
+
.select({ index: 'i', density: sum('w') }, groupby)
|
|
25
|
+
.groupby('index', groupby)
|
|
25
26
|
.having(neq('density', 0));
|
|
26
27
|
}
|
|
@@ -26,11 +26,11 @@ function identity(x) {
|
|
|
26
26
|
* @param {import('../types.js').ExprValue} yp The y grid bin expression
|
|
27
27
|
* @param {import('../types.js').ExprValue | undefined} weight Point weights.
|
|
28
28
|
* @param {number} xn The number of x grid bins.
|
|
29
|
-
* @param {string[]} groupby Group by expressions.
|
|
29
|
+
* @param {string[]} [groupby] Group by expressions.
|
|
30
30
|
* @returns {SelectQuery} A linear binning query for bin `index` and
|
|
31
31
|
* aggregate `density` columns, in addition to any group by expressions.
|
|
32
32
|
*/
|
|
33
|
-
export function binLinear2d(q, xp, yp, weight, xn, groupby) {
|
|
33
|
+
export function binLinear2d(q, xp, yp, weight, xn, groupby = []) {
|
|
34
34
|
|
|
35
35
|
const w = weight ? x => mul(x, weight) : identity;
|
|
36
36
|
|
package/src/visit/visitors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AGGREGATE, COLUMN_REF, FRAGMENT, PARAM, VERBATIM, WINDOW } from '../constants.js';
|
|
1
|
+
import { AGGREGATE, COLUMN_PARAM, COLUMN_REF, FRAGMENT, PARAM, VERBATIM, WINDOW } from '../constants.js';
|
|
2
2
|
import { aggregateNames, AggregateNode } from '../ast/aggregate.js';
|
|
3
3
|
import { ColumnRefNode } from '../ast/column-ref.js';
|
|
4
4
|
import { SQLNode } from '../ast/node.js';
|
|
@@ -82,7 +82,7 @@ export function collectAggregates(root) {
|
|
|
82
82
|
export function collectColumns(root) {
|
|
83
83
|
const cols = {};
|
|
84
84
|
walk(root, (node) => {
|
|
85
|
-
if (node.type === COLUMN_REF) {
|
|
85
|
+
if (node.type === COLUMN_REF || node.type === COLUMN_PARAM) {
|
|
86
86
|
cols[node] = node; // key on string-coerced node
|
|
87
87
|
}
|
|
88
88
|
});
|