cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
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_Fatma
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! 
 

Connect with Databricks Users in Your Area

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