Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl TableProvider for CustomDataSource {
struct CustomExec {
db: CustomDataSource,
projected_schema: SchemaRef,
cache: PlanProperties,
cache: Arc<PlanProperties>,
}

impl CustomExec {
Expand All @@ -207,7 +207,7 @@ impl CustomExec {
Self {
db,
projected_schema,
cache,
cache: Arc::new(cache),
}
}

Expand Down Expand Up @@ -238,7 +238,7 @@ impl ExecutionPlan for CustomExec {
self
}

fn properties(&self) -> &PlanProperties {
fn properties(&self) -> &Arc<PlanProperties> {
&self.cache
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl ExternalBatchBufferer {
struct BufferingExecutionPlan {
schema: SchemaRef,
input: Arc<dyn ExecutionPlan>,
properties: PlanProperties,
properties: Arc<PlanProperties>,
}

impl BufferingExecutionPlan {
Expand Down Expand Up @@ -233,7 +233,7 @@ impl ExecutionPlan for BufferingExecutionPlan {
self.schema.clone()
}

fn properties(&self) -> &PlanProperties {
fn properties(&self) -> &Arc<PlanProperties> {
&self.properties
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl ExecutionPlan for ParentExec {
self
}

fn properties(&self) -> &datafusion::physical_plan::PlanProperties {
fn properties(&self) -> &Arc<datafusion::physical_plan::PlanProperties> {
unreachable!()
}

Expand Down Expand Up @@ -182,7 +182,7 @@ impl ExecutionPlan for ChildExec {
self
}

fn properties(&self) -> &datafusion::physical_plan::PlanProperties {
fn properties(&self) -> &Arc<datafusion::physical_plan::PlanProperties> {
unreachable!()
}

Expand Down
6 changes: 3 additions & 3 deletions datafusion-examples/examples/relation_planner/table_sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ pub struct SampleExec {
upper_bound: f64,
seed: u64,
metrics: ExecutionPlanMetricsSet,
cache: PlanProperties,
cache: Arc<PlanProperties>,
}

impl SampleExec {
Expand Down Expand Up @@ -656,7 +656,7 @@ impl SampleExec {
upper_bound,
seed,
metrics: ExecutionPlanMetricsSet::new(),
cache,
cache: Arc::new(cache),
})
}

Expand Down Expand Up @@ -686,7 +686,7 @@ impl ExecutionPlan for SampleExec {
self
}

fn properties(&self) -> &PlanProperties {
fn properties(&self) -> &Arc<PlanProperties> {
&self.cache
}

Expand Down
6 changes: 3 additions & 3 deletions datafusion/catalog/src/memory/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn evaluate_filters_to_mask(
struct DmlResultExec {
rows_affected: u64,
schema: SchemaRef,
properties: PlanProperties,
properties: Arc<PlanProperties>,
}

impl DmlResultExec {
Expand All @@ -570,7 +570,7 @@ impl DmlResultExec {
Self {
rows_affected,
schema,
properties,
properties: Arc::new(properties),
}
}
}
Expand Down Expand Up @@ -604,7 +604,7 @@ impl ExecutionPlan for DmlResultExec {
Arc::clone(&self.schema)
}

fn properties(&self) -> &PlanProperties {
fn properties(&self) -> &Arc<PlanProperties> {
&self.properties
}

Expand Down
13 changes: 9 additions & 4 deletions datafusion/common/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,13 @@ impl Statistics {
/// For example, if we had statistics for columns `{"a", "b", "c"}`,
/// projecting to `vec![2, 1]` would return statistics for columns `{"c",
/// "b"}`.
pub fn project(mut self, projection: Option<&Vec<usize>>) -> Self {
let Some(projection) = projection else {
pub fn project(self, projection: Option<&impl AsRef<[usize]>>) -> Self {
let projection = projection.map(AsRef::as_ref);
self.project_impl(projection)
}

fn project_impl(mut self, projection: Option<&[usize]>) -> Self {
let Some(projection) = projection.map(AsRef::as_ref) else {
return self;
};

Expand All @@ -410,7 +415,7 @@ impl Statistics {
.map(Slot::Present)
.collect();

for idx in projection {
for idx in projection.iter() {
let next_idx = self.column_statistics.len();
let slot = std::mem::replace(
columns.get_mut(*idx).expect("projection out of bounds"),
Expand Down Expand Up @@ -1066,7 +1071,7 @@ mod tests {

#[test]
fn test_project_none() {
let projection = None;
let projection: Option<Vec<usize>> = None;
let stats = make_stats(vec![10, 20, 30]).project(projection.as_ref());
assert_eq!(stats, make_stats(vec![10, 20, 30]));
}
Expand Down
4 changes: 2 additions & 2 deletions datafusion/common/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ use std::thread::available_parallelism;
/// ```
pub fn project_schema(
schema: &SchemaRef,
projection: Option<&Vec<usize>>,
projection: Option<&impl AsRef<[usize]>>,
) -> Result<SchemaRef> {
let schema = match projection {
Some(columns) => Arc::new(schema.project(columns)?),
Some(columns) => Arc::new(schema.project(columns.as_ref())?),
None => Arc::clone(schema),
};
Ok(schema)
Expand Down
Loading
Loading