-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtypes.d.ts
More file actions
545 lines (494 loc) · 14.2 KB
/
Copy pathtypes.d.ts
File metadata and controls
545 lines (494 loc) · 14.2 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
import type { AsyncBuffer } from 'hyparquet'
import type { Writer } from 'hyparquet-writer/src/types.js'
export interface WriterOptions {
/**
* If `'*'`, the writer must create the object only if it does not already
* exist (S3 conditional write: `If-None-Match: *`). On collision the
* underlying `finish()` rejects with an error whose `status` is 412 (or 409
* on some providers). The HTTP/S3 `urlResolver` translates this to the
* `If-None-Match` header. Other resolvers may honor or ignore it.
*/
ifNoneMatch?: '*'
}
export interface Resolver {
reader: (path: string, byteLength?: number) => AsyncBuffer | Promise<AsyncBuffer>
writer?: (path: string, options?: WriterOptions) => Writer
deleter?: (path: string) => Promise<void>
}
export type Lister = (path: string) => Promise<string[]>
/** Catalogs */
export interface RestCatalogContext {
type: 'rest'
url: string
prefix: string
defaults: Record<string, string>
overrides: Record<string, string>
requestInit?: RequestInit
}
export interface FileCatalog {
type: 'file'
resolver: Resolver
lister?: Lister
/**
* Opt in to S3-safe metadata commits: every `vN.metadata.json` (the
* initial create and every subsequent commit) is written with
* `If-None-Match: *` and `version-hint.text` is best-effort. High-level
* write functions retry on 412/409 by reloading the latest metadata and
* re-staging. `icebergCreateTable` and `icebergTransaction` do not retry.
* Default false preserves backwards-compatible (overwrite) behavior.
*/
conditionalCommits?: boolean
}
export type Catalog = RestCatalogContext | FileCatalog
export interface TableIdentifier {
namespace: string[]
name: string
}
export interface LoadTableResponse {
metadataLocation?: string
metadata: TableMetadata
config: Record<string, string>
}
export interface StorageCredential {
prefix: string
config: Record<string, string>
}
export interface TableMetadata {
'format-version': number
'table-uuid': string
location: string
'last-sequence-number': number // missing in V1, required in V2+
'last-updated-ms': number
'last-column-id': number
'current-schema-id': number // optional in V1, required in V2+
schemas: Schema[] // optional in V1, required in V2+
'default-spec-id': number // optional in V1, required in V2+
'partition-specs': PartitionSpec[] // optional in V1, required in V2+
'last-partition-id': number // optional in V1, required in V2+
properties?: Record<string, string>
'current-snapshot-id'?: number | bigint
snapshots?: Snapshot[]
'snapshot-log'?: SnapshotLog[]
'metadata-log'?: MetadataLog[]
'sort-orders': SortOrder[] // optional in V1, required in V2+
'default-sort-order-id': number // optional in V1, required in V2+
refs?: Record<string, SnapshotRef>
statistics?: TableStatistics[]
'partition-statistics'?: PartitionStatistics[]
'next-row-id'?: number | bigint // required in V3
'encryption-keys'?: EncryptionKey[] // V3
}
export interface Schema {
type: 'struct'
'schema-id': number
'identifier-field-ids'?: number[]
fields: Field[]
}
export interface Field {
id: number
name: string
required: boolean
type: IcebergType
doc?: string
'initial-default'?: any
'write-default'?: any
}
export type IcebergType =
'unknown' |
'boolean' |
'int' |
'long' |
'float' |
'double' |
'date' |
'time' |
'timestamp' |
'timestamptz' |
'timestamp_ns' |
'timestamptz_ns' |
'string' |
'uuid' |
`fixed[${number}]` |
'binary' |
`decimal(${number},${number})` |
`decimal(${number}, ${number})` |
'variant' |
'geometry' |
`geometry(${string})` |
'geography' |
`geography(${string})` |
IcebergNestedType
export type IcebergNestedType =
| Schema
| {
type: 'list'
'element-id': number
'element-required': boolean
element: IcebergType
}
| {
type: 'map'
'key-id': number
key: IcebergType
'value-id': number
'value-required': boolean
value: IcebergType
}
export interface PartitionSpec {
'spec-id': number
fields: PartitionField[]
}
interface PartitionField {
'source-id'?: number
'source-ids'?: number[]
'field-id': number
name: string
transform: PartitionTransform
}
export type PartitionTransform =
'identity' |
`bucket[${number}]` |
`truncate[${number}]` |
'year' |
'month' |
'day' |
'hour' |
'void' |
string
interface PartitionStatistics {
'snapshot-id': bigint
'statistics-path': string
'file-size-in-bytes': bigint
}
interface SortOrder {
'order-id': number
'fields': SortField[]
}
interface SortField {
transform: string
'source-id'?: number
'source-ids'?: number[] // V3
'direction': 'asc' | 'desc'
'null-order': 'nulls-first' | 'nulls-last'
}
export interface NameMapping {
names: string[]
'field-id'?: number
fields?: NameMapping[]
}
export interface Snapshot {
'snapshot-id': number | bigint
'parent-snapshot-id'?: number | bigint
'sequence-number': number
'timestamp-ms': number
'manifest-list': string
manifests?: Manifest[]
summary: {
// spec: "value of these fields should be of string type"
operation: string
// 'spark.app.id'?: string
'added-data-files'?: string
'added-records'?: string
'deleted-data-files'?: string
'deleted-records'?: string
'removed-files-size'?: string
'added-delete-files'?: string
'removed-delete-files'?: string
'added-position-deletes'?: string
'removed-position-deletes'?: string
'added-equality-deletes'?: string
'removed-equality-deletes'?: string
'added-dvs'?: string
'removed-dvs'?: string
'added-files-size'?: string
'changed-partition-count'?: string
'total-records'?: string
'total-files-size'?: string
'total-data-files'?: string
'total-delete-files'?: string
'total-position-deletes'?: string
'total-equality-deletes'?: string
}
'schema-id'?: number
'first-row-id'?: number // V3
'added-rows'?: number // V3
'key-id'?: string // V3
}
interface TableStatistics {
'snapshot-id': number | bigint
'statistics-path': string
'file-size-in-bytes': bigint
'file-footer-size-in-bytes': bigint
}
interface SnapshotLog {
'timestamp-ms': number
'snapshot-id': number | bigint
}
export interface SnapshotRef {
'snapshot-id': number | bigint
type: 'branch' | 'tag'
'min-snapshots-to-keep'?: number
'max-snapshot-age-ms'?: number
'max-ref-age-ms'?: number
}
interface EncryptionKey {
'key-id': string
'key-metadata': string
}
/**
* Iceberg REST `TableRequirement`s recognized by `checkRequirements`.
*/
export type TableRequirement =
| { type: 'assert-create' }
| { type: 'assert-table-uuid', uuid: string }
| { type: 'assert-ref-snapshot-id', ref: string, 'snapshot-id': number | bigint | null }
| { type: 'assert-next-row-id', 'next-row-id': number }
| { type: 'assert-current-schema-id', 'current-schema-id': number }
| { type: 'assert-last-assigned-field-id', 'last-assigned-field-id': number }
| { type: 'assert-last-assigned-partition-id', 'last-assigned-partition-id': number }
| { type: 'assert-default-spec-id', 'default-spec-id': number }
| { type: 'assert-default-sort-order-id', 'default-sort-order-id': number }
/**
* Subset of Iceberg REST `TableUpdate`s that the staging API emits.
*/
export type TableUpdate =
| { action: 'add-snapshot', snapshot: Snapshot }
| {
action: 'set-snapshot-ref'
'ref-name': string
type: 'branch' | 'tag'
'snapshot-id': number | bigint
'min-snapshots-to-keep'?: number
'max-snapshot-age-ms'?: number
'max-ref-age-ms'?: number
}
| { action: 'set-properties', updates: Record<string, string> }
| { action: 'remove-properties', removals: string[] }
| { action: 'add-schema', schema: Schema, 'last-column-id'?: number }
| { action: 'set-current-schema', 'schema-id': number }
| { action: 'add-sort-order', 'sort-order': SortOrder }
| { action: 'set-default-sort-order', 'sort-order-id': number }
| { action: 'add-spec', spec: PartitionSpec }
| { action: 'set-default-spec', 'spec-id': number }
| { action: 'remove-snapshots', 'snapshot-ids': (number | bigint)[] }
/**
* Argument passed to the `icebergTransaction` callback. Methods stage
* operations against an in-memory working copy of the table metadata; the
* accumulated updates ship in one commit when the callback resolves.
*/
export interface IcebergTransaction {
append(options: { records: Record<string, any>[], sortOrderId?: number }): Promise<void>
delete(options: {
deletes: { file_path: string, pos: bigint | number }[]
mode?: 'puffin' | 'parquet'
}): Promise<void>
setRef(options: {
ref: string
snapshotId: number | bigint
type?: 'branch' | 'tag'
minSnapshotsToKeep?: number
maxSnapshotAgeMs?: number
maxRefAgeMs?: number
}): void
expireSnapshots(options: { snapshotIds: (number | bigint)[] }): void
}
/**
* Input to a commit function (`fileCatalogCommit`, `restCatalogUpdateTable`):
* the CAS preconditions and updates a catalog must apply, and the
* data/manifest files already written to storage (useful for cleanup on
* commit failure). `snapshot` is absent for metadata-only updates like a
* schema change.
*/
export interface StagedCommit {
snapshot?: Snapshot
requirements: TableRequirement[]
updates: TableUpdate[]
writtenFiles: string[]
}
/**
* Output of an `icebergStage*` call that produces a snapshot (append, delete,
* rewrite, setRef, expireSnapshots).
*/
export interface StagedUpdate extends StagedCommit {
snapshot: Snapshot
}
/**
* Output of `prepareAppend`. Captures everything that does NOT depend on the
* eventually-committed snapshot's sequence number or parent: the data files,
* the manifest, and the assigned snapshot id. `stageSnapshotForAppend` consumes
* this against the freshest metadata to produce a `StagedUpdate` per attempt
* without re-writing data or manifest files.
*/
export interface PreparedAppend {
snapshotId: bigint
manifestUuid: string
formatVersion: 2 | 3
manifestPath: string
manifestLength: bigint
partitionSpecId: number
partitions: FieldSummary[]
addedDataFilesCount: number
addedRowCount: bigint
addedFilesSize: bigint
recordsCount: number
/** Data files + the manifest. Useful for orphan cleanup if the commit ultimately fails. */
writtenFiles: string[]
}
interface MetadataLog {
'timestamp-ms': number
'metadata-file': string
}
export interface Manifest {
manifest_path: string
manifest_length: bigint
partition_spec_id: number
content: 0 | 1 // 0=data, 1=deletes
sequence_number?: bigint
min_sequence_number?: bigint
added_snapshot_id: bigint
added_files_count: number
existing_files_count: number
deleted_files_count: number
added_rows_count: bigint
existing_rows_count: bigint
deleted_rows_count: bigint
partitions?: FieldSummary[]
// key_metadata?: unknown
first_row_id?: bigint | number
}
export interface ManifestEntry {
status: 0 | 1 | 2 // 0=existing, 1=added, 2=deleted
snapshot_id?: bigint
sequence_number?: bigint
file_sequence_number?: bigint
partition_spec_id?: number
data_file: DataFile
}
interface FieldSummary {
contains_null: boolean
contains_nan?: boolean | null
lower_bound?: Uint8Array | null
upper_bound?: Uint8Array | null
}
export interface DataFile {
content: 0 | 1 | 2 // 0=data, 1=position_delete, 2=equality_delete
file_path: string
file_format: 'avro' | 'orc' | 'parquet' | 'puffin'
partition: Record<string, unknown> // keyed by partition-field name in Avro
record_count: bigint
file_size_in_bytes: bigint
column_sizes?: Record<number, bigint>
value_counts?: Record<number, bigint>
null_value_counts?: Record<number, bigint>
nan_value_counts?: Record<number, bigint>
lower_bounds?: Record<number, unknown>
upper_bounds?: Record<number, unknown>
// key_metadata?: string
split_offsets?: bigint[]
equality_ids?: number[]
sort_order_id?: number
first_row_id?: bigint | number
referenced_data_file?: string
content_offset?: bigint
content_size_in_bytes?: bigint
}
export interface FilePositionDelete {
file_path: string
pos: bigint
}
/* Avro types */
interface AvroField {
name: string
type: AvroType
doc?: string
default?: any
'field-id'?: number
}
export type AvroType = AvroPrimitiveType | AvroComplexType | AvroLogicalType
type AvroPrimitiveType = 'null' | 'boolean' | 'int' | 'long' | 'float' | 'double' | 'bytes' | 'string'
interface AvroRecord {
type: 'record'
name: string
namespace?: string
doc?: string
aliases?: string[]
fields: AvroField[]
'schema-id'?: number
}
interface AvroArray {
type: 'array'
items: AvroType
default?: any[]
logicalType?: 'map' // Iceberg map-as-array annotation for non-string keys
'element-id'?: number // Iceberg field id of the array element (e.g. equality_ids[*])
}
type AvroUnion = AvroType[]
type AvroDate = {
type: 'int'
logicalType: 'date'
}
type AvroTimeMillis = {
type: 'int'
logicalType: 'time-millis'
}
type AvroTimeMicros = {
type: 'long'
logicalType: 'time-micros'
}
type AvroDecimal = {
type: 'bytes'
logicalType: 'decimal'
precision: number
scale?: number
}
type AvroTimestampMillis = {
type: 'long'
logicalType: 'timestamp-millis'
'adjust-to-utc'?: boolean
}
type AvroTimestampMicros = {
type: 'long'
logicalType: 'timestamp-micros'
'adjust-to-utc'?: boolean
}
type AvroTimestampNanos = {
type: 'long'
logicalType: 'timestamp-nanos'
'adjust-to-utc'?: boolean
}
type AvroLogicalTypeType =
'date' |
'decimal' |
'duration' |
'local-timestamp-millis' |
'local-timestamp-micros' |
'time-millis' |
'time-micros' |
'timestamp-millis' |
'timestamp-micros' |
'timestamp-nanos' |
'uuid'
// catch-all: "implementations must ignore unknown logical types when reading"
type AvroGenericLogicalType = {
type: AvroPrimitiveType
logicalType: AvroLogicalTypeType
}
type AvroLogicalType =
AvroDate |
AvroTimeMillis |
AvroTimeMicros |
AvroDecimal |
AvroTimestampMillis |
AvroTimestampMicros |
AvroTimestampNanos |
AvroGenericLogicalType
type AvroFixed = {
type: 'fixed'
name: string
size: number
logicalType?: 'uuid' | 'decimal'
precision?: number
scale?: number
}
// Avro complex types: records, enums, arrays, maps, unions, fixed
type AvroComplexType = AvroRecord | AvroArray | AvroUnion | AvroFixed