diff --git a/datafusion-examples/examples/dataframe_in_memory.rs b/datafusion-examples/examples/dataframe_in_memory.rs index be622d469f4d..c57c38870a7e 100644 --- a/datafusion-examples/examples/dataframe_in_memory.rs +++ b/datafusion-examples/examples/dataframe_in_memory.rs @@ -21,7 +21,6 @@ use datafusion::arrow::array::{Int32Array, StringArray}; use datafusion::arrow::datatypes::{DataType, Field, Schema}; use datafusion::arrow::record_batch::RecordBatch; use datafusion::error::Result; -use datafusion::from_slice::FromSlice; use datafusion::prelude::*; /// This example demonstrates how to use the DataFrame API against in-memory data. @@ -37,8 +36,8 @@ async fn main() -> Result<()> { let batch = RecordBatch::try_new( schema, vec![ - Arc::new(StringArray::from_slice(["a", "b", "c", "d"])), - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), + Arc::new(StringArray::from(vec!["a", "b", "c", "d"])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), ], )?; diff --git a/datafusion-examples/examples/simple_udaf.rs b/datafusion-examples/examples/simple_udaf.rs index b858ce7ebf1f..e3b290cc54d7 100644 --- a/datafusion-examples/examples/simple_udaf.rs +++ b/datafusion-examples/examples/simple_udaf.rs @@ -20,7 +20,6 @@ use datafusion::arrow::{ array::ArrayRef, array::Float32Array, datatypes::DataType, record_batch::RecordBatch, }; -use datafusion::from_slice::FromSlice; use datafusion::{error::Result, physical_plan::Accumulator}; use datafusion::{logical_expr::Volatility, prelude::*, scalar::ScalarValue}; use datafusion_common::cast::as_float64_array; @@ -37,11 +36,11 @@ fn create_context() -> Result { // define data in two partitions let batch1 = RecordBatch::try_new( schema.clone(), - vec![Arc::new(Float32Array::from_slice([2.0, 4.0, 8.0]))], + vec![Arc::new(Float32Array::from(vec![2.0, 4.0, 8.0]))], )?; let batch2 = RecordBatch::try_new( schema.clone(), - vec![Arc::new(Float32Array::from_slice([64.0]))], + vec![Arc::new(Float32Array::from(vec![64.0]))], )?; // declare a new context. In spark API, this corresponds to a new spark SQLsession diff --git a/datafusion-examples/examples/simple_udf.rs b/datafusion-examples/examples/simple_udf.rs index f735f9938fe8..dba4385b8eea 100644 --- a/datafusion-examples/examples/simple_udf.rs +++ b/datafusion-examples/examples/simple_udf.rs @@ -24,7 +24,6 @@ use datafusion::{ logical_expr::Volatility, }; -use datafusion::from_slice::FromSlice; use datafusion::prelude::*; use datafusion::{error::Result, physical_plan::functions::make_scalar_function}; use datafusion_common::cast::as_float64_array; @@ -43,8 +42,8 @@ fn create_context() -> Result { let batch = RecordBatch::try_new( schema, vec![ - Arc::new(Float32Array::from_slice([2.1, 3.1, 4.1, 5.1])), - Arc::new(Float64Array::from_slice([1.0, 2.0, 3.0, 4.0])), + Arc::new(Float32Array::from(vec![2.1, 3.1, 4.1, 5.1])), + Arc::new(Float64Array::from(vec![1.0, 2.0, 3.0, 4.0])), ], )?; diff --git a/datafusion/common/src/from_slice.rs b/datafusion/common/src/from_slice.rs deleted file mode 100644 index 385848f934e9..000000000000 --- a/datafusion/common/src/from_slice.rs +++ /dev/null @@ -1,116 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//! A trait to define from_slice functions for arrow types -//! -//! This file essentially exists to ease the transition onto arrow2 - -use arrow::array::{ - ArrayData, BooleanArray, GenericBinaryArray, GenericStringArray, OffsetSizeTrait, - PrimitiveArray, -}; -use arrow::buffer::{Buffer, MutableBuffer}; -use arrow::datatypes::{ArrowPrimitiveType, DataType}; -use arrow::util::bit_util; - -/// A trait to define from_slice functions for arrow primitive array types -pub trait FromSlice -where - S: AsRef<[E]>, -{ - /// convert a slice of native types into a primitive array (without nulls) - fn from_slice(slice: S) -> Self; -} - -/// default implementation for primitive array types, adapted from `From>` -impl FromSlice for PrimitiveArray -where - T: ArrowPrimitiveType, - S: AsRef<[T::Native]>, -{ - fn from_slice(slice: S) -> Self { - Self::from_iter_values(slice.as_ref().iter().cloned()) - } -} - -/// default implementation for binary array types, adapted from `From>` -impl FromSlice for GenericBinaryArray -where - OffsetSize: OffsetSizeTrait, - S: AsRef<[I]>, - I: AsRef<[u8]>, -{ - /// convert a slice of byte slices into a binary array (without nulls) - /// - /// implementation details: here the Self::from_vec can be called but not without another copy - fn from_slice(slice: S) -> Self { - let slice = slice.as_ref(); - let mut offsets = Vec::with_capacity(slice.len() + 1); - let mut values = Vec::new(); - let mut length_so_far: OffsetSize = OffsetSize::zero(); - offsets.push(length_so_far); - for s in slice { - let s = s.as_ref(); - length_so_far += OffsetSize::from_usize(s.len()).unwrap(); - offsets.push(length_so_far); - values.extend_from_slice(s); - } - let array_data = ArrayData::builder(Self::DATA_TYPE) - .len(slice.len()) - .add_buffer(Buffer::from_slice_ref(&offsets)) - .add_buffer(Buffer::from_slice_ref(&values)); - let array_data = unsafe { array_data.build_unchecked() }; - Self::from(array_data) - } -} - -/// default implementation for utf8 array types, adapted from `From>` -impl FromSlice for GenericStringArray -where - OffsetSize: OffsetSizeTrait, - S: AsRef<[I]>, - I: AsRef, -{ - fn from_slice(slice: S) -> Self { - Self::from_iter_values(slice.as_ref().iter()) - } -} - -/// default implementation for boolean array type, adapted from `From>` -impl FromSlice for BooleanArray -where - S: AsRef<[bool]>, -{ - fn from_slice(slice: S) -> Self { - let slice = slice.as_ref(); - let mut mut_buf = MutableBuffer::new_null(slice.len()); - { - let mut_slice = mut_buf.as_slice_mut(); - for (i, b) in slice.iter().enumerate() { - if *b { - bit_util::set_bit(mut_slice, i); - } - } - } - let array_data = ArrayData::builder(DataType::Boolean) - .len(slice.len()) - .add_buffer(mut_buf.into()); - - let array_data = unsafe { array_data.build_unchecked() }; - Self::from(array_data) - } -} diff --git a/datafusion/common/src/lib.rs b/datafusion/common/src/lib.rs index f58964bc2288..ef7e0947008a 100644 --- a/datafusion/common/src/lib.rs +++ b/datafusion/common/src/lib.rs @@ -21,7 +21,6 @@ pub mod config; pub mod delta; mod dfschema; mod error; -pub mod from_slice; mod join_type; pub mod parsers; #[cfg(feature = "pyarrow")] diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs index 724b21787f6f..e84ef545198e 100644 --- a/datafusion/common/src/scalar.rs +++ b/datafusion/common/src/scalar.rs @@ -3851,7 +3851,6 @@ mod tests { use rand::Rng; use crate::cast::{as_string_array, as_uint32_array, as_uint64_array}; - use crate::from_slice::FromSlice; use super::*; @@ -4827,26 +4826,26 @@ mod tests { let expected = Arc::new(StructArray::from(vec![ ( field_a.clone(), - Arc::new(Int32Array::from_slice([23, 23])) as ArrayRef, + Arc::new(Int32Array::from(vec![23, 23])) as ArrayRef, ), ( field_b.clone(), - Arc::new(BooleanArray::from_slice([false, false])) as ArrayRef, + Arc::new(BooleanArray::from(vec![false, false])) as ArrayRef, ), ( field_c.clone(), - Arc::new(StringArray::from_slice(["Hello", "Hello"])) as ArrayRef, + Arc::new(StringArray::from(vec!["Hello", "Hello"])) as ArrayRef, ), ( field_d.clone(), Arc::new(StructArray::from(vec![ ( field_e.clone(), - Arc::new(Int16Array::from_slice([2, 2])) as ArrayRef, + Arc::new(Int16Array::from(vec![2, 2])) as ArrayRef, ), ( field_f.clone(), - Arc::new(Int64Array::from_slice([3, 3])) as ArrayRef, + Arc::new(Int64Array::from(vec![3, 3])) as ArrayRef, ), ])) as ArrayRef, ), @@ -4922,27 +4921,26 @@ mod tests { let expected = Arc::new(StructArray::from(vec![ ( field_a, - Arc::new(Int32Array::from_slice([23, 7, -1000])) as ArrayRef, + Arc::new(Int32Array::from(vec![23, 7, -1000])) as ArrayRef, ), ( field_b, - Arc::new(BooleanArray::from_slice([false, true, true])) as ArrayRef, + Arc::new(BooleanArray::from(vec![false, true, true])) as ArrayRef, ), ( field_c, - Arc::new(StringArray::from_slice(["Hello", "World", "!!!!!"])) - as ArrayRef, + Arc::new(StringArray::from(vec!["Hello", "World", "!!!!!"])) as ArrayRef, ), ( field_d, Arc::new(StructArray::from(vec![ ( field_e, - Arc::new(Int16Array::from_slice([2, 4, 6])) as ArrayRef, + Arc::new(Int16Array::from(vec![2, 4, 6])) as ArrayRef, ), ( field_f, - Arc::new(Int64Array::from_slice([3, 5, 7])) as ArrayRef, + Arc::new(Int64Array::from(vec![3, 5, 7])) as ArrayRef, ), ])) as ArrayRef, ), @@ -5003,8 +5001,7 @@ mod tests { let expected = StructArray::from(vec![ ( field_a.clone(), - Arc::new(StringArray::from_slice(["First", "Second", "Third"])) - as ArrayRef, + Arc::new(StringArray::from(vec!["First", "Second", "Third"])) as ArrayRef, ), ( field_primitive_list.clone(), diff --git a/datafusion/common/src/utils.rs b/datafusion/common/src/utils.rs index b565feafb5aa..2edcd07846da 100644 --- a/datafusion/common/src/utils.rs +++ b/datafusion/common/src/utils.rs @@ -388,24 +388,22 @@ pub mod datafusion_strsim { #[cfg(test)] mod tests { + use crate::ScalarValue; + use crate::ScalarValue::Null; use arrow::array::Float64Array; use arrow_array::Array; use std::ops::Range; use std::sync::Arc; - use crate::from_slice::FromSlice; - use crate::ScalarValue; - use crate::ScalarValue::Null; - use super::*; #[test] fn test_bisect_linear_left_and_right() -> Result<()> { let arrays: Vec = vec![ - Arc::new(Float64Array::from_slice([5.0, 7.0, 8.0, 9., 10.])), - Arc::new(Float64Array::from_slice([2.0, 3.0, 3.0, 4.0, 5.0])), - Arc::new(Float64Array::from_slice([5.0, 7.0, 8.0, 10., 11.0])), - Arc::new(Float64Array::from_slice([15.0, 13.0, 8.0, 5., 0.0])), + Arc::new(Float64Array::from(vec![5.0, 7.0, 8.0, 9., 10.])), + Arc::new(Float64Array::from(vec![2.0, 3.0, 3.0, 4.0, 5.0])), + Arc::new(Float64Array::from(vec![5.0, 7.0, 8.0, 10., 11.0])), + Arc::new(Float64Array::from(vec![15.0, 13.0, 8.0, 5., 0.0])), ]; let search_tuple: Vec = vec![ ScalarValue::Float64(Some(8.0)), @@ -478,9 +476,8 @@ mod tests { #[test] fn test_bisect_linear_left_and_right_diff_sort() -> Result<()> { // Descending, left - let arrays: Vec = vec![Arc::new(Float64Array::from_slice([ - 4.0, 3.0, 2.0, 1.0, 0.0, - ]))]; + let arrays: Vec = + vec![Arc::new(Float64Array::from(vec![4.0, 3.0, 2.0, 1.0, 0.0]))]; let search_tuple: Vec = vec![ScalarValue::Float64(Some(4.0))]; let ords = [SortOptions { descending: true, @@ -492,9 +489,8 @@ mod tests { assert_eq!(res, 0); // Descending, right - let arrays: Vec = vec![Arc::new(Float64Array::from_slice([ - 4.0, 3.0, 2.0, 1.0, 0.0, - ]))]; + let arrays: Vec = + vec![Arc::new(Float64Array::from(vec![4.0, 3.0, 2.0, 1.0, 0.0]))]; let search_tuple: Vec = vec![ScalarValue::Float64(Some(4.0))]; let ords = [SortOptions { descending: true, @@ -507,7 +503,7 @@ mod tests { // Ascending, left let arrays: Vec = - vec![Arc::new(Float64Array::from_slice([5.0, 7.0, 8.0, 9., 10.]))]; + vec![Arc::new(Float64Array::from(vec![5.0, 7.0, 8.0, 9., 10.]))]; let search_tuple: Vec = vec![ScalarValue::Float64(Some(7.0))]; let ords = [SortOptions { descending: false, @@ -520,7 +516,7 @@ mod tests { // Ascending, right let arrays: Vec = - vec![Arc::new(Float64Array::from_slice([5.0, 7.0, 8.0, 9., 10.]))]; + vec![Arc::new(Float64Array::from(vec![5.0, 7.0, 8.0, 9., 10.]))]; let search_tuple: Vec = vec![ScalarValue::Float64(Some(7.0))]; let ords = [SortOptions { descending: false, @@ -532,8 +528,8 @@ mod tests { assert_eq!(res, 2); let arrays: Vec = vec![ - Arc::new(Float64Array::from_slice([5.0, 7.0, 8.0, 8.0, 9., 10.])), - Arc::new(Float64Array::from_slice([10.0, 9.0, 8.0, 7.5, 7., 6.])), + Arc::new(Float64Array::from(vec![5.0, 7.0, 8.0, 8.0, 9., 10.])), + Arc::new(Float64Array::from(vec![10.0, 9.0, 8.0, 7.5, 7., 6.])), ]; let search_tuple: Vec = vec![ ScalarValue::Float64(Some(8.0)), @@ -564,8 +560,8 @@ mod tests { #[test] fn test_evaluate_partition_ranges() -> Result<()> { let arrays: Vec = vec![ - Arc::new(Float64Array::from_slice([1.0, 1.0, 1.0, 2.0, 2.0, 2.0])), - Arc::new(Float64Array::from_slice([4.0, 4.0, 3.0, 2.0, 1.0, 1.0])), + Arc::new(Float64Array::from(vec![1.0, 1.0, 1.0, 2.0, 2.0, 2.0])), + Arc::new(Float64Array::from(vec![4.0, 4.0, 3.0, 2.0, 1.0, 1.0])), ]; let n_row = arrays[0].len(); let options: Vec = vec![ @@ -641,10 +637,10 @@ mod tests { #[test] fn test_get_arrayref_at_indices() -> Result<()> { let arrays: Vec = vec![ - Arc::new(Float64Array::from_slice([5.0, 7.0, 8.0, 9., 10.])), - Arc::new(Float64Array::from_slice([2.0, 3.0, 3.0, 4.0, 5.0])), - Arc::new(Float64Array::from_slice([5.0, 7.0, 8.0, 10., 11.0])), - Arc::new(Float64Array::from_slice([15.0, 13.0, 8.0, 5., 0.0])), + Arc::new(Float64Array::from(vec![5.0, 7.0, 8.0, 9., 10.])), + Arc::new(Float64Array::from(vec![2.0, 3.0, 3.0, 4.0, 5.0])), + Arc::new(Float64Array::from(vec![5.0, 7.0, 8.0, 10., 11.0])), + Arc::new(Float64Array::from(vec![15.0, 13.0, 8.0, 5., 0.0])), ]; let row_indices_vec: Vec> = vec![ diff --git a/datafusion/core/benches/data_utils/mod.rs b/datafusion/core/benches/data_utils/mod.rs index 575e1831c838..9169c3dda48e 100644 --- a/datafusion/core/benches/data_utils/mod.rs +++ b/datafusion/core/benches/data_utils/mod.rs @@ -27,7 +27,6 @@ use arrow::{ }; use datafusion::datasource::MemTable; use datafusion::error::Result; -use datafusion::from_slice::FromSlice; use rand::rngs::StdRng; use rand::seq::SliceRandom; use rand::{Rng, SeedableRng}; @@ -131,7 +130,7 @@ fn create_record_batch( schema, vec![ Arc::new(StringArray::from(keys)), - Arc::new(Float32Array::from_slice(vec![i as f32; batch_size])), + Arc::new(Float32Array::from(vec![i as f32; batch_size])), Arc::new(Float64Array::from(values)), Arc::new(UInt64Array::from(integer_values_wide)), Arc::new(UInt64Array::from(integer_values_narrow)), diff --git a/datafusion/core/benches/filter_query_sql.rs b/datafusion/core/benches/filter_query_sql.rs index 8b0142078d90..01adc357b39a 100644 --- a/datafusion/core/benches/filter_query_sql.rs +++ b/datafusion/core/benches/filter_query_sql.rs @@ -21,7 +21,6 @@ use arrow::{ record_batch::RecordBatch, }; use criterion::{criterion_group, criterion_main, Criterion}; -use datafusion::from_slice::FromSlice; use datafusion::prelude::SessionContext; use datafusion::{datasource::MemTable, error::Result}; use futures::executor::block_on; @@ -49,8 +48,8 @@ fn create_context(array_len: usize, batch_size: usize) -> Result RecordBatch::try_new( schema.clone(), vec![ - Arc::new(Float32Array::from_slice(vec![i as f32; batch_size])), - Arc::new(Float64Array::from_slice(vec![i as f64; batch_size])), + Arc::new(Float32Array::from(vec![i as f32; batch_size])), + Arc::new(Float64Array::from(vec![i as f64; batch_size])), ], ) .unwrap() diff --git a/datafusion/core/benches/math_query_sql.rs b/datafusion/core/benches/math_query_sql.rs index 87c7a363efc0..92c59d506640 100644 --- a/datafusion/core/benches/math_query_sql.rs +++ b/datafusion/core/benches/math_query_sql.rs @@ -35,7 +35,6 @@ use arrow::{ use datafusion::datasource::MemTable; use datafusion::error::Result; use datafusion::execution::context::SessionContext; -use datafusion::from_slice::FromSlice; fn query(ctx: Arc>, sql: &str) { let rt = Runtime::new().unwrap(); @@ -61,8 +60,8 @@ fn create_context( RecordBatch::try_new( schema.clone(), vec![ - Arc::new(Float32Array::from_slice(vec![i as f32; batch_size])), - Arc::new(Float64Array::from_slice(vec![i as f64; batch_size])), + Arc::new(Float32Array::from(vec![i as f32; batch_size])), + Arc::new(Float64Array::from(vec![i as f64; batch_size])), ], ) .unwrap() diff --git a/datafusion/core/src/dataframe.rs b/datafusion/core/src/dataframe.rs index 1b285107b38a..7d0fddcf8226 100644 --- a/datafusion/core/src/dataframe.rs +++ b/datafusion/core/src/dataframe.rs @@ -27,7 +27,6 @@ use async_trait::async_trait; use datafusion_common::{DataFusionError, SchemaError}; use parquet::file::properties::WriterProperties; -use datafusion_common::from_slice::FromSlice; use datafusion_common::{Column, DFSchema, ScalarValue}; use datafusion_expr::{ avg, count, is_null, max, median, min, stddev, utils::COUNT_STAR_EXPANSION, @@ -411,7 +410,7 @@ impl DataFrame { ]; // first column with function names - let mut array_ref_vec: Vec = vec![Arc::new(StringArray::from_slice( + let mut array_ref_vec: Vec = vec![Arc::new(StringArray::from( supported_describe_functions.clone(), ))]; for field in original_schema_fields { @@ -435,7 +434,7 @@ impl DataFrame { cast(column, &DataType::Utf8)? } } - _ => Arc::new(StringArray::from_slice(["null"])), + _ => Arc::new(StringArray::from(vec!["null"])), } } //Handling error when only boolean/binary column, and in other cases @@ -446,7 +445,7 @@ impl DataFrame { or aggregate expression", ) => { - Arc::new(StringArray::from_slice(["null"])) + Arc::new(StringArray::from(vec!["null"])) } Err(other_err) => { panic!("{other_err}") diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rs index b11fa8b06377..670400084e06 100644 --- a/datafusion/core/src/datasource/listing/table.rs +++ b/datafusion/core/src/datasource/listing/table.rs @@ -903,7 +903,6 @@ mod tests { use arrow::record_batch::RecordBatch; use chrono::DateTime; use datafusion_common::assert_contains; - use datafusion_common::from_slice::FromSlice; use datafusion_expr::LogicalPlanBuilder; use rstest::*; use std::fs::File; @@ -1527,7 +1526,7 @@ mod tests { // Create a new batch of data to insert into the table let batch = RecordBatch::try_new( schema.clone(), - vec![Arc::new(arrow_array::Int32Array::from_slice([1, 2, 3]))], + vec![Arc::new(arrow_array::Int32Array::from(vec![1, 2, 3]))], )?; // Filename with extension diff --git a/datafusion/core/src/datasource/memory.rs b/datafusion/core/src/datasource/memory.rs index 97758031851d..f66b44e9d1f9 100644 --- a/datafusion/core/src/datasource/memory.rs +++ b/datafusion/core/src/datasource/memory.rs @@ -256,7 +256,6 @@ impl DataSink for MemSink { mod tests { use super::*; use crate::datasource::provider_as_source; - use crate::from_slice::FromSlice; use crate::physical_plan::collect; use crate::prelude::SessionContext; use arrow::array::{AsArray, Int32Array}; @@ -280,9 +279,9 @@ mod tests { let batch = RecordBatch::try_new( schema.clone(), vec![ - Arc::new(Int32Array::from_slice([1, 2, 3])), - Arc::new(Int32Array::from_slice([4, 5, 6])), - Arc::new(Int32Array::from_slice([7, 8, 9])), + Arc::new(Int32Array::from(vec![1, 2, 3])), + Arc::new(Int32Array::from(vec![4, 5, 6])), + Arc::new(Int32Array::from(vec![7, 8, 9])), Arc::new(Int32Array::from(vec![None, None, Some(9)])), ], )?; @@ -317,9 +316,9 @@ mod tests { let batch = RecordBatch::try_new( schema.clone(), vec![ - Arc::new(Int32Array::from_slice([1, 2, 3])), - Arc::new(Int32Array::from_slice([4, 5, 6])), - Arc::new(Int32Array::from_slice([7, 8, 9])), + Arc::new(Int32Array::from(vec![1, 2, 3])), + Arc::new(Int32Array::from(vec![4, 5, 6])), + Arc::new(Int32Array::from(vec![7, 8, 9])), ], )?; @@ -347,9 +346,9 @@ mod tests { let batch = RecordBatch::try_new( schema.clone(), vec![ - Arc::new(Int32Array::from_slice([1, 2, 3])), - Arc::new(Int32Array::from_slice([4, 5, 6])), - Arc::new(Int32Array::from_slice([7, 8, 9])), + Arc::new(Int32Array::from(vec![1, 2, 3])), + Arc::new(Int32Array::from(vec![4, 5, 6])), + Arc::new(Int32Array::from(vec![7, 8, 9])), ], )?; @@ -390,9 +389,9 @@ mod tests { let batch = RecordBatch::try_new( schema1, vec![ - Arc::new(Int32Array::from_slice([1, 2, 3])), - Arc::new(Int32Array::from_slice([4, 5, 6])), - Arc::new(Int32Array::from_slice([7, 8, 9])), + Arc::new(Int32Array::from(vec![1, 2, 3])), + Arc::new(Int32Array::from(vec![4, 5, 6])), + Arc::new(Int32Array::from(vec![7, 8, 9])), ], )?; @@ -422,8 +421,8 @@ mod tests { let batch = RecordBatch::try_new( schema1, vec![ - Arc::new(Int32Array::from_slice([1, 2, 3])), - Arc::new(Int32Array::from_slice([7, 5, 9])), + Arc::new(Int32Array::from(vec![1, 2, 3])), + Arc::new(Int32Array::from(vec![7, 5, 9])), ], )?; @@ -466,18 +465,18 @@ mod tests { let batch1 = RecordBatch::try_new( Arc::new(schema1), vec![ - Arc::new(Int32Array::from_slice([1, 2, 3])), - Arc::new(Int32Array::from_slice([4, 5, 6])), - Arc::new(Int32Array::from_slice([7, 8, 9])), + Arc::new(Int32Array::from(vec![1, 2, 3])), + Arc::new(Int32Array::from(vec![4, 5, 6])), + Arc::new(Int32Array::from(vec![7, 8, 9])), ], )?; let batch2 = RecordBatch::try_new( Arc::new(schema2), vec![ - Arc::new(Int32Array::from_slice([1, 2, 3])), - Arc::new(Int32Array::from_slice([4, 5, 6])), - Arc::new(Int32Array::from_slice([7, 8, 9])), + Arc::new(Int32Array::from(vec![1, 2, 3])), + Arc::new(Int32Array::from(vec![4, 5, 6])), + Arc::new(Int32Array::from(vec![7, 8, 9])), ], )?; @@ -574,7 +573,7 @@ mod tests { // Create a new batch of data to insert into the table let batch = RecordBatch::try_new( schema.clone(), - vec![Arc::new(Int32Array::from_slice([1, 2, 3]))], + vec![Arc::new(Int32Array::from(vec![1, 2, 3]))], )?; // Run the experiment and obtain the resulting data in the table let resulting_data_in_table = @@ -594,7 +593,7 @@ mod tests { // Create a new batch of data to insert into the table let batch = RecordBatch::try_new( schema.clone(), - vec![Arc::new(Int32Array::from_slice([1, 2, 3]))], + vec![Arc::new(Int32Array::from(vec![1, 2, 3]))], )?; // Run the experiment and obtain the resulting data in the table let resulting_data_in_table = experiment( @@ -617,7 +616,7 @@ mod tests { // Create a new batch of data to insert into the table let batch = RecordBatch::try_new( schema.clone(), - vec![Arc::new(Int32Array::from_slice([1, 2, 3]))], + vec![Arc::new(Int32Array::from(vec![1, 2, 3]))], )?; // Run the experiment and obtain the resulting data in the table let resulting_data_in_table = experiment( @@ -643,7 +642,7 @@ mod tests { // Create a new batch of data to insert into the table let batch = RecordBatch::try_new( schema.clone(), - vec![Arc::new(Int32Array::from_slice([1, 2, 3]))], + vec![Arc::new(Int32Array::from(vec![1, 2, 3]))], )?; // Run the experiment and obtain the resulting data in the table let resulting_data_in_table = experiment( diff --git a/datafusion/core/src/lib.rs b/datafusion/core/src/lib.rs index 4082a22daac1..a7fea05a569a 100644 --- a/datafusion/core/src/lib.rs +++ b/datafusion/core/src/lib.rs @@ -437,8 +437,6 @@ pub use datafusion_physical_expr as physical_expr; pub use datafusion_row as row; pub use datafusion_sql as sql; -pub use common::from_slice; - #[cfg(test)] pub mod test; pub mod test_util; diff --git a/datafusion/core/src/physical_optimizer/pruning.rs b/datafusion/core/src/physical_optimizer/pruning.rs index bab9c247208b..8fb3058308fb 100644 --- a/datafusion/core/src/physical_optimizer/pruning.rs +++ b/datafusion/core/src/physical_optimizer/pruning.rs @@ -933,7 +933,6 @@ pub(crate) enum StatisticsType { #[cfg(test)] mod tests { use super::*; - use crate::from_slice::FromSlice; use crate::logical_expr::{col, lit}; use crate::{assert_batches_eq, physical_optimizer::pruning::StatisticsType}; use arrow::array::Decimal128Array; @@ -1298,7 +1297,7 @@ mod tests { // Note the statistics return an invalid UTF-8 sequence which will be converted to null let statistics = OneContainerStats { - min_values: Some(Arc::new(BinaryArray::from_slice([&[255u8] as &[u8]]))), + min_values: Some(Arc::new(BinaryArray::from(vec![&[255u8] as &[u8]]))), max_values: None, num_containers: 1, }; diff --git a/datafusion/core/src/physical_plan/aggregates/mod.rs b/datafusion/core/src/physical_plan/aggregates/mod.rs index f96a09c8e9ad..a2ae41de1f74 100644 --- a/datafusion/core/src/physical_plan/aggregates/mod.rs +++ b/datafusion/core/src/physical_plan/aggregates/mod.rs @@ -1182,7 +1182,6 @@ fn evaluate_group_by( mod tests { use super::*; use crate::execution::context::SessionConfig; - use crate::from_slice::FromSlice; use crate::physical_plan::aggregates::{ get_finest_requirement, get_working_mode, AggregateExec, AggregateMode, PhysicalGroupBy, @@ -1320,16 +1319,16 @@ mod tests { RecordBatch::try_new( schema.clone(), vec![ - Arc::new(UInt32Array::from_slice([2, 3, 4, 4])), - Arc::new(Float64Array::from_slice([1.0, 2.0, 3.0, 4.0])), + Arc::new(UInt32Array::from(vec![2, 3, 4, 4])), + Arc::new(Float64Array::from(vec![1.0, 2.0, 3.0, 4.0])), ], ) .unwrap(), RecordBatch::try_new( schema, vec![ - Arc::new(UInt32Array::from_slice([2, 3, 3, 4])), - Arc::new(Float64Array::from_slice([1.0, 2.0, 3.0, 4.0])), + Arc::new(UInt32Array::from(vec![2, 3, 3, 4])), + Arc::new(Float64Array::from(vec![1.0, 2.0, 3.0, 4.0])), ], ) .unwrap(), diff --git a/datafusion/core/src/physical_plan/common.rs b/datafusion/core/src/physical_plan/common.rs index 031c2dd0f320..982bb4f2e6ba 100644 --- a/datafusion/core/src/physical_plan/common.rs +++ b/datafusion/core/src/physical_plan/common.rs @@ -289,7 +289,6 @@ mod tests { use std::ops::Not; use super::*; - use crate::from_slice::FromSlice; use crate::physical_plan::memory::MemoryExec; use crate::physical_plan::sorts::sort::SortExec; use crate::physical_plan::union::UnionExec; @@ -601,8 +600,8 @@ mod tests { let batch = RecordBatch::try_new( Arc::clone(&schema), vec![ - Arc::new(Float32Array::from_slice([1., 2., 3.])), - Arc::new(Float64Array::from_slice([9., 8., 7.])), + Arc::new(Float32Array::from(vec![1., 2., 3.])), + Arc::new(Float64Array::from(vec![9., 8., 7.])), ], )?; let actual = diff --git a/datafusion/core/src/physical_plan/insert.rs b/datafusion/core/src/physical_plan/insert.rs index 6e02a54da221..f3bd701a565d 100644 --- a/datafusion/core/src/physical_plan/insert.rs +++ b/datafusion/core/src/physical_plan/insert.rs @@ -206,7 +206,7 @@ impl ExecutionPlan for InsertExec { /// +-------+, /// ``` fn make_count_batch(count: u64) -> RecordBatch { - let array = Arc::new(UInt64Array::from_iter_values(vec![count])) as ArrayRef; + let array = Arc::new(UInt64Array::from(vec![count])) as ArrayRef; RecordBatch::try_from_iter_with_nullable(vec![("count", array, false)]).unwrap() } diff --git a/datafusion/core/src/physical_plan/repartition/mod.rs b/datafusion/core/src/physical_plan/repartition/mod.rs index 47814a27de7a..d7dc54afd6e1 100644 --- a/datafusion/core/src/physical_plan/repartition/mod.rs +++ b/datafusion/core/src/physical_plan/repartition/mod.rs @@ -685,7 +685,6 @@ impl RecordBatchStream for RepartitionStream { mod tests { use super::*; use crate::execution::context::SessionConfig; - use crate::from_slice::FromSlice; use crate::prelude::SessionContext; use crate::test::create_vec_batches; use crate::{ @@ -852,7 +851,7 @@ mod tests { // have to send at least one batch through to provoke error let batch = RecordBatch::try_from_iter(vec![( "my_awesome_field", - Arc::new(StringArray::from_slice(["foo", "bar"])) as ArrayRef, + Arc::new(StringArray::from(vec!["foo", "bar"])) as ArrayRef, )]) .unwrap(); @@ -909,7 +908,7 @@ mod tests { let task_ctx = session_ctx.task_ctx(); let batch = RecordBatch::try_from_iter(vec![( "my_awesome_field", - Arc::new(StringArray::from_slice(["foo", "bar"])) as ArrayRef, + Arc::new(StringArray::from(vec!["foo", "bar"])) as ArrayRef, )]) .unwrap(); @@ -943,13 +942,13 @@ mod tests { let task_ctx = session_ctx.task_ctx(); let batch1 = RecordBatch::try_from_iter(vec![( "my_awesome_field", - Arc::new(StringArray::from_slice(["foo", "bar"])) as ArrayRef, + Arc::new(StringArray::from(vec!["foo", "bar"])) as ArrayRef, )]) .unwrap(); let batch2 = RecordBatch::try_from_iter(vec![( "my_awesome_field", - Arc::new(StringArray::from_slice(["frob", "baz"])) as ArrayRef, + Arc::new(StringArray::from(vec!["frob", "baz"])) as ArrayRef, )]) .unwrap(); @@ -1095,25 +1094,25 @@ mod tests { fn make_barrier_exec() -> BarrierExec { let batch1 = RecordBatch::try_from_iter(vec![( "my_awesome_field", - Arc::new(StringArray::from_slice(["foo", "bar"])) as ArrayRef, + Arc::new(StringArray::from(vec!["foo", "bar"])) as ArrayRef, )]) .unwrap(); let batch2 = RecordBatch::try_from_iter(vec![( "my_awesome_field", - Arc::new(StringArray::from_slice(["frob", "baz"])) as ArrayRef, + Arc::new(StringArray::from(vec!["frob", "baz"])) as ArrayRef, )]) .unwrap(); let batch3 = RecordBatch::try_from_iter(vec![( "my_awesome_field", - Arc::new(StringArray::from_slice(["goo", "gar"])) as ArrayRef, + Arc::new(StringArray::from(vec!["goo", "gar"])) as ArrayRef, )]) .unwrap(); let batch4 = RecordBatch::try_from_iter(vec![( "my_awesome_field", - Arc::new(StringArray::from_slice(["grob", "gaz"])) as ArrayRef, + Arc::new(StringArray::from(vec!["grob", "gaz"])) as ArrayRef, )]) .unwrap(); @@ -1153,7 +1152,7 @@ mod tests { let task_ctx = session_ctx.task_ctx(); let batch = RecordBatch::try_from_iter(vec![( "a", - Arc::new(StringArray::from_slice(["foo"])) as ArrayRef, + Arc::new(StringArray::from(vec!["foo"])) as ArrayRef, )]) .unwrap(); let partitioning = Partitioning::Hash( diff --git a/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs b/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs index 9d93a5055ec5..1195959a89b6 100644 --- a/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs +++ b/datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs @@ -233,7 +233,6 @@ mod tests { use arrow::record_batch::RecordBatch; use futures::{FutureExt, StreamExt}; - use crate::from_slice::FromSlice; use crate::physical_plan::coalesce_partitions::CoalescePartitionsExec; use crate::physical_plan::expressions::col; use crate::physical_plan::memory::MemoryExec; @@ -253,7 +252,7 @@ mod tests { async fn test_merge_interleave() { let session_ctx = SessionContext::new(); let task_ctx = session_ctx.task_ctx(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([1, 2, 7, 9, 3])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 7, 9, 3])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("a"), Some("c"), @@ -264,7 +263,7 @@ mod tests { let c: ArrayRef = Arc::new(TimestampNanosecondArray::from(vec![8, 7, 6, 5, 8])); let b1 = RecordBatch::try_from_iter(vec![("a", a), ("b", b), ("c", c)]).unwrap(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([10, 20, 70, 90, 30])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![10, 20, 70, 90, 30])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("b"), Some("d"), @@ -302,7 +301,7 @@ mod tests { async fn test_merge_some_overlap() { let session_ctx = SessionContext::new(); let task_ctx = session_ctx.task_ctx(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([1, 2, 7, 9, 3])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 7, 9, 3])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("a"), Some("b"), @@ -313,7 +312,7 @@ mod tests { let c: ArrayRef = Arc::new(TimestampNanosecondArray::from(vec![8, 7, 6, 5, 8])); let b1 = RecordBatch::try_from_iter(vec![("a", a), ("b", b), ("c", c)]).unwrap(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([70, 90, 30, 100, 110])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![70, 90, 30, 100, 110])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("c"), Some("d"), @@ -351,7 +350,7 @@ mod tests { async fn test_merge_no_overlap() { let session_ctx = SessionContext::new(); let task_ctx = session_ctx.task_ctx(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([1, 2, 7, 9, 3])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 7, 9, 3])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("a"), Some("b"), @@ -362,7 +361,7 @@ mod tests { let c: ArrayRef = Arc::new(TimestampNanosecondArray::from(vec![8, 7, 6, 5, 8])); let b1 = RecordBatch::try_from_iter(vec![("a", a), ("b", b), ("c", c)]).unwrap(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([10, 20, 70, 90, 30])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![10, 20, 70, 90, 30])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("f"), Some("g"), @@ -400,7 +399,7 @@ mod tests { async fn test_merge_three_partitions() { let session_ctx = SessionContext::new(); let task_ctx = session_ctx.task_ctx(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([1, 2, 7, 9, 3])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 7, 9, 3])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("a"), Some("b"), @@ -411,7 +410,7 @@ mod tests { let c: ArrayRef = Arc::new(TimestampNanosecondArray::from(vec![8, 7, 6, 5, 8])); let b1 = RecordBatch::try_from_iter(vec![("a", a), ("b", b), ("c", c)]).unwrap(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([10, 20, 70, 90, 30])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![10, 20, 70, 90, 30])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("e"), Some("g"), @@ -423,7 +422,7 @@ mod tests { Arc::new(TimestampNanosecondArray::from(vec![40, 60, 20, 20, 60])); let b2 = RecordBatch::try_from_iter(vec![("a", a), ("b", b), ("c", c)]).unwrap(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([100, 200, 700, 900, 300])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![100, 200, 700, 900, 300])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ Some("f"), Some("g"), @@ -696,7 +695,7 @@ mod tests { async fn test_nulls() { let session_ctx = SessionContext::new(); let task_ctx = session_ctx.task_ctx(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([1, 2, 7, 9, 3])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 7, 9, 3])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ None, Some("a"), @@ -713,7 +712,7 @@ mod tests { ])); let b1 = RecordBatch::try_from_iter(vec![("a", a), ("b", b), ("c", c)]).unwrap(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([1, 2, 3, 4, 5])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![ None, Some("b"), @@ -841,11 +840,11 @@ mod tests { async fn test_merge_metrics() { let session_ctx = SessionContext::new(); let task_ctx = session_ctx.task_ctx(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([1, 2])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![Some("a"), Some("c")])); let b1 = RecordBatch::try_from_iter(vec![("a", a), ("b", b)]).unwrap(); - let a: ArrayRef = Arc::new(Int32Array::from_slice([10, 20])); + let a: ArrayRef = Arc::new(Int32Array::from(vec![10, 20])); let b: ArrayRef = Arc::new(StringArray::from_iter(vec![Some("b"), Some("d")])); let b2 = RecordBatch::try_from_iter(vec![("a", a), ("b", b)]).unwrap(); diff --git a/datafusion/core/src/test/mod.rs b/datafusion/core/src/test/mod.rs index 82b55063dcff..838c13f96856 100644 --- a/datafusion/core/src/test/mod.rs +++ b/datafusion/core/src/test/mod.rs @@ -24,7 +24,6 @@ use crate::datasource::object_store::ObjectStoreUrl; use crate::datasource::physical_plan::{CsvExec, FileScanConfig}; use crate::datasource::{MemTable, TableProvider}; use crate::error::Result; -use crate::from_slice::FromSlice; use crate::logical_expr::LogicalPlan; use crate::physical_plan::memory::MemoryExec; use crate::physical_plan::ExecutionPlan; @@ -64,8 +63,8 @@ pub fn create_table_dual() -> Arc { let batch = RecordBatch::try_new( dual_schema.clone(), vec![ - Arc::new(array::Int32Array::from_slice([1])), - Arc::new(array::StringArray::from_slice(["a"])), + Arc::new(array::Int32Array::from(vec![1])), + Arc::new(array::StringArray::from(vec!["a"])), ], ) .unwrap(); @@ -357,7 +356,7 @@ pub fn csv_exec_sorted( fn create_batch(schema: &Schema) -> RecordBatch { RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(UInt32Array::from_slice([1, 2, 3, 4, 5, 6, 7, 8]))], + vec![Arc::new(UInt32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8]))], ) .unwrap() } diff --git a/datafusion/core/tests/custom_sources.rs b/datafusion/core/tests/custom_sources.rs index 57314f2e1eb8..b060480d64d0 100644 --- a/datafusion/core/tests/custom_sources.rs +++ b/datafusion/core/tests/custom_sources.rs @@ -20,7 +20,6 @@ use arrow::compute::kernels::aggregate; use arrow::datatypes::{DataType, Field, Int32Type, Schema, SchemaRef}; use arrow::record_batch::RecordBatch; use datafusion::execution::context::{SessionContext, SessionState, TaskContext}; -use datafusion::from_slice::FromSlice; use datafusion::logical_expr::{ col, Expr, LogicalPlan, LogicalPlanBuilder, TableScan, UNNAMED_TABLE, }; @@ -70,8 +69,8 @@ macro_rules! TEST_CUSTOM_RECORD_BATCH { RecordBatch::try_new( TEST_CUSTOM_SCHEMA_REF!(), vec![ - Arc::new(Int32Array::from_slice(&[1, 10, 10, 100])), - Arc::new(Int32Array::from_slice(&[2, 12, 12, 120])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), + Arc::new(Int32Array::from(vec![2, 12, 12, 120])), ], ) }; @@ -268,9 +267,9 @@ async fn optimizers_catch_all_statistics() { Field::new("MAX(test.c1)", DataType::Int32, false), ])), vec![ - Arc::new(Int64Array::from_slice([4])), - Arc::new(Int32Array::from_slice([1])), - Arc::new(Int32Array::from_slice([100])), + Arc::new(Int64Array::from(vec![4])), + Arc::new(Int32Array::from(vec![1])), + Arc::new(Int32Array::from(vec![100])), ], ) .unwrap(); diff --git a/datafusion/core/tests/dataframe.rs b/datafusion/core/tests/dataframe.rs index 7c1a31b6cca9..f19f6d3c5908 100644 --- a/datafusion/core/tests/dataframe.rs +++ b/datafusion/core/tests/dataframe.rs @@ -24,7 +24,6 @@ use arrow::{ }, record_batch::RecordBatch, }; -use datafusion::from_slice::FromSlice; use std::sync::Arc; use datafusion::dataframe::DataFrame; @@ -342,16 +341,16 @@ async fn join() -> Result<()> { let batch1 = RecordBatch::try_new( schema1.clone(), vec![ - Arc::new(StringArray::from_slice(["a", "b", "c", "d"])), - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), + Arc::new(StringArray::from(vec!["a", "b", "c", "d"])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), ], )?; // define data. let batch2 = RecordBatch::try_new( schema2.clone(), vec![ - Arc::new(StringArray::from_slice(["a", "b", "c", "d"])), - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), + Arc::new(StringArray::from(vec!["a", "b", "c", "d"])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), ], )?; @@ -384,8 +383,8 @@ async fn sort_on_unprojected_columns() -> Result<()> { let batch = RecordBatch::try_new( Arc::new(schema.clone()), vec![ - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), - Arc::new(Int32Array::from_slice([2, 12, 12, 120])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), + Arc::new(Int32Array::from(vec![2, 12, 12, 120])), ], ) .unwrap(); @@ -429,8 +428,8 @@ async fn sort_on_distinct_columns() -> Result<()> { let batch = RecordBatch::try_new( Arc::new(schema.clone()), vec![ - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), - Arc::new(Int32Array::from_slice([2, 3, 4, 5])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), + Arc::new(Int32Array::from(vec![2, 3, 4, 5])), ], ) .unwrap(); @@ -473,8 +472,8 @@ async fn sort_on_distinct_unprojected_columns() -> Result<()> { let batch = RecordBatch::try_new( Arc::new(schema.clone()), vec![ - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), - Arc::new(Int32Array::from_slice([2, 3, 4, 5])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), + Arc::new(Int32Array::from(vec![2, 3, 4, 5])), ], )?; @@ -574,7 +573,7 @@ async fn filter_with_alias_overwrite() -> Result<()> { let batch = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([1, 10, 10, 100]))], + vec![Arc::new(Int32Array::from(vec![1, 10, 10, 100]))], ) .unwrap(); @@ -611,7 +610,7 @@ async fn select_with_alias_overwrite() -> Result<()> { let batch = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([1, 10, 10, 100]))], + vec![Arc::new(Int32Array::from(vec![1, 10, 10, 100]))], )?; let ctx = SessionContext::new(); @@ -1090,13 +1089,13 @@ async fn create_test_table(name: &str) -> Result { let batch = RecordBatch::try_new( schema, vec![ - Arc::new(StringArray::from_slice([ + Arc::new(StringArray::from(vec![ "abcDEF", "abc123", "CBAdef", "123AbcDef", ])), - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), ], )?; @@ -1133,18 +1132,18 @@ fn create_join_context() -> Result { let batch1 = RecordBatch::try_new( t1, vec![ - Arc::new(UInt32Array::from_slice([1, 10, 11, 100])), - Arc::new(StringArray::from_slice(["a", "b", "c", "d"])), - Arc::new(Int32Array::from_slice([10, 20, 30, 40])), + Arc::new(UInt32Array::from(vec![1, 10, 11, 100])), + Arc::new(StringArray::from(vec!["a", "b", "c", "d"])), + Arc::new(Int32Array::from(vec![10, 20, 30, 40])), ], )?; // define data. let batch2 = RecordBatch::try_new( t2, vec![ - Arc::new(UInt32Array::from_slice([3, 10, 13, 100])), - Arc::new(StringArray::from_slice(["a", "b", "c", "d"])), - Arc::new(Int32Array::from_slice([1, 2, 3, 4])), + Arc::new(UInt32Array::from(vec![3, 10, 13, 100])), + Arc::new(StringArray::from(vec!["a", "b", "c", "d"])), + Arc::new(Int32Array::from(vec![1, 2, 3, 4])), ], )?; diff --git a/datafusion/core/tests/dataframe_functions.rs b/datafusion/core/tests/dataframe_functions.rs index 88b6114309e0..fb10caf1b07d 100644 --- a/datafusion/core/tests/dataframe_functions.rs +++ b/datafusion/core/tests/dataframe_functions.rs @@ -20,7 +20,6 @@ use arrow::{ array::{Int32Array, StringArray}, record_batch::RecordBatch, }; -use datafusion::from_slice::FromSlice; use std::sync::Arc; use datafusion::dataframe::DataFrame; @@ -44,13 +43,13 @@ async fn create_test_table() -> Result { let batch = RecordBatch::try_new( schema, vec![ - Arc::new(StringArray::from_slice([ + Arc::new(StringArray::from(vec![ "abcDEF", "abc123", "CBAdef", "123AbcDef", ])), - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), ], )?; diff --git a/datafusion/core/tests/parquet/mod.rs b/datafusion/core/tests/parquet/mod.rs index 031aab9f4555..6f289e0c064b 100644 --- a/datafusion/core/tests/parquet/mod.rs +++ b/datafusion/core/tests/parquet/mod.rs @@ -378,7 +378,7 @@ fn make_decimal_batch(v: Vec, precision: u8, scale: i8) -> RecordBatch { true, )])); let array = Arc::new( - Decimal128Array::from_iter_values(v) + Decimal128Array::from(v) .with_precision_and_scale(precision, scale) .unwrap(), ) as ArrayRef; diff --git a/datafusion/core/tests/repartition.rs b/datafusion/core/tests/repartition.rs index 4fd3a91255f7..20e64b2eeefc 100644 --- a/datafusion/core/tests/repartition.rs +++ b/datafusion/core/tests/repartition.rs @@ -23,7 +23,6 @@ use datafusion::physical_plan::repartition::RepartitionExec; use datafusion::physical_plan::{ExecutionPlan, Partitioning}; use datafusion::prelude::{SessionConfig, SessionContext}; use datafusion::test_util::UnboundedExec; -use datafusion_common::from_slice::FromSlice; use datafusion_common::Result; use datafusion_physical_expr::expressions::Column; use datafusion_physical_expr::PhysicalExpr; @@ -39,7 +38,7 @@ async fn unbounded_repartition() -> Result<()> { let schema = Arc::new(Schema::new(vec![Field::new("a2", DataType::UInt32, false)])); let batch = RecordBatch::try_new( Arc::clone(&schema), - vec![Arc::new(UInt32Array::from_slice([1]))], + vec![Arc::new(UInt32Array::from(vec![1]))], )?; let input = Arc::new(UnboundedExec::new(None, batch.clone(), 1)); let on: Vec> = vec![Arc::new(Column::new("a2", 0))]; diff --git a/datafusion/core/tests/sql/aggregates.rs b/datafusion/core/tests/sql/aggregates.rs index 81a0122b8083..251063e396b6 100644 --- a/datafusion/core/tests/sql/aggregates.rs +++ b/datafusion/core/tests/sql/aggregates.rs @@ -599,11 +599,11 @@ async fn simple_avg() -> Result<()> { let batch1 = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([1, 2, 3]))], + vec![Arc::new(Int32Array::from(vec![1, 2, 3]))], )?; let batch2 = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([4, 5]))], + vec![Arc::new(Int32Array::from(vec![4, 5]))], )?; let ctx = SessionContext::new(); @@ -630,11 +630,11 @@ async fn simple_mean() -> Result<()> { let batch1 = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([1, 2, 3]))], + vec![Arc::new(Int32Array::from(vec![1, 2, 3]))], )?; let batch2 = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([4, 5]))], + vec![Arc::new(Int32Array::from(vec![4, 5]))], )?; let ctx = SessionContext::new(); diff --git a/datafusion/core/tests/sql/functions.rs b/datafusion/core/tests/sql/functions.rs index cb9827cb7475..b7531cc6876a 100644 --- a/datafusion/core/tests/sql/functions.rs +++ b/datafusion/core/tests/sql/functions.rs @@ -81,43 +81,43 @@ async fn case_builtin_math_expression() { let type_values = vec![ ( DataType::Int8, - Arc::new(Int8Array::from_slice([1])) as ArrayRef, + Arc::new(Int8Array::from(vec![1])) as ArrayRef, ), ( DataType::Int16, - Arc::new(Int16Array::from_slice([1])) as ArrayRef, + Arc::new(Int16Array::from(vec![1])) as ArrayRef, ), ( DataType::Int32, - Arc::new(Int32Array::from_slice([1])) as ArrayRef, + Arc::new(Int32Array::from(vec![1])) as ArrayRef, ), ( DataType::Int64, - Arc::new(Int64Array::from_slice([1])) as ArrayRef, + Arc::new(Int64Array::from(vec![1])) as ArrayRef, ), ( DataType::UInt8, - Arc::new(UInt8Array::from_slice([1])) as ArrayRef, + Arc::new(UInt8Array::from(vec![1])) as ArrayRef, ), ( DataType::UInt16, - Arc::new(UInt16Array::from_slice([1])) as ArrayRef, + Arc::new(UInt16Array::from(vec![1])) as ArrayRef, ), ( DataType::UInt32, - Arc::new(UInt32Array::from_slice([1])) as ArrayRef, + Arc::new(UInt32Array::from(vec![1])) as ArrayRef, ), ( DataType::UInt64, - Arc::new(UInt64Array::from_slice([1])) as ArrayRef, + Arc::new(UInt64Array::from(vec![1])) as ArrayRef, ), ( DataType::Float32, - Arc::new(Float32Array::from_slice([1.0_f32])) as ArrayRef, + Arc::new(Float32Array::from(vec![1.0_f32])) as ArrayRef, ), ( DataType::Float64, - Arc::new(Float64Array::from_slice([1.0_f64])) as ArrayRef, + Arc::new(Float64Array::from(vec![1.0_f64])) as ArrayRef, ), ]; diff --git a/datafusion/core/tests/sql/information_schema.rs b/datafusion/core/tests/sql/information_schema.rs index 5927f36e18d9..68ac6c5d6290 100644 --- a/datafusion/core/tests/sql/information_schema.rs +++ b/datafusion/core/tests/sql/information_schema.rs @@ -160,12 +160,12 @@ fn table_with_many_types() -> Arc { let batch = RecordBatch::try_new( Arc::new(schema.clone()), vec![ - Arc::new(Int32Array::from_slice([1])), - Arc::new(Float64Array::from_slice([1.0])), + Arc::new(Int32Array::from(vec![1])), + Arc::new(Float64Array::from(vec![1.0])), Arc::new(StringArray::from(vec![Some("foo")])), Arc::new(LargeStringArray::from(vec![Some("bar")])), - Arc::new(BinaryArray::from_slice([b"foo" as &[u8]])), - Arc::new(LargeBinaryArray::from_slice([b"foo" as &[u8]])), + Arc::new(BinaryArray::from(vec![b"foo" as &[u8]])), + Arc::new(LargeBinaryArray::from(vec![b"foo" as &[u8]])), Arc::new(TimestampNanosecondArray::from(vec![Some(123)])), ], ) diff --git a/datafusion/core/tests/sql/joins.rs b/datafusion/core/tests/sql/joins.rs index 32e3de748327..118aeb043e44 100644 --- a/datafusion/core/tests/sql/joins.rs +++ b/datafusion/core/tests/sql/joins.rs @@ -16,7 +16,6 @@ // under the License. use super::*; -use datafusion::from_slice::FromSlice; #[tokio::test] async fn test_join_timestamp() -> Result<()> { @@ -72,7 +71,7 @@ async fn test_join_float32() -> Result<()> { population_schema.clone(), vec![ Arc::new(StringArray::from(vec![Some("a"), Some("b"), Some("c")])), - Arc::new(Float32Array::from_slice([838.698, 1778.934, 626.443])), + Arc::new(Float32Array::from(vec![838.698, 1778.934, 626.443])), ], )?; ctx.register_batch("population", population_data)?; @@ -111,7 +110,7 @@ async fn test_join_float64() -> Result<()> { population_schema.clone(), vec![ Arc::new(StringArray::from(vec![Some("a"), Some("b"), Some("c")])), - Arc::new(Float64Array::from_slice([838.698, 1778.934, 626.443])), + Arc::new(Float64Array::from(vec![838.698, 1778.934, 626.443])), ], )?; ctx.register_batch("population", population_data)?; @@ -213,10 +212,10 @@ async fn nestedjoin_without_alias() -> Result<()> { async fn join_tables_with_duplicated_column_name_not_in_on_constraint() -> Result<()> { let ctx = SessionContext::new(); let batch = RecordBatch::try_from_iter(vec![ - ("id", Arc::new(Int32Array::from_slice([1, 2, 3])) as _), + ("id", Arc::new(Int32Array::from(vec![1, 2, 3])) as _), ( "country", - Arc::new(StringArray::from_slice(["Germany", "Sweden", "Japan"])) as _, + Arc::new(StringArray::from(vec!["Germany", "Sweden", "Japan"])) as _, ), ]) .unwrap(); @@ -225,11 +224,11 @@ async fn join_tables_with_duplicated_column_name_not_in_on_constraint() -> Resul let batch = RecordBatch::try_from_iter(vec![ ( "id", - Arc::new(Int32Array::from_slice([1, 2, 3, 4, 5, 6, 7])) as _, + Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7])) as _, ), ( "city", - Arc::new(StringArray::from_slice([ + Arc::new(StringArray::from(vec![ "Hamburg", "Stockholm", "Osaka", @@ -241,7 +240,7 @@ async fn join_tables_with_duplicated_column_name_not_in_on_constraint() -> Resul ), ( "country_id", - Arc::new(Int32Array::from_slice([1, 2, 3, 1, 2, 3, 3])) as _, + Arc::new(Int32Array::from(vec![1, 2, 3, 1, 2, 3, 3])) as _, ), ]) .unwrap(); @@ -329,8 +328,8 @@ async fn left_join_should_not_panic_with_empty_side() -> Result<()> { let t1_data = RecordBatch::try_new( Arc::new(t1_schema), vec![ - Arc::new(Int64Array::from_slice([5247, 3821, 6321, 8821, 7748])), - Arc::new(StringArray::from_slice(["a", "b", "c", "d", "e"])), + Arc::new(Int64Array::from(vec![5247, 3821, 6321, 8821, 7748])), + Arc::new(StringArray::from(vec!["a", "b", "c", "d", "e"])), ], )?; ctx.register_batch("t1", t1_data)?; @@ -342,7 +341,7 @@ async fn left_join_should_not_panic_with_empty_side() -> Result<()> { let t2_data = RecordBatch::try_new( Arc::new(t2_schema), vec![ - Arc::new(Int64Array::from_slice([358, 2820, 3804, 7748])), + Arc::new(Int64Array::from(vec![358, 2820, 3804, 7748])), Arc::new(BooleanArray::from(vec![ Some(true), Some(false), diff --git a/datafusion/core/tests/sql/mod.rs b/datafusion/core/tests/sql/mod.rs index af79a10104d6..10660f787399 100644 --- a/datafusion/core/tests/sql/mod.rs +++ b/datafusion/core/tests/sql/mod.rs @@ -27,7 +27,6 @@ use chrono::Duration; use datafusion::config::ConfigOptions; use datafusion::datasource::TableProvider; -use datafusion::from_slice::FromSlice; use datafusion::logical_expr::{Aggregate, LogicalPlan, TableScan}; use datafusion::physical_plan::metrics::MetricValue; use datafusion::physical_plan::ExecutionPlan; @@ -169,14 +168,14 @@ fn create_join_context( let t1_data = RecordBatch::try_new( t1_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 33, 44])), + Arc::new(UInt32Array::from(vec![11, 22, 33, 44])), Arc::new(StringArray::from(vec![ Some("a"), Some("b"), Some("c"), Some("d"), ])), - Arc::new(UInt32Array::from_slice([1, 2, 3, 4])), + Arc::new(UInt32Array::from(vec![1, 2, 3, 4])), ], )?; ctx.register_batch("t1", t1_data)?; @@ -189,14 +188,14 @@ fn create_join_context( let t2_data = RecordBatch::try_new( t2_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 44, 55])), + Arc::new(UInt32Array::from(vec![11, 22, 44, 55])), Arc::new(StringArray::from(vec![ Some("z"), Some("y"), Some("x"), Some("w"), ])), - Arc::new(UInt32Array::from_slice([3, 1, 3, 3])), + Arc::new(UInt32Array::from(vec![3, 1, 3, 3])), ], )?; ctx.register_batch("t2", t2_data)?; @@ -225,14 +224,14 @@ fn create_sub_query_join_context( let t0_data = RecordBatch::try_new( t0_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 33, 44])), + Arc::new(UInt32Array::from(vec![11, 22, 33, 44])), Arc::new(StringArray::from(vec![ Some("a"), Some("b"), Some("c"), Some("d"), ])), - Arc::new(UInt32Array::from_slice([1, 2, 3, 4])), + Arc::new(UInt32Array::from(vec![1, 2, 3, 4])), ], )?; ctx.register_batch("t0", t0_data)?; @@ -245,14 +244,14 @@ fn create_sub_query_join_context( let t1_data = RecordBatch::try_new( t1_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 33, 44])), + Arc::new(UInt32Array::from(vec![11, 22, 33, 44])), Arc::new(StringArray::from(vec![ Some("a"), Some("b"), Some("c"), Some("d"), ])), - Arc::new(UInt32Array::from_slice([1, 2, 3, 4])), + Arc::new(UInt32Array::from(vec![1, 2, 3, 4])), ], )?; ctx.register_batch("t1", t1_data)?; @@ -265,14 +264,14 @@ fn create_sub_query_join_context( let t2_data = RecordBatch::try_new( t2_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 44, 55])), + Arc::new(UInt32Array::from(vec![11, 22, 44, 55])), Arc::new(StringArray::from(vec![ Some("z"), Some("y"), Some("x"), Some("w"), ])), - Arc::new(UInt32Array::from_slice([3, 1, 3, 3])), + Arc::new(UInt32Array::from(vec![3, 1, 3, 3])), ], )?; ctx.register_batch("t2", t2_data)?; @@ -316,7 +315,7 @@ fn create_left_semi_anti_join_context_with_null_ids( Some("d"), Some("e"), ])), - Arc::new(UInt32Array::from_slice([1, 1, 2, 3, 4, 0])), + Arc::new(UInt32Array::from(vec![1, 1, 2, 3, 4, 0])), ], )?; ctx.register_batch("t1", t1_data)?; @@ -345,7 +344,7 @@ fn create_left_semi_anti_join_context_with_null_ids( Some("w"), Some("v"), ])), - Arc::new(UInt32Array::from_slice([3, 3, 1, 3, 3, 0])), + Arc::new(UInt32Array::from(vec![3, 3, 1, 3, 3, 0])), ], )?; ctx.register_batch("t2", t2_data)?; @@ -387,7 +386,7 @@ fn create_right_semi_anti_join_context_with_null_ids( Some("d"), Some("e"), ])), - Arc::new(UInt32Array::from_slice([1, 2, 3, 4, 0])), + Arc::new(UInt32Array::from(vec![1, 2, 3, 4, 0])), ], )?; ctx.register_batch("t1", t1_data)?; @@ -423,9 +422,9 @@ fn create_join_context_qualified( let t1_data = RecordBatch::try_new( t1_schema, vec![ - Arc::new(UInt32Array::from_slice([1, 2, 3, 4])), - Arc::new(UInt32Array::from_slice([10, 20, 30, 40])), - Arc::new(UInt32Array::from_slice([50, 60, 70, 80])), + Arc::new(UInt32Array::from(vec![1, 2, 3, 4])), + Arc::new(UInt32Array::from(vec![10, 20, 30, 40])), + Arc::new(UInt32Array::from(vec![50, 60, 70, 80])), ], )?; ctx.register_batch(left_name, t1_data)?; @@ -438,9 +437,9 @@ fn create_join_context_qualified( let t2_data = RecordBatch::try_new( t2_schema, vec![ - Arc::new(UInt32Array::from_slice([1, 2, 9, 4])), - Arc::new(UInt32Array::from_slice([100, 200, 300, 400])), - Arc::new(UInt32Array::from_slice([500, 600, 700, 800])), + Arc::new(UInt32Array::from(vec![1, 2, 9, 4])), + Arc::new(UInt32Array::from(vec![100, 200, 300, 400])), + Arc::new(UInt32Array::from(vec![500, 600, 700, 800])), ], )?; ctx.register_batch(right_name, t2_data)?; @@ -535,14 +534,14 @@ fn create_sort_merge_join_context( let t1_data = RecordBatch::try_new( t1_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 33, 44])), + Arc::new(UInt32Array::from(vec![11, 22, 33, 44])), Arc::new(StringArray::from(vec![ Some("a"), Some("b"), Some("c"), Some("d"), ])), - Arc::new(UInt32Array::from_slice([1, 2, 3, 4])), + Arc::new(UInt32Array::from(vec![1, 2, 3, 4])), ], )?; ctx.register_batch("t1", t1_data)?; @@ -555,14 +554,14 @@ fn create_sort_merge_join_context( let t2_data = RecordBatch::try_new( t2_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 44, 55])), + Arc::new(UInt32Array::from(vec![11, 22, 44, 55])), Arc::new(StringArray::from(vec![ Some("z"), Some("y"), Some("x"), Some("w"), ])), - Arc::new(UInt32Array::from_slice([3, 1, 3, 3])), + Arc::new(UInt32Array::from(vec![3, 1, 3, 3])), ], )?; ctx.register_batch("t2", t2_data)?; @@ -660,14 +659,14 @@ fn create_nested_loop_join_context() -> Result { let t1_data = RecordBatch::try_new( t1_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 33, 44])), + Arc::new(UInt32Array::from(vec![11, 22, 33, 44])), Arc::new(StringArray::from(vec![ Some("a"), Some("b"), Some("c"), Some("d"), ])), - Arc::new(UInt32Array::from_slice([1, 2, 3, 4])), + Arc::new(UInt32Array::from(vec![1, 2, 3, 4])), ], )?; ctx.register_batch("t1", t1_data)?; @@ -680,14 +679,14 @@ fn create_nested_loop_join_context() -> Result { let t2_data = RecordBatch::try_new( t2_schema, vec![ - Arc::new(UInt32Array::from_slice([11, 22, 44, 55])), + Arc::new(UInt32Array::from(vec![11, 22, 44, 55])), Arc::new(StringArray::from(vec![ Some("z"), Some("y"), Some("x"), Some("w"), ])), - Arc::new(UInt32Array::from_slice([3, 1, 3, 3])), + Arc::new(UInt32Array::from(vec![3, 1, 3, 3])), ], )?; ctx.register_batch("t2", t2_data)?; diff --git a/datafusion/core/tests/sql/order.rs b/datafusion/core/tests/sql/order.rs index 07254c8044ae..100e5b8c44fb 100644 --- a/datafusion/core/tests/sql/order.rs +++ b/datafusion/core/tests/sql/order.rs @@ -102,7 +102,7 @@ async fn sort_with_duplicate_sort_exprs() -> Result<()> { t1_schema.clone(), vec![ Arc::new(Int32Array::from(vec![2, 4, 9, 3, 4])), - Arc::new(StringArray::from_slice(["a", "b", "c", "d", "e"])), + Arc::new(StringArray::from(vec!["a", "b", "c", "d", "e"])), ], )?; ctx.register_batch("t1", t1_data)?; diff --git a/datafusion/core/tests/sql/parquet.rs b/datafusion/core/tests/sql/parquet.rs index 0d780c6694e7..907a2c950672 100644 --- a/datafusion/core/tests/sql/parquet.rs +++ b/datafusion/core/tests/sql/parquet.rs @@ -311,9 +311,9 @@ async fn parquet_query_with_max_min() { .unwrap(); // create mock record batch - let c1s = Arc::new(Int32Array::from_slice([1, 2, 3])); - let c2s = Arc::new(StringArray::from_slice(["aaa", "bbb", "ccc"])); - let c3s = Arc::new(Int64Array::from_slice([100, 200, 300])); + let c1s = Arc::new(Int32Array::from(vec![1, 2, 3])); + let c2s = Arc::new(StringArray::from(vec!["aaa", "bbb", "ccc"])); + let c3s = Arc::new(Int64Array::from(vec![100, 200, 300])); let c4s = Arc::new(Date32Array::from(vec![Some(1), Some(2), Some(3)])); let rec_batch = RecordBatch::try_new(schema.clone(), vec![c1s, c2s, c3s, c4s]).unwrap(); diff --git a/datafusion/core/tests/sql/parquet_schema.rs b/datafusion/core/tests/sql/parquet_schema.rs index 7de83046af11..1d96f2b1ff97 100644 --- a/datafusion/core/tests/sql/parquet_schema.rs +++ b/datafusion/core/tests/sql/parquet_schema.rs @@ -176,8 +176,8 @@ fn write_files(table_path: &Path, schemas: Vec) { let mut writer = ArrowWriter::try_new(file, schema.clone(), None).unwrap(); // create mock record batch - let ids = Arc::new(Int32Array::from_slice([i as i32])); - let names = Arc::new(StringArray::from_slice(["test"])); + let ids = Arc::new(Int32Array::from(vec![i as i32])); + let names = Arc::new(StringArray::from(vec!["test"])); let rec_batch = RecordBatch::try_new(schema.clone(), vec![ids, names]).unwrap(); writer.write(&rec_batch).unwrap(); diff --git a/datafusion/core/tests/sql/projection.rs b/datafusion/core/tests/sql/projection.rs index ac697b11768c..a90cf1a2c202 100644 --- a/datafusion/core/tests/sql/projection.rs +++ b/datafusion/core/tests/sql/projection.rs @@ -270,9 +270,9 @@ async fn projection_on_memory_scan() -> Result<()> { let partitions = vec![vec![RecordBatch::try_new( schema.clone(), vec![ - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), - Arc::new(Int32Array::from_slice([2, 12, 12, 120])), - Arc::new(Int32Array::from_slice([3, 12, 12, 120])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), + Arc::new(Int32Array::from(vec![2, 12, 12, 120])), + Arc::new(Int32Array::from(vec![3, 12, 12, 120])), ], )?]]; diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs index 68a3a7008e84..2058d8ed1fd6 100644 --- a/datafusion/core/tests/sql/timestamp.rs +++ b/datafusion/core/tests/sql/timestamp.rs @@ -16,7 +16,6 @@ // under the License. use super::*; -use datafusion::from_slice::FromSlice; use std::ops::Add; #[tokio::test] @@ -509,7 +508,7 @@ async fn group_by_timestamp_millis() -> Result<()> { schema.clone(), vec![ Arc::new(TimestampMillisecondArray::from(timestamps)), - Arc::new(Int32Array::from_slice([10, 20, 30, 40, 50, 60])), + Arc::new(Int32Array::from(vec![10, 20, 30, 40, 50, 60])), ], )?; ctx.register_batch("t1", data).unwrap(); diff --git a/datafusion/core/tests/sql/udf.rs b/datafusion/core/tests/sql/udf.rs index 3f4402ec410a..a31028fd71cb 100644 --- a/datafusion/core/tests/sql/udf.rs +++ b/datafusion/core/tests/sql/udf.rs @@ -48,8 +48,8 @@ async fn scalar_udf() -> Result<()> { let batch = RecordBatch::try_new( Arc::new(schema.clone()), vec![ - Arc::new(Int32Array::from_slice([1, 10, 10, 100])), - Arc::new(Int32Array::from_slice([2, 12, 12, 120])), + Arc::new(Int32Array::from(vec![1, 10, 10, 100])), + Arc::new(Int32Array::from(vec![2, 12, 12, 120])), ], )?; @@ -127,7 +127,7 @@ async fn scalar_udf_zero_params() -> Result<()> { let batch = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([1, 10, 10, 100]))], + vec![Arc::new(Int32Array::from(vec![1, 10, 10, 100]))], )?; let ctx = SessionContext::new(); @@ -186,11 +186,11 @@ async fn simple_udaf() -> Result<()> { let batch1 = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([1, 2, 3]))], + vec![Arc::new(Int32Array::from(vec![1, 2, 3]))], )?; let batch2 = RecordBatch::try_new( Arc::new(schema.clone()), - vec![Arc::new(Int32Array::from_slice([4, 5]))], + vec![Arc::new(Int32Array::from(vec![4, 5]))], )?; let ctx = SessionContext::new(); diff --git a/datafusion/physical-expr/src/functions.rs b/datafusion/physical-expr/src/functions.rs index e8b262c7617c..648dd4a144c6 100644 --- a/datafusion/physical-expr/src/functions.rs +++ b/datafusion/physical-expr/src/functions.rs @@ -811,7 +811,6 @@ mod tests { use super::*; use crate::expressions::try_cast; use crate::expressions::{col, lit}; - use crate::from_slice::FromSlice; use arrow::{ array::{ Array, ArrayRef, BinaryArray, BooleanArray, Float32Array, Float64Array, @@ -839,7 +838,7 @@ mod tests { // any type works here: we evaluate against a literal of `value` let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]); - let columns: Vec = vec![Arc::new(Int32Array::from_slice(&[1]))]; + let columns: Vec = vec![Arc::new(Int32Array::from(vec![1]))]; let expr = create_physical_expr_with_type_coercion(&BuiltinScalarFunction::$FUNC, $ARGS, &schema, &execution_props)?; @@ -2816,7 +2815,7 @@ mod tests { let schema = Schema::new(vec![Field::new("a", DataType::Utf8, false)]); let execution_props = ExecutionProps::new(); - let col_value: ArrayRef = Arc::new(StringArray::from_slice(["aaa-555"])); + let col_value: ArrayRef = Arc::new(StringArray::from(vec!["aaa-555"])); let pattern = lit(r".*-(\d*)"); let columns: Vec = vec![col_value]; let expr = create_physical_expr_with_type_coercion( @@ -2857,7 +2856,7 @@ mod tests { let col_value = lit("aaa-555"); let pattern = lit(r".*-(\d*)"); - let columns: Vec = vec![Arc::new(Int32Array::from_slice([1]))]; + let columns: Vec = vec![Arc::new(Int32Array::from(vec![1]))]; let expr = create_physical_expr_with_type_coercion( &BuiltinScalarFunction::RegexpMatch, &[col_value, pattern], diff --git a/datafusion/physical-expr/src/hash_utils.rs b/datafusion/physical-expr/src/hash_utils.rs index ab2377da94aa..b751df928d2a 100644 --- a/datafusion/physical-expr/src/hash_utils.rs +++ b/datafusion/physical-expr/src/hash_utils.rs @@ -284,7 +284,6 @@ pub fn create_row_hashes_v2<'a>( #[cfg(test)] mod tests { - use crate::from_slice::FromSlice; use arrow::{array::*, datatypes::*}; use std::sync::Arc; @@ -308,8 +307,8 @@ mod tests { #[test] fn create_hashes_for_float_arrays() -> Result<()> { - let f32_arr = Arc::new(Float32Array::from_slice([0.12, 0.5, 1f32, 444.7])); - let f64_arr = Arc::new(Float64Array::from_slice([0.12, 0.5, 1f64, 444.7])); + let f32_arr = Arc::new(Float32Array::from(vec![0.12, 0.5, 1f32, 444.7])); + let f64_arr = Arc::new(Float64Array::from(vec![0.12, 0.5, 1f64, 444.7])); let random_state = RandomState::with_seeds(0, 0, 0, 0); let hashes_buff = &mut vec![0; f32_arr.len()]; diff --git a/datafusion/physical-expr/src/lib.rs b/datafusion/physical-expr/src/lib.rs index 21a88b5d891d..0a2e0e58df7a 100644 --- a/datafusion/physical-expr/src/lib.rs +++ b/datafusion/physical-expr/src/lib.rs @@ -46,7 +46,6 @@ pub mod window; // reexport this to maintain compatibility with anything that used from_slice previously pub use aggregate::AggregateExpr; -pub use datafusion_common::from_slice; pub use equivalence::{ project_equivalence_properties, project_ordering_equivalence_properties, EquivalenceProperties, EquivalentClass, OrderingEquivalenceProperties, diff --git a/datafusion/physical-expr/src/window/nth_value.rs b/datafusion/physical-expr/src/window/nth_value.rs index 4da91e75ef20..4bfe514c38da 100644 --- a/datafusion/physical-expr/src/window/nth_value.rs +++ b/datafusion/physical-expr/src/window/nth_value.rs @@ -252,7 +252,7 @@ mod tests { Arc::new(Column::new("arr", 0)), DataType::Int32, ); - test_i32_result(first_value, Int32Array::from_iter_values(vec![1; 8]))?; + test_i32_result(first_value, Int32Array::from(vec![1; 8]))?; Ok(()) } @@ -287,7 +287,7 @@ mod tests { DataType::Int32, 1, )?; - test_i32_result(nth_value, Int32Array::from_iter_values(vec![1; 8]))?; + test_i32_result(nth_value, Int32Array::from(vec![1; 8]))?; Ok(()) } diff --git a/datafusion/physical-expr/src/window/ntile.rs b/datafusion/physical-expr/src/window/ntile.rs index b8365dba19d0..479fa263337a 100644 --- a/datafusion/physical-expr/src/window/ntile.rs +++ b/datafusion/physical-expr/src/window/ntile.rs @@ -77,6 +77,6 @@ impl PartitionEvaluator for NtileEvaluator { let res = i * self.n / num_rows; vec.push(res + 1) } - Ok(Arc::new(UInt64Array::from_iter_values(vec))) + Ok(Arc::new(UInt64Array::from(vec))) } } diff --git a/datafusion/physical-expr/src/window/window_frame_state.rs b/datafusion/physical-expr/src/window/window_frame_state.rs index 01a4f9ad71a8..e23a58a09b66 100644 --- a/datafusion/physical-expr/src/window/window_frame_state.rs +++ b/datafusion/physical-expr/src/window/window_frame_state.rs @@ -550,14 +550,13 @@ mod tests { use crate::window::window_frame_state::WindowFrameStateGroups; use arrow::array::{ArrayRef, Float64Array}; use arrow_schema::SortOptions; - use datafusion_common::from_slice::FromSlice; use datafusion_common::{Result, ScalarValue}; use datafusion_expr::{WindowFrame, WindowFrameBound, WindowFrameUnits}; use std::ops::Range; use std::sync::Arc; fn get_test_data() -> (Vec, Vec) { - let range_columns: Vec = vec![Arc::new(Float64Array::from_slice([ + let range_columns: Vec = vec![Arc::new(Float64Array::from(vec![ 5.0, 7.0, 8.0, 8.0, 9., 10., 10., 10., 11., ]))]; let sort_options = vec![SortOptions {