Skip to content

Fix toWeek monotonicity#24446

Merged
CurtizJ merged 4 commits intoClickHouse:masterfrom
amosbird:fixdate
May 26, 2021
Merged

Fix toWeek monotonicity#24446
CurtizJ merged 4 commits intoClickHouse:masterfrom
amosbird:fixdate

Conversation

@amosbird
Copy link
Copy Markdown
Collaborator

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Bug Fix

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix incorrect monotonicity of toWeek function. This fixes #24422 . This bug was introduced in #5212 , and was exposed later by smarter partition pruner.

Detailed description / Documentation draft:

.

@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label May 24, 2021
@CurtizJ CurtizJ self-assigned this May 24, 2021
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.

But function toStartOfWeek is always monotonic and it's better to keep this behaviour.

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.

The same about toYearWeek.

Comment on lines 140 to 141
Copy link
Copy Markdown
Member

@CurtizJ CurtizJ May 24, 2021

Choose a reason for hiding this comment

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

This looks wrong, because, it will erroneously return true for ranges, that start at the same week, but last more than year and will return false for ranges, that are in one year, but start at different weeks. I think, it's better to use ToStartOfYearImpl as FactorTransform for toWeek like it is done, e.g. for function toMonth in DateTimeTransforms.h.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. I didn't understand the code style. It should be trivial :) Updated

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.

ToStartOfYearImpl? We need to check, that two dates belong to the same year.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

but toStartOfWeek contains year

┌─toStartOfWeek(now())─┐
│           2021-05-23 │
└──────────────────────┘

Copy link
Copy Markdown
Member

@CurtizJ CurtizJ May 24, 2021

Choose a reason for hiding this comment

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

Yes, but toWeek in range of one year can be treated as monotonic, but toStartOfWeek doesn't allow this.

Copy link
Copy Markdown
Collaborator Author

@amosbird amosbird May 24, 2021

Choose a reason for hiding this comment

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

Ah, right. I failed to understand it twice somehow ...

@CurtizJ
Copy link
Copy Markdown
Member

CurtizJ commented May 26, 2021

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented May 26, 2021

Command update: success

Branch has been successfully updated

@CurtizJ
Copy link
Copy Markdown
Member

CurtizJ commented May 26, 2021

No new tests failed.

CurtizJ added a commit that referenced this pull request May 27, 2021
Backport #24446 to 21.4: Fix toWeek monotonicity
vitlibar pushed a commit that referenced this pull request Jun 22, 2021
Backport #24446 to 21.3: Fix toWeek monotonicity
vitlibar pushed a commit that referenced this pull request Jun 22, 2021
Backport #24446 to 20.8: Fix toWeek monotonicity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Date range filter doesn't work for table partitioned by toWeek

3 participants