-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TestCustomQuery test that fails at beginning of year #6853
Conversation
The index name template uses week number and when we calculate the expected index names by adding 7 days to figure out the next week number, that doesn't work at the beginning of the year when the previous year includes a partial week. This fixes that by changing the code to figure out week numbers by incrementing by one day, generating index names, throwing those in a set, and then turning that into a sorted list.
# the index name is based on the week number and this handles the | ||
# end-of-year/beginning-of-year case correctly. | ||
for i in range(7): | ||
indices.add((now - datetime.timedelta(days=i)).strftime(template)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old version used now and now–7d as the index names. The new version only goes back to now-6d. I can't tell whether that's intentional or not, or whether it matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops--I forgot that range is open-ended.
import datetime
def old_way(template, date):
return [
(date - datetime.timedelta(days=7)).strftime(template),
date.strftime(template)
]
def new_way(template, date):
indices = set()
# NOTE(willkg): we have to build the list of indices this way because
# the index name is based on the week number and this handles the
# end-of-year/beginning-of-year case correctly.
for i in range(7):
indices.add((date - datetime.timedelta(days=i)).strftime(template))
return sorted(indices)
template = "socorro%Y%W"
deltas = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for i in deltas:
date = datetime.date.today() + datetime.timedelta(days=i)
print(f"{date}: old way:{old_way(template, date)} new way: {new_way(template, date)}")
2024-12-27: old way:['socorro202451', 'socorro202452'] new way: ['socorro202451', 'socorro202452']
2024-12-28: old way:['socorro202451', 'socorro202452'] new way: ['socorro202451', 'socorro202452']
2024-12-29: old way:['socorro202451', 'socorro202452'] new way: ['socorro202452']
2024-12-30: old way:['socorro202452', 'socorro202453'] new way: ['socorro202452', 'socorro202453']
2024-12-31: old way:['socorro202452', 'socorro202453'] new way: ['socorro202452', 'socorro202453']
2025-01-01: old way:['socorro202452', 'socorro202500'] new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-02: old way:['socorro202452', 'socorro202500'] new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-03: old way:['socorro202452', 'socorro202500'] new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-04: old way:['socorro202452', 'socorro202500'] new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-05: old way:['socorro202452', 'socorro202500'] new way: ['socorro202453', 'socorro202500']
2025-01-06: old way:['socorro202453', 'socorro202501'] new way: ['socorro202453', 'socorro202500', 'socorro202501']
2025-01-07: old way:['socorro202453', 'socorro202501'] new way: ['socorro202500', 'socorro202501']
2025-01-08: old way:['socorro202500', 'socorro202501'] new way: ['socorro202500', 'socorro202501']
2025-01-09: old way:['socorro202500', 'socorro202501'] new way: ['socorro202500', 'socorro202501']
2025-01-10: old way:['socorro202500', 'socorro202501'] new way: ['socorro202500', 'socorro202501']
2025-01-11: old way:['socorro202500', 'socorro202501'] new way: ['socorro202500', 'socorro202501']
2025-01-12: old way:['socorro202500', 'socorro202501'] new way: ['socorro202501']
2025-01-13: old way:['socorro202501', 'socorro202502'] new way: ['socorro202501', 'socorro202502']
2025-01-14: old way:['socorro202501', 'socorro202502'] new way: ['socorro202501', 'socorro202502']
2025-01-15: old way:['socorro202501', 'socorro202502'] new way: ['socorro202501', 'socorro202502']
2025-01-16: old way:['socorro202501', 'socorro202502'] new way: ['socorro202501', 'socorro202502']
^^^ That fixes the index names generation:
|
Thank you! |
The index name template uses week number and when we calculate the expected index names by adding 7 days to figure out the next week number, that doesn't work at the beginning of the year when the previous year includes a partial week.
This fixes that by changing the code to figure out week numbers by incrementing by one day, generating index names, throwing those in a set, and then turning that into a sorted list.