02-08-2022 09:22 PM
I have setup authentication using this page https://docs.databricks.com/sql/api/authentication.html
and run
curl -n -X GET https://<databricks-instance>.cloud.databricks.com/api/2.0/sql/history/queries
To get history of all sql endpoint queries, but I want to get all queries for a particular day - say Jan 1st, 2021.
How do I do this? I don't see any examples in the documentation about this
02-10-2022 06:44 AM
Hi @John Constantine
To the above GET request add following raw data.
{
"filter_by": {
"endpoint_ids": ["<endpoint_id_1", "<endpoint_id_2", ...... "<endpoint_id_N"],
"query_start_time_range":{
"start_time_ms" :1640995200000,
"end_time_ms" : 1641081599000
}
},
"max_results": 999
}
Here,
1640995200000 refers to Saturday, January 1, 2022 12:00:00 AM GMT+0
1641081599000 refers to Saturday, January 1, 2022 11:59:59 PM GMT+0
Refer to Query API 2.0 documentation for more filters.
02-10-2022 06:44 AM
Hi @John Constantine
To the above GET request add following raw data.
{
"filter_by": {
"endpoint_ids": ["<endpoint_id_1", "<endpoint_id_2", ...... "<endpoint_id_N"],
"query_start_time_range":{
"start_time_ms" :1640995200000,
"end_time_ms" : 1641081599000
}
},
"max_results": 999
}
Here,
1640995200000 refers to Saturday, January 1, 2022 12:00:00 AM GMT+0
1641081599000 refers to Saturday, January 1, 2022 11:59:59 PM GMT+0
Refer to Query API 2.0 documentation for more filters.
03-07-2022 02:33 PM
Hi @John Constantine ,
Did @Aman Sehgal response helped you with your question? If it does, could you please mark it as best response.
12-05-2023 05:08 PM
Are you sure this works?
03-27-2024 11:01 AM
I get the same error message - databricks documentation is not showing a working example
10-08-2024 04:51 PM
Here's how to query with databricks-sdk-py (working code). I had a frustrating time doing it with vanilla python + requests/urllib and couldn't figure it out.
import datetime
import os
from databricks.sdk import WorkspaceClient
from databricks.sdk.service import sql
w = WorkspaceClient(
host=os.getenv("DATABRICKS_HOST"),
token=os.getenv("DATABRICKS_TOKEN"),
)
NOW = datetime.datetime.now()
ONE_MINUTE = NOW - datetime.timedelta(minutes=1)
NOW_MS = int(NOW.timestamp() * 1000)
ONE_MINUTE_MS = int(ONE_MINUTE.timestamp() * 1000)
recent_queries = w.query_history.list(
filter_by=sql.QueryFilter(
query_start_time_range=sql.TimeRange(
start_time_ms=ONE_MINUTE_MS, end_time_ms=NOW_MS
),
statuses=[sql.QueryStatus.FINISHED],
),
include_metrics=False,
)
print(list(recent_queries))
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group