Skip to content

Commit

Permalink
parquet refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Apr 3, 2024
1 parent eeaf012 commit 7d14344
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
13 changes: 0 additions & 13 deletions utils/duckdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as duckdb from "@duckdb/duckdb-wasm"
import { AsyncDuckDB, DuckDBBundle } from "@duckdb/duckdb-wasm"
import Worker from "web-worker"
import path from "path"
import { useEffect, useState } from "react"

const ENABLE_DUCK_LOGGING = false

Expand Down Expand Up @@ -119,18 +118,6 @@ export async function loadParquet<T>(path: string): Promise<T[]> {
})
}

/**
* Hook for loading a parquet file or URL; starts out `null`, gets populated asynchronously
*/
export function useParquet<T>(url?: string): T[] | null {
const [data, setData] = useState<T[] | null>(null)
useEffect(() => {
if (!url) return
loadParquet<T>(url).then((data) => setData(data))
}, [])
return data
}

/**
* Convert [a byte array representing a Parquet file] to an array of records
*/
Expand Down
15 changes: 15 additions & 0 deletions utils/useParquet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import { useEffect, useState } from "react"
import { loadParquet } from "./duckdb"

/**
* Hook for loading a parquet file or URL; starts out `null`, gets populated asynchronously
*/
export function useParquet<T>(url?: string): T[] | null {
const [data, setData] = useState<T[] | null>(null)
useEffect(() => {
if (!url) return
loadParquet<T>(url).then((data) => setData(data))
}, [])
return data
}

0 comments on commit 7d14344

Please sign in to comment.