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
41 changes: 40 additions & 1 deletion ballista/client/tests/context_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ mod standalone {

use std::sync::{Arc, atomic::AtomicBool};

use crate::common::{register_alltypes, state_with_config};
use crate::common::{ALLTYPES_GROUP_BY_SQL, register_alltypes, state_with_config};
use crate::{assert_job_name_setting, job_name_state};
use ballista::extension::{SessionConfigExt, SessionContextExt};
use ballista_core::execution_plans::plan_algebra::PartitionSliceableResolver;
use ballista_core::serde::BallistaPhysicalExtensionCodec;
use datafusion::{
catalog::Session,
Expand Down Expand Up @@ -184,6 +185,26 @@ mod standalone {
Ok(())
}

#[tokio::test]
async fn should_set_partition_sliceable_resolver() -> datafusion::error::Result<()> {
let resolver = Arc::new(MockPartitionSliceableResolver::default());
let session_config = SessionConfig::new_with_ballista()
.with_ballista_partition_sliceable_resolver(resolver.clone());

let state = state_with_config(session_config);
let ctx = SessionContext::standalone_with_state(state).await?;

register_alltypes(&ctx, "test").await;

// Execute a query to verify that the standalone scheduler uses the
// resolver registered in the session configuration.
ctx.sql(ALLTYPES_GROUP_BY_SQL).await?.collect().await?;

assert!(resolver.invoked.load(std::sync::atomic::Ordering::Relaxed));

Ok(())
}

// check
#[tokio::test]
async fn should_override_planner() -> datafusion::error::Result<()> {
Expand Down Expand Up @@ -330,6 +351,24 @@ mod standalone {
}
}

#[derive(Debug, Default)]
struct MockPartitionSliceableResolver {
invoked: AtomicBool,
}

impl PartitionSliceableResolver for MockPartitionSliceableResolver {
fn restrict_to_partitions(
&self,
_plan: &Arc<dyn ExecutionPlan>,
_children: Vec<Arc<dyn ExecutionPlan>>,
_partitions: &[usize],
) -> Option<datafusion::error::Result<Arc<dyn ExecutionPlan>>> {
self.invoked
.store(true, std::sync::atomic::Ordering::Relaxed);
None
}
}

#[derive(Debug, Default)]
struct BadPlanner {}

Expand Down
50 changes: 50 additions & 0 deletions ballista/core/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::config::{
BALLISTA_SKEW_JOIN_SMALL_PARTITION_FACTOR, BALLISTA_STANDALONE_PARALLELISM,
BallistaConfig, ExecutionMode,
};
use crate::execution_plans::plan_algebra::PartitionSliceableResolver;
use crate::planner::BallistaQueryPlanner;
use crate::serde::protobuf::KeyValuePair;
use crate::serde::{BallistaLogicalExtensionCodec, BallistaPhysicalExtensionCodec};
Expand Down Expand Up @@ -123,6 +124,16 @@ pub trait SessionConfigExt {
codec: Arc<dyn PhysicalExtensionCodec>,
) -> SessionConfig;

/// Sets how custom plan nodes are restricted to a task's partitions.
///
/// Used when creating a standalone scheduler from SessionConfig. Setting
/// this when not in standalone mode has no effect. Configure the remote scheduler with
/// `SchedulerConfig::with_partition_sliceable_resolver` instead.
fn with_ballista_partition_sliceable_resolver(
self,
resolver: Arc<dyn PartitionSliceableResolver>,
) -> SessionConfig;

/// returns [LogicalExtensionCodec] if set
/// or default ballista codec if not
fn ballista_logical_extension_codec(&self) -> Arc<dyn LogicalExtensionCodec>;
Expand All @@ -131,6 +142,13 @@ pub trait SessionConfigExt {
/// or default ballista codec if not
fn ballista_physical_extension_codec(&self) -> Arc<dyn PhysicalExtensionCodec>;

/// Returns the resolver for restricting custom plan nodes to a task's partitions.
///
/// Returns `None` if not set.
fn ballista_partition_sliceable_resolver(
&self,
) -> Option<Arc<dyn PartitionSliceableResolver>>;

/// Overrides ballista's [QueryPlanner]
fn with_ballista_query_planner(
self,
Expand Down Expand Up @@ -530,6 +548,7 @@ impl SessionConfigExt for SessionConfig {
let extension = BallistaConfigExtensionLogicalCodec::new(codec);
self.with_extension(Arc::new(extension))
}

fn with_ballista_physical_extension_codec(
self,
codec: Arc<dyn PhysicalExtensionCodec>,
Expand All @@ -538,6 +557,14 @@ impl SessionConfigExt for SessionConfig {
self.with_extension(Arc::new(extension))
}

fn with_ballista_partition_sliceable_resolver(
self,
resolver: Arc<dyn PartitionSliceableResolver>,
) -> SessionConfig {
let extension = BallistaConfigExtensionPartitionSliceableResolver::new(resolver);
self.with_extension(Arc::new(extension))
}

fn ballista_logical_extension_codec(&self) -> Arc<dyn LogicalExtensionCodec> {
self.get_extension::<BallistaConfigExtensionLogicalCodec>()
.map(|c| c.codec())
Expand All @@ -549,6 +576,13 @@ impl SessionConfigExt for SessionConfig {
.unwrap_or_else(|| Arc::new(BallistaPhysicalExtensionCodec::default()))
}

fn ballista_partition_sliceable_resolver(
&self,
) -> Option<Arc<dyn PartitionSliceableResolver>> {
self.get_extension::<BallistaConfigExtensionPartitionSliceableResolver>()
.map(|extension| extension.resolver())
}

fn with_ballista_query_planner(
self,
planner: Arc<dyn QueryPlanner + Send + Sync + 'static>,
Expand Down Expand Up @@ -881,6 +915,22 @@ impl BallistaConfigExtensionPhysicalCodec {
}
}

/// Wrapper for [SessionConfig] extension
/// holding [PartitionSliceableResolver] if set
struct BallistaConfigExtensionPartitionSliceableResolver {
resolver: Arc<dyn PartitionSliceableResolver>,
}

impl BallistaConfigExtensionPartitionSliceableResolver {
fn new(resolver: Arc<dyn PartitionSliceableResolver>) -> Self {
Self { resolver }
}

fn resolver(&self) -> Arc<dyn PartitionSliceableResolver> {
self.resolver.clone()
}
}

/// Wrapper for [SessionConfig] extension
/// holding overridden [QueryPlanner]
struct BallistaQueryPlannerExtension {
Expand Down
8 changes: 7 additions & 1 deletion ballista/scheduler/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@ pub async fn new_standalone_scheduler_with_builder(

let metrics_collector = default_metrics_collector()?;

let mut scheduler_config = SchedulerConfig::default().with_scheduler_policy(policy);

if let Some(resolver) = config.ballista_partition_sliceable_resolver() {
scheduler_config = scheduler_config.with_partition_sliceable_resolver(resolver);
}

let mut scheduler_server: SchedulerServer<LogicalPlanNode, PhysicalPlanNode> =
SchedulerServer::new(
endpoint,
cluster,
codec,
Arc::new(SchedulerConfig::default().with_scheduler_policy(policy)),
Arc::new(scheduler_config),
metrics_collector,
);

Expand Down
8 changes: 8 additions & 0 deletions docs/source/upgrading/56.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ nodes that cannot implement `PartitionSliceable`, such as a `DataSourceExec`.
literal that doesn't end in `..Default::default()` needs to set it.
- `task_builder::restrict_plan_to_partitions` takes a third argument,
`Option<&dyn PartitionSliceableResolver>`. Pass `None` for none.
- `SessionConfigExt` gains two required methods:
`with_ballista_partition_sliceable_resolver` and
`ballista_partition_sliceable_resolver`. Downstream implementations of this
trait must implement both methods. Existing callers need no changes.

For standalone execution, register the resolver in the session configuration
with `with_ballista_partition_sliceable_resolver`, then pass the session state
to `SessionContext::standalone_with_state`.

#### Partition locations hold an `ExecutorEndpoint`

Expand Down
2 changes: 1 addition & 1 deletion docs/source/user-guide/extending-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ let config = SchedulerConfig::default().with_partition_sliceable_resolver(Arc::n
- The restricted node is serialized with the scheduler's `physical codec`, so what it carries per partition has to survive encoding and decoding.
- The resolver does not need `PartitionSliceable`. It can build the restricted node itself, which is the way to restrict a node you cannot implement the trait on, such as a `DataSourceExec` over a `DataSource` of your own: match it with `downcast_ref`, then build a `DataSourceExec` over the restricted source.
- The resolver is asked after Ballista's own list. A node that is read whole, such as one below a `CoalescePartitionsExec` or on a join's build side, needs none of this.
- The standalone scheduler (`SessionContext::standalone`) builds its own `SchedulerConfig`, so it cannot be given a resolver.
- The standalone scheduler reads the resolver from the session configuration. Register it with `with_ballista_partition_sliceable_resolver`, then use that configuration when building the session state passed to `SessionContext::standalone_with_state`.
Loading