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

refactor: port get_scan_files to Ballista #877

Merged
merged 1 commit into from
Sep 15, 2023
Merged
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
3 changes: 1 addition & 2 deletions ballista/scheduler/src/cluster/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::cluster::storage::{KeyValueStore, Keyspace, Lock, Operation, WatchEvent};
use crate::cluster::{
bind_task_bias, bind_task_consistent_hash, bind_task_round_robin,
bind_task_bias, bind_task_consistent_hash, bind_task_round_robin, get_scan_files,
is_skip_consistent_hash, BoundTask, ClusterState, ExecutorHeartbeatStream,
ExecutorSlot, JobState, JobStateEvent, JobStateEventStream, JobStatus,
TaskDistributionPolicy, TopologyNode,
Expand All @@ -39,7 +39,6 @@ use ballista_core::serde::protobuf::{
use ballista_core::serde::scheduler::{ExecutorData, ExecutorMetadata};
use ballista_core::serde::BallistaCodec;
use dashmap::DashMap;
use datafusion::datasource::physical_plan::get_scan_files;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point of this PR is to remove this dependency (so we can remove it from DataFusion)

use datafusion::physical_plan::ExecutionPlan;
use datafusion::prelude::SessionContext;
use datafusion_proto::logical_plan::AsLogicalPlan;
Expand Down
3 changes: 1 addition & 2 deletions ballista/scheduler/src/cluster/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.

use crate::cluster::{
bind_task_bias, bind_task_consistent_hash, bind_task_round_robin,
bind_task_bias, bind_task_consistent_hash, bind_task_round_robin, get_scan_files,
is_skip_consistent_hash, BoundTask, ClusterState, ExecutorSlot, JobState,
JobStateEvent, JobStateEventStream, JobStatus, TaskDistributionPolicy, TopologyNode,
};
Expand All @@ -42,7 +42,6 @@ use std::collections::{HashMap, HashSet};
use std::ops::DerefMut;

use ballista_core::consistent_hash::node::Node;
use datafusion::datasource::physical_plan::get_scan_files;
use datafusion::physical_plan::ExecutionPlan;
use std::sync::Arc;
use tokio::sync::{Mutex, MutexGuard};
Expand Down
30 changes: 30 additions & 0 deletions ballista/scheduler/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ use std::pin::Pin;
use std::sync::Arc;

use clap::ArgEnum;
use datafusion::common::tree_node::TreeNode;
use datafusion::common::tree_node::VisitRecursion;
use datafusion::datasource::listing::PartitionedFile;
use datafusion::datasource::physical_plan::{AvroExec, CsvExec, NdJsonExec, ParquetExec};
use datafusion::error::DataFusionError;
use datafusion::physical_plan::ExecutionPlan;
use datafusion::prelude::SessionContext;
use datafusion_proto::logical_plan::AsLogicalPlan;
Expand Down Expand Up @@ -680,6 +684,32 @@ pub(crate) fn is_skip_consistent_hash(scan_files: &[Vec<Vec<PartitionedFile>>])
scan_files.is_empty() || scan_files.len() > 1
}

/// Get all of the [`PartitionedFile`] to be scanned for an [`ExecutionPlan`]
pub(crate) fn get_scan_files(
plan: Arc<dyn ExecutionPlan>,
) -> std::result::Result<Vec<Vec<Vec<PartitionedFile>>>, DataFusionError> {
let mut collector: Vec<Vec<Vec<PartitionedFile>>> = vec![];
plan.apply(&mut |plan| {
let plan_any = plan.as_any();
let file_groups =
if let Some(parquet_exec) = plan_any.downcast_ref::<ParquetExec>() {
parquet_exec.base_config().file_groups.clone()
} else if let Some(avro_exec) = plan_any.downcast_ref::<AvroExec>() {
avro_exec.base_config().file_groups.clone()
} else if let Some(json_exec) = plan_any.downcast_ref::<NdJsonExec>() {
json_exec.base_config().file_groups.clone()
} else if let Some(csv_exec) = plan_any.downcast_ref::<CsvExec>() {
csv_exec.base_config().file_groups.clone()
} else {
return Ok(VisitRecursion::Continue);
};

collector.push(file_groups);
Ok(VisitRecursion::Skip)
})?;
Ok(collector)
}

#[derive(Clone)]
pub struct TopologyNode {
pub id: String,
Expand Down