diff --git a/src/assemble.js b/src/assemble.js index 467c759..d66d3f3 100644 --- a/src/assemble.js +++ b/src/assemble.js @@ -28,12 +28,13 @@ export function assembleLists(output, definitionLevels, repetitionLevels, values if (repetitionLevels[0]) { // continue previous row while (currentDepth < repetitionPath.length - 2 && currentRepLevel < repetitionLevels[0]) { - if (!currentContainer) throw new Error('parquet cannot resume previous page') - // go into last list - currentContainer = currentContainer.at(-1) - containerStack.push(currentContainer) currentDepth++ - if (repetitionPath[currentDepth] !== 'REQUIRED') currentDefLevel++ + if (repetitionPath[currentDepth] !== 'REQUIRED') { + // go into last list + currentContainer = currentContainer.at(-1) + containerStack.push(currentContainer) + currentDefLevel++ + } if (repetitionPath[currentDepth] === 'REPEATED') currentRepLevel++ } } diff --git a/test/assemble.test.js b/test/assemble.test.js index ad97bcb..98c80cd 100644 --- a/test/assemble.test.js +++ b/test/assemble.test.js @@ -66,7 +66,7 @@ describe('assembleLists', () => { expect(result).toEqual([[['a', 'b']], [], [['d', 'e']]]) }) - it('should handle continuing a row from the previous page', () => { + it('should continue from the previous page', () => { const definitionLevels = [3, 3, 3, 1] const repetitionLevels = [1, 0, 1, 0] const values = ['b', 'c', 'd', 'e'] @@ -75,6 +75,14 @@ describe('assembleLists', () => { expect(result).toEqual([[['a', 'b']], [['c', 'd']], [[]]]) }) + it('should continue from the previous page (depth 2)', () => { + const repetitionLevels = [2, 0, 2, 0] + const values = ['b', 'c', 'd', 'e'] + const prev = [[['a']]] + const result = assembleLists(prev, [], repetitionLevels, values, nestedRequired) + expect(result).toEqual([[['a', 'b']], [['c', 'd']], [['e']]]) + }) + it('should handle nested arrays', () => { // from nullable.impala.parquet const repetitionLevels = [0, 2, 1, 2]