@uwdata/flechette
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,2 +0,2 @@ | ||
!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,b=Int16Array,I=Int32Array,g=BigInt64Array,v=Float32Array,w=Float64Array;function m(t,e){const n=Math.log2(t)-3;return(e?[p,b,I,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 S(t,e,n){for(;t.length<=e;)t=A(t,t.length<<1,n?t.length:0);return t}function N(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),N(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,N(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}),z=()=>j(i.Null),R=(t=32,e=!0)=>({typeId:i.Int,bitWidth:B(t,[8,16,32,64]),signed:e,values:m(t,e)}),_=()=>R(8),$=()=>R(16),Y=()=>R(32),P=()=>R(64),H=()=>R(8,!1),W=()=>R(16,!1),G=()=>R(32,!1),J=()=>R(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:I}),Z=()=>({typeId:i.Utf8,offsets:I}),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?I: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?I: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:I}),ct=t=>({typeId:i.List,children:[F(t)],offsets:I}),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:I}),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:I}),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}),bt=t=>({typeId:i.LargeList,children:[F(t)],offsets:g}),It=(t,e)=>({typeId:i.RunEndEncoded,children:[N(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:I}),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 I(mt),Et=new l(mt);function Dt(t){return t}function At(t){return BigInt(t)}function St(t){return E(t)?At:Dt}function Nt(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 zt(t){return jt.encode(t)}function Rt(t){return`${"object"==typeof t&&t?function(t){return t instanceof Date}(t)?+t:L(t)?`[${t.map(Rt)}]`:function(t){let e="",n=-1;for(const s in t)++n>0&&(e+=","),e+=`"${s}":${Rt(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 be=ue;class Ie 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 Se extends ae{value(t){return kt(Le(this,t))}}class Ne 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 ze 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 Re extends ze{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(t){let e=[];return{add(t){return e.push(t),this},clear:()=>e=[],done:()=>new Xe(e,t)}}class Xe{constructor(t,e=t[0]?.type){this.type=e,this.length=t.reduce(((t,e)=>t+e.length),0),this.nullCount=t.reduce(((t,e)=>t+e.nullCount),0),this.data=t;const n=t.length,s=new Int32Array(n+1);if(1===n){const[e]=t;s[1]=e.length,this.at=t=>e.at(t)}else for(let e=0,r=0;e<n;++e)s[e+1]=r+=t[e].length;this.offsets=s}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:be,l&&ye);case i.Timestamp:return Qe(a===u.SECOND?Ie: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 Se;case i.Binary:return Ee;case i.LargeBinary:return De;case i.BinaryView:return We;case i.Utf8View:return Ge;case i.List:return Ne;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?Re:ze}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 bt(s[0]);case i.LargeListView:return vt(s[0]);case i.Struct:return ut(s);case i.RunEndEncoded:return It(s[0],s[1]);case i.Int:return R(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 s instanceof Uint8Array&&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){if(!(t instanceof Uint8Array))throw new Error("IPC data batch was not a Uint8Array.");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 bn(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 In(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){In(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,In(d,t.space,o-r);else{const e=t.offset();l.push(e),In(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=zt(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=S(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 Sn(t,{offset:e,metadataLength:n,bodyLength:s}){return t.writeInt64(s),t.writeInt32(0),t.writeInt32(n),t.writeInt64(e),t.offset()}function Nn(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&&Nn(d,r.Schema,Dn(d,a),0);for(const t of c){const{data:e}=t;Nn(d,r.DictionaryBatch,xn(d,t),e.byteLength,h),Un(d,e.buffers)}for(const t of u)Nn(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,Sn),o=t.addVector(r,24,8,Sn),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 zn(t){return new Rn(t)}class Rn{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=S(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 Rn{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=Rt(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=zn(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,b=1/0,I=-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<b&&(b=t),t>I&&(I=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?z():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(),b,I):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=St(t.offsets)}init(){return this.offsets=zn(this.type.offsets),this.values=zn(),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=zn(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=zn(),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=zn(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=zn(),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=zn(t),this.toOffset=St(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=Rt(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=zn(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=zn(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&&zt(t),e)}}class ys extends Pn{constructor(t,e){super(t,e),this.values=zn(t.values)}init(){return this.values=zn(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 bs 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 Is(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=Is()){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 bs(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 bs(t,e,t.unit?At:Nt);case i.Timestamp:return new bs(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){const r="function"==typeof t[Symbol.iterator]?e=>{for(const n of t)e(n)}:t;e??=Gn(r);const{maxBatchRows:a=1/0,...c}=n;let u;if(e.typeId===i.Null){let t=0;r((()=>++t)),u=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}(e,t,a)}else{const t=Is(c,s),n=gs(e,t).init(),i=t=>u.push(t.batch());u=[];let o=0;r((t=>{n.set(t,o++),o>=a&&(i(n),o=0)})),o&&i(n),t.finish()}return new Xe(u,e)}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 b:return $();case I: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:n-e,nullCount:0,type:r,validity:new l(0),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((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=R,t.int16=$,t.int32=Y,t.int64=P,t.int8=_,t.interval=at,t.largeBinary=yt,t.largeList=bt,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=z,t.runEndEncoded=It,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=>bn(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=d.get(e),a=bn(i,o({...n,body:r}));if(l.has(e)){const t=l.get(e);s||t.clear(),t.add(a)}else{if(s)throw new Error("Delta update can not be first dictionary batch.");l.set(e,Je(i).add(a))}}l.forEach(((t,e)=>u.set(e,t.done())));const h=c.map((t=>Je(t.type)));for(const t of r){const e=o(t);c.forEach(((t,n)=>h[n].add(bn(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;!function(t){const e=t[0]?.data.map((t=>t.length));t.forEach((({data:t})=>{if(t.length!==e.length||t.some(((t,n)=>t.length!==e[n])))throw new Error("Columns have inconsistent batch sizes.")}))}(n);const{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)})); | ||
!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=Uint8Array.of(255,255,255,255,0,0,0,0),s={V1:0,V2:1,V3:2,V4:3,V5:4},r={Little:0,Big:1},i={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},c={HALF:0,SINGLE:1,DOUBLE:2},u={DAY:0,MILLISECOND:1},o={SECOND:0,MILLISECOND:1,MICROSECOND:2,NANOSECOND:3},d={YEAR_MONTH:0,DAY_TIME:1,MONTH_DAY_NANO:2},l={Sparse:0,Dense:1},h=Uint8Array,f=Uint16Array,y=Uint32Array,p=BigUint64Array,b=Int8Array,I=Int16Array,g=Int32Array,v=BigInt64Array,w=Float32Array,m=Float64Array;function x(t,e){const n=Math.log2(t)-3;return(e?[b,I,g,v]:[h,f,y,p])[n]}const O=Object.getPrototypeOf(Int8Array);function L(t){return t instanceof O}function E(t){return Array.isArray(t)||L(t)}function D(t){return t===v||t===p}function A(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 S(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=S(t,t.length<<1,n?t.length:0);return t}function B(t,e,n){if(e(t))return t;throw new Error(n(t))}function M(t,e,n){return e=Array.isArray(e)?e:Object.values(e),B(t,(t=>e.includes(t)),n??(()=>`${t} must be one of ${e}`))}function C(t,e){for(const[n,s]of Object.entries(t))if(s===e)return n;return"<Unknown>"}const U=t=>`Unsupported data type: "${C(a,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")&&F(t.type)}function F(t){return"number"==typeof t?.typeId}function j(t,e="",n=!0){return T(t)?t:V(e,B(t,F,(()=>"Data type expected.")),n)}const k=t=>({typeId:t}),z=(t,e,n=!1,s=-1)=>({typeId:a.Dictionary,id:s,dictionary:t,indices:e||P(),ordered:n}),R=()=>k(a.Null),_=(t=32,e=!0)=>({typeId:a.Int,bitWidth:M(t,[8,16,32,64]),signed:e,values:x(t,e)}),$=()=>_(8),Y=()=>_(16),P=()=>_(32),H=()=>_(64),W=()=>_(8,!1),G=()=>_(16,!1),J=()=>_(32,!1),X=()=>_(64,!1),q=(t=2)=>({typeId:a.Float,precision:M(t,c),values:[f,w,m][t]}),K=()=>q(c.SINGLE),Q=()=>q(c.DOUBLE),Z=()=>({typeId:a.Binary,offsets:g}),tt=()=>({typeId:a.Utf8,offsets:g}),et=()=>k(a.Bool),nt=(t,e,n=128)=>({typeId:a.Decimal,precision:t,scale:e,bitWidth:M(n,[128,256]),values:p}),st=t=>({typeId:a.Date,unit:M(t,u),values:t===u.DAY?g:v}),rt=()=>st(u.DAY),it=(t=o.MILLISECOND,e=32)=>({typeId:a.Time,unit:M(t,o),bitWidth:M(e,[32,64]),values:32===e?g:v}),at=(t=o.MILLISECOND,e=null)=>({typeId:a.Timestamp,unit:M(t,o),timezone:e,values:v}),ct=(t=d.MONTH_DAY_NANO)=>({typeId:a.Interval,unit:M(t,d),values:t===d.MONTH_DAY_NANO?void 0:g}),ut=t=>({typeId:a.List,children:[j(t)],offsets:g}),ot=t=>({typeId:a.Struct,children:Array.isArray(t)&&T(t[0])?t:Object.entries(t).map((([t,e])=>V(t,e)))}),dt=(t,e,n,s)=>(n??=e.map(((t,e)=>e)),{typeId:a.Union,mode:M(t,l),typeIds:n,typeMap:n.reduce(((t,e,n)=>(t[e]=n,t)),{}),children:e.map(((t,e)=>j(t,`_${e}`))),typeIdForValue:s,offsets:g}),lt=t=>({typeId:a.FixedSizeBinary,stride:t}),ht=(t,e)=>({typeId:a.FixedSizeList,stride:e,children:[j(t)]}),ft=(t,e)=>({typeId:a.Map,keysSorted:t,children:[e],offsets:g}),yt=(t=o.MILLISECOND)=>({typeId:a.Duration,unit:M(t,o),values:v}),pt=()=>({typeId:a.LargeBinary,offsets:v}),bt=()=>({typeId:a.LargeUtf8,offsets:v}),It=t=>({typeId:a.LargeList,children:[j(t)],offsets:v}),gt=(t,e)=>({typeId:a.RunEndEncoded,children:[B(j(t,"run_ends"),(t=>t.type.typeId===a.Int),(()=>"Run-ends must have an integer type.")),j(e,"values")]}),vt=t=>({typeId:a.ListView,children:[j(t,"value")],offsets:g}),wt=t=>({typeId:a.LargeListView,children:[j(t,"value")],offsets:v}),mt=new m(2),xt=mt.buffer,Ot=new v(xt),Lt=new y(xt),Et=new g(xt),Dt=new h(xt);function At(t){return t}function St(t){return BigInt(t)}function Nt(t){return D(t)?St:At}function Bt(t){return t/864e5|0}function Mt(t){if(t>Number.MAX_SAFE_INTEGER||t<Number.MIN_SAFE_INTEGER)throw Error(`BigInt exceeds integer number representation: ${t}`);return Number(t)}function Ct(t,e){return Number(t/e)+Number(t%e)/Number(e)}const Ut=t=>BigInt.asUintN(64,t);function Vt(t,e){const n=e<<1;let s;return BigInt.asIntN(64,t[n+1])<0?(s=Ut(~t[n])|Ut(~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=Ut(~t[n])|Ut(~t[n+1])<<64n|Ut(~t[n+2])<<128n|Ut(~t[n+3])<<192n,s=-(s+1n)):s=t[n]|t[n+1]<<64n|t[n+2]<<128n|t[n+3]<<192n,s}function Ft(t){if(t!=t)return 32256;mt[0]=t;const e=(2147483648&Lt[1])>>16&65535;let n=2146435072&Lt[1],s=0;return n>=1089470464?Lt[0]>0?n=31744:(n=(2080374784&n)>>16,s=(1048575&Lt[1])>>10):n<=1056964608?(s=1048576+(1048575&Lt[1]),s=1048576+(s<<(n>>20)-998)>>21,n=0):(n=n-1056964608>>10,s=512+(1048575&Lt[1])>>10),e|n|65535&s}const jt=new TextDecoder("utf-8"),kt=new TextEncoder;function zt(t){return jt.decode(t)}function Rt(t){return kt.encode(t)}function _t(t){return`${"object"==typeof t&&t?function(t){return t instanceof Date}(t)?+t:E(t)?`[${t.map(_t)}]`:function(t){let e="",n=-1;for(const s in t)++n>0&&(e+=","),e+=`"${s}":${_t(t[s])}`;return`{${e}}`}(t):t??null}`}const $t=4;function Yt(t,e){return!!(t[e>>3]&1<<e%8)}function Pt(t,e){const n=e+Xt(t,e),s=n-Xt(t,n),r=Jt(t,s);return(e,i,a=null)=>{if(e<r){const r=Jt(t,s+e);if(r)return i(t,n+r)}return a}}function Ht(t,e){return e}function Wt(t,e){return!!function(t,e){return Gt(t,e)<<24>>24}(t,e)}function Gt(t,e){return t[e]}function Jt(t,e){return function(t,e){return t[e]|t[e+1]<<8}(t,e)<<16>>16}function Xt(t,e){return t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24}function qt(t,e){return Xt(t,e)>>>0}function Kt(t,e){return Mt(BigInt.asIntN(64,BigInt(qt(t,e))+(BigInt(qt(t,e+$t))<<32n)))}function Qt(t,e){let n=e+Xt(t,e);const s=Xt(t,n);return n+=$t,zt(t.subarray(n,n+s))}function Zt(t,e,n,s){if(!e)return[];const r=e+Xt(t,e);return Array.from({length:Xt(t,r)},((e,i)=>s(t,r+$t+i*n)))}const te=Symbol("rowIndex");function ee(t,e){class n{constructor(t){this[te]=t}toJSON(){return se(t,e,this[te])}}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[te])},enumerable:!0})}return t=>new n(t)}function ne(t,e){return n=>se(t,e,n)}function se(t,e,n){const s={};for(let r=0;r<t.length;++r)s[t[r]]=e[r].at(n);return s}class re{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 Yt(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 ie extends re{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 ae extends re{static ArrayType=m}class ce extends re{static ArrayType=Array}class ue extends ce{value(t){return null}}class oe extends ae{value(t){return Mt(this.values[t])}}class de extends ae{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 le extends ce{value(t){return Yt(this.values,t)}}class he extends re{constructor(t){super(t);const{bitWidth:e,scale:n}=this.type;this.decimal=128===e?Vt:Tt,this.scale=10n**BigInt(n)}}class fe extends he{static ArrayType=m;value(t){return Ct(this.decimal(this.values,t),this.scale)}}class ye extends he{static ArrayType=Array;value(t){return this.decimal(this.values,t)}}class pe extends ce{constructor(t){super(t),this.source=t}value(t){return new Date(this.source.value(t))}}class be extends ae{value(t){return 864e5*this.values[t]}}const Ie=oe;class ge extends oe{value(t){return 1e3*super.value(t)}}const ve=oe;class we extends oe{value(t){return Ct(this.values[t],1000n)}}class me extends oe{value(t){return Ct(this.values[t],1000000n)}}class xe extends ce{value(t){return this.values.subarray(t<<1,t+1<<1)}}class Oe extends ce{value(t){const e=this.values,n=t<<4;return Float64Array.of(Xt(e,n),Xt(e,n+4),Kt(e,n+8))}}const Le=({values:t,offsets:e},n)=>t.subarray(e[n],e[n+1]),Ee=({values:t,offsets:e},n)=>t.subarray(Mt(e[n]),Mt(e[n+1]));class De extends ce{value(t){return Le(this,t)}}class Ae extends ce{value(t){return Ee(this,t)}}class Se extends ce{value(t){return zt(Le(this,t))}}class Ne extends ce{value(t){return zt(Ee(this,t))}}class Be extends ce{value(t){const e=this.offsets;return this.children[0].slice(e[t],e[t+1])}}class Me extends ce{value(t){const e=this.offsets;return this.children[0].slice(Mt(e[t]),Mt(e[t+1]))}}class Ce extends ce{value(t){const e=this.offsets[t],n=e+this.sizes[t];return this.children[0].slice(e,n)}}class Ue extends ce{value(t){const e=this.offsets[t],n=e+this.sizes[t];return this.children[0].slice(Mt(e),Mt(n))}}class Ve extends ce{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 Fe extends Ve{value(t){const{children:e,stride:n}=this;return e[0].slice(t*n,(t+1)*n)}}function je({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 ke extends ce{value(t){return je(this,t)}}class ze extends ce{value(t){return new Map(je(this,t))}}class Re extends ce{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 _e extends Re{value(t){return super.value(t,this.offsets[t])}}class $e extends ce{constructor(t,e=ne){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 Ye extends $e{constructor(t){super(t,ee)}}class Pe extends ce{value(t){const[{values:e},n]=this.children;return n.at(A(e,t))}}class He extends ce{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 We extends ce{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=Xt(i,s);return a>12&&(r=Xt(i,s+12),i=n[Xt(i,s+8)]),i.subarray(r,r+a)}}class Ge extends We{value(t){return this.view(t)}}class Je extends We{value(t){return zt(this.view(t))}}function Xe(t){let e=[];return{add(t){return e.push(t),this},clear:()=>e=[],done:()=>new qe(e,t)}}class qe{constructor(t,e=t[0]?.type){this.type=e,this.length=t.reduce(((t,e)=>t+e.length),0),this.nullCount=t.reduce(((t,e)=>t+e.nullCount),0),this.data=t;const n=t.length,s=new Int32Array(n+1);if(1===n){const[e]=t;s[1]=e.length,this.at=t=>e.at(t)}else for(let e=0,r=0;e<n;++e)s[e+1]=r+=t[e].length;this.offsets=s}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=A(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 ie;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 Ke{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?ee:ne;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 Ke({...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===ee)}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=A(r,t)-1;return n(i)(t-r[i])}get(t){return this.at(t)}}function Qe(t,e={}){const{typeId:n,bitWidth:s,precision:r,unit:i}=t,{useBigInt:c,useDate:l,useDecimalBigInt:h,useMap:f,useProxy:y}=e;switch(n){case a.Null:return ue;case a.Bool:return le;case a.Int:case a.Time:case a.Duration:return c||s<64?ie:oe;case a.Float:return r?ie:de;case a.Date:return Ze(i===u.DAY?be:Ie,l&&pe);case a.Timestamp:return Ze(i===o.SECOND?ge:i===o.MILLISECOND?ve:i===o.MICROSECOND?we:me,l&&pe);case a.Decimal:return h?ye:fe;case a.Interval:return i===d.DAY_TIME?xe:i===d.YEAR_MONTH?ie:Oe;case a.FixedSizeBinary:return Te;case a.Utf8:return Se;case a.LargeUtf8:return Ne;case a.Binary:return De;case a.LargeBinary:return Ae;case a.BinaryView:return Ge;case a.Utf8View:return Je;case a.List:return Be;case a.LargeList:return Me;case a.Map:return f?ze:ke;case a.ListView:return Ce;case a.LargeListView:return Ue;case a.FixedSizeList:return Fe;case a.Struct:return y?Ye:$e;case a.RunEndEncoded:return Pe;case a.Dictionary:return He;case a.Union:return t.mode?_e:Re}throw new Error(U(n))}function Ze(t,e){return e?class extends e{constructor(e){super(new t(e))}}:t}function tn(t,e){return{offset:Kt(t,e),metadataLength:Xt(t,e+8),bodyLength:Kt(t,e+16)}}function en(t,e){return Zt(t,e,24,tn)}function nn(t,e,n){const r=Pt(t,e);if(r(10,Ht,0))throw new Error("Record batch compression not implemented");const i=n<s.V4?8:0;return{length:r(4,Kt,0),nodes:Zt(t,r(6,Ht),16,((t,e)=>({length:Kt(t,e),nullCount:Kt(t,e+8)}))),regions:Zt(t,r(8,Ht),16+i,((t,e)=>({offset:Kt(t,e+i),length:Kt(t,e+i+8)}))),variadic:Zt(t,r(12,Ht),8,Kt)}}function sn(t,e,n){const s=Pt(t,e);return{id:s(4,Kt,0),data:s(6,((t,e)=>nn(t,e,n))),isDelta:s(8,Wt,!1)}}function rn(t,e,n,s){M(n,a,U);const r=Pt(t,e);switch(n){case a.Binary:return Z();case a.Utf8:return tt();case a.LargeBinary:return pt();case a.LargeUtf8:return bt();case a.List:return ut(s[0]);case a.ListView:return vt(s[0]);case a.LargeList:return It(s[0]);case a.LargeListView:return wt(s[0]);case a.Struct:return ot(s);case a.RunEndEncoded:return gt(s[0],s[1]);case a.Int:return _(r(4,Xt,0),r(6,Wt,!1));case a.Float:return q(r(4,Jt,c.HALF));case a.Decimal:return nt(r(4,Xt,0),r(6,Xt,0),r(8,Xt,128));case a.Date:return st(r(4,Jt,u.MILLISECOND));case a.Time:return it(r(4,Jt,o.MILLISECOND),r(6,Xt,32));case a.Timestamp:return at(r(4,Jt,o.SECOND),r(6,Qt));case a.Interval:return ct(r(4,Jt,d.YEAR_MONTH));case a.Duration:return yt(r(4,Jt,o.MILLISECOND));case a.FixedSizeBinary:return lt(r(4,Xt,0));case a.FixedSizeList:return ht(s[0],r(4,Xt,0));case a.Map:return ft(r(4,Wt,!1),s[0]);case a.Union:return dt(r(4,Jt,l.Sparse),s,Zt(t,r(6,Ht),4,Xt))}return{typeId:n}}function an(t,e){const n=Zt(t,e,4,((t,e)=>{const n=Pt(t,e);return[n(4,Qt),n(6,Qt)]}));return n.length?new Map(n):null}function cn(t,e,n){const s=Pt(t,e);return{version:n,endianness:s(4,Jt,0),fields:s(6,un,[]),metadata:s(8,an)}}function un(t,e){return Zt(t,e,4,on)}function on(t,e){const n=Pt(t,e),s=n(8,Gt,a.NONE),r=n(10,Ht,0),i=n(12,dn),c=n(14,((t,e)=>function(t,e){const n=Zt(t,e,4,on);return n.length?n:null}(t,e)));let u=rn(t,r,s,c);return i&&(i.dictionary=u,u=i),{name:n(4,Qt),type:u,nullable:n(6,Wt,!1),metadata:n(16,an)}}function dn(t,e){if(!e)return null;const n=Pt(t,e);return z(null,n(6,ln,P()),n(8,Wt,!1),n(4,Kt,0))}function ln(t,e){return rn(t,e,a.Int)}const hn=(t,e)=>`Expected to read ${t} metadata bytes, but only read ${e}.`,fn=(t,e)=>`Expected to read ${t} bytes for message body, but only read ${e}.`,yn=t=>`Unsupported message type: ${t} (${C(i,t)})`;function pn(t,e){let n=Xt(t,e)||0;if(e+=$t,-1===n&&(n=Xt(t,e)||0,e+=$t),0===n)return null;const r=t.subarray(e,e+=n);if(r.byteLength<n)throw new Error(hn(n,r.byteLength));const a=Pt(r,0),c=a(4,Jt,s.V1),u=a(6,Gt,i.NONE),o=a(8,Ht,0),d=a(10,Kt,0);let l;if(o){const n=u===i.Schema?cn:u===i.DictionaryBatch?sn:u===i.RecordBatch?nn:null;if(!n)throw new Error(yn(u));if(l=n(r,o,c),d>0){const n=t.subarray(e,e+=d);if(n.byteLength<d)throw new Error(fn(d,n.byteLength));l.body=n}}return{version:c,type:u,index:e,content:l}}function bn(t){const n=t instanceof ArrayBuffer?new Uint8Array(t):t;return n instanceof Uint8Array&&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}(n)?function(t){const n=t.byteLength-(e.length+4),r=Xt(t,n),i=Pt(t,n-r),a=i(4,Jt,s.V1),c=i(8,en,[]),u=i(10,en,[]);return{schema:i(6,((t,e)=>cn(t,e,a))),dictionaries:c.map((({offset:e})=>pn(t,e).content)),records:u.map((({offset:e})=>pn(t,e).content)),metadata:i(12,an)}}(n):function(t){const e=[t].flat();let n;const s=[],r=[];for(const t of e){if(!(t instanceof Uint8Array))throw new Error("IPC data batch was not a Uint8Array.");let e=0;for(;;){const a=pn(t,e);if(null===a)break;if(e=a.index,a.content)switch(a.type){case i.Schema:n||(n=a.content);break;case i.RecordBatch:s.push(a.content);break;case i.DictionaryBatch:r.push(a.content)}}}return{schema:n,dictionaries:r,records:s,metadata:null}}(n)}function In(t,e){const{typeId:n}=t,{length:r,options:i,node:c,buffer:u,variadic:o,version:d}=e,h=Qe(t,i);if(n===a.Null)return new h({length:r,nullCount:r,type:t});const f={...c(),type:t};switch(n){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 h({...f,validity:u(),values:u(t.values)});case a.Utf8:case a.LargeUtf8:case a.Binary:case a.LargeBinary:return new h({...f,validity:u(),offsets:u(t.offsets),values:u()});case a.BinaryView:case a.Utf8View:return new h({...f,validity:u(),values:u(),data:Array.from({length:o()},(()=>u()))});case a.List:case a.LargeList:case a.Map:return new h({...f,validity:u(),offsets:u(t.offsets),children:e.visit(t.children)});case a.ListView:case a.LargeListView:return new h({...f,validity:u(),offsets:u(t.offsets),sizes:u(t.offsets),children:e.visit(t.children)});case a.FixedSizeList:case a.Struct:return new h({...f,validity:u(),children:e.visit(t.children)});case a.RunEndEncoded:return new h({...f,children:e.visit(t.children)});case a.Dictionary:{const{id:n,indices:s}=t;return new h({...f,validity:u(),values:u(s.values)}).setDictionary(e.dictionary(n))}case a.Union:return d<s.V5&&u(),new h({...f,typeIds:u(b),offsets:t.mode===l.Sparse?null:u(t.offsets),children:e.visit(t.children)});default:throw new Error(U(n))}}function gn(t,e,n){t[e]=n,t[e+1]=n>>8,t[e+2]=n>>16,t[e+3]=n>>24}const vn=1024;class wn{constructor(t){this.sink=t,this.minalign=1,this.buf=new Uint8Array(vn),this.space=vn,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){gn(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){mn(this,1,0),this.writeInt8(t)}addInt16(t){mn(this,2,0),this.writeInt16(t)}addInt32(t){mn(this,4,0),this.writeInt32(t)}addInt64(t){mn(this,8,0),this.writeInt64(t)}addOffset(t){mn(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==Jt(d,t)){for(let e=2;e<u;e+=2)if(Jt(d,h+e)!=Jt(d,t+e))continue t;o=l[i];break}}if(o)t.space=d.length-r,gn(d,t.space,o-r);else{const e=t.offset();l.push(e),gn(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;mn(this,$t,e*r),mn(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),mn(this,$t,n),this.buf.set(e,this.space-=n),this.writeInt32(n),this.offset()}finish(t){mn(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(vn),this.space=vn}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 mn(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 xn(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 On(t,e){const n=xn(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 Ln(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 En(t,e){switch(M(e.typeId,a,U)){case a.Dictionary:return function(t,e){return t.addObject(4,(n=>{n.addInt64(0,e.id,0),n.addOffset(1,En(t,e.indices),0),n.addInt8(2,+e.ordered,0)}))}(t,e);case a.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 a.Float:return function(t,e){return t.addObject(1,(t=>{t.addInt16(0,e.precision,c.HALF)}))}(t,e);case a.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 a.Date:return function(t,e){return t.addObject(1,(t=>{t.addInt16(0,e.unit,u.MILLISECOND)}))}(t,e);case a.Time:return function(t,e){return t.addObject(2,(t=>{t.addInt16(0,e.unit,o.MILLISECOND),t.addInt32(1,e.bitWidth,32)}))}(t,e);case a.Timestamp:return function(t,e){const n=t.addString(e.timezone);return t.addObject(2,(t=>{t.addInt16(0,e.unit,o.SECOND),t.addOffset(1,n,0)}))}(t,e);case a.Interval:return function(t,e){return t.addObject(1,(t=>{t.addInt16(0,e.unit,d.YEAR_MONTH)}))}(t,e);case a.Duration:return function(t,e){return t.addObject(1,(t=>{t.addInt16(0,e.unit,o.MILLISECOND)}))}(t,e);case a.FixedSizeBinary:case a.FixedSizeList:return function(t,e){return t.addObject(1,(t=>{t.addInt32(0,e.stride,0)}))}(t,e);case a.Map:return function(t,e){return t.addObject(1,(t=>{t.addInt8(0,+e.keysSorted,0)}))}(t,e);case a.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,l.Sparse),t.addOffset(1,n,0)}))}(t,e)}return t.addObject(0)}const Dn=1===new Uint16Array(new Uint8Array([1,0]).buffer)[0];function An(t,e){const{fields:n,metadata:s}=e,r=n.map((e=>Sn(t,e))),i=t.addOffsetVector(r),a=Ln(t,s);return t.addObject(4,(t=>{t.addInt16(0,+!Dn,0),t.addOffset(1,i,0),t.addOffset(2,a,0)}))}function Sn(t,e){const{name:n,nullable:s,type:r,metadata:i}=e;let{typeId:c}=r,u=0,o=0;if(c!==a.Dictionary)u=En(t,r);else{const e=r.dictionary;c=e.typeId,o=En(t,r),u=En(t,e)}const d=(r.children||[]).map((e=>Sn(t,e))),l=t.addOffsetVector(d),h=Ln(t,i),f=t.addString(n);return t.addObject(7,(t=>{t.addOffset(0,f,0),t.addInt8(1,+s,0),t.addInt8(2,c,a.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 Bn(t,e,n,r,a){t.finish(t.addObject(5,(t=>{t.addInt16(0,s.V5,s.V1),t.addInt8(1,e,i.NONE),t.addOffset(2,n,0),t.addInt64(3,r,0)})));const c=t.offset(),u=c+8+7&-8;a?.push({offset:t.outputBytes,metadataLength:u,bodyLength:r}),t.addInt32(u-8),t.addInt32(-1),t.flush(),t.addPadding(u-c-8)}class Mn{write(t){}pad(t){this.write(new Uint8Array(t))}finish(){return null}}class Cn extends Mn{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 Un="stream",Vn="file";function Tn(t,{sink:r,format:a=Un}={}){if(a!==Un&&a!==Vn)throw new Error(`Unrecognized Arrow IPC format: ${a}`);const{schema:c,dictionaries:u=[],records:o=[],metadata:d}=t,l=new wn(r||new Cn),h=a===Vn,f=[],y=[];h&&l.addBuffer(e),c&&Bn(l,i.Schema,An(l,c),0);for(const t of u){const{data:e}=t;Bn(l,i.DictionaryBatch,On(l,t),e.byteLength,f),Fn(l,e.buffers)}for(const t of o)Bn(l,i.RecordBatch,xn(l,t),t.byteLength,y),Fn(l,t.buffers);return l.addBuffer(n),h&&function(t,n,r,i,a){const c=Ln(t,a),u=t.addVector(i,24,8,Nn),o=t.addVector(r,24,8,Nn),d=An(t,n);t.finish(t.addObject(5,(t=>{t.addInt16(0,s.V5,s.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)}(l,c,f,y,d),l.sink}function Fn(t,e){for(let n=0;n<e.length;++n)t.addBuffer(e[n])}function jn(t,e){if(t?.type.typeId===a.Dictionary){const n=t.dictionary;e(n),jn(n.data[0],e)}t?.children?.forEach((t=>jn(t,e)))}function kn(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)=>{zn(t.type,e.children[n],this)}))},done:()=>({byteLength:t,nodes:e,regions:n,variadic:r,buffers:s})}}();return t.forEach((t=>{zn(t.type,t.data[e],n)})),n.done()}function zn(t,e,n){const{typeId:s}=t;if(s!==a.Null)switch(n.node(e.length,e.nullCount),s){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:return n.buffer(e.validity),void n.buffer(e.values);case a.Utf8:case a.LargeUtf8:case a.Binary:case a.LargeBinary:return n.buffer(e.validity),n.buffer(e.offsets),void n.buffer(e.values);case a.BinaryView:case a.Utf8View:return n.buffer(e.validity),n.buffer(e.values),n.variadic(e.data.length),void e.data.forEach((t=>n.buffer(t)));case a.List:case a.LargeList:case a.Map:return n.buffer(e.validity),n.buffer(e.offsets),void n.children(t,e);case a.ListView:case a.LargeListView:return n.buffer(e.validity),n.buffer(e.offsets),n.buffer(e.sizes),void n.children(t,e);case a.FixedSizeList:case a.Struct:return n.buffer(e.validity),void n.children(t,e);case a.RunEndEncoded:return void n.children(t,e);case a.Union:return n.buffer(e.typeIds),t.mode===l.Dense&&n.buffer(e.offsets),void n.children(t,e);default:throw new Error(U(s))}}function Rn(t){return new _n(t)}class _n{constructor(t=h){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?S(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 Yn}class Yn extends _n{set(t){const e=t>>3;this.prep(e),this.buf[e]|=1<<t%8}}class Pn{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 Hn extends Pn{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 h(0)}}}function Wn(){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=_t(t);let r=n[e];return void 0===r&&(n[e]=r=++i,s.set(t,r)),r},finish(e){const n=new(Qe(t.dictionary,e))(s.done()),i=new qe([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 Gn extends Hn{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 Jn(t){const e=Xn();return t((t=>e.add(t))),e.type()}function Xn(){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,b=1/0,I=-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(E(v)){h++;const t=v.length;t<b&&(b=t),t>I&&(I=t),n??=Xn(),v.forEach(n.add)}else{f++;for(const t in v){(g[t]??(g[t]=Xn())).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?Y():n<2**31?P():Q()}(y,p):a===v?Q():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 H()}(t,e):i===v?et():d===v?rt():o===v?at():l===v?z(tt()):h===v?function(t,e,n){return n===e?ht(t,e):ut(t)}(n.type(),b,I):f===v?ot(Object.entries(g).map((t=>V(t[0],t[1].type())))):function(){throw new Error("Mixed types detected, please define a union type.")}()}}}class qn extends Hn{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 Kn extends Hn{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 Qn extends Hn{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:St(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 Zn extends Hn{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 ts extends Hn{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 es extends Hn{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 ns extends Hn{init(){return this.values=Rn(),super.init()}set(t,e){super.set(t,e)&&this.values.write(function([t,e,n]){return Et[0]=t,Et[1]=e,Ot[1]=St(n),Dt}(t),e<<4)}done(){return{...super.done(),values:this.values.array(this.index+1<<4)}}}class ss extends Hn{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 rs extends ss{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 is extends Hn{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 as extends is{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 cs extends ss{constructor(t,e){super(t,e,new us(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 us extends is{set(t,e){super.set(t,e);const[n,s]=this.children;n.set(t[0],e),s.set(t[1],e)}}const os={};class ds extends Pn{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=os,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=_t(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 ls extends Pn{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(b),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 hs extends ls{update(t,e,n){n.set(t,e),this.children.forEach((t=>{t!==n&&t.set(null,e)}))}}class fs extends ls{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 ys extends qn{set(t,e){super.set(t&&Rt(t),e)}}class ps extends Hn{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 bs extends ps{set(t,e){super.set(null==t?t:St(t),e)}}class Is extends ps{constructor(t,e,n){super(t,e),this.transform=n}set(t,e){super.set(null==t?t:this.transform(t),e)}}function gs(t={},e=Wn()){return{batchType:e=>Qe(e,t),builder(t){return vs(t,this)},dictionary(t){return e.get(t,this)},finish:()=>e.finish(t)}}function vs(t,e=gs()){const{typeId:n}=t;switch(n){case a.Int:case a.Time:case a.Duration:return D(t.values)?new bs(t,e):new ps(t,e);case a.Float:return t.precision?new ps(t,e):new Is(t,e,Ft);case a.Binary:case a.LargeBinary:return new qn(t,e);case a.Utf8:case a.LargeUtf8:return new ys(t,e);case a.Bool:return new Kn(t,e);case a.Decimal:return new Qn(t,e);case a.Date:return new Is(t,e,t.unit?St:Bt);case a.Timestamp:return new Is(t,e,(s=t.unit)===o.SECOND?t=>St(t/1e3):s===o.MILLISECOND?St:s===o.MICROSECOND?t=>St(1e3*t):t=>St(1e6*t));case a.Interval:switch(t.unit){case d.DAY_TIME:return new es(t,e);case d.MONTH_DAY_NANO:return new ns(t,e)}return new ps(t,e);case a.List:case a.LargeList:return new rs(t,e);case a.Struct:return new as(t,e);case a.Union:return t.mode?new fs(t,e):new hs(t,e);case a.FixedSizeBinary:return new Zn(t,e);case a.FixedSizeList:return new ts(t,e);case a.Map:return new cs(t,e);case a.RunEndEncoded:return new ds(t,e);case a.Dictionary:return new Gn(t,e)}var s;throw new Error(U(n))}function ws(t,e,n={},s){const r="function"==typeof t[Symbol.iterator]?e=>{for(const n of t)e(n)}:t;e??=Jn(r);const{maxBatchRows:i=1/0,...c}=n;let u;if(e.typeId===a.Null){let t=0;r((()=>++t)),u=function(t,e,n){const s=[],r=e=>new ue({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}(e,t,i)}else{const t=gs(c,s),n=vs(e,t).init(),a=t=>u.push(t.batch());u=[];let o=0;r((t=>{n.set(t,o++),o>=i&&(a(n),o=0)})),o&&a(n),t.finish()}return new qe(u,e)}function ms(t,e,n={},s){return!e&&L(t)?function(t,{maxBatchRows:e,useBigInt:n}){const s=t.constructor,r=function(t){switch(t){case w:return K();case m:return Q();case b:return $();case I:return Y();case g:return P();case v:return H();case h:return W();case f:return G();case y:return J();case p:return X()}}(s),i=t.length,a=Math.min(e||1/0,i),c=Math.floor(i/a),u=[],o=D(s)&&!n?oe:ie,d=(e,n)=>u.push(new o({length:n-e,nullCount:0,type:r,validity:new h(0),values:t.subarray(e,n)}));let l=0;for(let t=0;t<c;++t)d(l,l+=a);l<i&&d(l,i);return new qe(u)}(t,n):ws((e=>t.forEach(e)),e,n,s)}function xs(t,e){const n=[],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 n.push(V(t,e.type)),e})),u={version:s.V5,endianness:r.Little,fields:n,metadata:null};return new Ke(u,c,e)}t.Batch=re,t.Column=qe,t.DateUnit=u,t.Endianness=r,t.IntervalUnit=d,t.Precision=c,t.Table=Ke,t.TimeUnit=o,t.Type=a,t.UnionMode=l,t.Version=s,t.batchType=Qe,t.binary=Z,t.binaryView=()=>k(a.BinaryView),t.bool=et,t.columnFromArray=ms,t.columnFromValues=ws,t.date=st,t.dateDay=rt,t.dateMillisecond=()=>st(u.MILLISECOND),t.decimal=nt,t.dictionary=z,t.dictionaryContext=Wn,t.duration=yt,t.field=V,t.fixedSizeBinary=lt,t.fixedSizeList=ht,t.float=q,t.float16=()=>q(c.HALF),t.float32=K,t.float64=Q,t.int=_,t.int16=Y,t.int32=P,t.int64=H,t.int8=$,t.interval=ct,t.largeBinary=pt,t.largeList=It,t.largeListView=wt,t.largeUtf8=bt,t.list=ut,t.listView=vt,t.map=(t,e,n=!1)=>ft(n,V("entries",ot([j(t,"key",!1),j(e,"value")]),!1)),t.nullType=R,t.runEndEncoded=gt,t.struct=ot,t.tableFromArrays=function(t,e={}){const{types:n={},...s}=e,r=Wn();return xs((Array.isArray(t)?t:Object.entries(t)).map((([t,e])=>[t,ms(e,n[t],s,r)])),e.useProxy)},t.tableFromColumns=xs,t.tableFromIPC=function(t,e){return function(t,e={}){const{schema:n={fields:[]},dictionaries:s,records:r}=t,{version:i,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,i,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===a.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=d.get(e),a=In(i,o({...n,body:r}));if(l.has(e)){const t=l.get(e);s||t.clear(),t.add(a)}else{if(s)throw new Error("Delta update can not be first dictionary batch.");l.set(e,Xe(i).add(a))}}l.forEach(((t,e)=>u.set(e,t.done())));const h=c.map((t=>Xe(t.type)));for(const t of r){const e=o(t);c.forEach(((t,n)=>h[n].add(In(t.type,e))))}return new Ke(n,h.map((t=>t.done())),e.useProxy)}(bn(t),e)},t.tableToIPC=function(t,e){"string"==typeof e&&(e={format:e});const n=t.children;!function(t){const e=t[0]?.data.map((t=>t.length));t.forEach((({data:t})=>{if(t.length!==e.length||t.some(((t,n)=>t.length!==e[n])))throw new Error("Columns have inconsistent batch sizes.")}))}(n);const{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:kn([t],n)});s.set(t.type,r)}};return t.forEach((t=>jn(t.data[0],i))),{dictionaries:e,idMap:s}}(n),i=function(t){return(t[0]?.data||[]).map(((e,n)=>kn(t,n)))}(n),c=function(t,e){if(!e.size)return t;const n=t=>{t.typeId===a.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:i},e).finish()},t.time=it,t.timeMicrosecond=()=>it(o.MICROSECOND,64),t.timeMillisecond=()=>it(o.MILLISECOND,32),t.timeNanosecond=()=>it(o.NANOSECOND,64),t.timeSecond=()=>it(o.SECOND,32),t.timestamp=at,t.uint16=G,t.uint32=J,t.uint64=X,t.uint8=W,t.union=dt,t.utf8=tt,t.utf8View=()=>k(a.Utf8View)})); | ||
//# sourceMappingURL=flechette.min.js.map |
@@ -46,3 +46,3 @@ /** | ||
type: import("./types.js").DataType; | ||
validity: Uint8Array; | ||
validity: Uint8Array<ArrayBufferLike>; | ||
values: import("./types.js").TypedArray; | ||
@@ -296,3 +296,3 @@ offsets: import("./types.js").OffsetArray; | ||
*/ | ||
export class IntervalDayTimeBatch extends ArrayBatch<Int32Array> { | ||
export class IntervalDayTimeBatch extends ArrayBatch<Int32Array<ArrayBufferLike>> { | ||
/** | ||
@@ -325,3 +325,3 @@ * Create a new column batch. | ||
*/ | ||
export class IntervalMonthDayNanoBatch extends ArrayBatch<Float64Array> { | ||
export class IntervalMonthDayNanoBatch extends ArrayBatch<Float64Array<ArrayBufferLike>> { | ||
/** | ||
@@ -349,2 +349,6 @@ * Create a new column batch. | ||
}); | ||
/** | ||
* @param {number} index The value index | ||
*/ | ||
value(index: number): Float64Array<ArrayBuffer>; | ||
} | ||
@@ -356,3 +360,3 @@ /** | ||
*/ | ||
export class BinaryBatch extends ArrayBatch<Uint8Array> { | ||
export class BinaryBatch extends ArrayBatch<Uint8Array<ArrayBufferLike>> { | ||
/** | ||
@@ -387,3 +391,3 @@ * Create a new column batch. | ||
*/ | ||
export class LargeBinaryBatch extends ArrayBatch<Uint8Array> { | ||
export class LargeBinaryBatch extends ArrayBatch<Uint8Array<ArrayBufferLike>> { | ||
/** | ||
@@ -508,3 +512,3 @@ * Create a new column batch. | ||
*/ | ||
export class FixedBinaryBatch extends FixedBatch<Uint8Array> { | ||
export class FixedBinaryBatch extends FixedBatch<Uint8Array<ArrayBufferLike>> { | ||
constructor(options: any); | ||
@@ -687,3 +691,3 @@ } | ||
*/ | ||
export class BinaryViewBatch extends ViewBatch<Uint8Array> { | ||
export class BinaryViewBatch extends ViewBatch<Uint8Array<ArrayBufferLike>> { | ||
/** | ||
@@ -767,3 +771,3 @@ * Create a new view batch. | ||
}); | ||
data: Uint8Array[]; | ||
data: Uint8Array<ArrayBufferLike>[]; | ||
/** | ||
@@ -770,0 +774,0 @@ * Get the binary data at the provided index. |
@@ -22,3 +22,3 @@ /** | ||
constructor(arrayType?: import("../types.js").TypedArrayConstructor); | ||
buf: Uint8Array | Float64Array | BigInt64Array | Uint32Array | Int32Array | Uint16Array | Int8Array | Int16Array | BigUint64Array | Float32Array; | ||
buf: Uint8Array<ArrayBuffer> | Float64Array<ArrayBuffer> | BigInt64Array<ArrayBuffer> | Uint32Array<ArrayBuffer> | Int32Array<ArrayBuffer> | Uint16Array<ArrayBuffer> | Int8Array<ArrayBuffer> | Int16Array<ArrayBuffer> | BigUint64Array<ArrayBuffer> | Float32Array<ArrayBuffer>; | ||
/** | ||
@@ -25,0 +25,0 @@ * Return the underlying data as a 64-bit aligned array of minimum size. |
@@ -17,5 +17,5 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
} | ||
import { ValidityBuilder } from './validity.js'; |
@@ -13,5 +13,5 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
} | ||
import { ValidityBuilder } from './validity.js'; |
@@ -15,5 +15,5 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
} | ||
import { ValidityBuilder } from './validity.js'; |
@@ -47,3 +47,3 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
@@ -50,0 +50,0 @@ batch(): any; |
@@ -14,5 +14,5 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
} | ||
import { ValidityBuilder } from './validity.js'; |
@@ -14,5 +14,5 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
} | ||
import { ValidityBuilder } from './validity.js'; |
@@ -13,3 +13,3 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
@@ -29,5 +29,5 @@ } | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
} | ||
import { ValidityBuilder } from './validity.js'; |
@@ -17,3 +17,3 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
@@ -20,0 +20,0 @@ } |
@@ -12,3 +12,3 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
@@ -15,0 +15,0 @@ } |
@@ -12,5 +12,5 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
} | ||
import { BatchBuilder } from './batch.js'; |
@@ -12,3 +12,3 @@ /** | ||
type: any; | ||
validity: import("../../types.js").TypedArray; | ||
validity: Uint8Array<ArrayBuffer> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | BigUint64Array<ArrayBufferLike> | BigInt64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>; | ||
}; | ||
@@ -15,0 +15,0 @@ } |
@@ -5,3 +5,3 @@ /** | ||
export function columnBuilder(type: any): { | ||
add(batch: any): any; | ||
add(batch: any): /*elided*/ any; | ||
clear: () => any[]; | ||
@@ -8,0 +8,0 @@ done: () => Column<any>; |
/** Magic bytes 'ARROW1' indicating the Arrow 'file' format. */ | ||
export const MAGIC: Uint8Array; | ||
export const MAGIC: Uint8Array<ArrayBuffer>; | ||
/** Bytes for an 'end of stream' message. */ | ||
export const EOS: Uint8Array<ArrayBuffer>; | ||
export namespace Version { | ||
@@ -4,0 +6,0 @@ let V1: 0; |
@@ -70,4 +70,4 @@ --- | ||
<hr/><a id="iterator" href="#iterator">#</a> | ||
Column[<b>Symbol.iterator</b>]() | ||
Column\[<b>Symbol.iterator</b>\]() | ||
Return an iterator over the values in this column. The value type is determined by the column data type and extraction options; see the [data types](data-types#data-type-overview) documentation for more. |
@@ -97,4 +97,4 @@ --- | ||
<hr/><a id="iterator" href="#iterator">#</a> | ||
Table[<b>Symbol.iterator</b>]() | ||
Table\[<b>Symbol.iterator</b>\]() | ||
Return an iterator over row objects representing the rows of this table. The type of object (standard object or row proxy object) is determined by the table `useProxy` constructor argument. The property values of the object are determined by the column data types and extraction options; see the [data types](data-types#data-type-overview) documentation for more. |
@@ -36,3 +36,3 @@ # Flechette <a href="https://idl.uw.edu/flechette"><img align="right" src="assets/logo.svg" height="38"/></a> | ||
const url = 'https://vega.github.io/vega-datasets/data/flights-200k.arrow'; | ||
const url = 'https://cdn.jsdelivr.net/npm/vega-datasets@2/data/flights-200k.arrow'; | ||
const ipc = await fetch(url).then(r => r.arrayBuffer()); | ||
@@ -39,0 +39,0 @@ const table = tableFromIPC(ipc); |
{ | ||
"name": "@uwdata/flechette", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Fast, lightweight access to Apache Arrow data.", | ||
@@ -37,11 +37,11 @@ "keywords": [ | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@uwdata/mosaic-duckdb": "^0.11.0", | ||
"apache-arrow": "^18.0.0", | ||
"eslint": "^9.14.0", | ||
"mocha": "^10.8.2", | ||
"@uwdata/mosaic-duckdb": "^0.12.2", | ||
"apache-arrow": "^18.1.0", | ||
"eslint": "^9.18.0", | ||
"mocha": "^11.0.1", | ||
"rimraf": "^6.0.1", | ||
"rollup": "^4.24.4", | ||
"rollup": "^4.30.1", | ||
"rollup-plugin-bundle-size": "^1.0.3", | ||
"typescript": "^5.6.3" | ||
"typescript": "^5.7.3" | ||
} | ||
} |
@@ -36,3 +36,3 @@ # 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> | ||
const url = 'https://vega.github.io/vega-datasets/data/flights-200k.arrow'; | ||
const url = 'https://cdn.jsdelivr.net/npm/vega-datasets@2/data/flights-200k.arrow'; | ||
const ipc = await fetch(url).then(r => r.arrayBuffer()); | ||
@@ -39,0 +39,0 @@ const table = tableFromIPC(ipc); |
/** Magic bytes 'ARROW1' indicating the Arrow 'file' format. */ | ||
export const MAGIC = Uint8Array.of(65, 82, 82, 79, 87, 49); | ||
/** Bytes for an 'end of stream' message. */ | ||
export const EOS = Uint8Array.of(255, 255, 255, 255, 0, 0, 0, 0); | ||
/** | ||
@@ -5,0 +8,0 @@ * Apache Arrow version. |
@@ -136,8 +136,8 @@ import { DateUnit, IntervalUnit, Precision, TimeUnit, Type, UnionMode } from '../constants.js'; | ||
function encodeDictionary(builder, type) { | ||
const keyTypeOffset = isInt32(type.indices) | ||
? 0 | ||
: encodeDataType(builder, type.indices); | ||
// The Arrow spec uses signed 32-bit integers as the default index type. | ||
// However, multiple 3rd party tools fail on a null (default) index type, | ||
// so we always encode the index data type explicitly here. | ||
return builder.addObject(4, b => { | ||
b.addInt64(0, type.id, 0); | ||
b.addOffset(1, keyTypeOffset, 0); | ||
b.addOffset(1, encodeDataType(builder, type.indices), 0); | ||
b.addInt8(2, +type.ordered, 0); | ||
@@ -147,5 +147,1 @@ // NOT SUPPORTED: 3, dictionaryKind (defaults to dense array) | ||
} | ||
function isInt32(type) { | ||
return type.typeId === Type.Int && type.bitWidth === 32 && type.signed; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { MAGIC, MessageHeader } from '../constants.js'; | ||
import { EOS, MAGIC, MessageHeader } from '../constants.js'; | ||
import { Builder } from './builder.js'; | ||
@@ -33,3 +33,6 @@ import { encodeDictionaryBatch } from './dictionary-batch.js'; | ||
builder.addBuffer(MAGIC); | ||
} else if (schema) { | ||
} | ||
// both stream and file start with the schema | ||
if (schema) { | ||
writeMessage( | ||
@@ -43,2 +46,3 @@ builder, | ||
// write dictionary messages | ||
for (const dict of dictionaries) { | ||
@@ -56,2 +60,3 @@ const { data } = dict; | ||
// write record batch messages | ||
for (const batch of records) { | ||
@@ -68,2 +73,5 @@ writeMessage( | ||
// both stream and file include end-of-stream message | ||
builder.addBuffer(EOS); | ||
if (file) { | ||
@@ -70,0 +78,0 @@ writeFooter(builder, schema, dictBlocks, recordBlocks, metadata); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1097111
20911