Skip to main content

query_history

Creates, updates, deletes, gets or lists a query_history resource.

Overview

Namequery_history
TypeResource
Iddatabricks_workspace.sql.query_history

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
cache_query_idstring
endpoint_idstringAlias for ``warehouse_id``.
executed_as_user_idintegerThe ID of the user whose credentials were used to run the query.
query_idstringThe query ID.
session_idstringThe spark session UUID that query ran on. This is either the Spark Connect, DBSQL, or SDP session ID.
user_idintegerThe ID of the user who ran the query.
warehouse_idstringWarehouse ID.
executed_as_user_namestringThe email address or username of the user whose credentials were used to run the query.
user_namestringThe email address or username of the user who ran the query.
channel_usedobjectSQL Warehouse channel information at the time of query execution
client_applicationstringClient application that ran the statement. For example: Databricks SQL Editor, Tableau, and Power BI. This field is derived from information provided by client applications. While values are expected to remain static over time, this cannot be guaranteed.
durationintegerTotal time of the statement execution. This value does not include the time taken to retrieve the results, which can result in a discrepancy between this value and the start-to-finish wall-clock time.
error_messagestringMessage describing why the query could not complete.
execution_end_time_msintegerThe time execution of the query ended.
is_finalbooleanWhether more updates for the query are expected.
lookup_keystringA key that can be used to look up query details.
metricsobjectMetrics about query execution.
plans_statestringWhether plans exist for the execution, or the reason why they are missing (EMPTY, EXISTS, IGNORED_LARGE_PLANS_SIZE, IGNORED_SMALL_DURATION, IGNORED_SPARK_PLAN_TYPE, UNKNOWN)
query_end_time_msintegerThe time the query ended.
query_sourceobjectA struct that contains key-value pairs representing Databricks entities that were involved in the execution of this statement, such as jobs, notebooks, or dashboards. This field only records Databricks entities.
query_start_time_msintegerThe time the query started.
query_tagsarrayA query execution can be optionally annotated with query tags
query_textstringThe text of the query.
rows_producedintegerThe number of results returned by the query.
spark_ui_urlstringURL to the Spark UI query plan.
statement_typestringType of statement for this query (ALTER, ANALYZE, CALL, COPY, CREATE, DELETE, DESCRIBE, DROP, EXPLAIN, GRANT, INSERT, MERGE, OPTIMIZE, OTHER, REFRESH, REPLACE, REVOKE, SELECT, SET, SHOW, TRUNCATE, UPDATE, USE)
statusstringStatuses which are also used by OperationStatus in runtime. When adding a new QueryStatus, make<br />sure to update com.databricks.sqlgateway.history.QueryStatusOrdering (CANCELED, COMPILED, COMPILING, FAILED, FINISHED, QUEUED, RUNNING, STARTED)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
listselectdeployment_namefilter_by, include_metrics, max_results, page_tokenList the history of queries through SQL warehouses, and serverless compute.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
deployment_namestringThe Databricks Workspace Deployment Name (default: dbc-abcd0123-a1bc)
filter_byobjectAn optional filter object to limit query history results. Accepts parameters such as user IDs, endpoint IDs, and statuses to narrow the returned data. In a URL, the parameters of this filter are specified with dot notation. For example: filter_by.statement_ids.
include_metricsbooleanWhether to include the query metrics with each query. Only use this for a small subset of queries (max_results). Defaults to false.
max_resultsintegerLimit the number of results returned in one page. Must be less than 1000 and the default is 100.
page_tokenstringA token that can be used to get the next page of results. The token can contains characters that need to be encoded before using it in a URL. For example, the character '+' needs to be replaced by %2B. This field is optional.

SELECT examples

List the history of queries through SQL warehouses, and serverless compute.

SELECT
cache_query_id,
endpoint_id,
executed_as_user_id,
query_id,
session_id,
user_id,
warehouse_id,
executed_as_user_name,
user_name,
channel_used,
client_application,
duration,
error_message,
execution_end_time_ms,
is_final,
lookup_key,
metrics,
plans_state,
query_end_time_ms,
query_source,
query_start_time_ms,
query_tags,
query_text,
rows_produced,
spark_ui_url,
statement_type,
status
FROM databricks_workspace.sql.query_history
WHERE deployment_name = '{{ deployment_name }}' -- required
AND filter_by = '{{ filter_by }}'
AND include_metrics = '{{ include_metrics }}'
AND max_results = '{{ max_results }}'
AND page_token = '{{ page_token }}'
;