Apache DataFusion SQL Query Engine
flx clippy warnings (#8455)
Ruihang Xiac0c9e8888878
diff --git a/datafusion-examples/examples/custom_datasource.rs b/datafusion-examples/examples/custom_datasource.rsindex 9f25a0b2fa..69f9c9530e 100644--- a/datafusion-examples/examples/custom_datasource.rs+++ b/datafusion-examples/examples/custom_datasource.rs@@ -80,7 +80,7 @@ async fn search_accounts(timeout(Duration::from_secs(10), async move {let result = dataframe.collect().await.unwrap();- let record_batch = result.get(0).unwrap();+ let record_batch = result.first().unwrap();assert_eq!(expected_result_length, record_batch.column(1).len());dbg!(record_batch.columns());diff --git a/datafusion-examples/examples/memtable.rs b/datafusion-examples/examples/memtable.rsindex bef8f3e5bb..5cce578039 100644--- a/datafusion-examples/examples/memtable.rs+++ b/datafusion-examples/examples/memtable.rs@@ -40,7 +40,7 @@ async fn main() -> Result<()> {timeout(Duration::from_secs(10), async move {let result = dataframe.collect().await.unwrap();- let record_batch = result.get(0).unwrap();+ let record_batch = result.first().unwrap();assert_eq!(1, record_batch.column(0).len());dbg!(record_batch.columns());diff --git a/datafusion-examples/examples/simple_udtf.rs b/datafusion-examples/examples/simple_udtf.rsindex bce6337652..e120c5e7bf 100644--- a/datafusion-examples/examples/simple_udtf.rs+++ b/datafusion-examples/examples/simple_udtf.rs@@ -129,7 +129,7 @@ struct LocalCsvTableFunc {}impl TableFunctionImpl for LocalCsvTableFunc {fn call(&self, exprs: &[Expr]) -> Result<Arc<dyn TableProvider>> {- let Some(Expr::Literal(ScalarValue::Utf8(Some(ref path)))) = exprs.get(0) else {+ let Some(Expr::Literal(ScalarValue::Utf8(Some(ref path)))) = exprs.first() else {return plan_err!("read_csv requires at least one string argument");};diff --git a/datafusion/common/src/dfschema.rs b/datafusion/common/src/dfschema.rsindex 52cd856758..9819ae795b 100644--- a/datafusion/common/src/dfschema.rs+++ b/datafusion/common/src/dfschema.rs@@ -1476,8 +1476,8 @@ mod tests {DFSchema::new_with_metadata([a, b].to_vec(), HashMap::new()).unwrap(),);let schema: Schema = df_schema.as_ref().clone().into();- let a_df = df_schema.fields.get(0).unwrap().field();- let a_arrow = schema.fields.get(0).unwrap();+ let a_df = df_schema.fields.first().unwrap().field();+ let a_arrow = schema.fields.first().unwrap();assert_eq!(a_df.metadata(), a_arrow.metadata())}diff --git a/datafusion/common/src/error.rs b/datafusion/common/src/error.rsindex 9114c669ab..4ae30ae86c 100644--- a/datafusion/common/src/error.rs+++ b/datafusion/common/src/error.rs@@ -564,18 +564,16 @@ mod test {assert_eq!(err.split(DataFusionError::BACK_TRACE_SEP).collect::<Vec<&str>>()- .get(0)+ .first().unwrap(),&"Error during planning: Err");- assert!(- err.split(DataFusionError::BACK_TRACE_SEP)- .collect::<Vec<&str>>()- .get(1)- .unwrap()- .len()- > 0- );+ assert!(!err+ .split(DataFusionError::BACK_TRACE_SEP)+ .collect::<Vec<&str>>()+ .get(1)+ .unwrap()+ .is_empty());}#[cfg(not(feature = "backtrace"))]diff --git a/datafusion/common/src/utils.rs b/datafusion/common/src/utils.rsindex 7f2dc61c07..9094ecd063 100644--- a/datafusion/common/src/utils.rs+++ b/datafusion/common/src/utils.rs@@ -135,7 +135,7 @@ pub fn bisect<const SIDE: bool>() -> Result<usize> {let low: usize = 0;let high: usize = item_columns- .get(0)+ .first().ok_or_else(|| {DataFusionError::Internal("Column array shouldn't be empty".to_string())})?@@ -186,7 +186,7 @@ pub fn linear_search<const SIDE: bool>() -> Result<usize> {let low: usize = 0;let high: usize = item_columns- .get(0)+ .first().ok_or_else(|| {DataFusionError::Internal("Column array shouldn't be empty".to_string())})?diff --git a/datafusion/core/benches/sort_limit_query_sql.rs b/datafusion/core/benches/sort_limit_query_sql.rsindex efed5a04e7..cfd4b8bc4b 100644--- a/datafusion/core/benches/sort_limit_query_sql.rs+++ b/datafusion/core/benches/sort_limit_query_sql.rs@@ -99,7 +99,7 @@ fn create_context() -> Arc<Mutex<SessionContext>> {ctx_holder.lock().push(Arc::new(Mutex::new(ctx)))});- let ctx = ctx_holder.lock().get(0).unwrap().clone();+ let ctx = ctx_holder.lock().first().unwrap().clone();ctx}diff --git a/datafusion/core/benches/sql_query_with_io.rs b/datafusion/core/benches/sql_query_with_io.rsindex 1f9b4dc6cc..c7a838385b 100644--- a/datafusion/core/benches/sql_query_with_io.rs+++ b/datafusion/core/benches/sql_query_with_io.rs@@ -93,10 +93,9 @@ async fn setup_files(store: Arc<dyn ObjectStore>) {for partition in 0..TABLE_PARTITIONS {for file in 0..PARTITION_FILES {let data = create_parquet_file(&mut rng, file * FILE_ROWS);- let location = Path::try_from(format!(+ let location = Path::from(format!("{table_name}/partition={partition}/{file}.parquet"- ))- .unwrap();+ ));store.put(&location, data).await.unwrap();}}diff --git a/datafusion/core/src/datasource/file_format/parquet.rs b/datafusion/core/src/datasource/file_format/parquet.rsindex cf6b874081..09e54558f1 100644--- a/datafusion/core/src/datasource/file_format/parquet.rs+++ b/datafusion/core/src/datasource/file_format/parquet.rs@@ -1803,8 +1803,8 @@ mod tests {// there is only one row group in one file.assert_eq!(page_index.len(), 1);assert_eq!(offset_index.len(), 1);- let page_index = page_index.get(0).unwrap();- let offset_index = offset_index.get(0).unwrap();+ let page_index = page_index.first().unwrap();+ let offset_index = offset_index.first().unwrap();// 13 col in one row groupassert_eq!(page_index.len(), 13);diff --git a/datafusion/core/src/datasource/file_format/write/demux.rs b/datafusion/core/src/datasource/file_format/write/demux.rsindex 27c65dd459..fa4ed84370 100644--- a/datafusion/core/src/datasource/file_format/write/demux.rs+++ b/datafusion/core/src/datasource/file_format/write/demux.rs@@ -264,12 +264,9 @@ async fn hive_style_partitions_demuxer(// TODO: upstream RecordBatch::take to arrow-rslet take_indices = builder.finish();let struct_array: StructArray = rb.clone().into();- let parted_batch = RecordBatch::try_from(+ let parted_batch = RecordBatch::from(arrow::compute::take(&struct_array, &take_indices, None)?.as_struct(),- )- .map_err(|_| {- DataFusionError::Internal("Unexpected error partitioning batch!".into())- })?;+ );// Get or create channel for this batchlet part_tx = match value_map.get_mut(&part_key) {diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rsindex effeacc480..a7f69a1d3c 100644--- a/datafusion/core/src/datasource/listing/table.rs+++ b/datafusion/core/src/datasource/listing/table.rs@@ -157,7 +157,7 @@ impl ListingTableConfig {/// Infer `ListingOptions` based on `table_path` suffix.pub async fn infer_options(self, state: &SessionState) -> Result<Self> {- let store = if let Some(url) = self.table_paths.get(0) {+ let store = if let Some(url) = self.table_paths.first() {state.runtime_env().object_store(url)?} else {return Ok(self);@@ -165,7 +165,7 @@ impl ListingTableConfig {let file = self.table_paths- .get(0)+ .first().unwrap().list_all_files(state, store.as_ref(), "").await?@@ -191,7 +191,7 @@ impl ListingTableConfig {pub async fn infer_schema(self, state: &SessionState) -> Result<Self> {match self.options {Some(options) => {- let schema = if let Some(url) = self.table_paths.get(0) {+ let schema = if let Some(url) = self.table_paths.first() {options.infer_schema(state, url).await?} else {Arc::new(Schema::empty())@@ -710,7 +710,7 @@ impl TableProvider for ListingTable {None};- let object_store_url = if let Some(url) = self.table_paths.get(0) {+ let object_store_url = if let Some(url) = self.table_paths.first() {url.object_store()} else {return Ok(Arc::new(EmptyExec::new(false, Arc::new(Schema::empty()))));@@ -835,7 +835,7 @@ impl TableProvider for ListingTable {// Multiple sort orders in outer vec are equivalent, so we pass only the first onelet ordering = self.try_create_output_ordering()?- .get(0)+ .first().ok_or(DataFusionError::Internal("Expected ListingTable to have a sort order, but none found!".into(),))?@@ -872,7 +872,7 @@ impl ListingTable {filters: &'a [Expr],limit: Option<usize>,) -> Result<(Vec<Vec<PartitionedFile>>, Statistics)> {- let store = if let Some(url) = self.table_paths.get(0) {+ let store = if let Some(url) = self.table_paths.first() {ctx.runtime_env().object_store(url)?} else {return Ok((vec![], Statistics::new_unknown(&self.file_schema)));diff --git a/datafusion/core/src/datasource/physical_plan/json.rs b/datafusion/core/src/datasource/physical_plan/json.rsindex 73dcb32ac8..9c3b523a65 100644--- a/datafusion/core/src/datasource/physical_plan/json.rs+++ b/datafusion/core/src/datasource/physical_plan/json.rs@@ -357,9 +357,9 @@ mod tests {).unwrap();let meta = file_groups- .get(0)+ .first().unwrap()- .get(0)+ .first().unwrap().clone().object_meta;@@ -391,9 +391,9 @@ mod tests {).unwrap();let path = file_groups- .get(0)+ .first().unwrap()- .get(0)+ .first().unwrap().object_meta.locationdiff --git a/datafusion/core/src/datasource/physical_plan/mod.rs b/datafusion/core/src/datasource/physical_plan/mod.rsindex 4cf115d03a..14e550eab1 100644--- a/datafusion/core/src/datasource/physical_plan/mod.rs+++ b/datafusion/core/src/datasource/physical_plan/mod.rs@@ -135,7 +135,7 @@ impl DisplayAs for FileScanConfig {write!(f, ", infinite_source=true")?;}- if let Some(ordering) = orderings.get(0) {+ if let Some(ordering) = orderings.first() {if !ordering.is_empty() {let start = if orderings.len() == 1 {", output_ordering="diff --git a/datafusion/core/src/physical_planner.rs b/datafusion/core/src/physical_planner.rsindex 65a2e4e0a4..38532002a6 100644--- a/datafusion/core/src/physical_planner.rs+++ b/datafusion/core/src/physical_planner.rs@@ -2012,7 +2012,7 @@ impl DefaultPhysicalPlanner {let mut column_names = StringBuilder::new();let mut data_types = StringBuilder::new();let mut is_nullables = StringBuilder::new();- for (_, field) in table_schema.fields().iter().enumerate() {+ for field in table_schema.fields() {column_names.append_value(field.name());// "System supplied type" --> Use debug format of the datatypediff --git a/datafusion/core/tests/parquet/file_statistics.rs b/datafusion/core/tests/parquet/file_statistics.rsindex 1ea154303d..9f94a59a3e 100644--- a/datafusion/core/tests/parquet/file_statistics.rs+++ b/datafusion/core/tests/parquet/file_statistics.rs@@ -133,7 +133,7 @@ async fn list_files_with_session_level_cache() {assert_eq!(get_list_file_cache_size(&state1), 1);let fg = &parquet1.base_config().file_groups;assert_eq!(fg.len(), 1);- assert_eq!(fg.get(0).unwrap().len(), 1);+ assert_eq!(fg.first().unwrap().len(), 1);//Session 2 first time list files//check session 1 cache result not show in session 2@@ -144,7 +144,7 @@ async fn list_files_with_session_level_cache() {assert_eq!(get_list_file_cache_size(&state2), 1);let fg2 = &parquet2.base_config().file_groups;assert_eq!(fg2.len(), 1);- assert_eq!(fg2.get(0).unwrap().len(), 1);+ assert_eq!(fg2.first().unwrap().len(), 1);//Session 1 second time list files//check session 1 cache result not show in session 2@@ -155,7 +155,7 @@ async fn list_files_with_session_level_cache() {assert_eq!(get_list_file_cache_size(&state1), 1);let fg = &parquet3.base_config().file_groups;assert_eq!(fg.len(), 1);- assert_eq!(fg.get(0).unwrap().len(), 1);+ assert_eq!(fg.first().unwrap().len(), 1);// List same file no increaseassert_eq!(get_list_file_cache_size(&state1), 1);}diff --git a/datafusion/core/tests/sql/mod.rs b/datafusion/core/tests/sql/mod.rsindex 47de6ec857..94fc8015a7 100644--- a/datafusion/core/tests/sql/mod.rs+++ b/datafusion/core/tests/sql/mod.rs@@ -15,7 +15,6 @@// specific language governing permissions and limitations// under the License.-use std::convert::TryFrom;use std::sync::Arc;use arrow::{diff --git a/datafusion/core/tests/sql/parquet.rs b/datafusion/core/tests/sql/parquet.rsindex c2844a2b76..8f810a929d 100644--- a/datafusion/core/tests/sql/parquet.rs+++ b/datafusion/core/tests/sql/parquet.rs@@ -263,7 +263,7 @@ async fn parquet_list_columns() {assert_eq!(as_string_array(&utf8_list_array.value(0)).unwrap(),- &StringArray::try_from(vec![Some("abc"), Some("efg"), Some("hij"),]).unwrap()+ &StringArray::from(vec![Some("abc"), Some("efg"), Some("hij"),]));assert_eq!(diff --git a/datafusion/execution/src/cache/cache_unit.rs b/datafusion/execution/src/cache/cache_unit.rsindex c54839061c..25f9b9fa4d 100644--- a/datafusion/execution/src/cache/cache_unit.rs+++ b/datafusion/execution/src/cache/cache_unit.rs@@ -228,7 +228,7 @@ mod tests {cache.put(&meta.location, vec![meta.clone()].into());assert_eq!(- cache.get(&meta.location).unwrap().get(0).unwrap().clone(),+ cache.get(&meta.location).unwrap().first().unwrap().clone(),meta.clone());}diff --git a/datafusion/expr/src/utils.rs b/datafusion/expr/src/utils.rsindex 7d126a0f33..c30c734fcf 100644--- a/datafusion/expr/src/utils.rs+++ b/datafusion/expr/src/utils.rs@@ -501,7 +501,6 @@ pub fn generate_sort_key(let res = final_sort_keys.into_iter().zip(is_partition_flag)- .map(|(lhs, rhs)| (lhs, rhs)).collect::<Vec<_>>();Ok(res)}diff --git a/datafusion/optimizer/src/eliminate_limit.rs b/datafusion/optimizer/src/eliminate_limit.rsindex 7844ca7909..4386253740 100644--- a/datafusion/optimizer/src/eliminate_limit.rs+++ b/datafusion/optimizer/src/eliminate_limit.rs@@ -97,7 +97,7 @@ mod tests {let optimizer = Optimizer::with_rules(vec![Arc::new(EliminateLimit::new())]);let optimized_plan = optimizer.optimize_recursively(- optimizer.rules.get(0).unwrap(),+ optimizer.rules.first().unwrap(),plan,&OptimizerContext::new(),)?diff --git a/datafusion/optimizer/src/push_down_filter.rs b/datafusion/optimizer/src/push_down_filter.rsindex e8f116d894..c090fb849a 100644--- a/datafusion/optimizer/src/push_down_filter.rs+++ b/datafusion/optimizer/src/push_down_filter.rs@@ -1062,7 +1062,7 @@ mod tests {]);let mut optimized_plan = optimizer.optimize_recursively(- optimizer.rules.get(0).unwrap(),+ optimizer.rules.first().unwrap(),plan,&OptimizerContext::new(),)?diff --git a/datafusion/optimizer/src/push_down_projection.rs b/datafusion/optimizer/src/push_down_projection.rsindex bdd6634763..10cc1879ae 100644--- a/datafusion/optimizer/src/push_down_projection.rs+++ b/datafusion/optimizer/src/push_down_projection.rs@@ -625,7 +625,7 @@ mod tests {let optimizer = Optimizer::with_rules(vec![Arc::new(OptimizeProjections::new())]);let optimized_plan = optimizer.optimize_recursively(- optimizer.rules.get(0).unwrap(),+ optimizer.rules.first().unwrap(),plan,&OptimizerContext::new(),)?diff --git a/datafusion/optimizer/src/test/mod.rs b/datafusion/optimizer/src/test/mod.rsindex 917ddc565c..e691fe9a53 100644--- a/datafusion/optimizer/src/test/mod.rs+++ b/datafusion/optimizer/src/test/mod.rs@@ -158,7 +158,7 @@ pub fn assert_optimized_plan_eq(let optimizer = Optimizer::with_rules(vec![rule.clone()]);let optimized_plan = optimizer.optimize_recursively(- optimizer.rules.get(0).unwrap(),+ optimizer.rules.first().unwrap(),plan,&OptimizerContext::new(),)?@@ -199,7 +199,7 @@ pub fn assert_optimized_plan_eq_display_indent(let optimizer = Optimizer::with_rules(vec![rule]);let optimized_plan = optimizer.optimize_recursively(- optimizer.rules.get(0).unwrap(),+ optimizer.rules.first().unwrap(),plan,&OptimizerContext::new(),)@@ -233,7 +233,7 @@ pub fn assert_optimizer_err() {let optimizer = Optimizer::with_rules(vec![rule]);let res = optimizer.optimize_recursively(- optimizer.rules.get(0).unwrap(),+ optimizer.rules.first().unwrap(),plan,&OptimizerContext::new(),);@@ -255,7 +255,7 @@ pub fn assert_optimization_skipped(let optimizer = Optimizer::with_rules(vec![rule]);let new_plan = optimizer.optimize_recursively(- optimizer.rules.get(0).unwrap(),+ optimizer.rules.first().unwrap(),plan,&OptimizerContext::new(),)?diff --git a/datafusion/physical-expr/src/aggregate/groups_accumulator/adapter.rs b/datafusion/physical-expr/src/aggregate/groups_accumulator/adapter.rsindex dcc8c37e74..cf980f4c3f 100644--- a/datafusion/physical-expr/src/aggregate/groups_accumulator/adapter.rs+++ b/datafusion/physical-expr/src/aggregate/groups_accumulator/adapter.rs@@ -309,7 +309,7 @@ impl GroupsAccumulator for GroupsAccumulatorAdapter {// double check each array has the same length (aka the// accumulator was implemented correctly- if let Some(first_col) = arrays.get(0) {+ if let Some(first_col) = arrays.first() {for arr in &arrays {assert_eq!(arr.len(), first_col.len())}diff --git a/datafusion/physical-expr/src/array_expressions.rs b/datafusion/physical-expr/src/array_expressions.rsindex 269bbf7dcf..08df3ef9f6 100644--- a/datafusion/physical-expr/src/array_expressions.rs+++ b/datafusion/physical-expr/src/array_expressions.rs@@ -537,7 +537,7 @@ fn general_except<OffsetSize: OffsetSizeTrait>(dedup.clear();}- if let Some(values) = converter.convert_rows(rows)?.get(0) {+ if let Some(values) = converter.convert_rows(rows)?.first() {Ok(GenericListArray::<OffsetSize>::new(field.to_owned(),OffsetBuffer::new(offsets.into()),@@ -2088,7 +2088,7 @@ pub fn array_intersect(args: &[ArrayRef]) -> Result<ArrayRef> {};offsets.push(last_offset + rows.len() as i32);let arrays = converter.convert_rows(rows)?;- let array = match arrays.get(0) {+ let array = match arrays.first() {Some(array) => array.clone(),None => {return internal_err!(diff --git a/datafusion/physical-plan/src/memory.rs b/datafusion/physical-plan/src/memory.rsindex 39cd47452e..7de474fda1 100644--- a/datafusion/physical-plan/src/memory.rs+++ b/datafusion/physical-plan/src/memory.rs@@ -55,7 +55,7 @@ impl fmt::Debug for MemoryExec {write!(f, "partitions: [...]")?;write!(f, "schema: {:?}", self.projected_schema)?;write!(f, "projection: {:?}", self.projection)?;- if let Some(sort_info) = &self.sort_information.get(0) {+ if let Some(sort_info) = &self.sort_information.first() {write!(f, ", output_ordering: {:?}", sort_info)?;}Ok(())diff --git a/datafusion/physical-plan/src/test/exec.rs b/datafusion/physical-plan/src/test/exec.rsindex 71e6cba674..1f6ee1f117 100644--- a/datafusion/physical-plan/src/test/exec.rs+++ b/datafusion/physical-plan/src/test/exec.rs@@ -790,7 +790,7 @@ impl Stream for PanicStream {} else {self.ready = true;// get called again- cx.waker().clone().wake();+ cx.waker().wake_by_ref();return Poll::Pending;}}diff --git a/datafusion/sql/src/relation/mod.rs b/datafusion/sql/src/relation/mod.rsindex 6fc7e96012..b233f47a05 100644--- a/datafusion/sql/src/relation/mod.rs+++ b/datafusion/sql/src/relation/mod.rs@@ -36,7 +36,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {name, alias, args, ..} => {if let Some(func_args) = args {- let tbl_func_name = name.0.get(0).unwrap().value.to_string();+ let tbl_func_name = name.0.first().unwrap().value.to_string();let args = func_args.into_iter().flat_map(|arg| {