Skip to content

Add this year function - #48321

Closed
2063436123 wants to merge 3 commits into
ClickHouse:masterfrom
2063436123:add_this_year_function
Closed

2063436123 wants to merge 3 commits into
ClickHouse:masterfrom
2063436123:add_this_year_function

Conversation

@2063436123

@2063436123 2063436123 commented Apr 2, 2023 •

Copy link
Copy Markdown

Changelog category (leave one):

  • New Feature

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

Add function year() with no arguments that returns current year.
year() = year(now()) = year(today()).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@CLAassistant

CLAassistant commented Apr 2, 2023 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@robot-clickhouse robot-clickhouse added the pr-feature Pull request with new product feature label Apr 2, 2023
@evillique evillique added the can be tested Allows running workflows for external contributors label Apr 2, 2023
@evillique evillique self-assigned this Apr 2, 2023
## toYear

Converts a date or date with time to a UInt16 number containing the year number (AD).
Also accepts zero arguments and returns the current year at one of the moments of query analysis. The same as ‘toYear(now())’ or ‘toYear(today())’.

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.

"at one of the moments of query analysis" sounds obvious and weird. Yes, the wording was copypasted from other places in this file. It would be nice if you could omit that phrase in all places in this document.

Also, it's just fine to mention toYear(now()) instead of toYear(now()) or toYear(today()).

--> "Also accepts zero arguments in which it returns the current year, i.e. toYear(now())"

## toYear

Converts a date or date with time to a UInt16 number containing the year number (AD).
Also accepts zero arguments and returns the current year at one of the moments of query analysis. The same as ‘toYear(now())’ or ‘toYear(today())’.

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.

From a usage POV, a zero-argument form of toYear/YEAR is nice, but the user will wonder why a similar syntax is not available for toQuarter()/toMonth()/toDayOfYear()/toDayOfMonth()/toDayOfWeek()/toHour()/toMinute()/toSecond(). It will be perceived as inconsistency. Would it be possible to implement the same also for the listed functions?

@2063436123 2063436123 Apr 7, 2023 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

maybe I should create a new function with name thisYear()? But it looks strange.

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.

@2063436123 Can't we just add this behavior to other functions?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@evillique yes, I'm planning to realize a new function thisYear().

@evillique evillique Apr 10, 2023 •

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.

Why is a separate function needed? Current solution is great and we only need to add similar behavior to other functions like quarter() = quarter(now()), month() = month(now()), etc

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry, I misunderstood your last comment, you are right, we should add this new syntax, of course, it will add a lot of new usages of functions.

@rschu1ze

Copy link
Copy Markdown
Member

@jjyep101 Could you please ask more specifically about certain behavior or design? The classes you mentioned are base classes used by different date-time related functions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This new bit of code is to display the current year when year() is called, correct?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why are you error checking a 0 argument size here? Don't you want 0 arguments to pass?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This bit of code is where it translates year() the same as year(now()), correct?

@alexey-milovidov

Copy link
Copy Markdown
Member

@evillique I'd prefer if only year will be available with zero arguments, not toYear.

@alexey-milovidov

Copy link
Copy Markdown
Member

I thought it was for MySQL compatibility, but I checked - MySQL does not have a function year without arguments.
Then, it does not make sense to add this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants