-
Notifications
You must be signed in to change notification settings - Fork 64
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
Issue Querying MotherDuck After v0.12.2 Upgrade #662
Comments
I suspect the issue is that mosaic now uses flechette instead of arrow js. Can motherduck just return the binary blob instead of an arrow table object? |
I will find out. What would be the idea from that point? Hand the binary blob to Flechette to turn into a Table? |
Yeah, something like
|
Note that the mosaic/packages/core/src/index.js Line 19 in fba8d95
Personally, I would prefer if data tools defaulted to proving Arrow bytes rather than a specific Arrow implementation, especially as the default ( |
Chatted with the MotherDuck team, they suggested an approach for getting at the IPC data. I implemented their suggestion into my sample project. See summary below and https://github.com/enlore/debug-motherduck-mosaic-v_0_12_2/blob/main/src/App.tsx for details. Good news: seems to work as far as ensuring we are creating Flechette tables from query result byte streams. Bad news: Mosaic is still choking on Below are the key elements of getting at the IPC data directly. // We need connection ID to poll against later and the MDConnection does not
// provide a useUnsafe method
//
// const connection = MDConnection.create({
// mdToken: token,
// });
// So we drop down a level to the DuckDB instance provided by MotherDuck's
// getAsyncDuckDb and get a connection from it
const duckDb = await getAsyncDuckDb({
mdToken: token,
})
// Cast to the DuckDB Wasm version of the AsyncDuckDBConnection type
const duckDbConn = await duckDb.connect() as unknown as AsyncDuckDBConnection /**
* Start a query and poll it to see when it finishes. Get the IPC data and build a Uint8Array from it.
* @param conn AsyncDuckDBConnection
* @param sql string A DuckDB SQL query string
* @returns Promise<Uint8Array | undefined> The query results IPC data stream all buffered into one place
*/
async function getMDArrowIPC(conn: AsyncDuckDBConnection, sql: string): Promise<Uint8Array | undefined> {
return await conn.useUnsafe(async (bindings: AsyncDuckDB, connId: number) => {
try {
let header = await bindings.startPendingQuery(connId, sql);
while (header == null) {
header = await bindings.pollPendingQuery(connId);
}
// see the duckdb-wasm AsyncResultStreamIterator: https://github.com/duckdb/duckdb-wasm/blob/41c03bef54cbc310ba2afa2e5f71f7a22b38364f/packages/duckdb-wasm/src/parallel/async_connection.ts#L111-L158
const iter = new AsyncResultStreamIterator(bindings, connId, header);
const buffer = await accumulateIPCBuffer(iter);
return buffer;
} catch (error) {
// TODO blearg
console.error(error)
}
});
} Finally we function decodeIPCToFlechette(result: Uint8Array): Table {
const table = decodeIPC(result)
return table
} |
In the below screenshot, an error is thrown because Errors: Possibly related behavior: if I run a DESCRIBE query using the exact same quotes as the query generated by Mosaic before I build the Code the runs the describe query: const d2 = await vg.coordinator().query('DESCRIBE SELECT "tpep_pickup_datetime" AS "column" FROM "sample_data"."nyc"."taxi" AS "source"') as Table
console.info('d2', d2.toArray()) Screenshot: Further, if I run a DESCRIBE query prior to building the Code to run the describe query: // Confirming that we can DESCRIBE successfully
const d1 = await vg.coordinator().query('DESCRIBE SELECT tpep_pickup_datetime AS column FROM sample_data.nyc.taxi AS source') as Table
console.info('d1', d1.toArray()) Screenshot of error, no |
Possibly related? |
Hmm, that definitely looks like it could break Mosaic in some cases. Thanks for flagging! |
Summary
Dependencies
Dependency versions:
Errors
When attempting to build plots using data fetched from MotherDuck, one of two errors occurs.
ERROR 1:
getFieldInfo
throws:This happens when attempting to build a plot by querying data from MotherDuck.
ERROR 2:
arrowToColumns
throws:While exploring this issue, I validated that I can execute
DESCRIBE
queries against the plot's source table directly usingvg.coordinator().query()
.If I execute a
DESCRIBE
query with the same exact quotes as generated by Mosaic's query building logic before attempting to create the plot, this error is thrown instead of ERROR 1. Seesrc/App.tsx
line 28 for sample code.Repro
See reference repo here: https://github.com/enlore/debug-motherduck-mosaic-v_0_12_2
It should be good to go so you can clone,
npm i
, andnpm run dev
.The repo includes a read only token so the app can connect to my personal MotherDuck free tier account for convenience.
src/App.tsx
contains the relevant logicCONNECT_TO_MOTHERDUCK
totrue
to see ERROR 1CONNECT_TO_MOTHERDUCK
tofalse
to validate that Mosaic can build a line plot from a browser local DuckDB Wasm instance without issueLet me know if I can provide additional information.
Thank you.
The text was updated successfully, but these errors were encountered: