Skip to content

Commit

Permalink
feat: Enable clippy::clone_on_ref_ptr on core crate (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
comphead authored Aug 22, 2024
1 parent 3b59999 commit a99f742
Show file tree
Hide file tree
Showing 25 changed files with 185 additions and 139 deletions.
2 changes: 1 addition & 1 deletion native/core/src/execution/datafusion/expressions/avg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl AggregateExpr for Avg {
}

fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
vec![self.expr.clone()]
vec![Arc::clone(&self.expr)]
}

fn name(&self) -> &str {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl AggregateExpr for AvgDecimal {
}

fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
vec![self.expr.clone()]
vec![Arc::clone(&self.expr)]
}

fn name(&self) -> &str {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl PhysicalExpr for BitwiseNotExpr {
self: Arc<Self>,
children: Vec<Arc<dyn PhysicalExpr>>,
) -> Result<Arc<dyn PhysicalExpr>> {
Ok(Arc::new(BitwiseNotExpr::new(children[0].clone())))
Ok(Arc::new(BitwiseNotExpr::new(Arc::clone(&children[0]))))
}

fn dyn_hash(&self, state: &mut dyn Hasher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ impl PhysicalExpr for BloomFilterMightContain {
children: Vec<Arc<dyn PhysicalExpr>>,
) -> Result<Arc<dyn PhysicalExpr>> {
Ok(Arc::new(BloomFilterMightContain::try_new(
children[0].clone(),
children[1].clone(),
Arc::clone(&children[0]),
Arc::clone(&children[1]),
)?))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl PhysicalExpr for CheckOverflow {
children: Vec<Arc<dyn PhysicalExpr>>,
) -> datafusion_common::Result<Arc<dyn PhysicalExpr>> {
Ok(Arc::new(CheckOverflow::new(
children[0].clone(),
Arc::clone(&children[0]),
self.data_type.clone(),
self.fail_on_error,
)))
Expand Down
22 changes: 15 additions & 7 deletions native/core/src/execution/datafusion/expressions/correlation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl AggregateExpr for Correlation {
}

fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
vec![self.expr1.clone(), self.expr2.clone()]
vec![Arc::clone(&self.expr1), Arc::clone(&self.expr2)]
}

fn name(&self) -> &str {
Expand Down Expand Up @@ -209,13 +209,21 @@ impl Accumulator for CorrelationAccumulator {

fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
let states_c = [
states[0].clone(),
states[1].clone(),
states[2].clone(),
states[3].clone(),
Arc::clone(&states[0]),
Arc::clone(&states[1]),
Arc::clone(&states[2]),
Arc::clone(&states[3]),
];
let states_s1 = [
Arc::clone(&states[0]),
Arc::clone(&states[1]),
Arc::clone(&states[4]),
];
let states_s2 = [
Arc::clone(&states[0]),
Arc::clone(&states[2]),
Arc::clone(&states[5]),
];
let states_s1 = [states[0].clone(), states[1].clone(), states[4].clone()];
let states_s2 = [states[0].clone(), states[2].clone(), states[5].clone()];

if states[0].len() > 0 && states[1].len() > 0 && states[2].len() > 0 {
self.covar.merge_batch(&states_c)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl AggregateExpr for Covariance {
}

fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
vec![self.expr1.clone(), self.expr2.clone()]
vec![Arc::clone(&self.expr1), Arc::clone(&self.expr2)]
}

fn name(&self) -> &str {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl PhysicalExpr for NegativeExpr {
children: Vec<Arc<dyn PhysicalExpr>>,
) -> Result<Arc<dyn PhysicalExpr>> {
Ok(Arc::new(NegativeExpr::new(
children[0].clone(),
Arc::clone(&children[0]),
self.fail_on_error,
)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl PhysicalExpr for NormalizeNaNAndZero {
) -> datafusion_common::Result<Arc<dyn PhysicalExpr>> {
Ok(Arc::new(NormalizeNaNAndZero::new(
self.data_type.clone(),
children[0].clone(),
Arc::clone(&children[0]),
)))
}

Expand Down
2 changes: 1 addition & 1 deletion native/core/src/execution/datafusion/expressions/stddev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl AggregateExpr for Stddev {
}

fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
vec![self.expr.clone()]
vec![Arc::clone(&self.expr)]
}

fn name(&self) -> &str {
Expand Down
4 changes: 2 additions & 2 deletions native/core/src/execution/datafusion/expressions/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl PhysicalExpr for SubstringExpr {
children: Vec<Arc<dyn PhysicalExpr>>,
) -> datafusion_common::Result<Arc<dyn PhysicalExpr>> {
Ok(Arc::new(SubstringExpr::new(
children[0].clone(),
Arc::clone(&children[0]),
self.start,
self.len,
)))
Expand Down Expand Up @@ -292,7 +292,7 @@ impl PhysicalExpr for StringSpaceExpr {
self: Arc<Self>,
children: Vec<Arc<dyn PhysicalExpr>>,
) -> datafusion_common::Result<Arc<dyn PhysicalExpr>> {
Ok(Arc::new(StringSpaceExpr::new(children[0].clone())))
Ok(Arc::new(StringSpaceExpr::new(Arc::clone(&children[0]))))
}

fn dyn_hash(&self, state: &mut dyn Hasher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl AggregateExpr for SumDecimal {
}

fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
vec![self.expr.clone()]
vec![Arc::clone(&self.expr)]
}

fn name(&self) -> &str {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl AggregateExpr for Variance {
}

fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>> {
vec![self.expr.clone()]
vec![Arc::clone(&self.expr)]
}

fn name(&self) -> &str {
Expand Down
19 changes: 11 additions & 8 deletions native/core/src/execution/datafusion/operators/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl CometExpandExec {
schema: SchemaRef,
) -> Self {
let cache = PlanProperties::new(
EquivalenceProperties::new(schema.clone()),
EquivalenceProperties::new(Arc::clone(&schema)),
Partitioning::UnknownPartitioning(1),
ExecutionMode::Bounded,
);
Expand Down Expand Up @@ -93,7 +93,7 @@ impl ExecutionPlan for CometExpandExec {
}

fn schema(&self) -> SchemaRef {
self.schema.clone()
Arc::clone(&self.schema)
}

fn children(&self) -> Vec<&Arc<dyn ExecutionPlan>> {
Expand All @@ -106,8 +106,8 @@ impl ExecutionPlan for CometExpandExec {
) -> datafusion_common::Result<Arc<dyn ExecutionPlan>> {
let new_expand = CometExpandExec::new(
self.projections.clone(),
children[0].clone(),
self.schema.clone(),
Arc::clone(&children[0]),
Arc::clone(&self.schema),
);
Ok(Arc::new(new_expand))
}
Expand All @@ -118,8 +118,11 @@ impl ExecutionPlan for CometExpandExec {
context: Arc<TaskContext>,
) -> datafusion_common::Result<SendableRecordBatchStream> {
let child_stream = self.child.execute(partition, context)?;
let expand_stream =
ExpandStream::new(self.projections.clone(), child_stream, self.schema.clone());
let expand_stream = ExpandStream::new(
self.projections.clone(),
child_stream,
Arc::clone(&self.schema),
);
Ok(Box::pin(expand_stream))
}

Expand Down Expand Up @@ -174,7 +177,7 @@ impl ExpandStream {
})?;

let options = RecordBatchOptions::new().with_row_count(Some(batch.num_rows()));
RecordBatch::try_new_with_options(self.schema.clone(), columns, &options)
RecordBatch::try_new_with_options(Arc::clone(&self.schema), columns, &options)
.map_err(|e| e.into())
}
}
Expand Down Expand Up @@ -210,6 +213,6 @@ impl Stream for ExpandStream {

impl RecordBatchStream for ExpandStream {
fn schema(&self) -> SchemaRef {
self.schema.clone()
Arc::clone(&self.schema)
}
}
Loading

0 comments on commit a99f742

Please sign in to comment.