You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/02/19 02:57:03 UTC

[arrow] branch master updated: ARROW-4565: [R] Fix decimal record batches with no null values

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new aeb40ed  ARROW-4565: [R] Fix decimal record batches with no null values
aeb40ed is described below

commit aeb40ed8bdb939662f43c6a38fd960294542e01b
Author: Javier Luraschi <ja...@hotmail.com>
AuthorDate: Mon Feb 18 20:56:53 2019 -0600

    ARROW-4565: [R] Fix decimal record batches with no null values
    
    Fix for https://issues.apache.org/jira/browse/ARROW-4565. We were missing to handle cases where decimal arrays have no null values.
    
    Regarding adding a test, there seems to be no way to convert arrays to `DecimalType`, if someone can thing of a workaround I'll add a test. Otherwise, there are a bunch of Arrow tests running in the [sparklyr](https://github.com/rstudio/sparklyr/) repo. I'm also planning to start testing against arrow devel in our Travis builds.
    
    Author: Javier Luraschi <ja...@hotmail.com>
    
    Closes #3640 from javierluraschi/bugfix/r-decimal-4565 and squashes the following commits:
    
    16d4e0330 <Javier Luraschi> ARROW-4565:  Fix decimal record batches with no null values
---
 r/src/array__to_vector.cpp | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/r/src/array__to_vector.cpp b/r/src/array__to_vector.cpp
index c531933..af9cdb4 100644
--- a/r/src/array__to_vector.cpp
+++ b/r/src/array__to_vector.cpp
@@ -460,12 +460,19 @@ class Converter_Decimal : public Converter {
     const auto& decimals_arr =
         internal::checked_cast<const arrow::Decimal128Array&>(*array);
 
-    internal::BitmapReader bitmap_reader(array->null_bitmap()->data(), array->offset(),
-                                         n);
+    if (array->null_count()) {
+      internal::BitmapReader bitmap_reader(array->null_bitmap()->data(), array->offset(),
+                                           n);
 
-    for (size_t i = 0; i < n; i++, bitmap_reader.Next(), ++p_data) {
-      *p_data = bitmap_reader.IsSet() ? std::stod(decimals_arr.FormatValue(i).c_str())
-                                      : NA_REAL;
+      for (size_t i = 0; i < n; i++, bitmap_reader.Next(), ++p_data) {
+        *p_data = bitmap_reader.IsSet() ? std::stod(decimals_arr.FormatValue(i).c_str())
+                                        : NA_REAL;
+      }
+    }
+    else {
+      for (size_t i = 0; i < n; i++, ++p_data) {
+        *p_data = std::stod(decimals_arr.FormatValue(i).c_str());
+      }
     }
 
     return Status::OK();