@@ -48,7 +48,7 @@ use ballista_core::serde::protobuf::{
4848use ballista_core:: serde:: scheduler:: ExecutorMeta ;
4949
5050use clap:: arg_enum;
51- use datafusion:: physical_plan:: ExecutionPlan ;
51+ use datafusion:: physical_plan:: { ExecutionPlan , Partitioning } ;
5252#[ cfg( feature = "sled" ) ]
5353extern crate sled_package as sled;
5454
@@ -80,9 +80,12 @@ use tonic::{Request, Response};
8080
8181use self :: state:: { ConfigBackendClient , SchedulerState } ;
8282use ballista_core:: config:: BallistaConfig ;
83+ use ballista_core:: serde:: protobuf;
8384use ballista_core:: utils:: create_datafusion_context;
8485use datafusion:: physical_plan:: parquet:: ParquetExec ;
8586use std:: time:: { Instant , SystemTime , UNIX_EPOCH } ;
87+ use ballista_core:: execution_plans:: ShuffleWriterExec ;
88+ use datafusion:: physical_plan:: expressions:: Column ;
8689
8790#[ derive( Clone ) ]
8891pub struct SchedulerServer {
@@ -229,9 +232,47 @@ impl SchedulerGrpc for SchedulerServer {
229232 partition_id. partition_id
230233 ) ;
231234 }
232- plan. map ( |( status, plan) | TaskDefinition {
233- plan : Some ( plan. try_into ( ) . unwrap ( ) ) ,
234- task_id : status. partition_id ,
235+ plan. map ( |( status, plan) | {
236+ if let Some ( shuffle_writer) = plan. as_any ( ) . downcast_ref :: < ShuffleWriterExec > ( ) {
237+ let shuffle_child = plan. children ( ) [ 0 ] . clone ( ) ;
238+ match shuffle_writer. output_partitioning ( ) {
239+ Partitioning :: Hash ( expr, n) => {
240+ let shuffle_output_partitioning = Some ( protobuf:: PhysicalHashRepartition {
241+ hash_expr : expr. iter ( ) . map ( |e| {
242+ if let Some ( col) = e. as_any ( ) . downcast_ref :: < Column > ( ) {
243+ protobuf:: PhysicalExprNode {
244+ expr_type : Some ( protobuf:: physical_expr_node:: ExprType :: Column (
245+ //TODO should implement Into for this type?
246+ protobuf:: PhysicalColumn {
247+ name : col. name ( ) . to_string ( ) ,
248+ index : col. index ( ) as u32 ,
249+ } ) )
250+ }
251+ } else {
252+ todo ! ( )
253+ }
254+ } ) . collect :: < Vec < _ > > ( ) ,
255+ partition_count : n as u64
256+ } ) ;
257+
258+ TaskDefinition {
259+ plan : Some ( shuffle_child. try_into ( ) . unwrap ( ) ) ,
260+ task_id : status. partition_id ,
261+ shuffle_output_partitioning,
262+ }
263+ }
264+ Partitioning :: UnknownPartitioning ( 1 ) => {
265+ TaskDefinition {
266+ plan : Some ( shuffle_child. try_into ( ) . unwrap ( ) ) ,
267+ task_id : status. partition_id ,
268+ shuffle_output_partitioning : None ,
269+ }
270+ }
271+ _ => todo ! ( )
272+ }
273+ } else {
274+ unreachable ! ( )
275+ }
235276 } )
236277 } else {
237278 None
@@ -431,25 +472,25 @@ impl SchedulerGrpc for SchedulerServer {
431472 } ) ) ;
432473
433474 // save stages into state
434- for stage in stages {
475+ for shuffle_writer in stages {
435476 fail_job ! ( state
436477 . save_stage_plan(
437478 & job_id_spawn,
438- stage . stage_id( ) ,
439- stage . children ( ) [ 0 ] . clone( )
479+ shuffle_writer . stage_id( ) ,
480+ shuffle_writer . clone( )
440481 )
441482 . await
442483 . map_err( |e| {
443484 let msg = format!( "Could not save stage plan: {}" , e) ;
444485 error!( "{}" , msg) ;
445486 tonic:: Status :: internal( msg)
446487 } ) ) ;
447- let num_partitions = stage . output_partitioning ( ) . partition_count ( ) ;
488+ let num_partitions = shuffle_writer . output_partitioning ( ) . partition_count ( ) ;
448489 for partition_id in 0 ..num_partitions {
449490 let pending_status = TaskStatus {
450491 partition_id : Some ( PartitionId {
451492 job_id : job_id_spawn. clone ( ) ,
452- stage_id : stage . stage_id ( ) as u32 ,
493+ stage_id : shuffle_writer . stage_id ( ) as u32 ,
453494 partition_id : partition_id as u32 ,
454495 } ) ,
455496 status : None ,
0 commit comments