You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/21 15:54:14 UTC

[GitHub] [arrow] lidavidm commented on a change in pull request #10712: ARROW-13307: [C++][Python][R] Use reflection-based enums for function options

lidavidm commented on a change in pull request #10712:
URL: https://github.com/apache/arrow/pull/10712#discussion_r674112394



##########
File path: cpp/src/arrow/compute/function_internal.h
##########
@@ -376,16 +359,31 @@ GenericFromScalar(const std::shared_ptr<Scalar>& value) {
   return holder.value;
 }
 
+template <typename T, typename U>
+using enable_if_same_result = enable_if_same<T, U, Result<T>>;
+
 template <typename T>
-static inline enable_if_primitive_ctype<typename EnumTraits<T>::Type, Result<T>>
-GenericFromScalar(const std::shared_ptr<Scalar>& value) {
-  ARROW_ASSIGN_OR_RAISE(auto raw_val,
-                        GenericFromScalar<typename EnumTraits<T>::CType>(value));
-  return ValidateEnumValue<T>(raw_val);
+static inline enable_if_same_result<T, TimeUnit::type> GenericFromScalar(
+    const std::shared_ptr<Scalar>& value) {
+  ARROW_ASSIGN_OR_RAISE(auto raw_val, GenericFromScalar<int32_t>(value));
+  switch (raw_val) {
+    case static_cast<int32_t>(TimeUnit::type::SECOND):
+      return TimeUnit::type::SECOND;
+    case static_cast<int32_t>(TimeUnit::type::MILLI):
+      return TimeUnit::type::MILLI;
+    case static_cast<int32_t>(TimeUnit::type::MICRO):
+      return TimeUnit::type::MICRO;
+    case static_cast<int32_t>(TimeUnit::type::NANO):
+      return TimeUnit::type::NANO;

Review comment:
       Current master actually uses a trait based approach on top of enum; only the value->string conversion need be spelled out: https://github.com/apache/arrow/blob/5889ebb99bb1d13b0a108ddc993f33148651e425/cpp/src/arrow/compute/api_scalar.cc#L56-L74
   
   This PR removes that, but doesn't convert enums outside of arrow::compute, so it spells out explicitly those enums used in FunctionOptions.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org