Skip to content

Commit

Permalink
Remove unnecessary qualified names
Browse files Browse the repository at this point in the history
Leverage existing imports.
  • Loading branch information
findepi committed Jul 5, 2024
1 parent d44c7f2 commit 7db6dc8
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 69 deletions.
2 changes: 1 addition & 1 deletion datafusion-examples/examples/advanced_udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl AggregateUDFImpl for GeoMeanUdaf {
}

/// This is the description of the state. accumulator's state() must match the types here.
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<arrow_schema::Field>> {
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> {
Ok(vec![
Field::new("prod", args.return_type.clone(), true),
Field::new("n", DataType::UInt32, true),
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions-aggregate/src/approx_distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ where

impl<T> Accumulator for NumericHLLAccumulator<T>
where
T: ArrowPrimitiveType + std::fmt::Debug,
T: ArrowPrimitiveType + Debug,
T::Native: Hash,
{
fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl AggregateUDFImpl for ApproxPercentileCont {
}

#[allow(rustdoc::private_intra_doc_links)]
/// See [`datafusion_physical_expr_common::aggregate::tdigest::TDigest::to_scalar_state()`] for a description of the serialised
/// See [`TDigest::to_scalar_state()`] for a description of the serialised
/// state.
fn state_fields(
&self,
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions-aggregate/src/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ where
.into_iter()
.zip(counts.into_iter())
.map(|(sum, count)| (self.avg_fn)(sum, count))
.collect::<datafusion_common::Result<Vec<_>>>()?;
.collect::<Result<Vec<_>>>()?;
PrimitiveArray::new(averages.into(), Some(nulls)) // no copy
.with_data_type(self.return_data_type.clone())
};
Expand Down
8 changes: 4 additions & 4 deletions datafusion/functions-aggregate/src/bit_and_or_xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ struct BitAndAccumulator<T: ArrowNumericType> {
}

impl<T: ArrowNumericType> std::fmt::Debug for BitAndAccumulator<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "BitAndAccumulator({})", T::DATA_TYPE)
}
}
Expand Down Expand Up @@ -290,7 +290,7 @@ struct BitOrAccumulator<T: ArrowNumericType> {
}

impl<T: ArrowNumericType> std::fmt::Debug for BitOrAccumulator<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "BitOrAccumulator({})", T::DATA_TYPE)
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ struct BitXorAccumulator<T: ArrowNumericType> {
}

impl<T: ArrowNumericType> std::fmt::Debug for BitXorAccumulator<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "BitXorAccumulator({})", T::DATA_TYPE)
}
}
Expand Down Expand Up @@ -380,7 +380,7 @@ struct DistinctBitXorAccumulator<T: ArrowNumericType> {
}

impl<T: ArrowNumericType> std::fmt::Debug for DistinctBitXorAccumulator<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "DistinctBitXorAccumulator({})", T::DATA_TYPE)
}
}
Expand Down
20 changes: 9 additions & 11 deletions datafusion/functions-aggregate/src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ make_udaf_expr_and_func!(
count_udaf
);

pub fn count_distinct(expr: Expr) -> datafusion_expr::Expr {
datafusion_expr::Expr::AggregateFunction(
datafusion_expr::expr::AggregateFunction::new_udf(
count_udaf(),
vec![expr],
true,
None,
None,
None,
),
)
pub fn count_distinct(expr: Expr) -> Expr {
Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
count_udaf(),
vec![expr],
true,
None,
None,
None,
))
}

pub struct Count {
Expand Down
4 changes: 2 additions & 2 deletions datafusion/physical-expr-common/src/binary_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ where
/// the same output type
pub fn take(&mut self) -> Self {
let mut new_self = Self::new(self.output_type);
std::mem::swap(self, &mut new_self);
mem::swap(self, &mut new_self);
new_self
}

Expand Down Expand Up @@ -538,7 +538,7 @@ where
/// this set, not including `self`
pub fn size(&self) -> usize {
self.map_size
+ self.buffer.capacity() * std::mem::size_of::<u8>()
+ self.buffer.capacity() * mem::size_of::<u8>()
+ self.offsets.allocated_size()
+ self.hashes_buffer.allocated_size()
}
Expand Down
89 changes: 42 additions & 47 deletions datafusion/physical-expr-common/src/expressions/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ mod tests {

generic_decimal_to_other_test_cast!(
decimal_array,
DataType::Decimal128(10, 3),
Decimal128(10, 3),
Decimal128Array,
DataType::Decimal128(20, 6),
Decimal128(20, 6),
[
Some(1_234_000),
Some(2_222_000),
Expand All @@ -387,9 +387,9 @@ mod tests {

generic_decimal_to_other_test_cast!(
decimal_array,
DataType::Decimal128(10, 3),
Decimal128(10, 3),
Decimal128Array,
DataType::Decimal128(10, 2),
Decimal128(10, 2),
[Some(123), Some(222), Some(0), Some(400), Some(500), None],
None
);
Expand All @@ -408,9 +408,9 @@ mod tests {
.with_precision_and_scale(10, 0)?;
generic_decimal_to_other_test_cast!(
decimal_array,
DataType::Decimal128(10, 0),
Decimal128(10, 0),
Int8Array,
DataType::Int8,
Int8,
[
Some(1_i8),
Some(2_i8),
Expand All @@ -430,9 +430,9 @@ mod tests {
.with_precision_and_scale(10, 0)?;
generic_decimal_to_other_test_cast!(
decimal_array,
DataType::Decimal128(10, 0),
Decimal128(10, 0),
Int16Array,
DataType::Int16,
Int16,
[
Some(1_i16),
Some(2_i16),
Expand All @@ -452,9 +452,9 @@ mod tests {
.with_precision_and_scale(10, 0)?;
generic_decimal_to_other_test_cast!(
decimal_array,
DataType::Decimal128(10, 0),
Decimal128(10, 0),
Int32Array,
DataType::Int32,
Int32,
[
Some(1_i32),
Some(2_i32),
Expand All @@ -473,9 +473,9 @@ mod tests {
.with_precision_and_scale(10, 0)?;
generic_decimal_to_other_test_cast!(
decimal_array,
DataType::Decimal128(10, 0),
Decimal128(10, 0),
Int64Array,
DataType::Int64,
Int64,
[
Some(1_i64),
Some(2_i64),
Expand Down Expand Up @@ -503,9 +503,9 @@ mod tests {
.with_precision_and_scale(10, 3)?;
generic_decimal_to_other_test_cast!(
decimal_array,
DataType::Decimal128(10, 3),
Decimal128(10, 3),
Float32Array,
DataType::Float32,
Float32,
[
Some(1.234_f32),
Some(2.222_f32),
Expand All @@ -524,9 +524,9 @@ mod tests {
.with_precision_and_scale(20, 6)?;
generic_decimal_to_other_test_cast!(
decimal_array,
DataType::Decimal128(20, 6),
Decimal128(20, 6),
Float64Array,
DataType::Float64,
Float64,
[
Some(0.001234_f64),
Some(0.002222_f64),
Expand All @@ -545,76 +545,76 @@ mod tests {
// int8
generic_test_cast!(
Int8Array,
DataType::Int8,
Int8,
vec![1, 2, 3, 4, 5],
Decimal128Array,
DataType::Decimal128(3, 0),
Decimal128(3, 0),
[Some(1), Some(2), Some(3), Some(4), Some(5)],
None
);

// int16
generic_test_cast!(
Int16Array,
DataType::Int16,
Int16,
vec![1, 2, 3, 4, 5],
Decimal128Array,
DataType::Decimal128(5, 0),
Decimal128(5, 0),
[Some(1), Some(2), Some(3), Some(4), Some(5)],
None
);

// int32
generic_test_cast!(
Int32Array,
DataType::Int32,
Int32,
vec![1, 2, 3, 4, 5],
Decimal128Array,
DataType::Decimal128(10, 0),
Decimal128(10, 0),
[Some(1), Some(2), Some(3), Some(4), Some(5)],
None
);

// int64
generic_test_cast!(
Int64Array,
DataType::Int64,
Int64,
vec![1, 2, 3, 4, 5],
Decimal128Array,
DataType::Decimal128(20, 0),
Decimal128(20, 0),
[Some(1), Some(2), Some(3), Some(4), Some(5)],
None
);

// int64 to different scale
generic_test_cast!(
Int64Array,
DataType::Int64,
Int64,
vec![1, 2, 3, 4, 5],
Decimal128Array,
DataType::Decimal128(20, 2),
Decimal128(20, 2),
[Some(100), Some(200), Some(300), Some(400), Some(500)],
None
);

// float32
generic_test_cast!(
Float32Array,
DataType::Float32,
Float32,
vec![1.5, 2.5, 3.0, 1.123_456_8, 5.50],
Decimal128Array,
DataType::Decimal128(10, 2),
Decimal128(10, 2),
[Some(150), Some(250), Some(300), Some(112), Some(550)],
None
);

// float64
generic_test_cast!(
Float64Array,
DataType::Float64,
Float64,
vec![1.5, 2.5, 3.0, 1.123_456_8, 5.50],
Decimal128Array,
DataType::Decimal128(20, 4),
Decimal128(20, 4),
[
Some(15000),
Some(25000),
Expand All @@ -631,10 +631,10 @@ mod tests {
fn test_cast_i32_u32() -> Result<()> {
generic_test_cast!(
Int32Array,
DataType::Int32,
Int32,
vec![1, 2, 3, 4, 5],
UInt32Array,
DataType::UInt32,
UInt32,
[
Some(1_u32),
Some(2_u32),
Expand All @@ -651,10 +651,10 @@ mod tests {
fn test_cast_i32_utf8() -> Result<()> {
generic_test_cast!(
Int32Array,
DataType::Int32,
Int32,
vec![1, 2, 3, 4, 5],
StringArray,
DataType::Utf8,
Utf8,
[Some("1"), Some("2"), Some("3"), Some("4"), Some("5")],
None
);
Expand All @@ -670,10 +670,10 @@ mod tests {
.collect();
generic_test_cast!(
Int64Array,
DataType::Int64,
Int64,
original,
TimestampNanosecondArray,
DataType::Timestamp(TimeUnit::Nanosecond, None),
Timestamp(TimeUnit::Nanosecond, None),
expected,
None
);
Expand All @@ -683,7 +683,7 @@ mod tests {
#[test]
fn invalid_cast() {
// Ensure a useful error happens at plan time if invalid casts are used
let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
let schema = Schema::new(vec![Field::new("a", Int32, false)]);

let result = cast(
col("a", &schema).unwrap(),
Expand All @@ -696,11 +696,10 @@ mod tests {
#[test]
fn invalid_cast_with_options_error() -> Result<()> {
// Ensure a useful error happens at plan time if invalid casts are used
let schema = Schema::new(vec![Field::new("a", DataType::Utf8, false)]);
let schema = Schema::new(vec![Field::new("a", Utf8, false)]);
let a = StringArray::from(vec!["9.1"]);
let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
let expression =
cast_with_options(col("a", &schema)?, &schema, DataType::Int32, None)?;
let expression = cast_with_options(col("a", &schema)?, &schema, Int32, None)?;
let result = expression.evaluate(&batch);

match result {
Expand All @@ -717,15 +716,11 @@ mod tests {
#[test]
#[ignore] // TODO: https://github.com/apache/datafusion/issues/5396
fn test_cast_decimal() -> Result<()> {
let schema = Schema::new(vec![Field::new("a", DataType::Int64, false)]);
let schema = Schema::new(vec![Field::new("a", Int64, false)]);
let a = Int64Array::from(vec![100]);
let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
let expression = cast_with_options(
col("a", &schema)?,
&schema,
DataType::Decimal128(38, 38),
None,
)?;
let expression =
cast_with_options(col("a", &schema)?, &schema, Decimal128(38, 38), None)?;
expression.evaluate(&batch)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/expressions/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ mod tests {
);
assert!(expr.is_ok());
let result_type = expr.unwrap().data_type(schema.as_ref())?;
assert_eq!(DataType::Float64, result_type);
assert_eq!(Float64, result_type);
Ok(())
}

Expand Down

0 comments on commit 7db6dc8

Please sign in to comment.