-
Notifications
You must be signed in to change notification settings - Fork 179
WIP: [Issue-36] Add DateTime64 data type. #38
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
Conversation
2051808
to
fb3170f
Compare
fc72ee7
to
3c57c4b
Compare
clickhouse/columns/date.cpp
Outdated
@@ -113,4 +113,69 @@ ItemView ColumnDateTime::GetItem(size_t index) const { | |||
return data_->GetItem(index); | |||
} | |||
|
|||
|
|||
ColumnDateTime64::ColumnDateTime64() | |||
: Column(Type::CreateDateTime64(3ul)) |
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.
Maybe we shouldn't provide a default constructor at all or come up with a different default precision. I will be happy to get feedback regarding this line.
clickhouse/columns/date.cpp
Outdated
} | ||
|
||
|
||
Int128 ColumnDateTime64::At(size_t n) const { |
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.
I Decided to use Int128 because ColumnDecimal deals with this type. Poco supports https://pocoproject.org/docs/Poco.DateTime.html, but DateTime64 in Clickhouse has a higher resolution than in Poco.
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.
Great start!
- Please add unit-tests!
- Please fix other issues.
size_t precision = col->Type()->As<DateTime64Type>()->GetPrecision(); | ||
auto result = std::make_shared<ColumnDateTime64>(precision); // TODO FIXME | ||
|
||
result->data_->Append(col); |
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.
Why appending when you can swap?
clickhouse/columns/date.h
Outdated
ColumnDateTime64(size_t); | ||
|
||
/// Appends one element to the end of column. | ||
void Append(const Int128& value); |
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.
I would rather use Int64 here, since it is a bit misleading to put 128-bit int into DateTime64 column
clickhouse/columns/date.h
Outdated
class ColumnDateTime64 : public Column { | ||
public: | ||
ColumnDateTime64(); | ||
ColumnDateTime64(size_t); |
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.
that should be explicit
clickhouse/columns/date.h
Outdated
/** */ | ||
class ColumnDateTime64 : public Column { | ||
public: | ||
ColumnDateTime64(); |
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.
I do not think that having a default precision here is a good thing, can you remove it?
clickhouse/columns/date.h
Outdated
void Append(const std::string& value); | ||
|
||
/// Returns element at given row number. | ||
Int128 At(size_t n) const; |
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.
I guess it makes sense to use Int64 here too.
|
||
/// Returns element at given row number. | ||
Int128 At(size_t n) const; | ||
|
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.
Please add method GetPrecision() const
@@ -26,6 +26,7 @@ class Type { | |||
String, | |||
FixedString, | |||
DateTime, | |||
DateTime64, |
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.
IMO that could break some implicit user assumptions, it is better to add new enum value to the end of the list.
|
||
ColumnRef ColumnDateTime64::Slice(size_t begin, size_t len) { | ||
auto col = data_->Slice(begin, len)->As<ColumnDecimal>(); | ||
size_t precision = col->Type()->As<DateTime64Type>()->GetPrecision(); |
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.
that would blow up terribly, do you mean col->Type()->As<DecimalType>()->GetPrecision()
? Also please add following to the DecimalType
:
inline size_t GetPrecision() const { return precision_; }
@@ -144,6 +147,18 @@ class DecimalType : public Type { | |||
const size_t precision_, scale_; | |||
}; | |||
|
|||
class DateTime64Type: public Type { | |||
public: | |||
DateTime64Type(size_t precision); |
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.
please make it explicit
…ers for Decimals and DateTime64
…ers for Decimals and DateTime64
What's the status of this PR? I would like to use this feature. Is there any way I could contribute or help anyway? |
Going to add tests, and we are good to go.