@uwdata/mosaic-sql
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -509,4 +509,3 @@ // src/ref.js | ||
var epoch_ms = (expr) => { | ||
const d = asColumn(expr); | ||
return sql`(1000 * (epoch(${d}) - second(${d})) + millisecond(${d}))::DOUBLE`; | ||
return sql`epoch_ms(${asColumn(expr)})`; | ||
}; | ||
@@ -932,2 +931,85 @@ var dateMonth = (expr) => { | ||
// src/scales.js | ||
var identity = (x2) => x2; | ||
function scaleLinear() { | ||
return { | ||
apply: identity, | ||
invert: identity, | ||
sqlApply: asColumn, | ||
sqlInvert: identity | ||
}; | ||
} | ||
function scaleLog({ base } = {}) { | ||
if (base == null || base === Math.E) { | ||
return { | ||
apply: Math.log, | ||
invert: Math.exp, | ||
sqlApply: (c) => sql`LN(${asColumn(c)})`, | ||
sqlInvert: (c) => sql`EXP(${c})` | ||
}; | ||
} else if (base === 10) { | ||
return { | ||
apply: Math.log10, | ||
invert: (x2) => Math.pow(10, x2), | ||
sqlApply: (c) => sql`LOG(${asColumn(c)})`, | ||
sqlInvert: (c) => sql`POW(10, ${c})` | ||
}; | ||
} else { | ||
const b = +base; | ||
return { | ||
apply: (x2) => Math.log(x2) / Math.log(b), | ||
invert: (x2) => Math.pow(b, x2), | ||
sqlApply: (c) => sql`LN(${asColumn(c)}) / LN(${b})`, | ||
sqlInvert: (c) => sql`POW(${b}, ${c})` | ||
}; | ||
} | ||
} | ||
function scaleSymlog({ constant = 1 } = {}) { | ||
const _ = +constant; | ||
return { | ||
apply: (x2) => Math.sign(x2) * Math.log1p(Math.abs(x2)), | ||
invert: (x2) => Math.sign(x2) * Math.exp(Math.abs(x2) - _), | ||
sqlApply: (c) => (c = asColumn(c), sql`SIGN(${c}) * LN(${_} + ABS(${c}))`), | ||
sqlInvert: (c) => sql`SIGN(${c}) * (EXP(ABS(${c})) - ${_})` | ||
}; | ||
} | ||
function scaleSqrt() { | ||
return { | ||
apply: (x2) => Math.sign(x2) * Math.sqrt(Math.abs(x2)), | ||
invert: (x2) => Math.sign(x2) * x2 * x2, | ||
sqlApply: (c) => (c = asColumn(c), sql`SIGN(${c}) * SQRT(ABS(${c}))`), | ||
sqlInvert: (c) => sql`SIGN(${c}) * (${c}) ** 2` | ||
}; | ||
} | ||
function scalePow({ exponent = 1 } = {}) { | ||
const e = +exponent; | ||
return { | ||
apply: (x2) => Math.sign(x2) * Math.pow(Math.abs(x2), e), | ||
invert: (x2) => Math.sign(x2) * Math.pow(Math.abs(x2), 1 / e), | ||
sqlApply: (c) => (c = asColumn(c), sql`SIGN(${c}) * POW(ABS(${c}), ${e})`), | ||
sqlInvert: (c) => sql`SIGN(${c}) * POW(ABS(${c}), 1/${e})` | ||
}; | ||
} | ||
function scaleTime() { | ||
return { | ||
apply: (x2) => +x2, | ||
invert: (x2) => new Date(x2), | ||
sqlApply: (c) => c instanceof Date ? +c : epoch_ms(asColumn(c)), | ||
sqlInvert: identity | ||
}; | ||
} | ||
var scales = { | ||
linear: scaleLinear, | ||
log: scaleLog, | ||
symlog: scaleSymlog, | ||
sqrt: scaleSqrt, | ||
pow: scalePow, | ||
time: scaleTime, | ||
utc: scaleTime | ||
}; | ||
function scaleTransform(options) { | ||
const scale = scales[options.type]; | ||
return scale ? { ...options, ...scale(options) } : null; | ||
} | ||
// src/load/create.js | ||
@@ -1118,2 +1200,3 @@ function create(name, query, { | ||
row_number, | ||
scaleTransform, | ||
skewness, | ||
@@ -1120,0 +1203,0 @@ sql, |
@@ -1,1 +0,1 @@ | ||
var N=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?`${Q(t)}.`:""}${n}`}else return t?Q(t):"NULL"}};function Q(r){return r.split(".").map(e=>`"${e}"`).join(".")}function V(r,t){return r instanceof N&&r.column===t}function l(r){return typeof r=="string"?H(r):r}function I(r){return typeof r=="string"?k(r):r}function k(r){return new N(r)}function H(r,t){return arguments.length===1&&(t=r,r=null),new N(r,t)}function it(r){return new N(r,"*")}function ct(r){return typeof r=="string"?`"${r}"`:E(r)}function E(r){switch(typeof r){case"boolean":return r?"TRUE":"FALSE";case"string":return`'${r}'`;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 R=r=>typeof r?.addEventListener=="function";function _(r){return r instanceof S}var S=class{constructor(t,e,n){this._expr=Array.isArray(t)?t:[t],this._deps=e||[],this.annotate(n);let o=this._expr.filter(s=>R(s));o.length>0?(this._params=Array.from(new Set(o)),this._params.forEach(s=>{s.addEventListener("value",()=>at(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=>R(t)&&!_(t)?E(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 at(r,t){if(t?.size)return Promise.allSettled(Array.from(t,e=>e(r)))}function M(r,t){let e=[r[0]],n=new Set,o=t.length;for(let s=0,i=0;s<o;){let c=t[s];R(c)?e[++i]=c:(Array.isArray(c?.columns)&&c.columns.forEach(x=>n.add(x)),e[i]+=typeof c=="string"?c:E(c));let p=r[++s];R(e[i])?e[++i]=p:e[i]+=p}return{spans:e,cols:Array.from(n)}}function u(r,...t){let{spans:e,cols:n}=M(r,t);return new S(e,n)}function ut(r){let t=l(r);return u`${t} DESC NULLS LAST`.annotate({label:t?.label,desc:!0})}var lt=r=>({value:r,toString:()=>E(r)});function D(r){r(this.op,this),this.children?.forEach(t=>t.visit(r))}function K(r,t){let e=t.filter(o=>o!=null).map(l),n=e.map((o,s)=>s?` ${r} `:"");return e.length===1?n.push(""):e.length>1&&(n[0]="(",n.push(")")),u(n,...e).annotate({op:r,children:e,visit:D})}var pt=(...r)=>K("AND",r.flat()),ft=(...r)=>K("OR",r.flat()),ht=r=>t=>u`(${r} ${l(t)})`.annotate({op:r,a:t,visit:D}),mt=ht("NOT"),v=r=>t=>u`(${l(t)} ${r})`.annotate({op:r,a:t,visit:D}),gt=v("IS NULL"),xt=v("IS NOT NULL"),w=r=>(t,e)=>u`(${l(t)} ${r} ${l(e)})`.annotate({op:r,a:t,b:e,visit:D}),dt=w("="),Et=w("<>"),$t=w("<"),yt=w(">"),Nt=w("<="),St=w(">="),wt=w("IS DISTINCT FROM"),At=w("IS NOT DISTINCT FROM");function z(r,t,e,n){t=l(t);let o=r.startsWith("NOT ")?"NOT ":"";return(e?n?u`${o}(${e[0]} <= ${t} AND ${t} < ${e[1]})`:u`(${t} ${r} ${e[0]} AND ${e[1]})`:u``).annotate({op:r,visit:D,field:t,range:e})}var Rt=(r,t,e)=>z("BETWEEN",r,t,e),Tt=(r,t,e)=>z("NOT BETWEEN",r,t,e);function T(r,t){return Array.from({length:r},()=>t)}function m(r,t){return(...e)=>{let n=e.map(l),o=t?`::${t}`:"";return(n.length?u([`${r}(`,...T(n.length-1,", "),`)${o}`],...n):u`${r}()${o}`).annotate({func:r,args:n})}}var bt=m("REGEXP_MATCHES"),Lt=m("CONTAINS"),Ot=m("PREFIX"),qt=m("SUFFIX"),It=m("LOWER"),Dt=m("UPPER"),Ct=m("LENGTH"),_t=m("ISNAN"),Ft=m("ISFINITE"),Pt=m("ISINF");var C=class r extends S{constructor(t,e,n,o,s="",i="",c=""){let p;if(o&&!(s||i||c))p=o?u`${e} OVER "${o}"`:u`${e} OVER ()`;else{let L=s&&i?" ":"",O=(s||i)&&c?" ":"";p=u`${e} OVER (${o?`"${o}" `:""}${s}${L}${i}${O}${c})`}n&&(p=u`(${p})::${n}`);let{_expr:y,_deps:A}=p;super(y,A,{window:t,func:e,type:n,name:o,group:s,order:i,frame:c})}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:c}=this;return new r(e,n,o,t,s,i,c)}partitionby(...t){let e=t.flat().filter(y=>y).map(l),n=u(["PARTITION BY ",T(e.length-1,", "),""],...e),{window:o,func:s,type:i,name:c,order:p,frame:x}=this;return new r(o,s,i,c,n,p,x)}orderby(...t){let e=t.flat().filter(y=>y).map(l),n=u(["ORDER BY ",T(e.length-1,", "),""],...e),{window:o,func:s,type:i,name:c,group:p,frame:x}=this;return new r(o,s,i,c,p,n,x)}rows(t){let e=J("ROWS",t),{window:n,func:o,type:s,name:i,group:c,order:p}=this;return new r(n,o,s,i,c,p,e)}range(t){let e=J("RANGE",t),{window:n,func:o,type:s,name:i,group:c,order:p}=this;return new r(n,o,s,i,c,p,e)}};function J(r,t){if(R(t)){let e=u`${t}`;return e.toString=()=>`${r} ${Z(t.value)}`,e}return`${r} ${Z(t)}`}function Z(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 $(r,t){return(...e)=>{let n=m(r)(...e);return new C(r,n,t)}}var Ut=$("ROW_NUMBER","INTEGER"),jt=$("RANK","INTEGER"),Gt=$("DENSE_RANK","INTEGER"),Mt=$("PERCENT_RANK"),Yt=$("CUME_DIST"),Wt=$("NTILE"),Xt=$("LAG"),Bt=$("LEAD"),Qt=$("FIRST_VALUE"),Vt=$("LAST_VALUE"),kt=$("NTH_VALUE");function Ht(r,...t){return u(r,...t).annotate({aggregate:!0})}var Y=class r extends S{constructor(t,e,n,o,s){e=(e||[]).map(l);let{strings:i,exprs:c}=Kt(t,e,n,o,s),{spans:p,cols:x}=M(i,c);super(p,x,{aggregate:t,args:e,type:n,isDistinct:o,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(vt).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,e){return this.window().rows(t,e)}range(t,e){return this.window().range(t,e)}};function Kt(r,t,e,n,o){let s=`)${e?`::${e}`:""}`,i=[`${r}(${n?"DISTINCT ":""}`],c=[];return t.length?(i=i.concat([...T(t.length-1,", "),`${s}${o?" FILTER (WHERE ":""}`,...o?[")"]:[]]),c=[...t,...o?[o]:[]]):i[0]+="*"+s,{exprs:c,strings:i}}function vt(r){let t=E(r);return t&&t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function a(r,t){return(...e)=>new Y(r,e,t)}var zt=a("COUNT","INTEGER"),Jt=a("AVG"),Zt=a("AVG"),te=a("MAD"),ee=a("MAX"),re=a("MIN"),ne=a("SUM","DOUBLE"),oe=a("PRODUCT"),se=a("MEDIAN"),ie=a("QUANTILE"),ce=a("MODE"),ae=a("VARIANCE"),ue=a("STDDEV"),le=a("SKEWNESS"),pe=a("KURTOSIS"),fe=a("ENTROPY"),he=a("VAR_POP"),me=a("STDDEV_POP"),ge=a("CORR"),xe=a("COVAR_POP"),de=a("REGR_INTERCEPT"),Ee=a("REGR_SLOPE"),$e=a("REGR_COUNT"),ye=a("REGR_R2"),Ne=a("REGR_SYY"),Se=a("REGR_SXX"),we=a("REGR_SXY"),Ae=a("REGR_AVGX"),Re=a("REGR_AVGY"),Te=a("FIRST"),be=a("LAST"),Le=a("ARG_MIN"),Oe=a("ARG_MAX"),qe=a("STRING_AGG"),Ie=a("ARRAY_AGG");function W(r,t){let e=l(r),n=u`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 De=r=>W(r,"DOUBLE"),Ce=r=>W(r,"INTEGER");var _e=r=>{let t=l(r);return u`(1000 * (epoch(${t}) - second(${t})) + millisecond(${t}))::DOUBLE`},Fe=r=>{let t=l(r);return u`MAKE_DATE(2012, MONTH(${t}), 1)`.annotate({label:"month"})},Pe=r=>{let t=l(r);return u`MAKE_DATE(2012, MONTH(${t}), DAY(${t}))`.annotate({label:"date"})},Ue=r=>{let t=l(r);return u`MAKE_DATE(2012, 1, DAY(${t}))`.annotate({label:"date"})};var je=m("ST_AsGeoJSON"),tt=m("ST_X"),et=m("ST_Y"),X=m("ST_CENTROID"),Ge=r=>tt(X(r)),Me=r=>et(X(r));var U=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 b("UNION",t.flat())}static unionAll(...t){return new b("UNION ALL",t.flat())}static intersect(...t){return new b("INTERSECT",t.flat())}static except(...t){return new b("EXCEPT",t.flat())}constructor(){this.query={with:[],select:[],from:[],where:[],groupby:[],having:[],window:[],qualify:[],orderby:[]}}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 c=i.clone();c.cteFor=this,n.push({as:s,query:c})};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 o of t.flat())if(o!=null)if(typeof o=="string")n.push({as:o,expr:l(o)});else if(o instanceof N)n.push({as:o.column,expr:o});else if(Array.isArray(o))n.push({as:o[0],expr:o[1]});else for(let s in o)n.push({as:F(s),expr:l(o[s])});return e.select=e.select.concat(n),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:I(o)});else if(o instanceof N)n.push({as:o.table,from:o});else if(P(o)||_(o))n.push({from:o});else if(Array.isArray(o))n.push({as:F(o[0]),from:I(o[1])});else for(let s in o)n.push({as:F(s),from:I(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(l)),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:F(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(l)),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:c,query:p})=>(i[c]=p,i),{}),s=[];return t.from.forEach(({from:i})=>{if(P(i))s.push(i);else if(o[i.table]){let c=o[i.table];s.push(c)}}),s}toString(){let{select:t,distinct:e,from:n,sample:o,where:s,groupby:i,having:c,window:p,qualify:x,orderby:y,limit:A,offset:L,with:O}=this.query,g=[];if(O.length){let f=O.map(({as:h,query:d})=>`"${h}" AS (${d})`);g.push(`WITH ${f.join(", ")}`)}let nt=t.map(({as:f,expr:h})=>V(h,f)&&!h.table?`${h}`:`${h} AS "${f}"`);if(g.push(`SELECT${e?" DISTINCT":""} ${nt.join(", ")}`),n.length){let f=n.map(({as:h,from:d})=>{let q=P(d)?`(${d})`:`${d}`;return!h||h===d.table?q:`${q} AS "${h}"`});g.push(`FROM ${f.join(", ")}`)}if(s.length){let f=s.map(String).filter(h=>h).join(" AND ");f&&g.push(`WHERE ${f}`)}if(o){let{rows:f,perc:h,method:d,seed:q}=o,ot=f?`${f} ROWS`:`${h} PERCENT`,st=d?` (${d}${q!=null?`, ${q}`:""})`:"";g.push(`USING SAMPLE ${ot}${st}`)}if(i.length&&g.push(`GROUP BY ${i.join(", ")}`),c.length){let f=c.map(String).filter(h=>h).join(" AND ");f&&g.push(`HAVING ${f}`)}if(p.length){let f=p.map(({as:h,expr:d})=>`"${h}" AS (${d})`);g.push(`WINDOW ${f.join(", ")}`)}if(x.length){let f=x.map(String).filter(h=>h).join(" AND ");f&&g.push(`QUALIFY ${f}`)}return y.length&&g.push(`ORDER BY ${y.join(", ")}`),Number.isFinite(A)&&g.push(`LIMIT ${A}`),Number.isFinite(L)&&g.push(`OFFSET ${L}`),g.join(" ")}},b=class r{constructor(t,e){this.op=t,this.queries=e.map(n=>n.clone()),this.query={orderby:[]}}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(l)),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 P(r){return r instanceof U||r instanceof b}function F(r){return Ye(r)?r.slice(1,-1):r}function Ye(r){return r[0]==='"'&&r[r.length-1]==='"'}function j(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 We(r){return`INSTALL ${r}; LOAD ${r}`}function rt(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=>`${E(o[i])} AS "${t[i]}"`);n.push(`(SELECT ${s.join(", ")})`)}return n.join(" UNION ALL ")}function G(r,t,e,n={},o={}){let{select:s=["*"],where:i,view:c,temp:p,replace:x,...y}=n,A=He({...o,...y}),L=`${r}('${e}'${A?", "+A:""})`,O=i?` WHERE ${i}`:"",g=`SELECT ${s.join(", ")} FROM ${L}${O}`;return j(t,g,{view:c,temp:p,replace:x})}function Xe(r,t,e){return G("read_csv",r,t,e,{auto_detect:!0,sample_size:-1})}function Be(r,t,e){return G("read_json",r,t,e,{auto_detect:!0,json_format:"auto"})}function Qe(r,t,e){return G("read_parquet",r,t,e)}function Ve(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,c])=>`${i}=${c}`).join(", ");o.open_options=s.toUpperCase()}return G("st_read",r,t,o)}function ke(r,t,e={}){let{select:n=["*"],...o}=e,s=rt(t),i=n.length===1&&n[0]==="*"?s:`SELECT ${n} FROM ${s}`;return j(r,i,o)}function He(r){return Object.entries(r).map(([t,e])=>`${t}=${B(e)}`).join(", ")}function B(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=>B(t)).join(", ")+"]":"{"+Object.entries(r).map(([t,e])=>`'${t}': ${B(e)}`).join(", ")+"}";default:return r}}export{U as Query,N as Ref,Ht as agg,it as all,pt as and,Oe as argmax,Le as argmin,Ie as arrayAgg,l as asColumn,I as asRelation,Jt as avg,W as cast,De as castDouble,Ce as castInteger,X as centroid,Ge as centroidX,Me as centroidY,H as column,Lt as contains,ge as corr,zt as count,xe as covarPop,j as create,Yt as cume_dist,Ue as dateDay,Fe as dateMonth,Pe as dateMonthDay,Gt as dense_rank,ut as desc,fe as entropy,_e as epoch_ms,dt as eq,Te as first,Qt as first_value,je as geojson,yt as gt,St as gte,Rt as isBetween,wt as isDistinct,Ft as isFinite,Pt as isInfinite,_t as isNaN,Tt as isNotBetween,At as isNotDistinct,xt as isNotNull,gt as isNull,R as isParamLike,P as isQuery,_ as isSQLExpression,pe as kurtosis,Xt as lag,be as last,Vt as last_value,Bt as lead,Ct as length,lt as literal,E as literalToSQL,Xe as loadCSV,We as loadExtension,Be as loadJSON,ke as loadObjects,Qe as loadParquet,Ve as loadSpatial,It as lower,$t as lt,Nt as lte,te as mad,ee as max,Zt as mean,se as median,re as min,ce as mode,Et as neq,mt as not,kt as nth_value,Wt as ntile,ft as or,Mt as percent_rank,Ot as prefix,oe as product,ie as quantile,jt as rank,bt as regexp_matches,Ae as regrAvgX,Re as regrAvgY,$e as regrCount,de as regrIntercept,ye as regrR2,Se as regrSXX,we as regrSXY,Ne as regrSYY,Ee as regrSlope,k as relation,Ut as row_number,le as skewness,u as sql,ue as stddev,me as stddevPop,qe as stringAgg,qt as suffix,ne as sum,ct as toSQL,Dt as upper,he as varPop,ae as variance,tt as x,et as y}; | ||
var N=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 N&&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 N(r)}function K(r,t){return arguments.length===1&&(t=r,r=null),new N(r,t)}function ut(r){return new N(r,"*")}function lt(r){return typeof r=="string"?`"${r}"`:$(r)}function $(r){switch(typeof r){case"boolean":return r?"TRUE":"FALSE";case"string":return`'${r}'`;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 M(r){return r instanceof S}var S=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",()=>pt(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)&&!M(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 pt(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 S(e,n)}function ft(r){let t=u(r);return c`${t} DESC NULLS LAST`.annotate({label:t?.label,desc:!0})}var ht=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 mt=(...r)=>z("AND",r.flat()),gt=(...r)=>z("OR",r.flat()),dt=r=>t=>c`(${r} ${u(t)})`.annotate({op:r,a:t,visit:D}),xt=dt("NOT"),J=r=>t=>c`(${u(t)} ${r})`.annotate({op:r,a:t,visit:D}),$t=J("IS NULL"),Et=J("IS NOT NULL"),w=r=>(t,e)=>c`(${u(t)} ${r} ${u(e)})`.annotate({op:r,a:t,b:e,visit:D}),yt=w("="),Nt=w("<>"),St=w("<"),wt=w(">"),At=w("<="),Tt=w(">="),Rt=w("IS DISTINCT FROM"),qt=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 bt=(r,t,e)=>Z("BETWEEN",r,t,e),It=(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 Lt=m("REGEXP_MATCHES"),Ot=m("CONTAINS"),Dt=m("PREFIX"),_t=m("SUFFIX"),Mt=m("LOWER"),Ct=m("UPPER"),Pt=m("LENGTH"),Ft=m("ISNAN"),Gt=m("ISFINITE"),Ut=m("ISINF");var _=class r extends S{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,{window:t,func:e,type:n,name:o,group:s,order:i,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 _(r,n,t)}}var jt=E("ROW_NUMBER","INTEGER"),Wt=E("RANK","INTEGER"),Yt=E("DENSE_RANK","INTEGER"),vt=E("PERCENT_RANK"),Bt=E("CUME_DIST"),Xt=E("NTILE"),Qt=E("LAG"),Vt=E("LEAD"),kt=E("FIRST_VALUE"),Ht=E("LAST_VALUE"),Kt=E("NTH_VALUE");function zt(r,...t){return c(r,...t).annotate({aggregate:!0})}var Y=class r extends S{constructor(t,e,n,o,s){e=(e||[]).map(u);let{strings:i,exprs:a}=Jt(t,e,n,o,s),{spans:p,cols:d}=W(i,a);super(p,d,{aggregate:t,args:e,type:n,isDistinct:o,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(Zt).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 _(t,s,n)}partitionby(...t){return this.window().partitionby(...t)}orderby(...t){return this.window().orderby(...t)}rows(t,e){return this.window().rows(t,e)}range(t,e){return this.window().range(t,e)}};function Jt(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 Zt(r){let t=$(r);return t&&t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function l(r,t){return(...e)=>new Y(r,e,t)}var te=l("COUNT","INTEGER"),ee=l("AVG"),re=l("AVG"),ne=l("MAD"),oe=l("MAX"),se=l("MIN"),ie=l("SUM","DOUBLE"),ce=l("PRODUCT"),ae=l("MEDIAN"),ue=l("QUANTILE"),le=l("MODE"),pe=l("VARIANCE"),fe=l("STDDEV"),he=l("SKEWNESS"),me=l("KURTOSIS"),ge=l("ENTROPY"),de=l("VAR_POP"),xe=l("STDDEV_POP"),$e=l("CORR"),Ee=l("COVAR_POP"),ye=l("REGR_INTERCEPT"),Ne=l("REGR_SLOPE"),Se=l("REGR_COUNT"),we=l("REGR_R2"),Ae=l("REGR_SYY"),Te=l("REGR_SXX"),Re=l("REGR_SXY"),qe=l("REGR_AVGX"),be=l("REGR_AVGY"),Ie=l("FIRST"),Le=l("LAST"),Oe=l("ARG_MIN"),De=l("ARG_MAX"),_e=l("STRING_AGG"),Me=l("ARRAY_AGG");function v(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 Ce=r=>v(r,"DOUBLE"),Pe=r=>v(r,"INTEGER");var B=r=>c`epoch_ms(${u(r)})`,Fe=r=>{let t=u(r);return c`MAKE_DATE(2012, MONTH(${t}), 1)`.annotate({label:"month"})},Ge=r=>{let t=u(r);return c`MAKE_DATE(2012, MONTH(${t}), DAY(${t}))`.annotate({label:"date"})},Ue=r=>{let t=u(r);return c`MAKE_DATE(2012, 1, DAY(${t}))`.annotate({label:"date"})};var je=m("ST_AsGeoJSON"),rt=m("ST_X"),nt=m("ST_Y"),X=m("ST_CENTROID"),We=r=>rt(X(r)),Ye=r=>nt(X(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())}constructor(){this.query={with:[],select:[],from:[],where:[],groupby:[],having:[],window:[],qualify:[],orderby:[]}}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 o of t.flat())if(o!=null)if(typeof o=="string")n.push({as:o,expr:u(o)});else if(o instanceof N)n.push({as:o.column,expr:o});else if(Array.isArray(o))n.push({as:o[0],expr:o[1]});else for(let s in o)n.push({as:C(s),expr:u(o[s])});return e.select=e.select.concat(n),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 N)n.push({as:o.table,from:o});else if(P(o)||M(o))n.push({from:o});else if(Array.isArray(o))n.push({as:C(o[0]),from:O(o[1])});else for(let s in o)n.push({as:C(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:C(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(P(i))s.push(i);else if(o[i.table]){let a=o[i.table];s.push(a)}}),s}toString(){let{select:t,distinct:e,from:n,sample:o,where:s,groupby:i,having:a,window:p,qualify:d,orderby:y,limit:A,offset:b,with:I}=this.query,g=[];if(I.length){let f=I.map(({as:h,query:x})=>`"${h}" AS (${x})`);g.push(`WITH ${f.join(", ")}`)}let it=t.map(({as:f,expr:h})=>k(h,f)&&!h.table?`${h}`:`${h} AS "${f}"`);if(g.push(`SELECT${e?" DISTINCT":""} ${it.join(", ")}`),n.length){let f=n.map(({as:h,from:x})=>{let L=P(x)?`(${x})`:`${x}`;return!h||h===x.table?L:`${L} AS "${h}"`});g.push(`FROM ${f.join(", ")}`)}if(s.length){let f=s.map(String).filter(h=>h).join(" AND ");f&&g.push(`WHERE ${f}`)}if(o){let{rows:f,perc:h,method:x,seed:L}=o,ct=f?`${f} ROWS`:`${h} PERCENT`,at=x?` (${x}${L!=null?`, ${L}`:""})`:"";g.push(`USING SAMPLE ${ct}${at}`)}if(i.length&&g.push(`GROUP BY ${i.join(", ")}`),a.length){let f=a.map(String).filter(h=>h).join(" AND ");f&&g.push(`HAVING ${f}`)}if(p.length){let f=p.map(({as:h,expr:x})=>`"${h}" AS (${x})`);g.push(`WINDOW ${f.join(", ")}`)}if(d.length){let f=d.map(String).filter(h=>h).join(" AND ");f&&g.push(`QUALIFY ${f}`)}return y.length&&g.push(`ORDER BY ${y.join(", ")}`),Number.isFinite(A)&&g.push(`LIMIT ${A}`),Number.isFinite(b)&&g.push(`OFFSET ${b}`),g.join(" ")}},q=class r{constructor(t,e){this.op=t,this.queries=e.map(n=>n.clone()),this.query={orderby:[]}}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 P(r){return r instanceof F||r instanceof q}function C(r){return ve(r)?r.slice(1,-1):r}function ve(r){return r[0]==='"'&&r[r.length-1]==='"'}var G=r=>r;function Be(){return{apply:G,invert:G,sqlApply:u,sqlInvert:G}}function Xe({base:r}={}){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 Qe({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 Ve(){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 ke({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 ot(){return{apply:r=>+r,invert:r=>new Date(r),sqlApply:r=>r instanceof Date?+r:B(u(r)),sqlInvert:G}}var He={linear:Be,log:Xe,symlog:Qe,sqrt:Ve,pow:ke,time:ot,utc:ot};function Ke(r){let t=He[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 ze(r){return`INSTALL ${r}; LOAD ${r}`}function st(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=nr({...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 Je(r,t,e){return j("read_csv",r,t,e,{auto_detect:!0,sample_size:-1})}function Ze(r,t,e){return j("read_json",r,t,e,{auto_detect:!0,json_format:"auto"})}function tr(r,t,e){return j("read_parquet",r,t,e)}function er(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(", ");o.open_options=s.toUpperCase()}return j("st_read",r,t,o)}function rr(r,t,e={}){let{select:n=["*"],...o}=e,s=st(t),i=n.length===1&&n[0]==="*"?s:`SELECT ${n} FROM ${s}`;return U(r,i,o)}function nr(r){return Object.entries(r).map(([t,e])=>`${t}=${Q(e)}`).join(", ")}function Q(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=>Q(t)).join(", ")+"]":"{"+Object.entries(r).map(([t,e])=>`'${t}': ${Q(e)}`).join(", ")+"}";default:return r}}export{F as Query,N as Ref,zt as agg,ut as all,mt as and,De as argmax,Oe as argmin,Me as arrayAgg,u as asColumn,O as asRelation,ee as avg,v as cast,Ce as castDouble,Pe as castInteger,X as centroid,We as centroidX,Ye as centroidY,K as column,Ot as contains,$e as corr,te as count,Ee as covarPop,U as create,Bt as cume_dist,Ue as dateDay,Fe as dateMonth,Ge as dateMonthDay,Yt as dense_rank,ft as desc,ge as entropy,B as epoch_ms,yt as eq,Ie as first,kt as first_value,je as geojson,wt as gt,Tt as gte,bt as isBetween,Rt as isDistinct,Gt as isFinite,Ut as isInfinite,Ft as isNaN,It as isNotBetween,qt as isNotDistinct,Et as isNotNull,$t as isNull,T as isParamLike,P as isQuery,M as isSQLExpression,me as kurtosis,Qt as lag,Le as last,Ht as last_value,Vt as lead,Pt as length,ht as literal,$ as literalToSQL,Je as loadCSV,ze as loadExtension,Ze as loadJSON,rr as loadObjects,tr as loadParquet,er as loadSpatial,Mt as lower,St as lt,At as lte,ne as mad,oe as max,re as mean,ae as median,se as min,le as mode,Nt as neq,xt as not,Kt as nth_value,Xt as ntile,gt as or,vt as percent_rank,Dt as prefix,ce as product,ue as quantile,Wt as rank,Lt as regexp_matches,qe as regrAvgX,be as regrAvgY,Se as regrCount,ye as regrIntercept,we as regrR2,Te as regrSXX,Re as regrSXY,Ae as regrSYY,Ne as regrSlope,H as relation,jt as row_number,Ke as scaleTransform,he as skewness,c as sql,fe as stddev,xe as stddevPop,_e as stringAgg,_t as suffix,ie as sum,lt as toSQL,Ct as upper,de as varPop,pe as variance,rt as x,nt as y}; |
{ | ||
"name": "@uwdata/mosaic-sql", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "SQL query construction and analysis.", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "92886dddfb126c1439924c5a0189e4639c3519a7" | ||
"gitHead": "51517b28e916e355f4ce0dc6e98aef3a1db3f7b2" | ||
} |
@@ -5,4 +5,3 @@ import { sql } from './expression.js'; | ||
export const epoch_ms = expr => { | ||
const d = asColumn(expr); | ||
return sql`(1000 * (epoch(${d}) - second(${d})) + millisecond(${d}))::DOUBLE`; | ||
return sql`epoch_ms(${asColumn(expr)})`; | ||
}; | ||
@@ -9,0 +8,0 @@ |
@@ -140,2 +140,6 @@ export { | ||
export { | ||
scaleTransform | ||
} from './scales.js'; | ||
export { create } from './load/create.js'; | ||
@@ -142,0 +146,0 @@ export { loadExtension } from './load/extension.js'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98821
25
2720