@uwdata/mosaic-sql 0.11.0 → 0.12.1
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 +2242 -1064
- package/dist/mosaic-sql.min.js +1 -1
- package/dist/types/ast/aggregate.d.ts +70 -0
- package/dist/types/ast/between-op.d.ts +46 -0
- package/dist/types/ast/binary-op.d.ts +28 -0
- package/dist/types/ast/case.d.ts +68 -0
- package/dist/types/ast/cast.d.ts +21 -0
- package/dist/types/ast/column-param.d.ts +17 -0
- package/dist/types/ast/column-ref.d.ts +39 -0
- package/dist/types/ast/fragment.d.ts +14 -0
- package/dist/types/ast/from.d.ts +21 -0
- package/dist/types/ast/function.d.ts +21 -0
- package/dist/types/ast/in-op.d.ts +21 -0
- package/dist/types/ast/interval.d.ts +21 -0
- package/dist/types/ast/literal.d.ts +15 -0
- package/dist/types/ast/logical-op.d.ts +46 -0
- package/dist/types/ast/node.d.ts +24 -0
- package/dist/types/ast/order-by.d.ts +29 -0
- package/dist/types/ast/param.d.ts +19 -0
- package/dist/types/ast/query.d.ts +268 -0
- package/dist/types/ast/sample.d.ts +42 -0
- package/dist/types/ast/select.d.ts +22 -0
- package/dist/types/ast/table-ref.d.ts +25 -0
- package/dist/types/ast/unary-op.d.ts +39 -0
- package/dist/types/ast/verbatim.d.ts +9 -0
- package/dist/types/ast/window.d.ts +177 -0
- package/dist/types/ast/with.d.ts +22 -0
- package/dist/types/constants.d.ts +38 -0
- package/dist/types/functions/aggregate.d.ts +229 -0
- package/dist/types/functions/case.d.ts +15 -0
- package/dist/types/functions/cast.d.ts +26 -0
- package/dist/types/functions/column.d.ts +9 -0
- package/dist/types/functions/datetime.d.ts +44 -0
- package/dist/types/functions/literal.d.ts +16 -0
- package/dist/types/functions/numeric.d.ts +93 -0
- package/dist/types/functions/operators.d.ts +198 -0
- package/dist/types/functions/order-by.d.ts +17 -0
- package/dist/types/functions/spatial.d.ts +37 -0
- package/dist/types/functions/sql-template-tag.d.ts +16 -0
- package/dist/types/functions/string.d.ts +55 -0
- package/dist/types/functions/table-ref.d.ts +9 -0
- package/dist/types/functions/window.d.ts +87 -0
- package/dist/types/index-types.d.ts +2 -0
- package/dist/types/index.d.ts +53 -0
- package/dist/types/load/create.d.ts +8 -0
- package/dist/types/load/extension.d.ts +1 -0
- package/dist/types/load/load.d.ts +12 -0
- package/dist/types/load/sql-from.d.ts +11 -0
- package/dist/types/transforms/bin-1d.d.ts +14 -0
- package/dist/types/transforms/bin-2d.d.ts +18 -0
- package/dist/types/transforms/bin-linear-1d.d.ts +9 -0
- package/dist/types/transforms/bin-linear-2d.d.ts +18 -0
- package/dist/types/transforms/line-density.d.ts +23 -0
- package/dist/types/transforms/m4.d.ts +18 -0
- package/dist/types/transforms/scales.d.ts +1 -0
- package/dist/types/types.d.ts +59 -0
- package/dist/types/util/ast.d.ts +60 -0
- package/dist/types/util/function.d.ts +54 -0
- package/dist/types/util/string.d.ts +3 -0
- package/dist/types/util/type-check.d.ts +18 -0
- package/dist/types/visit/recurse.d.ts +28 -0
- package/dist/types/visit/rewrite.d.ts +10 -0
- package/dist/types/visit/visitors.d.ts +33 -0
- package/dist/types/visit/walk.d.ts +7 -0
- package/jsconfig.json +11 -0
- package/package.json +6 -4
- package/src/ast/aggregate.js +164 -0
- package/src/ast/between-op.js +75 -0
- package/src/ast/binary-op.js +40 -0
- package/src/ast/case.js +105 -0
- package/src/ast/cast.js +34 -0
- package/src/ast/column-param.js +29 -0
- package/src/ast/column-ref.js +72 -0
- package/src/ast/fragment.js +26 -0
- package/src/ast/from.js +40 -0
- package/src/ast/function.js +34 -0
- package/src/ast/in-op.js +33 -0
- package/src/ast/interval.js +33 -0
- package/src/ast/literal.js +55 -0
- package/src/ast/logical-op.js +67 -0
- package/src/ast/node.js +29 -0
- package/src/ast/order-by.js +48 -0
- package/src/ast/param.js +35 -0
- package/src/ast/query.js +578 -0
- package/src/ast/sample.js +53 -0
- package/src/ast/select.js +44 -0
- package/src/ast/table-ref.js +44 -0
- package/src/ast/unary-op.js +64 -0
- package/src/ast/verbatim.js +26 -0
- package/src/ast/window.js +290 -0
- package/src/ast/with.js +30 -0
- package/src/constants.js +44 -0
- package/src/functions/aggregate.js +335 -0
- package/src/functions/case.js +21 -0
- package/src/functions/cast.js +39 -0
- package/src/functions/column.js +20 -0
- package/src/functions/datetime.js +65 -0
- package/src/functions/literal.js +22 -0
- package/src/functions/numeric.js +139 -0
- package/src/functions/operators.js +298 -0
- package/src/functions/order-by.js +24 -0
- package/src/functions/spatial.js +56 -0
- package/src/functions/sql-template-tag.js +51 -0
- package/src/functions/string.js +82 -0
- package/src/functions/table-ref.js +14 -0
- package/src/functions/window.js +121 -0
- package/src/index-types.ts +2 -0
- package/src/index.js +57 -155
- package/src/load/create.js +10 -2
- package/src/load/load.js +4 -4
- package/src/load/sql-from.js +7 -6
- package/src/transforms/bin-1d.js +21 -0
- package/src/transforms/bin-2d.js +29 -0
- package/src/transforms/bin-linear-1d.js +26 -0
- package/src/transforms/bin-linear-2d.js +71 -0
- package/src/transforms/line-density.js +113 -0
- package/src/transforms/m4.js +38 -0
- package/src/{scales.js → transforms/scales.js} +31 -17
- package/src/types.ts +96 -0
- package/src/util/ast.js +96 -0
- package/src/util/function.js +78 -0
- package/src/util/string.js +16 -0
- package/src/util/type-check.js +29 -0
- package/src/visit/recurse.js +57 -0
- package/src/visit/rewrite.js +32 -0
- package/src/visit/visitors.js +108 -0
- package/src/visit/walk.js +30 -0
- package/tsconfig.json +12 -0
- package/src/Query.js +0 -593
- package/src/aggregates.js +0 -185
- package/src/cast.js +0 -19
- package/src/datetime.js +0 -31
- package/src/desc.js +0 -13
- package/src/expression.js +0 -170
- package/src/functions.js +0 -25
- package/src/literal.js +0 -6
- package/src/operators.js +0 -54
- package/src/ref.js +0 -109
- package/src/repeat.js +0 -3
- package/src/spatial.js +0 -10
- package/src/to-sql.js +0 -52
- package/src/windows.js +0 -239
package/dist/mosaic-sql.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var S=class{constructor(t,e){t&&(this.table=String(t)),e&&(this.column=e)}get columns(){return this.column?[this.column]:[]}toString(){let{table:t,column:e}=this;if(e){let n=e.startsWith("*")?e:`"${e}"`;return`${t?`${V(t)}.`:""}${n}`}else return t?V(t):"NULL"}};function V(r){return r.split(".").map(e=>`"${e}"`).join(".")}function k(r,t){return r instanceof S&&r.column===t}function u(r){return typeof r=="string"?K(r):r}function O(r){return typeof r=="string"?H(r):r}function H(r){return new S(r)}function K(r,t=null){return arguments.length===1&&(t=r,r=null),new S(r,t)}function lt(r){return new S(r,"*")}function pt(r){return typeof r=="string"?`"${r}"`:$(r)}function $(r){switch(typeof r){case"boolean":return r?"TRUE":"FALSE";case"string":return`'${r.replace("'","''")}'`;case"number":return Number.isFinite(r)?String(r):"NULL";default:if(r==null)return"NULL";if(r instanceof Date){let t=+r;if(Number.isNaN(t))return"NULL";let e=r.getUTCFullYear(),n=r.getUTCMonth(),o=r.getUTCDate();return t===Date.UTC(e,n,o)?`MAKE_DATE(${e}, ${n+1}, ${o})`:`EPOCH_MS(${t})`}else return r instanceof RegExp?`'${r.source}'`:String(r)}}var T=r=>typeof r?.addEventListener=="function";function _(r){return r instanceof N}var N=class{constructor(t,e,n){this._expr=Array.isArray(t)?t:[t],this._deps=e||[],this.annotate(n);let o=this._expr.filter(s=>T(s));o.length>0?(this._params=Array.from(new Set(o)),this._params.forEach(s=>{s.addEventListener("value",()=>ft(this,this.map?.get("value")))})):this.addEventListener=void 0}get value(){return this}get columns(){let{_params:t,_deps:e}=this;if(t){let n=new Set(t.flatMap(o=>{let s=o.value?.columns;return Array.isArray(s)?s:[]}));if(n.size){let o=new Set(e);return n.forEach(s=>o.add(s)),Array.from(o)}}return e}get column(){return this._deps.length?this._deps[0]:this.columns[0]}annotate(...t){return Object.assign(this,...t)}toString(){return this._expr.map(t=>T(t)&&!_(t)?$(t.value):t).join("")}addEventListener(t,e){let n=this.map||(this.map=new Map);(n.get(t)||(n.set(t,new Set),n.get(t))).add(e)}};function ft(r,t){if(t?.size)return Promise.allSettled(Array.from(t,e=>e(r)))}function W(r,t){let e=[r[0]],n=new Set,o=t.length;for(let s=0,i=0;s<o;){let a=t[s];T(a)?e[++i]=a:(Array.isArray(a?.columns)&&a.columns.forEach(d=>n.add(d)),e[i]+=typeof a=="string"?a:$(a));let p=r[++s];T(e[i])?e[++i]=p:e[i]+=p}return{spans:e,cols:Array.from(n)}}function c(r,...t){let{spans:e,cols:n}=W(r,t);return new N(e,n)}function ht(r){let t=u(r);return c`${t} DESC NULLS LAST`.annotate({label:t?.label,desc:!0})}var mt=r=>({value:r,toString:()=>$(r)});function D(r){r(this.op,this),this.children?.forEach(t=>t.visit(r))}function z(r,t){let e=t.filter(o=>o!=null).map(u),n=e.map((o,s)=>s?` ${r} `:"");return e.length===1?n.push(""):e.length>1&&(n[0]="(",n.push(")")),c(n,...e).annotate({op:r,children:e,visit:D})}var gt=(...r)=>z("AND",r.flat()),dt=(...r)=>z("OR",r.flat()),xt=r=>t=>c`(${r} ${u(t)})`.annotate({op:r,a:t,visit:D}),$t=xt("NOT"),J=r=>t=>c`(${u(t)} ${r})`.annotate({op:r,a:t,visit:D}),Et=J("IS NULL"),yt=J("IS NOT NULL"),w=r=>(t,e)=>c`(${u(t)} ${r} ${u(e)})`.annotate({op:r,a:t,b:e,visit:D}),St=w("="),Nt=w("<>"),wt=w("<"),At=w(">"),Tt=w("<="),Rt=w(">="),qt=w("IS DISTINCT FROM"),bt=w("IS NOT DISTINCT FROM");function Z(r,t,e,n){t=u(t);let o=r.startsWith("NOT ")?"NOT ":"";return(e?n?c`${o}(${e[0]} <= ${t} AND ${t} < ${e[1]})`:c`(${t} ${r} ${e[0]} AND ${e[1]})`:c``).annotate({op:r,visit:D,field:t,range:e})}var It=(r,t,e)=>Z("BETWEEN",r,t,e),Lt=(r,t,e)=>Z("NOT BETWEEN",r,t,e);function R(r,t){return Array.from({length:r},()=>t)}function m(r,t){return(...e)=>{let n=e.map(u),o=t?`::${t}`:"";return(n.length?c([`${r}(`,...R(n.length-1,", "),`)${o}`],...n):c`${r}()${o}`).annotate({func:r,args:n})}}var Ot=m("REGEXP_MATCHES"),Dt=m("CONTAINS"),Ct=m("PREFIX"),Mt=m("SUFFIX"),_t=m("LOWER"),Pt=m("UPPER"),Ft=m("LENGTH"),Gt=m("ISNAN"),Ut=m("ISFINITE"),jt=m("ISINF");var C=class r extends N{constructor(t,e,n,o,s="",i="",a=""){let p;if(o&&!(s||i||a))p=o?c`${e} OVER "${o}"`:c`${e} OVER ()`;else{let b=s&&i?" ":"",I=(s||i)&&a?" ":"";p=c`${e} OVER (${o?`"${o}" `:""}${s}${b}${i}${I}${a})`}n&&(p=c`(${p})::${n}`);let{_expr:y,_deps:A}=p;super(y,A),this.window=t,this.func=e,this.type=n,this.name=o,this.group=s,this.order=i,this.frame=a}get basis(){return this.column}get label(){let{func:t}=this;return t.label??t.toString()}over(t){let{window:e,func:n,type:o,group:s,order:i,frame:a}=this;return new r(e,n,o,t,s,i,a)}partitionby(...t){let e=t.flat().filter(y=>y).map(u),n=c(["PARTITION BY ",R(e.length-1,", "),""],...e),{window:o,func:s,type:i,name:a,order:p,frame:d}=this;return new r(o,s,i,a,n,p,d)}orderby(...t){let e=t.flat().filter(y=>y).map(u),n=c(["ORDER BY ",R(e.length-1,", "),""],...e),{window:o,func:s,type:i,name:a,group:p,frame:d}=this;return new r(o,s,i,a,p,n,d)}rows(t){let e=tt("ROWS",t),{window:n,func:o,type:s,name:i,group:a,order:p}=this;return new r(n,o,s,i,a,p,e)}range(t){let e=tt("RANGE",t),{window:n,func:o,type:s,name:i,group:a,order:p}=this;return new r(n,o,s,i,a,p,e)}};function tt(r,t){if(T(t)){let e=c`${t}`;return e.toString=()=>`${r} ${et(t.value)}`,e}return`${r} ${et(t)}`}function et(r){let[t,e]=r,n=t===0?"CURRENT ROW":Number.isFinite(t)?`${Math.abs(t)} PRECEDING`:"UNBOUNDED PRECEDING",o=e===0?"CURRENT ROW":Number.isFinite(e)?`${Math.abs(e)} FOLLOWING`:"UNBOUNDED FOLLOWING";return`BETWEEN ${n} AND ${o}`}function E(r,t){return(...e)=>{let n=m(r)(...e);return new C(r,n,t)}}var Wt=E("ROW_NUMBER","INTEGER"),Bt=E("RANK","INTEGER"),Yt=E("DENSE_RANK","INTEGER"),vt=E("PERCENT_RANK"),Qt=E("CUME_DIST"),Xt=E("NTILE"),Vt=E("LAG"),kt=E("LEAD"),Ht=E("FIRST_VALUE"),Kt=E("LAST_VALUE"),zt=E("NTH_VALUE");function Jt(r,...t){return c(r,...t).annotate({aggregate:!0})}var B=class r extends N{constructor(t,e,n,o,s){e=(e||[]).map(u);let{strings:i,exprs:a}=Zt(t,e,n,o,s),{spans:p,cols:d}=W(i,a);super(p,d),this.aggregate=t,this.args=e,this.type=n,this.isDistinct=o,this.filter=s}get basis(){return this.column}get label(){let{aggregate:t,args:e,isDistinct:n}=this,o=n?"DISTINCT"+(e.length?" ":""):"",s=e.length?`(${o}${e.map(te).join(", ")})`:"";return`${t.toLowerCase()}${s}`}distinct(){let{aggregate:t,args:e,type:n,filter:o}=this;return new r(t,e,n,!0,o)}where(t){let{aggregate:e,args:n,type:o,isDistinct:s}=this;return new r(e,n,o,s,t)}window(){let{aggregate:t,args:e,type:n,isDistinct:o}=this,s=new r(t,e,null,o);return new C(t,s,n)}partitionby(...t){return this.window().partitionby(...t)}orderby(...t){return this.window().orderby(...t)}rows(t){return this.window().rows(t)}range(t){return this.window().range(t)}};function Zt(r,t,e,n,o){let s=`)${e?`::${e}`:""}`,i=[`${r}(${n?"DISTINCT ":""}`],a=[];return t.length?(i=i.concat([...R(t.length-1,", "),`${s}${o?" FILTER (WHERE ":""}`,...o?[")"]:[]]),a=[...t,...o?[o]:[]]):i[0]+="*"+s,{exprs:a,strings:i}}function te(r){let t=$(r);return t&&t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function l(r,t){return(...e)=>new B(r,e,t)}var ee=l("COUNT","INTEGER"),re=l("AVG"),ne=l("AVG"),oe=l("MAD"),se=l("MAX"),ie=l("MIN"),ce=l("SUM","DOUBLE"),ae=l("PRODUCT"),ue=l("MEDIAN"),le=l("QUANTILE"),pe=l("MODE"),fe=l("VARIANCE"),he=l("STDDEV"),me=l("SKEWNESS"),ge=l("KURTOSIS"),de=l("ENTROPY"),xe=l("VAR_POP"),$e=l("STDDEV_POP"),Ee=l("CORR"),ye=l("COVAR_SAMP"),Se=l("COVAR_POP"),Ne=l("REGR_INTERCEPT"),we=l("REGR_SLOPE"),Ae=l("REGR_COUNT"),Te=l("REGR_R2"),Re=l("REGR_SYY"),qe=l("REGR_SXX"),be=l("REGR_SXY"),Ie=l("REGR_AVGX"),Le=l("REGR_AVGY"),Oe=l("FIRST"),De=l("LAST"),Ce=l("ARG_MIN"),Me=l("ARG_MAX"),_e=l("STRING_AGG"),Pe=l("ARRAY_AGG");function Y(r,t){let e=u(r),n=c`CAST(${e} AS ${t})`;return Object.defineProperty(n,"label",{enumerable:!0,get(){return r.label}}),Object.defineProperty(n,"aggregate",{enumerable:!0,get(){return r.aggregate||!1}}),n}var Fe=r=>Y(r,"DOUBLE"),Ge=r=>Y(r,"INTEGER");var v=r=>c`epoch_ms(${u(r)})`;function Ue(r,t,e=1){let n=`INTERVAL ${e} ${t}`,o=u(r);return c`TIME_BUCKET(${n}, ${o})`.annotate({label:t})}var je=r=>{let t=u(r);return c`MAKE_DATE(2012, MONTH(${t}), 1)`.annotate({label:"month"})},We=r=>{let t=u(r);return c`MAKE_DATE(2012, MONTH(${t}), DAY(${t}))`.annotate({label:"date"})},Be=r=>{let t=u(r);return c`MAKE_DATE(2012, 1, DAY(${t}))`.annotate({label:"date"})};var Ye=m("ST_AsGeoJSON"),rt=m("ST_X"),nt=m("ST_Y"),Q=m("ST_CENTROID"),ve=r=>rt(Q(r)),Qe=r=>nt(Q(r));var F=class r{static select(...t){return new r().select(...t)}static from(...t){return new r().from(...t)}static with(...t){return new r().with(...t)}static union(...t){return new q("UNION",t.flat())}static unionAll(...t){return new q("UNION ALL",t.flat())}static intersect(...t){return new q("INTERSECT",t.flat())}static except(...t){return new q("EXCEPT",t.flat())}static describe(t){let e=t.clone(),{clone:n,toString:o}=e;return Object.assign(e,{describe:!0,clone:()=>r.describe(n.call(e)),toString:()=>`DESCRIBE ${o.call(e)}`})}constructor(){this.query={with:[],select:[],from:[],where:[],groupby:[],having:[],window:[],qualify:[],orderby:[]},this.cteFor=null}clone(){let t=new r;return t.query={...this.query},t}with(...t){let{query:e}=this;if(t.length===0)return e.with;{let n=[],o=(s,i)=>{let a=i.clone();a.cteFor=this,n.push({as:s,query:a})};return t.flat().forEach(s=>{if(s!=null)if(s.as&&s.query)o(s.as,s.query);else for(let i in s)o(i,s[i])}),e.with=e.with.concat(n),this}}select(...t){let{query:e}=this;if(t.length===0)return e.select;{let n=[];for(let s of t.flat())if(s!=null)if(typeof s=="string")n.push({as:s,expr:u(s)});else if(s instanceof S)n.push({as:s.column,expr:s});else if(Array.isArray(s))n.push({as:s[0],expr:s[1]});else for(let i in s)n.push({as:P(i),expr:u(s[i])});let o=new Set(n.map(s=>s.as));return e.select=e.select.filter(s=>!o.has(s.as)).concat(n.filter(s=>s.expr)),this}}$select(...t){return this.query.select=[],this.select(...t)}distinct(t=!0){return this.query.distinct=!!t,this}from(...t){let{query:e}=this;if(t.length===0)return e.from;{let n=[];return t.flat().forEach(o=>{if(o!=null)if(typeof o=="string")n.push({as:o,from:O(o)});else if(o instanceof S)n.push({as:o.table,from:o});else if(M(o)||_(o))n.push({from:o});else if(Array.isArray(o))n.push({as:P(o[0]),from:O(o[1])});else for(let s in o)n.push({as:P(s),from:O(o[s])})}),e.from=e.from.concat(n),this}}$from(...t){return this.query.from=[],this.from(...t)}sample(t,e){let{query:n}=this;if(arguments.length===0)return n.sample;{let o=t;return typeof t=="number"&&(o=t>0&&t<1?{perc:100*t,method:e}:{rows:Math.round(t),method:e}),n.sample=o,this}}where(...t){let{query:e}=this;return t.length===0?e.where:(e.where=e.where.concat(t.flat().filter(n=>n)),this)}$where(...t){return this.query.where=[],this.where(...t)}groupby(...t){let{query:e}=this;return t.length===0?e.groupby:(e.groupby=e.groupby.concat(t.flat().filter(n=>n).map(u)),this)}$groupby(...t){return this.query.groupby=[],this.groupby(...t)}having(...t){let{query:e}=this;return t.length===0?e.having:(e.having=e.having.concat(t.flat().filter(n=>n)),this)}window(...t){let{query:e}=this;if(t.length===0)return e.window;{let n=[];return t.flat().forEach(o=>{if(o!=null)for(let s in o)n.push({as:P(s),expr:o[s]})}),e.window=e.window.concat(n),this}}qualify(...t){let{query:e}=this;return t.length===0?e.qualify:(e.qualify=e.qualify.concat(t.flat().filter(n=>n)),this)}orderby(...t){let{query:e}=this;return t.length===0?e.orderby:(e.orderby=e.orderby.concat(t.flat().filter(n=>n).map(u)),this)}limit(t){let{query:e}=this;return arguments.length===0?e.limit:(e.limit=Number.isFinite(t)?t:void 0,this)}offset(t){let{query:e}=this;return arguments.length===0?e.offset:(e.offset=Number.isFinite(t)?t:void 0,this)}get subqueries(){let{query:t,cteFor:e}=this,o=(e?.query||t).with?.reduce((i,{as:a,query:p})=>(i[a]=p,i),{}),s=[];return t.from.forEach(({from:i})=>{if(M(i))s.push(i);else if(o[i.table]){let a=o[i.table];s.push(a)}}),s}toString(){let{with:t,select:e,distinct:n,from:o,sample:s,where:i,groupby:a,having:p,window:d,qualify:y,orderby:A,limit:b,offset:I}=this.query,g=[];if(t.length){let f=t.map(({as:h,query:x})=>`"${h}" AS (${x})`);g.push(`WITH ${f.join(", ")}`)}let ct=e.map(({as:f,expr:h})=>k(h,f)&&!h.table?`${h}`:`${h} AS "${f}"`);if(g.push(`SELECT${n?" DISTINCT":""} ${ct.join(", ")}`),o.length){let f=o.map(({as:h,from:x})=>{let L=M(x)?`(${x})`:`${x}`;return!h||h===x.table?L:`${L} AS "${h}"`});g.push(`FROM ${f.join(", ")}`)}if(i.length){let f=i.map(String).filter(h=>h).join(" AND ");f&&g.push(`WHERE ${f}`)}if(s){let{rows:f,perc:h,method:x,seed:L}=s,at=f?`${f} ROWS`:`${h} PERCENT`,ut=x?` (${x}${L!=null?`, ${L}`:""})`:"";g.push(`USING SAMPLE ${at}${ut}`)}if(a.length&&g.push(`GROUP BY ${a.join(", ")}`),p.length){let f=p.map(String).filter(h=>h).join(" AND ");f&&g.push(`HAVING ${f}`)}if(d.length){let f=d.map(({as:h,expr:x})=>`"${h}" AS (${x})`);g.push(`WINDOW ${f.join(", ")}`)}if(y.length){let f=y.map(String).filter(h=>h).join(" AND ");f&&g.push(`QUALIFY ${f}`)}return A.length&&g.push(`ORDER BY ${A.join(", ")}`),Number.isFinite(b)&&g.push(`LIMIT ${b}`),Number.isFinite(I)&&g.push(`OFFSET ${I}`),g.join(" ")}},q=class r{constructor(t,e){this.op=t,this.queries=e.map(n=>n.clone()),this.query={orderby:[]},this.cteFor=null}clone(){let t=new r(this.op,this.queries);return t.query={...this.query},t}orderby(...t){let{query:e}=this;return t.length===0?e.orderby:(e.orderby=e.orderby.concat(t.flat().filter(n=>n).map(u)),this)}limit(t){let{query:e}=this;return arguments.length===0?e.limit:(e.limit=Number.isFinite(t)?t:void 0,this)}offset(t){let{query:e}=this;return arguments.length===0?e.offset:(e.offset=Number.isFinite(t)?t:void 0,this)}get subqueries(){let{queries:t,cteFor:e}=this;return e&&t.forEach(n=>n.cteFor=e),t}toString(){let{op:t,queries:e,query:{orderby:n,limit:o,offset:s}}=this,i=[e.join(` ${t} `)];return n.length&&i.push(`ORDER BY ${n.join(", ")}`),Number.isFinite(o)&&i.push(`LIMIT ${o}`),Number.isFinite(s)&&i.push(`OFFSET ${s}`),i.join(" ")}};function M(r){return r instanceof F||r instanceof q}function Xe(r){return M(r)&&r.describe}function P(r){return Ve(r)?r.slice(1,-1):r}function Ve(r){return r[0]==='"'&&r[r.length-1]==='"'}var G=r=>r;function ot(){return{apply:G,invert:G,sqlApply:u,sqlInvert:G}}function ke({base:r=null}={}){if(r==null||r===Math.E)return{apply:Math.log,invert:Math.exp,sqlApply:t=>c`LN(${u(t)})`,sqlInvert:t=>c`EXP(${t})`};if(r===10)return{apply:Math.log10,invert:t=>Math.pow(10,t),sqlApply:t=>c`LOG(${u(t)})`,sqlInvert:t=>c`POW(10, ${t})`};{let t=+r;return{apply:e=>Math.log(e)/Math.log(t),invert:e=>Math.pow(t,e),sqlApply:e=>c`LN(${u(e)}) / LN(${t})`,sqlInvert:e=>c`POW(${t}, ${e})`}}}function He({constant:r=1}={}){let t=+r;return{apply:e=>Math.sign(e)*Math.log1p(Math.abs(e)),invert:e=>Math.sign(e)*Math.exp(Math.abs(e)-t),sqlApply:e=>(e=u(e),c`SIGN(${e}) * LN(${t} + ABS(${e}))`),sqlInvert:e=>c`SIGN(${e}) * (EXP(ABS(${e})) - ${t})`}}function Ke(){return{apply:r=>Math.sign(r)*Math.sqrt(Math.abs(r)),invert:r=>Math.sign(r)*r*r,sqlApply:r=>(r=u(r),c`SIGN(${r}) * SQRT(ABS(${r}))`),sqlInvert:r=>c`SIGN(${r}) * (${r}) ** 2`}}function ze({exponent:r=1}={}){let t=+r;return{apply:e=>Math.sign(e)*Math.pow(Math.abs(e),t),invert:e=>Math.sign(e)*Math.pow(Math.abs(e),1/t),sqlApply:e=>(e=u(e),c`SIGN(${e}) * POW(ABS(${e}), ${t})`),sqlInvert:e=>c`SIGN(${e}) * POW(ABS(${e}), 1/${t})`}}function st(){return{apply:r=>+r,invert:r=>new Date(r),sqlApply:r=>r instanceof Date?+r:v(u(r)),sqlInvert:G}}var Je={identity:ot,linear:ot,log:ke,symlog:He,sqrt:Ke,pow:ze,time:st,utc:st};function Ze(r){let t=Je[r.type];return t?{...r,...t(r)}:null}function U(r,t,{replace:e=!1,temp:n=!0,view:o=!1}={}){return"CREATE"+(e?" OR REPLACE ":" ")+(n?"TEMP ":"")+(o?"VIEW":"TABLE")+(e?" ":" IF NOT EXISTS ")+r+" AS "+t}function tr(r){return`INSTALL ${r}; LOAD ${r}`}function it(r,{columns:t=Object.keys(r?.[0]||{})}={}){let e=[];if(Array.isArray(t)?(e=t,t=e.reduce((o,s)=>(o[s]=s,o),{})):t&&(e=Object.keys(t)),!e.length)throw new Error("Can not create table from empty column set.");let n=[];for(let o of r){let s=e.map(i=>`${$(o[i])} AS "${t[i]}"`);n.push(`(SELECT ${s.join(", ")})`)}return n.join(" UNION ALL ")}function j(r,t,e,n={},o={}){let{select:s=["*"],where:i,view:a,temp:p,replace:d,...y}=n,A=ir({...o,...y}),b=`${r}('${e}'${A?", "+A:""})`,I=i?` WHERE ${i}`:"",g=`SELECT ${s.join(", ")} FROM ${b}${I}`;return U(t,g,{view:a,temp:p,replace:d})}function er(r,t,e){return j("read_csv",r,t,e,{auto_detect:!0,sample_size:-1})}function rr(r,t,e){return j("read_json",r,t,e,{auto_detect:!0,json_format:"auto"})}function nr(r,t,e){return j("read_parquet",r,t,e)}function or(r,t,e={}){let{options:n,...o}=e;if(n){let s=Array.isArray(n)?n.join(", "):typeof n=="string"?n:Object.entries(n).map(([i,a])=>`${i}=${a}`).join(", ");Object.assign(o,{open_options:s.toUpperCase()})}return j("st_read",r,t,o)}function sr(r,t,e={}){let{select:n=["*"],...o}=e,s=it(t),i=n.length===1&&n[0]==="*"?s:`SELECT ${n} FROM ${s}`;return U(r,i,o)}function ir(r){return Object.entries(r).map(([t,e])=>`${t}=${X(e)}`).join(", ")}function X(r){switch(typeof r){case"boolean":return String(r);case"string":return`'${r}'`;case"undefined":case"object":return r==null?"NULL":Array.isArray(r)?"["+r.map(t=>X(t)).join(", ")+"]":"{"+Object.entries(r).map(([t,e])=>`'${t}': ${X(e)}`).join(", ")+"}";default:return r}}export{F as Query,S as Ref,N as SQLExpression,Jt as agg,lt as all,gt as and,Me as argmax,Ce as argmin,Pe as arrayAgg,u as asColumn,O as asRelation,re as avg,Y as cast,Fe as castDouble,Ge as castInteger,Q as centroid,ve as centroidX,Qe as centroidY,K as column,Dt as contains,Ee as corr,ee as count,Se as covarPop,ye as covariance,U as create,Qt as cume_dist,Ue as dateBin,Be as dateDay,je as dateMonth,We as dateMonthDay,Yt as dense_rank,ht as desc,de as entropy,v as epoch_ms,St as eq,Oe as first,Ht as first_value,Ye as geojson,At as gt,Rt as gte,It as isBetween,Xe as isDescribeQuery,qt as isDistinct,Ut as isFinite,jt as isInfinite,Gt as isNaN,Lt as isNotBetween,bt as isNotDistinct,yt as isNotNull,Et as isNull,T as isParamLike,M as isQuery,_ as isSQLExpression,ge as kurtosis,Vt as lag,De as last,Kt as last_value,kt as lead,Ft as length,mt as literal,$ as literalToSQL,er as loadCSV,tr as loadExtension,rr as loadJSON,sr as loadObjects,nr as loadParquet,or as loadSpatial,_t as lower,wt as lt,Tt as lte,oe as mad,se as max,ne as mean,ue as median,ie as min,pe as mode,Nt as neq,$t as not,zt as nth_value,Xt as ntile,dt as or,vt as percent_rank,Ct as prefix,ae as product,le as quantile,Bt as rank,Ot as regexp_matches,Ie as regrAvgX,Le as regrAvgY,Ae as regrCount,Ne as regrIntercept,Te as regrR2,qe as regrSXX,be as regrSXY,Re as regrSYY,we as regrSlope,H as relation,Wt as row_number,Ze as scaleTransform,me as skewness,c as sql,he as stddev,$e as stddevPop,_e as stringAgg,Mt as suffix,ce as sum,pt as toSQL,Pt as upper,xe as varPop,fe as variance,rt as x,nt as y};
|
|
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};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export class AggregateNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate an aggregate function node.
|
|
4
|
+
* @param {string} name The aggregate function name.
|
|
5
|
+
* @param {ExprNode[]} args The aggregate function arguments.
|
|
6
|
+
* @param {boolean} [distinct] The distinct flag.
|
|
7
|
+
* @param {ExprNode} [filter] Filter expression.
|
|
8
|
+
*/
|
|
9
|
+
constructor(name: string, args: ExprNode[], distinct?: boolean, filter?: ExprNode);
|
|
10
|
+
/**
|
|
11
|
+
* The aggregate function name.
|
|
12
|
+
* @type {string}
|
|
13
|
+
* @readonly
|
|
14
|
+
*/
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/**
|
|
17
|
+
* The aggregate function arguments.
|
|
18
|
+
* @type {ExprNode[]}
|
|
19
|
+
* @readonly
|
|
20
|
+
*/
|
|
21
|
+
readonly args: ExprNode[];
|
|
22
|
+
/**
|
|
23
|
+
* The distinct flag.
|
|
24
|
+
* @type {boolean}
|
|
25
|
+
* @readonly
|
|
26
|
+
*/
|
|
27
|
+
readonly isDistinct: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Filter criteria.
|
|
30
|
+
* @type {ExprNode}
|
|
31
|
+
* @readonly
|
|
32
|
+
*/
|
|
33
|
+
readonly filter: ExprNode;
|
|
34
|
+
/**
|
|
35
|
+
* Return a new derived aggregate over distinct values.
|
|
36
|
+
* @param {boolean} [isDistinct=true] The distinct flag.
|
|
37
|
+
* @returns {AggregateNode} A new aggregate node.
|
|
38
|
+
*/
|
|
39
|
+
distinct(isDistinct?: boolean): AggregateNode;
|
|
40
|
+
/**
|
|
41
|
+
* Return a new derived aggregate function that filters values.
|
|
42
|
+
* @param {ExprNode | string} filter The filter expression.
|
|
43
|
+
* @returns {AggregateNode} A new aggregate node.
|
|
44
|
+
*/
|
|
45
|
+
where(filter: ExprNode | string): AggregateNode;
|
|
46
|
+
/**
|
|
47
|
+
* Return a new window function over this aggregate.
|
|
48
|
+
* @returns {WindowNode} A new window node.
|
|
49
|
+
*/
|
|
50
|
+
window(): WindowNode;
|
|
51
|
+
/**
|
|
52
|
+
* Return a new window function over this aggregate with the given partitions.
|
|
53
|
+
* @param {...import('../types.js').ExprVarArgs} expr The partition by criteria.
|
|
54
|
+
* @returns {WindowNode} A new window node.
|
|
55
|
+
*/
|
|
56
|
+
partitionby(...expr: import("../types.js").ExprVarArgs[]): WindowNode;
|
|
57
|
+
/**
|
|
58
|
+
* Return a new window function over this aggregate with the given ordering.
|
|
59
|
+
* @param {...import('../types.js').ExprVarArgs} expr The order by criteria.
|
|
60
|
+
* @returns {WindowNode} A new window node.
|
|
61
|
+
*/
|
|
62
|
+
orderby(...expr: import("../types.js").ExprVarArgs[]): WindowNode;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* An array of known aggregate function names.
|
|
66
|
+
* From https://duckdb.org/docs/sql/functions/aggregates.html.
|
|
67
|
+
*/
|
|
68
|
+
export const aggregateNames: string[];
|
|
69
|
+
import { ExprNode } from './node.js';
|
|
70
|
+
import { WindowNode } from './window.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class BetweenOpNode extends AbstractBetweenOpNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate a between operator node.
|
|
4
|
+
* @param {ExprNode} expr The input expression.
|
|
5
|
+
* @param {[ExprNode, ExprNode]} extent
|
|
6
|
+
* The range extent.
|
|
7
|
+
*/
|
|
8
|
+
constructor(expr: ExprNode, extent: [ExprNode, ExprNode]);
|
|
9
|
+
}
|
|
10
|
+
export class NotBetweenOpNode extends AbstractBetweenOpNode {
|
|
11
|
+
/**
|
|
12
|
+
* Instantiate a not between operator node.
|
|
13
|
+
* @param {ExprNode} expr The input expression.
|
|
14
|
+
* @param {[ExprNode, ExprNode]} extent
|
|
15
|
+
* The range extent.
|
|
16
|
+
*/
|
|
17
|
+
constructor(expr: ExprNode, extent: [ExprNode, ExprNode]);
|
|
18
|
+
}
|
|
19
|
+
declare class AbstractBetweenOpNode extends ExprNode {
|
|
20
|
+
/**
|
|
21
|
+
* Instantiate an abstract between operator node.
|
|
22
|
+
* @param {string} type The node type.
|
|
23
|
+
* @param {ExprNode} expr The input expression.
|
|
24
|
+
* @param {[ExprNode, ExprNode]} extent The range extent.
|
|
25
|
+
*/
|
|
26
|
+
constructor(type: string, expr: ExprNode, extent: [ExprNode, ExprNode]);
|
|
27
|
+
/**
|
|
28
|
+
* The input expression.
|
|
29
|
+
* @type {ExprNode}
|
|
30
|
+
* @readonly
|
|
31
|
+
*/
|
|
32
|
+
readonly expr: ExprNode;
|
|
33
|
+
/**
|
|
34
|
+
* The range extent.
|
|
35
|
+
* @type {[ExprNode, ExprNode]}
|
|
36
|
+
* @readonly
|
|
37
|
+
*/
|
|
38
|
+
readonly extent: [ExprNode, ExprNode];
|
|
39
|
+
/**
|
|
40
|
+
* Generate a SQL query string for this node.
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
toSQL(op: any): string;
|
|
44
|
+
}
|
|
45
|
+
import { ExprNode } from './node.js';
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class BinaryOpNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate a binary operator node.
|
|
4
|
+
* @param {string} op The operator type.
|
|
5
|
+
* @param {ExprNode} left The left input expression.
|
|
6
|
+
* @param {ExprNode} right The right input expression.
|
|
7
|
+
*/
|
|
8
|
+
constructor(op: string, left: ExprNode, right: ExprNode);
|
|
9
|
+
/**
|
|
10
|
+
* The operator type.
|
|
11
|
+
* @type {string}
|
|
12
|
+
* @readonly
|
|
13
|
+
*/
|
|
14
|
+
readonly op: string;
|
|
15
|
+
/**
|
|
16
|
+
* The left input expression.
|
|
17
|
+
* @type {ExprNode}
|
|
18
|
+
* @readonly
|
|
19
|
+
*/
|
|
20
|
+
readonly left: ExprNode;
|
|
21
|
+
/**
|
|
22
|
+
* The right input expression.
|
|
23
|
+
* @type {ExprNode}
|
|
24
|
+
* @readonly
|
|
25
|
+
*/
|
|
26
|
+
readonly right: ExprNode;
|
|
27
|
+
}
|
|
28
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export class CaseNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate a case node.
|
|
4
|
+
* @param {ExprNode} [expr] An optional base expression, that comes
|
|
5
|
+
* immediately after the CASE keyword. If specified, this case statement
|
|
6
|
+
* acts like a switch statement, with WHEN expressions as values to
|
|
7
|
+
* match against the switch value rather than boolean conditions.
|
|
8
|
+
* @param {WhenNode[]} [when] An array of WHEN/THEN expression nodes.
|
|
9
|
+
* @param {ExprNode} [elseExpr] An ELSE expression.
|
|
10
|
+
*/
|
|
11
|
+
constructor(expr?: ExprNode, when?: WhenNode[], elseExpr?: ExprNode);
|
|
12
|
+
/**
|
|
13
|
+
* The optional base expression.
|
|
14
|
+
* @type {ExprNode}
|
|
15
|
+
* @readonly
|
|
16
|
+
*/
|
|
17
|
+
readonly expr: ExprNode;
|
|
18
|
+
/**
|
|
19
|
+
* An array of WHEN/THEN expression nodes.
|
|
20
|
+
* @type {WhenNode[]}
|
|
21
|
+
* @readonly
|
|
22
|
+
*/
|
|
23
|
+
readonly _when: WhenNode[];
|
|
24
|
+
/**
|
|
25
|
+
* An ELSE expression.
|
|
26
|
+
* @type {ExprNode}
|
|
27
|
+
* @readonly
|
|
28
|
+
*/
|
|
29
|
+
readonly _else: ExprNode;
|
|
30
|
+
/**
|
|
31
|
+
* Return a new case node with the given conditional added as
|
|
32
|
+
* the last WHEN / THEN pair.
|
|
33
|
+
* @param {import('../types.js').ExprValue} cond
|
|
34
|
+
* The WHEN condition expression.
|
|
35
|
+
* @param {import('../types.js').ExprValue} value
|
|
36
|
+
* The THEN value expression.
|
|
37
|
+
* @returns {CaseNode}
|
|
38
|
+
*/
|
|
39
|
+
when(cond: import("../types.js").ExprValue, value: import("../types.js").ExprValue): CaseNode;
|
|
40
|
+
/**
|
|
41
|
+
* Return a new case node with the given ELSE expression.
|
|
42
|
+
* @param {import('../types.js').ExprValue} expr The ELSE expression.
|
|
43
|
+
* @returns {CaseNode}
|
|
44
|
+
*/
|
|
45
|
+
else(expr: import("../types.js").ExprValue): CaseNode;
|
|
46
|
+
}
|
|
47
|
+
export class WhenNode extends SQLNode {
|
|
48
|
+
/**
|
|
49
|
+
* Instantiate a case node.
|
|
50
|
+
* @param {ExprNode} when The WHEN condition expression.
|
|
51
|
+
* @param {ExprNode} then The THEN value expression.
|
|
52
|
+
*/
|
|
53
|
+
constructor(when: ExprNode, then: ExprNode);
|
|
54
|
+
/**
|
|
55
|
+
* The condition expression.
|
|
56
|
+
* @type {ExprNode}
|
|
57
|
+
* @readonly
|
|
58
|
+
*/
|
|
59
|
+
readonly when: ExprNode;
|
|
60
|
+
/**
|
|
61
|
+
* The value expression.
|
|
62
|
+
* @type {ExprNode}
|
|
63
|
+
* @readonly
|
|
64
|
+
*/
|
|
65
|
+
readonly then: ExprNode;
|
|
66
|
+
}
|
|
67
|
+
import { ExprNode } from './node.js';
|
|
68
|
+
import { SQLNode } from './node.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class CastNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate a cast node.
|
|
4
|
+
* @param {ExprNode} expr The expression to type cast.
|
|
5
|
+
* @param {string} type The type to cast to.
|
|
6
|
+
*/
|
|
7
|
+
constructor(expr: ExprNode, type: string);
|
|
8
|
+
/**
|
|
9
|
+
* The expression to type cast.
|
|
10
|
+
* @type {ExprNode}
|
|
11
|
+
* @readonly
|
|
12
|
+
*/
|
|
13
|
+
readonly expr: ExprNode;
|
|
14
|
+
/**
|
|
15
|
+
* The type to cast to.
|
|
16
|
+
* @type {string}
|
|
17
|
+
* @readonly
|
|
18
|
+
*/
|
|
19
|
+
readonly cast: string;
|
|
20
|
+
}
|
|
21
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class ColumnParamNode extends ColumnRefNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate a column param node.
|
|
4
|
+
* @param {import('./param.js').ParamNode} param The column name as a
|
|
5
|
+
* parameter node.
|
|
6
|
+
* @param {import('./table-ref.js').TableRefNode} [table] The table
|
|
7
|
+
* reference.
|
|
8
|
+
*/
|
|
9
|
+
constructor(param: import("./param.js").ParamNode, table?: import("./table-ref.js").TableRefNode);
|
|
10
|
+
/**
|
|
11
|
+
* The column name as a parameter node.
|
|
12
|
+
* @type {import('./param.js').ParamNode}
|
|
13
|
+
* @readonly
|
|
14
|
+
*/
|
|
15
|
+
readonly param: import("./param.js").ParamNode;
|
|
16
|
+
}
|
|
17
|
+
import { ColumnRefNode } from './column-ref.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a value is a column reference node.
|
|
3
|
+
* @param {*} value The value to check.
|
|
4
|
+
* @returns {value is ColumnRefNode}
|
|
5
|
+
*/
|
|
6
|
+
export function isColumnRef(value: any): value is ColumnRefNode;
|
|
7
|
+
export class ColumnRefNode extends ExprNode {
|
|
8
|
+
/**
|
|
9
|
+
* Instantiate a column reference node.
|
|
10
|
+
* @param {import('./table-ref.js').TableRefNode} [table] The table reference.
|
|
11
|
+
*/
|
|
12
|
+
constructor(type: any, table?: import("./table-ref.js").TableRefNode);
|
|
13
|
+
/**
|
|
14
|
+
* The table reference.
|
|
15
|
+
* @type {import('./table-ref.js').TableRefNode}
|
|
16
|
+
* @readonly
|
|
17
|
+
*/
|
|
18
|
+
readonly table: import("./table-ref.js").TableRefNode;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the column name.
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
get column(): string;
|
|
24
|
+
}
|
|
25
|
+
export class ColumnNameRefNode extends ColumnRefNode {
|
|
26
|
+
/**
|
|
27
|
+
* Instantiate a column reference node.
|
|
28
|
+
* @param {string} name The column name.
|
|
29
|
+
* @param {import('./table-ref.js').TableRefNode} [table] The table reference.
|
|
30
|
+
*/
|
|
31
|
+
constructor(name: string, table?: import("./table-ref.js").TableRefNode);
|
|
32
|
+
/**
|
|
33
|
+
* The column name.
|
|
34
|
+
* @type {string}
|
|
35
|
+
* @readonly
|
|
36
|
+
*/
|
|
37
|
+
readonly name: string;
|
|
38
|
+
}
|
|
39
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class FragmentNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate a fragment node with arbitrary content.
|
|
4
|
+
* @param {ExprNode[]} spans The consecutive parts making up the fragment.
|
|
5
|
+
*/
|
|
6
|
+
constructor(spans: ExprNode[]);
|
|
7
|
+
/**
|
|
8
|
+
* The consecutive parts making up the fragment.
|
|
9
|
+
* @type {ExprNode[]}
|
|
10
|
+
* @readonly
|
|
11
|
+
*/
|
|
12
|
+
readonly spans: ExprNode[];
|
|
13
|
+
}
|
|
14
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class FromClauseNode extends SQLNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate a from node.
|
|
4
|
+
* @param {SQLNode} expr The from expression.
|
|
5
|
+
* @param {string} alias The output name.
|
|
6
|
+
*/
|
|
7
|
+
constructor(expr: SQLNode, alias: string);
|
|
8
|
+
/**
|
|
9
|
+
* The from expression.
|
|
10
|
+
* @type {SQLNode}
|
|
11
|
+
* @readonly
|
|
12
|
+
*/
|
|
13
|
+
readonly expr: SQLNode;
|
|
14
|
+
/**
|
|
15
|
+
* The output name.
|
|
16
|
+
* @type {string}
|
|
17
|
+
* @readonly
|
|
18
|
+
*/
|
|
19
|
+
readonly alias: string;
|
|
20
|
+
}
|
|
21
|
+
import { SQLNode } from './node.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class FunctionNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate a function node.
|
|
4
|
+
* @param {string} name The function name.
|
|
5
|
+
* @param {ExprNode[]} [args=[]] The function arguments.
|
|
6
|
+
*/
|
|
7
|
+
constructor(name: string, args?: ExprNode[]);
|
|
8
|
+
/**
|
|
9
|
+
* The function name.
|
|
10
|
+
* @type {string}
|
|
11
|
+
* @readonly
|
|
12
|
+
*/
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/**
|
|
15
|
+
* The function arguments.
|
|
16
|
+
* @type {ExprNode[]}
|
|
17
|
+
* @readonly
|
|
18
|
+
*/
|
|
19
|
+
readonly args: ExprNode[];
|
|
20
|
+
}
|
|
21
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class InOpNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate an in operator node.
|
|
4
|
+
* @param {ExprNode} expr The input expression.
|
|
5
|
+
* @param {ExprNode[]} values The value set.
|
|
6
|
+
*/
|
|
7
|
+
constructor(expr: ExprNode, values: ExprNode[]);
|
|
8
|
+
/**
|
|
9
|
+
* The input expression.
|
|
10
|
+
* @type {ExprNode}
|
|
11
|
+
* @readonly
|
|
12
|
+
*/
|
|
13
|
+
readonly expr: ExprNode;
|
|
14
|
+
/**
|
|
15
|
+
* The value set.
|
|
16
|
+
* @type {ExprNode[]}
|
|
17
|
+
* @readonly
|
|
18
|
+
*/
|
|
19
|
+
readonly values: ExprNode[];
|
|
20
|
+
}
|
|
21
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class IntervalNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate an interval node.
|
|
4
|
+
* @param {string} name The interval name.
|
|
5
|
+
* @param {number} [steps=1] The interval steps.
|
|
6
|
+
*/
|
|
7
|
+
constructor(name: string, steps?: number);
|
|
8
|
+
/**
|
|
9
|
+
* The interval name.
|
|
10
|
+
* @type {string}
|
|
11
|
+
* @readonly
|
|
12
|
+
*/
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/**
|
|
15
|
+
* The interval steps.
|
|
16
|
+
* @type {number}
|
|
17
|
+
* @readonly
|
|
18
|
+
*/
|
|
19
|
+
readonly steps: number;
|
|
20
|
+
}
|
|
21
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function literalToSQL(value: any): string;
|
|
2
|
+
export class LiteralNode extends ExprNode {
|
|
3
|
+
/**
|
|
4
|
+
* Instantiate an literal node.
|
|
5
|
+
* @param {*} value The literal value.
|
|
6
|
+
*/
|
|
7
|
+
constructor(value: any);
|
|
8
|
+
/**
|
|
9
|
+
* The literal value.
|
|
10
|
+
* @type {any}
|
|
11
|
+
* @readonly
|
|
12
|
+
*/
|
|
13
|
+
readonly value: any;
|
|
14
|
+
}
|
|
15
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template {ExprNode} T
|
|
3
|
+
*/
|
|
4
|
+
export class LogicalOpNode<T extends ExprNode> extends ExprNode {
|
|
5
|
+
/**
|
|
6
|
+
* Instantiate a logical operator node.
|
|
7
|
+
* @param {string} op The logical operation.
|
|
8
|
+
* @param {T[]} clauses The input clause expressions.
|
|
9
|
+
*/
|
|
10
|
+
constructor(op: string, clauses: T[]);
|
|
11
|
+
/**
|
|
12
|
+
* The logical operator.
|
|
13
|
+
* @type {string}
|
|
14
|
+
* @readonly
|
|
15
|
+
*/
|
|
16
|
+
readonly op: string;
|
|
17
|
+
/**
|
|
18
|
+
* The input clause expressions.
|
|
19
|
+
* @type {T[]}
|
|
20
|
+
* @readonly
|
|
21
|
+
*/
|
|
22
|
+
readonly clauses: T[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @template {ExprNode} T
|
|
26
|
+
* @extends {LogicalOpNode<T>}
|
|
27
|
+
*/
|
|
28
|
+
export class AndNode<T extends ExprNode> extends LogicalOpNode<T> {
|
|
29
|
+
/**
|
|
30
|
+
* Instantiate a logical AND operator node.
|
|
31
|
+
* @param {T[]} clauses The input clause expressions.
|
|
32
|
+
*/
|
|
33
|
+
constructor(clauses: T[]);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @template {ExprNode} T
|
|
37
|
+
* @extends {LogicalOpNode<T>}
|
|
38
|
+
*/
|
|
39
|
+
export class OrNode<T extends ExprNode> extends LogicalOpNode<T> {
|
|
40
|
+
/**
|
|
41
|
+
* Instantiate a logical OR operator node.
|
|
42
|
+
* @param {T[]} clauses The input clause expressions.
|
|
43
|
+
*/
|
|
44
|
+
constructor(clauses: T[]);
|
|
45
|
+
}
|
|
46
|
+
import { ExprNode } from './node.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a value is a SQL AST node.
|
|
3
|
+
* @param {*} value The value to check.
|
|
4
|
+
* @returns {value is SQLNode}
|
|
5
|
+
*/
|
|
6
|
+
export function isNode(value: any): value is SQLNode;
|
|
7
|
+
export class SQLNode {
|
|
8
|
+
/**
|
|
9
|
+
* Instantiate a SQL AST node.
|
|
10
|
+
* @param {string} type The SQL AST node type.
|
|
11
|
+
*/
|
|
12
|
+
constructor(type: string);
|
|
13
|
+
/**
|
|
14
|
+
* The SQL AST node type.
|
|
15
|
+
* @type {string}
|
|
16
|
+
* @readonly
|
|
17
|
+
*/
|
|
18
|
+
readonly type: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* AST node corresponding to an individual expression.
|
|
22
|
+
*/
|
|
23
|
+
export class ExprNode extends SQLNode {
|
|
24
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class OrderByNode extends ExprNode {
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate an order by entry node.
|
|
4
|
+
* @param {ExprNode} expr The expression to order by.
|
|
5
|
+
* @param {boolean | undefined} [desc] Flag indicating descending order.
|
|
6
|
+
* @param {boolean | undefined} [nullsFirst] Flag indicating if null
|
|
7
|
+
* values should be sorted first.
|
|
8
|
+
*/
|
|
9
|
+
constructor(expr: ExprNode, desc?: boolean | undefined, nullsFirst?: boolean | undefined);
|
|
10
|
+
/**
|
|
11
|
+
* The expression to order by.
|
|
12
|
+
* @type {ExprNode}
|
|
13
|
+
* @readonly
|
|
14
|
+
*/
|
|
15
|
+
readonly expr: ExprNode;
|
|
16
|
+
/**
|
|
17
|
+
* Flag indicating descending order.
|
|
18
|
+
* @type {boolean | undefined}
|
|
19
|
+
* @readonly
|
|
20
|
+
*/
|
|
21
|
+
readonly desc: boolean | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Flag indicating if null values should be sorted first.
|
|
24
|
+
* @type {boolean | undefined}
|
|
25
|
+
* @readonly
|
|
26
|
+
*/
|
|
27
|
+
readonly nullsFirst: boolean | undefined;
|
|
28
|
+
}
|
|
29
|
+
import { ExprNode } from './node.js';
|