MCPcopy Create free account
hub / github.com/apache/datafusion / rewrite

Method rewrite

datafusion/optimizer/src/propagate_empty_relation.rs:55–234  ·  view source on GitHub ↗
(
        &self,
        plan: LogicalPlan,
        _config: &dyn OptimizerConfig,
    )

Source from the content-addressed store, hash-verified

53 }
54
55 fn rewrite(
56 &self,
57 plan: LogicalPlan,
58 _config: &dyn OptimizerConfig,
59 ) -> Result<Transformed<LogicalPlan>> {
60 match plan {
61 LogicalPlan::EmptyRelation(_) => Ok(Transformed::no(plan)),
62 LogicalPlan::Projection(_)
63 | LogicalPlan::Filter(_)
64 | LogicalPlan::Window(_)
65 | LogicalPlan::Sort(_)
66 | LogicalPlan::SubqueryAlias(_)
67 | LogicalPlan::Repartition(_)
68 | LogicalPlan::Limit(_) => {
69 let empty = empty_child(&plan)?;
70 if let Some(empty_plan) = empty {
71 return Ok(Transformed::yes(empty_plan));
72 }
73 Ok(Transformed::no(plan))
74 }
75 LogicalPlan::Join(ref join) => {
76 let (left_empty, right_empty) = binary_plan_children_is_empty(&plan)?;
77 let left_field_count = join.left.schema().fields().len();
78
79 match join.join_type {
80 // For Full Join, only both sides are empty, the Join result is empty.
81 JoinType::Full if left_empty && right_empty => Ok(Transformed::yes(
82 LogicalPlan::EmptyRelation(EmptyRelation {
83 produce_one_row: false,
84 schema: Arc::clone(&join.schema),
85 }),
86 )),
87 // For Full Join, if one side is empty, replace with a
88 // Projection that null-pads the empty side's columns.
89 JoinType::Full if right_empty => {
90 Ok(Transformed::yes(build_null_padded_projection(
91 Arc::clone(&join.left),
92 &join.schema,
93 left_field_count,
94 true,
95 )?))
96 }
97 JoinType::Full if left_empty => {
98 Ok(Transformed::yes(build_null_padded_projection(
99 Arc::clone(&join.right),
100 &join.schema,
101 left_field_count,
102 false,
103 )?))
104 }
105 JoinType::Inner if left_empty || right_empty => Ok(Transformed::yes(
106 LogicalPlan::EmptyRelation(EmptyRelation {
107 produce_one_row: false,
108 schema: Arc::clone(&join.schema),
109 }),
110 )),
111 JoinType::Left if left_empty => Ok(Transformed::yes(
112 LogicalPlan::EmptyRelation(EmptyRelation {

Callers

nothing calls this directly

Calls 15

empty_childFunction · 0.85
EmptyRelationClass · 0.85
has_empty_grouping_setFunction · 0.85
AggregateClass · 0.85
ProjectionClass · 0.85
newFunction · 0.85
UnionClass · 0.50
lenMethod · 0.45
fieldsMethod · 0.45
schemaMethod · 0.45

Tested by

no test coverage detected