cancel
Showing results for 
Search instead for 
Did you mean: 
Community Discussions
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

3 REPLIES 3

Emil_Kaminski
Contributor

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

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

Kaniz
Community Manager
Community Manager

Hi @tanmoy-km, Thank you for posting your question in our community! We are happy to assist you.

To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?

This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance! 
 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.