Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordworms committed Feb 6, 2024
1 parent ddcc1e8 commit 8a4b21e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
22 changes: 10 additions & 12 deletions datafusion/physical-expr/src/equivalence/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// specific language governing permissions and limitations
// under the License.

use crate::expressions::{CastExpr, Column};
use crate::expressions::CastExpr;
use arrow_schema::SchemaRef;
use datafusion_common::{scalar, JoinSide, JoinType};
use datafusion_common::{JoinSide, JoinType};
use indexmap::IndexSet;
use itertools::Itertools;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -433,14 +433,12 @@ impl EquivalenceProperties {
/// x is DESC or ASC
pub fn substitute_ordering_component(
matching_exprs: Arc<Vec<&Arc<dyn PhysicalExpr>>>,
sort_expr: &Vec<PhysicalSortExpr>,
sort_expr: &[PhysicalSortExpr],
) -> Vec<PhysicalSortExpr> {
sort_expr
.iter()
.filter(|sort_expr| {
matching_exprs
.iter()
.any(|matched| !matched.eq(sort_expr.clone()))
matching_exprs.iter().any(|matched| !matched.eq(*sort_expr))
})
.map(|sort_expr| {
let referring_exprs: Vec<_> = matching_exprs
Expand All @@ -449,9 +447,8 @@ impl EquivalenceProperties {
.cloned()
.collect();
// does not referring to any matching component, we just skip it
if referring_exprs.len() == 0 {
sort_expr.clone()
} else {

if referring_exprs.len() == 1 {
// we check whether this expression is substitutable or not
let r_expr = referring_exprs[0].clone();
if let Some(cast_expr) = r_expr.as_any().downcast_ref::<CastExpr>() {
Expand All @@ -471,7 +468,7 @@ impl EquivalenceProperties {
let mut result = sort_expr.clone();
if let Some(v) = scalar_func_expr.monotonicity() {
if v == &[Some(true)] {
if let Some(arg) = scalar_func_expr.args().get(0) {
if let Some(arg) = scalar_func_expr.args().first() {
//println!("arg is {:?}", arg);
if arg.eq(&sort_expr.expr)
|| arg.as_any().downcast_ref::<CastExpr>().map_or(
Expand All @@ -493,6 +490,8 @@ impl EquivalenceProperties {
} else {
sort_expr.clone()
}
} else {
sort_expr.clone()
}
})
.collect()
Expand All @@ -504,7 +503,7 @@ impl EquivalenceProperties {
/// dependency map, happen in issue 8838: https://github.com/apache/arrow-datafusion/issues/8838
pub fn substitute_oeq_class(
&mut self,
exprs: &Vec<(Arc<dyn PhysicalExpr>, String)>,
exprs: &[(Arc<dyn PhysicalExpr>, String)],
mapping: &ProjectionMapping,
) {
let matching_exprs: Arc<Vec<_>> = Arc::new(
Expand Down Expand Up @@ -664,7 +663,6 @@ impl EquivalenceProperties {

// Get dependency map for existing orderings:
let dependency_map = self.construct_dependency_map(&mapping);

let orderings = mapping.iter().flat_map(|(source, target)| {
referred_dependencies(&dependency_map, source)
.into_iter()
Expand Down
3 changes: 1 addition & 2 deletions datafusion/physical-plan/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ impl ExecutionPlan for ProjectionExec {
fn equivalence_properties(&self) -> EquivalenceProperties {
let mut equi_properties = self.input.equivalence_properties();
equi_properties.substitute_oeq_class(&self.expr, &self.projection_mapping);
let res = equi_properties.project(&self.projection_mapping, self.schema());
res
equi_properties.project(&self.projection_mapping, self.schema())
}

fn with_new_children(
Expand Down

0 comments on commit 8a4b21e

Please sign in to comment.