Skip to content

Commit

Permalink
Fix cargo fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Tai Le Manh <[email protected]>
  • Loading branch information
tlm365 committed Aug 16, 2024
1 parent 1ea189e commit 230281c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
21 changes: 19 additions & 2 deletions datafusion/functions/src/string/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use std::fmt::{Display, Formatter};
use std::sync::Arc;

use arrow::array::{
new_null_array, Array, ArrayDataBuilder, ArrayRef, GenericStringArray,
GenericStringBuilder, OffsetSizeTrait, StringArray,
new_null_array, Array, ArrayAccessor, ArrayDataBuilder, ArrayIter, ArrayRef,
GenericStringArray, GenericStringBuilder, OffsetSizeTrait, StringArray,
StringViewArray,
};
use arrow::buffer::{Buffer, MutableBuffer, NullBuffer};
use arrow::datatypes::DataType;
Expand Down Expand Up @@ -251,6 +252,22 @@ impl<'a> ColumnarValueRef<'a> {
}
}

pub trait StringArrayType<'a>: ArrayAccessor<Item = &'a str> + Sized {
fn iter(&self) -> ArrayIter<Self>;
}

impl<'a, T: OffsetSizeTrait> StringArrayType<'a> for &'a GenericStringArray<T> {
fn iter(&self) -> ArrayIter<Self> {
GenericStringArray::<T>::iter(self)
}
}

impl<'a> StringArrayType<'a> for &'a StringViewArray {
fn iter(&self) -> ArrayIter<Self> {
StringViewArray::iter(self)
}
}

/// Optimized version of the StringBuilder in Arrow that:
/// 1. Precalculating the expected length of the result, avoiding reallocations.
/// 2. Avoids creating / incrementally creating a `NullBufferBuilder`
Expand Down
7 changes: 4 additions & 3 deletions datafusion/functions/src/string/repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::any::Any;
use std::sync::Arc;

use arrow::array::{
ArrayRef, AsArray, GenericStringArray, GenericStringBuilder,
Int64Array, OffsetSizeTrait, StringViewArray,
ArrayRef, AsArray, GenericStringArray, GenericStringBuilder, Int64Array,
OffsetSizeTrait, StringViewArray,
};
use arrow::datatypes::DataType;
use arrow::datatypes::DataType::{Int64, LargeUtf8, Utf8, Utf8View};
Expand All @@ -31,7 +31,8 @@ use datafusion_expr::TypeSignature::*;
use datafusion_expr::{ColumnarValue, Volatility};
use datafusion_expr::{ScalarUDFImpl, Signature};

use crate::utils::{make_scalar_function, utf8_to_str_type, StringArrayType};
use crate::string::common::StringArrayType;
use crate::utils::{make_scalar_function, utf8_to_str_type};

#[derive(Debug)]
pub struct RepeatFunc {
Expand Down
3 changes: 2 additions & 1 deletion datafusion/functions/src/unicode/lpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use datafusion_common::{exec_err, Result};
use datafusion_expr::TypeSignature::Exact;
use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility};

use crate::utils::{make_scalar_function, utf8_to_str_type, StringArrayType};
use crate::string::common::StringArrayType;
use crate::utils::{make_scalar_function, utf8_to_str_type};

#[derive(Debug)]
pub struct LPadFunc {
Expand Down
21 changes: 1 addition & 20 deletions datafusion/functions/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

use std::sync::Arc;

use arrow::array::{
ArrayAccessor, ArrayIter, ArrayRef, GenericStringArray, OffsetSizeTrait,
StringViewArray,
};
use arrow::array::ArrayRef;
use arrow::datatypes::DataType;

use datafusion_common::{Result, ScalarValue};
Expand Down Expand Up @@ -125,22 +122,6 @@ where
})
}

pub trait StringArrayType<'a>: ArrayAccessor<Item = &'a str> + Sized {
fn iter(&self) -> ArrayIter<Self>;
}

impl<'a, T: OffsetSizeTrait> StringArrayType<'a> for &'a GenericStringArray<T> {
fn iter(&self) -> ArrayIter<Self> {
GenericStringArray::<T>::iter(self)
}
}

impl<'a> StringArrayType<'a> for &'a StringViewArray {
fn iter(&self) -> ArrayIter<Self> {
StringViewArray::iter(self)
}
}

#[cfg(test)]
pub mod test {
/// $FUNC ScalarUDFImpl to test
Expand Down

0 comments on commit 230281c

Please sign in to comment.