-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable readColumn to read all rows #53
Merged
platypii
merged 15 commits into
hyparam:master
from
park-brian:read-column-rowlimit-infinite
Dec 20, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d6e04ea
Enable readColumn to read all rows
park-brian b4a79b0
Refactor readColumn to use hasRowLimit
park-brian 3a29c7d
Simplify hasRowLimit condition
park-brian 24fa314
Check less common condition first
park-brian ee45b24
Merge branch 'hyparam:master' into read-column-rowlimit-infinite
park-brian 764d40e
add readColumn test files
park-brian afb38b8
implement readColumn tests for undefined rowLimits
park-brian 4b25716
remove unused variable
park-brian acb49f7
return early if no metadata is present
park-brian 6da005b
address tsc warnings
park-brian 0426230
add comparison
park-brian dab11c2
clarify that undefined is valid for rowLimit
park-brian 481c5d7
remove test files
park-brian 3eb6568
verify edge case works when rowLimit is undefined
park-brian 79ccbe3
add test cases for readColumn
park-brian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { compressors } from 'hyparquet-compressors' | ||
import { describe, expect, it } from 'vitest' | ||
import { parquetMetadata } from '../src/hyparquet.js' | ||
import { getSchemaPath } from '../src/schema.js' | ||
import { getColumnRange, readColumn } from '../src/column.js' | ||
import { asyncBufferFromFile } from '../src/utils.js' | ||
|
||
describe('readColumn', () => { | ||
it('read columns when rowLimit is undefined', async () => { | ||
const testFile = 'test/files/float16_nonzeros_and_nans.parquet' | ||
const asyncBuffer = await asyncBufferFromFile(testFile) | ||
const arrayBuffer = await asyncBuffer.slice(0) | ||
const metadata = parquetMetadata(arrayBuffer) | ||
|
||
const column = metadata.row_groups[0].columns[0] | ||
if (!column.meta_data) throw new Error(`No column metadata for ${testFile}`) | ||
const [columnStartByte, columnEndByte] = getColumnRange(column.meta_data).map(Number) | ||
const columnArrayBuffer = arrayBuffer.slice(columnStartByte, columnEndByte) | ||
const schemaPath = getSchemaPath(metadata.schema, column.meta_data?.path_in_schema ?? []) | ||
const reader = { view: new DataView(columnArrayBuffer), offset: 0 } | ||
|
||
const rowLimit = undefined | ||
const result = readColumn(reader, rowLimit, column.meta_data, schemaPath, { file: asyncBuffer, compressors }) | ||
const expected = [null, 1, -2, NaN, 0, -1, -0, 2] | ||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('read columns when rowLimit is Infinity', async () => { | ||
const testFile = 'test/files/float16_nonzeros_and_nans.parquet' | ||
const asyncBuffer = await asyncBufferFromFile(testFile) | ||
const arrayBuffer = await asyncBuffer.slice(0) | ||
const metadata = parquetMetadata(arrayBuffer) | ||
|
||
const column = metadata.row_groups[0].columns[0] | ||
if (!column.meta_data) throw new Error(`No column metadata for ${testFile}`) | ||
const [columnStartByte, columnEndByte] = getColumnRange(column.meta_data).map(Number) | ||
const columnArrayBuffer = arrayBuffer.slice(columnStartByte, columnEndByte) | ||
const schemaPath = getSchemaPath(metadata.schema, column.meta_data?.path_in_schema ?? []) | ||
const reader = { view: new DataView(columnArrayBuffer), offset: 0 } | ||
|
||
const rowLimit = Infinity | ||
const result = readColumn(reader, rowLimit, column.meta_data, schemaPath, { file: asyncBuffer, compressors }) | ||
const expected = [null, 1, -2, NaN, 0, -1, -0, 2] | ||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('read columns when rowLimit is defined', async () => { | ||
const testFile = 'test/files/float16_nonzeros_and_nans.parquet' | ||
const asyncBuffer = await asyncBufferFromFile(testFile) | ||
const arrayBuffer = await asyncBuffer.slice(0) | ||
const metadata = parquetMetadata(arrayBuffer) | ||
|
||
const column = metadata.row_groups[0].columns[0] | ||
if (!column.meta_data) throw new Error(`No column metadata for ${testFile}`) | ||
const [columnStartByte, columnEndByte] = getColumnRange(column.meta_data).map(Number) | ||
const columnArrayBuffer = arrayBuffer.slice(columnStartByte, columnEndByte) | ||
const schemaPath = getSchemaPath(metadata.schema, column.meta_data?.path_in_schema ?? []) | ||
const reader = { view: new DataView(columnArrayBuffer), offset: 0 } | ||
|
||
const rowLimit = 2 | ||
const result = readColumn(reader, rowLimit, column.meta_data, schemaPath, { file: asyncBuffer, compressors }) | ||
expect(result.length).toBe(rowLimit) | ||
}) | ||
|
||
it('read columns when rowLimit is 0', async () => { | ||
const testFile = 'test/files/float16_nonzeros_and_nans.parquet' | ||
const asyncBuffer = await asyncBufferFromFile(testFile) | ||
const arrayBuffer = await asyncBuffer.slice(0) | ||
const metadata = parquetMetadata(arrayBuffer) | ||
|
||
const column = metadata.row_groups[0].columns[0] | ||
if (!column.meta_data) throw new Error(`No column metadata for ${testFile}`) | ||
const [columnStartByte, columnEndByte] = getColumnRange(column.meta_data).map(Number) | ||
const columnArrayBuffer = arrayBuffer.slice(columnStartByte, columnEndByte) | ||
const schemaPath = getSchemaPath(metadata.schema, column.meta_data?.path_in_schema ?? []) | ||
const reader = { view: new DataView(columnArrayBuffer), offset: 0 } | ||
|
||
const rowLimit = 0 | ||
const result = readColumn(reader, rowLimit, column.meta_data, schemaPath, { file: asyncBuffer, compressors }) | ||
expect(result.length).toBe(rowLimit) | ||
}) | ||
|
||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could factor these four tests with https://vitest.dev/api/#test-for, as they only differ in the last two lines. I'll send a PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#55