fix: max_streaksの二重タイムゾーン変換によるストリーク計算バグを修正#1559
Merged
Merged
Conversation
`AT TIME ZONE 'UTC'` の後に `AT TIME ZONE 'Asia/Tokyo'` を連鎖させると、 一度naiveなtimestampに変換された値を「これはJSTの時刻表記だ」と再解釈して しまい、意図した+9時間ではなく-9時間の変換になっていた。 結果、UTC 9-15時台(JSTの夜、コンテスト時間帯)に行われた提出だけ 偶然日付が一致し、それ以外の時間帯(日中の精進や早朝の提出など)は solve_date が1日ずれて計算され、本来連続しているストリークが streak_groups の判定で途切れてしまっていた。 Fixes #1549 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rK811gLsFrY6BiaZYYUW7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dbt/models/marts/max_streaks.sqlでAT TIME ZONE 'UTC'→AT TIME ZONE 'Asia/Tokyo'と2回連鎖させていたため、意図した「UTC+9時間」ではなく実質「UTC-9時間」の変換になっていたsolve_dateが1日ずれ、本来連続しているストリークがstreak_groupsの判定(前日との差が1日超なら切る)で誤って途切れていたRoot cause
timestamptz AT TIME ZONE 'UTC'で一度naiveなtimestampに変換した後、それを再度AT TIME ZONE 'Asia/Tokyo'すると、Postgresはその値を「JSTの時刻表記」として再解釈し、そこから9時間引いてUTCに変換する。単純にto_timestamp(epoch) AT TIME ZONE 'Asia/Tokyo'と1回だけ変換すれば正しくJSTのwall-clock(naive timestamp)が得られ、::dateも後続のセッションタイムゾーンに依存せず一意に決まる。Verification
atcoder-problems-2025-dbtスケジュールタスクの実行ログを確認し、2時間おきに実行され毎回ERROR=0で成功していることを確認済み(dbtが実行されていない/失敗しているわけではなく、ロジックの誤りが原因と特定)AT TIME ZONEの変換規則(timestamptz→timestampとtimestamp→timestamptzで意味が逆になる)を手動でトレースし、UTC時刻帯ごとに正しい日付とバグの日付がずれることを確認max_streaksはmaterialized='table'で毎回全量再作成されるため、本番データへの追加のバックフィル作業は不要。次回のスケジュール実行(2時間おき)で自動的に正しい値に再計算されるTest plan
docker compose run --rm dbt buildをローカルで実行し、max_streaksモデルが正常にビルドされ既存のテスト(unique/not_nullonuser_id)が通ることを確認max_streaksテーブルの値が更新され、Streak Rankingに正しい順位が反映されることを確認🤖 Generated with Claude Code
https://claude.ai/code/session_015rK811gLsFrY6BiaZYYUW7