Skip to content

Standardize courserun_is_current in dbt#1939

Merged
rachellougee merged 6 commits into
mainfrom
consolidate-courserun_is_current
Feb 24, 2026
Merged

Standardize courserun_is_current in dbt#1939
rachellougee merged 6 commits into
mainfrom
consolidate-courserun_is_current

Conversation

@rachellougee
Copy link
Copy Markdown
Contributor

What are the relevant tickets?

NA
noticed when reviewing #1906 (review)

Description (What does it do?)

Standardize courserun_is_current Logic in dbt, as currently its implemented in two different ways. But they should be consistent

How can this be tested?

dbt build --select int__combined__course_runs mitxonline_video_engagements_w_video_counts

Additional Context

Comment thread src/ol_dbt/macros/common_utils.sql.sql Outdated
Comment thread src/ol_dbt/macros/common_utils.sql.sql Outdated
Comment thread src/ol_dbt/macros/common_utils.sql.sql Outdated
{% macro is_courserun_current(courserun_start_on, courserun_end_on) %}
case
when
date(from_iso8601_timestamp({{ courserun_start_on }})) <= current_date
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might need to use the cross-database macro for timestamp handling in order for it to work locally with DuckDB.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we can't run these two models in duckdb, but I've added the cross-database macro to work with DuckDB

Comment thread src/ol_dbt/macros/cross_db_functions.sql Outdated
then true
when
{{ from_iso8601_timestamp('mitxonline_runs.courserun_start_on') }} <= current_date
and {{ from_iso8601_timestamp('mitxonline_runs.courserun_end_on') }} > current_date
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how important this detail is but should the new macro's logic match the older logic exactly? I'm wondering about how this code has ">" but the new code has ">="

Copy link
Copy Markdown
Contributor Author

@rachellougee rachellougee Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is doing a timestamp boundary comparison:
from_iso8601_timestamp(mitxonline_runs.courserun_end_on) > current_date

vs

the new code performs a date-based comparison:
cast(from_iso8601_timestamp(end_on_timestamp_str) as date) >= current_date

The old logic is time-precision based, while the new logic is date-based, so they behave slightly differently.

If we change from cast(from_iso8601_timestamp(end_on_timestamp_str) as date) >= current_date to cast(from_iso8601_timestamp(end_on_timestamp_str) as date) > current_date will produce false if end_date is today. Also, this field is not highly time-sensitive, given how frequently the dbt models are built, so a date-based comparison should be enough unless the requirements change in the future

Copy link
Copy Markdown
Contributor

@quazi-h quazi-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me. The only thing I was curious about was the. detail about greater than vs greater than or equal to for the logic with current_date.

@rachellougee rachellougee merged commit 381e4b5 into main Feb 24, 2026
6 checks passed
@rachellougee rachellougee deleted the consolidate-courserun_is_current branch February 24, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants