@uwdata/flechette
Advanced tools
Comparing version 0.0.1 to 0.0.2
// src/constants.js | ||
var Version = { | ||
/** 0.1.0 (October 2016). */ | ||
V1: 0, | ||
/** 0.2.0 (February 2017). Non-backwards compatible with V1. */ | ||
V2: 1, | ||
/** 0.3.0 -> 0.7.1 (May - December 2017). Non-backwards compatible with V2. */ | ||
V3: 2, | ||
/** >= 0.8.0 (December 2017). Non-backwards compatible with V3. */ | ||
V4: 3, | ||
/** | ||
* >= 1.0.0 (July 2020). Backwards compatible with V4 (V5 readers can read V4 | ||
* metadata and IPC messages). Implementations are recommended to provide a | ||
* V4 compatibility mode with V5 format changes disabled. | ||
* | ||
* Incompatible changes between V4 and V5: | ||
* - Union buffer layout has changed. In V5, Unions don't have a validity bitmap buffer. | ||
*/ | ||
V5: 4 | ||
}; | ||
var MessageHeader = { | ||
NONE: 0, | ||
/** | ||
* A Schema describes the columns in a record batch. | ||
*/ | ||
Schema: 1, | ||
/** | ||
* For sending dictionary encoding information. Any Field can be | ||
* dictionary-encoded, but in this case none of its children may be | ||
* dictionary-encoded. | ||
* There is one vector / column per dictionary, but that vector / column | ||
* may be spread across multiple dictionary batches by using the isDelta | ||
* flag. | ||
*/ | ||
DictionaryBatch: 2, | ||
/** | ||
* A data header describing the shared memory layout of a "record" or "row" | ||
* batch. Some systems call this a "row batch" internally and others a "record | ||
* batch". | ||
*/ | ||
RecordBatch: 3, | ||
/** | ||
* EXPERIMENTAL: Metadata for n-dimensional arrays, aka "tensors" or | ||
* "ndarrays". Arrow implementations in general are not required to implement | ||
* this type. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
Tensor: 4, | ||
/** | ||
* EXPERIMENTAL: Metadata for n-dimensional sparse arrays, aka "sparse | ||
* tensors". Arrow implementations in general are not required to implement | ||
* this type. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
SparseTensor: 5 | ||
}; | ||
var Type = { | ||
/** | ||
* Dictionary types compress data by using a set of integer indices to | ||
* lookup potentially repeated vales in a separate dictionary of values. | ||
* | ||
* This type entry is provided for API convenience, it does not occur | ||
* in actual Arrow IPC binary data. | ||
*/ | ||
Dictionary: -1, | ||
/** No data type. Included for flatbuffer compatibility. */ | ||
NONE: 0, | ||
/** Null values only. */ | ||
Null: 1, | ||
/** Integers, either signed or unsigned, with 8, 16, 32, or 64 bit widths. */ | ||
Int: 2, | ||
/** Floating point numbers with 16, 32, or 64 bit precision. */ | ||
Float: 3, | ||
/** Opaque binary data. */ | ||
Binary: 4, | ||
/** Unicode with UTF-8 encoding. */ | ||
Utf8: 5, | ||
/** Booleans represented as 8 bit bytes. */ | ||
Bool: 6, | ||
/** | ||
* Exact decimal value represented as an integer value in two's complement. | ||
* Currently only 128-bit (16-byte) and 256-bit (32-byte) integers are used. | ||
* The representation uses the endianness indicated in the schema. | ||
*/ | ||
Decimal: 7, | ||
/** | ||
* Date is either a 32-bit or 64-bit signed integer type representing an | ||
* elapsed time since UNIX epoch (1970-01-01), stored in either of two units: | ||
* - Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no | ||
* leap seconds), where the values are evenly divisible by 86400000 | ||
* - Days (32 bits) since the UNIX epoch | ||
*/ | ||
Date: 8, | ||
/** | ||
* Time is either a 32-bit or 64-bit signed integer type representing an | ||
* elapsed time since midnight, stored in either of four units: seconds, | ||
* milliseconds, microseconds or nanoseconds. | ||
* | ||
* The integer `bitWidth` depends on the `unit` and must be one of the following: | ||
* - SECOND and MILLISECOND: 32 bits | ||
* - MICROSECOND and NANOSECOND: 64 bits | ||
* | ||
* The allowed values are between 0 (inclusive) and 86400 (=24*60*60) seconds | ||
* (exclusive), adjusted for the time unit (for example, up to 86400000 | ||
* exclusive for the MILLISECOND unit). | ||
* This definition doesn't allow for leap seconds. Time values from | ||
* measurements with leap seconds will need to be corrected when ingesting | ||
* into Arrow (for example by replacing the value 86400 with 86399). | ||
*/ | ||
Time: 9, | ||
/** | ||
* Timestamp is a 64-bit signed integer representing an elapsed time since a | ||
* fixed epoch, stored in either of four units: seconds, milliseconds, | ||
* microseconds or nanoseconds, and is optionally annotated with a timezone. | ||
* | ||
* Timestamp values do not include any leap seconds (in other words, all | ||
* days are considered 86400 seconds long). | ||
* | ||
* The timezone is an optional string for the name of a timezone, one of: | ||
* | ||
* - As used in the Olson timezone database (the "tz database" or | ||
* "tzdata"), such as "America/New_York". | ||
* - An absolute timezone offset of the form "+XX:XX" or "-XX:XX", | ||
* such as "+07:30". | ||
* | ||
* Whether a timezone string is present indicates different semantics about | ||
* the data. | ||
*/ | ||
Timestamp: 10, | ||
/** | ||
* A "calendar" interval which models types that don't necessarily | ||
* have a precise duration without the context of a base timestamp (e.g. | ||
* days can differ in length during day light savings time transitions). | ||
* All integers in the types below are stored in the endianness indicated | ||
* by the schema. | ||
*/ | ||
Interval: 11, | ||
/** | ||
* List (vector) data supporting variably-sized lists. | ||
* A list has a single child data type for list entries. | ||
*/ | ||
List: 12, | ||
/** | ||
* A struct consisting of multiple named child data types. | ||
*/ | ||
Struct: 13, | ||
/** | ||
* A union is a complex type with parallel child data types. By default ids | ||
* in the type vector refer to the offsets in the children. Optionally | ||
* typeIds provides an indirection between the child offset and the type id. | ||
* For each child `typeIds[offset]` is the id used in the type vector. | ||
*/ | ||
Union: 14, | ||
/** | ||
* Binary data where each entry has the same fixed size. | ||
*/ | ||
FixedSizeBinary: 15, | ||
/** | ||
* List (vector) data where every list has the same fixed size. | ||
* A list has a single child data type for list entries. | ||
*/ | ||
FixedSizeList: 16, | ||
/** | ||
* A Map is a logical nested type that is represented as | ||
* List<entries: Struct<key: K, value: V>> | ||
* | ||
* In this layout, the keys and values are each respectively contiguous. We do | ||
* not constrain the key and value types, so the application is responsible | ||
* for ensuring that the keys are hashable and unique. Whether the keys are sorted | ||
* may be set in the metadata for this field. | ||
* | ||
* In a field with Map type, the field has a child Struct field, which then | ||
* has two children: key type and the second the value type. The names of the | ||
* child fields may be respectively "entries", "key", and "value", but this is | ||
* not enforced. | ||
* | ||
* Map | ||
* ```text | ||
* - child[0] entries: Struct | ||
* - child[0] key: K | ||
* - child[1] value: V | ||
* ``` | ||
* Neither the "entries" field nor the "key" field may be nullable. | ||
* | ||
* The metadata is structured so that Arrow systems without special handling | ||
* for Map can make Map an alias for List. The "layout" attribute for the Map | ||
* field must have the same contents as a List. | ||
*/ | ||
Map: 17, | ||
/** | ||
* An absolute length of time unrelated to any calendar artifacts. For the | ||
* purposes of Arrow implementations, adding this value to a Timestamp | ||
* ("t1") naively (i.e. simply summing the two numbers) is acceptable even | ||
* though in some cases the resulting Timestamp (t2) would not account for | ||
* leap-seconds during the elapsed time between "t1" and "t2". Similarly, | ||
* representing the difference between two Unix timestamp is acceptable, but | ||
* would yield a value that is possibly a few seconds off from the true | ||
* elapsed time. | ||
* | ||
* The resolution defaults to millisecond, but can be any of the other | ||
* supported TimeUnit values as with Timestamp and Time types. This type is | ||
* always represented as an 8-byte integer. | ||
*/ | ||
Duration: 18, | ||
/** | ||
* Same as Binary, but with 64-bit offsets, allowing representation of | ||
* extremely large data values. | ||
*/ | ||
LargeBinary: 19, | ||
/** | ||
* Same as Utf8, but with 64-bit offsets, allowing representation of | ||
* extremely large data values. | ||
*/ | ||
LargeUtf8: 20, | ||
/** | ||
* Same as List, but with 64-bit offsets, allowing representation of | ||
* extremely large data values. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
LargeList: 21, | ||
/** | ||
* Contains two child arrays, run_ends and values. The run_ends child array | ||
* must be a 16/32/64-bit integer array which encodes the indices at which | ||
* the run with the value in each corresponding index in the values child | ||
* array ends. Like list/struct types, the value array can be of any type. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
RunEndEncoded: 22, | ||
/** | ||
* Logically the same as Binary, but the internal representation uses a view | ||
* struct that contains the string length and either the string's entire data | ||
* inline (for small strings) or an inlined prefix, an index of another buffer, | ||
* and an offset pointing to a slice in that buffer (for non-small strings). | ||
* | ||
* Since it uses a variable number of data buffers, each Field with this type | ||
* must have a corresponding entry in `variadicBufferCounts`. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
BinaryView: 23, | ||
/** | ||
* Logically the same as Utf8, but the internal representation uses a view | ||
* struct that contains the string length and either the string's entire data | ||
* inline (for small strings) or an inlined prefix, an index of another buffer, | ||
* and an offset pointing to a slice in that buffer (for non-small strings). | ||
* | ||
* Since it uses a variable number of data buffers, each Field with this type | ||
* must have a corresponding entry in `variadicBufferCounts`. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
Utf8View: 24, | ||
/** | ||
* Represents the same logical types that List can, but contains offsets and | ||
* sizes allowing for writes in any order and sharing of child values among | ||
* list values. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
ListView: 25, | ||
/** | ||
* Same as ListView, but with 64-bit offsets and sizes, allowing to represent | ||
* extremely large data values. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
LargeListView: 26 | ||
}; | ||
var Precision = { | ||
HALF: 0, | ||
SINGLE: 1, | ||
DOUBLE: 2 | ||
}; | ||
var DateUnit = { | ||
/* Days (32 bits) since the UNIX epoch. */ | ||
DAY: 0, | ||
/** | ||
* Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no | ||
* leap seconds), where the values are evenly divisible by 86400000. | ||
*/ | ||
MILLISECOND: 1 | ||
}; | ||
var TimeUnit = { | ||
/** Seconds. */ | ||
SECOND: 0, | ||
/** Milliseconds. */ | ||
MILLISECOND: 1, | ||
/** Microseconds. */ | ||
MICROSECOND: 2, | ||
/** Nanoseconds. */ | ||
NANOSECOND: 3 | ||
}; | ||
var IntervalUnit = { | ||
/** | ||
* Indicates the number of elapsed whole months, stored as 4-byte signed | ||
* integers. | ||
*/ | ||
YEAR_MONTH: 0, | ||
/** | ||
* Indicates the number of elapsed days and milliseconds (no leap seconds), | ||
* stored as 2 contiguous 32-bit signed integers (8-bytes in total). Support | ||
* of this IntervalUnit is not required for full arrow compatibility. | ||
*/ | ||
DAY_TIME: 1, | ||
/** | ||
* A triple of the number of elapsed months, days, and nanoseconds. | ||
* The values are stored contiguously in 16-byte blocks. Months and days are | ||
* encoded as 32-bit signed integers and nanoseconds is encoded as a 64-bit | ||
* signed integer. Nanoseconds does not allow for leap seconds. Each field is | ||
* independent (e.g. there is no constraint that nanoseconds have the same | ||
* sign as days or that the quantity of nanoseconds represents less than a | ||
* day's worth of time). | ||
*/ | ||
MONTH_DAY_NANO: 2 | ||
}; | ||
var UnionMode = { | ||
Sparse: 0, | ||
Dense: 1 | ||
}; | ||
var Version = ( | ||
/** @type {const} */ | ||
{ | ||
/** 0.1.0 (October 2016). */ | ||
V1: 0, | ||
/** 0.2.0 (February 2017). Non-backwards compatible with V1. */ | ||
V2: 1, | ||
/** 0.3.0 -> 0.7.1 (May - December 2017). Non-backwards compatible with V2. */ | ||
V3: 2, | ||
/** >= 0.8.0 (December 2017). Non-backwards compatible with V3. */ | ||
V4: 3, | ||
/** | ||
* >= 1.0.0 (July 2020). Backwards compatible with V4 (V5 readers can read V4 | ||
* metadata and IPC messages). Implementations are recommended to provide a | ||
* V4 compatibility mode with V5 format changes disabled. | ||
* | ||
* Incompatible changes between V4 and V5: | ||
* - Union buffer layout has changed. | ||
* In V5, Unions don't have a validity bitmap buffer. | ||
*/ | ||
V5: 4 | ||
} | ||
); | ||
var Endianness = ( | ||
/** @type {const} */ | ||
{ | ||
Little: 0, | ||
Big: 1 | ||
} | ||
); | ||
var MessageHeader = ( | ||
/** @type {const} */ | ||
{ | ||
NONE: 0, | ||
/** | ||
* A Schema describes the columns in a record batch. | ||
*/ | ||
Schema: 1, | ||
/** | ||
* For sending dictionary encoding information. Any Field can be | ||
* dictionary-encoded, but in this case none of its children may be | ||
* dictionary-encoded. | ||
* There is one vector / column per dictionary, but that vector / column | ||
* may be spread across multiple dictionary batches by using the isDelta | ||
* flag. | ||
*/ | ||
DictionaryBatch: 2, | ||
/** | ||
* A data header describing the shared memory layout of a "record" or "row" | ||
* batch. Some systems call this a "row batch" internally and others a "record | ||
* batch". | ||
*/ | ||
RecordBatch: 3, | ||
/** | ||
* EXPERIMENTAL: Metadata for n-dimensional arrays, aka "tensors" or | ||
* "ndarrays". Arrow implementations in general are not required to implement | ||
* this type. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
Tensor: 4, | ||
/** | ||
* EXPERIMENTAL: Metadata for n-dimensional sparse arrays, aka "sparse | ||
* tensors". Arrow implementations in general are not required to implement | ||
* this type. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
SparseTensor: 5 | ||
} | ||
); | ||
var Type = ( | ||
/** @type {const} */ | ||
{ | ||
/** | ||
* Dictionary types compress data by using a set of integer indices to | ||
* lookup potentially repeated vales in a separate dictionary of values. | ||
* | ||
* This type entry is provided for API convenience, it does not occur | ||
* in actual Arrow IPC binary data. | ||
*/ | ||
Dictionary: -1, | ||
/** No data type. Included for flatbuffer compatibility. */ | ||
NONE: 0, | ||
/** Null values only. */ | ||
Null: 1, | ||
/** Integers, either signed or unsigned, with 8, 16, 32, or 64 bit widths. */ | ||
Int: 2, | ||
/** Floating point numbers with 16, 32, or 64 bit precision. */ | ||
Float: 3, | ||
/** Opaque binary data. */ | ||
Binary: 4, | ||
/** Unicode with UTF-8 encoding. */ | ||
Utf8: 5, | ||
/** Booleans represented as 8 bit bytes. */ | ||
Bool: 6, | ||
/** | ||
* Exact decimal value represented as an integer value in two's complement. | ||
* Currently only 128-bit (16-byte) and 256-bit (32-byte) integers are used. | ||
* The representation uses the endianness indicated in the schema. | ||
*/ | ||
Decimal: 7, | ||
/** | ||
* Date is either a 32-bit or 64-bit signed integer type representing an | ||
* elapsed time since UNIX epoch (1970-01-01), stored in either of two units: | ||
* - Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no | ||
* leap seconds), where the values are evenly divisible by 86400000 | ||
* - Days (32 bits) since the UNIX epoch | ||
*/ | ||
Date: 8, | ||
/** | ||
* Time is either a 32-bit or 64-bit signed integer type representing an | ||
* elapsed time since midnight, stored in either of four units: seconds, | ||
* milliseconds, microseconds or nanoseconds. | ||
* | ||
* The integer `bitWidth` depends on the `unit` and must be one of the following: | ||
* - SECOND and MILLISECOND: 32 bits | ||
* - MICROSECOND and NANOSECOND: 64 bits | ||
* | ||
* The allowed values are between 0 (inclusive) and 86400 (=24*60*60) seconds | ||
* (exclusive), adjusted for the time unit (for example, up to 86400000 | ||
* exclusive for the MILLISECOND unit). | ||
* This definition doesn't allow for leap seconds. Time values from | ||
* measurements with leap seconds will need to be corrected when ingesting | ||
* into Arrow (for example by replacing the value 86400 with 86399). | ||
*/ | ||
Time: 9, | ||
/** | ||
* Timestamp is a 64-bit signed integer representing an elapsed time since a | ||
* fixed epoch, stored in either of four units: seconds, milliseconds, | ||
* microseconds or nanoseconds, and is optionally annotated with a timezone. | ||
* | ||
* Timestamp values do not include any leap seconds (in other words, all | ||
* days are considered 86400 seconds long). | ||
* | ||
* The timezone is an optional string for the name of a timezone, one of: | ||
* | ||
* - As used in the Olson timezone database (the "tz database" or | ||
* "tzdata"), such as "America/New_York". | ||
* - An absolute timezone offset of the form "+XX:XX" or "-XX:XX", | ||
* such as "+07:30". | ||
* | ||
* Whether a timezone string is present indicates different semantics about | ||
* the data. | ||
*/ | ||
Timestamp: 10, | ||
/** | ||
* A "calendar" interval which models types that don't necessarily | ||
* have a precise duration without the context of a base timestamp (e.g. | ||
* days can differ in length during day light savings time transitions). | ||
* All integers in the types below are stored in the endianness indicated | ||
* by the schema. | ||
*/ | ||
Interval: 11, | ||
/** | ||
* List (vector) data supporting variably-sized lists. | ||
* A list has a single child data type for list entries. | ||
*/ | ||
List: 12, | ||
/** | ||
* A struct consisting of multiple named child data types. | ||
*/ | ||
Struct: 13, | ||
/** | ||
* A union is a complex type with parallel child data types. By default ids | ||
* in the type vector refer to the offsets in the children. Optionally | ||
* typeIds provides an indirection between the child offset and the type id. | ||
* For each child `typeIds[offset]` is the id used in the type vector. | ||
*/ | ||
Union: 14, | ||
/** | ||
* Binary data where each entry has the same fixed size. | ||
*/ | ||
FixedSizeBinary: 15, | ||
/** | ||
* List (vector) data where every list has the same fixed size. | ||
* A list has a single child data type for list entries. | ||
*/ | ||
FixedSizeList: 16, | ||
/** | ||
* A Map is a logical nested type that is represented as | ||
* List<entries: Struct<key: K, value: V>> | ||
* | ||
* In this layout, the keys and values are each respectively contiguous. We do | ||
* not constrain the key and value types, so the application is responsible | ||
* for ensuring that the keys are hashable and unique. Whether the keys are sorted | ||
* may be set in the metadata for this field. | ||
* | ||
* In a field with Map type, the field has a child Struct field, which then | ||
* has two children: key type and the second the value type. The names of the | ||
* child fields may be respectively "entries", "key", and "value", but this is | ||
* not enforced. | ||
* | ||
* Map | ||
* ```text | ||
* - child[0] entries: Struct | ||
* - child[0] key: K | ||
* - child[1] value: V | ||
* ``` | ||
* Neither the "entries" field nor the "key" field may be nullable. | ||
* | ||
* The metadata is structured so that Arrow systems without special handling | ||
* for Map can make Map an alias for List. The "layout" attribute for the Map | ||
* field must have the same contents as a List. | ||
*/ | ||
Map: 17, | ||
/** | ||
* An absolute length of time unrelated to any calendar artifacts. For the | ||
* purposes of Arrow implementations, adding this value to a Timestamp | ||
* ("t1") naively (i.e. simply summing the two numbers) is acceptable even | ||
* though in some cases the resulting Timestamp (t2) would not account for | ||
* leap-seconds during the elapsed time between "t1" and "t2". Similarly, | ||
* representing the difference between two Unix timestamp is acceptable, but | ||
* would yield a value that is possibly a few seconds off from the true | ||
* elapsed time. | ||
* | ||
* The resolution defaults to millisecond, but can be any of the other | ||
* supported TimeUnit values as with Timestamp and Time types. This type is | ||
* always represented as an 8-byte integer. | ||
*/ | ||
Duration: 18, | ||
/** | ||
* Same as Binary, but with 64-bit offsets, allowing representation of | ||
* extremely large data values. | ||
*/ | ||
LargeBinary: 19, | ||
/** | ||
* Same as Utf8, but with 64-bit offsets, allowing representation of | ||
* extremely large data values. | ||
*/ | ||
LargeUtf8: 20, | ||
/** | ||
* Same as List, but with 64-bit offsets, allowing representation of | ||
* extremely large data values. | ||
*/ | ||
LargeList: 21, | ||
/** | ||
* Contains two child arrays, run_ends and values. The run_ends child array | ||
* must be a 16/32/64-bit integer array which encodes the indices at which | ||
* the run with the value in each corresponding index in the values child | ||
* array ends. Like list/struct types, the value array can be of any type. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
RunEndEncoded: 22, | ||
/** | ||
* Logically the same as Binary, but the internal representation uses a view | ||
* struct that contains the string length and either the string's entire data | ||
* inline (for small strings) or an inlined prefix, an index of another buffer, | ||
* and an offset pointing to a slice in that buffer (for non-small strings). | ||
* | ||
* Since it uses a variable number of data buffers, each Field with this type | ||
* must have a corresponding entry in `variadicBufferCounts`. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
BinaryView: 23, | ||
/** | ||
* Logically the same as Utf8, but the internal representation uses a view | ||
* struct that contains the string length and either the string's entire data | ||
* inline (for small strings) or an inlined prefix, an index of another buffer, | ||
* and an offset pointing to a slice in that buffer (for non-small strings). | ||
* | ||
* Since it uses a variable number of data buffers, each Field with this type | ||
* must have a corresponding entry in `variadicBufferCounts`. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
Utf8View: 24, | ||
/** | ||
* Represents the same logical types that List can, but contains offsets and | ||
* sizes allowing for writes in any order and sharing of child values among | ||
* list values. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
ListView: 25, | ||
/** | ||
* Same as ListView, but with 64-bit offsets and sizes, allowing to represent | ||
* extremely large data values. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
LargeListView: 26 | ||
} | ||
); | ||
var Precision = ( | ||
/** @type {const} */ | ||
{ | ||
/** 16-bit floating point number. */ | ||
HALF: 0, | ||
/** 32-bit floating point number. */ | ||
SINGLE: 1, | ||
/** 64-bit floating point number. */ | ||
DOUBLE: 2 | ||
} | ||
); | ||
var DateUnit = ( | ||
/** @type {const} */ | ||
{ | ||
/* Days (as 32 bit int) since the UNIX epoch. */ | ||
DAY: 0, | ||
/** | ||
* Milliseconds (as 64 bit int) indicating UNIX time elapsed since the epoch | ||
* (no leap seconds), with values evenly divisible by 86400000. | ||
*/ | ||
MILLISECOND: 1 | ||
} | ||
); | ||
var TimeUnit = ( | ||
/** @type {const} */ | ||
{ | ||
/** Seconds. */ | ||
SECOND: 0, | ||
/** Milliseconds. */ | ||
MILLISECOND: 1, | ||
/** Microseconds. */ | ||
MICROSECOND: 2, | ||
/** Nanoseconds. */ | ||
NANOSECOND: 3 | ||
} | ||
); | ||
var IntervalUnit = ( | ||
/** @type {const} */ | ||
{ | ||
/** | ||
* Indicates the number of elapsed whole months, stored as 4-byte signed | ||
* integers. | ||
*/ | ||
YEAR_MONTH: 0, | ||
/** | ||
* Indicates the number of elapsed days and milliseconds (no leap seconds), | ||
* stored as 2 contiguous 32-bit signed integers (8-bytes in total). Support | ||
* of this IntervalUnit is not required for full arrow compatibility. | ||
*/ | ||
DAY_TIME: 1, | ||
/** | ||
* A triple of the number of elapsed months, days, and nanoseconds. | ||
* The values are stored contiguously in 16-byte blocks. Months and days are | ||
* encoded as 32-bit signed integers and nanoseconds is encoded as a 64-bit | ||
* signed integer. Nanoseconds does not allow for leap seconds. Each field is | ||
* independent (e.g. there is no constraint that nanoseconds have the same | ||
* sign as days or that the quantity of nanoseconds represents less than a | ||
* day's worth of time). | ||
*/ | ||
MONTH_DAY_NANO: 2 | ||
} | ||
); | ||
var UnionMode = ( | ||
/** @type {const} */ | ||
{ | ||
/** Sparse union layout with full arrays for each sub-type. */ | ||
Sparse: 0, | ||
/** Dense union layout with offsets into value arrays. */ | ||
Dense: 1 | ||
} | ||
); | ||
@@ -343,3 +378,2 @@ // src/array-types.js | ||
var SIZEOF_INT = 4; | ||
var $iterator = Symbol.iterator; | ||
function decodeBit(bitmap, index) { | ||
@@ -359,3 +393,3 @@ return (bitmap[index >> 3] & 1 << index % 8) !== 0; | ||
function toNumber(value) { | ||
if (typeof value === "bigint" && (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)) { | ||
if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER) { | ||
throw Error(`BigInt exceeds integer number representation: ${value}`); | ||
@@ -470,2 +504,8 @@ } | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag]() { | ||
return "Batch"; | ||
} | ||
/** | ||
* Return the value at the given index. | ||
@@ -494,3 +534,6 @@ * @param {number} index The value index. | ||
value(index) { | ||
return this.values[index]; | ||
return ( | ||
/** @type {T} */ | ||
this.values[index] | ||
); | ||
} | ||
@@ -501,3 +544,3 @@ /** | ||
* @param {number} end The ending index, exclusive | ||
* @returns {T[] | import('./types.js').TypedArray} The slice of values | ||
* @returns {import('./types.js').ValueArray<T?>} The slice of values | ||
*/ | ||
@@ -514,5 +557,5 @@ slice(start, end) { | ||
* Return an iterator over the values in this batch. | ||
* @returns {Generator<T, any, null>} | ||
* @returns {Iterator<T?>} | ||
*/ | ||
*[$iterator]() { | ||
*[Symbol.iterator]() { | ||
const { length } = this; | ||
@@ -530,3 +573,3 @@ for (let i = 0; i < length; ++i) { | ||
* @param {number} end The ending index, exclusive | ||
* @returns {T[] | import('./types.js').TypedArray} The slice of values | ||
* @returns {import('./types.js').ValueArray<T?>} The slice of values | ||
*/ | ||
@@ -536,4 +579,11 @@ slice(start, end) { | ||
} | ||
[$iterator]() { | ||
return this.nullCount ? super[$iterator]() : this.values[$iterator](); | ||
/** | ||
* Return an iterator over the values in this batch. | ||
* @returns {Iterator<T?>} | ||
*/ | ||
[Symbol.iterator]() { | ||
return this.nullCount ? super[Symbol.iterator]() : ( | ||
/** @type {Iterator<T?>} */ | ||
this.values[Symbol.iterator]() | ||
); | ||
} | ||
@@ -561,3 +611,6 @@ }; | ||
value(index) { | ||
return toNumber(this.values[index]); | ||
return toNumber( | ||
/** @type {bigint} */ | ||
this.values[index] | ||
); | ||
} | ||
@@ -570,3 +623,6 @@ }; | ||
value(index) { | ||
const v = this.values[index]; | ||
const v = ( | ||
/** @type {number} */ | ||
this.values[index] | ||
); | ||
const expo = (v & 31744) >> 10; | ||
@@ -589,3 +645,7 @@ const sigf = (v & 1023) / 1024; | ||
value(index) { | ||
return decodeBit(this.values, index); | ||
return decodeBit( | ||
/** @type {Uint8Array} */ | ||
this.values, | ||
index | ||
); | ||
} | ||
@@ -600,5 +660,8 @@ }; | ||
super(options); | ||
const { bitWidth, scale } = this.type; | ||
this.stride = bitWidth >> 5; | ||
this.scale = Math.pow(10, scale); | ||
const type = ( | ||
/** @type {import('./types.js').DecimalType} */ | ||
this.type | ||
); | ||
this.stride = type.bitWidth >> 5; | ||
this.scale = Math.pow(10, type.scale); | ||
} | ||
@@ -609,3 +672,7 @@ /** | ||
value(index) { | ||
const { values: v, stride: n, scale: s } = this; | ||
const v = ( | ||
/** @type {Uint32Array} */ | ||
this.values | ||
); | ||
const n = this.stride; | ||
const off = index << 2; | ||
@@ -623,3 +690,3 @@ let x = 0; | ||
} | ||
return x / s; | ||
return x / this.scale; | ||
} | ||
@@ -645,3 +712,4 @@ }; | ||
value(index) { | ||
return 864e5 * this.values[index]; | ||
return 864e5 * /** @type {number} */ | ||
this.values[index]; | ||
} | ||
@@ -664,3 +732,7 @@ }; | ||
value(index) { | ||
return divide(this.values[index], 1000n); | ||
return divide( | ||
/** @type {bigint} */ | ||
this.values[index], | ||
1000n | ||
); | ||
} | ||
@@ -673,3 +745,7 @@ }; | ||
value(index) { | ||
return divide(this.values[index], 1000000n); | ||
return divide( | ||
/** @type {bigint} */ | ||
this.values[index], | ||
1000000n | ||
); | ||
} | ||
@@ -683,3 +759,7 @@ }; | ||
value(index) { | ||
return this.values.subarray(index << 1, index + 1 << 1); | ||
const values = ( | ||
/** @type {Int32Array} */ | ||
this.values | ||
); | ||
return values.subarray(index << 1, index + 1 << 1); | ||
} | ||
@@ -692,3 +772,6 @@ }; | ||
value(index) { | ||
const v = this.values[index]; | ||
const v = ( | ||
/** @type {number} */ | ||
this.values[index] | ||
); | ||
return Int32Array.of( | ||
@@ -707,3 +790,6 @@ Math.trunc(v / 12), | ||
value(index) { | ||
const values = this.values; | ||
const values = ( | ||
/** @type {Uint8Array} */ | ||
this.values | ||
); | ||
const base = index << 2; | ||
@@ -756,7 +842,10 @@ return Float64Array.of( | ||
* @param {number} index | ||
* @returns {import('./types.js').ColumnArray<V>} | ||
* @returns {import('./types.js').ValueArray<V>} | ||
*/ | ||
value(index) { | ||
const { offsets, children } = this; | ||
return children[0].slice(offsets[index], offsets[index + 1]); | ||
const offsets = ( | ||
/** @type {Int32Array} */ | ||
this.offsets | ||
); | ||
return this.children[0].slice(offsets[index], offsets[index + 1]); | ||
} | ||
@@ -767,7 +856,10 @@ }; | ||
* @param {number} index | ||
* @returns {import('./types.js').ColumnArray<V>} | ||
* @returns {import('./types.js').ValueArray<V>} | ||
*/ | ||
value(index) { | ||
const { offsets, children } = this; | ||
return children[0].slice(toNumber(offsets[index]), toNumber(offsets[index + 1])); | ||
const offsets = ( | ||
/** @type {BigInt64Array} */ | ||
this.offsets | ||
); | ||
return this.children[0].slice(toNumber(offsets[index]), toNumber(offsets[index + 1])); | ||
} | ||
@@ -781,4 +873,11 @@ }; | ||
value(index) { | ||
const { stride } = this.type; | ||
return this.values.subarray(index * stride, (index + 1) * stride); | ||
const { stride } = ( | ||
/** @type {import('./types.js').FixedSizeBinaryType} */ | ||
this.type | ||
); | ||
const values = ( | ||
/** @type {Uint8Array} */ | ||
this.values | ||
); | ||
return values.subarray(index * stride, (index + 1) * stride); | ||
} | ||
@@ -789,11 +888,14 @@ }; | ||
* @param {number} index | ||
* @returns {import('./types.js').ColumnArray<V>} | ||
* @returns {import('./types.js').ValueArray<V>} | ||
*/ | ||
value(index) { | ||
const { type, children } = this; | ||
const { stride } = type; | ||
const { stride } = ( | ||
/** @type {import('./types.js').FixedSizeListType} */ | ||
type | ||
); | ||
return children[0].slice(index * stride, (index + 1) * stride); | ||
} | ||
}; | ||
var pairs = ({ children, offsets }, index) => { | ||
function pairs({ children, offsets }, index) { | ||
const [keys, vals] = children[0].children; | ||
@@ -807,3 +909,3 @@ const start = offsets[index]; | ||
return entries; | ||
}; | ||
} | ||
var MapEntryBatch = class extends ArrayBatch { | ||
@@ -816,3 +918,6 @@ /** | ||
value(index) { | ||
return pairs(this, index); | ||
return ( | ||
/** @type {[K, V][]} */ | ||
pairs(this, index) | ||
); | ||
} | ||
@@ -827,3 +932,6 @@ }; | ||
value(index) { | ||
return new Map(pairs(this, index)); | ||
return new Map( | ||
/** @type {[K, V][]} */ | ||
pairs(this, index) | ||
); | ||
} | ||
@@ -850,3 +958,6 @@ }; | ||
value(index) { | ||
return super.value(this.offsets[index]); | ||
return super.value( | ||
/** @type {number} */ | ||
this.offsets[index] | ||
); | ||
} | ||
@@ -857,3 +968,7 @@ }; | ||
super(options); | ||
this.names = this.type.children.map((child) => child.name); | ||
const type = ( | ||
/** @type {import('./types.js').StructType} */ | ||
this.type | ||
); | ||
this.names = type.children.map((child) => child.name); | ||
} | ||
@@ -875,6 +990,16 @@ /** | ||
var DictionaryBatch = class extends ArrayBatch { | ||
/** | ||
* Create a new dictionary batch. | ||
* @param {object} options Batch options. | ||
* @param {import('./types.js').DataType} options.type The field data type | ||
* @param {number} options.length The length of the batch | ||
* @param {number} options.nullCount The null value count | ||
* @param {Uint8Array} [options.validity] Validity bitmap buffer | ||
* @param {import('./types.js').TypedArray} [options.values] Values buffer | ||
* @param {import('./column.js').Column<T>} options.dictionary | ||
* The dictionary of column values. | ||
*/ | ||
constructor(options) { | ||
super(options); | ||
const { dictionary: d } = options; | ||
this.cache = d.cache ?? (d.cache = d.toArray()); | ||
this.cache = options.dictionary.cache(); | ||
} | ||
@@ -885,3 +1010,3 @@ /** | ||
value(index) { | ||
return this.cache[this.values[index]]; | ||
return this.cache[this.key(index)]; | ||
} | ||
@@ -893,3 +1018,6 @@ /** | ||
key(index) { | ||
return this.values[index]; | ||
return ( | ||
/** @type {number} */ | ||
this.values[index] | ||
); | ||
} | ||
@@ -938,8 +1066,14 @@ }; | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag]() { | ||
return "Column"; | ||
} | ||
/** | ||
* Return an iterator over the values in this column. | ||
* @returns {Generator<T>} | ||
* @returns {Iterator<T?>} | ||
*/ | ||
[$iterator]() { | ||
[Symbol.iterator]() { | ||
const data = this.data; | ||
return data.length === 1 ? data[0][$iterator]() : batchedIterator(data); | ||
return data.length === 1 ? data[0][Symbol.iterator]() : batchedIterator(data); | ||
} | ||
@@ -970,3 +1104,3 @@ /** | ||
* a zero-copy subarray of the input Arrow data is returned. | ||
* @returns {import('./types.js').ColumnArray<T>} | ||
* @returns {import('./types.js').ValueArray<T?>} | ||
*/ | ||
@@ -983,2 +1117,9 @@ toArray() { | ||
} | ||
/** | ||
* Return an array of cached column values. | ||
* Used internally to accelerate dictionary types. | ||
*/ | ||
cache() { | ||
return this._cache ?? (this._cache = this.toArray()); | ||
} | ||
}; | ||
@@ -1072,3 +1213,3 @@ function* batchedIterator(data) { | ||
return typeInt( | ||
// @ts-ignore | ||
/** @type {import('../types.js').IntBitWidth} */ | ||
get(4, readInt32, 0), | ||
@@ -1082,7 +1223,10 @@ // bitwidth | ||
const get = table(buf, index); | ||
const precision = get(4, readInt16, Precision.HALF); | ||
const precision = ( | ||
/** @type {typeof Precision[keyof Precision]} */ | ||
get(4, readInt16, Precision.HALF) | ||
); | ||
return { | ||
typeId: Type.Float, | ||
precision, | ||
values: precision === Precision.HALF ? uint16 : precision === Precision.SINGLE ? float32 : precision === Precision.DOUBLE ? float64 : null | ||
values: precision === Precision.HALF ? uint16 : precision === Precision.SINGLE ? float32 : float64 | ||
}; | ||
@@ -1092,3 +1236,6 @@ } | ||
const get = table(buf, index); | ||
const bitWidth = get(8, readInt32, 128); | ||
const bitWidth = ( | ||
/** @type {128 | 256 } */ | ||
get(8, readInt32, 128) | ||
); | ||
return { | ||
@@ -1104,3 +1251,6 @@ typeId: Type.Decimal, | ||
const get = table(buf, index); | ||
const unit = get(4, readInt16, DateUnit.MILLISECOND); | ||
const unit = ( | ||
/** @type {typeof DateUnit[keyof DateUnit]} */ | ||
get(4, readInt16, DateUnit.MILLISECOND) | ||
); | ||
return { | ||
@@ -1114,6 +1264,12 @@ typeId: Type.Date, | ||
const get = table(buf, index); | ||
const bitWidth = get(6, readInt32, 32); | ||
const bitWidth = ( | ||
/** @type {32 | 64 } */ | ||
get(6, readInt32, 32) | ||
); | ||
return { | ||
typeId: Type.Time, | ||
unit: get(4, readInt16, TimeUnit.MILLISECOND), | ||
unit: ( | ||
/** @type {typeof TimeUnit[keyof TimeUnit]} */ | ||
get(4, readInt16, TimeUnit.MILLISECOND) | ||
), | ||
bitWidth, | ||
@@ -1127,3 +1283,6 @@ values: bitWidth === 32 ? int32 : int64 | ||
typeId: Type.Timestamp, | ||
unit: get(4, readInt16, TimeUnit.SECOND), | ||
unit: ( | ||
/** @type {typeof TimeUnit[keyof TimeUnit]} */ | ||
get(4, readInt16, TimeUnit.SECOND) | ||
), | ||
timezone: get(6, readString), | ||
@@ -1135,3 +1294,6 @@ values: int64 | ||
const get = table(buf, index); | ||
const unit = get(4, readInt16, IntervalUnit.YEAR_MONTH); | ||
const unit = ( | ||
/** @type {typeof IntervalUnit[keyof IntervalUnit]} */ | ||
get(4, readInt16, IntervalUnit.YEAR_MONTH) | ||
); | ||
return { | ||
@@ -1147,3 +1309,6 @@ typeId: Type.Interval, | ||
typeId: Type.Duration, | ||
unit: get(4, readInt16, TimeUnit.MILLISECOND), | ||
unit: ( | ||
/** @type {typeof TimeUnit[keyof TimeUnit]} */ | ||
get(4, readInt16, TimeUnit.MILLISECOND) | ||
), | ||
values: int64 | ||
@@ -1181,3 +1346,6 @@ }; | ||
typeId: Type.Union, | ||
mode: get(4, readInt16, UnionMode.Sparse), | ||
mode: ( | ||
/** @type {typeof UnionMode[keyof UnionMode]} */ | ||
get(4, readInt16, UnionMode.Sparse) | ||
), | ||
typeIds: new int32(buf.buffer, buf.byteOffset + base, length), | ||
@@ -1208,3 +1376,6 @@ children: children ?? [], | ||
version, | ||
endianness: get(4, readInt16, 0), | ||
endianness: ( | ||
/** @type {import('../types.js').Endianness_} */ | ||
get(4, readInt16, 0) | ||
), | ||
fields: get(6, (buf2, off) => decodeSchemaFields(buf2, off, dictionaryTypes), []), | ||
@@ -1342,4 +1513,10 @@ metadata: get(8, decodeMetadata), | ||
const get = table(head, 0); | ||
const version = get(4, readInt16, Version.V1); | ||
const type = get(6, readUint8, MessageHeader.NONE); | ||
const version = ( | ||
/** @type {import('../types.js').Version_} */ | ||
get(4, readInt16, Version.V1) | ||
); | ||
const type = ( | ||
/** @type {import('../types.js').MessageHeader_} */ | ||
get(6, readUint8, MessageHeader.NONE) | ||
); | ||
const offset = get(8, readOffset, 0); | ||
@@ -1418,3 +1595,6 @@ const bodyLength = get(10, readInt64AsNum, 0); | ||
} | ||
return { schema, dictionaries, records, metadata: null }; | ||
return ( | ||
/** @type {import('./types.js').ArrowData} */ | ||
{ schema, dictionaries, records, metadata: null } | ||
); | ||
} | ||
@@ -1425,13 +1605,17 @@ function parseIPCFile(data) { | ||
const get = table(data, offset - length); | ||
const version = get(4, readInt16, Version.V1); | ||
const version = ( | ||
/** @type {import('./types.js').Version_} */ | ||
get(4, readInt16, Version.V1) | ||
); | ||
const dicts = get(8, decodeBlocks, []); | ||
const recs = get(10, decodeBlocks, []); | ||
return { | ||
schema: get(6, (buf, index) => decodeSchema(buf, index, version)), | ||
// @ts-ignore | ||
dictionaries: dicts.map(({ offset: offset2 }) => decodeMessage(data, offset2).content), | ||
// @ts-ignore | ||
records: recs.map(({ offset: offset2 }) => decodeMessage(data, offset2).content), | ||
metadata: get(12, decodeMetadata) | ||
}; | ||
return ( | ||
/** @type {import('./types.js').ArrowData} */ | ||
{ | ||
schema: get(6, (buf, index) => decodeSchema(buf, index, version)), | ||
dictionaries: dicts.map(({ offset: offset2 }) => decodeMessage(data, offset2).content), | ||
records: recs.map(({ offset: offset2 }) => decodeMessage(data, offset2).content), | ||
metadata: get(12, decodeMetadata) | ||
} | ||
); | ||
} | ||
@@ -1451,2 +1635,8 @@ | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag]() { | ||
return "Table"; | ||
} | ||
/** | ||
* The number of columns in this table. | ||
@@ -1508,3 +1698,3 @@ * @return {number} The number of columns. | ||
* Return an object mapping column names to extracted value arrays. | ||
* @returns {Record<string, import('./types.js').ColumnArray<any>>} | ||
* @returns {Record<string, import('./types.js').ValueArray<any>>} | ||
*/ | ||
@@ -1520,2 +1710,18 @@ toColumns() { | ||
/** | ||
* Return an iterator over objects representing the rows of this table. | ||
* @returns {Generator<Record<string, any>, any, null>} | ||
*/ | ||
*[Symbol.iterator]() { | ||
const { children } = this; | ||
const batches = children[0].data.length; | ||
const names = children.map((c) => c.name); | ||
for (let b = 0; b < batches; ++b) { | ||
const data = children.map((c) => c.data[b]); | ||
const rows = data[0].length; | ||
for (let i = 0; i < rows; ++i) { | ||
yield rowObject(names, data, i); | ||
} | ||
} | ||
} | ||
/** | ||
* Return an array of objects representing the rows of this table. | ||
@@ -1525,15 +1731,11 @@ * @returns {Record<string, any>[]} | ||
toArray() { | ||
const { children, numCols, numRows } = this; | ||
const numBatches = children[0].data.length; | ||
const { children, numRows } = this; | ||
const batches = children[0].data.length; | ||
const names = children.map((c) => c.name); | ||
const output = Array(numRows); | ||
for (let b = 0, row = -1; b < numBatches; ++b) { | ||
for (let b = 0, row = -1; b < batches; ++b) { | ||
const data = children.map((c) => c.data[b]); | ||
const batchRows = data[0].length; | ||
for (let i = 0; i < batchRows; ++i) { | ||
const o = {}; | ||
for (let j = 0; j < numCols; ++j) { | ||
o[names[j]] = data[j].at(i); | ||
} | ||
output[++row] = o; | ||
const rows = data?.[0].length; | ||
for (let i = 0; i < rows; ++i) { | ||
output[++row] = rowObject(names, data, i); | ||
} | ||
@@ -1544,2 +1746,9 @@ } | ||
}; | ||
function rowObject(names, data, index) { | ||
const o = {}; | ||
for (let j = 0; j < names.length; ++j) { | ||
o[names[j]] = data[j].at(index); | ||
} | ||
return o; | ||
} | ||
@@ -1559,3 +1768,3 @@ // src/table-from-ipc.js | ||
const type = dictionaryTypes.get(id); | ||
const chunk = visit(type, context({ ...data2, body })); | ||
const batch = visit(type, context({ ...data2, body })); | ||
if (!dicts.has(id)) { | ||
@@ -1565,7 +1774,7 @@ if (isDelta) { | ||
} | ||
dicts.set(id, columnBuilder(`${id}`, type).add(chunk)); | ||
dicts.set(id, columnBuilder(`${id}`, type).add(batch)); | ||
} else { | ||
const dict2 = dicts.get(id); | ||
if (!isDelta) dict2.clear(); | ||
dict2.add(chunk); | ||
dict2.add(batch); | ||
} | ||
@@ -1594,3 +1803,2 @@ } | ||
length, | ||
debug: () => ({ nodeIndex, bufferIndex, nodes, buffers }), | ||
node: () => nodes[++nodeIndex], | ||
@@ -1651,7 +1859,7 @@ buffer: (ArrayType) => { | ||
case Type.Timestamp: | ||
return date(unit === TimeUnit.SECOND ? TimestampSecondBatch : unit === TimeUnit.MILLISECOND ? TimestampMillisecondBatch : unit === TimeUnit.MICROSECOND ? TimestampMicrosecondBatch : unit === TimeUnit.NANOSECOND ? TimestampNanosecondBatch : null); | ||
return date(unit === TimeUnit.SECOND ? TimestampSecondBatch : unit === TimeUnit.MILLISECOND ? TimestampMillisecondBatch : unit === TimeUnit.MICROSECOND ? TimestampMicrosecondBatch : TimestampNanosecondBatch); | ||
case Type.Decimal: | ||
return value(DecimalBatch); | ||
case Type.Interval: | ||
return value(unit === IntervalUnit.DAY_TIME ? IntervalDayTimeBatch : unit === IntervalUnit.YEAR_MONTH ? IntervalYearMonthBatch : unit === IntervalUnit.MONTH_DAY_NANO ? IntervalMonthDayNanoBatch : null); | ||
return value(unit === IntervalUnit.DAY_TIME ? IntervalDayTimeBatch : unit === IntervalUnit.YEAR_MONTH ? IntervalYearMonthBatch : IntervalMonthDayNanoBatch); | ||
case Type.FixedSizeBinary: | ||
@@ -1703,2 +1911,3 @@ return value(FixedBatch); | ||
DateUnit, | ||
Endianness, | ||
IntervalUnit, | ||
@@ -1705,0 +1914,0 @@ Precision, |
@@ -1,1 +0,1 @@ | ||
var M={V1:0,V2:1,V3:2,V4:3,V5:4},N={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},b={HALF:0,SINGLE:1,DOUBLE:2},k={DAY:0,MILLISECOND:1},D={SECOND:0,MILLISECOND:1,MICROSECOND:2,NANOSECOND:3},B={YEAR_MONTH:0,DAY_TIME:1,MONTH_DAY_NANO:2},H={Sparse:0,Dense:1};var Qt=Uint8Array,Mt=Uint16Array,St=Uint32Array,te=BigUint64Array,bt=Int8Array,ee=Int16Array,E=Int32Array,L=BigInt64Array,Rt=Float32Array,X=Float64Array;function $t(e,t){let r=Math.log2(e)-3;return(t?[bt,ee,E,L]:[Qt,Mt,St,te])[r]}var T=Symbol.iterator;function Bt(e,t){return(e[t>>3]&1<<t%8)!==0}var re=new TextDecoder("utf-8");function q(e){return re.decode(e)}function R(e,t){for(let[r,n]of Object.entries(e))if(n===t)return r;return"<Unknown>"}function w(e){if(typeof e=="bigint"&&(e>Number.MAX_SAFE_INTEGER||e<Number.MIN_SAFE_INTEGER))throw Error(`BigInt exceeds integer number representation: ${e}`);return Number(e)}function Lt(e,t){return w(e/t)+w(e%t)/w(t)}function f(e,t){let r=t+p(e,t),n=r-p(e,r),o=x(e,n);return(s,a,c=null)=>{if(s<o){let l=x(e,n+s);if(l)return a(e,r+l)}return c}}function O(e,t){return t}function U(e,t){return!!ne(e,t)}function ne(e,t){return Y(e,t)<<24>>24}function Y(e,t){return e[t]}function x(e,t){return oe(e,t)<<16>>16}function oe(e,t){return e[t]|e[t+1]<<8}function p(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function zt(e,t){return p(e,t)>>>0}function se(e,t){return BigInt.asIntN(64,BigInt(zt(e,t))+(BigInt(zt(e,t+4))<<BigInt(32)))}function v(e,t){return w(se(e,t))}function C(e,t){let r=t+p(e,t),n=p(e,r);return r+=4,q(e.subarray(r,r+n))}function A(e,t){return{length:p(e,t+p(e,t)),base:t+p(e,t)+4}}var P=class{static ArrayType=null;constructor({type:t,length:r,nullCount:n,validity:o,values:s,offsets:a,typeIds:c,children:l}){this.type=t,this.length=r,this.nullCount=n,this.validity=o,this.values=s,this.offsets=a,this.typeIds=c,this.children=l,n||(this.at=m=>this.value(m))}at(t){return this.isValid(t)?this.value(t):null}isValid(t){return Bt(this.validity,t)}value(t){return this.values[t]}slice(t,r){let n=r-t,o=Array(n);for(let s=0;s<n;++s)o[s]=this.at(t+s);return o}*[T](){let{length:t}=this;for(let r=0;r<t;++r)yield this.at(r)}},V=class extends P{slice(t,r){return this.nullCount?super.slice(t,r):this.values.subarray(t,r)}[T](){return this.nullCount?super[T]():this.values[T]()}},$=class extends P{static ArrayType=X},g=class extends P{static ArrayType=Array},J=class extends g{value(t){return null}},S=class extends ${value(t){return w(this.values[t])}},K=class extends ${value(t){let r=this.values[t],n=(r&31744)>>10,o=(r&1023)/1024,s=(-1)**((r&32768)>>15);switch(n){case 31:return s*(o?Number.NaN:1/0);case 0:return s*(o?6103515625e-14*o:0)}return s*2**(n-15)*(1+o)}},Q=class extends g{value(t){return Bt(this.values,t)}},Ht=Array.from({length:8},(e,t)=>Math.pow(2,t*32)),tt=class extends ${constructor(t){super(t);let{bitWidth:r,scale:n}=this.type;this.stride=r>>5,this.scale=Math.pow(10,n)}value(t){let{values:r,stride:n,scale:o}=this,s=t<<2,a=0;if((r[n-1]|0)<0){for(let c=0;c<n;++c)a+=~r[c+s]*Ht[c];a=-(a+1)}else for(let c=0;c<n;++c)a+=r[c+s]*Ht[c];return a/o}},et=class extends g{constructor(t){super(t),this.source=t}value(t){return new Date(this.source.value(t))}},rt=class extends ${value(t){return 864e5*this.values[t]}},Yt=S,nt=class extends S{value(t){return super.value(t)*1e3}},Pt=S,ot=class extends S{value(t){return Lt(this.values[t],1000n)}},st=class extends S{value(t){return Lt(this.values[t],1000000n)}},at=class extends g{value(t){return this.values.subarray(t<<1,t+1<<1)}},ct=class extends g{value(t){let r=this.values[t];return Int32Array.of(Math.trunc(r/12),Math.trunc(r%12))}},it=class extends g{value(t){let r=this.values,n=t<<2;return Float64Array.of(p(r,n),p(r,n+4),v(r,n+8))}},Gt=({values:e,offsets:t},r)=>e.subarray(t[r],t[r+1]),Zt=({values:e,offsets:t},r)=>e.subarray(w(t[r]),w(t[r+1])),lt=class extends g{value(t){return Gt(this,t)}},ut=class extends g{value(t){return Zt(this,t)}},dt=class extends g{value(t){return q(Gt(this,t))}},ft=class extends g{value(t){return q(Zt(this,t))}},pt=class extends g{value(t){let{offsets:r,children:n}=this;return n[0].slice(r[t],r[t+1])}},ht=class extends g{value(t){let{offsets:r,children:n}=this;return n[0].slice(w(r[t]),w(r[t+1]))}},mt=class extends g{value(t){let{stride:r}=this.type;return this.values.subarray(t*r,(t+1)*r)}},yt=class extends g{value(t){let{type:r,children:n}=this,{stride:o}=r;return n[0].slice(t*o,(t+1)*o)}},jt=({children:e,offsets:t},r)=>{let[n,o]=e[0].children,s=t[r],a=t[r+1],c=[];for(let l=s;l<a;++l)c.push([n.at(l),o.at(l)]);return c},gt=class extends g{value(t){return jt(this,t)}},It=class extends g{value(t){return new Map(jt(this,t))}},G=class extends g{constructor(t){super(t);let{typeIds:r}=t.type;this.map=r.reduce((n,o,s)=>(n[o]=s,n),{})}value(t){let{typeIds:r,children:n,map:o}=this;return n[o[r[t]]].at(t)}},vt=class extends G{value(t){return super.value(this.offsets[t])}},xt=class extends g{constructor(t){super(t),this.names=this.type.children.map(r=>r.name)}value(t){let{children:r,names:n}=this,o=n.length,s={};for(let a=0;a<o;++a)s[n[a]]=r[a].at(t);return s}},At=class extends g{constructor(t){super(t);let{dictionary:r}=t;this.cache=r.cache??(r.cache=r.toArray())}value(t){return this.cache[this.values[t]]}key(t){return this.values[t]}};function Ot(e,t){let r=[];return{type:t,add(n){return r.push(n),this},clear:()=>r=[],done:()=>new Tt(e,t,r)}}var Tt=class{constructor(t,r,n){this.name=t,this.type=r,this.length=n.reduce((a,c)=>a+c.length,0),this.nullCount=n.reduce((a,c)=>a+c.nullCount,0),this.data=n;let o=n.length,s=new Int32Array(o+1);if(o===1){let[a]=n;s[1]=a.length,this.at=c=>a.at(c)}else for(let a=0,c=0;a<o;++a)s[a+1]=c+=n[a].length;this.offsets=s}[T](){let t=this.data;return t.length===1?t[0][T]():ae(t)}at(t){let{data:r,offsets:n}=this,o=0,s=n.length;do{let a=o+s>>>1;n[a]<=t?o=a+1:s=a}while(o<s);return r[--o]?.at(t-n[o])}toArray(){let{length:t,nullCount:r,data:n}=this,o=!r&&ce(n);if(o&&n.length===1)return n[0].values;let s=r>0?Array:n[0].constructor.ArrayType??n[0].values.constructor,a=new s(t);return o?ie(a,n):le(a,n)}};function*ae(e){for(let t=0;t<e.length;++t){let r=e[t][Symbol.iterator]();for(let n=r.next();!n.done;n=r.next())yield n.value}}function ce(e){return e.length&&e[0]instanceof V}function ie(e,t){for(let r=0,n=0;r<t.length;++r){let{values:o}=t[r];e.set(o,n),n+=o.length}return e}function le(e,t){let r=-1;for(let n=0;n<t.length;++n){let o=t[n];for(let s=0;s<o.length;++s)e[++r]=o.at(s)}return e}function Ut(e,t,r,n){switch(r){case i.NONE:case i.Null:case i.Bool:return{typeId:r};case i.Binary:case i.Utf8:return{typeId:r,offsets:E};case i.LargeBinary:case i.LargeUtf8:return{typeId:r,offsets:L};case i.List:return{typeId:r,children:[n?.[0]??null],offsets:E};case i.LargeList:return{typeId:r,children:[n?.[0]??null],offsets:L};case i.Struct:return{typeId:r,children:n};case i.Int:return Ct(e,t);case i.Float:return ue(e,t);case i.Decimal:return de(e,t);case i.Date:return fe(e,t);case i.Time:return pe(e,t);case i.Timestamp:return he(e,t);case i.Interval:return me(e,t);case i.Duration:return ye(e,t);case i.FixedSizeBinary:return ge(e,t);case i.FixedSizeList:return Ie(e,t,n);case i.Map:return ve(e,t,n);case i.Union:return xe(e,t,n)}throw new Error(`Unrecognized type: "${R(i,r)}" (id ${r})`)}function Ft(e,t){return{typeId:i.Int,bitWidth:e,signed:t,values:$t(e,t)}}function Ct(e,t){let r=f(e,t);return Ft(r(4,p,0),r(6,U,!1))}function ue(e,t){let n=f(e,t)(4,x,b.HALF);return{typeId:i.Float,precision:n,values:n===b.HALF?Mt:n===b.SINGLE?Rt:n===b.DOUBLE?X:null}}function de(e,t){let r=f(e,t),n=r(8,p,128);return{typeId:i.Decimal,precision:r(4,p,0),scale:r(6,p,0),bitWidth:n,values:St}}function fe(e,t){let n=f(e,t)(4,x,k.MILLISECOND);return{typeId:i.Date,unit:n,values:n===k.DAY?E:L}}function pe(e,t){let r=f(e,t),n=r(6,p,32);return{typeId:i.Time,unit:r(4,x,D.MILLISECOND),bitWidth:n,values:n===32?E:L}}function he(e,t){let r=f(e,t);return{typeId:i.Timestamp,unit:r(4,x,D.SECOND),timezone:r(6,C),values:L}}function me(e,t){let n=f(e,t)(4,x,B.YEAR_MONTH);return{typeId:i.Interval,unit:n,values:n===B.MONTH_DAY_NANO?void 0:E}}function ye(e,t){let r=f(e,t);return{typeId:i.Duration,unit:r(4,x,D.MILLISECOND),values:L}}function ge(e,t){let r=f(e,t);return{typeId:i.FixedSizeBinary,stride:r(4,p,0)}}function Ie(e,t,r){let n=f(e,t);return{typeId:i.FixedSizeList,stride:n(4,p,0),children:[r?.[0]??null]}}function ve(e,t,r){let n=f(e,t);return{typeId:i.Map,keysSorted:n(4,U,!1),children:r,offsets:E}}function xe(e,t,r){let n=f(e,t),{length:o,base:s}=A(e,n(6,O));return{typeId:i.Union,mode:n(4,x,H.Sparse),typeIds:new E(e.buffer,e.byteOffset+s,o),children:r??[],offsets:E}}function Z(e,t){let{length:r,base:n}=A(e,t),o=r>0?new Map:null;for(let s=0;s<r;++s){let a=f(e,n+s*4),c=a(4,C),l=a(6,C);(c||l)&&o.set(c,l)}return o?.size?o:null}function Nt(e,t,r){let n=new Map,o=f(e,t);return{version:r,endianness:o(4,x,0),fields:o(6,(s,a)=>Ae(s,a,n),[]),metadata:o(8,Z),dictionaryTypes:n}}function Ae(e,t,r){let{length:n,base:o}=A(e,t),s=[];for(let a=0;a<n;++a)s.push(Wt(e,o+a*4,r));return s}function Wt(e,t,r){let n=f(e,t),o=n(8,Y,i.NONE),s=n(10,O,0),a=n(12,(m,d)=>De(m,d)),c=n(14,Ne),l;if(a){let{id:m}=a,d=r.get(m);d||(d=Ut(e,s,o,c),r.set(m,d)),a.type=d,l=a}else l=Ut(e,s,o,c);return{name:n(4,C),type:l,nullable:n(6,U,!1),metadata:n(16,Z)}}function Ne(e,t,r){let{length:n,base:o}=A(e,t),s=[];for(let a=0;a<n;++a){let c=o+a*4;s.push(Wt(e,c,r))}return s.length?s:null}function De(e,t){if(!t)return null;let r=f(e,t);return{type:null,typeId:i.Dictionary,id:r(4,v,0),keys:r(6,Ct,Ft(32,!0)),ordered:r(8,U,!1)}}function Dt(e,t,r){let n=f(e,t);if(n(10,O,0))throw new Error("Record batch compression not implemented");let o=[],s=n(6,A);if(s){let{length:l,base:m}=s;for(let d=0;d<l;++d){let u=m+d*16;o.push({length:v(e,u),nullCount:v(e,u+8)})}}let a=[],c=n(8,A);if(c){let{length:l,base:m}=c,d=r<M.V4;for(let u=0;u<l;++u){let h=m+u*16+(d?8*(u+1):0);a.push({offset:v(e,h),length:v(e,h+8)})}}return{length:n(4,v,0),nodes:o,buffers:a}}function Xt(e,t,r){let n=f(e,t);return{id:n(4,v,0),data:n(6,(o,s)=>Dt(o,s,r)),isDelta:n(8,U,!1)}}var Ee=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,we=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,Me=e=>`Unsupported message type: ${e} (${R(N,e)})`;function Et(e,t){let r=p(e,t)||0;if(t+=4,r===-1&&(r=p(e,t)||0,t+=4),r===0)return null;let n=e.subarray(t,t+=r);if(n.byteLength<r)throw new Error(Ee(r,n.byteLength));let o=f(n,0),s=o(4,x,M.V1),a=o(6,Y,N.NONE),c=o(8,O,0),l=o(10,v,0),m;if(c){let d=a===N.Schema?Nt:a===N.DictionaryBatch?Xt:a===N.RecordBatch?Dt:null;if(!d)throw new Error(Me(a));if(m=d(n,c,s),l>0){let u=e.subarray(t,t+=l);if(u.byteLength<l)throw new Error(we(l,u.byteLength));m.body=u}}return{version:s,type:a,index:t,content:m}}function Se(e,t){return{offset:v(e,t),metadataLength:p(e,t+8),bodyLength:v(e,t+16)}}function Vt(e,t){let{length:r,base:n}=A(e,t),o=[];for(let s=0;s<r;++s)o.push(Se(e,n+s*24));return o}function Jt(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;return!Array.isArray(t)&&be(t)?Le(t):Be(t)}var Kt=Uint8Array.of(65,82,82,79,87,49);function be(e){if(!e||e.length<4)return!1;for(let t=0;t<6;++t)if(Kt[t]!==e[t])return!1;return!0}function Be(e){let t=[e].flat(),r,n=[],o=[];for(let s of t){let a=0;for(;;){let c=Et(s,a);if(c===null)break;if(a=c.index,!!c.content)switch(c.type){case N.Schema:r||(r=c.content);break;case N.RecordBatch:n.push(c.content);break;case N.DictionaryBatch:o.push(c.content);break}}}return{schema:r,dictionaries:o,records:n,metadata:null}}function Le(e){let t=e.byteLength-(Kt.length+4),r=p(e,t),n=f(e,t-r),o=n(4,x,M.V1),s=n(8,Vt,[]),a=n(10,Vt,[]);return{schema:n(6,(c,l)=>Nt(c,l,o)),dictionaries:s.map(({offset:c})=>Et(e,c).content),records:a.map(({offset:c})=>Et(e,c).content),metadata:n(12,Z)}}var wt=class e{constructor(t,r){this.schema=t,this.children=r}get numCols(){return this.children.length}get numRows(){return this.children?.[0].length??0}getChildAt(t){return this.children[t]}getChild(t){return this.children.find(r=>r.name===t)}selectAt(t){let{fields:r}=this.schema;return new e({...this.schema,fields:t.map(n=>r[n])},t.map(n=>this.children[n]))}select(t){let r=this.children.map(o=>o.name),n=t.map(o=>r.indexOf(o)).filter(o=>o>-1);return this.selectAt(n)}toColumns(){let{children:t}=this,r={};for(let n of t)r[n.name]=n.toArray();return r}toArray(){let{children:t,numCols:r,numRows:n}=this,o=t[0].data.length,s=t.map(c=>c.name),a=Array(n);for(let c=0,l=-1;c<o;++c){let m=t.map(u=>u.data[c]),d=m[0].length;for(let u=0;u<d;++u){let h={};for(let y=0;y<r;++y)h[s[y]]=m[y].at(u);a[++l]=h}}return a}};function Te(e,t){return Oe(Jt(e),t)}function Oe(e,t={}){let{schema:r,dictionaries:n,records:o}=e,{version:s,fields:a,dictionaryTypes:c}=r,l=new Map,m=Ue(t,s,l),d=new Map;for(let h of n){let{id:y,data:F,isDelta:z,body:I}=h,_=c.get(y),j=_t(_,m({...F,body:I}));if(d.has(y)){let W=d.get(y);z||W.clear(),W.add(j)}else{if(z)throw new Error("Delta update can not be first dictionary batch.");d.set(y,Ot(`${y}`,_).add(j))}}d.forEach((h,y)=>l.set(y,h.done()));let u=a.map(({name:h,type:y})=>Ot(h,y));for(let h of o){let y=m(h);u.forEach(F=>F.add(_t(F.type,y)))}return new wt(r,u.map(h=>h.done()))}function Ue(e,t,r){let n={version:t,options:e,dictionary:o=>r.get(o)};return o=>{let{length:s,nodes:a,buffers:c,body:l}=o,m=-1,d=-1;return{...n,length:s,debug:()=>({nodeIndex:m,bufferIndex:d,nodes:a,buffers:c}),node:()=>a[++m],buffer:u=>{let{length:h,offset:y}=c[++d];return u?new u(l.buffer,l.byteOffset+y,h/u.BYTES_PER_ELEMENT):l.subarray(y,y+h)},visitAll(u){return u.map(h=>_t(h.type,this))}}}}function _t(e,t){let{typeId:r,bitWidth:n,precision:o,unit:s}=e,{useBigInt:a,useDate:c,useMap:l}=t.options;if(r===i.Null){let{length:I}=t;return new J({type:e,length:I,nullCount:I})}let d={...t.node(),type:e},u=I=>new I({...d,validity:t.buffer(),values:t.buffer(e.values)}),h=I=>new I({...d,validity:t.buffer(),offsets:t.buffer(e.offsets),values:t.buffer()}),y=I=>new I({...d,validity:t.buffer(),offsets:t.buffer(e.offsets),children:t.visitAll(e.children)}),F=I=>new I({...d,validity:t.buffer(),children:t.visitAll(e.children)}),z=c?I=>new et(u(I)):u;switch(r){case i.Bool:return u(Q);case i.Int:case i.Time:case i.Duration:return u(n===64&&!a?S:V);case i.Float:return u(o===b.HALF?K:V);case i.Date:return z(s===k.DAY?rt:Yt);case i.Timestamp:return z(s===D.SECOND?nt:s===D.MILLISECOND?Pt:s===D.MICROSECOND?ot:s===D.NANOSECOND?st:null);case i.Decimal:return u(tt);case i.Interval:return u(s===B.DAY_TIME?at:s===B.YEAR_MONTH?ct:s===B.MONTH_DAY_NANO?it:null);case i.FixedSizeBinary:return u(mt);case i.Utf8:return h(dt);case i.LargeUtf8:return h(ft);case i.Binary:return h(lt);case i.LargeBinary:return h(ut);case i.List:return y(pt);case i.LargeList:return y(ht);case i.Map:return y(l?It:gt);case i.FixedSizeList:return F(yt);case i.Struct:return F(xt);case i.Dictionary:{let{id:I,keys:_}=e;return new At({...d,validity:t.buffer(),values:t.buffer(_.values),dictionary:t.dictionary(I)})}case i.Union:{t.version<M.V5&&t.buffer();let I=e.mode===H.Sparse,_=t.buffer(bt),j=I?null:t.buffer(e.offsets),W=t.visitAll(e.children),kt={...d,typeIds:_,offsets:j,children:W};return I?new G(kt):new vt(kt)}default:throw new Error(`Unsupported type: ${r}, (${R(i,r)})`)}}export{k as DateUnit,B as IntervalUnit,b as Precision,D as TimeUnit,i as Type,H as UnionMode,M as Version,Te as tableFromIPC}; | ||
var N={V1:0,V2:1,V3:2,V4:3,V5:4},Qt={Little:0,Big:1},A={NONE:0,Schema:1,DictionaryBatch:2,RecordBatch:3,Tensor:4,SparseTensor:5},c={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},U={HALF:0,SINGLE:1,DOUBLE:2},_={DAY:0,MILLISECOND:1},w={SECOND:0,MILLISECOND:1,MICROSECOND:2,NANOSECOND:3},F={YEAR_MONTH:0,DAY_TIME:1,MONTH_DAY_NANO:2},H={Sparse:0,Dense:1};var te=Uint8Array,Nt=Uint16Array,wt=Uint32Array,ee=BigUint64Array,Et=Int8Array,re=Int16Array,S=Int32Array,M=BigInt64Array,kt=Float32Array,W=Float64Array;function Rt(e,t){let r=Math.log2(e)-3;return(t?[Et,re,S,M]:[te,Nt,wt,ee])[r]}function Mt(e,t){return(e[t>>3]&1<<t%8)!==0}var ne=new TextDecoder("utf-8");function X(e){return ne.decode(e)}function k(e,t){for(let[r,n]of Object.entries(e))if(n===t)return r;return"<Unknown>"}function D(e){if(e>Number.MAX_SAFE_INTEGER||e<Number.MIN_SAFE_INTEGER)throw Error(`BigInt exceeds integer number representation: ${e}`);return Number(e)}function Tt(e,t){return D(e/t)+D(e%t)/D(t)}function f(e,t){let r=t+h(e,t),n=r-h(e,r),o=x(e,n);return(s,a,i=null)=>{if(s<o){let l=x(e,n+s);if(l)return a(e,r+l)}return i}}function T(e,t){return t}function B(e,t){return!!oe(e,t)}function oe(e,t){return $(e,t)<<24>>24}function $(e,t){return e[t]}function x(e,t){return se(e,t)<<16>>16}function se(e,t){return e[t]|e[t+1]<<8}function h(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function zt(e,t){return h(e,t)>>>0}function ae(e,t){return BigInt.asIntN(64,BigInt(zt(e,t))+(BigInt(zt(e,t+4))<<BigInt(32)))}function I(e,t){return D(ae(e,t))}function O(e,t){let r=t+h(e,t),n=h(e,r);return r+=4,X(e.subarray(r,r+n))}function b(e,t){return{length:h(e,t+h(e,t)),base:t+h(e,t)+4}}var P=class{static ArrayType=null;constructor({type:t,length:r,nullCount:n,validity:o,values:s,offsets:a,typeIds:i,children:l}){this.type=t,this.length=r,this.nullCount=n,this.validity=o,this.values=s,this.offsets=a,this.typeIds=i,this.children=l,n||(this.at=p=>this.value(p))}get[Symbol.toStringTag](){return"Batch"}at(t){return this.isValid(t)?this.value(t):null}isValid(t){return Mt(this.validity,t)}value(t){return this.values[t]}slice(t,r){let n=r-t,o=Array(n);for(let s=0;s<n;++s)o[s]=this.at(t+s);return o}*[Symbol.iterator](){let{length:t}=this;for(let r=0;r<t;++r)yield this.at(r)}},C=class extends P{slice(t,r){return this.nullCount?super.slice(t,r):this.values.subarray(t,r)}[Symbol.iterator](){return this.nullCount?super[Symbol.iterator]():this.values[Symbol.iterator]()}},R=class extends P{static ArrayType=W},y=class extends P{static ArrayType=Array},q=class extends y{value(t){return null}},E=class extends R{value(t){return D(this.values[t])}},J=class extends R{value(t){let r=this.values[t],n=(r&31744)>>10,o=(r&1023)/1024,s=(-1)**((r&32768)>>15);switch(n){case 31:return s*(o?Number.NaN:1/0);case 0:return s*(o?6103515625e-14*o:0)}return s*2**(n-15)*(1+o)}},K=class extends y{value(t){return Mt(this.values,t)}},Ht=Array.from({length:8},(e,t)=>Math.pow(2,t*32)),Q=class extends R{constructor(t){super(t);let r=this.type;this.stride=r.bitWidth>>5,this.scale=Math.pow(10,r.scale)}value(t){let r=this.values,n=this.stride,o=t<<2,s=0;if((r[n-1]|0)<0){for(let a=0;a<n;++a)s+=~r[a+o]*Ht[a];s=-(s+1)}else for(let a=0;a<n;++a)s+=r[a+o]*Ht[a];return s/this.scale}},tt=class extends y{constructor(t){super(t),this.source=t}value(t){return new Date(this.source.value(t))}},et=class extends R{value(t){return 864e5*this.values[t]}},$t=E,rt=class extends E{value(t){return super.value(t)*1e3}},Pt=E,nt=class extends E{value(t){return Tt(this.values[t],1000n)}},ot=class extends E{value(t){return Tt(this.values[t],1000000n)}},st=class extends y{value(t){return this.values.subarray(t<<1,t+1<<1)}},at=class extends y{value(t){let r=this.values[t];return Int32Array.of(Math.trunc(r/12),Math.trunc(r%12))}},ct=class extends y{value(t){let r=this.values,n=t<<2;return Float64Array.of(h(r,n),h(r,n+4),I(r,n+8))}},Yt=({values:e,offsets:t},r)=>e.subarray(t[r],t[r+1]),Gt=({values:e,offsets:t},r)=>e.subarray(D(t[r]),D(t[r+1])),it=class extends y{value(t){return Yt(this,t)}},lt=class extends y{value(t){return Gt(this,t)}},ut=class extends y{value(t){return X(Yt(this,t))}},dt=class extends y{value(t){return X(Gt(this,t))}},ft=class extends y{value(t){let r=this.offsets;return this.children[0].slice(r[t],r[t+1])}},ht=class extends y{value(t){let r=this.offsets;return this.children[0].slice(D(r[t]),D(r[t+1]))}},pt=class extends y{value(t){let{stride:r}=this.type;return this.values.subarray(t*r,(t+1)*r)}},mt=class extends y{value(t){let{type:r,children:n}=this,{stride:o}=r;return n[0].slice(t*o,(t+1)*o)}};function jt({children:e,offsets:t},r){let[n,o]=e[0].children,s=t[r],a=t[r+1],i=[];for(let l=s;l<a;++l)i.push([n.at(l),o.at(l)]);return i}var yt=class extends y{value(t){return jt(this,t)}},gt=class extends y{value(t){return new Map(jt(this,t))}},Y=class extends y{constructor(t){super(t);let{typeIds:r}=t.type;this.map=r.reduce((n,o,s)=>(n[o]=s,n),{})}value(t){let{typeIds:r,children:n,map:o}=this;return n[o[r[t]]].at(t)}},vt=class extends Y{value(t){return super.value(this.offsets[t])}},It=class extends y{constructor(t){super(t);let r=this.type;this.names=r.children.map(n=>n.name)}value(t){let{children:r,names:n}=this,o=n.length,s={};for(let a=0;a<o;++a)s[n[a]]=r[a].at(t);return s}},xt=class extends y{constructor(t){super(t),this.cache=t.dictionary.cache()}value(t){return this.cache[this.key(t)]}key(t){return this.values[t]}};function Lt(e,t){let r=[];return{type:t,add(n){return r.push(n),this},clear:()=>r=[],done:()=>new Bt(e,t,r)}}var Bt=class{constructor(t,r,n){this.name=t,this.type=r,this.length=n.reduce((a,i)=>a+i.length,0),this.nullCount=n.reduce((a,i)=>a+i.nullCount,0),this.data=n;let o=n.length,s=new Int32Array(o+1);if(o===1){let[a]=n;s[1]=a.length,this.at=i=>a.at(i)}else for(let a=0,i=0;a<o;++a)s[a+1]=i+=n[a].length;this.offsets=s}get[Symbol.toStringTag](){return"Column"}[Symbol.iterator](){let t=this.data;return t.length===1?t[0][Symbol.iterator]():ce(t)}at(t){let{data:r,offsets:n}=this,o=0,s=n.length;do{let a=o+s>>>1;n[a]<=t?o=a+1:s=a}while(o<s);return r[--o]?.at(t-n[o])}toArray(){let{length:t,nullCount:r,data:n}=this,o=!r&&ie(n);if(o&&n.length===1)return n[0].values;let s=r>0?Array:n[0].constructor.ArrayType??n[0].values.constructor,a=new s(t);return o?le(a,n):ue(a,n)}cache(){return this._cache??(this._cache=this.toArray())}};function*ce(e){for(let t=0;t<e.length;++t){let r=e[t][Symbol.iterator]();for(let n=r.next();!n.done;n=r.next())yield n.value}}function ie(e){return e.length&&e[0]instanceof C}function le(e,t){for(let r=0,n=0;r<t.length;++r){let{values:o}=t[r];e.set(o,n),n+=o.length}return e}function ue(e,t){let r=-1;for(let n=0;n<t.length;++n){let o=t[n];for(let s=0;s<o.length;++s)e[++r]=o.at(s)}return e}function Ut(e,t,r,n){switch(r){case c.NONE:case c.Null:case c.Bool:return{typeId:r};case c.Binary:case c.Utf8:return{typeId:r,offsets:S};case c.LargeBinary:case c.LargeUtf8:return{typeId:r,offsets:M};case c.List:return{typeId:r,children:[n?.[0]??null],offsets:S};case c.LargeList:return{typeId:r,children:[n?.[0]??null],offsets:M};case c.Struct:return{typeId:r,children:n};case c.Int:return Ot(e,t);case c.Float:return de(e,t);case c.Decimal:return fe(e,t);case c.Date:return he(e,t);case c.Time:return pe(e,t);case c.Timestamp:return me(e,t);case c.Interval:return ye(e,t);case c.Duration:return ge(e,t);case c.FixedSizeBinary:return ve(e,t);case c.FixedSizeList:return Ie(e,t,n);case c.Map:return xe(e,t,n);case c.Union:return be(e,t,n)}throw new Error(`Unrecognized type: "${k(c,r)}" (id ${r})`)}function Ft(e,t){return{typeId:c.Int,bitWidth:e,signed:t,values:Rt(e,t)}}function Ot(e,t){let r=f(e,t);return Ft(r(4,h,0),r(6,B,!1))}function de(e,t){let n=f(e,t)(4,x,U.HALF);return{typeId:c.Float,precision:n,values:n===U.HALF?Nt:n===U.SINGLE?kt:W}}function fe(e,t){let r=f(e,t),n=r(8,h,128);return{typeId:c.Decimal,precision:r(4,h,0),scale:r(6,h,0),bitWidth:n,values:wt}}function he(e,t){let n=f(e,t)(4,x,_.MILLISECOND);return{typeId:c.Date,unit:n,values:n===_.DAY?S:M}}function pe(e,t){let r=f(e,t),n=r(6,h,32);return{typeId:c.Time,unit:r(4,x,w.MILLISECOND),bitWidth:n,values:n===32?S:M}}function me(e,t){let r=f(e,t);return{typeId:c.Timestamp,unit:r(4,x,w.SECOND),timezone:r(6,O),values:M}}function ye(e,t){let n=f(e,t)(4,x,F.YEAR_MONTH);return{typeId:c.Interval,unit:n,values:n===F.MONTH_DAY_NANO?void 0:S}}function ge(e,t){let r=f(e,t);return{typeId:c.Duration,unit:r(4,x,w.MILLISECOND),values:M}}function ve(e,t){let r=f(e,t);return{typeId:c.FixedSizeBinary,stride:r(4,h,0)}}function Ie(e,t,r){let n=f(e,t);return{typeId:c.FixedSizeList,stride:n(4,h,0),children:[r?.[0]??null]}}function xe(e,t,r){let n=f(e,t);return{typeId:c.Map,keysSorted:n(4,B,!1),children:r,offsets:S}}function be(e,t,r){let n=f(e,t),{length:o,base:s}=b(e,n(6,T));return{typeId:c.Union,mode:n(4,x,H.Sparse),typeIds:new S(e.buffer,e.byteOffset+s,o),children:r??[],offsets:S}}function G(e,t){let{length:r,base:n}=b(e,t),o=r>0?new Map:null;for(let s=0;s<r;++s){let a=f(e,n+s*4),i=a(4,O),l=a(6,O);(i||l)&&o.set(i,l)}return o?.size?o:null}function bt(e,t,r){let n=new Map,o=f(e,t);return{version:r,endianness:o(4,x,0),fields:o(6,(s,a)=>Ae(s,a,n),[]),metadata:o(8,G),dictionaryTypes:n}}function Ae(e,t,r){let{length:n,base:o}=b(e,t),s=[];for(let a=0;a<n;++a)s.push(Zt(e,o+a*4,r));return s}function Zt(e,t,r){let n=f(e,t),o=n(8,$,c.NONE),s=n(10,T,0),a=n(12,(p,u)=>De(p,u)),i=n(14,Se),l;if(a){let{id:p}=a,u=r.get(p);u||(u=Ut(e,s,o,i),r.set(p,u)),a.type=u,l=a}else l=Ut(e,s,o,i);return{name:n(4,O),type:l,nullable:n(6,B,!1),metadata:n(16,G)}}function Se(e,t,r){let{length:n,base:o}=b(e,t),s=[];for(let a=0;a<n;++a){let i=o+a*4;s.push(Zt(e,i,r))}return s.length?s:null}function De(e,t){if(!t)return null;let r=f(e,t);return{type:null,typeId:c.Dictionary,id:r(4,I,0),keys:r(6,Ot,Ft(32,!0)),ordered:r(8,B,!1)}}function At(e,t,r){let n=f(e,t);if(n(10,T,0))throw new Error("Record batch compression not implemented");let o=[],s=n(6,b);if(s){let{length:l,base:p}=s;for(let u=0;u<l;++u){let d=p+u*16;o.push({length:I(e,d),nullCount:I(e,d+8)})}}let a=[],i=n(8,b);if(i){let{length:l,base:p}=i,u=r<N.V4;for(let d=0;d<l;++d){let m=p+d*16+(u?8*(d+1):0);a.push({offset:I(e,m),length:I(e,m+8)})}}return{length:n(4,I,0),nodes:o,buffers:a}}function Wt(e,t,r){let n=f(e,t);return{id:n(4,I,0),data:n(6,(o,s)=>At(o,s,r)),isDelta:n(8,B,!1)}}var Ne=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,we=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,Ee=e=>`Unsupported message type: ${e} (${k(A,e)})`;function St(e,t){let r=h(e,t)||0;if(t+=4,r===-1&&(r=h(e,t)||0,t+=4),r===0)return null;let n=e.subarray(t,t+=r);if(n.byteLength<r)throw new Error(Ne(r,n.byteLength));let o=f(n,0),s=o(4,x,N.V1),a=o(6,$,A.NONE),i=o(8,T,0),l=o(10,I,0),p;if(i){let u=a===A.Schema?bt:a===A.DictionaryBatch?Wt:a===A.RecordBatch?At:null;if(!u)throw new Error(Ee(a));if(p=u(n,i,s),l>0){let d=e.subarray(t,t+=l);if(d.byteLength<l)throw new Error(we(l,d.byteLength));p.body=d}}return{version:s,type:a,index:t,content:p}}function Me(e,t){return{offset:I(e,t),metadataLength:h(e,t+8),bodyLength:I(e,t+16)}}function Ct(e,t){let{length:r,base:n}=b(e,t),o=[];for(let s=0;s<r;++s)o.push(Me(e,n+s*24));return o}function qt(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;return!Array.isArray(t)&&Te(t)?Le(t):Be(t)}var Jt=Uint8Array.of(65,82,82,79,87,49);function Te(e){if(!e||e.length<4)return!1;for(let t=0;t<6;++t)if(Jt[t]!==e[t])return!1;return!0}function Be(e){let t=[e].flat(),r,n=[],o=[];for(let s of t){let a=0;for(;;){let i=St(s,a);if(i===null)break;if(a=i.index,!!i.content)switch(i.type){case A.Schema:r||(r=i.content);break;case A.RecordBatch:n.push(i.content);break;case A.DictionaryBatch:o.push(i.content);break}}}return{schema:r,dictionaries:o,records:n,metadata:null}}function Le(e){let t=e.byteLength-(Jt.length+4),r=h(e,t),n=f(e,t-r),o=n(4,x,N.V1),s=n(8,Ct,[]),a=n(10,Ct,[]);return{schema:n(6,(i,l)=>bt(i,l,o)),dictionaries:s.map(({offset:i})=>St(e,i).content),records:a.map(({offset:i})=>St(e,i).content),metadata:n(12,G)}}var Dt=class e{constructor(t,r){this.schema=t,this.children=r}get[Symbol.toStringTag](){return"Table"}get numCols(){return this.children.length}get numRows(){return this.children?.[0].length??0}getChildAt(t){return this.children[t]}getChild(t){return this.children.find(r=>r.name===t)}selectAt(t){let{fields:r}=this.schema;return new e({...this.schema,fields:t.map(n=>r[n])},t.map(n=>this.children[n]))}select(t){let r=this.children.map(o=>o.name),n=t.map(o=>r.indexOf(o)).filter(o=>o>-1);return this.selectAt(n)}toColumns(){let{children:t}=this,r={};for(let n of t)r[n.name]=n.toArray();return r}*[Symbol.iterator](){let{children:t}=this,r=t[0].data.length,n=t.map(o=>o.name);for(let o=0;o<r;++o){let s=t.map(i=>i.data[o]),a=s[0].length;for(let i=0;i<a;++i)yield Kt(n,s,i)}}toArray(){let{children:t,numRows:r}=this,n=t[0].data.length,o=t.map(a=>a.name),s=Array(r);for(let a=0,i=-1;a<n;++a){let l=t.map(u=>u.data[a]),p=l?.[0].length;for(let u=0;u<p;++u)s[++i]=Kt(o,l,u)}return s}};function Kt(e,t,r){let n={};for(let o=0;o<e.length;++o)n[e[o]]=t[o].at(r);return n}function Ue(e,t){return Fe(qt(e),t)}function Fe(e,t={}){let{schema:r,dictionaries:n,records:o}=e,{version:s,fields:a,dictionaryTypes:i}=r,l=new Map,p=Oe(t,s,l),u=new Map;for(let m of n){let{id:g,data:L,isDelta:z,body:v}=m,V=i.get(g),j=Vt(V,p({...L,body:v}));if(u.has(g)){let Z=u.get(g);z||Z.clear(),Z.add(j)}else{if(z)throw new Error("Delta update can not be first dictionary batch.");u.set(g,Lt(`${g}`,V).add(j))}}u.forEach((m,g)=>l.set(g,m.done()));let d=a.map(({name:m,type:g})=>Lt(m,g));for(let m of o){let g=p(m);d.forEach(L=>L.add(Vt(L.type,g)))}return new Dt(r,d.map(m=>m.done()))}function Oe(e,t,r){let n={version:t,options:e,dictionary:o=>r.get(o)};return o=>{let{length:s,nodes:a,buffers:i,body:l}=o,p=-1,u=-1;return{...n,length:s,node:()=>a[++p],buffer:d=>{let{length:m,offset:g}=i[++u];return d?new d(l.buffer,l.byteOffset+g,m/d.BYTES_PER_ELEMENT):l.subarray(g,g+m)},visitAll(d){return d.map(m=>Vt(m.type,this))}}}}function Vt(e,t){let{typeId:r,bitWidth:n,precision:o,unit:s}=e,{useBigInt:a,useDate:i,useMap:l}=t.options;if(r===c.Null){let{length:v}=t;return new q({type:e,length:v,nullCount:v})}let u={...t.node(),type:e},d=v=>new v({...u,validity:t.buffer(),values:t.buffer(e.values)}),m=v=>new v({...u,validity:t.buffer(),offsets:t.buffer(e.offsets),values:t.buffer()}),g=v=>new v({...u,validity:t.buffer(),offsets:t.buffer(e.offsets),children:t.visitAll(e.children)}),L=v=>new v({...u,validity:t.buffer(),children:t.visitAll(e.children)}),z=i?v=>new tt(d(v)):d;switch(r){case c.Bool:return d(K);case c.Int:case c.Time:case c.Duration:return d(n===64&&!a?E:C);case c.Float:return d(o===U.HALF?J:C);case c.Date:return z(s===_.DAY?et:$t);case c.Timestamp:return z(s===w.SECOND?rt:s===w.MILLISECOND?Pt:s===w.MICROSECOND?nt:ot);case c.Decimal:return d(Q);case c.Interval:return d(s===F.DAY_TIME?st:s===F.YEAR_MONTH?at:ct);case c.FixedSizeBinary:return d(pt);case c.Utf8:return m(ut);case c.LargeUtf8:return m(dt);case c.Binary:return m(it);case c.LargeBinary:return m(lt);case c.List:return g(ft);case c.LargeList:return g(ht);case c.Map:return g(l?gt:yt);case c.FixedSizeList:return L(mt);case c.Struct:return L(It);case c.Dictionary:{let{id:v,keys:V}=e;return new xt({...u,validity:t.buffer(),values:t.buffer(V.values),dictionary:t.dictionary(v)})}case c.Union:{t.version<N.V5&&t.buffer();let v=e.mode===H.Sparse,V=t.buffer(Et),j=v?null:t.buffer(e.offsets),Z=t.visitAll(e.children),_t={...u,typeIds:V,offsets:j,children:Z};return v?new Y(_t):new vt(_t)}default:throw new Error(`Unsupported type: ${r}, (${k(c,r)})`)}}export{_ as DateUnit,Qt as Endianness,F as IntervalUnit,U as Precision,w as TimeUnit,c as Type,H as UnionMode,N as Version,Ue as tableFromIPC}; |
@@ -68,5 +68,14 @@ /** | ||
* @param {number} end The ending index, exclusive | ||
* @returns {T[] | import('./types.js').TypedArray} The slice of values | ||
* @returns {import('./types.js').ValueArray<T?>} The slice of values | ||
*/ | ||
slice(start: number, end: number): T[] | import("./types.js").TypedArray; | ||
slice(start: number, end: number): import("./types.js").ValueArray<T | null>; | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag](): string; | ||
/** | ||
* Return an iterator over the values in this batch. | ||
* @returns {Iterator<T?>} | ||
*/ | ||
[Symbol.iterator](): Iterator<T | null>; | ||
} | ||
@@ -438,5 +447,5 @@ /** | ||
* @template V | ||
* @extends {ArrayBatch<import('./types.js').ColumnArray<V>>} | ||
* @extends {ArrayBatch<import('./types.js').ValueArray<V>>} | ||
*/ | ||
export class ListBatch<V> extends ArrayBatch<import("./types.js").ColumnArray<V>> { | ||
export class ListBatch<V> extends ArrayBatch<import("./types.js").ValueArray<V>> { | ||
} | ||
@@ -448,5 +457,5 @@ /** | ||
* @template V | ||
* @extends {ArrayBatch<import('./types.js').ColumnArray<V>>} | ||
* @extends {ArrayBatch<import('./types.js').ValueArray<V>>} | ||
*/ | ||
export class LargeListBatch<V> extends ArrayBatch<import("./types.js").ColumnArray<V>> { | ||
export class LargeListBatch<V> extends ArrayBatch<import("./types.js").ValueArray<V>> { | ||
} | ||
@@ -485,5 +494,5 @@ /** | ||
* @template V | ||
* @extends {ArrayBatch<import('./types.js').ColumnArray<V>>} | ||
* @extends {ArrayBatch<import('./types.js').ValueArray<V>>} | ||
*/ | ||
export class FixedListBatch<V> extends ArrayBatch<import("./types.js").ColumnArray<V>> { | ||
export class FixedListBatch<V> extends ArrayBatch<import("./types.js").ValueArray<V>> { | ||
} | ||
@@ -580,4 +589,3 @@ /** | ||
constructor(options: any); | ||
/** @type {string} */ | ||
names: string; | ||
names: string[]; | ||
} | ||
@@ -590,9 +598,22 @@ /** | ||
export class DictionaryBatch<T> extends ArrayBatch<T> { | ||
constructor(options: any); | ||
/** @type {import('./types.js').ColumnArray<T>} */ | ||
cache: import("./types.js").ColumnArray<T>; | ||
/** | ||
* @param {number} index The value index. | ||
* Create a new dictionary batch. | ||
* @param {object} options Batch options. | ||
* @param {import('./types.js').DataType} options.type The field data type | ||
* @param {number} options.length The length of the batch | ||
* @param {number} options.nullCount The null value count | ||
* @param {Uint8Array} [options.validity] Validity bitmap buffer | ||
* @param {import('./types.js').TypedArray} [options.values] Values buffer | ||
* @param {import('./column.js').Column<T>} options.dictionary | ||
* The dictionary of column values. | ||
*/ | ||
value(index: number): any; | ||
constructor(options: { | ||
type: import("./types.js").DataType; | ||
length: number; | ||
nullCount: number; | ||
validity?: Uint8Array; | ||
values?: import("./types.js").TypedArray; | ||
dictionary: import("./column.js").Column<T>; | ||
}); | ||
cache: import("./types.js").ValueArray<T>; | ||
/** | ||
@@ -599,0 +620,0 @@ * @param {number} index The value index. |
@@ -72,5 +72,20 @@ /** | ||
* a zero-copy subarray of the input Arrow data is returned. | ||
* @returns {import('./types.js').ColumnArray<T>} | ||
* @returns {import('./types.js').ValueArray<T?>} | ||
*/ | ||
toArray(): import("./types.js").ColumnArray<T>; | ||
toArray(): import("./types.js").ValueArray<T | null>; | ||
/** | ||
* Return an array of cached column values. | ||
* Used internally to accelerate dictionary types. | ||
*/ | ||
cache(): import("./types.js").ValueArray<T>; | ||
_cache: import("./types.js").ValueArray<T>; | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag](): string; | ||
/** | ||
* Return an iterator over the values in this column. | ||
* @returns {Iterator<T?>} | ||
*/ | ||
[Symbol.iterator](): Iterator<T | null>; | ||
} |
export namespace Version { | ||
let V1: number; | ||
let V2: number; | ||
let V3: number; | ||
let V4: number; | ||
let V5: number; | ||
let V1: 0; | ||
let V2: 1; | ||
let V3: 2; | ||
let V4: 3; | ||
let V5: 4; | ||
} | ||
export namespace Endianness { | ||
let Little: 0; | ||
let Big: 1; | ||
} | ||
export namespace MessageHeader { | ||
let NONE: number; | ||
let Schema: number; | ||
let DictionaryBatch: number; | ||
let RecordBatch: number; | ||
let Tensor: number; | ||
let SparseTensor: number; | ||
let NONE: 0; | ||
let Schema: 1; | ||
let DictionaryBatch: 2; | ||
let RecordBatch: 3; | ||
let Tensor: 4; | ||
let SparseTensor: 5; | ||
} | ||
export namespace Type { | ||
export let Dictionary: number; | ||
let NONE_1: number; | ||
export let Dictionary: -1; | ||
let NONE_1: 0; | ||
export { NONE_1 as NONE }; | ||
export let Null: number; | ||
export let Int: number; | ||
export let Float: number; | ||
export let Binary: number; | ||
export let Utf8: number; | ||
export let Bool: number; | ||
export let Decimal: number; | ||
export let Date: number; | ||
export let Time: number; | ||
export let Timestamp: number; | ||
export let Interval: number; | ||
export let List: number; | ||
export let Struct: number; | ||
export let Union: number; | ||
export let FixedSizeBinary: number; | ||
export let FixedSizeList: number; | ||
export let Map: number; | ||
export let Duration: number; | ||
export let LargeBinary: number; | ||
export let LargeUtf8: number; | ||
export let LargeList: number; | ||
export let RunEndEncoded: number; | ||
export let BinaryView: number; | ||
export let Utf8View: number; | ||
export let ListView: number; | ||
export let LargeListView: number; | ||
export let Null: 1; | ||
export let Int: 2; | ||
export let Float: 3; | ||
export let Binary: 4; | ||
export let Utf8: 5; | ||
export let Bool: 6; | ||
export let Decimal: 7; | ||
export let Date: 8; | ||
export let Time: 9; | ||
export let Timestamp: 10; | ||
export let Interval: 11; | ||
export let List: 12; | ||
export let Struct: 13; | ||
export let Union: 14; | ||
export let FixedSizeBinary: 15; | ||
export let FixedSizeList: 16; | ||
export let Map: 17; | ||
export let Duration: 18; | ||
export let LargeBinary: 19; | ||
export let LargeUtf8: 20; | ||
export let LargeList: 21; | ||
export let RunEndEncoded: 22; | ||
export let BinaryView: 23; | ||
export let Utf8View: 24; | ||
export let ListView: 25; | ||
export let LargeListView: 26; | ||
} | ||
export namespace Precision { | ||
let HALF: number; | ||
let SINGLE: number; | ||
let DOUBLE: number; | ||
let HALF: 0; | ||
let SINGLE: 1; | ||
let DOUBLE: 2; | ||
} | ||
export namespace DateUnit { | ||
let DAY: number; | ||
let MILLISECOND: number; | ||
let DAY: 0; | ||
let MILLISECOND: 1; | ||
} | ||
export namespace TimeUnit { | ||
export let SECOND: number; | ||
let MILLISECOND_1: number; | ||
export let SECOND: 0; | ||
let MILLISECOND_1: 1; | ||
export { MILLISECOND_1 as MILLISECOND }; | ||
export let MICROSECOND: number; | ||
export let NANOSECOND: number; | ||
export let MICROSECOND: 2; | ||
export let NANOSECOND: 3; | ||
} | ||
export namespace IntervalUnit { | ||
let YEAR_MONTH: number; | ||
let DAY_TIME: number; | ||
let MONTH_DAY_NANO: number; | ||
let YEAR_MONTH: 0; | ||
let DAY_TIME: 1; | ||
let MONTH_DAY_NANO: 2; | ||
} | ||
export namespace UnionMode { | ||
let Sparse: number; | ||
let Dense: number; | ||
let Sparse: 0; | ||
let Dense: 1; | ||
} |
@@ -12,7 +12,7 @@ /** | ||
* Construct an integer data type. | ||
* @param {8|16|32|64} bitWidth The integer bit width. | ||
* @param {import('../types.js').IntBitWidth} bitWidth The integer bit width. | ||
* @param {boolean} signed Flag for signed or unsigned integers. | ||
* @returns {import('../types.js').IntType} The integer data type. | ||
*/ | ||
export function typeInt(bitWidth: 8 | 16 | 32 | 64, signed: boolean): import("../types.js").IntType; | ||
export function typeInt(bitWidth: import("../types.js").IntBitWidth, signed: boolean): import("../types.js").IntType; | ||
/** | ||
@@ -19,0 +19,0 @@ * Decode an integer data type from binary data. |
@@ -5,5 +5,5 @@ /** | ||
* @param {number} index The starting index in the byte buffer | ||
* @param {import('../types.js').Version} version Arrow version value | ||
* @param {import('../types.js').Version_} version Arrow version value | ||
* @returns {import('../types.js').DictionaryBatch} The dictionary batch | ||
*/ | ||
export function decodeDictionaryBatch(buf: Uint8Array, index: number, version: import("../types.js").Version): import("../types.js").DictionaryBatch; | ||
export function decodeDictionaryBatch(buf: Uint8Array, index: number, version: import("../types.js").Version_): import("../types.js").DictionaryBatch; |
@@ -5,5 +5,5 @@ /** | ||
* @param {number} index The starting index in the byte buffer | ||
* @param {import('../types.js').Version} version Arrow version value | ||
* @param {import('../types.js').Version_} version Arrow version value | ||
* @returns {import('../types.js').RecordBatch} The record batch | ||
*/ | ||
export function decodeRecordBatch(buf: Uint8Array, index: number, version: import("../types.js").Version): import("../types.js").RecordBatch; | ||
export function decodeRecordBatch(buf: Uint8Array, index: number, version: import("../types.js").Version_): import("../types.js").RecordBatch; |
@@ -5,5 +5,5 @@ /** | ||
* @param {number} index The starting index in the byte buffer | ||
* @param {import('../types.js').Version} version Arrow version value | ||
* @param {import('../types.js').Version_} version Arrow version value | ||
* @returns {import('../types.js').Schema} The schema | ||
*/ | ||
export function decodeSchema(buf: Uint8Array, index: number, version: import("../types.js").Version): import("../types.js").Schema; | ||
export function decodeSchema(buf: Uint8Array, index: number, version: import("../types.js").Version_): import("../types.js").Schema; |
export { tableFromIPC } from "./table-from-ipc.js"; | ||
export { Version, Type, Precision, DateUnit, TimeUnit, IntervalUnit, UnionMode } from "./constants.js"; | ||
export { Version, Endianness, Type, Precision, DateUnit, TimeUnit, IntervalUnit, UnionMode } from "./constants.js"; | ||
import { Version, Endianness, MessageHeader, Precision, DateUnit, TimeUnit, IntervalUnit, UnionMode } from './constants.js'; | ||
export { Batch } from './batch.js'; | ||
export { Column } from './column.js'; | ||
export { Table } from './table.js'; | ||
/** A valid Arrow version number. */ | ||
export type Version_ = typeof Version[keyof typeof Version]; | ||
/** A valid endianness value. */ | ||
export type Endianness_ = typeof Endianness[keyof typeof Endianness]; | ||
/** A valid message header type value. */ | ||
export type MessageHeader_ = typeof MessageHeader[keyof typeof MessageHeader]; | ||
/** A valid floating point precision value. */ | ||
export type Precision_ = typeof Precision[keyof typeof Precision]; | ||
/** A valid date unit value. */ | ||
export type DateUnit_ = typeof DateUnit[keyof typeof DateUnit]; | ||
/** A valid time unit value. */ | ||
export type TimeUnit_ = typeof TimeUnit[keyof typeof TimeUnit]; | ||
/** A valid date/time interval unit value. */ | ||
export type IntervalUnit_ = typeof IntervalUnit[keyof typeof IntervalUnit]; | ||
/** A valid union type mode value. */ | ||
export type UnionMode_ = typeof UnionMode[keyof typeof UnionMode]; | ||
export type TypedArray = Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; | ||
export type OffsetArray = Int32Array | BigInt64Array; | ||
export type IntArrayConstructor = Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | BigUint64ArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | BigInt64ArrayConstructor; | ||
export type FloatArrayConstructor = Uint16ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor; | ||
export type DateTimeArrayConstructor = Int32ArrayConstructor | BigInt64ArrayConstructor; | ||
export type TypedArrayConstructor = Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | BigUint64ArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | BigInt64ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor; | ||
/** An extracted array of column values. */ | ||
export interface ValueArray<T> extends ArrayLike<T>, Iterable<T> { | ||
slice(start?: number, end?: number): ValueArray<T>; | ||
} | ||
/** Custom metadata. */ | ||
export type Metadata = Map<string, string>; | ||
/** | ||
* Arrow table schema. | ||
*/ | ||
export interface Schema { | ||
version: Version_; | ||
endianness: Endianness_; | ||
fields: Field[]; | ||
metadata?: Metadata | null; | ||
dictionaryTypes: Map<number, DataType>; | ||
} | ||
/** | ||
* Arrow schema field definition. | ||
*/ | ||
export interface Field { | ||
name: string; | ||
type: DataType; | ||
nullable: boolean; | ||
metadata: Metadata; | ||
} | ||
/** Valid integer bit widths. */ | ||
export type IntBitWidth = 8 | 16 | 32 | 64; | ||
/** Dictionary-encoded data type. */ | ||
export type DictionaryType = { | ||
typeId: -1; | ||
type: DataType; | ||
id: number; | ||
keys: IntType; | ||
ordered: boolean; | ||
}; | ||
/** None data type. */ | ||
export type NoneType = { | ||
typeId: 0; | ||
}; | ||
/** Null data type. */ | ||
export type NullType = { | ||
typeId: 1; | ||
}; | ||
/** Integer data type. */ | ||
export type IntType = { | ||
typeId: 2; | ||
bitWidth: IntBitWidth; | ||
signed: boolean; | ||
values: IntArrayConstructor; | ||
}; | ||
/** Floating point number data type. */ | ||
export type FloatType = { | ||
typeId: 3; | ||
precision: Precision_; | ||
values: FloatArrayConstructor; | ||
}; | ||
/** Opaque binary data type. */ | ||
export type BinaryType = { | ||
typeId: 4; | ||
offsets: Int32ArrayConstructor; | ||
}; | ||
/** UTF-8 encoded string data type. */ | ||
export type Utf8Type = { | ||
typeId: 5; | ||
offsets: Int32ArrayConstructor; | ||
}; | ||
/** Boolean data type. */ | ||
export type BoolType = { | ||
typeId: 6; | ||
}; | ||
/** Fixed decimal number data type. */ | ||
export type DecimalType = { | ||
typeId: 7; | ||
precision: number; | ||
scale: number; | ||
bitWidth: 128 | 256; | ||
values: Uint32ArrayConstructor; | ||
}; | ||
/** Date data type. */ | ||
export type DateType = { | ||
typeId: 8; | ||
unit: DateUnit_; | ||
values: DateTimeArrayConstructor; | ||
}; | ||
/** Time data type. */ | ||
export type TimeType = { | ||
typeId: 9; | ||
unit: TimeUnit_; | ||
bitWidth: 32 | 64; | ||
values: DateTimeArrayConstructor; | ||
}; | ||
/** Timestamp data type. */ | ||
export type TimestampType = { | ||
typeId: 10; | ||
unit: TimeUnit_; | ||
timezone: string | null; | ||
values: BigInt64ArrayConstructor; | ||
}; | ||
/** Date/time interval data type. */ | ||
export type IntervalType = { | ||
typeId: 11; | ||
unit: IntervalUnit_; | ||
values?: Int32ArrayConstructor; | ||
}; | ||
/** List data type. */ | ||
export type ListType = { | ||
typeId: 12; | ||
children: [Field]; | ||
offsets: Int32ArrayConstructor; | ||
}; | ||
/** Struct data type. */ | ||
export type StructType = { | ||
typeId: 13; | ||
children: Field[]; | ||
}; | ||
/** Union data type. */ | ||
export type UnionType = { | ||
typeId: 14; | ||
mode: UnionMode_; | ||
typeIds: Int32Array; | ||
children: Field[]; | ||
offsets: Int32ArrayConstructor; | ||
}; | ||
/** Fixed-size opaque binary data type. */ | ||
export type FixedSizeBinaryType = { | ||
typeId: 15; | ||
stride: number; | ||
}; | ||
/** Fixed-size list data type. */ | ||
export type FixedSizeListType = { | ||
typeId: 16; | ||
stride: number; | ||
children: Field[]; | ||
}; | ||
/** Key-value map data type. */ | ||
export type MapType = { | ||
typeId: 17; | ||
keysSorted: boolean; | ||
children: [Field, Field]; | ||
offsets: Int32ArrayConstructor; | ||
}; | ||
/** Duration data type. */ | ||
export type DurationType = { | ||
typeId: 18; | ||
unit: TimeUnit_; | ||
values: BigInt64ArrayConstructor; | ||
}; | ||
/** Opaque binary data type with 64-bit integer offsets for larger data. */ | ||
export type LargeBinaryType = { | ||
typeId: 19; | ||
offsets: BigInt64ArrayConstructor; | ||
}; | ||
/** UTF-8 encoded string data type with 64-bit integer offsets for larger data. */ | ||
export type LargeUtf8Type = { | ||
typeId: 20; | ||
offsets: BigInt64ArrayConstructor; | ||
}; | ||
/** List data type with 64-bit integer offsets for larger data. */ | ||
export type LargeListType = { | ||
typeId: 21; | ||
children: [Field]; | ||
offsets: BigInt64ArrayConstructor; | ||
}; | ||
/** | ||
* Arrow field data types. | ||
*/ | ||
export type DataType = NoneType | NullType | IntType | FloatType | BinaryType | Utf8Type | BoolType | DecimalType | DateType | TimeType | TimestampType | IntervalType | ListType | StructType | UnionType | FixedSizeBinaryType | FixedSizeListType | MapType | DurationType | LargeBinaryType | LargeUtf8Type | LargeListType | DictionaryType; | ||
/** | ||
* Arrow IPC record batch message. | ||
*/ | ||
export interface RecordBatch { | ||
length: number; | ||
nodes: { | ||
length: number; | ||
nullCount: number; | ||
}[]; | ||
buffers: { | ||
offset: number; | ||
length: number; | ||
}[]; | ||
body?: Uint8Array; | ||
} | ||
/** | ||
* Arrow IPC dictionary batch message. | ||
*/ | ||
export interface DictionaryBatch { | ||
id: number; | ||
data: RecordBatch; | ||
isDelta: boolean; | ||
body?: Uint8Array; | ||
} | ||
/** | ||
* Parsed Arrow IPC data, prior to table construction. | ||
*/ | ||
export interface ArrowData { | ||
schema: Schema; | ||
dictionaries: DictionaryBatch[] | null; | ||
records: RecordBatch[] | null; | ||
metadata: Metadata | null; | ||
} | ||
/** | ||
* Parsed Arrow message data. | ||
*/ | ||
export interface Message { | ||
/** The Arrow version. */ | ||
version: Version_; | ||
/** The message header type. */ | ||
type: MessageHeader_; | ||
/** The buffer integer index after the message. */ | ||
index: number; | ||
/** The message content. */ | ||
content?: Schema | RecordBatch | DictionaryBatch; | ||
} | ||
/** | ||
* Options for controlling how values are transformed when extracted | ||
* from am Arrow binary representation. | ||
*/ | ||
export interface ExtractionOptions { | ||
/** | ||
* If true, extract dates and timestamps as JavaScript `Date` objects. | ||
* Otherwise, return numerical timestamp values (default). | ||
*/ | ||
useDate?: boolean; | ||
/** | ||
* If true, extract 64-bit integers as JavaScript `BigInt` values. | ||
* Otherwise, coerce long integers to JavaScript number values (default). | ||
*/ | ||
useBigInt?: boolean; | ||
/** | ||
* If true, extract Arrow 'Map' values as JavaScript `Map` instances. | ||
* Otherwise, return an array of [key, value] pairs compatible with | ||
* both `Map` and `Object.fromEntries` (default). | ||
*/ | ||
useMap?: boolean; | ||
} |
@@ -61,5 +61,5 @@ /** | ||
* Return an object mapping column names to extracted value arrays. | ||
* @returns {Record<string, import('./types.js').ColumnArray<any>>} | ||
* @returns {Record<string, import('./types.js').ValueArray<any>>} | ||
*/ | ||
toColumns(): Record<string, import("./types.js").ColumnArray<any>>; | ||
toColumns(): Record<string, import("./types.js").ValueArray<any>>; | ||
/** | ||
@@ -70,2 +70,11 @@ * Return an array of objects representing the rows of this table. | ||
toArray(): Record<string, any>[]; | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag](): string; | ||
/** | ||
* Return an iterator over objects representing the rows of this table. | ||
* @returns {Generator<Record<string, any>, any, null>} | ||
*/ | ||
[Symbol.iterator](): Generator<Record<string, any>, any, null>; | ||
} |
@@ -1,83 +0,21 @@ | ||
/** Arrow version. */ | ||
export declare enum Version { | ||
V1 = 0, | ||
V2 = 1, | ||
V3 = 2, | ||
V4 = 3, | ||
V5 = 4 | ||
} | ||
/** Endianness of Arrow-encoded data. */ | ||
export declare enum Endianness { | ||
Little = 0, | ||
Big = 1 | ||
} | ||
/** Message header type codes. */ | ||
export declare enum MessageHeader { | ||
NONE = 0, | ||
Schema = 1, | ||
DictionaryBatch = 2, | ||
RecordBatch = 3, | ||
Tensor = 4, | ||
SparseTensor = 5 | ||
} | ||
/** Floating point number precision. */ | ||
export declare enum Precision { | ||
HALF = 0, | ||
SINGLE = 1, | ||
DOUBLE = 2 | ||
} | ||
/** Date units. */ | ||
export declare enum DateUnit { | ||
DAY = 0, | ||
MILLISECOND = 1 | ||
} | ||
/** Time units. */ | ||
export declare enum TimeUnit { | ||
SECOND = 0, | ||
MILLISECOND = 1, | ||
MICROSECOND = 2, | ||
NANOSECOND = 3 | ||
} | ||
/** Date/time interval units. */ | ||
export declare enum IntervalUnit { | ||
YEAR_MONTH = 0, | ||
DAY_TIME = 1, | ||
MONTH_DAY_NANO = 2 | ||
} | ||
/** Union type modes. */ | ||
export declare enum UnionMode { | ||
Sparse = 0, | ||
Dense = 1 | ||
} | ||
/** Field data type ids. */ | ||
export declare enum TypeId { | ||
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 | ||
} | ||
import { Version, Endianness, MessageHeader, Precision, DateUnit, TimeUnit, IntervalUnit, UnionMode } from './constants.js'; | ||
export { Batch } from './batch.js'; | ||
export { Column } from './column.js'; | ||
export { Table } from './table.js'; | ||
/** A valid Arrow version number. */ | ||
export type Version_ = typeof Version[keyof typeof Version]; | ||
/** A valid endianness value. */ | ||
export type Endianness_ = typeof Endianness[keyof typeof Endianness]; | ||
/** A valid message header type value. */ | ||
export type MessageHeader_ = typeof MessageHeader[keyof typeof MessageHeader]; | ||
/** A valid floating point precision value. */ | ||
export type Precision_ = typeof Precision[keyof typeof Precision]; | ||
/** A valid date unit value. */ | ||
export type DateUnit_ = typeof DateUnit[keyof typeof DateUnit]; | ||
/** A valid time unit value. */ | ||
export type TimeUnit_ = typeof TimeUnit[keyof typeof TimeUnit]; | ||
/** A valid date/time interval unit value. */ | ||
export type IntervalUnit_ = typeof IntervalUnit[keyof typeof IntervalUnit]; | ||
/** A valid union type mode value. */ | ||
export type UnionMode_ = typeof UnionMode[keyof typeof UnionMode]; | ||
export type TypedArray = Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; | ||
@@ -90,3 +28,5 @@ export type OffsetArray = Int32Array | BigInt64Array; | ||
/** An extracted array of column values. */ | ||
export type ColumnArray<T> = T[] | TypedArray; | ||
export interface ValueArray<T> extends ArrayLike<T>, Iterable<T> { | ||
slice(start?: number, end?: number): ValueArray<T>; | ||
} | ||
/** Custom metadata. */ | ||
@@ -98,4 +38,4 @@ export type Metadata = Map<string, string>; | ||
export interface Schema { | ||
version: Version; | ||
endianness: Endianness; | ||
version: Version_; | ||
endianness: Endianness_; | ||
fields: Field[]; | ||
@@ -114,14 +54,24 @@ metadata?: Metadata | null; | ||
} | ||
/** Valid integer bit widths. */ | ||
export type IntBitWidth = 8 | 16 | 32 | 64; | ||
/** Dictionary-encoded data type. */ | ||
export type DictionaryType = { | ||
typeId: -1; | ||
type: DataType; | ||
id: number; | ||
keys: IntType; | ||
ordered: boolean; | ||
}; | ||
/** None data type. */ | ||
export type NoneType = { | ||
typeId: TypeId.NONE; | ||
typeId: 0; | ||
}; | ||
/** Null data type. */ | ||
export type NullType = { | ||
typeId: TypeId.Null; | ||
typeId: 1; | ||
}; | ||
/** Integer data type. */ | ||
export type IntType = { | ||
typeId: TypeId.Int; | ||
bitWidth: 8 | 16 | 32 | 64; | ||
typeId: 2; | ||
bitWidth: IntBitWidth; | ||
signed: boolean; | ||
@@ -132,4 +82,4 @@ values: IntArrayConstructor; | ||
export type FloatType = { | ||
typeId: TypeId.Float; | ||
precision: Precision; | ||
typeId: 3; | ||
precision: Precision_; | ||
values: FloatArrayConstructor; | ||
@@ -139,3 +89,3 @@ }; | ||
export type BinaryType = { | ||
typeId: TypeId.Binary; | ||
typeId: 4; | ||
offsets: Int32ArrayConstructor; | ||
@@ -145,3 +95,3 @@ }; | ||
export type Utf8Type = { | ||
typeId: TypeId.Utf8; | ||
typeId: 5; | ||
offsets: Int32ArrayConstructor; | ||
@@ -151,7 +101,7 @@ }; | ||
export type BoolType = { | ||
typeId: TypeId.Bool; | ||
typeId: 6; | ||
}; | ||
/** Fixed decimal number data type. */ | ||
export type DecimalType = { | ||
typeId: TypeId.Decimal; | ||
typeId: 7; | ||
precision: number; | ||
@@ -164,4 +114,4 @@ scale: number; | ||
export type DateType = { | ||
typeId: TypeId.Date; | ||
unit: DateUnit; | ||
typeId: 8; | ||
unit: DateUnit_; | ||
values: DateTimeArrayConstructor; | ||
@@ -171,6 +121,5 @@ }; | ||
export type TimeType = { | ||
typeId: TypeId.Time; | ||
unit: TimeUnit; | ||
typeId: 9; | ||
unit: TimeUnit_; | ||
bitWidth: 32 | 64; | ||
signed: boolean; | ||
values: DateTimeArrayConstructor; | ||
@@ -180,4 +129,4 @@ }; | ||
export type TimestampType = { | ||
typeId: TypeId.Timestamp; | ||
unit: TimeUnit; | ||
typeId: 10; | ||
unit: TimeUnit_; | ||
timezone: string | null; | ||
@@ -188,9 +137,10 @@ values: BigInt64ArrayConstructor; | ||
export type IntervalType = { | ||
typeId: TypeId.Interval; | ||
unit: IntervalUnit; | ||
typeId: 11; | ||
unit: IntervalUnit_; | ||
values?: Int32ArrayConstructor; | ||
}; | ||
/** List data type. */ | ||
export type ListType = { | ||
typeId: TypeId.List; | ||
children: [DataType]; | ||
typeId: 12; | ||
children: [Field]; | ||
offsets: Int32ArrayConstructor; | ||
@@ -200,11 +150,11 @@ }; | ||
export type StructType = { | ||
typeId: TypeId.Struct; | ||
children: DataType[]; | ||
typeId: 13; | ||
children: Field[]; | ||
}; | ||
/** Union data type. */ | ||
export type UnionType = { | ||
typeId: TypeId.Union; | ||
mode: UnionMode; | ||
typeId: 14; | ||
mode: UnionMode_; | ||
typeIds: Int32Array; | ||
children: DataType[]; | ||
children: Field[]; | ||
offsets: Int32ArrayConstructor; | ||
@@ -214,3 +164,3 @@ }; | ||
export type FixedSizeBinaryType = { | ||
typeId: TypeId.FixedSizeBinary; | ||
typeId: 15; | ||
stride: number; | ||
@@ -220,11 +170,11 @@ }; | ||
export type FixedSizeListType = { | ||
typeId: TypeId.FixedSizeList; | ||
typeId: 16; | ||
stride: number; | ||
children: DataType[]; | ||
children: Field[]; | ||
}; | ||
/** Key-value map data type. */ | ||
export type MapType = { | ||
typeId: TypeId.Map; | ||
typeId: 17; | ||
keysSorted: boolean; | ||
children: [DataType, DataType]; | ||
children: [Field, Field]; | ||
offsets: Int32ArrayConstructor; | ||
@@ -234,4 +184,4 @@ }; | ||
export type DurationType = { | ||
typeId: TypeId.Duration; | ||
unit: TimeUnit; | ||
typeId: 18; | ||
unit: TimeUnit_; | ||
values: BigInt64ArrayConstructor; | ||
@@ -241,3 +191,3 @@ }; | ||
export type LargeBinaryType = { | ||
typeId: TypeId.LargeBinary; | ||
typeId: 19; | ||
offsets: BigInt64ArrayConstructor; | ||
@@ -247,3 +197,3 @@ }; | ||
export type LargeUtf8Type = { | ||
typeId: TypeId.LargeUtf8; | ||
typeId: 20; | ||
offsets: BigInt64ArrayConstructor; | ||
@@ -253,14 +203,6 @@ }; | ||
export type LargeListType = { | ||
typeId: TypeId.LargeList; | ||
children: [DataType]; | ||
typeId: 21; | ||
children: [Field]; | ||
offsets: BigInt64ArrayConstructor; | ||
}; | ||
/** Dictionary-encoded data type. */ | ||
export type DictionaryType = { | ||
typeId: TypeId.Dictionary; | ||
type: DataType; | ||
id: number; | ||
keys: IntType; | ||
ordered: boolean; | ||
}; | ||
/** | ||
@@ -308,5 +250,5 @@ * Arrow field data types. | ||
/** The Arrow version. */ | ||
version: number; | ||
version: Version_; | ||
/** The message header type. */ | ||
type: number; | ||
type: MessageHeader_; | ||
/** The buffer integer index after the message. */ | ||
@@ -313,0 +255,0 @@ index: number; |
@@ -22,8 +22,8 @@ /** | ||
/** | ||
* Ensure a numerical value (number of BigInt) is a number. Throws an error | ||
* if a BigInt value is outside the range of what a number can represent. | ||
* @param {number | bigint} value The value to check and possibly convert. | ||
* @returns {number} | ||
* Coerce a bigint value to a number. Throws an error if the bigint value | ||
* lies outside the range of what a number can precisely represent. | ||
* @param {bigint} value The value to check and possibly convert. | ||
* @returns {number} The converted number value. | ||
*/ | ||
export function toNumber(value: number | bigint): number; | ||
export function toNumber(value: bigint): number; | ||
/** | ||
@@ -132,2 +132,1 @@ * Divide one BigInt value by another, and return the result as a number. | ||
export const SIZEOF_INT: 4; | ||
export const $iterator: symbol; |
{ | ||
"name": "@uwdata/flechette", | ||
"version": "0.0.1", | ||
"description": "Fast and lightweight access to Apache Arrow data.", | ||
"version": "0.0.2", | ||
"description": "Fast, lightweight access to Apache Arrow data.", | ||
"keywords": [ | ||
@@ -26,4 +26,5 @@ "arrow", | ||
"build": "node esbuild.js flechette", | ||
"build:types": "tsc --project tsconfig.json", | ||
"postbuild": "npm run build:types", | ||
"types": "tsc --project tsconfig.json && npm run types:merge", | ||
"types:merge": "cd dist/types; cat types.d.ts >> index.d.ts", | ||
"postbuild": "npm run types", | ||
"lint": "eslint src test", | ||
@@ -30,0 +31,0 @@ "test": "mocha 'test/**/*-test.js'", |
# Flechette | ||
**Flechette** is a JavaScript library for reading [Apache Arrow](https://arrow.apache.org/) data. It provides a faster, lighter, zero-dependency alternative to the Apache Arrow [JavaScript reference implementation](https://github.com/apache/arrow/tree/main/js). | ||
**Flechette** is a JavaScript library for reading the [Apache Arrow](https://arrow.apache.org/) columnar in-memory data format. It provides a faster, lighter, zero-dependency alternative to the [Arrow JS reference implementation](https://github.com/apache/arrow/tree/main/js). | ||
Flechette provides fast extraction of data in the Arrow binary IPC format, supporting ingestion of Arrow data (from sources such as [DuckDB](https://duckdb.org/)) for downstream use in JavaScript data analysis tools like [Arquero](https://github.com/uwdata/arquero), [Mosaic](https://github.com/uwdata/mosaic), [Observable Plot](https://observablehq.com/plot/), and [Vega-Lite](https://vega.github.io/vega-lite/). | ||
Flechette performs fast extraction of data columns in the Arrow binary IPC format, supporting ingestion of Arrow data (from sources such as [DuckDB](https://duckdb.org/)) for downstream use in JavaScript data analysis tools like [Arquero](https://github.com/uwdata/arquero), [Mosaic](https://github.com/uwdata/mosaic), [Observable Plot](https://observablehq.com/plot/), and [Vega-Lite](https://vega.github.io/vega-lite/). | ||
## Why Flechette? | ||
In the process of developing multiple data analysis packages that consume Apache Arrow data (including Arquero, Mosaic, and Vega), we had to develop workarounds for the performance and correctness of the Apache Arrow JavaScript reference implementation. Instead of workarounds, Flechette seeks to address these issues head-on. | ||
In the process of developing multiple data analysis packages that consume Arrow data (including Arquero, Mosaic, and Vega), we've had to develop workarounds for the performance and correctness of the Arrow JavaScript reference implementation. Instead of workarounds, Flechette addresses these issues head-on. | ||
* _Speed_. Flechette provides faster decoding. Across varied datasets, our initial performance tests find that Flechette provides 1.3-1.6x faster value iteration, 2-7x faster array extraction, and 5-9x faster row object extraction. | ||
* _Speed_. Flechette provides faster decoding. Across varied datasets, initial performance tests show 1.3-1.6x faster value iteration, 2-7x faster array extraction, and 5-9x faster row object extraction. | ||
* _Size_. Flechette is ~16k minified (~6k gzip'd), versus 163k minified (~43k gzip'd) for Arrow JS. | ||
* _Coverage_. At the time of writing, Flechette supports multiple data types unsupported by the reference implementation, including decimal-to-number conversion and support for month/day/nanosecond time intervals (as used, for example, by DuckDB). | ||
* _Coverage_. Flechette supports multiple data types unsupported by the reference implementation at the time of writing, including decimal-to-number conversion and support for month/day/nanosecond time intervals (as used, for example, by DuckDB). | ||
@@ -21,7 +21,7 @@ * _Flexibility_. Flechette includes options to control data value conversion, such as numerical timestamps vs. Date objects for temporal data, and numbers vs. bigint values for 64-bit integer data. | ||
That said, no tool is without limitations or trade-offs. Flechette is *consumption oriented*: it assumes Arrow data is generated elsewhere and then needs to be transformed and/or visualized in JavaScript. It does yet support encoding, though please [upvote encoding support](https://github.com/uwdata/flechette/issues/1) if you would use it. In addition, Flechette requires simpler inputs (byte buffers, no promises or streams), currently has less comprehensive TypeScript typings, and can have a slightly slower initial parse (as Flechette decodes dictionary-encoded data upfront for faster downstream access). | ||
That said, no tool is without limitations or trade-offs. Flechette is *consumption oriented*: it does yet support encoding (though feel free to [upvote encoding support](https://github.com/uwdata/flechette/issues/1)!). Flechette also requires simpler inputs (byte buffers, no promises or streams), has less strict TypeScript typings, and at times has a slightly slower initial parse (as it decodes dictionary data upfront for faster downstream access). | ||
## What's with the name? | ||
The project name stems from the French word [fléchette](https://en.wikipedia.org/wiki/Flechette), which means a "little arrow" or "dart". 🎯 | ||
The project name stems from the French word [fléchette](https://en.wikipedia.org/wiki/Flechette), which means "little arrow" or "dart". 🎯 | ||
@@ -68,2 +68,6 @@ ## Examples | ||
const objects = table.toArray(); | ||
// create a new table with a selected subset of columns | ||
// use this first to limit toColumns or toArray to fewer columns | ||
const subtable = table.select(['delay', 'time']); | ||
``` | ||
@@ -70,0 +74,0 @@ |
158
src/batch.js
import { float64 } from './array-types.js'; | ||
import { $iterator, decodeBit, decodeUtf8, divide, readInt32, readInt64AsNum, toNumber } from './util.js'; | ||
import { decodeBit, decodeUtf8, divide, readInt32, readInt64AsNum, toNumber } from './util.js'; | ||
@@ -57,2 +57,9 @@ /** | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag]() { | ||
return 'Batch'; | ||
} | ||
/** | ||
* Return the value at the given index. | ||
@@ -83,4 +90,3 @@ * @param {number} index The value index. | ||
value(index) { | ||
// @ts-ignore | ||
return this.values[index]; | ||
return /** @type {T} */ (this.values[index]); | ||
} | ||
@@ -92,3 +98,3 @@ | ||
* @param {number} end The ending index, exclusive | ||
* @returns {T[] | import('./types.js').TypedArray} The slice of values | ||
* @returns {import('./types.js').ValueArray<T?>} The slice of values | ||
*/ | ||
@@ -106,5 +112,5 @@ slice(start, end) { | ||
* Return an iterator over the values in this batch. | ||
* @returns {Generator<T, any, null>} | ||
* @returns {Iterator<T?>} | ||
*/ | ||
*[$iterator]() { | ||
*[Symbol.iterator]() { | ||
const { length } = this; | ||
@@ -128,5 +134,6 @@ for (let i = 0; i < length; ++i) { | ||
* @param {number} end The ending index, exclusive | ||
* @returns {T[] | import('./types.js').TypedArray} The slice of values | ||
* @returns {import('./types.js').ValueArray<T?>} The slice of values | ||
*/ | ||
slice(start, end) { | ||
// @ts-ignore | ||
return this.nullCount | ||
@@ -137,4 +144,10 @@ ? super.slice(start, end) | ||
[$iterator]() { | ||
return this.nullCount ? super[$iterator]() : this.values[$iterator](); | ||
/** | ||
* Return an iterator over the values in this batch. | ||
* @returns {Iterator<T?>} | ||
*/ | ||
[Symbol.iterator]() { | ||
return this.nullCount | ||
? super[Symbol.iterator]() | ||
: /** @type {Iterator<T?>} */ (this.values[Symbol.iterator]()); | ||
} | ||
@@ -183,3 +196,3 @@ } | ||
value(index) { | ||
return toNumber(this.values[index]); | ||
return toNumber(/** @type {bigint} */ (this.values[index])); | ||
} | ||
@@ -197,5 +210,3 @@ } | ||
value(index) { | ||
/** @type {number} */ | ||
// @ts-ignore | ||
const v = this.values[index]; | ||
const v = /** @type {number} */ (this.values[index]); | ||
const expo = (v & 0x7C00) >> 10; | ||
@@ -221,4 +232,3 @@ const sigf = (v & 0x03FF) / 1024; | ||
value(index) { | ||
// @ts-ignore | ||
return decodeBit(this.values, index); | ||
return decodeBit(/** @type {Uint8Array} */ (this.values), index); | ||
} | ||
@@ -242,7 +252,7 @@ } | ||
super(options); | ||
// @ts-ignore | ||
const { bitWidth, scale } = this.type; | ||
this.stride = bitWidth >> 5; // 8 bits/byte and 4 bytes/uint32; | ||
this.scale = Math.pow(10, scale); | ||
const type = /** @type {import('./types.js').DecimalType} */ (this.type); | ||
this.stride = type.bitWidth >> 5; // 8 bits/byte and 4 bytes/uint32; | ||
this.scale = Math.pow(10, type.scale); | ||
} | ||
/** | ||
@@ -254,9 +264,8 @@ * @param {number} index The value index | ||
// Using numbers we can prep with integers up to MAX_SAFE_INTEGER (2^53 - 1) | ||
const { values: v, stride: n, scale: s } = this; | ||
const v = /** @type {Uint32Array} */ (this.values); | ||
const n = this.stride; | ||
const off = index << 2; | ||
let x = 0; | ||
// @ts-ignore | ||
if ((v[n - 1] | 0) < 0) { | ||
for (let i = 0; i < n; ++i) { | ||
// @ts-ignore | ||
x += ~v[i + off] * BASE32[i]; | ||
@@ -267,7 +276,6 @@ } | ||
for (let i = 0; i < n; ++i) { | ||
// @ts-ignore | ||
x += v[i + off] * BASE32[i]; | ||
} | ||
} | ||
return x / s; | ||
return x / this.scale; | ||
} | ||
@@ -287,2 +295,3 @@ } | ||
} | ||
/** | ||
@@ -305,4 +314,4 @@ * @param {number} index The value index | ||
value(index) { | ||
// @ts-ignore | ||
return 86400000 * this.values[index]; // epoch days to milliseconds | ||
// epoch days to milliseconds | ||
return 86400000 * /** @type {number} */ (this.values[index]); | ||
} | ||
@@ -341,4 +350,4 @@ } | ||
value(index) { | ||
// @ts-ignore | ||
return divide(this.values[index], 1000n); // microseconds to milliseconds | ||
// microseconds to milliseconds | ||
return divide(/** @type {bigint} */ (this.values[index]), 1000n); | ||
} | ||
@@ -355,4 +364,4 @@ } | ||
value(index) { | ||
// @ts-ignore | ||
return divide(this.values[index], 1000000n); // nanoseconds to milliseconds | ||
// nanoseconds to milliseconds | ||
return divide(/** @type {bigint} */ (this.values[index]), 1000000n); | ||
} | ||
@@ -371,4 +380,4 @@ } | ||
value(index) { | ||
// @ts-ignore | ||
return this.values.subarray(index << 1, (index + 1) << 1); | ||
const values = /** @type {Int32Array} */ (this.values); | ||
return values.subarray(index << 1, (index + 1) << 1); | ||
} | ||
@@ -386,5 +395,3 @@ } | ||
value(index) { | ||
/** @type {number} */ | ||
// @ts-ignore | ||
const v = this.values[index]; | ||
const v = /** @type {number} */ (this.values[index]); | ||
return Int32Array.of( | ||
@@ -406,5 +413,3 @@ Math.trunc(v / 12), // years | ||
value(index) { | ||
/** @type {Uint8Array} */ | ||
// @ts-ignore | ||
const values = this.values; | ||
const values = /** @type {Uint8Array} */ (this.values); | ||
const base = index << 2; | ||
@@ -484,3 +489,3 @@ return Float64Array.of( | ||
* @template V | ||
* @extends {ArrayBatch<import('./types.js').ColumnArray<V>>} | ||
* @extends {ArrayBatch<import('./types.js').ValueArray<V>>} | ||
*/ | ||
@@ -490,8 +495,7 @@ export class ListBatch extends ArrayBatch { | ||
* @param {number} index | ||
* @returns {import('./types.js').ColumnArray<V>} | ||
* @returns {import('./types.js').ValueArray<V>} | ||
*/ | ||
value(index) { | ||
const { offsets, children } = this; | ||
// @ts-ignore | ||
return children[0].slice(offsets[index], offsets[index + 1]); | ||
const offsets = /** @type {Int32Array} */ (this.offsets); | ||
return this.children[0].slice(offsets[index], offsets[index + 1]); | ||
} | ||
@@ -505,3 +509,3 @@ } | ||
* @template V | ||
* @extends {ArrayBatch<import('./types.js').ColumnArray<V>>} | ||
* @extends {ArrayBatch<import('./types.js').ValueArray<V>>} | ||
*/ | ||
@@ -511,7 +515,7 @@ export class LargeListBatch extends ArrayBatch { | ||
* @param {number} index | ||
* @returns {import('./types.js').ColumnArray<V>} | ||
* @returns {import('./types.js').ValueArray<V>} | ||
*/ | ||
value(index) { | ||
const { offsets, children } = this; | ||
return children[0].slice(toNumber(offsets[index]), toNumber(offsets[index + 1])); | ||
const offsets = /** @type {BigInt64Array} */ (this.offsets); | ||
return this.children[0].slice(toNumber(offsets[index]), toNumber(offsets[index + 1])); | ||
} | ||
@@ -531,6 +535,5 @@ } | ||
value(index) { | ||
// @ts-ignore | ||
const { stride } = this.type; | ||
// @ts-ignore | ||
return this.values.subarray(index * stride, (index + 1) * stride); | ||
const { stride } = /** @type {import('./types.js').FixedSizeBinaryType} */ (this.type); | ||
const values = /** @type {Uint8Array} */ (this.values); | ||
return values.subarray(index * stride, (index + 1) * stride); | ||
} | ||
@@ -542,3 +545,3 @@ } | ||
* @template V | ||
* @extends {ArrayBatch<import('./types.js').ColumnArray<V>>} | ||
* @extends {ArrayBatch<import('./types.js').ValueArray<V>>} | ||
*/ | ||
@@ -548,8 +551,7 @@ export class FixedListBatch extends ArrayBatch { | ||
* @param {number} index | ||
* @returns {import('./types.js').ColumnArray<V>} | ||
* @returns {import('./types.js').ValueArray<V>} | ||
*/ | ||
value(index) { | ||
const { type, children } = this; | ||
// @ts-ignore | ||
const { stride } = type; | ||
const { stride } = /** @type {import('./types.js').FixedSizeListType} */ (type); | ||
return children[0].slice(index * stride, (index + 1) * stride); | ||
@@ -559,4 +561,6 @@ } | ||
// extract Map key-value pairs from parallel child batches | ||
const pairs = ({ children, offsets }, index) => { | ||
/** | ||
* Extract Map key-value pairs from parallel child batches. | ||
*/ | ||
function pairs({ children, offsets }, index) { | ||
const [ keys, vals ] = children[0].children; | ||
@@ -567,6 +571,4 @@ const start = offsets[index]; | ||
for (let i = start; i < end; ++i) { | ||
// @ts-ignore | ||
entries.push([keys.at(i), vals.at(i)]); | ||
} | ||
// @ts-ignore | ||
return entries; | ||
@@ -588,4 +590,3 @@ } | ||
value(index) { | ||
// @ts-ignore | ||
return pairs(this, index); | ||
return /** @type {[K, V][]} */ (pairs(this, index)); | ||
} | ||
@@ -607,4 +608,3 @@ } | ||
value(index) { | ||
// @ts-ignore | ||
return new Map(pairs(this, index)); | ||
return new Map(/** @type {[K, V][]} */ (pairs(this, index))); | ||
} | ||
@@ -626,2 +626,3 @@ } | ||
} | ||
/** | ||
@@ -647,4 +648,3 @@ * @param {number} index The value index. | ||
value(index) { | ||
// @ts-ignore | ||
return super.value(this.offsets[index]); | ||
return super.value(/** @type {number} */ (this.offsets[index])); | ||
} | ||
@@ -661,6 +661,6 @@ } | ||
super(options); | ||
/** @type {string} */ | ||
// @ts-ignore | ||
this.names = this.type.children.map(child => child.name); | ||
const type = /** @type {import('./types.js').StructType} */ (this.type); | ||
this.names = type.children.map(child => child.name); | ||
} | ||
/** | ||
@@ -687,8 +687,16 @@ * @param {number} index The value index. | ||
export class DictionaryBatch extends ArrayBatch { | ||
/** | ||
* Create a new dictionary batch. | ||
* @param {object} options Batch options. | ||
* @param {import('./types.js').DataType} options.type The field data type | ||
* @param {number} options.length The length of the batch | ||
* @param {number} options.nullCount The null value count | ||
* @param {Uint8Array} [options.validity] Validity bitmap buffer | ||
* @param {import('./types.js').TypedArray} [options.values] Values buffer | ||
* @param {import('./column.js').Column<T>} options.dictionary | ||
* The dictionary of column values. | ||
*/ | ||
constructor(options) { | ||
super(options); | ||
// extract and cache dictionary data (if not already done) | ||
const { dictionary: d } = options; | ||
/** @type {import('./types.js').ColumnArray<T>} */ | ||
this.cache = d.cache ?? (d.cache = d.toArray()); | ||
this.cache = options.dictionary.cache(); | ||
} | ||
@@ -699,4 +707,3 @@ /** | ||
value(index) { | ||
// @ts-ignore | ||
return this.cache[this.values[index]]; | ||
return this.cache[this.key(index)]; | ||
} | ||
@@ -708,5 +715,4 @@ /** | ||
key(index) { | ||
// @ts-ignore | ||
return this.values[index]; | ||
return /** @type {number} */ (this.values[index]); | ||
} | ||
} |
import { DirectBatch } from './batch.js'; | ||
import { $iterator } from './util.js'; | ||
@@ -82,9 +81,16 @@ /** | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag]() { | ||
return 'Column'; | ||
} | ||
/** | ||
* Return an iterator over the values in this column. | ||
* @returns {Generator<T>} | ||
* @returns {Iterator<T?>} | ||
*/ | ||
[$iterator]() { | ||
[Symbol.iterator]() { | ||
const data = this.data; | ||
return data.length === 1 | ||
? data[0][$iterator]() | ||
? data[0][Symbol.iterator]() | ||
: batchedIterator(data); | ||
@@ -124,3 +130,3 @@ } | ||
* a zero-copy subarray of the input Arrow data is returned. | ||
* @returns {import('./types.js').ColumnArray<T>} | ||
* @returns {import('./types.js').ValueArray<T?>} | ||
*/ | ||
@@ -133,2 +139,3 @@ toArray() { | ||
// use batch array directly | ||
// @ts-ignore | ||
return data[0].values; | ||
@@ -141,6 +148,14 @@ } | ||
: (data[0].constructor.ArrayType ?? data[0].values.constructor); | ||
const array = new ArrayType(length); | ||
return copy ? copyArray(array, data) : extractArray(array, data); | ||
} | ||
/** | ||
* Return an array of cached column values. | ||
* Used internally to accelerate dictionary types. | ||
*/ | ||
cache() { | ||
return this._cache ?? (this._cache = this.toArray()); | ||
} | ||
} | ||
@@ -147,0 +162,0 @@ |
@@ -1,2 +0,5 @@ | ||
export const Version = { | ||
/** | ||
* Apache Arrow version. | ||
*/ | ||
export const Version = /** @type {const} */ ({ | ||
/** 0.1.0 (October 2016). */ | ||
@@ -16,8 +19,20 @@ V1: 0, | ||
* Incompatible changes between V4 and V5: | ||
* - Union buffer layout has changed. In V5, Unions don't have a validity bitmap buffer. | ||
* - Union buffer layout has changed. | ||
* In V5, Unions don't have a validity bitmap buffer. | ||
*/ | ||
V5: 4 | ||
}; | ||
}); | ||
export const MessageHeader = { | ||
/** | ||
* Endianness of Arrow-encoded data. | ||
*/ | ||
export const Endianness = /** @type {const} */ ({ | ||
Little: 0, | ||
Big: 1 | ||
}); | ||
/** | ||
* Message header type codes. | ||
*/ | ||
export const MessageHeader = /** @type {const} */ ({ | ||
NONE: 0, | ||
@@ -59,9 +74,9 @@ /** | ||
SparseTensor: 5 | ||
}; | ||
}); | ||
/** | ||
* Top-level data type values, enabling extensible type-specific metadata. | ||
* Field data type ids. | ||
* Only non-negative values ever occur in IPC flatbuffer binary data. | ||
*/ | ||
export const Type = { | ||
export const Type = /** @type {const} */ ({ | ||
/** | ||
@@ -227,4 +242,2 @@ * Dictionary types compress data by using a set of integer indices to | ||
* extremely large data values. | ||
* | ||
* Not currently supported by Flechette. | ||
*/ | ||
@@ -280,21 +293,33 @@ LargeList: 21, | ||
LargeListView: 26 | ||
} | ||
}); | ||
export const Precision = { | ||
/** | ||
* Floating point number precision. | ||
*/ | ||
export const Precision = /** @type {const} */ ({ | ||
/** 16-bit floating point number. */ | ||
HALF: 0, | ||
/** 32-bit floating point number. */ | ||
SINGLE: 1, | ||
/** 64-bit floating point number. */ | ||
DOUBLE: 2 | ||
}; | ||
}); | ||
export const DateUnit = { | ||
/* Days (32 bits) since the UNIX epoch. */ | ||
/** | ||
* Date units. | ||
*/ | ||
export const DateUnit = /** @type {const} */ ({ | ||
/* Days (as 32 bit int) since the UNIX epoch. */ | ||
DAY: 0, | ||
/** | ||
* Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no | ||
* leap seconds), where the values are evenly divisible by 86400000. | ||
* Milliseconds (as 64 bit int) indicating UNIX time elapsed since the epoch | ||
* (no leap seconds), with values evenly divisible by 86400000. | ||
*/ | ||
MILLISECOND: 1 | ||
}; | ||
}); | ||
export const TimeUnit = { | ||
/** | ||
* Time units. | ||
*/ | ||
export const TimeUnit = /** @type {const} */ ({ | ||
/** Seconds. */ | ||
@@ -308,5 +333,8 @@ SECOND: 0, | ||
NANOSECOND: 3 | ||
}; | ||
}); | ||
export const IntervalUnit = { | ||
/** | ||
* Date/time interval units. | ||
*/ | ||
export const IntervalUnit = /** @type {const} */ ({ | ||
/** | ||
@@ -333,7 +361,12 @@ * Indicates the number of elapsed whole months, stored as 4-byte signed | ||
MONTH_DAY_NANO: 2 | ||
}; | ||
}); | ||
export const UnionMode = { | ||
/** | ||
* Union type modes. | ||
*/ | ||
export const UnionMode = /** @type {const} */ ({ | ||
/** Sparse union layout with full arrays for each sub-type. */ | ||
Sparse: 0, | ||
/** Dense union layout with offsets into value arrays. */ | ||
Dense: 1 | ||
}; | ||
}); |
@@ -62,3 +62,3 @@ import { arrayTypeInt, float32, float64, int32, int64, uint16, uint32 } from '../array-types.js'; | ||
* Construct an integer data type. | ||
* @param {8|16|32|64} bitWidth The integer bit width. | ||
* @param {import('../types.js').IntBitWidth} bitWidth The integer bit width. | ||
* @param {boolean} signed Flag for signed or unsigned integers. | ||
@@ -87,4 +87,4 @@ * @returns {import('../types.js').IntType} The integer data type. | ||
return typeInt( | ||
// @ts-ignore | ||
get(4, readInt32, 0), // bitwidth | ||
/** @type {import('../types.js').IntBitWidth} */ | ||
(get(4, readInt32, 0)), // bitwidth | ||
get(6, readBoolean, false) // signed | ||
@@ -94,6 +94,13 @@ ); | ||
/** | ||
* Decode a float type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').FloatType} | ||
*/ | ||
function decodeFloat(buf, index) { | ||
// 4: precision | ||
const get = table(buf, index); | ||
const precision = get(4, readInt16, Precision.HALF); | ||
const precision = /** @type {typeof Precision[keyof Precision]} */ | ||
(get(4, readInt16, Precision.HALF)); | ||
return { | ||
@@ -104,7 +111,12 @@ typeId: Type.Float, | ||
: precision === Precision.SINGLE ? float32 | ||
: precision === Precision.DOUBLE ? float64 | ||
: null | ||
: float64 | ||
}; | ||
} | ||
/** | ||
* Decode a decimal type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').DecimalType} | ||
*/ | ||
function decodeDecimal(buf, index) { | ||
@@ -115,3 +127,3 @@ // 4: precision | ||
const get = table(buf, index); | ||
const bitWidth = get(8, readInt32, 128); | ||
const bitWidth = /** @type {128 | 256 } */ (get(8, readInt32, 128)); | ||
return { | ||
@@ -126,6 +138,13 @@ typeId: Type.Decimal, | ||
/** | ||
* Decode a date type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').DateType} | ||
*/ | ||
function decodeDate(buf, index) { | ||
// 4: unit | ||
const get = table(buf, index); | ||
const unit = get(4, readInt16, DateUnit.MILLISECOND); | ||
const unit = /** @type {typeof DateUnit[keyof DateUnit]} */ | ||
(get(4, readInt16, DateUnit.MILLISECOND)); | ||
return { | ||
@@ -138,2 +157,8 @@ typeId: Type.Date, | ||
/** | ||
* Decode a time type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').TimeType} | ||
*/ | ||
function decodeTime(buf, index) { | ||
@@ -143,6 +168,7 @@ // 4: unit | ||
const get = table(buf, index); | ||
const bitWidth = get(6, readInt32, 32); | ||
const bitWidth = /** @type {32 | 64 } */ (get(6, readInt32, 32)); | ||
return { | ||
typeId: Type.Time, | ||
unit: get(4, readInt16, TimeUnit.MILLISECOND), | ||
unit: /** @type {typeof TimeUnit[keyof TimeUnit]} */ | ||
(get(4, readInt16, TimeUnit.MILLISECOND)), | ||
bitWidth, | ||
@@ -153,2 +179,8 @@ values: bitWidth === 32 ? int32 : int64 | ||
/** | ||
* Decode a timestamp type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').TimestampType} | ||
*/ | ||
function decodeTimestamp(buf, index) { | ||
@@ -160,3 +192,4 @@ // 4: unit | ||
typeId: Type.Timestamp, | ||
unit: get(4, readInt16, TimeUnit.SECOND), | ||
unit: /** @type {typeof TimeUnit[keyof TimeUnit]} */ | ||
(get(4, readInt16, TimeUnit.SECOND)), | ||
timezone: get(6, readString), | ||
@@ -167,6 +200,13 @@ values: int64 | ||
/** | ||
* Decode an interval type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').IntervalType} | ||
*/ | ||
function decodeInterval(buf, index) { | ||
// 4: unit | ||
const get = table(buf, index); | ||
const unit = get(4, readInt16, IntervalUnit.YEAR_MONTH); | ||
const unit = /** @type {typeof IntervalUnit[keyof IntervalUnit]} */ | ||
(get(4, readInt16, IntervalUnit.YEAR_MONTH)); | ||
return { | ||
@@ -179,2 +219,8 @@ typeId: Type.Interval, | ||
/** | ||
* Decode a duration type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').DurationType} | ||
*/ | ||
function decodeDuration(buf, index) { | ||
@@ -185,3 +231,4 @@ // 4: unit | ||
typeId: Type.Duration, | ||
unit: get(4, readInt16, TimeUnit.MILLISECOND), | ||
unit: /** @type {typeof TimeUnit[keyof TimeUnit]} */ | ||
(get(4, readInt16, TimeUnit.MILLISECOND)), | ||
values: int64 | ||
@@ -191,2 +238,8 @@ }; | ||
/** | ||
* Decode a fixed size binary type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').FixedSizeBinaryType} | ||
*/ | ||
function decodeFixedSizeBinary(buf, index) { | ||
@@ -201,2 +254,8 @@ // 4: size (byteWidth) | ||
/** | ||
* Decode a fixed size list type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').FixedSizeListType} | ||
*/ | ||
function decodeFixedSizeList(buf, index, children) { | ||
@@ -212,2 +271,8 @@ // 4: size (listSize) | ||
/** | ||
* Decode a map type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').MapType} | ||
*/ | ||
function decodeMap(buf, index, children) { | ||
@@ -224,2 +289,8 @@ // 4: keysSorted (bool) | ||
/** | ||
* Decode a union type. | ||
* @param {Uint8Array} buf A byte buffer of binary Arrow IPC data | ||
* @param {number} index The starting index in the byte buffer | ||
* @returns {import('../types.js').UnionType} | ||
*/ | ||
function decodeUnion(buf, index, children) { | ||
@@ -232,3 +303,4 @@ // 4: mode | ||
typeId: Type.Union, | ||
mode: get(4, readInt16, UnionMode.Sparse), | ||
mode: /** @type {typeof UnionMode[keyof UnionMode]} */ | ||
(get(4, readInt16, UnionMode.Sparse)), | ||
typeIds: new int32(buf.buffer, buf.byteOffset + base, length), | ||
@@ -235,0 +307,0 @@ children: children ?? [], |
@@ -8,3 +8,3 @@ import { readBoolean, readInt64AsNum, table } from '../util.js'; | ||
* @param {number} index The starting index in the byte buffer | ||
* @param {import('../types.js').Version} version Arrow version value | ||
* @param {import('../types.js').Version_} version Arrow version value | ||
* @returns {import('../types.js').DictionaryBatch} The dictionary batch | ||
@@ -11,0 +11,0 @@ */ |
@@ -49,4 +49,6 @@ import { MessageHeader, Version } from '../constants.js'; | ||
const get = table(head, 0); | ||
const version = get(4, readInt16, Version.V1); | ||
const type = get(6, readUint8, MessageHeader.NONE); | ||
const version = /** @type {import('../types.js').Version_} */ | ||
(get(4, readInt16, Version.V1)); | ||
const type = /** @type {import('../types.js').MessageHeader_} */ | ||
(get(6, readUint8, MessageHeader.NONE)); | ||
const offset = get(8, readOffset, 0); | ||
@@ -53,0 +55,0 @@ const bodyLength = get(10, readInt64AsNum, 0); |
@@ -8,3 +8,3 @@ import { Version } from '../constants.js'; | ||
* @param {number} index The starting index in the byte buffer | ||
* @param {import('../types.js').Version} version Arrow version value | ||
* @param {import('../types.js').Version_} version Arrow version value | ||
* @returns {import('../types.js').RecordBatch} The record batch | ||
@@ -11,0 +11,0 @@ */ |
@@ -10,3 +10,3 @@ import { Type } from '../constants.js'; | ||
* @param {number} index The starting index in the byte buffer | ||
* @param {import('../types.js').Version} version Arrow version value | ||
* @param {import('../types.js').Version_} version Arrow version value | ||
* @returns {import('../types.js').Schema} The schema | ||
@@ -23,3 +23,4 @@ */ | ||
version, | ||
endianness: get(4, readInt16, 0), | ||
endianness: /** @type {import('../types.js').Endianness_} */ | ||
(get(4, readInt16, 0)), | ||
fields: get(6, (buf, off) => decodeSchemaFields(buf, off, dictionaryTypes), []), | ||
@@ -26,0 +27,0 @@ metadata: get(8, decodeMetadata), |
@@ -1,3 +0,2 @@ | ||
export { Version, Type, Precision, DateUnit, TimeUnit, IntervalUnit, UnionMode } from './constants.js'; | ||
export { Version, Endianness, Type, Precision, DateUnit, TimeUnit, IntervalUnit, UnionMode } from './constants.js'; | ||
export { tableFromIPC } from './table-from-ipc.js'; |
@@ -89,4 +89,5 @@ import { MessageHeader, Version } from './constants.js'; | ||
// @ts-ignore | ||
return { schema, dictionaries, records, metadata: null }; | ||
return /** @type {import('./types.js').ArrowData} */ ( | ||
{ schema, dictionaries, records, metadata: null } | ||
); | ||
} | ||
@@ -113,14 +114,13 @@ | ||
const get = table(data, offset - length); | ||
const version = get(4, readInt16, Version.V1); | ||
const version = /** @type {import('./types.js').Version_} */ | ||
(get(4, readInt16, Version.V1)); | ||
const dicts = get(8, decodeBlocks, []); | ||
const recs = get(10, decodeBlocks, []); | ||
return { | ||
return /** @type {import('./types.js').ArrowData} */ ({ | ||
schema: get(6, (buf, index) => decodeSchema(buf, index, version)), | ||
// @ts-ignore | ||
dictionaries: dicts.map(({ offset }) => decodeMessage(data, offset).content), | ||
// @ts-ignore | ||
records: recs.map(({ offset }) => decodeMessage(data, offset).content), | ||
metadata: get(12, decodeMetadata) | ||
}; | ||
}); | ||
} |
import { int8 } from './array-types.js'; | ||
import { | ||
BinaryBatch, | ||
BoolBatch, DateBatch, DateDayBatch, DateDayMillisecondBatch, DecimalBatch, | ||
DenseUnionBatch, DictionaryBatch, DirectBatch, FixedBatch, FixedListBatch, | ||
Float16Batch, Int64Batch, IntervalDayTimeBatch, IntervalMonthDayNanoBatch, | ||
IntervalYearMonthBatch, LargeBinaryBatch, LargeListBatch, LargeUtf8Batch, | ||
ListBatch, MapBatch, MapEntryBatch, NullBatch, SparseUnionBatch, StructBatch, | ||
TimestampMicrosecondBatch, TimestampMillisecondBatch, TimestampNanosecondBatch, | ||
TimestampSecondBatch, Utf8Batch | ||
BinaryBatch, BoolBatch, DateBatch, DateDayBatch, DateDayMillisecondBatch, | ||
DecimalBatch, DenseUnionBatch, DictionaryBatch, DirectBatch, FixedBatch, | ||
FixedListBatch, Float16Batch, Int64Batch, IntervalDayTimeBatch, | ||
IntervalMonthDayNanoBatch, IntervalYearMonthBatch, LargeBinaryBatch, | ||
LargeListBatch, LargeUtf8Batch, ListBatch, MapBatch, MapEntryBatch, | ||
NullBatch, SparseUnionBatch, StructBatch, TimestampMicrosecondBatch, | ||
TimestampMillisecondBatch, TimestampNanosecondBatch, TimestampSecondBatch, | ||
Utf8Batch | ||
} from './batch.js'; | ||
@@ -60,3 +60,3 @@ import { columnBuilder } from './column.js'; | ||
const type = dictionaryTypes.get(id); | ||
const chunk = visit(type, context({ ...data, body })); | ||
const batch = visit(type, context({ ...data, body })); | ||
if (!dicts.has(id)) { | ||
@@ -66,7 +66,7 @@ if (isDelta) { | ||
} | ||
dicts.set(id, columnBuilder(`${id}`, type).add(chunk)); | ||
dicts.set(id, columnBuilder(`${id}`, type).add(batch)); | ||
} else { | ||
const dict = dicts.get(id); | ||
if (!isDelta) dict.clear(); | ||
dict.add(chunk); | ||
dict.add(batch); | ||
} | ||
@@ -104,3 +104,2 @@ } | ||
length, | ||
debug: () => ({nodeIndex, bufferIndex, nodes, buffers}), | ||
node: () => nodes[++nodeIndex], | ||
@@ -178,4 +177,3 @@ buffer: (ArrayType) => { | ||
: unit === TimeUnit.MICROSECOND ? TimestampMicrosecondBatch | ||
: unit === TimeUnit.NANOSECOND ? TimestampNanosecondBatch | ||
: null); | ||
: TimestampNanosecondBatch); | ||
case Type.Decimal: | ||
@@ -186,4 +184,3 @@ return value(DecimalBatch); | ||
: unit === IntervalUnit.YEAR_MONTH ? IntervalYearMonthBatch | ||
: unit === IntervalUnit.MONTH_DAY_NANO ? IntervalMonthDayNanoBatch | ||
: null); | ||
: IntervalMonthDayNanoBatch); | ||
case Type.FixedSizeBinary: | ||
@@ -190,0 +187,0 @@ return value(FixedBatch); |
@@ -25,2 +25,9 @@ /** | ||
/** | ||
* Provide an informative object string tag. | ||
*/ | ||
get [Symbol.toStringTag]() { | ||
return 'Table'; | ||
} | ||
/** | ||
* The number of columns in this table. | ||
@@ -88,6 +95,7 @@ * @return {number} The number of columns. | ||
* Return an object mapping column names to extracted value arrays. | ||
* @returns {Record<string, import('./types.js').ColumnArray<any>>} | ||
* @returns {Record<string, import('./types.js').ValueArray<any>>} | ||
*/ | ||
toColumns() { | ||
const { children } = this; | ||
/** @type {Record<string, import('./types.js').ValueArray<any>>} */ | ||
const cols = {}; | ||
@@ -97,3 +105,2 @@ for (const c of children) { | ||
} | ||
// @ts-ignore | ||
return cols; | ||
@@ -103,2 +110,21 @@ } | ||
/** | ||
* Return an iterator over objects representing the rows of this table. | ||
* @returns {Generator<Record<string, any>, any, null>} | ||
*/ | ||
*[Symbol.iterator]() { | ||
const { children } = this; | ||
const batches = children[0].data.length; | ||
const names = children.map(c => c.name); | ||
// for each batch... | ||
for (let b = 0; b < batches; ++b) { | ||
const data = children.map(c => c.data[b]); | ||
const rows = data[0].length; | ||
// for each row... | ||
for (let i = 0; i < rows; ++i) { | ||
yield rowObject(names, data, i); | ||
} | ||
} | ||
} | ||
/** | ||
* Return an array of objects representing the rows of this table. | ||
@@ -108,18 +134,13 @@ * @returns {Record<string, any>[]} | ||
toArray() { | ||
const { children, numCols, numRows } = this; | ||
const numBatches = children[0].data.length; | ||
const { children, numRows } = this; | ||
const batches = children[0].data.length; | ||
const names = children.map(c => c.name); | ||
const output = Array(numRows); | ||
// for each batch... | ||
for (let b = 0, row = -1; b < numBatches; ++b) { | ||
for (let b = 0, row = -1; b < batches; ++b) { | ||
const data = children.map(c => c.data[b]); | ||
const batchRows = data[0].length; | ||
const rows = data?.[0].length; | ||
// for each row... | ||
for (let i = 0; i < batchRows; ++i) { | ||
const o = {}; | ||
// for each column... | ||
for (let j = 0; j < numCols; ++j) { | ||
o[names[j]] = data[j].at(i); | ||
} | ||
output[++row] = o; | ||
for (let i = 0; i < rows; ++i) { | ||
output[++row] = rowObject(names, data, i); | ||
} | ||
@@ -130,1 +151,10 @@ } | ||
} | ||
function rowObject(names, data, index) { | ||
const o = {}; | ||
// for each column... | ||
for (let j = 0; j < names.length; ++j) { | ||
o[names[j]] = data[j].at(index); | ||
} | ||
return o; | ||
} |
178
src/types.ts
@@ -1,92 +0,41 @@ | ||
/** Arrow version. */ | ||
export enum Version { | ||
V1 = 0, | ||
V2 = 1, | ||
V3 = 2, | ||
V4 = 3, | ||
V5 = 4 | ||
} | ||
import { | ||
Version, | ||
Endianness, | ||
MessageHeader, | ||
Precision, | ||
DateUnit, | ||
TimeUnit, | ||
IntervalUnit, | ||
UnionMode | ||
} from './constants.js'; | ||
/** Endianness of Arrow-encoded data. */ | ||
export enum Endianness { | ||
Little = 0, | ||
Big = 1 | ||
} | ||
// additional jsdoc types to export | ||
export { Batch } from './batch.js'; | ||
export { Column } from './column.js'; | ||
export { Table } from './table.js'; | ||
/** Message header type codes. */ | ||
export enum MessageHeader { | ||
NONE = 0, | ||
Schema = 1, | ||
DictionaryBatch = 2, | ||
RecordBatch = 3, | ||
Tensor = 4, | ||
SparseTensor = 5 | ||
} | ||
/** A valid Arrow version number. */ | ||
export type Version_ = typeof Version[keyof typeof Version]; | ||
/** Floating point number precision. */ | ||
export enum Precision { | ||
HALF = 0, | ||
SINGLE = 1, | ||
DOUBLE = 2 | ||
}; | ||
/** A valid endianness value. */ | ||
export type Endianness_ = typeof Endianness[keyof typeof Endianness]; | ||
/** Date units. */ | ||
export enum DateUnit { | ||
DAY = 0, | ||
MILLISECOND = 1 | ||
}; | ||
/** A valid message header type value. */ | ||
export type MessageHeader_ = typeof MessageHeader[keyof typeof MessageHeader]; | ||
/** Time units. */ | ||
export enum TimeUnit { | ||
SECOND = 0, | ||
MILLISECOND = 1, | ||
MICROSECOND = 2, | ||
NANOSECOND = 3 | ||
}; | ||
/** A valid floating point precision value. */ | ||
export type Precision_ = typeof Precision[keyof typeof Precision]; | ||
/** Date/time interval units. */ | ||
export enum IntervalUnit { | ||
YEAR_MONTH = 0, | ||
DAY_TIME = 1, | ||
MONTH_DAY_NANO = 2 | ||
}; | ||
/** A valid date unit value. */ | ||
export type DateUnit_ = typeof DateUnit[keyof typeof DateUnit]; | ||
/** Union type modes. */ | ||
export enum UnionMode { | ||
Sparse = 0, | ||
Dense = 1 | ||
}; | ||
/** A valid time unit value. */ | ||
export type TimeUnit_ = typeof TimeUnit[keyof typeof TimeUnit]; | ||
/** Field data type ids. */ | ||
export enum TypeId { | ||
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 valid date/time interval unit value. */ | ||
export type IntervalUnit_ = typeof IntervalUnit[keyof typeof IntervalUnit]; | ||
/** A valid union type mode value. */ | ||
export type UnionMode_ = typeof UnionMode[keyof typeof UnionMode]; | ||
export type TypedArray = | ||
@@ -140,3 +89,5 @@ | Uint8Array | ||
/** An extracted array of column values. */ | ||
export type ColumnArray<T> = T[] | TypedArray; | ||
export interface ValueArray<T> extends ArrayLike<T>, Iterable<T> { | ||
slice(start?: number, end?: number): ValueArray<T>; | ||
} | ||
@@ -150,4 +101,4 @@ /** Custom metadata. */ | ||
export interface Schema { | ||
version: Version; | ||
endianness: Endianness; | ||
version: Version_; | ||
endianness: Endianness_; | ||
fields: Field[]; | ||
@@ -168,71 +119,74 @@ metadata?: Metadata | null; | ||
/** Valid integer bit widths. */ | ||
export type IntBitWidth = 8 | 16 | 32 | 64; | ||
/** Dictionary-encoded data type. */ | ||
export type DictionaryType = { typeId: -1, type: DataType, id: number, keys: IntType, ordered: boolean }; | ||
/** None data type. */ | ||
export type NoneType = { typeId: TypeId.NONE }; | ||
export type NoneType = { typeId: 0 }; | ||
/** Null data type. */ | ||
export type NullType = { typeId: TypeId.Null }; | ||
export type NullType = { typeId: 1 }; | ||
/** Integer data type. */ | ||
export type IntType = { typeId: TypeId.Int, bitWidth: 8 | 16 | 32 | 64, signed: boolean, values: IntArrayConstructor }; | ||
export type IntType = { typeId: 2, bitWidth: IntBitWidth, signed: boolean, values: IntArrayConstructor }; | ||
/** Floating point number data type. */ | ||
export type FloatType = { typeId: TypeId.Float, precision: Precision, values: FloatArrayConstructor }; | ||
export type FloatType = { typeId: 3, precision: Precision_, values: FloatArrayConstructor }; | ||
/** Opaque binary data type. */ | ||
export type BinaryType = { typeId: TypeId.Binary, offsets: Int32ArrayConstructor }; | ||
export type BinaryType = { typeId: 4, offsets: Int32ArrayConstructor }; | ||
/** UTF-8 encoded string data type. */ | ||
export type Utf8Type = { typeId: TypeId.Utf8, offsets: Int32ArrayConstructor }; | ||
export type Utf8Type = { typeId: 5, offsets: Int32ArrayConstructor }; | ||
/** Boolean data type. */ | ||
export type BoolType = { typeId: TypeId.Bool }; | ||
export type BoolType = { typeId: 6 }; | ||
/** Fixed decimal number data type. */ | ||
export type DecimalType = { typeId: TypeId.Decimal, precision: number, scale: number, bitWidth: 128 | 256, values: Uint32ArrayConstructor }; | ||
export type DecimalType = { typeId: 7, precision: number, scale: number, bitWidth: 128 | 256, values: Uint32ArrayConstructor }; | ||
/** Date data type. */ | ||
export type DateType = { typeId: TypeId.Date, unit: DateUnit, values: DateTimeArrayConstructor }; | ||
export type DateType = { typeId: 8, unit: DateUnit_, values: DateTimeArrayConstructor }; | ||
/** Time data type. */ | ||
export type TimeType = { typeId: TypeId.Time, unit: TimeUnit, bitWidth: 32 | 64, signed: boolean, values: DateTimeArrayConstructor }; | ||
export type TimeType = { typeId: 9, unit: TimeUnit_, bitWidth: 32 | 64, values: DateTimeArrayConstructor }; | ||
/** Timestamp data type. */ | ||
export type TimestampType = { typeId: TypeId.Timestamp, unit: TimeUnit, timezone: string | null, values: BigInt64ArrayConstructor }; | ||
export type TimestampType = { typeId: 10, unit: TimeUnit_, timezone: string | null, values: BigInt64ArrayConstructor }; | ||
/** Date/time interval data type. */ | ||
export type IntervalType = { typeId: TypeId.Interval, unit: IntervalUnit }; | ||
export type IntervalType = { typeId: 11, unit: IntervalUnit_, values?: Int32ArrayConstructor }; | ||
/** List data type. */ | ||
export type ListType = { typeId: TypeId.List, children: [DataType], offsets: Int32ArrayConstructor }; | ||
export type ListType = { typeId: 12, children: [Field], offsets: Int32ArrayConstructor }; | ||
/** Struct data type. */ | ||
export type StructType = { typeId: TypeId.Struct, children: DataType[] }; | ||
export type StructType = { typeId: 13, children: Field[] }; | ||
/** Union data type. */ | ||
export type UnionType = { typeId: TypeId.Union, mode: UnionMode, typeIds: Int32Array, children: DataType[], offsets: Int32ArrayConstructor }; | ||
export type UnionType = { typeId: 14, mode: UnionMode_, typeIds: Int32Array, children: Field[], offsets: Int32ArrayConstructor }; | ||
/** Fixed-size opaque binary data type. */ | ||
export type FixedSizeBinaryType = { typeId: TypeId.FixedSizeBinary, stride: number }; | ||
export type FixedSizeBinaryType = { typeId: 15, stride: number }; | ||
/** Fixed-size list data type. */ | ||
export type FixedSizeListType = { typeId: TypeId.FixedSizeList, stride: number, children: DataType[] }; | ||
export type FixedSizeListType = { typeId: 16, stride: number, children: Field[] }; | ||
/** Key-value map data type. */ | ||
export type MapType = { typeId: TypeId.Map, keysSorted: boolean, children: [DataType, DataType], offsets: Int32ArrayConstructor }; | ||
export type MapType = { typeId: 17, keysSorted: boolean, children: [Field, Field], offsets: Int32ArrayConstructor }; | ||
/** Duration data type. */ | ||
export type DurationType = { typeId: TypeId.Duration, unit: TimeUnit, values: BigInt64ArrayConstructor }; | ||
export type DurationType = { typeId: 18, unit: TimeUnit_, values: BigInt64ArrayConstructor }; | ||
/** Opaque binary data type with 64-bit integer offsets for larger data. */ | ||
export type LargeBinaryType = { typeId: TypeId.LargeBinary, offsets: BigInt64ArrayConstructor }; | ||
export type LargeBinaryType = { typeId: 19, offsets: BigInt64ArrayConstructor }; | ||
/** UTF-8 encoded string data type with 64-bit integer offsets for larger data. */ | ||
export type LargeUtf8Type = { typeId: TypeId.LargeUtf8, offsets: BigInt64ArrayConstructor }; | ||
export type LargeUtf8Type = { typeId: 20, offsets: BigInt64ArrayConstructor }; | ||
/** List data type with 64-bit integer offsets for larger data. */ | ||
export type LargeListType = { typeId: TypeId.LargeList, children: [DataType], offsets: BigInt64ArrayConstructor }; | ||
export type LargeListType = { typeId: 21, children: [Field], offsets: BigInt64ArrayConstructor }; | ||
/** Dictionary-encoded data type. */ | ||
export type DictionaryType = { typeId: TypeId.Dictionary, type: DataType, id: number, keys: IntType, ordered: boolean }; | ||
/** | ||
@@ -301,5 +255,5 @@ * Arrow field data types. | ||
/** The Arrow version. */ | ||
version: number; | ||
version: Version_; | ||
/** The message header type. */ | ||
type: number; | ||
type: MessageHeader_; | ||
/** The buffer integer index after the message. */ | ||
@@ -306,0 +260,0 @@ index: number; |
export const SIZEOF_INT = 4; | ||
export const $iterator = Symbol.iterator; | ||
/** | ||
@@ -40,11 +38,9 @@ * Return a boolean for a single bit in a bitmap. | ||
/** | ||
* Ensure a numerical value (number of BigInt) is a number. Throws an error | ||
* if a BigInt value is outside the range of what a number can represent. | ||
* @param {number | bigint} value The value to check and possibly convert. | ||
* @returns {number} | ||
* Coerce a bigint value to a number. Throws an error if the bigint value | ||
* lies outside the range of what a number can precisely represent. | ||
* @param {bigint} value The value to check and possibly convert. | ||
* @returns {number} The converted number value. | ||
*/ | ||
export function toNumber(value) { | ||
if (typeof value === 'bigint' && ( | ||
value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER | ||
)) { | ||
if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER) { | ||
throw Error(`BigInt exceeds integer number representation: ${value}`); | ||
@@ -51,0 +47,0 @@ } |
228337
6316
92