Example #1
0
P::PhysicalPtr ReduceGroupByAttributes::applyInternal(const P::PhysicalPtr &input) {
  std::vector<P::PhysicalPtr> new_children;
  for (const P::PhysicalPtr &child : input->children()) {
    new_children.push_back(applyInternal(child));
  }

  if (new_children != input->children()) {
    return applyToNode(input->copyWithNewChildren(new_children));
  } else {
    return applyToNode(input);
  }
}
P::PhysicalPtr InjectJoinFilters::transformHashJoinToFilters(
    const P::PhysicalPtr &input) const {
  std::vector<P::PhysicalPtr> new_children;
  for (const P::PhysicalPtr &child : input->children()) {
    new_children.emplace_back(transformHashJoinToFilters(child));
  }

  P::HashJoinPtr hash_join;
  if (P::SomeHashJoin::MatchesWithConditionalCast(input, &hash_join) &&
      isTransformable(hash_join)) {
    const bool is_anti_join =
        hash_join->join_type() == P::HashJoin::JoinType::kLeftAntiJoin;

    DCHECK_EQ(2u, new_children.size());
    P::PhysicalPtr build_child = new_children[1];
    E::PredicatePtr build_side_filter_predicate = nullptr;
    P::SelectionPtr selection;
    if (hash_join->build_predicate() == nullptr) {
      if (P::SomeSelection::MatchesWithConditionalCast(build_child, &selection) &&
          E::SubsetOfExpressions(hash_join->right_join_attributes(),
                                 selection->input()->getOutputAttributes())) {
        build_child = selection->input();
        build_side_filter_predicate = selection->filter_predicate();
      }
    } else {
      build_child = hash_join->right();
      build_side_filter_predicate = hash_join->build_predicate();
    }
    return P::FilterJoin::Create(new_children[0],
                                 build_child,
                                 hash_join->left_join_attributes(),
                                 hash_join->right_join_attributes(),
                                 hash_join->project_expressions(),
                                 build_side_filter_predicate,
                                 is_anti_join,
                                 hash_join->hasRepartition(),
                                 hash_join->cloneOutputPartitionSchemeHeader());
  }

  if (input->children() != new_children) {
    return input->copyWithNewChildren(new_children);
  } else {
    return input;
  }
}