ClickHouse / ClickHouse

ClickHouse® is a real-time analytics DBMS
https://clickhouse.com
Apache License 2.0
36.81k stars 6.8k forks source link

Add function year() that returns current year #45305

Open qoega opened 1 year ago

qoega commented 1 year ago

Use case

Similar logic as in now() and today() it returns current year.

Describe the solution you'd like

year() = year(now()) = year(today())

Currently year() fails: Code: 42. DB::Exception: Number of arguments for function toYear doesn't match: passed 0, should be 1 or 2: While processing toYear(). (NUMBER_OF_ARGUMENTS_DOESNT_MATCH) (version 22.13.1.294 (official build))

UtkarshAnand7 commented 1 year ago

Hi, I am new to open source contribution and it could be a good first issue for me, can you please assign it to me ?

Regards, Utkarsh

PrathyushaModala commented 1 year ago

Hi @qoega Can I work on this issue??

UtkarshAnand7 commented 1 year ago

Hi @qoega Can I work on this issue??

Sure !

ishk9 commented 1 year ago

Hi @qoega can you mention the file in which the error is?

qoega commented 1 year ago

This error is just an error when I run this query from client.

ishk9 commented 1 year ago

@qoega I'm sorry, I meant to ask in which file do I need to add the year() function.

ucasfl commented 1 year ago

@ishaan9006 Please check src/Functions/toYear.cpp andsrc/Functions/FunctionDateOrDateTimeToSomething.h

Vikrant-Khedkar commented 1 year ago

is it still open?

ucasfl commented 1 year ago

is it still open?

It's still open.

PrathyushaModala commented 1 year ago

Hey @ucasfl I'm working on it..I will raise pr asap.

is it still open?

It's still open.

ucasfl commented 1 year ago

Hey @ucasfl I'm working on it..I will raise pr asap.

is it still open?

It's still open.

@PrathyushaModala OK.

2063436123 commented 1 year ago

@ucasfl Hi, Maybe we should write a new function like thisYear(). It seems that toYear(which alias is year), toDayOfYear() belong to the same kind of function whichboth take arguments,but thisYear(), today(), now() belong to a different kind of function, neither of which takes arguments.

ucasfl commented 1 year ago

@ucasfl Hi, Maybe we should write a new function like thisYear(). It seems that toYear(which alias is year), toDayOfYear() belong to the same kind of function whichboth take arguments,but thisYear(), today(), now() belong to a different kind of function, neither of which takes arguments.

@2063436123 I don't agree, functions in ClickHouse can be variadic, which means it can take different number of arguments, so this feature can be implemented inside toYear function, instead create a new function.

2063436123 commented 1 year ago

@ucasfl thanks, Could I work on this issue? I will realize year() function.

ucasfl commented 1 year ago

@ucasfl thanks, Could I work on this issue? I will realize year() function.

Sure!

2063436123 commented 1 year ago

@ucasfl #48321 Here is my pr, please check it.

ajinkyalanjewar commented 1 year ago

Hi, I am new to open source, could you please assign This task to me, if it is still open?