-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cpp-client): Honor Arrow TimeUnit when converting Timestamp and …
…Time64 to ColumnSource (#6609) This PR has adds two tests but leaves one disabled. The disabled one will fail on the main branch; that is why it is disabled. To run all the tests, execute this command. ``` ./gradlew :cpp-client:testCppClient ``` Then, if you rebase this branch onto your `nate/nightly/barrage_types` branch, you can re-enable the disabled test by editing the file `cpp-client/deephaven/tests/src/time_unit_test.cc` and removing the tag `[.hidden]`. Currently that tag is at line 75. You should then be able to run all the unit tests with the same gradlew command above and they should all pass.
- Loading branch information
Showing
9 changed files
with
323 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
cpp-client/deephaven/dhclient/include/public/deephaven/client/utility/internal_types.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
*/ | ||
#pragma once | ||
|
||
#include <arrow/flight/types.h> | ||
|
||
namespace deephaven::client::utility { | ||
/** | ||
* For Deephaven use only | ||
*/ | ||
namespace internal { | ||
/** | ||
* This class exists only for the benefit of the unit tests. Our normal DateTime class has a | ||
* native time resolution of nanoseconds. This class allows our unit tests to upload a | ||
* DateTime having a different time unit so we can confirm that the client and server both handle | ||
* it correctly. | ||
*/ | ||
template<arrow::TimeUnit::type UNIT> | ||
struct InternalDateTime { | ||
explicit InternalDateTime(int64_t value) : value_(value) {} | ||
|
||
int64_t value_ = 0; | ||
}; | ||
|
||
/** | ||
* This class exists only for the benefit of the unit tests. Our normal LocalTime class has a | ||
* native time resolution of nanoseconds. This class allows our unit tests to upload a | ||
* LocalTime having a different time unit so we can confirm that the client and server both handle | ||
* it correctly. | ||
*/ | ||
template<arrow::TimeUnit::type UNIT> | ||
struct InternalLocalTime { | ||
// Arrow Time64 only supports micro and nano units | ||
static_assert(UNIT == arrow::TimeUnit::MICRO || UNIT == arrow::TimeUnit::NANO); | ||
|
||
explicit InternalLocalTime(int64_t value) : value_(value) {} | ||
|
||
int64_t value_ = 0; | ||
}; | ||
} // namespace internal | ||
} // namespace deephaven::client::utility |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
cpp-client/deephaven/dhclient/src/arrowutil/arrow_column_source.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
*/ | ||
#include "deephaven/client/arrowutil/arrow_column_source.h" | ||
#include "deephaven/client/utility/arrow_util.h" | ||
|
||
using deephaven::client::utility::OkOrThrow; | ||
|
||
namespace deephaven::client::arrowutil { | ||
namespace internal { | ||
|
||
namespace { | ||
struct NanoScaleFactorVisitor final : public arrow::TypeVisitor { | ||
size_t result_ = 1; | ||
|
||
arrow::Status Visit(const arrow::Int8Type &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::Int16Type &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::Int32Type &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::Int64Type &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::FloatType &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::DoubleType &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::BooleanType &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::UInt16Type &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::StringType &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::TimestampType &type) final { | ||
result_ = ScaleFromUnit(type.unit()); | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::Date64Type &/*type*/) final { | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Visit(const arrow::Time64Type &type) final { | ||
result_ = ScaleFromUnit(type.unit()); | ||
return arrow::Status::OK(); | ||
} | ||
|
||
static size_t ScaleFromUnit(arrow::TimeUnit::type unit) { | ||
switch (unit) { | ||
case arrow::TimeUnit::SECOND: return 1'000'000'000; | ||
case arrow::TimeUnit::MILLI: return 1'000'000; | ||
case arrow::TimeUnit::MICRO: return 1'000; | ||
case arrow::TimeUnit::NANO: return 1; | ||
default: { | ||
auto message = fmt::format("Unhandled arrow::TimeUnit {}", static_cast<size_t>(unit)); | ||
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message)); | ||
} | ||
} | ||
} | ||
}; | ||
} // namespace | ||
|
||
size_t CalcTimeNanoScaleFactor(const arrow::Array &array) { | ||
NanoScaleFactorVisitor visitor; | ||
OkOrThrow(DEEPHAVEN_LOCATION_EXPR(array.type()->Accept(&visitor))); | ||
return visitor.result_; | ||
} | ||
} // namespace internal | ||
} // namespace deephaven::client::arrowutil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.