Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
gdliu3 committed Jul 26, 2024
1 parent d2024fd commit 87d468e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions be/src/vec/data_types/serde/data_type_datetimev2_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "data_type_datetimev2_serde.h"

#include <arrow/builder.h>
#include <cctz/civil_time.h>
#include <cctz/time_zone.h>

#include <chrono> // IWYU pragma: keep

Expand Down Expand Up @@ -115,10 +117,24 @@ void DataTypeDateTimeV2SerDe::write_column_to_arrow(const IColumn& column, const
if (scale > 3) {
uint32_t microsecond = datetime_val.microsecond();
timestamp = (timestamp * 1000000) + microsecond;
timestamp -= std::chrono::duration_cast<std::chrono::microseconds>(
cctz::convert(cctz::civil_second(1970, 1, 1, 0, 0, 0), ctz)
.time_since_epoch())
.count();
} else if (scale > 0) {
uint32_t millisecond = datetime_val.microsecond() / 1000;
timestamp = (timestamp * 1000) + millisecond;
timestamp -= std::chrono::duration_cast<std::chrono::milliseconds>(
cctz::convert(cctz::civil_second(1970, 1, 1, 0, 0, 0), ctz)
.time_since_epoch())
.count();
} else if (scale == 0) {
timestamp -= std::chrono::duration_cast<std::chrono::seconds>(
cctz::convert(cctz::civil_second(1970, 1, 1, 0, 0, 0), ctz)
.time_since_epoch())
.count();
}

checkArrowStatus(timestamp_builder.Append(timestamp), column.get_name(),
array_builder->type()->name());
}
Expand Down

0 comments on commit 87d468e

Please sign in to comment.