Skip to content

Commit

Permalink
fix clippy failures (#5081)
Browse files Browse the repository at this point in the history
* fix clippy failures

* more fixes

* clippy --fix

* avro fixes

* cargo clippy --fix --features pyarrow,jit

* remove lifetime annotation
  • Loading branch information
andygrove authored Jan 26, 2023
1 parent d588b47 commit 7e94826
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 115 deletions.
2 changes: 1 addition & 1 deletion datafusion-examples/examples/avro_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn main() -> Result<()> {
let testdata = datafusion::test_util::arrow_test_data();

// register avro file with the execution context
let avro_file = &format!("{}/avro/alltypes_plain.avro", testdata);
let avro_file = &format!("{testdata}/avro/alltypes_plain.avro");
ctx.register_avro("alltypes_plain", avro_file, AvroReadOptions::default())
.await?;

Expand Down
3 changes: 1 addition & 2 deletions datafusion/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ impl ConfigField for ConfigOptions {
"optimizer" => self.optimizer.set(rem, value),
"explain" => self.explain.set(rem, value),
_ => Err(DataFusionError::Internal(format!(
"Config value \"{}\" not found on ConfigOptions",
key
"Config value \"{key}\" not found on ConfigOptions"
))),
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Display for DataFusionError {
}
#[cfg(feature = "avro")]
DataFusionError::AvroError(ref desc) => {
write!(f, "Avro error: {}", desc)
write!(f, "Avro error: {desc}")
}
DataFusionError::IoError(ref desc) => write!(f, "IO error: {desc}"),
DataFusionError::SQL(ref desc) => {
Expand Down
5 changes: 2 additions & 3 deletions datafusion/common/src/pyarrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ mod tests {
let python_path: Vec<&str> =
locals.get_item("python_path").unwrap().extract().unwrap();

panic!("pyarrow not found\nExecutable: {}\nPython path: {:?}\n\
panic!("pyarrow not found\nExecutable: {executable}\nPython path: {python_path:?}\n\
HINT: try `pip install pyarrow`\n\
NOTE: On Mac OS, you must compile against a Framework Python \
(default in python.org installers and brew, but not pyenv)\n\
NOTE: On Mac OS, PYO3 might point to incorrect Python library \
path when using virtual environments. Try \
`export PYTHONPATH=$(python -c \"import sys; print(sys.path[-1])\")`\n",
executable, python_path)
`export PYTHONPATH=$(python -c \"import sys; print(sys.path[-1])\")`\n")
}
})
}
Expand Down
30 changes: 11 additions & 19 deletions datafusion/core/src/avro_to_arrow/arrow_array_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ impl<'a, R: Read> AvroArrowArrayReader<'a, R> {
.map(|value| match value {
Ok(Value::Record(v)) => Ok(v),
Err(e) => Err(ArrowError::ParseError(format!(
"Failed to parse avro value: {:?}",
e
"Failed to parse avro value: {e:?}"
))),
other => Err(ArrowError::ParseError(format!(
"Row needs to be of type object, got: {:?}",
other
"Row needs to be of type object, got: {other:?}"
))),
})
.collect::<ArrowResult<Vec<Vec<(String, Value)>>>>()?;
Expand Down Expand Up @@ -237,8 +235,7 @@ impl<'a, R: Read> AvroArrowArrayReader<'a, R> {
self.list_array_string_array_builder::<UInt64Type>(&dtype, col_name, rows)
}
ref e => Err(SchemaError(format!(
"Data type is currently not supported for dictionaries in list : {:?}",
e
"Data type is currently not supported for dictionaries in list : {e:?}"
))),
}
}
Expand All @@ -265,8 +262,7 @@ impl<'a, R: Read> AvroArrowArrayReader<'a, R> {
}
e => {
return Err(SchemaError(format!(
"Nested list data builder type is not supported: {:?}",
e
"Nested list data builder type is not supported: {e:?}"
)))
}
};
Expand Down Expand Up @@ -331,8 +327,7 @@ impl<'a, R: Read> AvroArrowArrayReader<'a, R> {
}
e => {
return Err(SchemaError(format!(
"Nested list data builder type is not supported: {:?}",
e
"Nested list data builder type is not supported: {e:?}"
)))
}
}
Expand Down Expand Up @@ -564,8 +559,7 @@ impl<'a, R: Read> AvroArrowArrayReader<'a, R> {
}
datatype => {
return Err(ArrowError::SchemaError(format!(
"Nested list of {:?} not supported",
datatype
"Nested list of {datatype:?} not supported"
)));
}
};
Expand Down Expand Up @@ -673,8 +667,7 @@ impl<'a, R: Read> AvroArrowArrayReader<'a, R> {
),
t => {
return Err(ArrowError::SchemaError(format!(
"TimeUnit {:?} not supported with Time64",
t
"TimeUnit {t:?} not supported with Time64"
)))
}
},
Expand All @@ -691,8 +684,7 @@ impl<'a, R: Read> AvroArrowArrayReader<'a, R> {
),
t => {
return Err(ArrowError::SchemaError(format!(
"TimeUnit {:?} not supported with Time32",
t
"TimeUnit {t:?} not supported with Time32"
)))
}
},
Expand Down Expand Up @@ -755,7 +747,7 @@ impl<'a, R: Read> AvroArrowArrayReader<'a, R> {
bit_util::set_bit(null_buffer.as_slice_mut(), i);
value
} else {
panic!("expected struct got {:?}", v);
panic!("expected struct got {v:?}");
}
})
.collect::<Vec<&Vec<(String, Value)>>>();
Expand Down Expand Up @@ -877,7 +869,7 @@ fn resolve_string(v: &Value) -> ArrowResult<String> {
}
other => Err(AvroError::GetString(other.into())),
}
.map_err(|e| SchemaError(format!("expected resolvable string : {:?}", e)))
.map_err(|e| SchemaError(format!("expected resolvable string : {e:?}")))
}

fn resolve_u8(v: &Value) -> AvroResult<u8> {
Expand Down Expand Up @@ -983,7 +975,7 @@ mod test {

fn build_reader(name: &str, batch_size: usize) -> Reader<File> {
let testdata = crate::test_util::arrow_test_data();
let filename = format!("{}/avro/{}", testdata, name);
let filename = format!("{testdata}/avro/{name}");
let builder = ReaderBuilder::new()
.read_schema()
.with_batch_size(batch_size);
Expand Down
6 changes: 3 additions & 3 deletions datafusion/core/src/avro_to_arrow/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::arrow::datatypes::SchemaRef;
use crate::arrow::record_batch::RecordBatch;
use crate::error::Result;
use arrow::error::Result as ArrowResult;
use std::io::{Read, Seek, SeekFrom};
use std::io::{Read, Seek};
use std::sync::Arc;

/// Avro file reader builder
Expand Down Expand Up @@ -112,7 +112,7 @@ impl ReaderBuilder {
Some(schema) => schema,
None => Arc::new(super::read_avro_schema_from_reader(&mut source)?),
};
source.seek(SeekFrom::Start(0))?;
source.rewind()?;
Reader::try_new(source, schema, self.batch_size, self.projection)
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ mod tests {

fn build_reader(name: &str) -> Reader<File> {
let testdata = crate::test_util::arrow_test_data();
let filename = format!("{}/avro/{}", testdata, name);
let filename = format!("{testdata}/avro/{name}");
let builder = ReaderBuilder::new().read_schema().with_batch_size(64);
builder.build(File::open(filename).unwrap()).unwrap()
}
Expand Down
6 changes: 3 additions & 3 deletions datafusion/core/src/avro_to_arrow/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ mod test {
} ]
}"#,
);
assert!(schema.is_ok(), "{:?}", schema);
assert!(schema.is_ok(), "{schema:?}");
let arrow_schema = to_arrow_schema(&schema.unwrap());
assert!(arrow_schema.is_ok(), "{:?}", arrow_schema);
assert!(arrow_schema.is_ok(), "{arrow_schema:?}");
let expected = Schema::new(vec![
Field::new("id", Int32, true),
Field::new("bool_col", Boolean, true),
Expand All @@ -446,7 +446,7 @@ mod test {
#[test]
fn test_non_record_schema() {
let arrow_schema = to_arrow_schema(&AvroSchema::String);
assert!(arrow_schema.is_ok(), "{:?}", arrow_schema);
assert!(arrow_schema.is_ok(), "{arrow_schema:?}");
assert_eq!(
arrow_schema.unwrap(),
Schema::new(vec![Field::new("", Utf8, false)])
Expand Down
14 changes: 7 additions & 7 deletions datafusion/core/src/datasource/file_format/avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod tests {

assert_eq!(
"[true, false, true, false, true, false, true, false]",
format!("{:?}", values)
format!("{values:?}")
);

Ok(())
Expand All @@ -240,7 +240,7 @@ mod tests {
values.push(array.value(i));
}

assert_eq!("[4, 5, 6, 7, 2, 3, 0, 1]", format!("{:?}", values));
assert_eq!("[4, 5, 6, 7, 2, 3, 0, 1]", format!("{values:?}"));

Ok(())
}
Expand All @@ -264,7 +264,7 @@ mod tests {
values.push(array.value(i));
}

assert_eq!("[1235865600000000, 1235865660000000, 1238544000000000, 1238544060000000, 1233446400000000, 1233446460000000, 1230768000000000, 1230768060000000]", format!("{:?}", values));
assert_eq!("[1235865600000000, 1235865660000000, 1238544000000000, 1238544060000000, 1233446400000000, 1233446460000000, 1230768000000000, 1230768060000000]", format!("{values:?}"));

Ok(())
}
Expand All @@ -290,7 +290,7 @@ mod tests {

assert_eq!(
"[0.0, 1.1, 0.0, 1.1, 0.0, 1.1, 0.0, 1.1]",
format!("{:?}", values)
format!("{values:?}")
);

Ok(())
Expand All @@ -317,7 +317,7 @@ mod tests {

assert_eq!(
"[0.0, 10.1, 0.0, 10.1, 0.0, 10.1, 0.0, 10.1]",
format!("{:?}", values)
format!("{values:?}")
);

Ok(())
Expand All @@ -344,7 +344,7 @@ mod tests {

assert_eq!(
"[\"0\", \"1\", \"0\", \"1\", \"0\", \"1\", \"0\", \"1\"]",
format!("{:?}", values)
format!("{values:?}")
);

Ok(())
Expand All @@ -357,7 +357,7 @@ mod tests {
limit: Option<usize>,
) -> Result<Arc<dyn ExecutionPlan>> {
let testdata = crate::test_util::arrow_test_data();
let store_root = format!("{}/avro", testdata);
let store_root = format!("{testdata}/avro");
let format = AvroFormat {};
scan_format(state, &format, &store_root, file_name, projection, limit).await
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/physical_plan/aggregates/row_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl GroupedHashAggregateStream {
let row_aggr_layout =
Arc::new(RowLayout::new(&row_aggr_schema, RowType::WordAligned));

let name = format!("GroupedHashAggregateStream[{}]", partition);
let name = format!("GroupedHashAggregateStream[{partition}]");
let row_aggr_state = RowAggregationState {
reservation: MemoryConsumer::new(name).register(context.memory_pool()),
map: RawTable::with_capacity(0),
Expand Down
6 changes: 3 additions & 3 deletions datafusion/core/src/physical_plan/file_format/avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ mod tests {
.register_object_store("file", "", store.clone());

let testdata = crate::test_util::arrow_test_data();
let filename = format!("{}/avro/alltypes_plain.avro", testdata);
let filename = format!("{testdata}/avro/alltypes_plain.avro");
let meta = local_unpartitioned_file(filename);

let file_schema = AvroFormat {}
Expand Down Expand Up @@ -315,7 +315,7 @@ mod tests {
let state = session_ctx.state();

let testdata = crate::test_util::arrow_test_data();
let filename = format!("{}/avro/alltypes_plain.avro", testdata);
let filename = format!("{testdata}/avro/alltypes_plain.avro");
let object_store = Arc::new(LocalFileSystem::new()) as _;
let object_store_url = ObjectStoreUrl::local_filesystem();
let meta = local_unpartitioned_file(filename);
Expand Down Expand Up @@ -388,7 +388,7 @@ mod tests {
let state = session_ctx.state();

let testdata = crate::test_util::arrow_test_data();
let filename = format!("{}/avro/alltypes_plain.avro", testdata);
let filename = format!("{testdata}/avro/alltypes_plain.avro");
let object_store = Arc::new(LocalFileSystem::new()) as _;
let object_store_url = ObjectStoreUrl::local_filesystem();
let meta = local_unpartitioned_file(filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,7 @@ fn get_aggregate_result_out_column(
}
if running_length != len_to_show {
return Err(DataFusionError::Execution(format!(
"Generated row number should be {}, it is {}",
len_to_show, running_length
"Generated row number should be {len_to_show}, it is {running_length}"
)));
}
result
Expand Down
6 changes: 3 additions & 3 deletions datafusion/core/tests/sql/avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn register_alltypes_avro(ctx: &SessionContext) {
let testdata = datafusion::test_util::arrow_test_data();
ctx.register_avro(
"alltypes_plain",
&format!("{}/avro/alltypes_plain.avro", testdata),
&format!("{testdata}/avro/alltypes_plain.avro"),
AvroReadOptions::default(),
)
.await
Expand Down Expand Up @@ -59,7 +59,7 @@ async fn avro_query_multiple_files() {
let tempdir = tempfile::tempdir().unwrap();
let table_path = tempdir.path();
let testdata = datafusion::test_util::arrow_test_data();
let alltypes_plain_file = format!("{}/avro/alltypes_plain.avro", testdata);
let alltypes_plain_file = format!("{testdata}/avro/alltypes_plain.avro");
std::fs::copy(
&alltypes_plain_file,
format!("{}/alltypes_plain1.avro", table_path.display()),
Expand Down Expand Up @@ -115,7 +115,7 @@ async fn avro_single_nan_schema() {
let testdata = datafusion::test_util::arrow_test_data();
ctx.register_avro(
"single_nan",
&format!("{}/avro/single_nan.avro", testdata),
&format!("{testdata}/avro/single_nan.avro"),
AvroReadOptions::default(),
)
.await
Expand Down
Loading

0 comments on commit 7e94826

Please sign in to comment.