Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating assumption on children partition count #56

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
24 changes: 17 additions & 7 deletions src/query_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use datafusion::prelude::SessionContext;
use datafusion_proto::bytes::physical_plan_from_bytes_with_extension_codec;
use pyo3::prelude::*;
use pyo3::types::PyBytes;
use std::collections::HashSet;
use std::sync::Arc;

#[pyclass(name = "QueryStage", module = "datafusion_ray", subclass)]
Expand Down Expand Up @@ -99,14 +100,23 @@ impl QueryStage {
/// Get the input partition count. This is the same as the number of concurrent tasks
/// when we schedule this query stage for execution
pub fn get_input_partition_count(&self) -> usize {
if self.plan.children().is_empty() {
// leaf node (file scan)
self.plan.output_partitioning().partition_count()
} else {
self.plan.children()[0]
.output_partitioning()
.partition_count()
let mut output_partition_counts = HashSet::new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this check without creating additional data structures:

    let partition_count = self.plan.children()[0].output_partitioning().partition_count();
    for i in 1..self.plan.children().len() {
        if self.plan.children()[i].output_partitioning().partition_count() != partition_count {
            return Err(...)
        }
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, do you think we should r change the signature to return an error ? That was my original idea, I think there is a 'plan_err!' macro in datafusion we can use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #54 no longer looks at the plan's children in this section of code, so perhaps this check (which is a good check) should move somewhere else. I'd suggest adding it in QueryStage::new and have it return Result<Self>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, so let's postpone this as an improvement on #54

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I converted it into Draft in the meantime


for child in self.plan.children() {
output_partition_counts.insert(child.output_partitioning().partition_count());
if output_partition_counts.len() > 1 {
panic!(
"Children plan of {:#?} have a distinct output partitioning partition count",
self.plan
);
}
}
// If this stage is a leaf node (file scan), it won't have children
// so we return the partition count of the plan itself
output_partition_counts
.into_iter()
.next()
.unwrap_or(self.plan.output_partitioning().partition_count())
}

pub fn get_output_partition_count(&self) -> usize {
Expand Down