You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ag...@apache.org on 2020/05/21 23:34:19 UTC

[arrow] branch master updated: ARROW-8855: [Rust] [Integration] Complete record_batch_from_json types

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

agrove 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 4c5dccb  ARROW-8855: [Rust] [Integration] Complete record_batch_from_json types
4c5dccb is described below

commit 4c5dccb10e6dbe7c5068ec057db1db506e107d66
Author: Neville Dipale <ne...@gmail.com>
AuthorDate: Thu May 21 17:33:50 2020 -0600

    ARROW-8855: [Rust] [Integration] Complete record_batch_from_json types
    
    Adds missing types in `record_batch_from_json`.
    This however excludes list types, we can add them separately.
    
    Closes #7242 from nevi-me/ARROW-8855
    
    Authored-by: Neville Dipale <ne...@gmail.com>
    Signed-off-by: Andy Grove <an...@gmail.com>
---
 rust/arrow/src/compute/kernels/cast.rs               |  4 ++++
 .../src/bin/arrow-json-integration-test.rs           | 20 +++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/rust/arrow/src/compute/kernels/cast.rs b/rust/arrow/src/compute/kernels/cast.rs
index beaf2ac..f443e5a 100644
--- a/rust/arrow/src/compute/kernels/cast.rs
+++ b/rust/arrow/src/compute/kernels/cast.rs
@@ -327,9 +327,13 @@ pub fn cast(array: &ArrayRef, to_type: &DataType) -> Result<ArrayRef> {
 
         // temporal casts
         (Int32, Date32(_)) => cast_array_data::<Date32Type>(array, to_type.clone()),
+        (Int32, Time32(_)) => cast_array_data::<Date32Type>(array, to_type.clone()),
         (Date32(_), Int32) => cast_array_data::<Int32Type>(array, to_type.clone()),
+        (Time32(_), Int32) => cast_array_data::<Int32Type>(array, to_type.clone()),
         (Int64, Date64(_)) => cast_array_data::<Date64Type>(array, to_type.clone()),
+        (Int64, Time64(_)) => cast_array_data::<Date64Type>(array, to_type.clone()),
         (Date64(_), Int64) => cast_array_data::<Int64Type>(array, to_type.clone()),
+        (Time64(_), Int64) => cast_array_data::<Int64Type>(array, to_type.clone()),
         (Date32(DateUnit::Day), Date64(DateUnit::Millisecond)) => {
             let date_array = array.as_any().downcast_ref::<Date32Array>().unwrap();
             let mut b = Date64Builder::new(array.len());
diff --git a/rust/integration-testing/src/bin/arrow-json-integration-test.rs b/rust/integration-testing/src/bin/arrow-json-integration-test.rs
index d5ffbf3..f562adf 100644
--- a/rust/integration-testing/src/bin/arrow-json-integration-test.rs
+++ b/rust/integration-testing/src/bin/arrow-json-integration-test.rs
@@ -25,7 +25,7 @@ use arrow::array::{
     Float64Builder, Int16Builder, Int32Builder, Int64Builder, Int8Builder, NullArray,
     StringBuilder, UInt16Builder, UInt32Builder, UInt64Builder, UInt8Builder,
 };
-use arrow::datatypes::{DataType, Schema};
+use arrow::datatypes::{DataType, DateUnit, IntervalUnit, Schema};
 use arrow::error::{ArrowError, Result};
 use arrow::ipc::reader::FileReader;
 use arrow::ipc::writer::FileWriter;
@@ -156,7 +156,10 @@ fn record_batch_from_json(
                 }
                 Arc::new(b.finish())
             }
-            DataType::Int32 => {
+            DataType::Int32
+            | DataType::Date32(DateUnit::Day)
+            | DataType::Time32(_)
+            | DataType::Interval(IntervalUnit::YearMonth) => {
                 let mut b = Int32Builder::new(json_col.count);
                 for (is_valid, value) in json_col
                     .validity
@@ -171,9 +174,15 @@ fn record_batch_from_json(
                     }
                     .unwrap();
                 }
-                Arc::new(b.finish())
+                let array = Arc::new(b.finish()) as ArrayRef;
+                arrow::compute::cast(&array, field.data_type()).unwrap()
             }
-            DataType::Int64 => {
+            DataType::Int64
+            | DataType::Date64(DateUnit::Millisecond)
+            | DataType::Time64(_)
+            | DataType::Timestamp(_, _)
+            | DataType::Duration(_)
+            | DataType::Interval(IntervalUnit::DayTime) => {
                 let mut b = Int64Builder::new(json_col.count);
                 for (is_valid, value) in json_col
                     .validity
@@ -188,7 +197,8 @@ fn record_batch_from_json(
                     }
                     .unwrap();
                 }
-                Arc::new(b.finish())
+                let array = Arc::new(b.finish()) as ArrayRef;
+                arrow::compute::cast(&array, field.data_type()).unwrap()
             }
             DataType::UInt8 => {
                 let mut b = UInt8Builder::new(json_col.count);