2023-12-29 17:37:37 +00:00
# hyparquet
2023-12-29 18:46:40 +00:00
2024-02-19 00:42:58 +00:00

2023-12-29 20:12:30 +00:00
2024-01-04 19:24:35 +00:00
[](https://www.npmjs.com/package/hyparquet)
2024-01-11 18:46:23 +00:00
[](https://github.com/hyparam/hyparquet/actions)
[](https://opensource.org/licenses/MIT)
2024-02-02 21:24:53 +00:00
[](https://www.npmjs.com/package/hyparquet?activeTab=dependencies)
2023-12-29 18:46:40 +00:00
2023-12-29 19:27:16 +00:00
JavaScript parser for [Apache Parquet ](https://parquet.apache.org ) files.
Apache Parquet is an open source, column-oriented data file format designed for efficient data storage and retrieval.
2024-01-03 01:16:33 +00:00
2024-01-03 17:56:17 +00:00
Dependency free since 2023!
2024-01-09 23:15:08 +00:00
## Features
- Designed to work with huge ML datasets (things like [starcoder ](https://huggingface.co/datasets/bigcode/starcoderdata ))
2024-01-15 23:14:11 +00:00
- Can load metadata separately from data
2024-01-09 23:15:08 +00:00
- Data can be filtered by row and column ranges
- Only fetches the data needed
2024-01-15 23:14:11 +00:00
- Written in JavaScript, checked with TypeScript
2024-01-09 23:15:08 +00:00
- Fast data loading for large scale ML applications
- Bring data visualization closer to the user, in the browser
2024-01-15 19:01:35 +00:00
Why make a new parquet parser in javascript?
First, existing libraries like [parquetjs ](https://github.com/ironSource/parquetjs ) are officially "inactive".
Importantly, they do not support the kind of stream processing needed to make a really performant parser in the browser.
And finally, no dependencies means that hyparquet is lean, and easy to package and deploy.
## Demo
Online parquet file reader demo available at:
https://hyparam.github.io/hyparquet/
Demo source: [index.html ](index.html )
2024-01-09 23:15:08 +00:00
## Installation
2024-01-04 19:24:35 +00:00
```bash
npm install hyparquet
```
2024-01-09 23:15:08 +00:00
## Usage
If you're in a node.js environment, you can load a parquet file with the following example:
```js
const { parquetMetadata } = await import('hyparquet')
const fs = await import('fs')
const buffer = fs.readFileSync('example.parquet')
2024-01-15 23:14:11 +00:00
const arrayBuffer = new Uint8Array(buffer).buffer
2024-01-09 23:15:08 +00:00
const metadata = parquetMetadata(arrayBuffer)
```
If you're in a browser environment, you'll probably get parquet file data from either a drag-and-dropped file from the user, or downloaded from the web.
To load parquet data in the browser from a remote server using `fetch` :
2024-01-04 19:24:35 +00:00
```js
import { parquetMetadata } from 'hyparquet'
2024-01-09 23:15:08 +00:00
const res = await fetch(url)
const arrayBuffer = await res.arrayBuffer()
const metadata = parquetMetadata(arrayBuffer)
2024-01-04 19:24:35 +00:00
```
2024-01-09 23:15:08 +00:00
To parse parquet files from a user drag-and-drop action, see example in [index.html ](index.html ).
2024-04-03 20:30:08 +00:00
## Reading Data
To read the entire contents of a parquet file in a browser environment:
```js
const { parquetRead } = await import("https://cdn.jsdelivr.net/npm/hyparquet/src/hyparquet.min.js")
const res = await fetch(url)
const arrayBuffer = await res.arrayBuffer()
await parquetRead({
file: arrayBuffer,
onComplete: data => console.log(data)
})
```
2024-02-26 18:32:53 +00:00
## Async
Hyparquet supports asynchronous fetching of parquet files, over a network.
You can provide an `AsyncBuffer` which is like a js `ArrayBuffer` but the `slice` method returns `Promise<ArrayBuffer>` .
2024-02-13 18:50:36 +00:00
## Supported Parquet Files
2024-04-03 20:30:08 +00:00
The parquet format is known to be a sprawling format which includes options for a wide array of compression schemes, encoding types, and data structures.
2024-02-23 18:25:06 +00:00
Hyparquet does not support 100% of all parquet files.
Supporting every possible compression codec available in parquet would blow up the size of the hyparquet library.
In practice, most parquet files use snappy compression.
You can extend support for parquet files with other compression codec using the `compressors` option.
```js
import { gunzipSync } from 'zlib'
parquetRead({ file, compressors: {
// add gzip support:
GZIP: (input, output) => output.set(gunzipSync(input)),
}})
```
2024-02-13 18:50:36 +00:00
Compression:
- [X] Uncompressed
- [X] Snappy
- [ ] GZip
- [ ] LZO
- [ ] Brotli
- [ ] LZ4
- [ ] ZSTD
- [ ] LZ4_RAW
Page Type:
- [X] Data Page
- [ ] Index Page
- [X] Dictionary Page
2024-02-24 18:11:04 +00:00
- [X] Data Page V2
2024-02-13 18:50:36 +00:00
Contributions are welcome!
2024-01-03 01:16:33 +00:00
## References
- https://github.com/apache/parquet-format
2024-02-14 05:25:40 +00:00
- https://github.com/apache/parquet-testing
2024-01-03 01:16:33 +00:00
- https://github.com/apache/thrift
2024-02-14 05:25:40 +00:00
- https://github.com/dask/fastparquet
2024-01-03 01:16:33 +00:00
- https://github.com/google/snappy
- https://github.com/zhipeng-jia/snappyjs