Bird
Raised Fist0
dbtdata~20 mins

dbt-date for date spine - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
dbt-date Date Spine Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of dbt-date date_spine with daily frequency
What is the output of this dbt SQL code that uses dbt-date's date_spine macro to generate dates from 2024-01-01 to 2024-01-05 with daily frequency?
dbt
select * from {{ dbt_date.date_spine(
  datepart='day',
  start_date='2024-01-01',
  end_date='2024-01-05'
)}} order by date_day
A[{'date_day': '2024-01-01'}, {'date_day': '2024-01-02'}, {'date_day': '2024-01-03'}, {'date_day': '2024-01-04'}, {'date_day': '2024-01-05'}]
B[{'date_day': '2024-01-01'}, {'date_day': '2024-01-03'}, {'date_day': '2024-01-05'}]
C[{'date_day': '2024-01-02'}, {'date_day': '2024-01-03'}, {'date_day': '2024-01-04'}]
D[{'date_day': '2024-01-01'}, {'date_day': '2024-01-02'}, {'date_day': '2024-01-04'}, {'date_day': '2024-01-05'}]
Attempts:
2 left
💡 Hint
Think about what daily frequency means for a date range from start to end inclusive.
❓ data_output
intermediate
2:00remaining
Number of weeks generated by dbt-date date_spine
Using dbt-date's date_spine macro with weekly frequency from 2024-01-01 to 2024-02-01, how many rows will the resulting date spine table have?
dbt
select count(*) as week_count from {{ dbt_date.date_spine(
  datepart='week',
  start_date='2024-01-01',
  end_date='2024-02-01'
)}}
A4
B5
C6
D7
Attempts:
2 left
💡 Hint
Count the number of weeks starting from the first week containing 2024-01-01 up to the week containing 2024-02-01.
🔧 Debug
advanced
2:00remaining
Identify the error in dbt-date date_spine usage
What error will this dbt SQL code produce when running the date_spine macro with an invalid datepart 'fortnight'?
dbt
select * from {{ dbt_date.date_spine(
  datepart='fortnight',
  start_date='2024-01-01',
  end_date='2024-01-31'
)}}
ASyntax error: missing comma
BRuntime error: Invalid date format
CEmpty result set with no error
DCompilation error: Unsupported datepart 'fortnight'
Attempts:
2 left
💡 Hint
Check if 'fortnight' is a valid datepart for the macro.
🚀 Application
advanced
2:00remaining
Using dbt-date date_spine to fill missing dates in sales data
You have sales data with some missing dates. Which dbt-date date_spine usage will help create a complete date table from 2024-01-01 to 2024-01-10 to join and fill missing dates?
Aselect * from {{ dbt_date.date_spine(datepart='day', start_date='2024-01-01', end_date='2024-01-10') }}
Bselect * from {{ dbt_date.date_spine(datepart='month', start_date='2024-01-01', end_date='2024-01-10') }}
Cselect * from {{ dbt_date.date_spine(datepart='year', start_date='2024-01-01', end_date='2024-01-10') }}
Dselect * from {{ dbt_date.date_spine(datepart='hour', start_date='2024-01-01', end_date='2024-01-10') }}
Attempts:
2 left
💡 Hint
To fill missing daily sales, you need a daily date spine.
🧠 Conceptual
expert
3:00remaining
Why use dbt-date date_spine for time series analysis?
Which is the best reason to use dbt-date's date_spine macro when preparing data for time series analysis?
ATo filter out weekends and holidays from the dataset
BTo generate a continuous sequence of dates ensuring no gaps in the timeline
CTo aggregate data by random date intervals for sampling
DTo convert string dates into datetime format automatically
Attempts:
2 left
💡 Hint
Think about what a date spine provides for time series data.

Practice

(1/5)
1. What is the main purpose of using dbt-date to create a date spine in a data model?
easy
A. To join tables based on user IDs
B. To filter out invalid dates from data
C. To generate a continuous list of dates for analysis
D. To calculate the sum of sales values

Solution

  1. Step 1: Understand the concept of a date spine

    A date spine is a continuous list of dates covering a range, used to ensure consistent date coverage in analysis.
  2. Step 2: Identify the purpose of dbt-date

    dbt-date helps create this continuous list of dates automatically for use in data models.
  3. Final Answer:

    To generate a continuous list of dates for analysis -> Option C
  4. Quick Check:

    Date spine = continuous dates list [OK]
Hint: Date spine means continuous dates, not filtering or sums [OK]
Common Mistakes:
  • Confusing date spine with filtering data
  • Thinking it calculates aggregates
  • Assuming it joins unrelated tables
2. Which of the following is the correct syntax to create a date spine using dbt-date with a start date of '2023-01-01' and end date of '2023-01-05'?
easy
A. select * from dbt_date.spine('2023-01-01', '2023-01-05')
B. select * from dbt_date.spine(date_start = '2023-01-01', date_end = '2023-01-05')
C. select * from dbt_date.spine(start => '2023-01-01', finish => '2023-01-05')
D. select * from dbt_date.spine(start_date => '2023-01-01', end_date => '2023-01-05')

Solution

  1. Step 1: Recall dbt-date spine function syntax

    The correct syntax uses named parameters start_date and end_date with => to assign values.
  2. Step 2: Compare options to syntax

    select * from dbt_date.spine(start_date => '2023-01-01', end_date => '2023-01-05') matches the correct named parameter style. Others use incorrect parameter names or assignment styles.
  3. Final Answer:

    select * from dbt_date.spine(start_date => '2023-01-01', end_date => '2023-01-05') -> Option D
  4. Quick Check:

    Named params with => = select * from dbt_date.spine(start_date => '2023-01-01', end_date => '2023-01-05') [OK]
Hint: Use named params with => for dbt-date spine [OK]
Common Mistakes:
  • Using positional parameters instead of named
  • Wrong parameter names like start or finish
  • Using = instead of => for assignment
3. Given the following dbt model code snippet, what will be the output rows for the date spine?
select * from dbt_date.spine(start_date => '2023-01-01', end_date => '2023-01-03')
medium
A. [{'date': '2023-01-01'}, {'date': '2023-01-02'}, {'date': '2023-01-03'}]
B. [{'date': '2023-01-01'}, {'date': '2023-01-03'}]
C. [{'date': '2023-01-02'}]
D. Empty result set

Solution

  1. Step 1: Understand the date range in the spine

    The spine includes all dates from start_date to end_date inclusive, so from 2023-01-01 to 2023-01-03.
  2. Step 2: List all dates in the range

    The dates are 2023-01-01, 2023-01-02, and 2023-01-03, each as a separate row.
  3. Final Answer:

    [{'date': '2023-01-01'}, {'date': '2023-01-02'}, {'date': '2023-01-03'}] -> Option A
  4. Quick Check:

    Date spine includes all dates in range [OK]
Hint: Date spine includes every date from start to end [OK]
Common Mistakes:
  • Skipping dates between start and end
  • Only returning start and end dates
  • Expecting empty results for valid range
4. You wrote this dbt model to create a date spine:
select * from dbt_date.spine(start_date => '2023-01-01', end_date => '2023-01-05', datepart => 'month')

But the output only shows one date: '2023-01-01'. What is the likely error?
medium
A. The end_date is before the start_date
B. Using 'month' for datepart returns only the first date of the month
C. The function requires datepart to be 'day' to generate daily dates
D. The syntax for start_date is incorrect

Solution

  1. Step 1: Understand the effect of datepart = 'month'

    Setting datepart to 'month' generates one date per month, usually the first day of each month.
  2. Step 2: Analyze why only one date appears

    Since the range is within January 2023, only the first day of January is returned.
  3. Final Answer:

    Using 'month' for datepart returns only the first date of the month -> Option B
  4. Quick Check:

    datepart 'month' = first day only [OK]
Hint: datepart 'month' returns one date per month, not daily [OK]
Common Mistakes:
  • Assuming datepart 'month' returns all days
  • Thinking end_date is invalid
  • Believing syntax error caused issue
5. You want to create a date spine that includes every Monday between '2023-01-01' and '2023-01-31' using dbt-date. Which approach correctly achieves this?
hard
A. Set datepart = 'day' and filter dates where extract(dow from date) = 1 (Monday)
B. Use datepart = 'week' and filter the spine for dates where extract(dow from date) = 1 (Monday)
C. Set datepart = 'month' and filter for Mondays
D. Use datepart = 'day' without filtering, then manually select Mondays later

Solution

  1. Step 1: Understand datepart options

    datepart = 'day' generates every day in the range, allowing filtering by weekday.
  2. Step 2: Filter for Mondays

    Extracting day of week (dow) and selecting where dow = 1 (Monday) filters the daily spine to only Mondays.
  3. Step 3: Why not 'week' or 'month'

    datepart = 'week' returns one date per week (usually Sunday), so filtering for Monday won't work. 'month' returns one date per month.
  4. Final Answer:

    Set datepart = 'day' and filter dates where extract(dow from date) = 1 (Monday) -> Option A
  5. Quick Check:

    Daily spine + filter Monday = Set datepart = 'day' and filter dates where extract(dow from date) = 1 (Monday) [OK]
Hint: Generate daily spine, then filter Mondays by weekday [OK]
Common Mistakes:
  • Using datepart 'week' expecting Mondays
  • Using 'month' which returns too few dates
  • Not filtering after generating spine
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard