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

Implement protobuf serialization for AnalyzeExec #7574

Merged
merged 5 commits into from
Sep 18, 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
15 changes: 15 additions & 0 deletions datafusion/physical-plan/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ impl AnalyzeExec {
schema,
}
}

/// access to verbose
pub fn verbose(&self) -> bool {
self.verbose
}

/// access to show_statistics
pub fn show_statistics(&self) -> bool {
self.show_statistics
}

/// The input plan
pub fn input(&self) -> &Arc<dyn ExecutionPlan> {
&self.input
}
}

impl DisplayAs for AnalyzeExec {
Expand Down
8 changes: 8 additions & 0 deletions datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ message PhysicalPlanNode {
ExplainExecNode explain = 20;
SortPreservingMergeExecNode sort_preserving_merge = 21;
NestedLoopJoinExecNode nested_loop_join = 22;
AnalyzeExecNode analyze = 23;
}
}

Expand Down Expand Up @@ -1345,6 +1346,13 @@ message ExplainExecNode {
bool verbose = 3;
}

message AnalyzeExecNode {
bool verbose = 1;
bool show_statistics = 2;
PhysicalPlanNode input = 3;
Schema schema = 4;
}

message CrossJoinExecNode {
PhysicalPlanNode left = 1;
PhysicalPlanNode right = 2;
Expand Down
156 changes: 156 additions & 0 deletions datafusion/proto/src/generated/pbjson.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion datafusion/proto/src/generated/prost.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion datafusion/proto/src/physical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use datafusion::execution::FunctionRegistry;
use datafusion::logical_expr::WindowFrame;
use datafusion::physical_plan::aggregates::{create_aggregate_expr, AggregateMode};
use datafusion::physical_plan::aggregates::{AggregateExec, PhysicalGroupBy};
use datafusion::physical_plan::analyze::AnalyzeExec;
use datafusion::physical_plan::coalesce_batches::CoalesceBatchesExec;
use datafusion::physical_plan::coalesce_partitions::CoalescePartitionsExec;
use datafusion::physical_plan::empty::EmptyExec;
Expand Down Expand Up @@ -778,6 +779,20 @@ impl AsExecutionPlan for PhysicalPlanNode {
&join_type.into(),
)?))
}
PhysicalPlanType::Analyze(analyze) => {
let input: Arc<dyn ExecutionPlan> = into_physical_plan(
&analyze.input,
registry,
runtime,
extension_codec,
)?;
Ok(Arc::new(AnalyzeExec::new(
analyze.verbose,
analyze.show_statistics,
input,
Arc::new(analyze.schema.as_ref().unwrap().try_into()?),
)))
}
}
}

Expand Down Expand Up @@ -825,6 +840,21 @@ impl AsExecutionPlan for PhysicalPlanNode {
},
))),
})
} else if let Some(exec) = plan.downcast_ref::<AnalyzeExec>() {
let input = protobuf::PhysicalPlanNode::try_from_physical_plan(
exec.input().to_owned(),
extension_codec,
)?;
Ok(protobuf::PhysicalPlanNode {
physical_plan_type: Some(PhysicalPlanType::Analyze(Box::new(
protobuf::AnalyzeExecNode {
verbose: exec.verbose(),
show_statistics: exec.show_statistics(),
input: Some(Box::new(input)),
schema: Some(exec.schema().as_ref().try_into()?),
},
))),
})
} else if let Some(exec) = plan.downcast_ref::<FilterExec>() {
let input = protobuf::PhysicalPlanNode::try_from_physical_plan(
exec.input().to_owned(),
Expand Down Expand Up @@ -1391,6 +1421,7 @@ mod roundtrip_tests {
use datafusion::physical_expr::expressions::{cast, in_list};
use datafusion::physical_expr::ScalarFunctionExpr;
use datafusion::physical_plan::aggregates::PhysicalGroupBy;
use datafusion::physical_plan::analyze::AnalyzeExec;
use datafusion::physical_plan::expressions::{like, BinaryExpr, GetIndexedFieldExpr};
use datafusion::physical_plan::functions::make_scalar_function;
use datafusion::physical_plan::projection::ProjectionExec;
Expand Down Expand Up @@ -1946,7 +1977,7 @@ mod roundtrip_tests {
];

let schema = Schema::new(fields);
let input = Arc::new(EmptyExec::new(false, Arc::new(schema.clone())));
let input = Arc::new(EmptyExec::new(true, Arc::new(schema.clone())));

let col_arg = col("arg", &schema)?;
let col_key = col("key", &schema)?;
Expand Down Expand Up @@ -1993,4 +2024,19 @@ mod roundtrip_tests {

roundtrip_test(plan)
}

#[test]
fn rountrip_analyze() -> Result<()> {
let field_a = Field::new("plan_type", DataType::Utf8, false);
let field_b = Field::new("plan", DataType::Utf8, false);
let schema = Schema::new(vec![field_a, field_b]);
let input = Arc::new(EmptyExec::new(true, Arc::new(schema.clone())));

roundtrip_test(Arc::new(AnalyzeExec::new(
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

false,
false,
input,
Arc::new(schema),
)))
}
}