bkietz commented on code in PR #14659:
URL: https://github.com/apache/arrow/pull/14659#discussion_r1025425267
##########
cpp/src/arrow/compute/exec/expression_test.cc:
##########
@@ -69,6 +70,39 @@ Expression true_unless_null(Expression argument) {
return call("true_unless_null", {std::move(argument)});
}
+Expression add(Expression l, Expression r) {
+ return call("add", {std::move(l), std::move(r)});
+}
+
+namespace arrow_literals {
+
+using namespace std::chrono_literals;
+
+inline auto operator""_ts(const char* c, size_t s) {
+ return [s = StringScalar(std::string{c, s})](TimeUnit::type unit) {
+ return literal(*s.CastTo(timestamp(unit)));
+ };
+}
+
+} // namespace arrow_literals
+
+template <typename Rep, typename Period>
+Expression literal(std::chrono::duration<Rep, Period> d) {
+ int64_t int_value = d.count();
+ TimeUnit::type unit;
+ if constexpr (std::is_same_v<Period, std::nano>) {
+ unit = TimeUnit::NANO;
+ } else if constexpr (std::is_same_v<Period, std::micro>) {
+ unit = TimeUnit::MICRO;
+ } else if constexpr (std::is_same_v<Period, std::milli>) {
+ unit = TimeUnit::MILLI;
+ } else {
+ unit = TimeUnit::SECOND;
+ int_value = std::chrono::duration_cast<std::chrono::seconds>(d).count();
+ }
+ return literal(*MakeScalar(int_value)->CastTo(duration(unit)));
+}
Review Comment:
@pitrou I've removed `<chrono>`; for these constructors all we really needed
was `<ratio>` which is definitely tiny. How's that?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]