Skip to content

Commit

Permalink
FileAttachment.parquet (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Dec 12, 2023
1 parent 2309db8 commit 225edd1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/lib/arrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ Or using [Inputs.table](./inputs#table):
```js echo
Inputs.table(table)
```

More commonly you might use an Apache Parquet file. We use [parquet-wasm](https://kylebarron.dev/parquet-wasm/).

```js echo
const schools = FileAttachment("schools.parquet").parquet();
```

```js echo
Plot.plot({
projection: "albers-usa",
marks: [
Plot.dot(schools, {x: "LONGITUD", y: "LATITUDE"})
]
})
```
Binary file added docs/lib/schools.parquet
Binary file not shown.
4 changes: 4 additions & 0 deletions src/client/stdlib/fileAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class AbstractFile {
const [Arrow, response] = await Promise.all([import("npm:apache-arrow"), remote_fetch(this)]);
return Arrow.tableFromIPC(response);
}
async parquet() {
const [Arrow, Parquet, buffer] = await Promise.all([import("npm:apache-arrow"), import("npm:parquet-wasm/esm/arrow1.js").then(async (Parquet) => (await Parquet.default(), Parquet)), this.arrayBuffer()]); // prettier-ignore
return Arrow.tableFromIPC(Parquet.readParquet(new Uint8Array(buffer)).intoIPCStream());
}
async sqlite() {
return import("observablehq:stdlib/sqlite").then((sqlite) => sqlite.SQLiteDatabaseClient.open(remote_fetch(this)));
}
Expand Down
1 change: 1 addition & 0 deletions test/mocks/jsdelivr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const packages: [name: string, version: string][] = [
["leaflet", "1.9.4"],
["lodash", "4.17.21"],
["mermaid", "10.6.1"],
["parquet-wasm", "0.6.0-beta.1"],
["sql.js", "1.9.0"],
["topojson-client", "3.1.0"]
];
Expand Down

0 comments on commit 225edd1

Please sign in to comment.