2024-01-14 23:36:58 +00:00
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
import {
|
|
|
|
|
getMaxDefinitionLevel,
|
|
|
|
|
getMaxRepetitionLevel,
|
|
|
|
|
isRequired,
|
|
|
|
|
schemaElement,
|
|
|
|
|
skipDefinitionBytes,
|
|
|
|
|
} from '../src/schema.js'
|
|
|
|
|
|
|
|
|
|
describe('Parquet schema utils', () => {
|
2024-02-11 22:33:56 +00:00
|
|
|
/**
|
|
|
|
|
* @typedef {import('../src/types.js').SchemaElement} SchemaElement
|
|
|
|
|
* @type {SchemaElement[]}
|
|
|
|
|
*/
|
2024-01-14 23:36:58 +00:00
|
|
|
const schema = [
|
2024-02-11 22:33:56 +00:00
|
|
|
{ name: 'root', num_children: 2, repetition_type: 'REQUIRED' },
|
|
|
|
|
{ name: 'child1', repetition_type: 'OPTIONAL' },
|
|
|
|
|
{ name: 'child2', repetition_type: 'REPEATED' },
|
2024-01-14 23:36:58 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
describe('schemaElement', () => {
|
|
|
|
|
it('should return the correct schema element', () => {
|
2024-03-13 02:58:54 +00:00
|
|
|
expect(schemaElement(schema, ['child1'])).toEqual({
|
|
|
|
|
children: [],
|
|
|
|
|
count: 1,
|
|
|
|
|
element: { name: 'child1', repetition_type: 'OPTIONAL' },
|
|
|
|
|
})
|
2024-01-14 23:36:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should throw an error if element not found', () => {
|
|
|
|
|
expect(() => schemaElement(schema, ['nonexistent']))
|
|
|
|
|
.toThrow('parquet schema element not found: nonexistent')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('isRequired', () => {
|
|
|
|
|
it('should return true for required elements', () => {
|
|
|
|
|
expect(isRequired(schema, [])).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should return false for optional or repeated elements', () => {
|
|
|
|
|
expect(isRequired(schema, ['child1'])).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('getMaxRepetitionLevel should return the correct max repetition level', () => {
|
|
|
|
|
expect(getMaxRepetitionLevel(schema, ['child2'])).toBe(1)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('getMaxDefinitionLevel should return the correct max definition level', () => {
|
|
|
|
|
expect(getMaxDefinitionLevel(schema, ['child1'])).toBe(1)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('skipDefinitionBytes should return the correct number of bytes to skip', () => {
|
|
|
|
|
expect(skipDefinitionBytes(100)).toBe(6)
|
|
|
|
|
expect(skipDefinitionBytes(1000)).toBe(7)
|
|
|
|
|
})
|
|
|
|
|
})
|