Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-3878: [Rust] Improve primitive types #3031

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/benches/array_from_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn array_from_vec(n: usize) {
let arr_data = ArrayDataBuilder::new(DataType::Int32)
.add_buffer(Buffer::from(v))
.build();
criterion::black_box(PrimitiveArray::<i32>::from(arr_data));
criterion::black_box(Int32Array::from(arr_data));
}

fn criterion_benchmark(c: &mut Criterion) {
Expand Down
8 changes: 4 additions & 4 deletions rust/benches/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ fn bench_primitive(c: &mut Criterion) {
"bench_primitive",
Benchmark::new("bench_primitive", move |b| {
b.iter(|| {
let mut builder = PrimitiveArrayBuilder::<i64>::new(64);
let mut builder = Int64Builder::new(64);
for _ in 0..NUM_BATCHES {
black_box(builder.push_slice(&data[..]));
let _ = black_box(builder.push_slice(&data[..]));
}
black_box(builder.finish());
})
Expand All @@ -58,9 +58,9 @@ fn bench_bool(c: &mut Criterion) {
"bench_bool",
Benchmark::new("bench_bool", move |b| {
b.iter(|| {
let mut builder = PrimitiveArrayBuilder::<bool>::new(64);
let mut builder = BooleanBuilder::new(64);
for _ in 0..NUM_BATCHES {
black_box(builder.push_slice(&data[..]));
let _ = black_box(builder.push_slice(&data[..]));
}
black_box(builder.finish());
})
Expand Down
4 changes: 2 additions & 2 deletions rust/examples/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
///! Many builders are available to easily create different types of arrow arrays
extern crate arrow;

use arrow::builder::*;
use arrow::builder::{ArrayBuilder, Int32Builder};

fn main() {
// Primitive Arrays
Expand All @@ -27,7 +27,7 @@ fn main() {
// i32, i64, f32, f64)

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

// Push an individual primitive value
primitive_array_builder.push(55).unwrap();
Expand Down
16 changes: 8 additions & 8 deletions rust/examples/dynamic_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() {
]);

// create some data
let id = PrimitiveArray::from(vec![1, 2, 3, 4, 5]);
let id = Int32Array::from(vec![1, 2, 3, 4, 5]);

let nested = StructArray::from(vec![
(
Expand All @@ -49,11 +49,11 @@ fn main() {
),
(
Field::new("b", DataType::Float64, false),
Arc::new(PrimitiveArray::from(vec![1.1, 2.2, 3.3, 4.4, 5.5])),
Arc::new(Float64Array::from(vec![1.1, 2.2, 3.3, 4.4, 5.5])),
),
(
Field::new("c", DataType::Float64, false),
Arc::new(PrimitiveArray::from(vec![2.2, 3.3, 4.4, 5.5, 6.6])),
Arc::new(Float64Array::from(vec![2.2, 3.3, 4.4, 5.5, 6.6])),
),
]);

Expand All @@ -75,12 +75,12 @@ fn process(batch: &RecordBatch) {
let _nested_b = nested
.column(1)
.as_any()
.downcast_ref::<PrimitiveArray<f64>>()
.downcast_ref::<Float64Array>()
.unwrap();
let nested_c: &PrimitiveArray<f64> = nested
let nested_c: &Float64Array = nested
.column(2)
.as_any()
.downcast_ref::<PrimitiveArray<f64>>()
.downcast_ref::<Float64Array>()
.unwrap();

let projected_schema = Schema::new(vec![
Expand All @@ -91,8 +91,8 @@ fn process(batch: &RecordBatch) {
let _ = RecordBatch::new(
Arc::new(projected_schema),
vec![
id.clone(), //NOTE: this is cloning the Arc not the array data
Arc::new(PrimitiveArray::<f64>::from(nested_c.data())),
id.clone(), // NOTE: this is cloning the Arc not the array data
Arc::new(Float64Array::from(nested_c.data())),
],
);
}
6 changes: 3 additions & 3 deletions rust/examples/read_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

extern crate arrow;

use arrow::array::{BinaryArray, PrimitiveArray};
use arrow::array::{BinaryArray, Float64Array};
use arrow::csv;
use arrow::datatypes::{DataType, Field, Schema};
use std::fs::File;
Expand Down Expand Up @@ -49,12 +49,12 @@ fn main() {
let lat = batch
.column(1)
.as_any()
.downcast_ref::<PrimitiveArray<f64>>()
.downcast_ref::<Float64Array>()
.unwrap();
let lng = batch
.column(2)
.as_any()
.downcast_ref::<PrimitiveArray<f64>>()
.downcast_ref::<Float64Array>()
.unwrap();

for i in 0..batch.num_rows() {
Expand Down
Loading