<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to use Databricks Query History API (REST API) in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/93200#M38648</link>
    <description>&lt;P&gt;Here's how to query with &lt;A href="https://github.com/databricks/databricks-sdk-py" target="_blank"&gt;databricks-sdk-py&lt;/A&gt;&amp;nbsp;(working code). I had a frustrating time doing it with vanilla python + requests/urllib and couldn't figure it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Oct 2024 23:51:21 GMT</pubDate>
    <dc:creator>yegorski</dc:creator>
    <dc:date>2024-10-08T23:51:21Z</dc:date>
    <item>
      <title>How to use Databricks Query History API (REST API)</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/29048#M20805</link>
      <description>&lt;P&gt;I have setup authentication using this page &lt;A href="https://docs.databricks.com/sql/api/authentication.html" alt="https://docs.databricks.com/sql/api/authentication.html" target="_blank"&gt;https://docs.databricks.com/sql/api/authentication.html&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and run &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;curl -n -X GET &lt;A href="https://&amp;lt;databricks-instance&amp;gt;.cloud.databricks.com/api/2.0/sql/history/queries" target="test_blank"&gt;https://&amp;lt;databricks-instance&amp;gt;.cloud.databricks.com/api/2.0/sql/history/queries&lt;/A&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To get history of all sql endpoint queries, but I want to get all queries for a particular day - say Jan 1st, 2021.&lt;/P&gt;&lt;P&gt; How do I do this? I don't see any examples in the documentation about this&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 05:22:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/29048#M20805</guid>
      <dc:creator>Constantine</dc:creator>
      <dc:date>2022-02-09T05:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Databricks Query History API (REST API)</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/29050#M20807</link>
      <description>&lt;P&gt;Hi @John Constantine​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To the above GET request add following raw data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;{
 "filter_by": {
   "endpoint_ids": ["&amp;lt;endpoint_id_1", "&amp;lt;endpoint_id_2", ...... "&amp;lt;endpoint_id_N"],
   "query_start_time_range":{
       "start_time_ms" :1640995200000,&amp;nbsp;
       "end_time_ms" : 1641081599000
   }
 },
 "max_results": 999
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Here,&lt;/P&gt;&lt;P&gt;1640995200000 refers to Saturday, January 1, 2022 12:00:00 AM GMT+0&lt;/P&gt;&lt;P&gt;1641081599000 refers to Saturday, January 1, 2022 11:59:59 PM GMT+0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Refer to &lt;A href="https://docs.databricks.com/sql/api/query-history.html#timerange" alt="https://docs.databricks.com/sql/api/query-history.html#timerange" target="_blank"&gt;Query API 2.0 documentation&lt;/A&gt; for more filters.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 14:44:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/29050#M20807</guid>
      <dc:creator>AmanSehgal</dc:creator>
      <dc:date>2022-02-10T14:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Databricks Query History API (REST API)</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/29051#M20808</link>
      <description>&lt;P&gt;Hi @John Constantine​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Did @Aman Sehgal​&amp;nbsp;response helped you with your question? If it does, could you please mark it as best response.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 22:33:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/29051#M20808</guid>
      <dc:creator>jose_gonzalez</dc:creator>
      <dc:date>2022-03-07T22:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Databricks Query History API (REST API)</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/54695#M30148</link>
      <description>&lt;P&gt;Are you sure this works?&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;payload &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&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SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"end_time_ms"&lt;/SPAN&gt;&lt;SPAN&gt; : &lt;/SPAN&gt;&lt;SPAN&gt;1641081599000&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;},&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"max_results"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{'error_code': 'MALFORMED_REQUEST', 'message': "Could not parse request object: Expected 'START_OBJECT' not 'VALUE_STRING'\n at [Source: (ByteArrayInputStream); line: 1, column: 15]\n at [Source: java.io.ByteArrayInputStream@5297a56c; line: 1, column: 15]"}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Dec 2023 01:08:41 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/54695#M30148</guid>
      <dc:creator>MorpheusGoGo</dc:creator>
      <dc:date>2023-12-06T01:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Databricks Query History API (REST API)</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/64833#M32674</link>
      <description>&lt;P&gt;I get the same error message - databricks documentation is not showing a working example&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 18:01:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/64833#M32674</guid>
      <dc:creator>Cheryl</dc:creator>
      <dc:date>2024-03-27T18:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Databricks Query History API (REST API)</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/93200#M38648</link>
      <description>&lt;P&gt;Here's how to query with &lt;A href="https://github.com/databricks/databricks-sdk-py" target="_blank"&gt;databricks-sdk-py&lt;/A&gt;&amp;nbsp;(working code). I had a frustrating time doing it with vanilla python + requests/urllib and couldn't figure it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2024 23:51:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-databricks-query-history-api-rest-api/m-p/93200#M38648</guid>
      <dc:creator>yegorski</dc:creator>
      <dc:date>2024-10-08T23:51:21Z</dc:date>
    </item>
  </channel>
</rss>

