<?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 extract table-level execution time and resource allocation within a multi-table Job? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167732#M55769</link>
    <description>&lt;P&gt;Unable to access the link&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/250064"&gt;@Satyasai&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Sep 2026 06:03:25 GMT</pubDate>
    <dc:creator>Dolly0503</dc:creator>
    <dc:date>2026-09-07T06:03:25Z</dc:date>
    <item>
      <title>How to extract table-level execution time and resource allocation within a multi-table Job?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167727#M55767</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I am working on calculating accurate compute costs and execution times for individual tables within our Databricks environment, but I am running into an issue with metric granularity.&lt;/P&gt;&lt;P&gt;Currently, we are fetching execution data based on job_id. The problem is that a single job_id often executes multiple tables of varying sizes. Right now, our logic can only derive an average execution time across the entire job, which is highly inaccurate for attributing costs to a specific table.&lt;/P&gt;&lt;P&gt;To get precise, table-level cost metrics, we need to move away from job-level averages. Specifically, I am trying to find a way to extract:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Table-Specific Timestamps:&lt;/STRONG&gt; The exact execution start_time and end_time for an individual table running within a larger job.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Granular Resource Allocation:&lt;/STRONG&gt; The exact number of compute resources (DBUs, allocated vs. free resources) consumed &lt;I&gt;specifically during the time&lt;/I&gt; that individual table is actively running.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Are there specific System Tables (e.g., within system.information_schema or system.access), REST API endpoints, or Spark listener configurations that expose this level of granular, table-specific execution data? and also below am attaching my query.&lt;/P&gt;&lt;P&gt;WITH cost_agg AS (&lt;BR /&gt;SELECT job_id, day, SUM(cost_consumed) AS cost_val&lt;BR /&gt;FROM costing --Internal table&lt;BR /&gt;GROUP BY job_id, day&lt;BR /&gt;--goes to costing dashboard table for each job, for each day - adds up all the cost. Result is one row per job per day with total cost&lt;BR /&gt;),&lt;BR /&gt;base_data AS (&lt;BR /&gt;SELECT job_id, task_key,&lt;BR /&gt;to_date(period_start_time) as execution_date,&lt;BR /&gt;execution_duration_seconds&lt;BR /&gt;FROM system.lakeflow.job_task_run_timeline&lt;/P&gt;&lt;P&gt;),&lt;BR /&gt;task_avgs AS (&lt;BR /&gt;SELECT job_id, task_key, execution_date, avg(execution_duration_seconds) as avg_task_exec_for_day&lt;BR /&gt;FROM base_data&lt;BR /&gt;GROUP BY job_id, execution_date, task_key&lt;BR /&gt;--For each task within each job on each day, averages the execution time across all runs of that task that day.&lt;BR /&gt;-- e.g. prd-customers ran 3 times: 100s + 120s + 80s → avg = 100s&lt;BR /&gt;),&lt;BR /&gt;job_totals as (&lt;BR /&gt;select job_id, execution_date, greatest(sum(avg_task_exec_for_day),1) as total_task_seconds_for_day&lt;BR /&gt;from task_avgs&lt;BR /&gt;group by job_id, execution_date&lt;BR /&gt;--Sums all task averages per job per day to get the denominator for weightage.&lt;BR /&gt;),&lt;BR /&gt;table_costs as ( SELECT&lt;BR /&gt;ta.job_id, ta.execution_date, ta.task_key,&lt;BR /&gt;SPLIT_PART(ta.task_key, '-', 1) AS ctlg,&lt;BR /&gt;SPLIT_PART(ta.task_key, '-', 2) AS db_name,&lt;BR /&gt;SPLIT_PART(ta.task_key, '-', 3) AS tbl_name,&lt;BR /&gt;round(ta.avg_task_exec_for_day/jt.total_task_seconds_for_day, 5),&lt;BR /&gt;round(c.cost_val, 5) as job_cost_usd,&lt;BR /&gt;round((ta.avg_task_exec_for_day/jt.total_task_seconds_for_day) * c.cost_val, 5) as table_cost_usd&lt;BR /&gt;from task_avgs ta&lt;BR /&gt;join job_totals jt on ta.job_id = jt.job_id AND ta.execution_date = jt.execution_date&lt;BR /&gt;left join cost_agg c on c.job_id = ta.job_id AND c.day = ta.execution_date&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;select ctlg, db_name, tbl_name,&lt;BR /&gt;array_join(collect_set(cast(job_id as string)),',') as jobs_id,&lt;BR /&gt;count(distinct job_id) as jobs_count,&lt;BR /&gt;count(*) as times_run,&lt;BR /&gt;count(distinct execution_date) as days_run,&lt;BR /&gt;min(execution_date) as first_run_date,&lt;BR /&gt;max(execution_date) as last_run_date,&lt;BR /&gt;round(sum(table_cost_usd),5) as total_cost_usd,&lt;BR /&gt;ROUND(SUM(table_cost_usd) / NULLIF(COUNT(DISTINCT execution_date), 0), 5) AS avg_daily_cost_usd, -- ← replaced here&lt;BR /&gt;round(min(table_cost_usd),5) as min_daily_cost_usd,&lt;BR /&gt;round(max(table_cost_usd),5) as max_daily_cost_usd&lt;BR /&gt;from table_costs&lt;BR /&gt;where execution_date &amp;lt;= '2026-03-04' and ctlg = 'prd'&lt;BR /&gt;group by tbl_name, ctlg, db_name&lt;BR /&gt;order by total_cost_usd desc&lt;/P&gt;&lt;P&gt;Any guidance, query examples, or best practices would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2026 05:36:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167727#M55767</guid>
      <dc:creator>Dolly0503</dc:creator>
      <dc:date>2026-09-07T05:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract table-level execution time and resource allocation within a multi-table Job?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167730#M55768</link>
      <description>&lt;P&gt;&lt;A href="https://community.databricks.com/t5/data-engineering/how-to-calculate-cost-of-each-table-for-the-specific-databricks/td-p/167086," target="_blank"&gt;https://community.databricks.com/t5/data-engineering/how-to-calculate-cost-of-each-table-for-the-specific-databricks/td-p/167086,&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;This above may help you.&lt;BR /&gt;&lt;BR /&gt;OR use below Query for Reference&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;WITH table_queries AS (&lt;BR /&gt;SELECT&lt;BR /&gt;statement_id,&lt;BR /&gt;job_id,&lt;BR /&gt;task_id,&lt;BR /&gt;compute_id AS cluster_id,&lt;BR /&gt;-- Extract target table name or catalog.schema.table from query history&lt;BR /&gt;coalesce(executed_as_table, regexp_extract(query_text, '(?i)(?:INTO|UPDATE|TABLE|MERGE INTO)\\s+([a-zA-Z0-9_\\.-]+)', 1)) AS target_table,&lt;BR /&gt;from_unixtime(start_time_ms / 1000) AS table_execution_start,&lt;BR /&gt;from_unixtime(end_time_ms / 1000) AS table_execution_end,&lt;BR /&gt;(end_time_ms - start_time_ms) / 1000.0 AS execution_duration_seconds&lt;BR /&gt;FROM system.query.history&lt;BR /&gt;WHERE start_time_ms IS NOT NULL&lt;BR /&gt;AND end_time_ms IS NOT NULL&lt;BR /&gt;AND statement_type IN ('INSERT', 'MERGE', 'CREATE_TABLE_AS_SELECT', 'COPY')&lt;BR /&gt;),&lt;/P&gt;&lt;P&gt;cluster_hourly_costs AS (&lt;BR /&gt;SELECT&lt;BR /&gt;usage.cluster_id,&lt;BR /&gt;usage.usage_start_time,&lt;BR /&gt;usage.usage_end_time,&lt;BR /&gt;SUM(usage.usage_quantity * prices.price_start_price) AS cluster_cost_usd,&lt;BR /&gt;SUM(usage.usage_quantity) AS total_dbus&lt;BR /&gt;FROM system.billing.usage usage&lt;BR /&gt;JOIN system.billing.list_prices prices&lt;BR /&gt;ON usage.sku_name = prices.sku_name&lt;BR /&gt;AND usage.usage_start_time &amp;gt;= prices.price_start_time&lt;BR /&gt;AND (prices.price_end_time IS NULL OR usage.usage_start_time &amp;lt; prices.price_end_time)&lt;BR /&gt;GROUP BY usage.cluster_id, usage.usage_start_time, usage.usage_end_time&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;q.target_table,&lt;BR /&gt;q.job_id,&lt;BR /&gt;q.task_id,&lt;BR /&gt;MIN(q.table_execution_start) AS exact_start_time,&lt;BR /&gt;MAX(q.table_execution_end) AS exact_end_time,&lt;BR /&gt;SUM(q.execution_duration_seconds) AS total_active_seconds,&lt;BR /&gt;-- Calculate proportional DBU and USD cost attributed strictly to this table's query duration&lt;BR /&gt;ROUND(SUM(q.execution_duration_seconds / 3600.0 * c.total_dbus), 4) AS allocated_dbus,&lt;BR /&gt;ROUND(SUM((q.execution_duration_seconds / 3600.0) * c.cluster_cost_usd), 4) AS allocated_table_cost_usd&lt;BR /&gt;FROM table_queries q&lt;BR /&gt;JOIN cluster_hourly_costs c&lt;BR /&gt;ON q.cluster_id = c.cluster_id&lt;BR /&gt;AND q.table_execution_start &amp;gt;= c.usage_start_time&lt;BR /&gt;AND q.table_execution_end &amp;lt;= c.usage_end_time&lt;BR /&gt;WHERE q.target_table IS NOT NULL AND q.target_table != ''&lt;BR /&gt;GROUP BY q.target_table, q.job_id, q.task_id&lt;BR /&gt;ORDER BY allocated_table_cost_usd DESC;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2026 05:57:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167730#M55768</guid>
      <dc:creator>Satyasai</dc:creator>
      <dc:date>2026-09-07T05:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract table-level execution time and resource allocation within a multi-table Job?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167732#M55769</link>
      <description>&lt;P&gt;Unable to access the link&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/250064"&gt;@Satyasai&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2026 06:03:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167732#M55769</guid>
      <dc:creator>Dolly0503</dc:creator>
      <dc:date>2026-09-07T06:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract table-level execution time and resource allocation within a multi-table Job?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167736#M55770</link>
      <description>&lt;P&gt;Try this link&amp;nbsp;&lt;BR /&gt;&lt;A href="https://community.databricks.com/t5/data-engineering/how-to-calculate-cost-of-each-table-for-the-specific-databricks/td-p/167086" target="_blank"&gt;https://community.databricks.com/t5/data-engineering/how-to-calculate-cost-of-each-table-for-the-specific-databricks/td-p/167086&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2026 06:22:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-table-level-execution-time-and-resource/m-p/167736#M55770</guid>
      <dc:creator>Satyasai</dc:creator>
      <dc:date>2026-09-07T06:22:14Z</dc:date>
    </item>
  </channel>
</rss>

