Skip to content

Commit fb8fb4a

Browse files
committed
ARROW-3878: [Rust] Improve primitive types
1 parent 1013a1d commit fb8fb4a

File tree

11 files changed

+693
-687
lines changed

11 files changed

+693
-687
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ matrix:
267267
- $TRAVIS_BUILD_DIR/ci/travis_script_ruby.sh
268268
# Rust
269269
- language: rust
270+
rust:
271+
- stable
272+
- nightly
273+
matrix:
274+
allow_failures:
275+
- rust: stable
276+
fast_finish: true
270277
cache: cargo
271278
addons:
272279
apt:
@@ -280,8 +287,7 @@ matrix:
280287
- if [ $ARROW_CI_RUST_AFFECTED != "1" ]; then exit; fi
281288
- $TRAVIS_BUILD_DIR/ci/travis_install_cargo.sh
282289
script:
283-
- RUSTUP_TOOLCHAIN=stable $TRAVIS_BUILD_DIR/ci/travis_script_rust.sh
284-
- RUSTUP_TOOLCHAIN=nightly $TRAVIS_BUILD_DIR/ci/travis_script_rust.sh || true
290+
- $TRAVIS_BUILD_DIR/ci/travis_script_rust.sh
285291
after_success:
286292
- pushd ${TRAVIS_BUILD_DIR}/rust
287293
# Run coverage for codecov.io

rust/examples/builders.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
///! Many builders are available to easily create different types of arrow arrays
1919
extern crate arrow;
2020

21-
use arrow::builder::*;
21+
use arrow::builder::{ArrayBuilder, Int32Builder};
2222

2323
fn main() {
2424
// Primitive Arrays
@@ -27,7 +27,7 @@ fn main() {
2727
// i32, i64, f32, f64)
2828

2929
// Create a new builder with a capacity of 100
30-
let mut primitive_array_builder = PrimitiveArrayBuilder::<i32>::new(100);
30+
let mut primitive_array_builder = Int32Builder::new(100);
3131

3232
// Push an individual primitive value
3333
primitive_array_builder.push(55).unwrap();

rust/examples/dynamic_types.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
///! This example demonstrates dealing with mixed types dynamically at runtime
1919
use std::sync::Arc;
2020

21+
#[macro_use(numeric_from_nonnull)]
2122
extern crate arrow;
2223

2324
use arrow::array::*;
@@ -40,7 +41,7 @@ fn main() {
4041
]);
4142

4243
// create some data
43-
let id = PrimitiveArray::from(vec![1, 2, 3, 4, 5]);
44+
let id = numeric_from_nonnull!(Int32Array, 1, 2, 3, 4, 5);
4445

4546
let nested = StructArray::from(vec![
4647
(
@@ -49,11 +50,11 @@ fn main() {
4950
),
5051
(
5152
Field::new("b", DataType::Float64, false),
52-
Arc::new(PrimitiveArray::from(vec![1.1, 2.2, 3.3, 4.4, 5.5])),
53+
Arc::new(numeric_from_nonnull!(Float64Array, 1.1, 2.2, 3.3, 4.4, 5.5)),
5354
),
5455
(
5556
Field::new("c", DataType::Float64, false),
56-
Arc::new(PrimitiveArray::from(vec![2.2, 3.3, 4.4, 5.5, 6.6])),
57+
Arc::new(numeric_from_nonnull!(Float64Array, 2.2, 3.3, 4.4, 5.5, 6.6)),
5758
),
5859
]);
5960

@@ -75,12 +76,12 @@ fn process(batch: &RecordBatch) {
7576
let _nested_b = nested
7677
.column(1)
7778
.as_any()
78-
.downcast_ref::<PrimitiveArray<f64>>()
79+
.downcast_ref::<Float64Array>()
7980
.unwrap();
80-
let nested_c: &PrimitiveArray<f64> = nested
81+
let nested_c: &Float64Array = nested
8182
.column(2)
8283
.as_any()
83-
.downcast_ref::<PrimitiveArray<f64>>()
84+
.downcast_ref::<Float64Array>()
8485
.unwrap();
8586

8687
let projected_schema = Schema::new(vec![
@@ -91,8 +92,8 @@ fn process(batch: &RecordBatch) {
9192
let _ = RecordBatch::new(
9293
Arc::new(projected_schema),
9394
vec![
94-
id.clone(), //NOTE: this is cloning the Arc not the array data
95-
Arc::new(PrimitiveArray::<f64>::from(nested_c.data())),
95+
id.clone(), // NOTE: this is cloning the Arc not the array data
96+
Arc::new(Float64Array::from(nested_c.data())),
9697
],
9798
);
9899
}

rust/examples/read_csv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
extern crate arrow;
1919

20-
use arrow::array::{BinaryArray, PrimitiveArray};
20+
use arrow::array::{BinaryArray, Float64Array};
2121
use arrow::csv;
2222
use arrow::datatypes::{DataType, Field, Schema};
2323
use std::fs::File;
@@ -49,12 +49,12 @@ fn main() {
4949
let lat = batch
5050
.column(1)
5151
.as_any()
52-
.downcast_ref::<PrimitiveArray<f64>>()
52+
.downcast_ref::<Float64Array>()
5353
.unwrap();
5454
let lng = batch
5555
.column(2)
5656
.as_any()
57-
.downcast_ref::<PrimitiveArray<f64>>()
57+
.downcast_ref::<Float64Array>()
5858
.unwrap();
5959

6060
for i in 0..batch.num_rows() {

0 commit comments

Comments
 (0)