0

Get SQL Statement

by
Published 4 days ago

Fetch the status and (when SUCCEEDED) the result of a previously submitted SQL statement by its statement_id.

Script databricks Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
/**
4
 * Get SQL Statement
5
 * Fetch the status and (when SUCCEEDED) the result of a previously submitted SQL statement by its statement_id.
6
 */
7
export async function main(auth: RT.Databricks, statement_id: string) {
8
  const base = auth.workspace_url.replace(/\/$/, "")
9
  const url = new URL(`${base}/api/2.0/sql/statements/${statement_id}`)
10

11
  const response = await fetch(url, {
12
    method: "GET",
13
    headers: {
14
      Authorization: `Bearer ${auth.token}`,
15
      Accept: "application/json",
16
    },
17
  })
18

19
  if (!response.ok) {
20
    throw new Error(`${response.status} ${await response.text()}`)
21
  }
22

23
  return await response.json()
24
}
25