mirror of
https://github.com/asadbek064/hyparquet.git
synced 2026-01-04 02:36:36 +00:00
Simplify error messages
This commit is contained in:
parent
9a9519f0b7
commit
bf6ac3b644
@ -30,7 +30,7 @@ export const defaultInitialFetchSize = 1 << 19 // 512kb
|
||||
* @returns {Promise<FileMetaData>} parquet metadata object
|
||||
*/
|
||||
export async function parquetMetadataAsync(asyncBuffer, initialFetchSize = defaultInitialFetchSize) {
|
||||
if (!asyncBuffer || !(asyncBuffer.byteLength >= 0)) throw new Error('parquetMetadataAsync expected AsyncBuffer')
|
||||
if (!asyncBuffer || !(asyncBuffer.byteLength >= 0)) throw new Error('parquet expected AsyncBuffer')
|
||||
|
||||
// fetch last bytes (footer) of the file
|
||||
const footerOffset = Math.max(0, asyncBuffer.byteLength - initialFetchSize)
|
||||
@ -73,7 +73,7 @@ export async function parquetMetadataAsync(asyncBuffer, initialFetchSize = defau
|
||||
* @returns {FileMetaData} parquet metadata object
|
||||
*/
|
||||
export function parquetMetadata(arrayBuffer) {
|
||||
if (!(arrayBuffer instanceof ArrayBuffer)) throw new Error('parquetMetadata expected ArrayBuffer')
|
||||
if (!(arrayBuffer instanceof ArrayBuffer)) throw new Error('parquet expected ArrayBuffer')
|
||||
const view = new DataView(arrayBuffer)
|
||||
|
||||
// Validate footer magic number "PAR1"
|
||||
|
||||
@ -13,11 +13,11 @@ import { equals } from './utils.js'
|
||||
*/
|
||||
export async function parquetQuery(options) {
|
||||
if (!options.file || !(options.file.byteLength >= 0)) {
|
||||
throw new Error('parquetQuery expected file AsyncBuffer')
|
||||
throw new Error('parquet expected AsyncBuffer')
|
||||
}
|
||||
options.metadata ??= await parquetMetadataAsync(options.file)
|
||||
const { metadata, rowStart = 0, orderBy, filter } = options
|
||||
if (rowStart < 0) throw new Error('parquetQuery rowStart must be positive')
|
||||
if (rowStart < 0) throw new Error('parquet rowStart must be positive')
|
||||
const rowEnd = options.rowEnd ?? Number(metadata.num_rows)
|
||||
|
||||
if (filter && !orderBy && rowEnd < metadata.num_rows) {
|
||||
|
||||
@ -19,10 +19,6 @@ import { concat } from './utils.js'
|
||||
* @returns {Promise<void>} resolves when all requested rows and columns are parsed, all errors are thrown here
|
||||
*/
|
||||
export async function parquetRead(options) {
|
||||
if (!options.file || !(options.file.byteLength >= 0)) {
|
||||
throw new Error('parquetRead expected file AsyncBuffer')
|
||||
}
|
||||
|
||||
// load metadata if not provided
|
||||
options.metadata ??= await parquetMetadataAsync(options.file)
|
||||
const { metadata, onComplete, rowStart = 0, rowEnd } = options
|
||||
|
||||
@ -20,7 +20,7 @@ describe('parquetMetadata', () => {
|
||||
|
||||
it('throws for arrayBuffer undefined', () => {
|
||||
// @ts-expect-error testing invalid input
|
||||
expect(() => parquetMetadata(undefined)).toThrow('parquetMetadata expected ArrayBuffer')
|
||||
expect(() => parquetMetadata(undefined)).toThrow('parquet expected ArrayBuffer')
|
||||
})
|
||||
|
||||
it('throws for a too short file', () => {
|
||||
@ -66,7 +66,7 @@ describe('parquetMetadataAsync', () => {
|
||||
const arrayBuffer = undefined
|
||||
// @ts-expect-error testing invalid input
|
||||
await expect(parquetMetadataAsync(arrayBuffer)).rejects
|
||||
.toThrow('parquetMetadataAsync expected AsyncBuffer')
|
||||
.toThrow('parquet expected AsyncBuffer')
|
||||
})
|
||||
|
||||
it('throws for invalid magic number', async () => {
|
||||
|
||||
@ -7,7 +7,7 @@ describe('parquetQuery', () => {
|
||||
it('throws error for undefined file', async () => {
|
||||
// @ts-expect-error testing invalid input
|
||||
await expect(parquetQuery({ file: undefined }))
|
||||
.rejects.toThrow('parquetQuery expected file AsyncBuffer')
|
||||
.rejects.toThrow('parquet expected AsyncBuffer')
|
||||
})
|
||||
|
||||
it('reads data without orderBy', async () => {
|
||||
|
||||
@ -10,14 +10,14 @@ describe('parquetRead', () => {
|
||||
it('throws error for undefined file', async () => {
|
||||
// @ts-expect-error testing invalid input
|
||||
await expect(parquetRead({ file: undefined }))
|
||||
.rejects.toThrow('parquetRead expected file AsyncBuffer')
|
||||
.rejects.toThrow('parquet expected AsyncBuffer')
|
||||
})
|
||||
|
||||
it('throws error for undefined byteLength', async () => {
|
||||
const file = { byteLength: undefined, slice: () => new ArrayBuffer(0) }
|
||||
// @ts-expect-error testing invalid input
|
||||
await expect(parquetRead({ file }))
|
||||
.rejects.toThrow('parquetRead expected file AsyncBuffer')
|
||||
.rejects.toThrow('parquet expected AsyncBuffer')
|
||||
})
|
||||
|
||||
it('filter by row', async () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user