cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

Duplicate queryId in the query history api response

tanmoy-km
New Contributor

Hello Experts,

I was using the `/api/2.0/sql/history/queries` end-point to find the historical stats for queries on the warehouse endpoint.

I am surprised to see exact rows duplicated in the response, even though they have different `next_page_token` 

How do you suggest to avoid this, so that I get the actual stats about queries that leverage SQL endpoint

Reference link - https://docs.databricks.com/api/workspace/queryhistory/list

2 REPLIES 2

Emil_Kaminski
Contributor II

Hi

you can use SDK from your DataBricks notebook. Here comes example how can you do that:

 
 

 

%pip install databricks-sdk --upgrade<div><span>Restart Python kernel<li-code lang="markup">dbutils.library.restartPython()<p>List your queries history:<li-code lang="markup">from databricks.sdk import WorkspaceClient
w = WorkspaceClient()

for q in w.query_history.list():
    print(f"Query: {q.as_dict()['query_id']} \nStart Time: {q.as_dict()['query_start_time_ms']} \
        \nQuery text: {q.as_dict()['query_text']}\n")

 

Everything in the same notebook. 

Good luck

 

** You might also want to subscribe to Warsaw Databricks YT channel: https://www.youtube.com/channel/UC1-u_2nI97cNHtu_FQ3HP_A

Emil_Kaminski
Contributor II

Sorry for formatting. This editor drives me crazy. Python code once again:

#Install SDK first
%pip install databricks-sdk --upgrade

#Restart Python kernel
dbutils.library.restartPython() 

#List your queries history:
from databricks.sdk import WorkspaceClient 
w = WorkspaceClient() 
for q in w.query_history.list(): 
    print(f"Query: {q.as_dict()['query_id']} \nStart Time: {q.as_dict()['query_start_time_ms']} \nQuery text: {q.as_dict()['query_text']}\n") 
** You might also want to subscribe to Warsaw Databricks YT channel: https://www.youtube.com/channel/UC1-u_2nI97cNHtu_FQ3HP_A

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now