RiyazAliM
Honored Contributor

Hello @Shivaprasad 

Expanding on the code snippet provided above. Once you run the Rest Api code provided above, you will get the statement id. 

Use this statement_id to get the query results using the same statements api.
code snippet is as below:

import time

# Replace with your statement ID from the previous step
statement_id = statement_id

url = f"{databricks_instance}/api/2.0/sql/statements/{statement_id}"

while True:
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        status = response.json()["status"]
        if status['state'] == "SUCCEEDED":
            display("Column Info:", response.json()['manifest']['schema']['columns'])
            display("Query Results:", response.json()["result"]['data_array'])
            break
        elif status['state'] == "FAILED":
            display("Query failed:", response.json())
            break
        else:
            print(f"Query in progress...: {status['state']}")
            time.sleep(5)
    else:
        print("Error:", response.text)
        break

The result will look like below:

RiyazAli_0-1735544063414.png

 

Riz