Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Chong Gao committed Dec 12, 2023
1 parent 5c2ec6a commit 6854225
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
17 changes: 11 additions & 6 deletions src/main/cpp/src/datetime_parser.cu
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ struct timestamp_components
__device__ __host__ thrust::tuple<cudf::timestamp_us, bool>
to_utc_timestamp(timestamp_components components, cudf::string_view const &time_zone)
{
// TODO replace the temp implementation
long v = 365L * 86400L * 1000000L * components.year + 30L * 86400L * 1000000L * components.month +
86400L * 1000000L * components.day + 3600L * 1000000L * components.hour +
60L * 1000000L * components.minute + 1000000L * components.second +
components.microseconds;
return thrust::make_tuple(cudf::timestamp_us{cudf::duration_us{v}}, true);
// TODO replace the fake implementation
long seconds = components.year * 365L * 86400L +
components.month * 30L * 86400L +
components.day * 86400L +
components.hour * 3600L +
components.minute * 60L +
components.second;
long us = seconds * 1000000L + components.microseconds;
return thrust::make_tuple(cudf::timestamp_us{cudf::duration_us{us}}, true);
}

__device__ __host__ inline bool is_whitespace(const char chr)
Expand Down Expand Up @@ -492,11 +495,13 @@ parse_string_to_timestamp(cudf::strings_column_view const &input,
}
else
{
// TODO update bitmask
return std::make_pair(std::move(timestamp_column), true);
}
}
else
{
// TODO update bitmask
return std::make_pair(std::move(timestamp_column), true);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/cpp/tests/datetime_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ struct DateTimeParserTest : public cudf::test::BaseFixture

TEST_F(DateTimeParserTest, ParseTimestamp)
{
auto const ts_col = timestamp_col{
-719162L, -354285L, -141714, -141438, -141437, -141432, -141427, -31463, -31453, -1, 0, 18335};
auto v = (2023L * 365L * 86400L + 11L * 30L * 86400L + 5L * 86400L + 3L * 3600L + 4L * 60L + 55L) * 1000000L;
auto const ts_col = timestamp_col{v, v, v + 123456};

auto const ts_strings =
cudf::test::strings_column_wrapper{"2023-11-05T03:04:55Z",
"2023-11-05T03:04:55 ",
"2023-11-05T03:04:55.123456 "};
"2023-11-05T03:04:55 ",
"2023-11-05T03:04:55.123456 "};
auto const parsed_ts =
cudf::strings::string_to_timestamp(cudf::strings_column_view(ts_strings),
"Z",
true,
true);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(ts_col, *parsed_ts);
spark_rapids_jni::string_to_timestamp(cudf::strings_column_view(ts_strings),
"Z",
true,
true);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(ts_col, *(parsed_ts.first));
}

0 comments on commit 6854225

Please sign in to comment.