# Chalk operational tables
source: https://docs.chalk.ai/docs/chalksql/catalog/operational-tables

## Inspect scheduled jobs, job runs, query metadata, and online delta writes.

Use these tables in the chalk catalog to inspect schedules and query activity.
For spans, traces, and sessions, see Telemetry tables.

### chalk.jobs table

Use the native SQL server to list SQL jobs in your environment and scheduled jobs in its active deployment.
Each row describes a schedule, including schedules that have never run.

| Column           | Description                                                                                                   |
| ---------------- | ------------------------------------------------------------------------------------------------------------- |
| `name`           | Schedule name or fully qualified resolver name.                                                               |
| `kind`           | `sql`, `scheduled_query`, `scheduled_resolver`, or `scheduled_aggregation`.                                   |
| `schedule`       | Configured schedule expression.                                                                               |
| `state`          | `ACTIVE` or `SUSPENDED`.                                                                                      |
| `created_at`     | UTC timestamp when the schedule definition was created.                                                       |
| `resource_group` | Async SQL resource group for SQL jobs, otherwise NULL.                                                        |
| `job_id`         | Key for joining to `chalk.job_runs`. SQL jobs use their schedule ID. Deployment-defined jobs use `kind:name`. |

```sql
SELECT name, kind, schedule, state, created_at FROM chalk.jobs;
```

See Job statements for commands and permissions.

### Schedule a SQL statement

Use CREATE JOB to schedule a Chalk SQL statement.
See View run history for an example that queries one job's runs.

### chalk.job_runs table

Use chalk.job_runs to inspect recorded runs of the jobs listed in chalk.jobs.
The table includes scheduled and manually triggered runs. It also includes recorded skips and initialization failures.

| Column             | Description                                                                                   |
| ------------------ | --------------------------------------------------------------------------------------------- |
| `run_id`           | Run identifier from the scheduler.                                                            |
| `job_id`           | Key for joining to `chalk.jobs`.                                                              |
| `job_name`         | Schedule name or fully qualified resolver name.                                               |
| `job_kind`         | `sql`, `scheduled_query`, `scheduled_resolver`, or `scheduled_aggregation`.                   |
| `trigger_kind`     | `SCHEDULED`, `MANUAL`, or `API` when the scheduler provides the trigger kind. Otherwise NULL. |
| `status`           | Run status, such as `QUEUED`, `RUNNING`, `COMPLETED`, `FAILED`, or `SKIPPED`.                 |
| `status_message`   | Run status details, when available.                                                           |
| `triggered_at`     | UTC trigger time. For deployment-defined schedules, this is the run record's creation time.   |
| `completed_at`     | UTC end time, when available. Aggregate backfill runs return NULL.                            |
| `sql_operation_id` | Identifier in SQL query history, when available for a SQL job run.                            |

Join by job_id to include the job's configured schedule with each run.

```sql
SELECT r.job_name, j.schedule, r.trigger_kind, r.status, r.triggered_at, r.completed_at
FROM chalk.job_runs AS r
JOIN chalk.jobs AS j ON r.job_id = j.job_id
ORDER BY r.triggered_at DESC
LIMIT 50;
```

The table requires cron.read. SQL job runs are visible with workflow.read.
If the environment has scheduled aggregate backfills, the scan also requires deploy.read.

### chalk.query_log schema

The chalk.query_log schema consists of exactly one table, data, which is the query log table.
This table provides a list of query metadata for each operation ID, including which tables in the offline store
correspond to values queried in that operation ID. The data table has the following schema:

- operation_id, string, non-nullable: The unique identifier for the operation.
- environment_id, string, non-nullable: The environment ID where the operation was run.
- deployment_id, string: The deployment ID where the operation was run.
- operation_kind, string: The kind of operation that was run (inference, streaming, etc.).
- query_timestamp, timestamp: The value of now() that was used by the query.
- execution_started_at, timestamp: The time at which the operation started executing. Null if there were errors during planning.
- execution_finished_at, timestamp: The time at which the operation finished executing. Null if there were errors during execution.
- query_status, string: The status of the query (success, error, running, etc.).
- query_name, string: The query name for named queries, null otherwise.
- query_name_version, string: The version of the query for named queries, null otherwise.
- branch_name, string: The branch the query was run on, null if the query was not run on a branch.
- correlation_id, string: The correlation ID for the query, null if the query was not run with a correlation ID.
- value_tables: array of strings: The list of tables in the offline store that correspond to result values from this query.

### chalk.online_delta_writes schema

The chalk.online_delta_writes schema shows the digest state that online delta writes
(CHALK_ONLINE_DELTA_WRITES) keep for scheduled queries and scheduled aggregate backfills. Each run records a
digest of every row it writes to the online store, and the next run skips rows whose digest is unchanged.
Every schedule that writes to the online store appears here, with or without the setting enabled; runs made with
it disabled record no digests.

The schedules view has one row per schedule. A scheduled aggregate backfill has one row per resolver it
backfills, told apart by backfill_child. Its columns describe the schedule's two most recent runs:

- schedule_key, query_name, kind (scheduled_query or scheduled_aggregate_backfill), backfill_child
- current_run_id, previous_run_id
- retained_runs: runs whose digests are still in storage
- current_committed_attempts, current_uncommitted_attempts: shards or retries of the current run that
finished successfully, and those that recorded digests without finishing
- current_digest_files, current_digest_rows: the committed digests the next run compares against
- current_oldest_stored_at, current_latest_stored_at: the range of times the rows behind those digests were
last written to the online store
- previous_committed_attempts, previous_uncommitted_attempts, previous_digest_files, previous_digest_rows

The runs view has one row per retained run, with the schedule columns above plus run_id, is_current,
is_previous, committed_attempts, uncommitted_attempts and digest_files.

```sql
SELECT query_name, current_run_id, current_digest_rows, current_latest_stored_at
FROM chalk.online_delta_writes.schedules
```





