Skip to content

Commit e1eda6e

Browse files
committed
Preserve rewritten manifest metadata
1 parent b579b86 commit e1eda6e

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/write/manifest.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ function manifestEntrySchema(schema, partitionSpec, formatVersion, manifestConte
3939
mapField('nan_value_counts', 137, 'k138_v139', 138, 139, 'long'),
4040
mapField('lower_bounds', 125, 'k126_v127', 126, 127, 'bytes'),
4141
mapField('upper_bounds', 128, 'k129_v130', 129, 130, 'bytes'),
42+
{
43+
name: 'split_offsets',
44+
type: ['null', { type: 'array', items: 'long', 'element-id': 133 }],
45+
default: null,
46+
'field-id': 132,
47+
},
4248
{ name: 'sort_order_id', type: ['null', 'int'], default: null, 'field-id': 140 },
4349
]
4450
if (manifestContent === 1) {
@@ -236,6 +242,9 @@ export function writeDeleteManifest({ writer, schema, partitionSpec, snapshotId,
236242
export function writeExistingDataManifest({ writer, schema, partitionSpec, entries, formatVersion = 2 }) {
237243
const records = entries.map(entry => {
238244
const dataFile = entry.data_file
245+
if (entry.status === 2) {
246+
throw new Error('writeExistingDataManifest cannot rewrite deleted entries as existing')
247+
}
239248
if (dataFile.content !== 0) {
240249
throw new Error(`writeExistingDataManifest expects data files (content=0), got content=${dataFile.content}`)
241250
}
@@ -346,6 +355,7 @@ function manifestEntryRecord(dataFile, schema, partitionSpec, snapshotId, format
346355
nan_value_counts: encodeMap(dataFile.nan_value_counts),
347356
lower_bounds: encodeMap(dataFile.lower_bounds),
348357
upper_bounds: encodeMap(dataFile.upper_bounds),
358+
split_offsets: dataFile.split_offsets?.length ? dataFile.split_offsets : null,
349359
sort_order_id: dataFile.content === 1 ? null : dataFile.sort_order_id ?? 0,
350360
}
351361
if (manifestContent === 1) {

test/write/manifest.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ describe('writeExistingDataManifest', () => {
210210
...dataFile,
211211
value_counts: { 1: 3n, 2: 3n },
212212
lower_bounds: { 1: new Uint8Array([1, 0, 0, 0, 0, 0, 0, 0]) },
213+
split_offsets: [4n, 100n],
213214
}],
214215
})
215216
const firstBuffer = first.getBuffer()
@@ -245,9 +246,19 @@ describe('writeExistingDataManifest', () => {
245246
})
246247
expect(records[0].data_file.value_counts).toEqual(decoded.data_file.value_counts)
247248
expect(records[0].data_file.lower_bounds).toEqual(decoded.data_file.lower_bounds)
249+
expect(records[0].data_file.split_offsets).toEqual(decoded.data_file.split_offsets)
248250
expect(records[0].data_file.record_count).toBe(3n)
249251
})
250252

253+
it('rejects deleted entries', () => {
254+
expect(() => writeExistingDataManifest({
255+
writer: new ByteWriter(),
256+
schema,
257+
partitionSpec: unpartitioned,
258+
entries: [{ ...entry, status: 2 }],
259+
})).toThrow('writeExistingDataManifest cannot rewrite deleted entries as existing')
260+
})
261+
251262
it('rejects delete files', () => {
252263
expect(() => writeExistingDataManifest({
253264
writer: new ByteWriter(),

0 commit comments

Comments
 (0)