Skip to content

Commit 1a1ac48

Browse files
committed
Use asyncBufferFromUrl from hyparquet
1 parent 5f16b3b commit 1a1ac48

File tree

6 files changed

+8
-46
lines changed

6 files changed

+8
-46
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
"hyparquet-compressors": "0.1.4"
2929
},
3030
"devDependencies": {
31-
"@rollup/plugin-commonjs": "28.0.0",
31+
"@rollup/plugin-commonjs": "28.0.1",
3232
"@rollup/plugin-node-resolve": "15.3.0",
3333
"@rollup/plugin-replace": "6.0.1",
3434
"@rollup/plugin-terser": "0.4.4",
35-
"@rollup/plugin-typescript": "12.1.0",
35+
"@rollup/plugin-typescript": "12.1.1",
3636
"@testing-library/react": "16.0.1",
3737
"@types/node": "22.7.5",
3838
"@types/react": "18.3.11",
@@ -46,7 +46,7 @@
4646
"react-dom": "18.3.1",
4747
"rollup": "4.24.0",
4848
"rollup-plugin-postcss": "4.0.2",
49-
"tslib": "2.7.0",
49+
"tslib": "2.8.0",
5050
"typescript": "5.6.3",
5151
"typescript-eslint": "8.9.0",
5252
"vitest": "2.1.3"

public/build/app.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/worker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/worker.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tableProvider.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DataFrame } from 'hightable'
2-
import { AsyncBuffer, FileMetaData, parquetSchema } from 'hyparquet'
3-
import { readableStreamToArrayBuffer } from './streamConverters.js'
2+
import { FileMetaData, parquetSchema } from 'hyparquet'
43
import { AsyncBufferFrom, parquetQueryWorker } from './workers/parquetWorkerClient.js'
54

65
/**
@@ -17,40 +16,3 @@ export function parquetDataFrame(from: AsyncBufferFrom, metadata: FileMetaData):
1716
sortable: true,
1817
}
1918
}
20-
21-
export async function asyncBufferFrom(url: string): Promise<AsyncBuffer> {
22-
// get byteLength with head
23-
const res = await fetch(url, { method: 'HEAD' })
24-
if (!res.ok) throw new Error(`Failed to fetch parquet file: ${res.statusText}`)
25-
const contentLength = res.headers.get('Content-Length')
26-
if (!contentLength) throw new Error('Content-Length header missing')
27-
const byteLength = Number(contentLength)
28-
29-
// slice with range requests
30-
return {
31-
byteLength,
32-
slice: async (start: number, end?: number) => {
33-
const headers = new Headers({ Range: rangeString(start, end) })
34-
const res = await fetch(url, { headers })
35-
if (!res.ok || !res.body) throw new Error(`Failed to fetch parquet file: ${res.statusText}`)
36-
return readableStreamToArrayBuffer(res.body)
37-
},
38-
}
39-
}
40-
41-
42-
/**
43-
* Convert a start and end byte offset into a range string.
44-
* If start is negative, end must be undefined.
45-
*/
46-
export function rangeString(start: number, end?: number): string {
47-
if (start < 0) {
48-
if (end !== undefined) throw new Error(`invalid suffix range [${start}, ${end}]`)
49-
return `bytes=${start}`
50-
} else if (end !== undefined) {
51-
if (start >= end) throw new Error(`invalid empty range [${start}, ${end}]`)
52-
return `bytes=${start}-${end - 1}`
53-
} else {
54-
return `bytes=${start}-`
55-
}
56-
}

src/workers/parquetWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { compressors } from 'hyparquet-compressors'
33

44
self.onmessage = async ({ data }) => {
55
const { metadata, asyncBuffer, rowStart, rowEnd, orderBy } = data
6-
const file = await asyncBufferFromUrl(asyncBuffer.url)
6+
const file = await asyncBufferFromUrl(asyncBuffer.url, asyncBuffer.byteLength)
77
try {
88
const result = await parquetQuery({
99
metadata, file, rowStart, rowEnd, orderBy, compressors,

0 commit comments

Comments
 (0)