Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/appkit/src/connectors/sql-warehouse/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type sql,
type WorkspaceClient,
} from "@databricks/sdk-experimental";
import { tableFromIPC } from "apache-arrow";
import type { TelemetryOptions } from "shared";
import {
AppKitError,
Expand Down Expand Up @@ -439,6 +440,37 @@ export class SQLWarehouseConnector {
};
}

/**
* Decode a base64 Arrow IPC attachment into row objects.
* Some serverless warehouses return inline results as Arrow IPC in
* `result.attachment` rather than `result.data_array`.
*/
private _transformArrowAttachment(
response: sql.StatementResponse,
attachment: string,
) {
const buf = Buffer.from(attachment, "base64");
const table = tableFromIPC(buf);
const data = table.toArray().map((row) => {
const obj = row.toJSON();
// Convert BigInt values to strings to avoid JSON.stringify failures
for (const key of Object.keys(obj)) {
if (typeof obj[key] === "bigint") {
obj[key] = obj[key].toString();
}
}
return obj;
});
const { attachment: _att, ...restResult } = response.result as any;
return {
...response,
result: {
...restResult,
data,
},
};
}

private updateWithArrowStatus(response: sql.StatementResponse): {
result: { statement_id: string; status: sql.StatementStatus };
} {
Expand Down
Loading