[ 
https://issues.apache.org/jira/browse/ARROW-1491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16348891#comment-16348891
 ] 

ASF GitHub Bot commented on ARROW-1491:
---------------------------------------

cpcloud commented on a change in pull request #1387: ARROW-1491: [C++] Add 
casting implementations from strings to numbers or boolean
URL: https://github.com/apache/arrow/pull/1387#discussion_r165417094
 
 

 ##########
 File path: cpp/src/arrow/compute/kernels/cast.cc
 ##########
 @@ -703,6 +706,106 @@ struct CastFunctor<T, DictionaryType,
   }
 };
 
+// ----------------------------------------------------------------------
+// String to Number
+
+template <typename T>
+typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, 
int8_t>::value &&
+                            !std::is_same<T, uint8_t>::value,
+                        T>::type
+castStringToNumeric(const std::string& s) {
+  return boost::lexical_cast<T>(s);
+}
+
+template <typename T>
+typename std::enable_if<std::is_same<T, int8_t>::value || std::is_same<T, 
uint8_t>::value,
+                        T>::type
+castStringToNumeric(const std::string& s) {
+  // Convert to int before casting to T
+  // because boost::lexical_cast does not support 8bit int/uint.
+  return boost::numeric_cast<T>(boost::lexical_cast<int>(s));
+}
+
+template <typename O>
+struct CastFunctor<O, StringType,
+                   typename std::enable_if<std::is_base_of<Number, 
O>::value>::type> {
+  void operator()(FunctionContext* ctx, const CastOptions& options,
+                  const ArrayData& input, ArrayData* output) {
+    using out_type = typename O::c_type;
+    StringArray input_array(input.Copy());
+
+    auto out_data = GetMutableValues<out_type>(output, 1);
+
+    std::function<out_type(const std::string&)> cast_func;
 
 Review comment:
   Is this variable used anywhere? It looks like you might've replaced it with 
the `castStringToNumeric` function.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [C++] Add casting implementations from strings to numbers or boolean
> --------------------------------------------------------------------
>
>                 Key: ARROW-1491
>                 URL: https://issues.apache.org/jira/browse/ARROW-1491
>             Project: Apache Arrow
>          Issue Type: New Feature
>          Components: C++
>            Reporter: Wes McKinney
>            Assignee: Licht Takeuchi
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to