Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 11:34 PM
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)
breakThe result will look like below:
Riz