@uwdata/flechette
Advanced tools
Comparing version
@@ -1,1 +0,2 @@ | ||
var rt=Uint8Array.of(65,82,82,79,87,49),E={V1:0,V2:1,V3:2,V4:3,V5:4},dr={Little:0,Big:1},L={NONE:0,Schema:1,DictionaryBatch:2,RecordBatch:3,Tensor:4,SparseTensor:5},a={Dictionary:-1,NONE:0,Null:1,Int:2,Float:3,Binary:4,Utf8:5,Bool:6,Decimal:7,Date:8,Time:9,Timestamp:10,Interval:11,List:12,Struct:13,Union:14,FixedSizeBinary:15,FixedSizeList:16,Map:17,Duration:18,LargeBinary:19,LargeUtf8:20,LargeList:21,RunEndEncoded:22,BinaryView:23,Utf8View:24,ListView:25,LargeListView:26},H={HALF:0,SINGLE:1,DOUBLE:2},V={DAY:0,MILLISECOND:1},x={SECOND:0,MILLISECOND:1,MICROSECOND:2,NANOSECOND:3},T={YEAR_MONTH:0,DAY_TIME:1,MONTH_DAY_NANO:2},j={Sparse:0,Dense:1};var W=Uint8Array,Et=Uint16Array,Lt=Uint32Array,ut=BigUint64Array,nt=Int8Array,ur=Int16Array,b=Int32Array,S=BigInt64Array,Zt=Float32Array,Z=Float64Array;function Kr(e,t){let r=Math.log2(e)-3;return(t?[nt,ur,b,S]:[W,Et,Lt,ut])[r]}var Un=Object.getPrototypeOf(Int8Array);function lr(e){return e instanceof Un}function Jt(e){return Array.isArray(e)||lr(e)}function lt(e){return e===S||e===ut}function pt(e,t){let r=0,n=e.length;if(n<=2147483648)do{let s=r+n>>>1;e[s]<=t?r=s+1:n=s}while(r<n);else do{let s=Math.trunc((r+n)/2);e[s]<=t?r=s+1:n=s}while(r<n);return r}function Cn(e,t=1){return(e*t+7&-8)/t}function Xr(e,t=e.length){let r=Cn(t,e.BYTES_PER_ELEMENT);return e.length>r?e.subarray(0,r):e.length<r?qr(e,r):e}function qr(e,t,r=0){let n=new e.constructor(t);return n.set(e,r),n}function Kt(e,t,r){for(;e.length<=t;)e=qr(e,e.length<<1,r?e.length:0);return e}function Qr(e){return e instanceof Date}function Xt(e,t,r){if(t(e))return e;throw new Error(r(e))}function F(e,t,r){return t=Array.isArray(t)?t:Object.values(t),Xt(e,n=>t.includes(n),r??(()=>`${e} must be one of ${t}`))}function qt(e,t){for(let[r,n]of Object.entries(e))if(n===t)return r;return"<Unknown>"}var U=e=>`Unsupported data type: "${qt(a,e)}" (id ${e})`,X=(e,t,r=!0,n=null)=>({name:e,nullable:r,type:t,metadata:n});function tn(e){return Object.hasOwn(e,"name")&&en(e.type)}function en(e){return typeof e?.typeId=="number"}function Y(e,t="",r=!0){return tn(e)?e:X(t,Xt(e,en,()=>"Data type expected."),r)}var Qt=e=>({typeId:e}),Bt=(e,t,r=!1,n=-1)=>({typeId:a.Dictionary,dictionary:e,indices:t||q(),ordered:r,id:n}),pr=()=>Qt(a.Null),z=(e=32,t=!0)=>({typeId:a.Int,bitWidth:F(e,[8,16,32,64]),signed:t,values:Kr(e,t)}),Tt=()=>z(8),bt=()=>z(16),q=()=>z(32),St=()=>z(64),hr=()=>z(8,!1),mr=()=>z(16,!1),yr=()=>z(32,!1),xr=()=>z(64,!1),ht=(e=2)=>({typeId:a.Float,precision:F(e,H),values:[Et,Zt,Z][e]}),kn=()=>ht(H.HALF),Ir=()=>ht(H.SINGLE),mt=()=>ht(H.DOUBLE),gr=()=>({typeId:a.Binary,offsets:b}),Ft=()=>({typeId:a.Utf8,offsets:b}),wr=()=>Qt(a.Bool),Or=(e,t,r=128)=>({typeId:a.Decimal,precision:e,scale:t,bitWidth:F(r,[128,256]),values:ut}),Mt=e=>({typeId:a.Date,unit:F(e,V),values:e===V.DAY?b:S}),vr=()=>Mt(V.DAY),jn=()=>Mt(V.MILLISECOND),st=(e=x.MILLISECOND,t=32)=>({typeId:a.Time,unit:F(e,x),bitWidth:F(t,[32,64]),values:t===32?b:S}),zn=()=>st(x.SECOND,32),Rn=()=>st(x.MILLISECOND,32),_n=()=>st(x.MICROSECOND,64),Pn=()=>st(x.NANOSECOND,64),Nt=(e=x.MILLISECOND,t=null)=>({typeId:a.Timestamp,unit:F(e,x),timezone:t,values:S}),Ar=(e=T.MONTH_DAY_NANO)=>({typeId:a.Interval,unit:F(e,T),values:e===T.MONTH_DAY_NANO?void 0:b}),Vt=e=>({typeId:a.List,children:[Y(e)],offsets:b}),yt=e=>({typeId:a.Struct,children:Array.isArray(e)&&tn(e[0])?e:Object.entries(e).map(([t,r])=>X(t,r))}),Dr=(e,t,r,n)=>(r??=t.map((s,o)=>o),{typeId:a.Union,mode:F(e,j),typeIds:r,typeMap:r.reduce((s,o,i)=>(s[o]=i,s),{}),children:t.map((s,o)=>Y(s,`_${o}`)),typeIdForValue:n,offsets:b}),Er=e=>({typeId:a.FixedSizeBinary,stride:e}),Ut=(e,t)=>({typeId:a.FixedSizeList,stride:t,children:[Y(e)]}),Lr=(e,t)=>({typeId:a.Map,keysSorted:e,children:[t],offsets:b}),$n=(e,t,r=!1)=>Lr(r,X("entries",yt([Y(e,"key",!1),Y(t,"value")]),!1)),Br=(e=x.MILLISECOND)=>({typeId:a.Duration,unit:F(e,x),values:S}),Tr=()=>({typeId:a.LargeBinary,offsets:S}),br=()=>({typeId:a.LargeUtf8,offsets:S}),Sr=e=>({typeId:a.LargeList,children:[Y(e)],offsets:S}),Fr=(e,t)=>({typeId:a.RunEndEncoded,children:[Xt(Y(e,"run_ends"),r=>r.type.typeId===a.Int,()=>"Run-ends must have an integer type."),Y(t,"values")]}),Hn=()=>Qt(a.BinaryView),Yn=()=>Qt(a.Utf8View),Mr=e=>({typeId:a.ListView,children:[Y(e,"value")],offsets:b}),Nr=e=>({typeId:a.LargeListView,children:[Y(e,"value")],offsets:S});var nn=new Z(2),te=nn.buffer,Gn=new S(te),xt=new Lt(te),rn=new b(te),Wn=new W(te);function Zn(e){return e}function R(e){return BigInt(e)}function ee(e){return lt(e)?R:Zn}function sn(e){return e/864e5|0}function on(e){return e===x.SECOND?t=>R(t/1e3):e===x.MILLISECOND?R:e===x.MICROSECOND?t=>R(t*1e3):t=>R(t*1e6)}function an([e,t,r]){return rn[0]=e,rn[1]=t,Gn[1]=R(r),Wn}function G(e){if(e>Number.MAX_SAFE_INTEGER||e<Number.MIN_SAFE_INTEGER)throw Error(`BigInt exceeds integer number representation: ${e}`);return Number(e)}function re(e,t){return Number(e/t)+Number(e%t)/Number(t)}function cn(e,t,r,n,s){let o=typeof e=="bigint"?e:R(Math.trunc(e*s));t[r]=o,t[r+1]=o>>64n,n>2&&(t[r+2]=o>>128n,t[r+3]=o>>192n)}var It=e=>BigInt.asUintN(64,e);function fn(e,t){let r=t<<1,n;return BigInt.asIntN(64,e[r+1])<0?(n=It(~e[r])|It(~e[r+1])<<64n,n=-(n+1n)):n=e[r]|e[r+1]<<64n,n}function dn(e,t){let r=t<<2,n;return BigInt.asIntN(64,e[r+3])<0?(n=It(~e[r])|It(~e[r+1])<<64n|It(~e[r+2])<<128n|It(~e[r+3])<<192n,n=-(n+1n)):n=e[r]|e[r+1]<<64n|e[r+2]<<128n|e[r+3]<<192n,n}function un(e){if(e!==e)return 32256;nn[0]=e;let t=(xt[1]&2147483648)>>16&65535,r=xt[1]&2146435072,n=0;return r>=1089470464?xt[0]>0?r=31744:(r=(r&2080374784)>>16,n=(xt[1]&1048575)>>10):r<=1056964608?(n=1048576+(xt[1]&1048575),n=1048576+(n<<(r>>20)-998)>>21,r=0):(r=r-1056964608>>10,n=(xt[1]&1048575)+512>>10),t|r|n&65535}var Jn=new TextDecoder("utf-8"),Kn=new TextEncoder;function gt(e){return Jn.decode(e)}function ne(e){return Kn.encode(e)}function wt(e){return`${typeof e!="object"||!e?e??null:Qr(e)?+e:Jt(e)?`[${e.map(wt)}]`:Xn(e)}`}function Xn(e){let t="",r=-1;for(let n in e)++r>0&&(t+=","),t+=`"${n}":${wt(e[n])}`;return`{${t}}`}var C=4,se=2;function Vr(e,t){return(e[t>>3]&1<<t%8)!==0}function B(e,t){let r=t+y(e,t),n=r-y(e,r),s=w(e,n);return(o,i,c=null)=>{if(o<s){let f=w(e,n+o);if(f)return i(e,r+f)}return c}}function _(e,t){return t}function Q(e,t){return!!qn(e,t)}function qn(e,t){return Ct(e,t)<<24>>24}function Ct(e,t){return e[t]}function w(e,t){return Qn(e,t)<<16>>16}function Qn(e,t){return e[t]|e[t+1]<<8}function y(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function ln(e,t){return y(e,t)>>>0}function D(e,t){return G(BigInt.asIntN(64,BigInt(ln(e,t))+(BigInt(ln(e,t+C))<<32n)))}function ot(e,t){let r=t+y(e,t),n=y(e,r);return r+=C,gt(e.subarray(r,r+n))}function N(e,t,r,n){if(!t)return[];let s=t+y(e,t);return Array.from({length:y(e,s)},(o,i)=>n(e,s+C+i*r))}var Ur=Symbol("rowIndex");function kt(e,t){class r{constructor(o){this[Ur]=o}toJSON(){return pn(e,t,this[Ur])}}let n=r.prototype;for(let s=0;s<e.length;++s){if(Object.hasOwn(n,e[s]))continue;let o=t[s];Object.defineProperty(n,e[s],{get(){return o.at(this[Ur])},enumerable:!0})}return s=>new r(s)}function oe(e,t){return r=>pn(e,t,r)}function pn(e,t,r){let n={};for(let s=0;s<e.length;++s)n[e[s]]=t[s].at(r);return n}function hn(e){return e instanceof J}var it=class{static ArrayType=null;constructor({length:t,nullCount:r,type:n,validity:s,values:o,offsets:i,sizes:c,children:f}){this.length=t,this.nullCount=r,this.type=n,this.validity=s,this.values=o,this.offsets=i,this.sizes=c,this.children=f,(!r||!this.validity)&&(this.at=d=>this.value(d))}get[Symbol.toStringTag](){return"Batch"}at(t){return this.isValid(t)?this.value(t):null}isValid(t){return Vr(this.validity,t)}value(t){return this.values[t]}slice(t,r){let n=r-t,s=Array(n);for(let o=0;o<n;++o)s[o]=this.at(t+o);return s}*[Symbol.iterator](){for(let t=0;t<this.length;++t)yield this.at(t)}},J=class extends it{constructor(t){super(t);let{length:r,values:n}=this;this.values=n.subarray(0,r)}slice(t,r){return this.nullCount?super.slice(t,r):this.values.subarray(t,r)}[Symbol.iterator](){return this.nullCount?super[Symbol.iterator]():this.values[Symbol.iterator]()}},jt=class extends it{static ArrayType=Z},I=class extends it{static ArrayType=Array},Ot=class extends I{value(t){return null}},P=class extends jt{value(t){return G(this.values[t])}},ie=class extends jt{value(t){let r=this.values[t],n=(r&31744)>>10,s=(r&1023)/1024,o=(-1)**((r&32768)>>15);switch(n){case 31:return o*(s?Number.NaN:1/0);case 0:return o*(s?6103515625e-14*s:0)}return o*2**(n-15)*(1+s)}},ae=class extends I{value(t){return Vr(this.values,t)}},ce=class extends it{constructor(t){super(t);let{bitWidth:r,scale:n}=this.type;this.decimal=r===128?fn:dn,this.scale=10n**BigInt(n)}},fe=class extends ce{static ArrayType=Z;value(t){return re(this.decimal(this.values,t),this.scale)}},de=class extends ce{static ArrayType=Array;value(t){return this.decimal(this.values,t)}},zt=class extends I{constructor(t){super(t),this.source=t}value(t){return new Date(this.source.value(t))}},ue=class extends jt{value(t){return 864e5*this.values[t]}},mn=P,le=class extends P{value(t){return super.value(t)*1e3}},yn=P,pe=class extends P{value(t){return re(this.values[t],1000n)}},he=class extends P{value(t){return re(this.values[t],1000000n)}},me=class extends I{value(t){return this.values.subarray(t<<1,t+1<<1)}},ye=class extends I{value(t){let r=this.values,n=t<<4;return Float64Array.of(y(r,n),y(r,n+4),D(r,n+8))}},xn=({values:e,offsets:t},r)=>e.subarray(t[r],t[r+1]),In=({values:e,offsets:t},r)=>e.subarray(G(t[r]),G(t[r+1])),xe=class extends I{value(t){return xn(this,t)}},Ie=class extends I{value(t){return In(this,t)}},ge=class extends I{value(t){return gt(xn(this,t))}},we=class extends I{value(t){return gt(In(this,t))}},Oe=class extends I{value(t){let r=this.offsets;return this.children[0].slice(r[t],r[t+1])}},ve=class extends I{value(t){let r=this.offsets;return this.children[0].slice(G(r[t]),G(r[t+1]))}},Ae=class extends I{value(t){let r=this.offsets[t],n=r+this.sizes[t];return this.children[0].slice(r,n)}},De=class extends I{value(t){let r=this.offsets[t],n=r+this.sizes[t];return this.children[0].slice(G(r),G(n))}},Ee=class extends I{constructor(t){super(t),this.stride=this.type.stride}},Le=class extends Ee{value(t){let{stride:r,values:n}=this;return n.subarray(t*r,(t+1)*r)}},Be=class extends Ee{value(t){let{children:r,stride:n}=this;return r[0].slice(t*n,(t+1)*n)}};function gn({children:e,offsets:t},r){let[n,s]=e[0].children,o=t[r],i=t[r+1],c=[];for(let f=o;f<i;++f)c.push([n.at(f),s.at(f)]);return c}var Te=class extends I{value(t){return gn(this,t)}},be=class extends I{value(t){return new Map(gn(this,t))}},Rt=class extends I{constructor({typeIds:t,...r}){super(r),this.typeIds=t,this.typeMap=this.type.typeMap}value(t,r=t){let{typeIds:n,children:s,typeMap:o}=this;return s[o[n[t]]].at(r)}},Se=class extends Rt{value(t){return super.value(t,this.offsets[t])}},_t=class extends I{constructor(t,r=oe){super(t),this.names=this.type.children.map(n=>n.name),this.factory=r(this.names,this.children)}value(t){return this.factory(t)}},Fe=class extends _t{constructor(t){super(t,kt)}},Me=class extends I{value(t){let[{values:r},n]=this.children;return n.at(pt(r,t))}},Ne=class extends I{setDictionary(t){return this.dictionary=t,this.cache=t.cache(),this}value(t){return this.cache[this.key(t)]}key(t){return this.values[t]}},Ve=class extends I{constructor({data:t,...r}){super(r),this.data=t}view(t){let{values:r,data:n}=this,s=t<<4,o=s+4,i=r,c=y(i,s);return c>12&&(o=y(i,s+12),i=n[y(i,s+8)]),i.subarray(o,o+c)}},Ue=class extends Ve{value(t){return this.view(t)}},Ce=class extends Ve{value(t){return gt(this.view(t))}};function Cr(){let e=[];return{add(t){return e.push(t),this},clear:()=>e=[],done:()=>new $(e)}}var $=class{constructor(t){this.type=t[0].type,this.length=t.reduce((s,o)=>s+o.length,0),this.nullCount=t.reduce((s,o)=>s+o.nullCount,0),this.data=t;let r=t.length,n=new Int32Array(r+1);if(r===1){let[s]=t;n[1]=s.length,this.at=o=>s.at(o)}else for(let s=0,o=0;s<r;++s)n[s+1]=o+=t[s].length;this.offsets=n}get[Symbol.toStringTag](){return"Column"}[Symbol.iterator](){let t=this.data;return t.length===1?t[0][Symbol.iterator]():ts(t)}at(t){let{data:r,offsets:n}=this,s=pt(n,t)-1;return r[s]?.at(t-n[s])}get(t){return this.at(t)}toArray(){let{length:t,nullCount:r,data:n}=this,s=!r&&hn(n[0]),o=n.length;if(s&&o===1)return n[0].values;let i=!o||r>0?Array:n[0].constructor.ArrayType??n[0].values.constructor,c=new i(t);return s?es(c,n):rs(c,n)}cache(){return this._cache??(this._cache=this.toArray())}};function*ts(e){for(let t=0;t<e.length;++t){let r=e[t][Symbol.iterator]();for(let n=r.next();!n.done;n=r.next())yield n.value}}function es(e,t){for(let r=0,n=0;r<t.length;++r){let{values:s}=t[r];e.set(s,n),n+=s.length}return e}function rs(e,t){let r=-1;for(let n=0;n<t.length;++n){let s=t[n];for(let o=0;o<s.length;++o)e[++r]=s.at(o)}return e}var at=class e{constructor(t,r,n=!1){let s=t.fields.map(i=>i.name);this.schema=t,this.names=s,this.children=r,this.factory=n?kt:oe;let o=[];this.getFactory=i=>o[i]??(o[i]=this.factory(s,r.map(c=>c.data[i])))}get[Symbol.toStringTag](){return"Table"}get numCols(){return this.names.length}get numRows(){return this.children[0]?.length??0}getChildAt(t){return this.children[t]}getChild(t){let r=this.names.findIndex(n=>n===t);return r>-1?this.children[r]:void 0}selectAt(t,r=[]){let{children:n,factory:s,schema:o}=this,{fields:i}=o;return new e({...o,fields:t.map((c,f)=>ns(i[c],r[f]))},t.map(c=>n[c]),s===kt)}select(t,r){let n=this.names,s=t.map(o=>n.indexOf(o));return this.selectAt(s,r)}toColumns(){let{children:t,names:r}=this,n={};return r.forEach((s,o)=>n[s]=t[o]?.toArray()??[]),n}toArray(){let{children:t,getFactory:r,numRows:n}=this,s=t[0]?.data??[],o=Array(n);for(let i=0,c=-1;i<s.length;++i){let f=r(i);for(let d=0;d<s[i].length;++d)o[++c]=f(d)}return o}*[Symbol.iterator](){let{children:t,getFactory:r}=this,n=t[0]?.data??[];for(let s=0;s<n.length;++s){let o=r(s);for(let i=0;i<n[s].length;++i)yield o(i)}}at(t){let{children:r,getFactory:n,numRows:s}=this;if(t<0||t>=s)return null;let[{offsets:o}]=r,i=pt(o,t)-1;return n(i)(t-o[i])}get(t){return this.at(t)}};function ns(e,t){return t!=null&&t!==e.name?{...e,name:t}:e}function ct(e,t={}){let{typeId:r,bitWidth:n,precision:s,unit:o}=e,{useBigInt:i,useDate:c,useDecimalBigInt:f,useMap:d,useProxy:u}=t;switch(r){case a.Null:return Ot;case a.Bool:return ae;case a.Int:case a.Time:case a.Duration:return i||n<64?J:P;case a.Float:return s?J:ie;case a.Date:return wn(o===V.DAY?ue:mn,c&&zt);case a.Timestamp:return wn(o===x.SECOND?le:o===x.MILLISECOND?yn:o===x.MICROSECOND?pe:he,c&&zt);case a.Decimal:return f?de:fe;case a.Interval:return o===T.DAY_TIME?me:o===T.YEAR_MONTH?J:ye;case a.FixedSizeBinary:return Le;case a.Utf8:return ge;case a.LargeUtf8:return we;case a.Binary:return xe;case a.LargeBinary:return Ie;case a.BinaryView:return Ue;case a.Utf8View:return Ce;case a.List:return Oe;case a.LargeList:return ve;case a.Map:return d?be:Te;case a.ListView:return Ae;case a.LargeListView:return De;case a.FixedSizeList:return Be;case a.Struct:return u?Fe:_t;case a.RunEndEncoded:return Me;case a.Dictionary:return Ne;case a.Union:return e.mode?Se:Rt}throw new Error(U(r))}function wn(e,t){return t?class extends t{constructor(n){super(new e(n))}}:e}function ss(e,t){return{offset:D(e,t),metadataLength:y(e,t+8),bodyLength:D(e,t+16)}}function kr(e,t){return N(e,t,24,ss)}function ke(e,t,r){let n=B(e,t);if(n(10,_,0))throw new Error("Record batch compression not implemented");let s=r<E.V4?8:0;return{length:n(4,D,0),nodes:N(e,n(6,_),16,(o,i)=>({length:D(o,i),nullCount:D(o,i+8)})),regions:N(e,n(8,_),16+s,(o,i)=>({offset:D(o,i+s),length:D(o,i+s+8)})),variadic:N(e,n(12,_),8,D)}}function On(e,t,r){let n=B(e,t);return{id:n(4,D,0),data:n(6,(s,o)=>ke(s,o,r)),isDelta:n(8,Q,!1)}}function jr(e,t,r,n){F(r,a,U);let s=B(e,t);switch(r){case a.Binary:return gr();case a.Utf8:return Ft();case a.LargeBinary:return Tr();case a.LargeUtf8:return br();case a.List:return Vt(n[0]);case a.ListView:return Mr(n[0]);case a.LargeList:return Sr(n[0]);case a.LargeListView:return Nr(n[0]);case a.Struct:return yt(n);case a.RunEndEncoded:return Fr(n[0],n[1]);case a.Int:return z(s(4,y,0),s(6,Q,!1));case a.Float:return ht(s(4,w,H.HALF));case a.Decimal:return Or(s(4,y,0),s(6,y,0),s(8,y,128));case a.Date:return Mt(s(4,w,V.MILLISECOND));case a.Time:return st(s(4,w,x.MILLISECOND),s(6,y,32));case a.Timestamp:return Nt(s(4,w,x.SECOND),s(6,ot));case a.Interval:return Ar(s(4,w,T.YEAR_MONTH));case a.Duration:return Br(s(4,w,x.MILLISECOND));case a.FixedSizeBinary:return Er(s(4,y,0));case a.FixedSizeList:return Ut(n[0],s(4,y,0));case a.Map:return Lr(s(4,Q,!1),n[0]);case a.Union:return Dr(s(4,w,j.Sparse),n,N(e,s(6,_),4,y))}return{typeId:r}}function Pt(e,t){let r=N(e,t,4,(n,s)=>{let o=B(n,s);return[o(4,ot),o(6,ot)]});return r.length?new Map(r):null}function je(e,t,r){let n=B(e,t);return{version:r,endianness:n(4,w,0),fields:n(6,os,[]),metadata:n(8,Pt)}}function os(e,t){return N(e,t,4,vn)}function vn(e,t){let r=B(e,t),n=r(8,Ct,a.NONE),s=r(10,_,0),o=r(12,as),i=r(14,(f,d)=>is(f,d)),c=jr(e,s,n,i);return o&&(o.dictionary=c,c=o),{name:r(4,ot),type:c,nullable:r(6,Q,!1),metadata:r(16,Pt)}}function is(e,t){let r=N(e,t,4,vn);return r.length?r:null}function as(e,t){if(!t)return null;let r=B(e,t);return Bt(null,r(6,cs,q()),r(8,Q,!1),r(4,D,0))}function cs(e,t){return jr(e,t,a.Int)}var fs=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,ds=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,us=e=>`Unsupported message type: ${e} (${qt(L,e)})`;function ze(e,t){let r=y(e,t)||0;if(t+=C,r===-1&&(r=y(e,t)||0,t+=C),r===0)return null;let n=e.subarray(t,t+=r);if(n.byteLength<r)throw new Error(fs(r,n.byteLength));let s=B(n,0),o=s(4,w,E.V1),i=s(6,Ct,L.NONE),c=s(8,_,0),f=s(10,D,0),d;if(c){let u=i===L.Schema?je:i===L.DictionaryBatch?On:i===L.RecordBatch?ke:null;if(!u)throw new Error(us(i));if(d=u(n,c,o),f>0){let p=e.subarray(t,t+=f);if(p.byteLength<f)throw new Error(ds(f,p.byteLength));d.body=p}}return{version:o,type:i,index:t,content:d}}function An(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;return!Array.isArray(t)&&ls(t)?hs(t):ps(t)}function ls(e){if(!e||e.length<4)return!1;for(let t=0;t<6;++t)if(rt[t]!==e[t])return!1;return!0}function ps(e){let t=[e].flat(),r,n=[],s=[];for(let o of t){let i=0;for(;;){let c=ze(o,i);if(c===null)break;if(i=c.index,!!c.content)switch(c.type){case L.Schema:r||(r=c.content);break;case L.RecordBatch:n.push(c.content);break;case L.DictionaryBatch:s.push(c.content);break}}}return{schema:r,dictionaries:s,records:n,metadata:null}}function hs(e){let t=e.byteLength-(rt.length+4),r=y(e,t),n=B(e,t-r),s=n(4,w,E.V1),o=n(8,kr,[]),i=n(10,kr,[]);return{schema:n(6,(c,f)=>je(c,f,s)),dictionaries:o.map(({offset:c})=>ze(e,c).content),records:i.map(({offset:c})=>ze(e,c).content),metadata:n(12,Pt)}}function ms(e,t){return ys(An(e),t)}function ys(e,t={}){let{schema:r={fields:[]},dictionaries:n,records:s}=e,{version:o,fields:i}=r,c=new Map,f=Is(t,o,c),d=new Map;xs(r,h=>{let l=h.type;l.typeId===a.Dictionary&&d.set(l.id,l.dictionary)});let u=new Map;for(let h of n){let{id:l,data:A,isDelta:v,body:ft}=h,Dt=d.get(l),dt=zr(Dt,f({...A,body:ft}));if(u.has(l)){let m=u.get(l);v||m.clear(),m.add(dt)}else{if(v)throw new Error("Delta update can not be first dictionary batch.");u.set(l,Cr().add(dt))}}u.forEach((h,l)=>c.set(l,h.done()));let p=i.map(()=>Cr());for(let h of s){let l=f(h);i.forEach((A,v)=>p[v].add(zr(A.type,l)))}return new at(r,p.map(h=>h.done()),t.useProxy)}function xs(e,t){e.fields.forEach(function r(n){t(n),n.type.dictionary?.children?.forEach(r),n.type.children?.forEach(r)})}function Is(e,t,r){let n={version:t,options:e,dictionary:s=>r.get(s)};return s=>{let{length:o,nodes:i,regions:c,variadic:f,body:d}=s,u=-1,p=-1,h=-1;return{...n,length:o,node:()=>i[++u],buffer:l=>{let{length:A,offset:v}=c[++p];return l?new l(d.buffer,d.byteOffset+v,A/l.BYTES_PER_ELEMENT):d.subarray(v,v+A)},variadic:()=>f[++h],visit(l){return l.map(A=>zr(A.type,this))}}}}function zr(e,t){let{typeId:r}=e,{length:n,options:s,node:o,buffer:i,variadic:c,version:f}=t,d=ct(e,s);if(r===a.Null)return new d({length:n,nullCount:n,type:e});let u={...o(),type:e};switch(r){case a.Bool:case a.Int:case a.Time:case a.Duration:case a.Float:case a.Decimal:case a.Date:case a.Timestamp:case a.Interval:case a.FixedSizeBinary:return new d({...u,validity:i(),values:i(e.values)});case a.Utf8:case a.LargeUtf8:case a.Binary:case a.LargeBinary:return new d({...u,validity:i(),offsets:i(e.offsets),values:i()});case a.BinaryView:case a.Utf8View:return new d({...u,validity:i(),values:i(),data:Array.from({length:c()},()=>i())});case a.List:case a.LargeList:case a.Map:return new d({...u,validity:i(),offsets:i(e.offsets),children:t.visit(e.children)});case a.ListView:case a.LargeListView:return new d({...u,validity:i(),offsets:i(e.offsets),sizes:i(e.offsets),children:t.visit(e.children)});case a.FixedSizeList:case a.Struct:return new d({...u,validity:i(),children:t.visit(e.children)});case a.RunEndEncoded:return new d({...u,children:t.visit(e.children)});case a.Dictionary:{let{id:p,indices:h}=e;return new d({...u,validity:i(),values:i(h.values)}).setDictionary(t.dictionary(p))}case a.Union:return f<E.V5&&i(),new d({...u,typeIds:i(nt),offsets:e.mode===j.Sparse?null:i(e.offsets),children:t.visit(e.children)});default:throw new Error(U(r))}}function Rr(e,t,r){e[t]=r,e[t+1]=r>>8,e[t+2]=r>>16,e[t+3]=r>>24}var Re=1024,_e=class{constructor(t){this.sink=t,this.minalign=1,this.buf=new Uint8Array(Re),this.space=Re,this.vtables=[],this.outputBytes=0}offset(){return this.buf.length-this.space}writeInt8(t){this.buf[this.space-=1]=t}writeInt16(t){this.buf[this.space-=2]=t,this.buf[this.space+1]=t>>8}writeInt32(t){Rr(this.buf,this.space-=4,t)}writeInt64(t){let r=BigInt(t);this.writeInt32(Number(BigInt.asIntN(32,r>>BigInt(32)))),this.writeInt32(Number(BigInt.asIntN(32,r)))}addInt8(t){K(this,1,0),this.writeInt8(t)}addInt16(t){K(this,2,0),this.writeInt16(t)}addInt32(t){K(this,4,0),this.writeInt32(t)}addInt64(t){K(this,8,0),this.writeInt64(t)}addOffset(t){K(this,C,0),this.writeInt32(this.offset()-t+C)}addObject(t,r){let n=gs(this,t);return r?.(n),n.finish()}addVector(t,r,n,s){let o=t?.length;if(!o)return 0;K(this,C,r*o),K(this,n,r*o);for(let i=o;--i>=0;)s(this,t[i]);return this.writeInt32(o),this.offset()}addOffsetVector(t){return this.addVector(t,4,4,(r,n)=>r.addOffset(n))}addString(t){if(t==null)return 0;let r=ne(t),n=r.length;return this.addInt8(0),K(this,C,n),this.buf.set(r,this.space-=n),this.writeInt32(n),this.offset()}finish(t){K(this,this.minalign,C),this.addOffset(t)}flush(){let{buf:t,sink:r}=this,n=t.subarray(this.space,t.length);r.write(n),this.outputBytes+=n.byteLength,this.minalign=1,this.vtables=[],this.buf=new Uint8Array(Re),this.space=Re}addBuffer(t){let r=t.byteLength;if(!r)return 0;this.sink.write(t),this.outputBytes+=r;let n=(r+7&-8)-r;return this.addPadding(n),r+n}addPadding(t){t>0&&(this.sink.write(new Uint8Array(t)),this.outputBytes+=t)}};function K(e,t,r){let{buf:n,space:s,minalign:o}=e;t>o&&(e.minalign=t);let i=n.length,c=i-s+r,f=~c+1&t-1;n=Kt(n,c+f+t-1,!0),s+=n.length-i;for(let d=0;d<f;++d)n[--s]=0;e.buf=n,e.space=s}function gs(e,t){let r=Array(t).fill(0),n=e.offset();function s(o){r[o]=e.offset()}return{addInt8(o,i,c){i!=c&&(e.addInt8(i),s(o))},addInt16(o,i,c){i!=c&&(e.addInt16(i),s(o))},addInt32(o,i,c){i!=c&&(e.addInt32(i),s(o))},addInt64(o,i,c){i!=c&&(e.addInt64(i),s(o))},addOffset(o,i,c){i!=c&&(e.addOffset(i),s(o))},finish(){e.addInt32(0);let o=e.offset(),i=t;for(;--i>=0&&r[i]===0;);let c=i+1;for(;i>=0;--i)e.addInt16(r[i]?o-r[i]:0);let f=2;e.addInt16(o-n);let d=(c+f)*se;e.addInt16(d);let u=0,{buf:p,vtables:h,space:l}=e;t:for(i=0;i<h.length;++i){let A=p.length-h[i];if(d==w(p,A)){for(let v=se;v<d;v+=se)if(w(p,l+v)!=w(p,A+v))continue t;u=h[i];break}}if(u)e.space=p.length-o,Rr(p,e.space,u-o);else{let A=e.offset();h.push(A),Rr(p,p.length-o,A-o)}return o}}}function Pe(e,t){let{nodes:r,regions:n,variadic:s}=t,o=e.addVector(r,16,8,(f,d)=>(f.writeInt64(d.nullCount),f.writeInt64(d.length),f.offset())),i=e.addVector(n,16,8,(f,d)=>(f.writeInt64(d.length),f.writeInt64(d.offset),f.offset())),c=e.addVector(s,8,8,(f,d)=>f.addInt64(d));return e.addObject(5,f=>{f.addInt64(0,r[0].length,0),f.addOffset(1,o,0),f.addOffset(2,i,0),f.addOffset(4,c,0)})}function Dn(e,t){let r=Pe(e,t.data);return e.addObject(3,n=>{n.addInt64(0,t.id,0),n.addOffset(1,r,0),n.addInt8(2,+t.isDelta,0)})}function $t(e,t){return t?.size>0?e.addOffsetVector(Array.from(t,([r,n])=>{let s=e.addString(`${r}`),o=e.addString(`${n}`);return e.addObject(2,i=>{i.addOffset(0,s,0),i.addOffset(1,o,0)})})):0}function Ht(e,t){switch(F(t.typeId,a,U)){case a.Dictionary:return Fs(e,t);case a.Int:return Es(e,t);case a.Float:return Ds(e,t);case a.Decimal:return Os(e,t);case a.Date:return ws(e,t);case a.Time:return Ts(e,t);case a.Timestamp:return bs(e,t);case a.Interval:return Ls(e,t);case a.Duration:return vs(e,t);case a.FixedSizeBinary:case a.FixedSizeList:return As(e,t);case a.Map:return Bs(e,t);case a.Union:return Ss(e,t)}return e.addObject(0)}function ws(e,t){return e.addObject(1,r=>{r.addInt16(0,t.unit,V.MILLISECOND)})}function Os(e,t){return e.addObject(3,r=>{r.addInt32(0,t.precision,0),r.addInt32(1,t.scale,0),r.addInt32(2,t.bitWidth,128)})}function vs(e,t){return e.addObject(1,r=>{r.addInt16(0,t.unit,x.MILLISECOND)})}function As(e,t){return e.addObject(1,r=>{r.addInt32(0,t.stride,0)})}function Ds(e,t){return e.addObject(1,r=>{r.addInt16(0,t.precision,H.HALF)})}function Es(e,t){return e.addObject(2,r=>{r.addInt32(0,t.bitWidth,0),r.addInt8(1,+t.signed,0)})}function Ls(e,t){return e.addObject(1,r=>{r.addInt16(0,t.unit,T.YEAR_MONTH)})}function Bs(e,t){return e.addObject(1,r=>{r.addInt8(0,+t.keysSorted,0)})}function Ts(e,t){return e.addObject(2,r=>{r.addInt16(0,t.unit,x.MILLISECOND),r.addInt32(1,t.bitWidth,32)})}function bs(e,t){let r=e.addString(t.timezone);return e.addObject(2,n=>{n.addInt16(0,t.unit,x.SECOND),n.addOffset(1,r,0)})}function Ss(e,t){let r=e.addVector(t.typeIds,4,4,(n,s)=>n.addInt32(s));return e.addObject(2,n=>{n.addInt16(0,t.mode,j.Sparse),n.addOffset(1,r,0)})}function Fs(e,t){let r=Ms(t.indices)?0:Ht(e,t.indices);return e.addObject(4,n=>{n.addInt64(0,t.id,0),n.addOffset(1,r,0),n.addInt8(2,+t.ordered,0)})}function Ms(e){return e.typeId===a.Int&&e.bitWidth===32&&e.signed}var Ns=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function $e(e,t){let{fields:r,metadata:n}=t,s=r.map(c=>En(e,c)),o=e.addOffsetVector(s),i=$t(e,n);return e.addObject(4,c=>{c.addInt16(0,+!Ns,0),c.addOffset(1,o,0),c.addOffset(2,i,0)})}function En(e,t){let{name:r,nullable:n,type:s,metadata:o}=t,{typeId:i}=s,c=0,f=0;if(i!==a.Dictionary)c=Ht(e,s);else{let l=s.dictionary;i=l.typeId,f=Ht(e,s),c=Ht(e,l)}let d=(s.children||[]).map(l=>En(e,l)),u=e.addOffsetVector(d),p=$t(e,o),h=e.addString(r);return e.addObject(7,l=>{l.addOffset(0,h,0),l.addInt8(1,+n,0),l.addInt8(2,i,a.NONE),l.addOffset(3,c,0),l.addOffset(4,f,0),l.addOffset(5,u,0),l.addOffset(6,p,0)})}function Bn(e,t,r,n,s){let o=$t(e,s),i=e.addVector(n,24,8,Ln),c=e.addVector(r,24,8,Ln),f=$e(e,t);e.finish(e.addObject(5,u=>{u.addInt16(0,E.V5,E.V1),u.addOffset(1,f,0),u.addOffset(2,c,0),u.addOffset(3,i,0),u.addOffset(4,o,0)}));let d=e.offset();e.addInt32(0),e.addInt32(-1),e.flush(),e.sink.write(new Uint8Array(Int32Array.of(d).buffer)),e.sink.write(rt)}function Ln(e,{offset:t,metadataLength:r,bodyLength:n}){return e.writeInt64(n),e.writeInt32(0),e.writeInt32(r),e.writeInt64(t),e.offset()}function He(e,t,r,n,s){e.finish(e.addObject(5,f=>{f.addInt16(0,E.V5,E.V1),f.addInt8(1,t,L.NONE),f.addOffset(2,r,0),f.addInt64(3,n,0)}));let o=8,i=e.offset(),c=i+o+7&-8;s?.push({offset:e.outputBytes,metadataLength:c,bodyLength:n}),e.addInt32(c-o),e.addInt32(-1),e.flush(),e.addPadding(c-i-o)}var _r=class{write(t){}pad(t){this.write(new Uint8Array(t))}finish(){return null}},Ye=class extends _r{constructor(){super(),this.buffers=[]}write(t){this.buffers.push(t)}finish(){let t=this.buffers,r=t.reduce((s,o)=>s+o.byteLength,0),n=new Uint8Array(r);for(let s=0,o=0;s<t.length;++s)n.set(t[s],o),o+=t[s].byteLength;return n}};var Tn="stream",bn="file";function Fn(e,{sink:t,format:r=Tn}={}){if(r!==Tn&&r!==bn)throw new Error(`Unrecognized Arrow IPC format: ${r}`);let{schema:n,dictionaries:s=[],records:o=[],metadata:i}=e,c=new _e(t||new Ye),f=r===bn,d=[],u=[];f?c.addBuffer(rt):n&&He(c,L.Schema,$e(c,n),0);for(let p of s){let{data:h}=p;He(c,L.DictionaryBatch,Dn(c,p),h.byteLength,d),Sn(c,h.buffers)}for(let p of o)He(c,L.RecordBatch,Pe(c,p),p.byteLength,u),Sn(c,p.buffers);return f&&Bn(c,n,d,u,i),c.sink}function Sn(e,t){for(let r=0;r<t.length;++r)e.addBuffer(t[r])}function Vs(e,t){typeof t=="string"&&(t={format:t});let r=e.children,{dictionaries:n,idMap:s}=Cs(r),o=js(r),c={schema:ks(e.schema,s),dictionaries:n,records:o};return Fn(c,t).finish()}function Us(){let e=0,t=[],r=[],n=[],s=[];return{node(o,i){t.push({length:o,nullCount:i})},buffer(o){let i=o.byteLength,c=i+7&-8;r.push({offset:e,length:c}),e+=c,n.push(new Uint8Array(o.buffer,o.byteOffset,i))},variadic(o){s.push(o)},children(o,i){o.children.forEach((c,f)=>{Nn(c.type,i.children[f],this)})},done(){return{byteLength:e,nodes:t,regions:r,variadic:s,buffers:n}}}}function Cs(e){let t=[],r=new Map,n=new Map,s=-1,o=i=>{if(r.has(i))n.set(i.type,r.get(i));else{r.set(i,++s);for(let c=0;c<i.data.length;++c)t.push({id:s,isDelta:c>0,data:Mn([i],c)});n.set(i.type,s)}};return e.forEach(i=>Pr(i.data[0],o)),{dictionaries:t,idMap:n}}function Pr(e,t){if(e?.type.typeId===a.Dictionary){let r=e.dictionary;t(r),Pr(r.data[0],t)}e?.children?.forEach(r=>Pr(r,t))}function ks(e,t){if(!t.size)return e;let r=o=>{o.typeId===a.Dictionary&&(o.id=t.get(o.dictionary),s(o)),o.children&&(o.children=o.children.slice()).forEach(n)},n=(o,i,c)=>{let f={...o.type};c[i]={...o,type:f},r(f)},s=o=>{let i={...o.dictionary};o.dictionary=i,r(i)};return e={...e,fields:e.fields.slice()},e.fields.forEach(n),e}function js(e){return(e[0]?.data||[]).map((t,r)=>Mn(e,r))}function Mn(e,t=0){let r=Us();return e.forEach(n=>{Nn(n.type,n.data[t],r)}),r.done()}function Nn(e,t,r){let{typeId:n}=e;if(n!==a.Null)switch(r.node(t.length,t.nullCount),n){case a.Bool:case a.Int:case a.Time:case a.Duration:case a.Float:case a.Date:case a.Timestamp:case a.Decimal:case a.Interval:case a.FixedSizeBinary:case a.Dictionary:r.buffer(t.validity),r.buffer(t.values);return;case a.Utf8:case a.LargeUtf8:case a.Binary:case a.LargeBinary:r.buffer(t.validity),r.buffer(t.offsets),r.buffer(t.values);return;case a.BinaryView:case a.Utf8View:r.buffer(t.validity),r.buffer(t.values),r.variadic(t.data.length),t.data.forEach(s=>r.buffer(s));return;case a.List:case a.LargeList:case a.Map:r.buffer(t.validity),r.buffer(t.offsets),r.children(e,t);return;case a.ListView:case a.LargeListView:r.buffer(t.validity),r.buffer(t.offsets),r.buffer(t.sizes),r.children(e,t);return;case a.FixedSizeList:case a.Struct:r.buffer(t.validity),r.children(e,t);return;case a.RunEndEncoded:r.children(e,t);return;case a.Union:{r.buffer(t.typeIds),e.mode===j.Dense&&r.buffer(t.offsets),r.children(e,t);return}default:throw new Error(U(n))}}function O(e){return new Ge(e)}var Ge=class{constructor(t=W){this.buf=new t(512)}array(t){return Xr(this.buf,t)}prep(t){t>=this.buf.length&&(this.buf=Kt(this.buf,t))}get(t){return this.buf[t]}set(t,r){this.prep(r),this.buf[r]=t}write(t,r){this.prep(r+t.length),this.buf.set(t,r)}};function We(){return new $r}var $r=class extends Ge{set(t){let r=t>>3;this.prep(r),this.buf[r]|=1<<t%8}};var tt=class{constructor(t,r){this.type=t,this.ctx=r,this.batchClass=r.batchType(t)}init(){return this.index=-1,this}set(t,r){return this.index=r,!1}done(){return null}batch(){let t=new this.batchClass(this.done());return this.init(),t}};var g=class extends tt{constructor(t,r){super(t,r)}init(){return this.nullCount=0,this.validity=We(),super.init()}set(t,r){this.index=r;let n=t!=null;return n?this.validity.set(r):this.nullCount++,n}done(){let{index:t,nullCount:r,type:n,validity:s}=this;return{length:t+1,nullCount:r,type:n,validity:r?s.array((t>>3)+1):new W(0)}}};var vt=class extends g{constructor(t,r){super(t,r),this.toOffset=ee(t.offsets)}init(){return this.offsets=O(this.type.offsets),this.values=O(),this.pos=0,super.init()}set(t,r){let{offsets:n,values:s,toOffset:o}=this;super.set(t,r)&&(s.write(t,this.pos),this.pos+=t.length),n.set(o(this.pos),r+1)}done(){return{...super.done(),offsets:this.offsets.array(this.index+2),values:this.values.array(this.pos+1)}}};var Ze=class extends g{constructor(t,r){super(t,r)}init(){return this.values=We(),super.init()}set(t,r){super.set(t,r),t&&this.values.set(r)}done(){return{...super.done(),values:this.values.array((this.index>>3)+1)}}};var Je=class extends g{constructor(t,r){super(t,r),this.scale=10**t.scale,this.stride=t.bitWidth>>6}init(){return this.values=O(this.type.values),super.init()}set(t,r){let{scale:n,stride:s,values:o}=this;super.set(t,r)&&(o.prep((r+1)*s),cn(t,o.buf,r*s,s,n))}done(){let{index:t,stride:r,values:n}=this;return{...super.done(),values:n.array((t+1)*r)}}};var Ke=class extends g{constructor(t,r){super(t,r),this.stride=t.stride}init(){return this.values=O(),super.init()}set(t,r){super.set(t,r)&&this.values.write(t,r*this.stride)}done(){let{stride:t,values:r}=this;return{...super.done(),values:r.array(t*(this.index+1))}}};var Xe=class extends g{constructor(t,r){super(t,r),this.child=M(this.type.children[0].type,this.ctx),this.stride=t.stride}init(){return this.child.init(),super.init()}set(t,r){let{child:n,stride:s}=this,o=r*s;if(super.set(t,r))for(let i=0;i<s;++i)n.set(t[i],o+i);else n.index=o+s}done(){let{child:t}=this;return{...super.done(),children:[t.batch()]}}};var qe=class extends g{init(){return this.values=O(this.type.values),super.init()}set(t,r){if(super.set(t,r)){let n=r<<1;this.values.set(t[0],n),this.values.set(t[1],n+1)}}done(){return{...super.done(),values:this.values.array(this.index+1<<1)}}},Qe=class extends g{init(){return this.values=O(),super.init()}set(t,r){super.set(t,r)&&this.values.write(an(t),r<<4)}done(){return{...super.done(),values:this.values.array(this.index+1<<4)}}};var Yt=class extends g{constructor(t,r,n){super(t,r),this.child=n}init(){this.child.init();let t=this.type.offsets;return this.offsets=O(t),this.toOffset=ee(t),this.pos=0,super.init()}done(){return{...super.done(),offsets:this.offsets.array(this.index+2),children:[this.child.batch()]}}},tr=class extends Yt{constructor(t,r){super(t,r,M(t.children[0].type,r))}set(t,r){let{child:n,offsets:s,toOffset:o}=this;super.set(t,r)&&t.forEach(i=>n.set(i,this.pos++)),s.set(o(this.pos),r+1)}};var Gt=class extends g{constructor(t,r){super(t,r),this.children=t.children.map(n=>M(n.type,r))}init(){return this.children.forEach(t=>t.init()),super.init()}done(){let{children:t}=this;return t.forEach(r=>r.index=this.index),{...super.done(),children:t.map(r=>r.batch())}}},er=class extends Gt{constructor(t,r){super(t,r),this.setters=this.children.map((n,s)=>{let o=t.children[s].name;return(i,c)=>n.set(i?.[o],c)})}set(t,r){super.set(t,r);let n=this.setters;for(let s=0;s<n.length;++s)n[s](t,r)}};var rr=class extends Yt{constructor(t,r){super(t,r,new Hr(t.children[0].type,r))}set(t,r){let{child:n,offsets:s,toOffset:o}=this;if(super.set(t,r))for(let i of t)n.set(i,this.pos++);s.set(o(this.pos),r+1)}},Hr=class extends Gt{set(t,r){super.set(t,r);let[n,s]=this.children;n.set(t[0],r),s.set(t[1],r)}};var zs={},nr=class extends tt{constructor(t,r){super(t,r),this.children=t.children.map(n=>M(n.type,r))}init(){return this.pos=0,this.key=null,this.value=zs,this.children.forEach(t=>t.init()),super.init()}next(){let[t,r]=this.children;t.set(this.index+1,this.pos),r.set(this.value,this.pos++)}set(t,r){if(t!==this.value){let n=wt(t);n!==this.key&&(this.key&&this.next(),this.key=n,this.value=t)}this.index=r}done(){this.next();let{children:t,index:r,type:n}=this;return{length:r+1,nullCount:0,type:n,children:t.map(s=>s.batch())}}};var sr=class extends tt{constructor(t,r){super(t,r),this.children=t.children.map(n=>M(n.type,r)),this.typeMap=t.typeMap,this.lookup=t.typeIdForValue}init(){return this.nullCount=0,this.typeIds=O(nt),this.children.forEach(t=>t.init()),super.init()}set(t,r){let{children:n,lookup:s,typeMap:o,typeIds:i}=this;this.index=r;let c=s(t,r),f=n[o[c]];i.set(c,r),t==null&&++this.nullCount,this.update(t,r,f)}done(){let{children:t,nullCount:r,type:n,typeIds:s}=this,o=this.index+1;return{length:o,nullCount:r,type:n,typeIds:s.array(o),children:t.map(i=>i.batch())}}},or=class extends sr{update(t,r,n){n.set(t,r),this.children.forEach(s=>{s!==n&&s.set(null,r)})}},ir=class extends sr{init(){return this.offsets=O(this.type.offsets),super.init()}update(t,r,n){let s=n.index+1;n.set(t,s),this.offsets.set(s,r)}done(){return{...super.done(),offsets:this.offsets.array(this.index+1)}}};var ar=class extends vt{set(t,r){super.set(t&&ne(t),r)}};var et=class extends g{constructor(t,r){super(t,r),this.values=O(t.values)}init(){return this.values=O(this.type.values),super.init()}set(t,r){super.set(t,r)&&this.values.set(t,r)}done(){return{...super.done(),values:this.values.array(this.index+1)}}},cr=class extends et{set(t,r){super.set(t==null?t:R(t),r)}},At=class extends et{constructor(t,r,n){super(t,r),this.transform=n}set(t,r){super.set(t==null?t:this.transform(t),r)}};function Yr(e={},t=Wt()){return{batchType:r=>ct(r,e),dictionary(r){return t.get(r,this)},finish:()=>t.finish(e)}}function M(e,t=Yr()){let{typeId:r}=e;switch(r){case a.Int:case a.Time:case a.Duration:return lt(e.values)?new cr(e,t):new et(e,t);case a.Float:return e.precision?new et(e,t):new At(e,t,un);case a.Binary:case a.LargeBinary:return new vt(e,t);case a.Utf8:case a.LargeUtf8:return new ar(e,t);case a.Bool:return new Ze(e,t);case a.Decimal:return new Je(e,t);case a.Date:return new At(e,t,e.unit?R:sn);case a.Timestamp:return new At(e,t,on(e.unit));case a.Interval:switch(e.unit){case T.DAY_TIME:return new qe(e,t);case T.MONTH_DAY_NANO:return new Qe(e,t)}return new et(e,t);case a.List:case a.LargeList:return new tr(e,t);case a.Struct:return new er(e,t);case a.Union:return e.mode?new ir(e,t):new or(e,t);case a.FixedSizeBinary:return new Ke(e,t);case a.FixedSizeList:return new Xe(e,t);case a.Map:return new rr(e,t);case a.RunEndEncoded:return new nr(e,t);case a.Dictionary:return new fr(e,t)}throw new Error(U(r))}function Wt(){let e=new Map,t=new Set;return{get(r,n){let s=r.id;if(s>=0&&e.has(s))return e.get(s);{let o=Rs(r,n);return s>=0&&e.set(s,o),t.add(o),o}},finish(r){t.forEach(n=>n.finish(r))}}}function Rs(e,t){let r=Object.create(null),n=M(e.dictionary,t),s=[];n.init();let o=-1;return{type:e,values:n,add(i){return s.push(i),i},key(i){let c=wt(i),f=r[c];return f===void 0&&(r[c]=f=++o,n.set(i,f)),f},finish(i){let c=e.dictionary,f=new(ct(c,i))(n.done()),d=new $([f]);s.forEach(u=>u.setDictionary(d))}}}var fr=class extends g{constructor(t,r){super(t,r),this.dict=r.dictionary(t)}init(){return this.values=O(this.type.indices.values),super.init()}set(t,r){super.set(t,r)&&this.values.set(this.dict.key(t),r)}done(){return{...super.done(),values:this.values.array(this.index+1)}}batch(){return this.dict.add(super.batch())}};function Vn(e){let t=Gr();return e(r=>t.add(r)),t.type()}function Gr(){let e=0,t=0,r=0,n=0,s=0,o=0,i=0,c=0,f=0,d=0,u=0,p=1/0,h=-1/0,l=1/0,A=-1/0,v,ft,Dt,dt={};return{add(m){if(e++,m==null){t++;return}switch(typeof m){case"string":f++;break;case"number":n++,m<p&&(p=m),m>h&&(h=m),Number.isInteger(m)&&s++;break;case"bigint":o++,v===void 0?v=ft=m:(m<v&&(v=m),m>ft&&(ft=m));break;case"boolean":r++;break;case"object":if(m instanceof Date)i++,+m%864e5===0&&c++;else if(Jt(m)){d++;let k=m.length;k<l&&(l=k),k>A&&(A=k),Dt??=Gr(),m.forEach(Dt.add)}else{u++;for(let k in m)(dt[k]??(dt[k]=Gr())).add(m[k])}}},type(){let m=e-t;return m===0?pr():s===m?Ps(p,h):n===m?mt():o===m?$s(v,ft):r===m?wr():c===m?vr():i===m?Nt():f===m?Bt(Ft()):d===m?_s(Dt.type(),l,A):u===m?yt(Object.entries(dt).map(k=>X(k[0],k[1].type()))):Hs()}}}function _s(e,t,r){return r===t?Ut(e,t):Vt(e)}function Ps(e,t){let r=Math.max(Math.abs(e)-1,t);return r<128?Tt():r<32768?bt():r<2**31?q():mt()}function $s(e,t){let r=-e>t?-e-1n:t;if(r>=2**63)throw new Error(`BigInt exceeds 64 bits: ${r}`);return St()}function Hs(){throw new Error("Mixed types detected, please define a union type.")}function Wr(e,t,r,n,s){r??=Vn(t);let{maxBatchRows:o,...i}=n,c=Math.min(o||1/0,e);if(r.typeId===a.Null)return new $(Ys(r,e,c));let f=Yr(i,s),d=M(r,f).init(),u=[],p=l=>u.push(l.batch()),h=0;return t(l=>{d.set(l,h++),h>=c&&(p(d),h=0)}),h&&p(d),f.finish(),new $(u)}function Ys(e,t,r){let n=[],s=c=>new Ot({length:c,nullCount:c,type:e}),o=Math.floor(t/r);for(let c=0;c<o;++c)n.push(s(r));let i=t%r;return i&&n.push(s(i)),n}function Zr(e,t,r={},n){return!t&&lr(e)?Gs(e,r):Wr(e.length,s=>e.forEach(s),t,r,n)}function Gs(e,{maxBatchRows:t,useBigInt:r}){let n=e.constructor,s=Ws(n),o=e.length,i=Math.min(t||1/0,o),c=Math.floor(o/i),f=[],d=lt(n)&&!r?P:J,u=(h,l)=>f.push(new d({length:i,nullCount:0,type:s,values:e.subarray(h,l)})),p=0;for(let h=0;h<c;++h)u(p,p+=i);return p<o&&u(p,o),new $(f)}function Ws(e){switch(e){case Zt:return Ir();case Z:return mt();case nt:return Tt();case ur:return bt();case b:return q();case S:return St();case W:return hr();case Et:return mr();case Lt:return yr();case ut:return xr()}}function Jr(e,t){let r=[],n=Array.isArray(e)?e:Object.entries(e),s=n[0]?.[1].length,o=n.map(([c,f])=>{if(f.length!==s)throw new Error("All columns must have the same length.");return r.push(X(c,f.type)),f}),i={version:E.V5,endianness:dr.Little,fields:r,metadata:null};return new at(i,o,t)}function Zs(e,t={}){let{types:r={},...n}=t,s=Wt(),i=(Array.isArray(e)?e:Object.entries(e)).map(([c,f])=>[c,Zr(f,r[c],n,s)]);return Jr(i,t.useProxy)}export{it as Batch,$ as Column,V as DateUnit,dr as Endianness,T as IntervalUnit,H as Precision,at as Table,x as TimeUnit,a as Type,j as UnionMode,E as Version,ct as batchType,gr as binary,Hn as binaryView,wr as bool,Zr as columnFromArray,Wr as columnFromValues,Mt as date,vr as dateDay,jn as dateMillisecond,Or as decimal,Bt as dictionary,Wt as dictionaryContext,Br as duration,X as field,Er as fixedSizeBinary,Ut as fixedSizeList,ht as float,kn as float16,Ir as float32,mt as float64,z as int,bt as int16,q as int32,St as int64,Tt as int8,Ar as interval,Tr as largeBinary,Sr as largeList,Nr as largeListView,br as largeUtf8,Vt as list,Mr as listView,$n as map,pr as nullType,Fr as runEndEncoded,yt as struct,Zs as tableFromArrays,Jr as tableFromColumns,ms as tableFromIPC,Vs as tableToIPC,st as time,_n as timeMicrosecond,Rn as timeMillisecond,Pn as timeNanosecond,zn as timeSecond,Nt as timestamp,mr as uint16,yr as uint32,xr as uint64,hr as uint8,Dr as union,Ft as utf8,Yn as utf8View}; | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).fl={})}(this,(function(t){"use strict";const e=Uint8Array.of(65,82,82,79,87,49),n={V1:0,V2:1,V3:2,V4:3,V5:4},s={Little:0,Big:1},r={NONE:0,Schema:1,DictionaryBatch:2,RecordBatch:3,Tensor:4,SparseTensor:5},i={Dictionary:-1,NONE:0,Null:1,Int:2,Float:3,Binary:4,Utf8:5,Bool:6,Decimal:7,Date:8,Time:9,Timestamp:10,Interval:11,List:12,Struct:13,Union:14,FixedSizeBinary:15,FixedSizeList:16,Map:17,Duration:18,LargeBinary:19,LargeUtf8:20,LargeList:21,RunEndEncoded:22,BinaryView:23,Utf8View:24,ListView:25,LargeListView:26},a={HALF:0,SINGLE:1,DOUBLE:2},c={DAY:0,MILLISECOND:1},u={SECOND:0,MILLISECOND:1,MICROSECOND:2,NANOSECOND:3},o={YEAR_MONTH:0,DAY_TIME:1,MONTH_DAY_NANO:2},d={Sparse:0,Dense:1},l=Uint8Array,h=Uint16Array,f=Uint32Array,y=BigUint64Array,p=Int8Array,I=Int16Array,b=Int32Array,g=BigInt64Array,v=Float32Array,w=Float64Array;function m(t,e){const n=Math.log2(t)-3;return(e?[p,I,b,g]:[l,h,f,y])[n]}const x=Object.getPrototypeOf(Int8Array);function O(t){return t instanceof x}function L(t){return Array.isArray(t)||O(t)}function E(t){return t===g||t===y}function D(t,e){let n=0,s=t.length;if(s<=2147483648)do{const r=n+s>>>1;t[r]<=e?n=r+1:s=r}while(n<s);else do{const r=Math.trunc((n+s)/2);t[r]<=e?n=r+1:s=r}while(n<s);return n}function A(t,e,n=0){const s=new t.constructor(e);return s.set(t,n),s}function N(t,e,n){for(;t.length<=e;)t=A(t,t.length<<1,n?t.length:0);return t}function S(t,e,n){if(e(t))return t;throw new Error(n(t))}function B(t,e,n){return e=Array.isArray(e)?e:Object.values(e),S(t,(t=>e.includes(t)),n??(()=>`${t} must be one of ${e}`))}function M(t,e){for(const[n,s]of Object.entries(t))if(s===e)return n;return"<Unknown>"}const C=t=>`Unsupported data type: "${M(i,t)}" (id ${t})`,V=(t,e,n=!0,s=null)=>({name:t,type:e,nullable:n,metadata:s});function T(t){return Object.hasOwn(t,"name")&&U(t.type)}function U(t){return"number"==typeof t?.typeId}function F(t,e="",n=!0){return T(t)?t:V(e,S(t,U,(()=>"Data type expected.")),n)}const j=t=>({typeId:t}),k=(t,e,n=!1,s=-1)=>({typeId:i.Dictionary,id:s,dictionary:t,indices:e||Y(),ordered:n}),R=()=>j(i.Null),z=(t=32,e=!0)=>({typeId:i.Int,bitWidth:B(t,[8,16,32,64]),signed:e,values:m(t,e)}),_=()=>z(8),$=()=>z(16),Y=()=>z(32),P=()=>z(64),H=()=>z(8,!1),W=()=>z(16,!1),G=()=>z(32,!1),J=()=>z(64,!1),X=(t=2)=>({typeId:i.Float,precision:B(t,a),values:[h,v,w][t]}),q=()=>X(a.SINGLE),K=()=>X(a.DOUBLE),Q=()=>({typeId:i.Binary,offsets:b}),Z=()=>({typeId:i.Utf8,offsets:b}),tt=()=>j(i.Bool),et=(t,e,n=128)=>({typeId:i.Decimal,precision:t,scale:e,bitWidth:B(n,[128,256]),values:y}),nt=t=>({typeId:i.Date,unit:B(t,c),values:t===c.DAY?b:g}),st=()=>nt(c.DAY),rt=(t=u.MILLISECOND,e=32)=>({typeId:i.Time,unit:B(t,u),bitWidth:B(e,[32,64]),values:32===e?b:g}),it=(t=u.MILLISECOND,e=null)=>({typeId:i.Timestamp,unit:B(t,u),timezone:e,values:g}),at=(t=o.MONTH_DAY_NANO)=>({typeId:i.Interval,unit:B(t,o),values:t===o.MONTH_DAY_NANO?void 0:b}),ct=t=>({typeId:i.List,children:[F(t)],offsets:b}),ut=t=>({typeId:i.Struct,children:Array.isArray(t)&&T(t[0])?t:Object.entries(t).map((([t,e])=>V(t,e)))}),ot=(t,e,n,s)=>(n??=e.map(((t,e)=>e)),{typeId:i.Union,mode:B(t,d),typeIds:n,typeMap:n.reduce(((t,e,n)=>(t[e]=n,t)),{}),children:e.map(((t,e)=>F(t,`_${e}`))),typeIdForValue:s,offsets:b}),dt=t=>({typeId:i.FixedSizeBinary,stride:t}),lt=(t,e)=>({typeId:i.FixedSizeList,stride:e,children:[F(t)]}),ht=(t,e)=>({typeId:i.Map,keysSorted:t,children:[e],offsets:b}),ft=(t=u.MILLISECOND)=>({typeId:i.Duration,unit:B(t,u),values:g}),yt=()=>({typeId:i.LargeBinary,offsets:g}),pt=()=>({typeId:i.LargeUtf8,offsets:g}),It=t=>({typeId:i.LargeList,children:[F(t)],offsets:g}),bt=(t,e)=>({typeId:i.RunEndEncoded,children:[S(F(t,"run_ends"),(t=>t.type.typeId===i.Int),(()=>"Run-ends must have an integer type.")),F(e,"values")]}),gt=t=>({typeId:i.ListView,children:[F(t,"value")],offsets:b}),vt=t=>({typeId:i.LargeListView,children:[F(t,"value")],offsets:g}),wt=new w(2),mt=wt.buffer,xt=new g(mt),Ot=new f(mt),Lt=new b(mt),Et=new l(mt);function Dt(t){return t}function At(t){return BigInt(t)}function Nt(t){return E(t)?At:Dt}function St(t){return t/864e5|0}function Bt(t){if(t>Number.MAX_SAFE_INTEGER||t<Number.MIN_SAFE_INTEGER)throw Error(`BigInt exceeds integer number representation: ${t}`);return Number(t)}function Mt(t,e){return Number(t/e)+Number(t%e)/Number(e)}const Ct=t=>BigInt.asUintN(64,t);function Vt(t,e){const n=e<<1;let s;return BigInt.asIntN(64,t[n+1])<0?(s=Ct(~t[n])|Ct(~t[n+1])<<64n,s=-(s+1n)):s=t[n]|t[n+1]<<64n,s}function Tt(t,e){const n=e<<2;let s;return BigInt.asIntN(64,t[n+3])<0?(s=Ct(~t[n])|Ct(~t[n+1])<<64n|Ct(~t[n+2])<<128n|Ct(~t[n+3])<<192n,s=-(s+1n)):s=t[n]|t[n+1]<<64n|t[n+2]<<128n|t[n+3]<<192n,s}function Ut(t){if(t!=t)return 32256;wt[0]=t;const e=(2147483648&Ot[1])>>16&65535;let n=2146435072&Ot[1],s=0;return n>=1089470464?Ot[0]>0?n=31744:(n=(2080374784&n)>>16,s=(1048575&Ot[1])>>10):n<=1056964608?(s=1048576+(1048575&Ot[1]),s=1048576+(s<<(n>>20)-998)>>21,n=0):(n=n-1056964608>>10,s=512+(1048575&Ot[1])>>10),e|n|65535&s}const Ft=new TextDecoder("utf-8"),jt=new TextEncoder;function kt(t){return Ft.decode(t)}function Rt(t){return jt.encode(t)}function zt(t){return`${"object"==typeof t&&t?function(t){return t instanceof Date}(t)?+t:L(t)?`[${t.map(zt)}]`:function(t){let e="",n=-1;for(const s in t)++n>0&&(e+=","),e+=`"${s}":${zt(t[s])}`;return`{${e}}`}(t):t??null}`}const _t=4;function $t(t,e){return!!(t[e>>3]&1<<e%8)}function Yt(t,e){const n=e+Jt(t,e),s=n-Jt(t,n),r=Gt(t,s);return(e,i,a=null)=>{if(e<r){const r=Gt(t,s+e);if(r)return i(t,n+r)}return a}}function Pt(t,e){return e}function Ht(t,e){return!!function(t,e){return Wt(t,e)<<24>>24}(t,e)}function Wt(t,e){return t[e]}function Gt(t,e){return function(t,e){return t[e]|t[e+1]<<8}(t,e)<<16>>16}function Jt(t,e){return t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24}function Xt(t,e){return Jt(t,e)>>>0}function qt(t,e){return Bt(BigInt.asIntN(64,BigInt(Xt(t,e))+(BigInt(Xt(t,e+_t))<<32n)))}function Kt(t,e){let n=e+Jt(t,e);const s=Jt(t,n);return n+=_t,kt(t.subarray(n,n+s))}function Qt(t,e,n,s){if(!e)return[];const r=e+Jt(t,e);return Array.from({length:Jt(t,r)},((e,i)=>s(t,r+_t+i*n)))}const Zt=Symbol("rowIndex");function te(t,e){class n{constructor(t){this[Zt]=t}toJSON(){return ne(t,e,this[Zt])}}const s=n.prototype;for(let n=0;n<t.length;++n){if(Object.hasOwn(s,t[n]))continue;const r=e[n];Object.defineProperty(s,t[n],{get(){return r.at(this[Zt])},enumerable:!0})}return t=>new n(t)}function ee(t,e){return n=>ne(t,e,n)}function ne(t,e,n){const s={};for(let r=0;r<t.length;++r)s[t[r]]=e[r].at(n);return s}class se{static ArrayType=null;constructor({length:t,nullCount:e,type:n,validity:s,values:r,offsets:i,sizes:a,children:c}){this.length=t,this.nullCount=e,this.type=n,this.validity=s,this.values=r,this.offsets=i,this.sizes=a,this.children=c,e&&this.validity||(this.at=t=>this.value(t))}get[Symbol.toStringTag](){return"Batch"}at(t){return this.isValid(t)?this.value(t):null}isValid(t){return $t(this.validity,t)}value(t){return this.values[t]}slice(t,e){const n=e-t,s=Array(n);for(let e=0;e<n;++e)s[e]=this.at(t+e);return s}*[Symbol.iterator](){for(let t=0;t<this.length;++t)yield this.at(t)}}class re extends se{constructor(t){super(t);const{length:e,values:n}=this;this.values=n.subarray(0,e)}slice(t,e){return this.nullCount?super.slice(t,e):this.values.subarray(t,e)}[Symbol.iterator](){return this.nullCount?super[Symbol.iterator]():this.values[Symbol.iterator]()}}class ie extends se{static ArrayType=w}class ae extends se{static ArrayType=Array}class ce extends ae{value(t){return null}}class ue extends ie{value(t){return Bt(this.values[t])}}class oe extends ie{value(t){const e=this.values[t],n=(31744&e)>>10,s=(1023&e)/1024,r=(-1)**((32768&e)>>15);switch(n){case 31:return r*(s?Number.NaN:1/0);case 0:return r*(s?6103515625e-14*s:0)}return r*2**(n-15)*(1+s)}}class de extends ae{value(t){return $t(this.values,t)}}class le extends se{constructor(t){super(t);const{bitWidth:e,scale:n}=this.type;this.decimal=128===e?Vt:Tt,this.scale=10n**BigInt(n)}}class he extends le{static ArrayType=w;value(t){return Mt(this.decimal(this.values,t),this.scale)}}class fe extends le{static ArrayType=Array;value(t){return this.decimal(this.values,t)}}class ye extends ae{constructor(t){super(t),this.source=t}value(t){return new Date(this.source.value(t))}}class pe extends ie{value(t){return 864e5*this.values[t]}}const Ie=ue;class be extends ue{value(t){return 1e3*super.value(t)}}const ge=ue;class ve extends ue{value(t){return Mt(this.values[t],1000n)}}class we extends ue{value(t){return Mt(this.values[t],1000000n)}}class me extends ae{value(t){return this.values.subarray(t<<1,t+1<<1)}}class xe extends ae{value(t){const e=this.values,n=t<<4;return Float64Array.of(Jt(e,n),Jt(e,n+4),qt(e,n+8))}}const Oe=({values:t,offsets:e},n)=>t.subarray(e[n],e[n+1]),Le=({values:t,offsets:e},n)=>t.subarray(Bt(e[n]),Bt(e[n+1]));class Ee extends ae{value(t){return Oe(this,t)}}class De extends ae{value(t){return Le(this,t)}}class Ae extends ae{value(t){return kt(Oe(this,t))}}class Ne extends ae{value(t){return kt(Le(this,t))}}class Se extends ae{value(t){const e=this.offsets;return this.children[0].slice(e[t],e[t+1])}}class Be extends ae{value(t){const e=this.offsets;return this.children[0].slice(Bt(e[t]),Bt(e[t+1]))}}class Me extends ae{value(t){const e=this.offsets[t],n=e+this.sizes[t];return this.children[0].slice(e,n)}}class Ce extends ae{value(t){const e=this.offsets[t],n=e+this.sizes[t];return this.children[0].slice(Bt(e),Bt(n))}}class Ve extends ae{constructor(t){super(t),this.stride=this.type.stride}}class Te extends Ve{value(t){const{stride:e,values:n}=this;return n.subarray(t*e,(t+1)*e)}}class Ue extends Ve{value(t){const{children:e,stride:n}=this;return e[0].slice(t*n,(t+1)*n)}}function Fe({children:t,offsets:e},n){const[s,r]=t[0].children,i=e[n],a=e[n+1],c=[];for(let t=i;t<a;++t)c.push([s.at(t),r.at(t)]);return c}class je extends ae{value(t){return Fe(this,t)}}class ke extends ae{value(t){return new Map(Fe(this,t))}}class Re extends ae{constructor({typeIds:t,...e}){super(e),this.typeIds=t,this.typeMap=this.type.typeMap}value(t,e=t){const{typeIds:n,children:s,typeMap:r}=this;return s[r[n[t]]].at(e)}}class ze extends Re{value(t){return super.value(t,this.offsets[t])}}class _e extends ae{constructor(t,e=ee){super(t),this.names=this.type.children.map((t=>t.name)),this.factory=e(this.names,this.children)}value(t){return this.factory(t)}}class $e extends _e{constructor(t){super(t,te)}}class Ye extends ae{value(t){const[{values:e},n]=this.children;return n.at(D(e,t))}}class Pe extends ae{setDictionary(t){return this.dictionary=t,this.cache=t.cache(),this}value(t){return this.cache[this.key(t)]}key(t){return this.values[t]}}class He extends ae{constructor({data:t,...e}){super(e),this.data=t}view(t){const{values:e,data:n}=this,s=t<<4;let r=s+4,i=e;const a=Jt(i,s);return a>12&&(r=Jt(i,s+12),i=n[Jt(i,s+8)]),i.subarray(r,r+a)}}class We extends He{value(t){return this.view(t)}}class Ge extends He{value(t){return kt(this.view(t))}}function Je(){let t=[];return{add(e){return t.push(e),this},clear:()=>t=[],done:()=>new Xe(t)}}class Xe{constructor(t){this.type=t[0].type,this.length=t.reduce(((t,e)=>t+e.length),0),this.nullCount=t.reduce(((t,e)=>t+e.nullCount),0),this.data=t;const e=t.length,n=new Int32Array(e+1);if(1===e){const[e]=t;n[1]=e.length,this.at=t=>e.at(t)}else for(let s=0,r=0;s<e;++s)n[s+1]=r+=t[s].length;this.offsets=n}get[Symbol.toStringTag](){return"Column"}[Symbol.iterator](){const t=this.data;return 1===t.length?t[0][Symbol.iterator]():function*(t){for(let e=0;e<t.length;++e){const n=t[e][Symbol.iterator]();for(let t=n.next();!t.done;t=n.next())yield t.value}}(t)}at(t){const{data:e,offsets:n}=this,s=D(n,t)-1;return e[s]?.at(t-n[s])}get(t){return this.at(t)}toArray(){const{length:t,nullCount:e,data:n}=this,s=!e&&n[0]instanceof re;const r=n.length;if(s&&1===r)return n[0].values;const i=new(!r||e>0?Array:n[0].constructor.ArrayType??n[0].values.constructor)(t);return s?function(t,e){for(let n=0,s=0;n<e.length;++n){const{values:r}=e[n];t.set(r,s),s+=r.length}return t}(i,n):function(t,e){let n=-1;for(let s=0;s<e.length;++s){const r=e[s];for(let e=0;e<r.length;++e)t[++n]=r.at(e)}return t}(i,n)}cache(){return this._cache??(this._cache=this.toArray())}}class qe{constructor(t,e,n=!1){const s=t.fields.map((t=>t.name));this.schema=t,this.names=s,this.children=e,this.factory=n?te:ee;const r=[];this.getFactory=t=>r[t]??(r[t]=this.factory(s,e.map((e=>e.data[t]))))}get[Symbol.toStringTag](){return"Table"}get numCols(){return this.names.length}get numRows(){return this.children[0]?.length??0}getChildAt(t){return this.children[t]}getChild(t){const e=this.names.findIndex((e=>e===t));return e>-1?this.children[e]:void 0}selectAt(t,e=[]){const{children:n,factory:s,schema:r}=this,{fields:i}=r;return new qe({...r,fields:t.map(((t,n)=>function(t,e){return null!=e&&e!==t.name?{...t,name:e}:t}(i[t],e[n])))},t.map((t=>n[t])),s===te)}select(t,e){const n=this.names,s=t.map((t=>n.indexOf(t)));return this.selectAt(s,e)}toColumns(){const{children:t,names:e}=this,n={};return e.forEach(((e,s)=>n[e]=t[s]?.toArray()??[])),n}toArray(){const{children:t,getFactory:e,numRows:n}=this,s=t[0]?.data??[],r=Array(n);for(let t=0,n=-1;t<s.length;++t){const i=e(t);for(let e=0;e<s[t].length;++e)r[++n]=i(e)}return r}*[Symbol.iterator](){const{children:t,getFactory:e}=this,n=t[0]?.data??[];for(let t=0;t<n.length;++t){const s=e(t);for(let e=0;e<n[t].length;++e)yield s(e)}}at(t){const{children:e,getFactory:n,numRows:s}=this;if(t<0||t>=s)return null;const[{offsets:r}]=e,i=D(r,t)-1;return n(i)(t-r[i])}get(t){return this.at(t)}}function Ke(t,e={}){const{typeId:n,bitWidth:s,precision:r,unit:a}=t,{useBigInt:d,useDate:l,useDecimalBigInt:h,useMap:f,useProxy:y}=e;switch(n){case i.Null:return ce;case i.Bool:return de;case i.Int:case i.Time:case i.Duration:return d||s<64?re:ue;case i.Float:return r?re:oe;case i.Date:return Qe(a===c.DAY?pe:Ie,l&&ye);case i.Timestamp:return Qe(a===u.SECOND?be:a===u.MILLISECOND?ge:a===u.MICROSECOND?ve:we,l&&ye);case i.Decimal:return h?fe:he;case i.Interval:return a===o.DAY_TIME?me:a===o.YEAR_MONTH?re:xe;case i.FixedSizeBinary:return Te;case i.Utf8:return Ae;case i.LargeUtf8:return Ne;case i.Binary:return Ee;case i.LargeBinary:return De;case i.BinaryView:return We;case i.Utf8View:return Ge;case i.List:return Se;case i.LargeList:return Be;case i.Map:return f?ke:je;case i.ListView:return Me;case i.LargeListView:return Ce;case i.FixedSizeList:return Ue;case i.Struct:return y?$e:_e;case i.RunEndEncoded:return Ye;case i.Dictionary:return Pe;case i.Union:return t.mode?ze:Re}throw new Error(C(n))}function Qe(t,e){return e?class extends e{constructor(e){super(new t(e))}}:t}function Ze(t,e){return{offset:qt(t,e),metadataLength:Jt(t,e+8),bodyLength:qt(t,e+16)}}function tn(t,e){return Qt(t,e,24,Ze)}function en(t,e,s){const r=Yt(t,e);if(r(10,Pt,0))throw new Error("Record batch compression not implemented");const i=s<n.V4?8:0;return{length:r(4,qt,0),nodes:Qt(t,r(6,Pt),16,((t,e)=>({length:qt(t,e),nullCount:qt(t,e+8)}))),regions:Qt(t,r(8,Pt),16+i,((t,e)=>({offset:qt(t,e+i),length:qt(t,e+i+8)}))),variadic:Qt(t,r(12,Pt),8,qt)}}function nn(t,e,n){const s=Yt(t,e);return{id:s(4,qt,0),data:s(6,((t,e)=>en(t,e,n))),isDelta:s(8,Ht,!1)}}function sn(t,e,n,s){B(n,i,C);const r=Yt(t,e);switch(n){case i.Binary:return Q();case i.Utf8:return Z();case i.LargeBinary:return yt();case i.LargeUtf8:return pt();case i.List:return ct(s[0]);case i.ListView:return gt(s[0]);case i.LargeList:return It(s[0]);case i.LargeListView:return vt(s[0]);case i.Struct:return ut(s);case i.RunEndEncoded:return bt(s[0],s[1]);case i.Int:return z(r(4,Jt,0),r(6,Ht,!1));case i.Float:return X(r(4,Gt,a.HALF));case i.Decimal:return et(r(4,Jt,0),r(6,Jt,0),r(8,Jt,128));case i.Date:return nt(r(4,Gt,c.MILLISECOND));case i.Time:return rt(r(4,Gt,u.MILLISECOND),r(6,Jt,32));case i.Timestamp:return it(r(4,Gt,u.SECOND),r(6,Kt));case i.Interval:return at(r(4,Gt,o.YEAR_MONTH));case i.Duration:return ft(r(4,Gt,u.MILLISECOND));case i.FixedSizeBinary:return dt(r(4,Jt,0));case i.FixedSizeList:return lt(s[0],r(4,Jt,0));case i.Map:return ht(r(4,Ht,!1),s[0]);case i.Union:return ot(r(4,Gt,d.Sparse),s,Qt(t,r(6,Pt),4,Jt))}return{typeId:n}}function rn(t,e){const n=Qt(t,e,4,((t,e)=>{const n=Yt(t,e);return[n(4,Kt),n(6,Kt)]}));return n.length?new Map(n):null}function an(t,e,n){const s=Yt(t,e);return{version:n,endianness:s(4,Gt,0),fields:s(6,cn,[]),metadata:s(8,rn)}}function cn(t,e){return Qt(t,e,4,un)}function un(t,e){const n=Yt(t,e),s=n(8,Wt,i.NONE),r=n(10,Pt,0),a=n(12,on),c=n(14,((t,e)=>function(t,e){const n=Qt(t,e,4,un);return n.length?n:null}(t,e)));let u=sn(t,r,s,c);return a&&(a.dictionary=u,u=a),{name:n(4,Kt),type:u,nullable:n(6,Ht,!1),metadata:n(16,rn)}}function on(t,e){if(!e)return null;const n=Yt(t,e);return k(null,n(6,dn,Y()),n(8,Ht,!1),n(4,qt,0))}function dn(t,e){return sn(t,e,i.Int)}const ln=(t,e)=>`Expected to read ${t} metadata bytes, but only read ${e}.`,hn=(t,e)=>`Expected to read ${t} bytes for message body, but only read ${e}.`,fn=t=>`Unsupported message type: ${t} (${M(r,t)})`;function yn(t,e){let s=Jt(t,e)||0;if(e+=_t,-1===s&&(s=Jt(t,e)||0,e+=_t),0===s)return null;const i=t.subarray(e,e+=s);if(i.byteLength<s)throw new Error(ln(s,i.byteLength));const a=Yt(i,0),c=a(4,Gt,n.V1),u=a(6,Wt,r.NONE),o=a(8,Pt,0),d=a(10,qt,0);let l;if(o){const n=u===r.Schema?an:u===r.DictionaryBatch?nn:u===r.RecordBatch?en:null;if(!n)throw new Error(fn(u));if(l=n(i,o,c),d>0){const n=t.subarray(e,e+=d);if(n.byteLength<d)throw new Error(hn(d,n.byteLength));l.body=n}}return{version:c,type:u,index:e,content:l}}function pn(t){const s=t instanceof ArrayBuffer?new Uint8Array(t):t;return!Array.isArray(s)&&function(t){if(!t||t.length<4)return!1;for(let n=0;n<6;++n)if(e[n]!==t[n])return!1;return!0}(s)?function(t){const s=t.byteLength-(e.length+4),r=Jt(t,s),i=Yt(t,s-r),a=i(4,Gt,n.V1),c=i(8,tn,[]),u=i(10,tn,[]);return{schema:i(6,((t,e)=>an(t,e,a))),dictionaries:c.map((({offset:e})=>yn(t,e).content)),records:u.map((({offset:e})=>yn(t,e).content)),metadata:i(12,rn)}}(s):function(t){const e=[t].flat();let n;const s=[],i=[];for(const t of e){let e=0;for(;;){const a=yn(t,e);if(null===a)break;if(e=a.index,a.content)switch(a.type){case r.Schema:n||(n=a.content);break;case r.RecordBatch:s.push(a.content);break;case r.DictionaryBatch:i.push(a.content)}}}return{schema:n,dictionaries:i,records:s,metadata:null}}(s)}function In(t,e){const{typeId:s}=t,{length:r,options:a,node:c,buffer:u,variadic:o,version:l}=e,h=Ke(t,a);if(s===i.Null)return new h({length:r,nullCount:r,type:t});const f={...c(),type:t};switch(s){case i.Bool:case i.Int:case i.Time:case i.Duration:case i.Float:case i.Decimal:case i.Date:case i.Timestamp:case i.Interval:case i.FixedSizeBinary:return new h({...f,validity:u(),values:u(t.values)});case i.Utf8:case i.LargeUtf8:case i.Binary:case i.LargeBinary:return new h({...f,validity:u(),offsets:u(t.offsets),values:u()});case i.BinaryView:case i.Utf8View:return new h({...f,validity:u(),values:u(),data:Array.from({length:o()},(()=>u()))});case i.List:case i.LargeList:case i.Map:return new h({...f,validity:u(),offsets:u(t.offsets),children:e.visit(t.children)});case i.ListView:case i.LargeListView:return new h({...f,validity:u(),offsets:u(t.offsets),sizes:u(t.offsets),children:e.visit(t.children)});case i.FixedSizeList:case i.Struct:return new h({...f,validity:u(),children:e.visit(t.children)});case i.RunEndEncoded:return new h({...f,children:e.visit(t.children)});case i.Dictionary:{const{id:n,indices:s}=t;return new h({...f,validity:u(),values:u(s.values)}).setDictionary(e.dictionary(n))}case i.Union:return l<n.V5&&u(),new h({...f,typeIds:u(p),offsets:t.mode===d.Sparse?null:u(t.offsets),children:e.visit(t.children)});default:throw new Error(C(s))}}function bn(t,e,n){t[e]=n,t[e+1]=n>>8,t[e+2]=n>>16,t[e+3]=n>>24}const gn=1024;class vn{constructor(t){this.sink=t,this.minalign=1,this.buf=new Uint8Array(gn),this.space=gn,this.vtables=[],this.outputBytes=0}offset(){return this.buf.length-this.space}writeInt8(t){this.buf[this.space-=1]=t}writeInt16(t){this.buf[this.space-=2]=t,this.buf[this.space+1]=t>>8}writeInt32(t){bn(this.buf,this.space-=4,t)}writeInt64(t){const e=BigInt(t);this.writeInt32(Number(BigInt.asIntN(32,e>>BigInt(32)))),this.writeInt32(Number(BigInt.asIntN(32,e)))}addInt8(t){wn(this,1,0),this.writeInt8(t)}addInt16(t){wn(this,2,0),this.writeInt16(t)}addInt32(t){wn(this,4,0),this.writeInt32(t)}addInt64(t){wn(this,8,0),this.writeInt64(t)}addOffset(t){wn(this,_t,0),this.writeInt32(this.offset()-t+_t)}addObject(t,e){const n=function(t,e){const n=Array(e).fill(0),s=t.offset();function r(e){n[e]=t.offset()}return{addInt8(e,n,s){n!=s&&(t.addInt8(n),r(e))},addInt16(e,n,s){n!=s&&(t.addInt16(n),r(e))},addInt32(e,n,s){n!=s&&(t.addInt32(n),r(e))},addInt64(e,n,s){n!=s&&(t.addInt64(n),r(e))},addOffset(e,n,s){n!=s&&(t.addOffset(n),r(e))},finish(){t.addInt32(0);const r=t.offset();let i=e;for(;--i>=0&&0===n[i];);const a=i+1;for(;i>=0;--i)t.addInt16(n[i]?r-n[i]:0);const c=2;t.addInt16(r-s);const u=2*(a+c);t.addInt16(u);let o=0;const{buf:d,vtables:l,space:h}=t;t:for(i=0;i<l.length;++i){const t=d.length-l[i];if(u==Gt(d,t)){for(let e=2;e<u;e+=2)if(Gt(d,h+e)!=Gt(d,t+e))continue t;o=l[i];break}}if(o)t.space=d.length-r,bn(d,t.space,o-r);else{const e=t.offset();l.push(e),bn(d,d.length-r,e-r)}return r}}}(this,t);return e?.(n),n.finish()}addVector(t,e,n,s){const r=t?.length;if(!r)return 0;wn(this,_t,e*r),wn(this,n,e*r);for(let e=r;--e>=0;)s(this,t[e]);return this.writeInt32(r),this.offset()}addOffsetVector(t){return this.addVector(t,4,4,((t,e)=>t.addOffset(e)))}addString(t){if(null==t)return 0;const e=Rt(t),n=e.length;return this.addInt8(0),wn(this,_t,n),this.buf.set(e,this.space-=n),this.writeInt32(n),this.offset()}finish(t){wn(this,this.minalign,_t),this.addOffset(t)}flush(){const{buf:t,sink:e}=this,n=t.subarray(this.space,t.length);e.write(n),this.outputBytes+=n.byteLength,this.minalign=1,this.vtables=[],this.buf=new Uint8Array(gn),this.space=gn}addBuffer(t){const e=t.byteLength;if(!e)return 0;this.sink.write(t),this.outputBytes+=e;const n=(e+7&-8)-e;return this.addPadding(n),e+n}addPadding(t){t>0&&(this.sink.write(new Uint8Array(t)),this.outputBytes+=t)}}function wn(t,e,n){let{buf:s,space:r,minalign:i}=t;e>i&&(t.minalign=e);const a=s.length,c=a-r+n,u=1+~c&e-1;s=N(s,c+u+e-1,!0),r+=s.length-a;for(let t=0;t<u;++t)s[--r]=0;t.buf=s,t.space=r}function mn(t,e){const{nodes:n,regions:s,variadic:r}=e,i=t.addVector(n,16,8,((t,e)=>(t.writeInt64(e.nullCount),t.writeInt64(e.length),t.offset()))),a=t.addVector(s,16,8,((t,e)=>(t.writeInt64(e.length),t.writeInt64(e.offset),t.offset()))),c=t.addVector(r,8,8,((t,e)=>t.addInt64(e)));return t.addObject(5,(t=>{t.addInt64(0,n[0].length,0),t.addOffset(1,i,0),t.addOffset(2,a,0),t.addOffset(4,c,0)}))}function xn(t,e){const n=mn(t,e.data);return t.addObject(3,(t=>{t.addInt64(0,e.id,0),t.addOffset(1,n,0),t.addInt8(2,+e.isDelta,0)}))}function On(t,e){return e?.size>0?t.addOffsetVector(Array.from(e,(([e,n])=>{const s=t.addString(`${e}`),r=t.addString(`${n}`);return t.addObject(2,(t=>{t.addOffset(0,s,0),t.addOffset(1,r,0)}))}))):0}function Ln(t,e){switch(B(e.typeId,i,C)){case i.Dictionary:return function(t,e){const n=function(t){return t.typeId===i.Int&&32===t.bitWidth&&t.signed}(e.indices)?0:Ln(t,e.indices);return t.addObject(4,(t=>{t.addInt64(0,e.id,0),t.addOffset(1,n,0),t.addInt8(2,+e.ordered,0)}))}(t,e);case i.Int:return function(t,e){return t.addObject(2,(t=>{t.addInt32(0,e.bitWidth,0),t.addInt8(1,+e.signed,0)}))}(t,e);case i.Float:return function(t,e){return t.addObject(1,(t=>{t.addInt16(0,e.precision,a.HALF)}))}(t,e);case i.Decimal:return function(t,e){return t.addObject(3,(t=>{t.addInt32(0,e.precision,0),t.addInt32(1,e.scale,0),t.addInt32(2,e.bitWidth,128)}))}(t,e);case i.Date:return function(t,e){return t.addObject(1,(t=>{t.addInt16(0,e.unit,c.MILLISECOND)}))}(t,e);case i.Time:return function(t,e){return t.addObject(2,(t=>{t.addInt16(0,e.unit,u.MILLISECOND),t.addInt32(1,e.bitWidth,32)}))}(t,e);case i.Timestamp:return function(t,e){const n=t.addString(e.timezone);return t.addObject(2,(t=>{t.addInt16(0,e.unit,u.SECOND),t.addOffset(1,n,0)}))}(t,e);case i.Interval:return function(t,e){return t.addObject(1,(t=>{t.addInt16(0,e.unit,o.YEAR_MONTH)}))}(t,e);case i.Duration:return function(t,e){return t.addObject(1,(t=>{t.addInt16(0,e.unit,u.MILLISECOND)}))}(t,e);case i.FixedSizeBinary:case i.FixedSizeList:return function(t,e){return t.addObject(1,(t=>{t.addInt32(0,e.stride,0)}))}(t,e);case i.Map:return function(t,e){return t.addObject(1,(t=>{t.addInt8(0,+e.keysSorted,0)}))}(t,e);case i.Union:return function(t,e){const n=t.addVector(e.typeIds,4,4,((t,e)=>t.addInt32(e)));return t.addObject(2,(t=>{t.addInt16(0,e.mode,d.Sparse),t.addOffset(1,n,0)}))}(t,e)}return t.addObject(0)}const En=1===new Uint16Array(new Uint8Array([1,0]).buffer)[0];function Dn(t,e){const{fields:n,metadata:s}=e,r=n.map((e=>An(t,e))),i=t.addOffsetVector(r),a=On(t,s);return t.addObject(4,(t=>{t.addInt16(0,+!En,0),t.addOffset(1,i,0),t.addOffset(2,a,0)}))}function An(t,e){const{name:n,nullable:s,type:r,metadata:a}=e;let{typeId:c}=r,u=0,o=0;if(c!==i.Dictionary)u=Ln(t,r);else{const e=r.dictionary;c=e.typeId,o=Ln(t,r),u=Ln(t,e)}const d=(r.children||[]).map((e=>An(t,e))),l=t.addOffsetVector(d),h=On(t,a),f=t.addString(n);return t.addObject(7,(t=>{t.addOffset(0,f,0),t.addInt8(1,+s,0),t.addInt8(2,c,i.NONE),t.addOffset(3,u,0),t.addOffset(4,o,0),t.addOffset(5,l,0),t.addOffset(6,h,0)}))}function Nn(t,{offset:e,metadataLength:n,bodyLength:s}){return t.writeInt64(s),t.writeInt32(0),t.writeInt32(n),t.writeInt64(e),t.offset()}function Sn(t,e,s,i,a){t.finish(t.addObject(5,(t=>{t.addInt16(0,n.V5,n.V1),t.addInt8(1,e,r.NONE),t.addOffset(2,s,0),t.addInt64(3,i,0)})));const c=t.offset(),u=c+8+7&-8;a?.push({offset:t.outputBytes,metadataLength:u,bodyLength:i}),t.addInt32(u-8),t.addInt32(-1),t.flush(),t.addPadding(u-c-8)}class Bn{write(t){}pad(t){this.write(new Uint8Array(t))}finish(){return null}}class Mn extends Bn{constructor(){super(),this.buffers=[]}write(t){this.buffers.push(t)}finish(){const t=this.buffers,e=t.reduce(((t,e)=>t+e.byteLength),0),n=new Uint8Array(e);for(let e=0,s=0;e<t.length;++e)n.set(t[e],s),s+=t[e].byteLength;return n}}const Cn="stream",Vn="file";function Tn(t,{sink:s,format:i=Cn}={}){if(i!==Cn&&i!==Vn)throw new Error(`Unrecognized Arrow IPC format: ${i}`);const{schema:a,dictionaries:c=[],records:u=[],metadata:o}=t,d=new vn(s||new Mn),l=i===Vn,h=[],f=[];l?d.addBuffer(e):a&&Sn(d,r.Schema,Dn(d,a),0);for(const t of c){const{data:e}=t;Sn(d,r.DictionaryBatch,xn(d,t),e.byteLength,h),Un(d,e.buffers)}for(const t of u)Sn(d,r.RecordBatch,mn(d,t),t.byteLength,f),Un(d,t.buffers);return l&&function(t,s,r,i,a){const c=On(t,a),u=t.addVector(i,24,8,Nn),o=t.addVector(r,24,8,Nn),d=Dn(t,s);t.finish(t.addObject(5,(t=>{t.addInt16(0,n.V5,n.V1),t.addOffset(1,d,0),t.addOffset(2,o,0),t.addOffset(3,u,0),t.addOffset(4,c,0)})));const l=t.offset();t.addInt32(0),t.addInt32(-1),t.flush(),t.sink.write(new Uint8Array(Int32Array.of(l).buffer)),t.sink.write(e)}(d,a,h,f,o),d.sink}function Un(t,e){for(let n=0;n<e.length;++n)t.addBuffer(e[n])}function Fn(t,e){if(t?.type.typeId===i.Dictionary){const n=t.dictionary;e(n),Fn(n.data[0],e)}t?.children?.forEach((t=>Fn(t,e)))}function jn(t,e=0){const n=function(){let t=0;const e=[],n=[],s=[],r=[];return{node(t,n){e.push({length:t,nullCount:n})},buffer(e){const r=e.byteLength,i=r+7&-8;n.push({offset:t,length:i}),t+=i,s.push(new Uint8Array(e.buffer,e.byteOffset,r))},variadic(t){r.push(t)},children(t,e){t.children.forEach(((t,n)=>{kn(t.type,e.children[n],this)}))},done:()=>({byteLength:t,nodes:e,regions:n,variadic:r,buffers:s})}}();return t.forEach((t=>{kn(t.type,t.data[e],n)})),n.done()}function kn(t,e,n){const{typeId:s}=t;if(s!==i.Null)switch(n.node(e.length,e.nullCount),s){case i.Bool:case i.Int:case i.Time:case i.Duration:case i.Float:case i.Date:case i.Timestamp:case i.Decimal:case i.Interval:case i.FixedSizeBinary:case i.Dictionary:return n.buffer(e.validity),void n.buffer(e.values);case i.Utf8:case i.LargeUtf8:case i.Binary:case i.LargeBinary:return n.buffer(e.validity),n.buffer(e.offsets),void n.buffer(e.values);case i.BinaryView:case i.Utf8View:return n.buffer(e.validity),n.buffer(e.values),n.variadic(e.data.length),void e.data.forEach((t=>n.buffer(t)));case i.List:case i.LargeList:case i.Map:return n.buffer(e.validity),n.buffer(e.offsets),void n.children(t,e);case i.ListView:case i.LargeListView:return n.buffer(e.validity),n.buffer(e.offsets),n.buffer(e.sizes),void n.children(t,e);case i.FixedSizeList:case i.Struct:return n.buffer(e.validity),void n.children(t,e);case i.RunEndEncoded:return void n.children(t,e);case i.Union:return n.buffer(e.typeIds),t.mode===d.Dense&&n.buffer(e.offsets),void n.children(t,e);default:throw new Error(C(s))}}function Rn(t){return new zn(t)}class zn{constructor(t=l){this.buf=new t(512)}array(t){return function(t,e=t.length){const n=function(t,e=1){return(t*e+7&-8)/e}(e,t.BYTES_PER_ELEMENT);return t.length>n?t.subarray(0,n):t.length<n?A(t,n):t}(this.buf,t)}prep(t){t>=this.buf.length&&(this.buf=N(this.buf,t))}get(t){return this.buf[t]}set(t,e){this.prep(e),this.buf[e]=t}write(t,e){this.prep(e+t.length),this.buf.set(t,e)}}function _n(){return new $n}class $n extends zn{set(t){const e=t>>3;this.prep(e),this.buf[e]|=1<<t%8}}class Yn{constructor(t,e){this.type=t,this.ctx=e,this.batchClass=e.batchType(t)}init(){return this.index=-1,this}set(t,e){return this.index=e,!1}done(){return null}batch(){const t=new this.batchClass(this.done());return this.init(),t}}class Pn extends Yn{constructor(t,e){super(t,e)}init(){return this.nullCount=0,this.validity=_n(),super.init()}set(t,e){this.index=e;const n=null!=t;return n?this.validity.set(e):this.nullCount++,n}done(){const{index:t,nullCount:e,type:n,validity:s}=this;return{length:t+1,nullCount:e,type:n,validity:e?s.array(1+(t>>3)):new l(0)}}}function Hn(){const t=new Map,e=new Set;return{get(n,s){const r=n.id;if(r>=0&&t.has(r))return t.get(r);{const i=function(t,e){const n=Object.create(null),s=e.builder(t.dictionary),r=[];s.init();let i=-1;return{type:t,values:s,add:t=>(r.push(t),t),key(t){const e=zt(t);let r=n[e];return void 0===r&&(n[e]=r=++i,s.set(t,r)),r},finish(e){const n=new(Ke(t.dictionary,e))(s.done()),i=new Xe([n]);r.forEach((t=>t.setDictionary(i)))}}}(n,s);return r>=0&&t.set(r,i),e.add(i),i}},finish(t){e.forEach((e=>e.finish(t)))}}}class Wn extends Pn{constructor(t,e){super(t,e),this.dict=e.dictionary(t)}init(){return this.values=Rn(this.type.indices.values),super.init()}set(t,e){super.set(t,e)&&this.values.set(this.dict.key(t),e)}done(){return{...super.done(),values:this.values.array(this.index+1)}}batch(){return this.dict.add(super.batch())}}function Gn(t){const e=Jn();return t((t=>e.add(t))),e.type()}function Jn(){let t,e,n,s=0,r=0,i=0,a=0,c=0,u=0,o=0,d=0,l=0,h=0,f=0,y=1/0,p=-1/0,I=1/0,b=-1/0,g={};return{add(v){if(s++,null!=v)switch(typeof v){case"string":l++;break;case"number":a++,v<y&&(y=v),v>p&&(p=v),Number.isInteger(v)&&c++;break;case"bigint":u++,void 0===t?t=e=v:(v<t&&(t=v),v>e&&(e=v));break;case"boolean":i++;break;case"object":if(v instanceof Date)o++,+v%864e5==0&&d++;else if(L(v)){h++;const t=v.length;t<I&&(I=t),t>b&&(b=t),n??=Jn(),v.forEach(n.add)}else{f++;for(const t in v){(g[t]??(g[t]=Jn())).add(v[t])}}}else r++},type(){const v=s-r;return 0===v?R():c===v?function(t,e){const n=Math.max(Math.abs(t)-1,e);return n<128?_():n<32768?$():n<2**31?Y():K()}(y,p):a===v?K():u===v?function(t,e){const n=-t>e?-t-1n:e;if(n>=2**63)throw new Error(`BigInt exceeds 64 bits: ${n}`);return P()}(t,e):i===v?tt():d===v?st():o===v?it():l===v?k(Z()):h===v?function(t,e,n){return n===e?lt(t,e):ct(t)}(n.type(),I,b):f===v?ut(Object.entries(g).map((t=>V(t[0],t[1].type())))):function(){throw new Error("Mixed types detected, please define a union type.")}()}}}class Xn extends Pn{constructor(t,e){super(t,e),this.toOffset=Nt(t.offsets)}init(){return this.offsets=Rn(this.type.offsets),this.values=Rn(),this.pos=0,super.init()}set(t,e){const{offsets:n,values:s,toOffset:r}=this;super.set(t,e)&&(s.write(t,this.pos),this.pos+=t.length),n.set(r(this.pos),e+1)}done(){return{...super.done(),offsets:this.offsets.array(this.index+2),values:this.values.array(this.pos+1)}}}class qn extends Pn{constructor(t,e){super(t,e)}init(){return this.values=_n(),super.init()}set(t,e){super.set(t,e),t&&this.values.set(e)}done(){return{...super.done(),values:this.values.array(1+(this.index>>3))}}}class Kn extends Pn{constructor(t,e){super(t,e),this.scale=10**t.scale,this.stride=t.bitWidth>>6}init(){return this.values=Rn(this.type.values),super.init()}set(t,e){const{scale:n,stride:s,values:r}=this;super.set(t,e)&&(r.prep((e+1)*s),function(t,e,n,s,r){const i="bigint"==typeof t?t:At(Math.trunc(t*r));e[n]=i,e[n+1]=i>>64n,s>2&&(e[n+2]=i>>128n,e[n+3]=i>>192n)}(t,r.buf,e*s,s,n))}done(){const{index:t,stride:e,values:n}=this;return{...super.done(),values:n.array((t+1)*e)}}}class Qn extends Pn{constructor(t,e){super(t,e),this.stride=t.stride}init(){return this.values=Rn(),super.init()}set(t,e){super.set(t,e)&&this.values.write(t,e*this.stride)}done(){const{stride:t,values:e}=this;return{...super.done(),values:e.array(t*(this.index+1))}}}class Zn extends Pn{constructor(t,e){super(t,e),this.child=e.builder(this.type.children[0].type),this.stride=t.stride}init(){return this.child.init(),super.init()}set(t,e){const{child:n,stride:s}=this,r=e*s;if(super.set(t,e))for(let e=0;e<s;++e)n.set(t[e],r+e);else n.index=r+s}done(){const{child:t}=this;return{...super.done(),children:[t.batch()]}}}class ts extends Pn{init(){return this.values=Rn(this.type.values),super.init()}set(t,e){if(super.set(t,e)){const n=e<<1;this.values.set(t[0],n),this.values.set(t[1],n+1)}}done(){return{...super.done(),values:this.values.array(this.index+1<<1)}}}class es extends Pn{init(){return this.values=Rn(),super.init()}set(t,e){super.set(t,e)&&this.values.write(function([t,e,n]){return Lt[0]=t,Lt[1]=e,xt[1]=At(n),Et}(t),e<<4)}done(){return{...super.done(),values:this.values.array(this.index+1<<4)}}}class ns extends Pn{constructor(t,e,n){super(t,e),this.child=n}init(){this.child.init();const t=this.type.offsets;return this.offsets=Rn(t),this.toOffset=Nt(t),this.pos=0,super.init()}done(){return{...super.done(),offsets:this.offsets.array(this.index+2),children:[this.child.batch()]}}}class ss extends ns{constructor(t,e){super(t,e,e.builder(t.children[0].type))}set(t,e){const{child:n,offsets:s,toOffset:r}=this;super.set(t,e)&&t.forEach((t=>n.set(t,this.pos++))),s.set(r(this.pos),e+1)}}class rs extends Pn{constructor(t,e){super(t,e),this.children=t.children.map((t=>e.builder(t.type)))}init(){return this.children.forEach((t=>t.init())),super.init()}done(){const{children:t}=this;return t.forEach((t=>t.index=this.index)),{...super.done(),children:t.map((t=>t.batch()))}}}class is extends rs{constructor(t,e){super(t,e),this.setters=this.children.map(((e,n)=>{const s=t.children[n].name;return(t,n)=>e.set(t?.[s],n)}))}set(t,e){super.set(t,e);const n=this.setters;for(let s=0;s<n.length;++s)n[s](t,e)}}class as extends ns{constructor(t,e){super(t,e,new cs(t.children[0].type,e))}set(t,e){const{child:n,offsets:s,toOffset:r}=this;if(super.set(t,e))for(const e of t)n.set(e,this.pos++);s.set(r(this.pos),e+1)}}class cs extends rs{set(t,e){super.set(t,e);const[n,s]=this.children;n.set(t[0],e),s.set(t[1],e)}}const us={};class os extends Yn{constructor(t,e){super(t,e),this.children=t.children.map((t=>e.builder(t.type)))}init(){return this.pos=0,this.key=null,this.value=us,this.children.forEach((t=>t.init())),super.init()}next(){const[t,e]=this.children;t.set(this.index+1,this.pos),e.set(this.value,this.pos++)}set(t,e){if(t!==this.value){const e=zt(t);e!==this.key&&(this.key&&this.next(),this.key=e,this.value=t)}this.index=e}done(){this.next();const{children:t,index:e,type:n}=this;return{length:e+1,nullCount:0,type:n,children:t.map((t=>t.batch()))}}}class ds extends Yn{constructor(t,e){super(t,e),this.children=t.children.map((t=>e.builder(t.type))),this.typeMap=t.typeMap,this.lookup=t.typeIdForValue}init(){return this.nullCount=0,this.typeIds=Rn(p),this.children.forEach((t=>t.init())),super.init()}set(t,e){const{children:n,lookup:s,typeMap:r,typeIds:i}=this;this.index=e;const a=s(t,e),c=n[r[a]];i.set(a,e),null==t&&++this.nullCount,this.update(t,e,c)}done(){const{children:t,nullCount:e,type:n,typeIds:s}=this,r=this.index+1;return{length:r,nullCount:e,type:n,typeIds:s.array(r),children:t.map((t=>t.batch()))}}}class ls extends ds{update(t,e,n){n.set(t,e),this.children.forEach((t=>{t!==n&&t.set(null,e)}))}}class hs extends ds{init(){return this.offsets=Rn(this.type.offsets),super.init()}update(t,e,n){const s=n.index+1;n.set(t,s),this.offsets.set(s,e)}done(){return{...super.done(),offsets:this.offsets.array(this.index+1)}}}class fs extends Xn{set(t,e){super.set(t&&Rt(t),e)}}class ys extends Pn{constructor(t,e){super(t,e),this.values=Rn(t.values)}init(){return this.values=Rn(this.type.values),super.init()}set(t,e){super.set(t,e)&&this.values.set(t,e)}done(){return{...super.done(),values:this.values.array(this.index+1)}}}class ps extends ys{set(t,e){super.set(null==t?t:At(t),e)}}class Is extends ys{constructor(t,e,n){super(t,e),this.transform=n}set(t,e){super.set(null==t?t:this.transform(t),e)}}function bs(t={},e=Hn()){return{batchType:e=>Ke(e,t),builder(t){return gs(t,this)},dictionary(t){return e.get(t,this)},finish:()=>e.finish(t)}}function gs(t,e=bs()){const{typeId:n}=t;switch(n){case i.Int:case i.Time:case i.Duration:return E(t.values)?new ps(t,e):new ys(t,e);case i.Float:return t.precision?new ys(t,e):new Is(t,e,Ut);case i.Binary:case i.LargeBinary:return new Xn(t,e);case i.Utf8:case i.LargeUtf8:return new fs(t,e);case i.Bool:return new qn(t,e);case i.Decimal:return new Kn(t,e);case i.Date:return new Is(t,e,t.unit?At:St);case i.Timestamp:return new Is(t,e,(s=t.unit)===u.SECOND?t=>At(t/1e3):s===u.MILLISECOND?At:s===u.MICROSECOND?t=>At(1e3*t):t=>At(1e6*t));case i.Interval:switch(t.unit){case o.DAY_TIME:return new ts(t,e);case o.MONTH_DAY_NANO:return new es(t,e)}return new ys(t,e);case i.List:case i.LargeList:return new ss(t,e);case i.Struct:return new is(t,e);case i.Union:return t.mode?new hs(t,e):new ls(t,e);case i.FixedSizeBinary:return new Qn(t,e);case i.FixedSizeList:return new Zn(t,e);case i.Map:return new as(t,e);case i.RunEndEncoded:return new os(t,e);case i.Dictionary:return new Wn(t,e)}var s;throw new Error(C(n))}function vs(t,e,n,s,r){n??=Gn(e);const{maxBatchRows:a,...c}=s,u=Math.min(a||1/0,t);if(n.typeId===i.Null)return new Xe(function(t,e,n){const s=[],r=e=>new ce({length:e,nullCount:e,type:t}),i=Math.floor(e/n);for(let t=0;t<i;++t)s.push(r(n));const a=e%n;a&&s.push(r(a));return s}(n,t,u));const o=bs(c,r),d=gs(n,o).init(),l=[],h=t=>l.push(t.batch());let f=0;return e((t=>{d.set(t,f++),f>=u&&(h(d),f=0)})),f&&h(d),o.finish(),new Xe(l)}function ws(t,e,n={},s){return!e&&O(t)?function(t,{maxBatchRows:e,useBigInt:n}){const s=t.constructor,r=function(t){switch(t){case v:return q();case w:return K();case p:return _();case I:return $();case b:return Y();case g:return P();case l:return H();case h:return W();case f:return G();case y:return J()}}(s),i=t.length,a=Math.min(e||1/0,i),c=Math.floor(i/a),u=[],o=E(s)&&!n?ue:re,d=(e,n)=>u.push(new o({length:a,nullCount:0,type:r,values:t.subarray(e,n)}));let m=0;for(let t=0;t<c;++t)d(m,m+=a);m<i&&d(m,i);return new Xe(u)}(t,n):vs(t.length,(e=>t.forEach(e)),e,n,s)}function ms(t,e){const r=[],i=Array.isArray(t)?t:Object.entries(t),a=i[0]?.[1].length,c=i.map((([t,e])=>{if(e.length!==a)throw new Error("All columns must have the same length.");return r.push(V(t,e.type)),e})),u={version:n.V5,endianness:s.Little,fields:r,metadata:null};return new qe(u,c,e)}t.Batch=se,t.Column=Xe,t.DateUnit=c,t.Endianness=s,t.IntervalUnit=o,t.Precision=a,t.Table=qe,t.TimeUnit=u,t.Type=i,t.UnionMode=d,t.Version=n,t.batchType=Ke,t.binary=Q,t.binaryView=()=>j(i.BinaryView),t.bool=tt,t.columnFromArray=ws,t.columnFromValues=vs,t.date=nt,t.dateDay=st,t.dateMillisecond=()=>nt(c.MILLISECOND),t.decimal=et,t.dictionary=k,t.dictionaryContext=Hn,t.duration=ft,t.field=V,t.fixedSizeBinary=dt,t.fixedSizeList=lt,t.float=X,t.float16=()=>X(a.HALF),t.float32=q,t.float64=K,t.int=z,t.int16=$,t.int32=Y,t.int64=P,t.int8=_,t.interval=at,t.largeBinary=yt,t.largeList=It,t.largeListView=vt,t.largeUtf8=pt,t.list=ct,t.listView=gt,t.map=(t,e,n=!1)=>ht(n,V("entries",ut([F(t,"key",!1),F(e,"value")]),!1)),t.nullType=R,t.runEndEncoded=bt,t.struct=ut,t.tableFromArrays=function(t,e={}){const{types:n={},...s}=e,r=Hn();return ms((Array.isArray(t)?t:Object.entries(t)).map((([t,e])=>[t,ws(e,n[t],s,r)])),e.useProxy)},t.tableFromColumns=ms,t.tableFromIPC=function(t,e){return function(t,e={}){const{schema:n={fields:[]},dictionaries:s,records:r}=t,{version:a,fields:c}=n,u=new Map,o=function(t,e,n){const s={version:e,options:t,dictionary:t=>n.get(t)};return t=>{const{length:e,nodes:n,regions:r,variadic:i,body:a}=t;let c=-1,u=-1,o=-1;return{...s,length:e,node:()=>n[++c],buffer:t=>{const{length:e,offset:n}=r[++u];return t?new t(a.buffer,a.byteOffset+n,e/t.BYTES_PER_ELEMENT):a.subarray(n,n+e)},variadic:()=>i[++o],visit(t){return t.map((t=>In(t.type,this)))}}}}(e,a,u),d=new Map;!function(t,e){t.fields.forEach((function t(n){e(n),n.type.dictionary?.children?.forEach(t),n.type.children?.forEach(t)}))}(n,(t=>{const e=t.type;e.typeId===i.Dictionary&&d.set(e.id,e.dictionary)}));const l=new Map;for(const t of s){const{id:e,data:n,isDelta:s,body:r}=t,i=In(d.get(e),o({...n,body:r}));if(l.has(e)){const t=l.get(e);s||t.clear(),t.add(i)}else{if(s)throw new Error("Delta update can not be first dictionary batch.");l.set(e,Je().add(i))}}l.forEach(((t,e)=>u.set(e,t.done())));const h=c.map((()=>Je()));for(const t of r){const e=o(t);c.forEach(((t,n)=>h[n].add(In(t.type,e))))}return new qe(n,h.map((t=>t.done())),e.useProxy)}(pn(t),e)},t.tableToIPC=function(t,e){"string"==typeof e&&(e={format:e});const n=t.children,{dictionaries:s,idMap:r}=function(t){const e=[],n=new Map,s=new Map;let r=-1;const i=t=>{if(n.has(t))s.set(t.type,n.get(t));else{n.set(t,++r);for(let n=0;n<t.data.length;++n)e.push({id:r,isDelta:n>0,data:jn([t],n)});s.set(t.type,r)}};return t.forEach((t=>Fn(t.data[0],i))),{dictionaries:e,idMap:s}}(n),a=function(t){return(t[0]?.data||[]).map(((e,n)=>jn(t,n)))}(n),c=function(t,e){if(!e.size)return t;const n=t=>{t.typeId===i.Dictionary&&(t.id=e.get(t.dictionary),r(t)),t.children&&(t.children=t.children.slice()).forEach(s)},s=(t,e,s)=>{const r={...t.type};s[e]={...t,type:r},n(r)},r=t=>{const e={...t.dictionary};t.dictionary=e,n(e)};return t={...t,fields:t.fields.slice()},t.fields.forEach(s),t}(t.schema,r);return Tn({schema:c,dictionaries:s,records:a},e).finish()},t.time=rt,t.timeMicrosecond=()=>rt(u.MICROSECOND,64),t.timeMillisecond=()=>rt(u.MILLISECOND,32),t.timeNanosecond=()=>rt(u.NANOSECOND,64),t.timeSecond=()=>rt(u.SECOND,32),t.timestamp=it,t.uint16=W,t.uint32=G,t.uint64=J,t.uint8=H,t.union=ot,t.utf8=Z,t.utf8View=()=>j(i.Utf8View)})); | ||
//# sourceMappingURL=flechette.min.js.map |
@@ -10,2 +10,3 @@ /** | ||
batchType: (type: any) => any; | ||
builder(type: any): import("./builders/batch.js").BatchBuilder; | ||
dictionary(type: any): { | ||
@@ -12,0 +13,0 @@ type: import("../types.js").DictionaryType; |
@@ -5,3 +5,3 @@ /** | ||
export class FixedSizeListBuilder extends ValidityBuilder { | ||
child: import("./batch.js").BatchBuilder; | ||
child: any; | ||
stride: any; | ||
@@ -11,3 +11,3 @@ init(): this; | ||
done(): { | ||
children: import("../../batch.js").Batch<any>[]; | ||
children: any[]; | ||
length: number; | ||
@@ -14,0 +14,0 @@ nullCount: number; |
--- | ||
title: Column | API Reference | ||
--- | ||
# API Reference | ||
# Flechette API Reference <a href="https://idl.uw.edu/flechette"><img align="right" src="../assets/logo.svg" height="38"/></a> | ||
@@ -6,0 +6,0 @@ [Top-Level](/flechette/api) | [Data Types](data-types) | [Table](table) | [**Column**](column) |
--- | ||
title: Data Types | API Reference | ||
--- | ||
# API Reference | ||
# Flechette API Reference <a href="https://idl.uw.edu/flechette"><img align="right" src="../assets/logo.svg" height="38"/></a> | ||
@@ -97,2 +97,15 @@ [Top-Level](/flechette/api) | [**Data Types**](data-types) | [Table](table) | [Column](column) | ||
```js | ||
import { dictionary, int16, utf8 } from '@uwdata/flechette'; | ||
// dictionary type with string values and int16 indices | ||
// { | ||
// typeId: -1, | ||
// id: -1, | ||
// dictionary: { typeId: 5, ... }, | ||
// indices: { typeId: 2, bitWidth: 16, signed: true, ... } | ||
// ordered: false | ||
// } | ||
dictionary(utf8(), int16()) | ||
``` | ||
### Null | ||
@@ -105,2 +118,8 @@ | ||
```js | ||
import { nullType } from '@uwdata/flechette'; | ||
// { typeId: 1 } | ||
nullType() | ||
``` | ||
### Int | ||
@@ -116,2 +135,8 @@ | ||
```js | ||
import { int } from '@uwdata/flechette'; | ||
// { typeId: 2, bitWidth: 32, signed: true, ... } | ||
int() | ||
``` | ||
<hr/><a id="int8" href="#int8">#</a> | ||
@@ -166,2 +191,8 @@ <b>int8</b>() | ||
```js | ||
import { float } from '@uwdata/flechette'; | ||
// { typeId: 3, precision: 2, ... } | ||
float() | ||
``` | ||
<hr/><a id="float16" href="#float16">#</a> | ||
@@ -189,2 +220,8 @@ <b>float16</b>() | ||
```js | ||
import { binary } from '@uwdata/flechette'; | ||
// { typeId: 4 } | ||
binary() | ||
``` | ||
### Utf8 | ||
@@ -197,2 +234,8 @@ | ||
```js | ||
import { utf8 } from '@uwdata/flechette'; | ||
// { typeId: 5 } | ||
utf8() | ||
``` | ||
### Bool | ||
@@ -205,2 +248,8 @@ | ||
```js | ||
import { bool } from '@uwdata/flechette'; | ||
// { typeId: 6 } | ||
bool() | ||
``` | ||
### Decimal | ||
@@ -219,2 +268,9 @@ | ||
```js | ||
import { utf8 } from '@uwdata/flechette'; | ||
// decimal with 18 total digits, including 3 fractional digits | ||
// { typeId: 7, precision: 18, scale: 3, bitWidth: 128, ... } | ||
decimal(18, 3) | ||
``` | ||
### Date | ||
@@ -231,2 +287,8 @@ | ||
```js | ||
import { DateUnit, date } from '@uwdata/flechette'; | ||
// { typeId: 8, unit: 0, ... } | ||
date(DateUnit.DAY) | ||
``` | ||
<hr/><a id="dateDay" href="#dateDay">#</a> | ||
@@ -237,2 +299,8 @@ <b>dateDay</b>() | ||
```js | ||
import { dateDay } from '@uwdata/flechette'; | ||
// { typeId: 8, unit: 0, ... } | ||
dateDay() | ||
``` | ||
<hr/><a id="dateMillisecond" href="#dateMillisecond">#</a> | ||
@@ -243,2 +311,8 @@ <b>dateMillisecond</b>() | ||
```js | ||
import { dateMillisecond } from '@uwdata/flechette'; | ||
// { typeId: 8, unit: 1, ... } | ||
dateMillisecond() | ||
``` | ||
### Time | ||
@@ -258,2 +332,10 @@ | ||
```js | ||
import { TimeUnit, time } from '@uwdata/flechette'; | ||
// { typeId: 9, unit: 1, bitWidth: 32, ... } | ||
time() | ||
// { typeId: 9, unit: 2, bitWidth: 64, ... } | ||
time(TimeUnit.MICROSECONDS, 64) | ||
``` | ||
<hr/><a id="timeSecond" href="#timeSecond">#</a> | ||
@@ -264,2 +346,8 @@ <b>timeSecond</b>() | ||
```js | ||
import { timeSecond } from '@uwdata/flechette'; | ||
// { typeId: 9, unit: 0, bitWidth: 32, ... } | ||
timeSecond() | ||
``` | ||
<hr/><a id="timeMillisecond" href="#timeMillisecond">#</a> | ||
@@ -270,2 +358,8 @@ <b>timeMillisecond</b>() | ||
```js | ||
import { timeMillisecond } from '@uwdata/flechette'; | ||
// { typeId: 9, unit: 1, bitWidth: 32, ... } | ||
timeMillisecond() | ||
``` | ||
<hr/><a id="timeMicrosecond" href="#timeMicrosecond">#</a> | ||
@@ -276,2 +370,8 @@ <b>timeMicrosecond</b>() | ||
```js | ||
import { timeMicrosecond } from '@uwdata/flechette'; | ||
// { typeId: 9, unit: 2, bitWidth: 64, ... } | ||
timeMicrosecond() | ||
``` | ||
<hr/><a id="timeNanosecond" href="#timeNanosecond">#</a> | ||
@@ -282,2 +382,8 @@ <b>timeNanosecond</b>() | ||
```js | ||
import { timeNanosecond } from '@uwdata/flechette'; | ||
// { typeId: 9, unit: 3, bitWidth: 64, ... } | ||
timeNanosecond() | ||
``` | ||
### Timestamp | ||
@@ -293,4 +399,12 @@ | ||
* *unit* (`number`): The time unit, one of `TimeUnit.SECOND`, `TimeUnit.MILLISECOND` (default), `TimeUnit.MICROSECOND`, or `TimeUnit.NANOSECOND`. | ||
* *timezone* (`string`): An optional string for the name of a timezone. If provided, the value should either be a string as used in the Olson timezone database (the "tz database" or "tzdata"), such as "America/New_York", or an absolute timezone offset of the form "+XX:XX" or "-XX:XX", such as "+07:30". Whether a timezone string is present indicates different semantics about the data. | ||
* *timezone* (`string`): An optional string for the name of a timezone. If provided, the value should either be a string as used in the Olson timezone database (the "tz database" or "tzdata"), such as "America/New_York", or an absolute timezone offset of the form "+XX:XX" or "-XX:XX", such as "+07:30". Whether a timezone string is present indicates different semantics about the data. That said, Flechette does not process the timezone information. | ||
```js | ||
import { timestamp } from '@uwdata/flechette'; | ||
// { typeId: 10, unit: 1, timezone: null, ... } | ||
timestamp() | ||
// { typeId: 10, unit: 2, timezone: 'Europe/Berlin', ... } | ||
timestamp(TimeUnit.MICROSECOND, 'Europe/Berlin') | ||
``` | ||
### Interval | ||
@@ -311,2 +425,10 @@ | ||
```js | ||
import { interval } from '@uwdata/flechette'; | ||
// { typeId: 11, unit: 0, ... } | ||
interval(IntervalUnit.YEAR_MONTH) | ||
// { typeId: 11, unit: 2, ... } | ||
interval(IntervalUnit.MONTH_DAY_NANO) | ||
``` | ||
### List | ||
@@ -321,2 +443,16 @@ | ||
```js | ||
import { int32, list } from '@uwdata/flechette'; | ||
// { | ||
// typeId: 12, | ||
// children: [{ | ||
// name: '', | ||
// type: type: { typeId: 2, bitWidth: 32, signed: true, ... }, | ||
// ... | ||
// }], | ||
// ... | ||
// } | ||
list(int32()) | ||
``` | ||
### Struct | ||
@@ -333,12 +469,16 @@ | ||
*Examples* | ||
```js | ||
import { bool, float32, int16, struct } from '@uwdata/flechette'; | ||
import { bool, field, float32, int16, struct } from '@uwdata/flechette'; | ||
// using an object with property names and types | ||
// { | ||
// typeId: 13, | ||
// children: [ | ||
// { name: 'foo', type: { typeId: 2, bitWidth: 16, ... }, ... }, | ||
// { name: 'bar', type: { typeId: 6 }, ... }, | ||
// { name: 'baz', type: { typeId: 3, precision: 1, ... }, ... } | ||
// ] | ||
// } | ||
struct({ foo: int16(), bar: bool(), baz: float32() }) | ||
``` | ||
```js | ||
import { bool, field, float32, int16, struct } from '@uwdata/flechette'; | ||
// using an array of Field instances | ||
@@ -368,2 +508,23 @@ struct([ | ||
```js | ||
import { float64, utf8, union } from '@uwdata/flechette'; | ||
// { | ||
// typeId: 14, | ||
// mode: 1, | ||
// typeIds: [ 0, 1 ], | ||
// typeMap: { '0': 0, '1': 1 }, | ||
// children: [ | ||
// { name: '_0', type: { typeId: 3, precision: 2, ... }, ... }, | ||
// { name: '_1', type: { typeId: 5 }, ... } | ||
// ], | ||
// typeIdForValue: <<function>> | ||
// } | ||
union( | ||
UnionMode.Dense, | ||
[float64(), utf8()], | ||
[0, 1], | ||
v => typeof v === 'string' ? 1 : 0 | ||
) | ||
``` | ||
### FixedSizeBinary | ||
@@ -378,2 +539,8 @@ | ||
```js | ||
import { fixedSizeBinary } from '@uwdata/flechette'; | ||
// { typeId: 15, stride: 128 } | ||
fixedSizeBinary(128) | ||
``` | ||
### FixedSizeList | ||
@@ -389,2 +556,12 @@ | ||
```js | ||
import { fixedSizeList, float32 } from '@uwdata/flechette'; | ||
// { | ||
// typeId: 16, | ||
// stride: 8, | ||
// children: [ { name: '', type: { typeId: 3, precision: 1, ... }, ... } ] | ||
// } | ||
fixedSizeList(float32(), 8) | ||
``` | ||
### Map | ||
@@ -403,2 +580,22 @@ | ||
```js | ||
import { int64, map, utf8 } from '@uwdata/flechette'; | ||
// { | ||
// typeId: 17, | ||
// keysSorted: false, | ||
// children: [{ | ||
// name: 'entries', | ||
// type: { | ||
// typeId: 13, | ||
// children: [ | ||
// { name: 'key', type: { typeId: 5 }, ... }, | ||
// { name: 'value', type: { typeId: 2, bitWidth: 64, ... }, ... } | ||
// ] | ||
// }, ... | ||
// } | ||
// ]}, ... | ||
// } | ||
map(utf8(), int64()) | ||
``` | ||
### Duration | ||
@@ -415,2 +612,8 @@ | ||
```js | ||
import { duration } from '@uwdata/flechette'; | ||
// { typeId: 18, unit: 1, ... } | ||
duration() | ||
``` | ||
### LargeBinary | ||
@@ -423,2 +626,8 @@ | ||
```js | ||
import { largeBinary } from '@uwdata/flechette'; | ||
// { typeId: 19, ... } | ||
largeBinary() | ||
``` | ||
### LargeUtf8 | ||
@@ -431,2 +640,8 @@ | ||
```js | ||
import { largeUtf8 } from '@uwdata/flechette'; | ||
// { typeId: 20, ... } | ||
largeUtf8() | ||
``` | ||
### LargeList | ||
@@ -441,2 +656,8 @@ | ||
```js | ||
import { largeList, utf8 } from '@uwdata/flechette'; | ||
// { typeId: 21, children: [ { name: '', type: { typeId: 5 }, ... } ], ... } | ||
largeList(utf8()) | ||
``` | ||
### RunEndEncoded | ||
@@ -454,8 +675,13 @@ | ||
*Examples* | ||
```js | ||
import { int32, runEndEncoded, utf8 } from '@uwdata/flechette'; | ||
// 32-bit integer run ends and utf8 string values | ||
const type = runEndEncoded(int32(), utf8()); | ||
// { | ||
// typeId: 22, | ||
// children: [ | ||
// { name: 'run_ends', type: { typeId: 2, bitWidth: 32, ... }, ... }, | ||
// { name: 'values', type: { typeId: 5 }, ... } | ||
// ] | ||
// } | ||
runEndEncoded(int32(), utf8()) | ||
``` | ||
@@ -472,2 +698,8 @@ | ||
```js | ||
import { binaryView } from '@uwdata/flechette'; | ||
// { typeId: 23 } | ||
binaryView() | ||
``` | ||
### Utf8View | ||
@@ -482,2 +714,8 @@ | ||
```js | ||
import { utf8View } from '@uwdata/flechette'; | ||
// { typeId: 24 } | ||
utf8View() | ||
``` | ||
### ListView | ||
@@ -494,2 +732,11 @@ | ||
```js | ||
import { float16, listView } from '@uwdata/flechette'; | ||
// { | ||
// typeId: 25, | ||
// children: [ { name: 'value', type: { typeId: 3, ... }, ... } ] | ||
// } | ||
listView(float16()) | ||
``` | ||
### LargeListView | ||
@@ -505,1 +752,10 @@ | ||
* *child* (`DataType | Field`): The child (list item) field or data type. | ||
```js | ||
import { float16, largeListView } from '@uwdata/flechette'; | ||
// { | ||
// typeId: 26, | ||
// children: [ { name: 'value', type: { typeId: 3, ... }, ... } ] | ||
// } | ||
largeListView(float16()) | ||
``` |
--- | ||
title: API Reference | ||
--- | ||
# API Reference | ||
# Flechette API Reference <a href="https://idl.uw.edu/flechette"><img align="right" src="../assets/logo.svg" height="38"/></a> | ||
@@ -29,4 +29,2 @@ [**Top-Level**](/flechette/api) | [Data Types](data-types) | [Table](table) | [Column](column) | ||
*Examples* | ||
```js | ||
@@ -48,4 +46,2 @@ import { tableFromIPC } from '@uwdata/flechette'; | ||
*Examples* | ||
```js | ||
@@ -67,4 +63,2 @@ import { tableToIPC } from '@uwdata/flechette'; | ||
*Examples* | ||
```js | ||
@@ -114,23 +108,13 @@ import { tableFromArrays } from '@uwdata/flechette'; | ||
*Examples* | ||
```js | ||
import { columnFromArray } from '@uwdata/flechette'; | ||
import { columnFromArray, float32, int64 } from '@uwdata/flechette'; | ||
// create column with inferred type (here, float64) | ||
const col = columnFromArray([1.1, 2.2, 3.3, 4.4, 5.5]); | ||
``` | ||
columnFromArray([1.1, 2.2, 3.3, 4.4, 5.5]); | ||
```js | ||
import { columnFromArray, float32 } from '@uwdata/flechette'; | ||
// create column with specified type | ||
const col = columnFromArray([1.1, 2.2, 3.3, 4.4, 5.5], float32()); | ||
``` | ||
columnFromArray([1.1, 2.2, 3.3, 4.4, 5.5], float32()); | ||
```js | ||
import { columnFromArray, int64 } from '@uwdata/flechette'; | ||
// create column with specified type and options | ||
const col = columnFromArray( | ||
columnFromArray( | ||
[1n, 32n, 2n << 34n], int64(), | ||
@@ -149,4 +133,2 @@ { maxBatchRows: 1000, useBigInt: true } | ||
*Examples* | ||
```js | ||
@@ -153,0 +135,0 @@ import { columnFromArray, tableFromColumns } from '@uwdata/flechette'; |
--- | ||
title: Table | API Reference | ||
--- | ||
# API Reference | ||
# Flechette API Reference <a href="https://idl.uw.edu/flechette"><img align="right" src="../assets/logo.svg" height="38"/></a> | ||
@@ -6,0 +6,0 @@ [Top-Level](/flechette/api) | [Data Types](data-types) | [**Table**](table) | [Column](column) |
@@ -0,1 +1,3 @@ | ||
# Flechette <a href="https://idl.uw.edu/flechette"><img align="right" src="assets/logo.svg" height="38"/></a> | ||
**Flechette** is a JavaScript library for reading and writing the [Apache Arrow](https://arrow.apache.org/) columnar in-memory data format. It provides a faster, lighter, zero-dependency alternative to the [Arrow JS reference implementation](https://github.com/apache/arrow/tree/main/js). | ||
@@ -5,3 +7,3 @@ | ||
For documentation, see the [**API Reference**](api). | ||
For documentation, see the [**API Reference**](api). For code, see the [**Flechette GitHub repo**](https://github.com/uwdata/flechette). | ||
@@ -14,5 +16,5 @@ ## Why Flechette? | ||
* _Size_. Flechette is smaller: ~42k minified (~14k gzip'd) versus 163k minified (~43k gzip'd) for Arrow JS. Flechette's encoders and decoders also tree-shake cleanly, so only pay for what you need in your own bundles. | ||
* _Size_. Flechette is smaller: ~43k minified (~14k gzip'd) versus 163k minified (~43k gzip'd) for Arrow JS. Flechette's encoders and decoders also tree-shake cleanly, so you only pay for what you need in custom bundles. | ||
* _Coverage_. Flechette supports data types unsupported by the reference implementation, including decimal-to-number conversion, month/day/nanosecond time intervals (as used by DuckDB, for example), run-end encoded data, binary views, and list views. | ||
* _Coverage_. Flechette supports data types unsupported by the reference implementation, including decimal-to-number conversion, month/day/nanosecond time intervals (as used by DuckDB), run-end encoded data, binary views, and list views. | ||
@@ -19,0 +21,0 @@ * _Flexibility_. Flechette includes options to control data value conversion, such as numerical timestamps vs. Date objects for temporal data, and numbers vs. bigint values for 64-bit integer data. |
import js from '@eslint/js'; | ||
import globals from 'globals'; | ||
/** @type {import('@types/eslint').Linter.FlatConfig[]} */ | ||
/** @type {import('@types/eslint').Linter.Config[]} */ | ||
export default [ | ||
@@ -6,0 +6,0 @@ js.configs.recommended, |
{ | ||
"name": "@uwdata/flechette", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "Fast, lightweight access to Apache Arrow data.", | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
"type": "module", | ||
"main": "./src/index.js", | ||
"main": "./dist/flechette.cjs", | ||
"module": "./src/index.js", | ||
@@ -29,3 +29,3 @@ "jsdelivr": "./dist/flechette.min.js", | ||
"prebuild": "rimraf dist && mkdir dist", | ||
"build": "node esbuild.js flechette", | ||
"build": "rollup -c rollup.config.js", | ||
"types": "tsc --project tsconfig.json && npm run types:merge", | ||
@@ -39,10 +39,12 @@ "types:merge": "cd dist/types; cat types.d.ts >> index.d.ts", | ||
"devDependencies": { | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@uwdata/mosaic-duckdb": "^0.10.0", | ||
"apache-arrow": "^17.0.0", | ||
"esbuild": "^0.23.1", | ||
"eslint": "^9.10.0", | ||
"mocha": "^10.7.3", | ||
"rimraf": "^6.0.1", | ||
"rollup": "^4.21.3", | ||
"rollup-plugin-bundle-size": "^1.0.3", | ||
"typescript": "^5.6.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Flechette | ||
# Flechette <a href="https://idl.uw.edu/flechette"><img align="right" src="https://raw.githubusercontent.com/uwdata/flechette/main/docs/assets/logo.svg" height="38"></img></a> | ||
@@ -7,3 +7,3 @@ **Flechette** is a JavaScript library for reading and writing the [Apache Arrow](https://arrow.apache.org/) columnar in-memory data format. It provides a faster, lighter, zero-dependency alternative to the [Arrow JS reference implementation](https://github.com/apache/arrow/tree/main/js). | ||
For documentation, see the [**API Reference**](https://idl.uw.edu/flechette/api). | ||
For documentation, see the [**API Reference**](https://idl.uw.edu/flechette/api). For code, see the [**Flechette GitHub repo**](https://github.com/uwdata/flechette). | ||
@@ -16,5 +16,5 @@ ## Why Flechette? | ||
* _Size_. Flechette is smaller: ~42k minified (~14k gzip'd) versus 163k minified (~43k gzip'd) for Arrow JS. Flechette's encoders and decoders also tree-shake cleanly, so only pay for what you need in your own bundles. | ||
* _Size_. Flechette is smaller: ~43k minified (~14k gzip'd) versus 163k minified (~43k gzip'd) for Arrow JS. Flechette's encoders and decoders also tree-shake cleanly, so you only pay for what you need in custom bundles. | ||
* _Coverage_. Flechette supports data types unsupported by the reference implementation, including decimal-to-number conversion, month/day/nanosecond time intervals (as used by DuckDB, for example), run-end encoded data, binary views, and list views. | ||
* _Coverage_. Flechette supports data types unsupported by the reference implementation, including decimal-to-number conversion, month/day/nanosecond time intervals (as used by DuckDB), run-end encoded data, binary views, and list views. | ||
@@ -21,0 +21,0 @@ * _Flexibility_. Flechette includes options to control data value conversion, such as numerical timestamps vs. Date objects for temporal data, and numbers vs. bigint values for 64-bit integer data. |
@@ -34,2 +34,3 @@ import { batchType } from '../batch-type.js'; | ||
batchType: type => batchType(type, options), | ||
builder(type) { return builder(type, this); }, | ||
dictionary(type) { return dictionaries.get(type, this); }, | ||
@@ -36,0 +37,0 @@ finish: () => dictionaries.finish(options) |
@@ -5,3 +5,2 @@ import { Column } from '../../column.js'; | ||
import { buffer } from '../buffer.js'; | ||
import { builder } from '../builder.js'; | ||
import { ValidityBuilder } from './validity.js'; | ||
@@ -57,3 +56,3 @@ | ||
const keys = Object.create(null); | ||
const values = builder(type.dictionary, ctx); | ||
const values = ctx.builder(type.dictionary); | ||
const batches = []; | ||
@@ -60,0 +59,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { builder } from '../builder.js'; | ||
import { ValidityBuilder } from './validity.js'; | ||
@@ -10,3 +9,3 @@ | ||
super(type, ctx); | ||
this.child = builder(this.type.children[0].type, this.ctx); | ||
this.child = ctx.builder(this.type.children[0].type); | ||
this.stride = type.stride; | ||
@@ -13,0 +12,0 @@ } |
import { toOffset } from '../../util/numbers.js'; | ||
import { buffer } from '../buffer.js'; | ||
import { builder } from '../builder.js'; | ||
import { ValidityBuilder } from './validity.js'; | ||
@@ -38,3 +37,3 @@ | ||
constructor(type, ctx) { | ||
super(type, ctx, builder(type.children[0].type, ctx)); | ||
super(type, ctx, ctx.builder(type.children[0].type)); | ||
} | ||
@@ -41,0 +40,0 @@ |
import { keyString } from '../../util/strings.js'; | ||
import { BatchBuilder } from './batch.js'; | ||
import { builder } from '../builder.js'; | ||
@@ -13,3 +12,3 @@ const NO_VALUE = {}; // empty object that fails strict equality | ||
super(type, ctx); | ||
this.children = type.children.map(c => builder(c.type, ctx)); | ||
this.children = type.children.map(c => ctx.builder(c.type)); | ||
} | ||
@@ -16,0 +15,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { builder } from '../builder.js'; | ||
import { ValidityBuilder } from './validity.js'; | ||
@@ -10,3 +9,3 @@ | ||
super(type, ctx); | ||
this.children = type.children.map(c => builder(c.type, ctx)); | ||
this.children = type.children.map(c => ctx.builder(c.type)); | ||
} | ||
@@ -13,0 +12,0 @@ |
import { int8Array } from '../../util/arrays.js'; | ||
import { BatchBuilder } from './batch.js'; | ||
import { buffer } from '../buffer.js'; | ||
import { builder } from '../builder.js'; | ||
@@ -12,3 +11,3 @@ /** | ||
super(type, ctx); | ||
this.children = type.children.map(c => builder(c.type, ctx)); | ||
this.children = type.children.map(c => ctx.builder(c.type)); | ||
this.typeMap = type.typeMap; | ||
@@ -15,0 +14,0 @@ this.lookup = type.typeIdForValue; |
@@ -26,4 +26,4 @@ import { DateUnit, IntervalUnit, Precision, TimeUnit, Type, UnionMode } from './constants.js'; | ||
name, | ||
type, | ||
nullable, | ||
type, | ||
metadata | ||
@@ -100,6 +100,6 @@ }); | ||
typeId: Type.Dictionary, | ||
id, | ||
dictionary: type, | ||
indices: indexType || int32(), | ||
ordered, | ||
id | ||
ordered | ||
}); | ||
@@ -106,0 +106,0 @@ |
1090227
96.47%130
2.36%21118
52.71%9
28.57%