Skip to content

Commit

Permalink
Add unused_qualifications with deny level to linter. Fix unused_quali…
Browse files Browse the repository at this point in the history
…fications violations." (#13086)
  • Loading branch information
dhegberg authored Oct 29, 2024
1 parent 4e38abd commit ac79ef3
Show file tree
Hide file tree
Showing 170 changed files with 865 additions and 1,003 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,4 @@ large_futures = "warn"

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(tarpaulin)"] }
unused_qualifications = "deny"
6 changes: 3 additions & 3 deletions datafusion-examples/examples/advanced_udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl Accumulator for GeometricMean {
}

fn size(&self) -> usize {
std::mem::size_of_val(self)
size_of_val(self)
}
}

Expand Down Expand Up @@ -394,8 +394,8 @@ impl GroupsAccumulator for GeometricMeanGroupsAccumulator {
}

fn size(&self) -> usize {
self.counts.capacity() * std::mem::size_of::<u32>()
+ self.prods.capacity() * std::mem::size_of::<Float64Type>()
self.counts.capacity() * size_of::<u32>()
+ self.prods.capacity() * size_of::<Float64Type>()
}
}

Expand Down
4 changes: 2 additions & 2 deletions datafusion-examples/examples/custom_datasource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct CustomDataSourceInner {
}

impl Debug for CustomDataSource {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("custom_db")
}
}
Expand Down Expand Up @@ -220,7 +220,7 @@ impl CustomExec {
}

impl DisplayAs for CustomExec {
fn fmt_as(&self, _t: DisplayFormatType, f: &mut fmt::Formatter) -> std::fmt::Result {
fn fmt_as(&self, _t: DisplayFormatType, f: &mut Formatter) -> fmt::Result {
write!(f, "CustomExec")
}
}
Expand Down
5 changes: 1 addition & 4 deletions datafusion-examples/examples/custom_file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ impl FileFormat for TSVFileFormat {
"tsv".to_string()
}

fn get_ext_with_compression(
&self,
c: &FileCompressionType,
) -> datafusion::error::Result<String> {
fn get_ext_with_compression(&self, c: &FileCompressionType) -> Result<String> {
if c == &FileCompressionType::UNCOMPRESSED {
Ok("tsv".to_string())
} else {
Expand Down
2 changes: 1 addition & 1 deletion datafusion-examples/examples/flight/flight_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl FlightService for FlightServiceImpl {
}

// add an initial FlightData message that sends schema
let options = datafusion::arrow::ipc::writer::IpcWriteOptions::default();
let options = arrow::ipc::writer::IpcWriteOptions::default();
let schema_flight_data = SchemaAsIpc::new(&schema, &options);

let mut flights = vec![FlightData::from(schema_flight_data)];
Expand Down
2 changes: 1 addition & 1 deletion datafusion-examples/examples/function_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl ScalarUDFImpl for ScalarFunctionWrapper {
&self.name
}

fn signature(&self) -> &datafusion_expr::Signature {
fn signature(&self) -> &Signature {
&self.signature
}

Expand Down
2 changes: 1 addition & 1 deletion datafusion-examples/examples/simple_udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Accumulator for GeometricMean {
}

fn size(&self) -> usize {
std::mem::size_of_val(self)
size_of_val(self)
}
}

Expand Down
5 changes: 2 additions & 3 deletions datafusion-examples/examples/simplify_udaf_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl AggregateUDFImpl for BetterAvgUdaf {
unimplemented!("should not be invoked")
}

fn state_fields(&self, _args: StateFieldsArgs) -> Result<Vec<arrow_schema::Field>> {
fn state_fields(&self, _args: StateFieldsArgs) -> Result<Vec<Field>> {
unimplemented!("should not be invoked")
}

Expand All @@ -90,8 +90,7 @@ impl AggregateUDFImpl for BetterAvgUdaf {
fn simplify(&self) -> Option<AggregateFunctionSimplification> {
// as an example for this functionality we replace UDF function
// with build-in aggregate function to illustrate the use
let simplify = |aggregate_function: datafusion_expr::expr::AggregateFunction,
_: &dyn SimplifyInfo| {
let simplify = |aggregate_function: AggregateFunction, _: &dyn SimplifyInfo| {
Ok(Expr::AggregateFunction(AggregateFunction::new_udf(
avg_udaf(),
// yes it is the same Avg, `BetterAvgUdaf` was just a
Expand Down
3 changes: 1 addition & 2 deletions datafusion-examples/examples/simplify_udwf_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ impl WindowUDFImpl for SimplifySmoothItUdf {

/// this function will simplify `SimplifySmoothItUdf` to `SmoothItUdf`.
fn simplify(&self) -> Option<WindowFunctionSimplification> {
let simplify = |window_function: datafusion_expr::expr::WindowFunction,
_: &dyn SimplifyInfo| {
let simplify = |window_function: WindowFunction, _: &dyn SimplifyInfo| {
Ok(Expr::WindowFunction(WindowFunction {
fun: datafusion_expr::WindowFunctionDefinition::AggregateUDF(avg_udaf()),
args: window_function.args,
Expand Down
2 changes: 1 addition & 1 deletion datafusion/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ pub trait ConfigExtension: ExtensionOptions {
}

/// An object-safe API for storing arbitrary configuration
pub trait ExtensionOptions: Send + Sync + std::fmt::Debug + 'static {
pub trait ExtensionOptions: Send + Sync + fmt::Debug + 'static {
/// Return `self` as [`Any`]
///
/// This is needed until trait upcasting is stabilised
Expand Down
2 changes: 1 addition & 1 deletion datafusion/common/src/join_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub enum JoinConstraint {
}

impl Display for JoinSide {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
JoinSide::Left => write!(f, "left"),
JoinSide::Right => write!(f, "right"),
Expand Down
3 changes: 1 addition & 2 deletions datafusion/common/src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! Interval parsing logic
use std::fmt::Display;
use std::result;
use std::str::FromStr;

use sqlparser::parser::ParserError;
Expand All @@ -41,7 +40,7 @@ pub enum CompressionTypeVariant {
impl FromStr for CompressionTypeVariant {
type Err = ParserError;

fn from_str(s: &str) -> result::Result<Self, ParserError> {
fn from_str(s: &str) -> Result<Self, ParserError> {
let s = s.to_uppercase();
match s.as_str() {
"GZIP" | "GZ" => Ok(Self::GZIP),
Expand Down
2 changes: 1 addition & 1 deletion datafusion/common/src/pyarrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl From<DataFusionError> for PyErr {
}

impl FromPyArrow for ScalarValue {
fn from_pyarrow_bound(value: &pyo3::Bound<'_, pyo3::PyAny>) -> PyResult<Self> {
fn from_pyarrow_bound(value: &Bound<'_, PyAny>) -> PyResult<Self> {
let py = value.py();
let typ = value.getattr("type")?;
let val = value.call_method0("as_py")?;
Expand Down
55 changes: 27 additions & 28 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::fmt;
use std::hash::Hash;
use std::hash::Hasher;
use std::iter::repeat;
use std::mem::{size_of, size_of_val};
use std::str::FromStr;
use std::sync::Arc;

Expand Down Expand Up @@ -691,8 +692,8 @@ hash_float_value!((f64, u64), (f32, u32));
// # Panics
//
// Panics if there is an error when creating hash values for rows
impl std::hash::Hash for ScalarValue {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
impl Hash for ScalarValue {
fn hash<H: Hasher>(&self, state: &mut H) {
use ScalarValue::*;
match self {
Decimal128(v, p, s) => {
Expand Down Expand Up @@ -768,7 +769,7 @@ impl std::hash::Hash for ScalarValue {
}
}

fn hash_nested_array<H: std::hash::Hasher>(arr: ArrayRef, state: &mut H) {
fn hash_nested_array<H: Hasher>(arr: ArrayRef, state: &mut H) {
let arrays = vec![arr.to_owned()];
let hashes_buffer = &mut vec![0; arr.len()];
let random_state = ahash::RandomState::with_seeds(0, 0, 0, 0);
Expand Down Expand Up @@ -802,7 +803,7 @@ fn dict_from_scalar<K: ArrowDictionaryKeyType>(
let values_array = value.to_array_of_size(1)?;

// Create a key array with `size` elements, each of 0
let key_array: PrimitiveArray<K> = std::iter::repeat(if value.is_null() {
let key_array: PrimitiveArray<K> = repeat(if value.is_null() {
None
} else {
Some(K::default_value())
Expand Down Expand Up @@ -2043,7 +2044,7 @@ impl ScalarValue {
scale: i8,
size: usize,
) -> Result<Decimal256Array> {
Ok(std::iter::repeat(value)
Ok(repeat(value)
.take(size)
.collect::<Decimal256Array>()
.with_precision_and_scale(precision, scale)?)
Expand Down Expand Up @@ -2512,7 +2513,7 @@ impl ScalarValue {
}

fn list_to_array_of_size(arr: &dyn Array, size: usize) -> Result<ArrayRef> {
let arrays = std::iter::repeat(arr).take(size).collect::<Vec<_>>();
let arrays = repeat(arr).take(size).collect::<Vec<_>>();
let ret = match !arrays.is_empty() {
true => arrow::compute::concat(arrays.as_slice())?,
false => arr.slice(0, 0),
Expand Down Expand Up @@ -3083,7 +3084,7 @@ impl ScalarValue {
/// Estimate size if bytes including `Self`. For values with internal containers such as `String`
/// includes the allocated size (`capacity`) rather than the current length (`len`)
pub fn size(&self) -> usize {
std::mem::size_of_val(self)
size_of_val(self)
+ match self {
ScalarValue::Null
| ScalarValue::Boolean(_)
Expand Down Expand Up @@ -3137,12 +3138,12 @@ impl ScalarValue {
ScalarValue::Map(arr) => arr.get_array_memory_size(),
ScalarValue::Union(vals, fields, _mode) => {
vals.as_ref()
.map(|(_id, sv)| sv.size() - std::mem::size_of_val(sv))
.map(|(_id, sv)| sv.size() - size_of_val(sv))
.unwrap_or_default()
// `fields` is boxed, so it is NOT already included in `self`
+ std::mem::size_of_val(fields)
+ (std::mem::size_of::<Field>() * fields.len())
+ fields.iter().map(|(_idx, field)| field.size() - std::mem::size_of_val(field)).sum::<usize>()
+ size_of_val(fields)
+ (size_of::<Field>() * fields.len())
+ fields.iter().map(|(_idx, field)| field.size() - size_of_val(field)).sum::<usize>()
}
ScalarValue::Dictionary(dt, sv) => {
// `dt` and `sv` are boxed, so they are NOT already included in `self`
Expand All @@ -3155,35 +3156,35 @@ impl ScalarValue {
///
/// Includes the size of the [`Vec`] container itself.
pub fn size_of_vec(vec: &Vec<Self>) -> usize {
std::mem::size_of_val(vec)
+ (std::mem::size_of::<ScalarValue>() * vec.capacity())
size_of_val(vec)
+ (size_of::<ScalarValue>() * vec.capacity())
+ vec
.iter()
.map(|sv| sv.size() - std::mem::size_of_val(sv))
.map(|sv| sv.size() - size_of_val(sv))
.sum::<usize>()
}

/// Estimates [size](Self::size) of [`VecDeque`] in bytes.
///
/// Includes the size of the [`VecDeque`] container itself.
pub fn size_of_vec_deque(vec_deque: &VecDeque<Self>) -> usize {
std::mem::size_of_val(vec_deque)
+ (std::mem::size_of::<ScalarValue>() * vec_deque.capacity())
size_of_val(vec_deque)
+ (size_of::<ScalarValue>() * vec_deque.capacity())
+ vec_deque
.iter()
.map(|sv| sv.size() - std::mem::size_of_val(sv))
.map(|sv| sv.size() - size_of_val(sv))
.sum::<usize>()
}

/// Estimates [size](Self::size) of [`HashSet`] in bytes.
///
/// Includes the size of the [`HashSet`] container itself.
pub fn size_of_hashset<S>(set: &HashSet<Self, S>) -> usize {
std::mem::size_of_val(set)
+ (std::mem::size_of::<ScalarValue>() * set.capacity())
size_of_val(set)
+ (size_of::<ScalarValue>() * set.capacity())
+ set
.iter()
.map(|sv| sv.size() - std::mem::size_of_val(sv))
.map(|sv| sv.size() - size_of_val(sv))
.sum::<usize>()
}
}
Expand Down Expand Up @@ -4445,7 +4446,7 @@ mod tests {
let right_array = right.to_array().expect("Failed to convert to array");
let arrow_left_array = left_array.as_primitive::<T>();
let arrow_right_array = right_array.as_primitive::<T>();
let arrow_result = kernels::numeric::add(arrow_left_array, arrow_right_array);
let arrow_result = add(arrow_left_array, arrow_right_array);

assert_eq!(scalar_result.is_ok(), arrow_result.is_ok());
}
Expand Down Expand Up @@ -5060,13 +5061,13 @@ mod tests {
// thus the size of the enum appears to as well

// The value may also change depending on rust version
assert_eq!(std::mem::size_of::<ScalarValue>(), 64);
assert_eq!(size_of::<ScalarValue>(), 64);
}

#[test]
fn memory_size() {
let sv = ScalarValue::Binary(Some(Vec::with_capacity(10)));
assert_eq!(sv.size(), std::mem::size_of::<ScalarValue>() + 10,);
assert_eq!(sv.size(), size_of::<ScalarValue>() + 10,);
let sv_size = sv.size();

let mut v = Vec::with_capacity(10);
Expand All @@ -5075,9 +5076,7 @@ mod tests {
assert_eq!(v.capacity(), 10);
assert_eq!(
ScalarValue::size_of_vec(&v),
std::mem::size_of::<Vec<ScalarValue>>()
+ (9 * std::mem::size_of::<ScalarValue>())
+ sv_size,
size_of::<Vec<ScalarValue>>() + (9 * size_of::<ScalarValue>()) + sv_size,
);

let mut s = HashSet::with_capacity(0);
Expand All @@ -5087,8 +5086,8 @@ mod tests {
let s_capacity = s.capacity();
assert_eq!(
ScalarValue::size_of_hashset(&s),
std::mem::size_of::<HashSet<ScalarValue>>()
+ ((s_capacity - 1) * std::mem::size_of::<ScalarValue>())
size_of::<HashSet<ScalarValue>>()
+ ((s_capacity - 1) * size_of::<ScalarValue>())
+ sv_size,
);
}
Expand Down
6 changes: 3 additions & 3 deletions datafusion/common/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl Precision<ScalarValue> {
}
}

impl<T: fmt::Debug + Clone + PartialEq + Eq + PartialOrd> Debug for Precision<T> {
impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Debug for Precision<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Precision::Exact(inner) => write!(f, "Exact({:?})", inner),
Expand All @@ -200,7 +200,7 @@ impl<T: fmt::Debug + Clone + PartialEq + Eq + PartialOrd> Debug for Precision<T>
}
}

impl<T: fmt::Debug + Clone + PartialEq + Eq + PartialOrd> Display for Precision<T> {
impl<T: Debug + Clone + PartialEq + Eq + PartialOrd> Display for Precision<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Precision::Exact(inner) => write!(f, "Exact({:?})", inner),
Expand Down Expand Up @@ -341,7 +341,7 @@ fn check_num_rows(value: Option<usize>, is_exact: bool) -> Precision<usize> {
}

impl Display for Statistics {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// string of column statistics
let column_stats = self
.column_statistics
Expand Down
7 changes: 4 additions & 3 deletions datafusion/common/src/utils/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! This module provides a function to estimate the memory size of a HashTable prior to alloaction
use crate::{DataFusionError, Result};
use std::mem::size_of;

/// Estimates the memory size required for a hash table prior to allocation.
///
Expand Down Expand Up @@ -87,7 +88,7 @@ pub fn estimate_memory_size<T>(num_elements: usize, fixed_size: usize) -> Result
// + size of entry * number of buckets
// + 1 byte for each bucket
// + fixed size of collection (HashSet/HashTable)
std::mem::size_of::<T>()
size_of::<T>()
.checked_mul(estimated_buckets)?
.checked_add(estimated_buckets)?
.checked_add(fixed_size)
Expand All @@ -108,7 +109,7 @@ mod tests {
#[test]
fn test_estimate_memory() {
// size (bytes): 48
let fixed_size = std::mem::size_of::<HashSet<u32>>();
let fixed_size = size_of::<HashSet<u32>>();

// estimated buckets: 16 = (8 * 8 / 7).next_power_of_two()
let num_elements = 8;
Expand All @@ -126,7 +127,7 @@ mod tests {
#[test]
fn test_estimate_memory_overflow() {
let num_elements = usize::MAX;
let fixed_size = std::mem::size_of::<HashSet<u32>>();
let fixed_size = size_of::<HashSet<u32>>();
let estimated = estimate_memory_size::<u32>(num_elements, fixed_size);

assert!(estimated.is_err());
Expand Down
Loading

0 comments on commit ac79ef3

Please sign in to comment.