-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathtypes.d.ts
More file actions
615 lines (548 loc) · 15.8 KB
/
Copy pathtypes.d.ts
File metadata and controls
615 lines (548 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
/**
* Custom parsers for columns
*/
export interface ParquetParsers {
timestampFromMilliseconds(millis: bigint): any
timestampFromMicroseconds(micros: bigint): any
timestampFromNanoseconds(nanos: bigint): any
dateFromDays(days: number): any
stringFromBytes(bytes: Uint8Array): any
jsonFromBytes(bytes: Uint8Array): any
geometryFromBytes(bytes: Uint8Array): any
geographyFromBytes(bytes: Uint8Array): any
uuidFromBytes(bytes: Uint8Array): any
}
/**
* Parquet Metadata options for metadata parsing
*/
export interface MetadataOptions {
parsers?: ParquetParsers // custom parsers to decode advanced types
geoparquet?: boolean // parse geoparquet metadata and set logical type to geometry/geography for geospatial columns (default true)
}
/**
* Parquet query options for reading data
*/
export interface BaseParquetReadOptions {
file: AsyncBuffer // file-like object containing parquet data
metadata?: FileMetaData // parquet metadata, will be parsed if not provided
columns?: string[] // columns to read, all columns if undefined
filter?: ParquetQueryFilter // filter applied to rows (requires rowFormat: 'object', onChunk is not filtered)
filterStrict?: boolean // if true filtering uses strict equality (default true)
rowStart?: number // first requested row index (inclusive)
rowEnd?: number // last requested row index (exclusive)
onChunk?: (chunk: ColumnData) => void // called when a column chunk is parsed. chunks may contain data outside the requested range.
onPage?: (chunk: SubColumnData) => void // called when a data page is parsed. pages may contain data outside the requested range.
compressors?: Compressors // custom decompressors
utf8?: boolean // decode byte arrays as utf8 strings (default true)
parsers?: ParquetParsers // custom parsers to decode advanced types
geoparquet?: boolean // parse geoparquet metadata and set logical type to geometry/geography for geospatial columns (default true)
useOffsetIndex?: boolean // use offset index to limit column chunk reads when available (default false)
useBloomFilters?: boolean // fetch bloom filters to enable row-group skipping on $eq/$in predicates (default false)
usePageIndex?: boolean // fetch page indexes (column index + offset index) for filter columns to skip pages that cannot match (default false)
}
interface ArrayRowFormat {
rowFormat?: 'array' // format of each row passed to the onComplete function. Can be omitted, as it's the default.
onComplete?: (rows: any[][]) => void // called when all requested rows and columns are parsed
}
interface ObjectRowFormat {
rowFormat: 'object' // format of each row passed to the onComplete function
onComplete?: (rows: Record<string, any>[]) => void // called when all requested rows and columns are parsed
}
export type ParquetReadOptions = BaseParquetReadOptions & (ArrayRowFormat | ObjectRowFormat)
/** Options for a lazy, column-oriented parquet scan. */
export type ParquetScanOptions = Omit<BaseParquetReadOptions, 'filter' | 'onChunk' | 'onPage' | 'useOffsetIndex'> & {
/** Conservative filter used only to prune physical row ranges. */
pruningFilter?: ParquetQueryFilter
/** Use offset indexes for range reads when available (default true). */
useOffsetIndex?: boolean
}
/** A physical, zero-based, half-open row range in a parquet file. */
export interface ParquetRowRange {
readonly rowStart: number
readonly rowEnd: number
}
/** Options for reading one column from a prepared scan range or an exact subrange. */
export interface ParquetScanColumnOptions extends ParquetRowRange {
column: string
}
/** A prepared parquet scan with lazy physical column reads. */
export interface ParquetScan {
metadata: FileMetaData
ranges: readonly ParquetRowRange[]
readColumn(options: ParquetScanColumnOptions): Promise<DecodedArray>
}
/**
* Parquet query options for filtering data
*/
export type ParquetQueryFilter =
| ParquetQueryColumnsFilter
| { $and: ParquetQueryFilter[] }
| { $or: ParquetQueryFilter[] }
| { $nor: ParquetQueryFilter[] }
type ParquetQueryColumnsFilter = { [key: string]: ParquetQueryOperator }
export type ParquetQueryValue = string | number | bigint | boolean | object | null | undefined
export type ParquetQueryOperator = {
$gt?: ParquetQueryValue
$gte?: ParquetQueryValue
$lt?: ParquetQueryValue
$lte?: ParquetQueryValue
$eq?: ParquetQueryValue
$ne?: ParquetQueryValue
$in?: ParquetQueryValue[]
$nin?: ParquetQueryValue[]
$not?: ParquetQueryOperator
}
/**
* A run of column data
*/
export interface ColumnData {
columnName: string
columnData: DecodedArray
rowStart: number
rowEnd: number // exclusive
}
/**
* A run of sub-column data (pre-assembly)
*/
export interface SubColumnData {
pathInSchema: string[]
columnData: DecodedArray
rowStart: number
rowEnd: number // exclusive
}
/**
* File-like object that can read slices of a file asynchronously.
*/
export interface AsyncBuffer {
byteLength: number
slice(start: number, end?: number): Awaitable<ArrayBuffer>
}
export type Awaitable<T> = T | Promise<T>
export interface ByteRange {
startByte: number
endByte: number // exclusive
}
export interface DataReader {
view: DataView
offset: number
}
// Parquet file metadata types
export interface FileMetaData {
version: number
schema: SchemaElement[]
num_rows: bigint
row_groups: RowGroup[]
key_value_metadata?: KeyValue[]
created_by?: string
// column_orders?: ColumnOrder[]
// encryption_algorithm?: EncryptionAlgorithm
// footer_signing_key_metadata?: Uint8Array
metadata_length: number
}
export interface SchemaTree {
children: SchemaTree[]
count: number
element: SchemaElement
path: string[]
}
export interface SchemaElement {
type?: ParquetType
type_length?: number
repetition_type?: FieldRepetitionType
name: string
num_children?: number
converted_type?: ConvertedType
scale?: number
precision?: number
field_id?: number
logical_type?: LogicalType
}
export type ParquetType =
| 'BOOLEAN'
| 'INT32'
| 'INT64'
| 'INT96' // deprecated
| 'FLOAT'
| 'DOUBLE'
| 'BYTE_ARRAY'
| 'FIXED_LEN_BYTE_ARRAY'
export type FieldRepetitionType =
| 'REQUIRED'
| 'OPTIONAL'
| 'REPEATED'
export type ConvertedType =
| 'UTF8'
| 'MAP'
| 'MAP_KEY_VALUE'
| 'LIST'
| 'ENUM'
| 'DECIMAL'
| 'DATE'
| 'TIME_MILLIS'
| 'TIME_MICROS'
| 'TIMESTAMP_MILLIS'
| 'TIMESTAMP_MICROS'
| 'UINT_8'
| 'UINT_16'
| 'UINT_32'
| 'UINT_64'
| 'INT_8'
| 'INT_16'
| 'INT_32'
| 'INT_64'
| 'JSON'
| 'BSON'
| 'INTERVAL'
export type TimeUnit = 'MILLIS' | 'MICROS' | 'NANOS'
type EdgeInterpolationAlgorithm = 'SPHERICAL' | 'VINCENTY' | 'THOMAS' | 'ANDOYER' | 'KARNEY'
export type LogicalType =
| { type: 'STRING' }
| { type: 'MAP' }
| { type: 'LIST' }
| { type: 'ENUM' }
| { type: 'DATE' }
| { type: 'INTERVAL' }
| { type: 'NULL' }
| { type: 'JSON' }
| { type: 'BSON' }
| { type: 'UUID' }
| { type: 'FLOAT16' }
| { type: 'DECIMAL', precision: number, scale: number }
| { type: 'TIME', isAdjustedToUTC: boolean, unit: TimeUnit }
| { type: 'TIMESTAMP', isAdjustedToUTC: boolean, unit: TimeUnit }
| { type: 'INTEGER', bitWidth: number, isSigned: boolean }
| { type: 'VARIANT', specification_version?: number }
| { type: 'GEOMETRY', crs?: string }
| { type: 'GEOGRAPHY', crs?: string, algorithm?: EdgeInterpolationAlgorithm }
export interface RowGroup {
columns: ColumnChunk[]
total_byte_size: bigint
num_rows: bigint
sorting_columns?: SortingColumn[]
file_offset?: bigint
total_compressed_size?: bigint
ordinal?: number
}
export interface ColumnChunk {
file_path?: string
file_offset: bigint
meta_data?: ColumnMetaData
offset_index_offset?: bigint
offset_index_length?: number
column_index_offset?: bigint
column_index_length?: number
crypto_metadata?: ColumnCryptoMetaData
encrypted_column_metadata?: Uint8Array
}
export interface ColumnMetaData {
type: ParquetType
encodings: Encoding[]
path_in_schema: string[]
codec: CompressionCodec
num_values: bigint
total_uncompressed_size: bigint
total_compressed_size: bigint
key_value_metadata?: KeyValue[]
data_page_offset: bigint
index_page_offset?: bigint
dictionary_page_offset?: bigint
statistics?: Statistics
encoding_stats?: PageEncodingStats[]
bloom_filter_offset?: bigint
bloom_filter_length?: number
size_statistics?: SizeStatistics
geospatial_statistics?: GeospatialStatistics
}
type ColumnCryptoMetaData = Record<string, never>
export type Encoding =
| 'PLAIN'
| 'GROUP_VAR_INT' // deprecated
| 'PLAIN_DICTIONARY'
| 'RLE'
| 'BIT_PACKED' // deprecated
| 'DELTA_BINARY_PACKED'
| 'DELTA_LENGTH_BYTE_ARRAY'
| 'DELTA_BYTE_ARRAY'
| 'RLE_DICTIONARY'
| 'BYTE_STREAM_SPLIT'
| 'ALP'
export type CompressionCodec =
| 'UNCOMPRESSED'
| 'SNAPPY'
| 'GZIP'
| 'LZO'
| 'BROTLI'
| 'LZ4'
| 'ZSTD'
| 'LZ4_RAW'
export type Compressors = {
[K in CompressionCodec]?: (input: Uint8Array, outputLength: number) => Uint8Array
}
export interface KeyValue {
key: string
value?: string
}
export type MinMaxType = bigint | boolean | number | string | Date | Uint8Array
export interface Statistics {
max?: MinMaxType
min?: MinMaxType
null_count?: bigint
distinct_count?: bigint
max_value?: MinMaxType
min_value?: MinMaxType
is_max_value_exact?: boolean
is_min_value_exact?: boolean
}
interface SizeStatistics {
unencoded_byte_array_data_bytes?: bigint
repetition_level_histogram?: bigint[]
definition_level_histogram?: bigint[]
}
export interface GeospatialStatistics {
bbox?: BoundingBox
geospatial_types?: number[]
}
export interface BoundingBox {
xmin: number
xmax: number
ymin: number
ymax: number
zmin?: number
zmax?: number
mmin?: number
mmax?: number
}
export interface PageEncodingStats {
page_type: PageType
encoding: Encoding
count: number
}
export interface BloomFilter {
numBytes: number
blocks: Uint32Array
}
export type PageType =
'DATA_PAGE' |
'INDEX_PAGE' |
'DICTIONARY_PAGE' |
'DATA_PAGE_V2'
interface SortingColumn {
column_idx: number
descending: boolean
nulls_first: boolean
}
// Parquet file header types
export interface PageHeader {
type: PageType
uncompressed_page_size: number
compressed_page_size: number
crc?: number
data_page_header?: DataPageHeader
index_page_header?: IndexPageHeader
dictionary_page_header?: DictionaryPageHeader
data_page_header_v2?: DataPageHeaderV2
}
export interface DataPageHeader {
num_values: number
encoding: Encoding
definition_level_encoding: Encoding
repetition_level_encoding: Encoding
statistics?: Statistics
}
type IndexPageHeader = Record<string, never>
export interface DictionaryPageHeader {
num_values: number
encoding: Encoding
is_sorted?: boolean
}
export interface DataPageHeaderV2 {
num_values: number
num_nulls: number
num_rows: number
encoding: Encoding
definition_levels_byte_length: number
repetition_levels_byte_length: number
is_compressed?: boolean
statistics?: Statistics
}
interface DataPage {
definitionLevels: number[] | undefined
repetitionLevels: number[]
dataPage: DecodedArray
}
export type DecodedArray =
| Uint8Array
| Uint32Array
| Int32Array
| BigInt64Array
| BigUint64Array
| Float32Array
| Float64Array
| any[]
/** Wrapper around decoded page data */
export interface PageResult {
skipped: number
data?: DecodedArray
}
export interface OffsetIndex {
page_locations: PageLocation[]
unencoded_byte_array_data_bytes?: bigint[]
}
export interface PageLocation {
offset: bigint
compressed_page_size: number
first_row_index: bigint
}
export interface ColumnIndex {
null_pages: boolean[]
min_values: Uint8Array[]
max_values: Uint8Array[]
boundary_order: BoundaryOrder
null_counts?: bigint[]
repetition_level_histograms?: bigint[]
definition_level_histograms?: bigint[]
}
export type BoundaryOrder = 'UNORDERED' | 'ASCENDING' | 'DESCENDING'
/**
* Per-page statistics for one column chunk, decoded from the column index
* and offset index, used for page-level filter pushdown.
*/
export interface ColumnPageStats {
minValues: any[] // per-page lower bound
maxValues: any[] // per-page upper bound
nullPages: boolean[] // per-page all-null flag
nullCounts?: (bigint | undefined)[] // per-page null count, when supplied by the writer
pageStarts: number[] // first row index of each page, relative to the row group
element?: SchemaElement // physical type and logical annotation for comparisons
}
// Sorted disjoint [start, end) row ranges relative to a row group
export type PageRanges = [number, number][]
export interface VariantMetadata {
dictionary: string[]
sorted: boolean
}
export type ThriftObject = { [ key: `field_${number}` ]: ThriftType }
export type ThriftType = boolean | number | bigint | Uint8Array | ThriftType[] | ThriftObject
/**
* Query plan for which byte ranges to read.
*/
export interface QueryPlan {
metadata: FileMetaData
rowStart: number
rowEnd?: number
columns?: string[] // columns to read
fetches: ByteRange[] // byte ranges to fetch
groups: GroupPlan[] // byte ranges by row group
}
// Plan for one group
interface GroupPlan {
chunks: ChunkPlan[]
rowGroup: RowGroup // row group metadata
groupStart: number // row index of the first row in the group
selectStart: number // row index in the group to start reading
selectEnd: number // row index in the group to stop reading
groupRows: number // number of rows in the group
}
// Plan for one column within a row group
type ChunkPlan = ChunkFull | ChunkOffsetIndexed | ChunkPaged
// full column chunk
interface ChunkFull {
columnMetadata: ColumnMetaData
range: ByteRange
}
// column chunk with offset index pending
interface ChunkOffsetIndexed {
columnMetadata: ColumnMetaData
offsetIndex: ByteRange
range: ByteRange
}
// column chunk with page locations already parsed from the offset index
interface ChunkPaged {
columnMetadata: ColumnMetaData
pageLocations: PageLocation[]
range: ByteRange
}
export interface ColumnDecoder {
pathInSchema: string[]
type: ParquetType
element: SchemaElement
schemaPath: SchemaTree[]
codec: CompressionCodec
parsers: ParquetParsers
compressors?: Compressors
utf8?: boolean
}
export interface RowGroupSelect {
groupStart: number // row index of the first row in the group
selectStart: number // row index in the group to start reading
selectEnd: number // row index in the group to stop reading
groupRows: number
}
export interface AsyncRowGroup {
groupStart: number
groupRows: number
selectStart?: number // row index in the group to start reading
selectEnd?: number // row index in the group to stop reading
asyncColumns: AsyncColumn[]
}
export interface AsyncColumn {
pathInSchema: string[]
data: Promise<AsyncPages>
}
interface AsyncPages {
skipped: number // rows skipped from groupStart to first row of this column data
data: DecodedArray[]
}
/**
* Geometry types based on the GeoJSON specification (RFC 7946)
*/
export type Geometry =
| Point
| MultiPoint
| LineString
| MultiLineString
| Polygon
| MultiPolygon
| GeometryCollection
/**
* Position is an array of at least two numbers.
* The order should be [longitude, latitude] with optional properties (eg- altitude).
*/
export type Position = number[]
export interface Point {
type: 'Point'
coordinates: Position
}
export interface MultiPoint {
type: 'MultiPoint'
coordinates: Position[]
}
export interface LineString {
type: 'LineString'
coordinates: Position[]
}
/**
* Each element is one LineString.
*/
export interface MultiLineString {
type: 'MultiLineString'
coordinates: Position[][]
}
/**
* Each element is a linear ring.
*/
export interface Polygon {
type: 'Polygon'
coordinates: Position[][]
}
/**
* Each element is one Polygon.
*/
export interface MultiPolygon {
type: 'MultiPolygon'
coordinates: Position[][][]
}
export interface GeometryCollection {
type: 'GeometryCollection'
geometries: Geometry[]
}