This is an automated email from the ASF dual-hosted git repository.
comphead pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new b30edc897c chore: Minor code improvements suggested by newer clippy
(#13666)
b30edc897c is described below
commit b30edc897c8a790cb99c430fc6267bd5fef722bf
Author: Piotr Findeisen <[email protected]>
AuthorDate: Thu Dec 5 18:00:04 2024 +0100
chore: Minor code improvements suggested by newer clippy (#13666)
* Use Option::is_some_and where applicable
This will become a clippy warning in the future.
* Use String::len and str::len directly
The `len()` returns length in bytes, so doing `as_bytes().len()` is
redundant. This will become a clippy warning in the future.
---
datafusion/core/src/datasource/listing/url.rs | 2 +-
datafusion/core/src/physical_optimizer/enforce_distribution.rs | 2 +-
.../src/physical_optimizer/replace_with_order_preserving_variants.rs | 2 +-
datafusion/core/src/physical_optimizer/sanity_checker.rs | 2 +-
datafusion/functions/src/string/common.rs | 4 ++--
datafusion/functions/src/unicode/strpos.rs | 4 ++--
datafusion/physical-expr/src/equivalence/class.rs | 2 +-
datafusion/physical-plan/src/common.rs | 2 +-
8 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/datafusion/core/src/datasource/listing/url.rs
b/datafusion/core/src/datasource/listing/url.rs
index 2e8d314354..6fb536ca2f 100644
--- a/datafusion/core/src/datasource/listing/url.rs
+++ b/datafusion/core/src/datasource/listing/url.rs
@@ -170,7 +170,7 @@ impl ListingTableUrl {
if ignore_subdirectory {
segments
.next()
- .map_or(false, |file_name| glob.matches(file_name))
+ .is_some_and(|file_name| glob.matches(file_name))
} else {
let stripped = segments.join(DELIMITER);
glob.matches(&stripped)
diff --git a/datafusion/core/src/physical_optimizer/enforce_distribution.rs
b/datafusion/core/src/physical_optimizer/enforce_distribution.rs
index 82fde60de0..27323eaedc 100644
--- a/datafusion/core/src/physical_optimizer/enforce_distribution.rs
+++ b/datafusion/core/src/physical_optimizer/enforce_distribution.rs
@@ -617,7 +617,7 @@ pub(crate) fn reorder_join_keys_to_inputs(
left.equivalence_properties(),
right.equivalence_properties(),
);
- if positions.map_or(false, |idxs| !idxs.is_empty()) {
+ if positions.is_some_and(|idxs| !idxs.is_empty()) {
let JoinKeyPairs {
left_keys,
right_keys,
diff --git
a/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs
b/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs
index 7fc3adf784..2f6b7a51ee 100644
---
a/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs
+++
b/datafusion/core/src/physical_optimizer/replace_with_order_preserving_variants.rs
@@ -162,7 +162,7 @@ fn plan_with_order_breaking_variants(
// not required by intermediate operators:
if maintains
&& (is_sort_preserving_merge(plan)
- || !required_ordering.map_or(false, |required_ordering| {
+ || !required_ordering.is_some_and(|required_ordering| {
node.plan
.equivalence_properties()
.ordering_satisfy_requirement(&required_ordering)
diff --git a/datafusion/core/src/physical_optimizer/sanity_checker.rs
b/datafusion/core/src/physical_optimizer/sanity_checker.rs
index b2f2c933c1..99bd1cab3e 100644
--- a/datafusion/core/src/physical_optimizer/sanity_checker.rs
+++ b/datafusion/core/src/physical_optimizer/sanity_checker.rs
@@ -103,7 +103,7 @@ pub fn check_finiteness_requirements(
/// [`PhysicalExpr`]: crate::physical_plan::PhysicalExpr
/// [`Operator`]: datafusion_expr::Operator
fn is_prunable(join: &SymmetricHashJoinExec) -> bool {
- join.filter().map_or(false, |filter| {
+ join.filter().is_some_and(|filter| {
check_support(filter.expression(), &join.schema())
&& filter
.schema()
diff --git a/datafusion/functions/src/string/common.rs
b/datafusion/functions/src/string/common.rs
index 0d1f90eb22..6e5f767013 100644
--- a/datafusion/functions/src/string/common.rs
+++ b/datafusion/functions/src/string/common.rs
@@ -61,7 +61,7 @@ pub(crate) fn general_trim<T: OffsetSizeTrait>(
str::trim_start_matches::<&[char]>(input, pattern.as_ref());
// `ltrimmed_str` is actually `input`[start_offset..],
// so `start_offset` = len(`input`) - len(`ltrimmed_str`)
- let start_offset = input.as_bytes().len() -
ltrimmed_str.as_bytes().len();
+ let start_offset = input.len() - ltrimmed_str.len();
(ltrimmed_str, start_offset as u32)
},
@@ -78,7 +78,7 @@ pub(crate) fn general_trim<T: OffsetSizeTrait>(
str::trim_start_matches::<&[char]>(input, pattern.as_ref());
// `btrimmed_str` can be got by rtrim(ltrim(`input`)),
// so its `start_offset` should be same as ltrim situation above
- let start_offset = input.as_bytes().len() -
ltrimmed_str.as_bytes().len();
+ let start_offset = input.len() - ltrimmed_str.len();
let btrimmed_str =
str::trim_end_matches::<&[char]>(ltrimmed_str,
pattern.as_ref());
diff --git a/datafusion/functions/src/unicode/strpos.rs
b/datafusion/functions/src/unicode/strpos.rs
index 1917cd7291..5d1986e44c 100644
--- a/datafusion/functions/src/unicode/strpos.rs
+++ b/datafusion/functions/src/unicode/strpos.rs
@@ -173,13 +173,13 @@ where
// the sub vector in the main vector. This is faster than
string.find() method.
if ascii_only {
// If the substring is empty, the result is 1.
- if substring.as_bytes().is_empty() {
+ if substring.is_empty() {
T::Native::from_usize(1)
} else {
T::Native::from_usize(
string
.as_bytes()
- .windows(substring.as_bytes().len())
+ .windows(substring.len())
.position(|w| w == substring.as_bytes())
.map(|x| x + 1)
.unwrap_or(0),
diff --git a/datafusion/physical-expr/src/equivalence/class.rs
b/datafusion/physical-expr/src/equivalence/class.rs
index 1812844d98..d06a495d97 100644
--- a/datafusion/physical-expr/src/equivalence/class.rs
+++ b/datafusion/physical-expr/src/equivalence/class.rs
@@ -518,7 +518,7 @@ impl EquivalenceGroup {
// and the equivalence class `(a, b)`, expression `b` projects
to `a1`.
if self
.get_equivalence_class(source)
- .map_or(false, |group| group.contains(expr))
+ .is_some_and(|group| group.contains(expr))
{
return Some(Arc::clone(target));
}
diff --git a/datafusion/physical-plan/src/common.rs
b/datafusion/physical-plan/src/common.rs
index 844208999d..aefb90d1d1 100644
--- a/datafusion/physical-plan/src/common.rs
+++ b/datafusion/physical-plan/src/common.rs
@@ -261,7 +261,7 @@ pub fn can_project(
if columns
.iter()
.max()
- .map_or(false, |&i| i >= schema.fields().len())
+ .is_some_and(|&i| i >= schema.fields().len())
{
Err(arrow_schema::ArrowError::SchemaError(format!(
"project index {} out of bounds, max field {}",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]