-
Notifications
You must be signed in to change notification settings - Fork 187
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
Changes from 1 commit
3c57c4b
e449856
98f5ece
9f21aca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,3 +274,7 @@ BUCKAROO_DEPS | |
|
||
# Visual Studio Code | ||
/.vscode/ | ||
|
||
# Vim | ||
*.swp | ||
*.swo |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,4 +113,69 @@ ItemView ColumnDateTime::GetItem(size_t index) const { | |
return data_->GetItem(index); | ||
} | ||
|
||
|
||
ColumnDateTime64::ColumnDateTime64() | ||
: Column(Type::CreateDateTime64(3ul)) | ||
, data_(std::make_shared<ColumnDecimal>(18ul, 3ul)) | ||
{} | ||
|
||
ColumnDateTime64::ColumnDateTime64(size_t precision) | ||
: Column(Type::CreateDateTime64(precision)) | ||
, data_(std::make_shared<ColumnDecimal>(18ul, precision)) | ||
{} | ||
|
||
|
||
void ColumnDateTime64::Append(const Int128& value) { | ||
data_->Append(value); | ||
} | ||
|
||
void ColumnDateTime64::Append(const std::string& value) { | ||
data_->Append(value); | ||
} | ||
|
||
|
||
Int128 ColumnDateTime64::At(size_t n) const { | ||
|
||
return data_->At(n); | ||
} | ||
|
||
void ColumnDateTime64::Append(ColumnRef column) { | ||
if (auto col = column->As<ColumnDateTime64>()) { | ||
data_->Append(col->data_); | ||
} | ||
} | ||
|
||
bool ColumnDateTime64::Load(CodedInputStream* input, size_t rows) { | ||
return data_->Load(input, rows); | ||
} | ||
|
||
void ColumnDateTime64::Save(CodedOutputStream* output) { | ||
data_->Save(output); | ||
} | ||
|
||
void ColumnDateTime64::Clear() { | ||
data_->Clear(); | ||
} | ||
size_t ColumnDateTime64::Size() const { | ||
return data_->Size(); | ||
} | ||
|
||
ItemView ColumnDateTime64::GetItem(size_t index) const { | ||
return data_->GetItem(index); | ||
} | ||
|
||
void ColumnDateTime64::Swap(Column& other) { | ||
auto& col = dynamic_cast<ColumnDateTime64&>(other); | ||
data_.swap(col.data_); | ||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. that would blow up terribly, do you mean
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Why appending when you can swap? |
||
|
||
return result; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#pragma once | ||
|
||
#include "decimal.h" | ||
#include "numeric.h" | ||
|
||
#include <ctime> | ||
|
@@ -82,4 +83,44 @@ class ColumnDateTime : public Column { | |
std::shared_ptr<ColumnUInt32> data_; | ||
}; | ||
|
||
|
||
/** */ | ||
class ColumnDateTime64 : public Column { | ||
public: | ||
ColumnDateTime64(); | ||
|
||
ColumnDateTime64(size_t); | ||
|
||
|
||
/// Appends one element to the end of column. | ||
void Append(const Int128& value); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Please add method |
||
public: | ||
/// Appends content of given column to the end of current one. | ||
void Append(ColumnRef column) override; | ||
|
||
/// Loads column data from input stream. | ||
bool Load(CodedInputStream* input, size_t rows) override; | ||
|
||
/// Clear column data . | ||
void Clear() override; | ||
|
||
/// Saves column data to output stream. | ||
void Save(CodedOutputStream* output) override; | ||
|
||
/// Returns count of rows in the column. | ||
size_t Size() const override; | ||
|
||
/// Makes slice of the current column. | ||
ColumnRef Slice(size_t begin, size_t len) override; | ||
|
||
void Swap(Column& other) override; | ||
|
||
ItemView GetItem(size_t index) const override; | ||
private: | ||
std::shared_ptr<ColumnDecimal> data_; | ||
}; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ class Type { | |
String, | ||
FixedString, | ||
DateTime, | ||
DateTime64, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
Date, | ||
Array, | ||
Nullable, | ||
|
@@ -76,6 +77,8 @@ class Type { | |
|
||
static TypeRef CreateDateTime(); | ||
|
||
static TypeRef CreateDateTime64(size_t precision); | ||
|
||
static TypeRef CreateDecimal(size_t precision, size_t scale); | ||
|
||
static TypeRef CreateIPv4(); | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. please make it |
||
|
||
std::string GetName() const; | ||
|
||
inline size_t GetPrecision() const { return precision_; } | ||
|
||
private: | ||
size_t precision_; | ||
}; | ||
|
||
class EnumType : public Type { | ||
public: | ||
EnumType(Type::Code type, const std::vector<EnumItem>& items); | ||
|
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.