---
title: event_log table-valued function
description: Learn the syntax of the event\_log function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/event_log
---

# `event_log` table-valued function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 13.3 LTS and above

Returns the event log for [materialized views](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-materialized-view.md), [streaming tables](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table.md), and [Lakeflow pipelines](https://docs.databricks.com/aws/en/ldp/index.md).

Learn more about the Lakeflow pipelines [event log](https://docs.databricks.com/aws/en/ldp/monitor-event-logs.md).

> [!NOTE]
>
> The `event_log` table-valued function can be called only by the owner of a streaming table or materialized view, and a view created over the `event_log` table-valued function can be queried only by the owner of a streaming table or materialized view. The view cannot be shared with other users.

## Syntax

```
event_log( { TABLE ( table_name ) | pipeline_id } )
```

## Arguments

* [table\_name](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#table-name): The name of a materialized view or streaming table. The name must not include a temporal specification. If the name is not qualified, the current catalog and schema are used to qualify the identifier.
* `pipeline_id`: The string identifier of a pipeline.

## Returns

* `id STRING NOT NULL`: A unique identifier for the event log record.
* `sequence STRING NOT NULL`: A JSON object containing metadata to identify and order events.
* `origin STRING NOT NULL`: A JSON object containing metadata for the origin of the event, for example, cloud provider, region, `user_id`, or `pipeline_id`.
* `timestamp TIMESTAMP NOT NULL`: The time the event was recorded in UTC.
* `message STRING NOT NULL`: A human-readable message describing the event.
* `level STRING NOT NULL`: The level of logging, for example, `INFO`, `WARN`, `ERROR`, or `METRICS`.
* `maturity_level STRING NOT NULL`: The stability of the event schema. The possible values are:
  * `STABLE`: The schema is stable and will not change.
  * `NULL`: The schema is stable and will not change. The value may be `NULL` if the record was created before the `maturity_level` field was added (release 2022.37).
  * `EVOLVING`: The schema is not stable and may change.
  * `DEPRECATED`: The schema is deprecated and the Lakeflow pipelines runtime may stop producing this event at any time.
* `error STRING`: If an error occurred, details describing the error.
* `details STRING NOT NULL`: A JSON object containing structured details of the event. This is the primary field used for analyzing events.
* `event_type STRING NOT NULL`: The event type.

## Examples

For more examples, refer to [Pipeline event log](https://docs.databricks.com/aws/en/ldp/monitor-event-logs.md).

```sql
-- View the events on a materialized view
> SELECT timestamp, message, details
  FROM event_log(table(my_mv))
  WHERE level in ('INFO', 'WARN', 'ERROR')
  ORDER BY timestamp;

timestamp, message, details
---------------------------
2023-08-12 01:03:05.000, 'Flow "my_mv" is STARTING.', '{"flow_progress":{"status":"STARTING"}}'

-- Create a temp view with the latest update to the table/pipeline
> CREATE OR REPLACE TEMP VIEW latest_update AS
  SELECT origin.update_id AS id FROM event_log('<pipeline-ID>')
  WHERE event_type = 'create_update' ORDER BY timestamp DESC LIMIT 1;

-- Query lineage information
> SELECT
  details:flow_definition.output_dataset as output_dataset,
  details:flow_definition.input_datasets as input_dataset
FROM
  event_log('<pipeline-ID>'),
  latest_update
WHERE
  event_type = 'flow_definition' AND origin.update_id = latest_update.id;

output_dataset, input_dataset
-----------------------------
customers, null
sales_orders_raw, null
sales_orders_cleaned, ["customers", "sales_orders_raw"]
sales_order_in_la, ["sales_orders_cleaned"]

-- Query data quality expectation history for a streaming table
> WITH expectations_parsed AS (
    SELECT
      explode(
        from_json(
          details:flow_progress.data_quality.expectations,
          "array<struct<name: string, dataset: string, passed_records: int, failed_records: int>>"
        )
      ) row_expectations
    FROM
      event_log(table(my_st)),
      latest_update
    WHERE
      event_type = 'flow_progress'
      AND origin.update_id = latest_update.id
  )
  SELECT
    row_expectations.dataset as dataset,
    row_expectations.name as expectation,
    SUM(row_expectations.passed_records) as passing_records,
    SUM(row_expectations.failed_records) as failing_records
  FROM expectations_parsed
  GROUP BY
    row_expectations.dataset,
    row_expectations.name;

dataset, expectation, passing_records, failing_records
------------------------------------------------------
sales_orders_cleaned, valid_order_number, 4083, 0
```

## Related articles

* [Monitor pipelines](https://docs.databricks.com/aws/en/ldp/observability.md)
* [Pipeline event log](https://docs.databricks.com/aws/en/ldp/monitor-event-logs.md)
* [Spark Declarative Pipelines on Lakeflow](https://docs.databricks.com/aws/en/ldp/index.md)
* [CREATE STREAMING TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-table.md)
