cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How much USD are you spending on Databricks?

Hubert-Dudek
Esteemed Contributor III

Join two system tables and get exactly how much USD you are spending.

The short version of the query:

 

SELECT 
    u.usage_date,
    u.sku_name,
    SUM(u.usage_quantity * p.pricing.default) AS total_spent,
    p.currency_code
FROM 
    system.billing.usage u
LEFT JOIN 
    system.billing.list_prices p
ON 
    u.sku_name = p.sku_name
    AND u.cloud = p.cloud
    AND u.usage_start_time < COALESCE(p.price_end_time, date'2029-12-31')
    AND u.usage_end_time > p.price_start_time
GROUP BY 
    ALL
ORDER BY 
    ALL;

 

Extended version (which is handling potential price overlap):

 

SELECT 
    u.usage_date,
    u.sku_name,
    SUM(
        (UNIX_TIMESTAMP(
            LEAST(u.usage_end_time, COALESCE(p.price_end_time, date'2029-12-31'))
        ) -
        UNIX_TIMESTAMP(
            GREATEST(u.usage_start_time, p.price_start_time)
        ))
        / (UNIX_TIMESTAMP(u.usage_end_time) - UNIX_TIMESTAMP(u.usage_start_time))
        * u.usage_quantity * p.pricing.default
    ) AS total_spent,
    p.currency_code
FROM 
    system.billing.usage u
LEFT JOIN 
    system.billing.list_prices p
ON 
    u.sku_name = p.sku_name
    AND u.cloud = p.cloud
    AND u.usage_start_time < COALESCE(p.price_end_time, date'2029-12-31')
    AND u.usage_end_time > p.price_start_time
GROUP BY 
    ALL
ORDER BY 
    ALL;

 

system_pig.png

1 REPLY 1

jose_gonzalez
Databricks Employee
Databricks Employee

Thank you for sharing this information @Hubert-Dudek 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group