Skip to content

Commit

Permalink
Make arrow.flight.Timestamp truely nanoseconds precision
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Nov 8, 2024
1 parent b193c4f commit 65032f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 6 additions & 12 deletions cpp/src/arrow/flight/flight_internals_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,9 @@ TEST(FlightTypes, FlightDescriptor) {
TEST(FlightTypes, FlightEndpoint) {
ASSERT_OK_AND_ASSIGN(auto location1, Location::ForGrpcTcp("localhost", 1024));
ASSERT_OK_AND_ASSIGN(auto location2, Location::ForGrpcTls("localhost", 1024));
// 2023-06-19 03:14:06.004330100
// We must use microsecond resolution here for portability.
// std::chrono::system_clock::time_point may not provide nanosecond
// resolution on some platforms such as Windows.
// 2023-06-19 03:14:06.004339123
const auto expiration_time_duration =
std::chrono::seconds{1687144446} + std::chrono::nanoseconds{4339000};
std::chrono::seconds{1687144446} + std::chrono::nanoseconds{4339123};
Timestamp expiration_time(
std::chrono::duration_cast<Timestamp::duration>(expiration_time_duration));
std::vector<FlightEndpoint> values = {
Expand All @@ -210,7 +207,7 @@ TEST(FlightTypes, FlightEndpoint) {
"<FlightEndpoint ticket=<Ticket ticket='bar'> locations=[] "
"expiration_time=null app_metadata='DEADBEEF'>",
"<FlightEndpoint ticket=<Ticket ticket='foo'> locations=[] "
"expiration_time=2023-06-19 03:14:06.004339000 app_metadata=''>",
"expiration_time=2023-06-19 03:14:06.004339123 app_metadata=''>",
"<FlightEndpoint ticket=<Ticket ticket='foo'> locations="
"[grpc+tcp://localhost:1024] expiration_time=null app_metadata=''>",
"<FlightEndpoint ticket=<Ticket ticket='bar'> locations="
Expand Down Expand Up @@ -271,12 +268,9 @@ TEST(FlightTypes, PollInfo) {
auto desc = FlightDescriptor::Command("foo");
auto endpoint = FlightEndpoint{Ticket{"foo"}, {}, std::nullopt, ""};
auto info = MakeFlightInfo(schema, desc, {endpoint}, -1, 42, true, "");
// 2023-06-19 03:14:06.004330100
// We must use microsecond resolution here for portability.
// std::chrono::system_clock::time_point may not provide nanosecond
// resolution on some platforms such as Windows.
// 2023-06-19 03:14:06.004339123
const auto expiration_time_duration =
std::chrono::seconds{1687144446} + std::chrono::nanoseconds{4339000};
std::chrono::seconds{1687144446} + std::chrono::nanoseconds{4339123};
Timestamp expiration_time(
std::chrono::duration_cast<Timestamp::duration>(expiration_time_duration));
std::vector<PollInfo> values = {
Expand All @@ -292,7 +286,7 @@ TEST(FlightTypes, PollInfo) {
"progress=null expiration_time=null>",
"<PollInfo info=" + info.ToString() +
" descriptor=<FlightDescriptor cmd='poll'> "
"progress=0.1 expiration_time=2023-06-19 03:14:06.004339000>",
"progress=0.1 expiration_time=2023-06-19 03:14:06.004339123>",
"<PollInfo info=null descriptor=null progress=null expiration_time=null>",
};

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/flight/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class FlightServerBase;
/// > all minutes are 60 seconds long, i.e. leap seconds are "smeared"
/// > so that no leap second table is needed for interpretation. Range
/// > is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
using Timestamp = std::chrono::system_clock::time_point;
using Timestamp =
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;

/// \brief A Flight-specific status code. Used to encode some
/// additional status codes into an Arrow Status.
Expand Down

0 comments on commit 65032f0

Please sign in to comment.