Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Mar 1, 2024
1 parent fae7941 commit 81947e1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions velox/vector/arrow/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,33 @@ TypePtr importFromArrow(const ArrowSchema& arrowSchema) {

namespace {

std::optional<TimestampUnit> getTimestampUnit(const ArrowSchema& arrowSchema) {
const char* format = arrowSchema.dictionary ? arrowSchema.dictionary->format
: arrowSchema.format;
VELOX_USER_CHECK_NOT_NULL(format);
VELOX_USER_CHECK_GE(
strlen(format),
2,
"The arrow format string of timestamp type should contain 'ts'.");
VELOX_USER_CHECK_EQ(format[0], 't', "The first character should be 't'.");
VELOX_USER_CHECK_EQ(format[1], 's', "The second character should be 's'.");
if (strlen(format) > 2) {
switch (format[2]) {
case 's':
return TimestampUnit::SECOND;
case 'm':
return TimestampUnit::MILLISECOND;
case 'u':
return TimestampUnit::MICROSECOND;
case 'n':
return TimestampUnit::NANOSECOND;
default:
VELOX_UNREACHABLE();
}
}
return std::nullopt;
}

VectorPtr importFromArrowImpl(
const ArrowOptions& options,
ArrowSchema& arrowSchema,
Expand Down Expand Up @@ -1576,6 +1603,13 @@ VectorPtr importFromArrowImpl(
arrowArray.null_count,
wrapInBufferView);
} else if (type->isTimestamp()) {
const auto unit = getTimestampUnit(arrowSchema);
if (unit.has_value()) {
VELOX_USER_CHECK_EQ(
unit.value(),
options.timestampUnit,
"Timestamp unit mismatch between schema and arrow options.")
}
return createTimestampVector(
options,
pool,
Expand Down

0 comments on commit 81947e1

Please sign in to comment.