[
https://issues.apache.org/jira/browse/ARROW-1491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16280621#comment-16280621
]
ASF GitHub Bot commented on ARROW-1491:
---------------------------------------
wesm 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_r155317738
##########
File path: cpp/src/arrow/compute/kernels/cast.cc
##########
@@ -660,6 +663,100 @@ struct CastFunctor<T, DictionaryType,
}
};
+// ----------------------------------------------------------------------
+// String to Number
+
+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());
+
+ if (input_array.null_count() > 0) {
+ std::stringstream ss;
+ ss << "Failed to cast NA into " << output->type->ToString();
+ ctx->SetStatus(Status(StatusCode::SerializationError, ss.str()));
+ return;
+ }
+
+ auto out_data = GetMutableValues<out_type>(output, 1);
+
+ std::function<out_type(const std::string&)> cast_func;
+ if (output->type->id() == Type::INT8 || output->type->id() == Type::UINT8)
{
+ cast_func = [](const std::string& s) {
+ return boost::numeric_cast<out_type>(boost::lexical_cast<int>(s));
+ };
+ } else {
+ cast_func = [](const std::string& s) { return
boost::lexical_cast<out_type>(s); };
Review comment:
I think C++11 Lambdas actually incur more overhead than an inlined function.
We should instead introduce an auxiliary numeric cast functor that does this
switch at compile-time (resulting in an inlined function in the inner loop for
all possible types) rather than runtime
----------------------------------------------------------------
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:
[email protected]
> [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
> Labels: pull-request-available
> Fix For: 0.9.0
>
>
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)