Github user hbdeshmukh commented on a diff in the pull request:

    https://github.com/apache/incubator-quickstep/pull/181#discussion_r104723411
  
    --- Diff: query_optimizer/ExecutionGenerator.cpp ---
    @@ -740,6 +805,202 @@ void ExecutionGenerator::convertHashJoin(const 
P::HashJoinPtr &physical_plan) {
         key_types.push_back(&left_attribute_type);
       }
     
    +  const CatalogRelationInfo *build_relation_info =
    +      findRelationInfoOutputByPhysical(build_physical);
    +  const CatalogRelationInfo *probe_operator_info =
    +      findRelationInfoOutputByPhysical(probe_physical);
    +
    +  const CatalogRelation *build_relation = build_relation_info->relation;
    +  const CatalogRelation *probe_relation = probe_operator_info->relation;
    +
    +  // FIXME(quickstep-team): Add support for self-join.
    +  if (build_relation == probe_relation) {
    +    THROW_SQL_ERROR() << "Self-join is not supported";
    +  }
    +
    +  const PartitionScheme *build_partition_scheme = 
build_relation->getPartitionScheme();
    +  const PartitionScheme *probe_partition_scheme = 
probe_relation->getPartitionScheme();
    +
    +  bool build_needs_repartition = false;
    +  bool probe_needs_repartition = false;
    +  bool needs_swap = false;
    +  if (build_partition_scheme && probe_partition_scheme) {
    +    const PartitionSchemeHeader &build_partition_scheme_header = 
build_partition_scheme->getPartitionSchemeHeader();
    +    const PartitionSchemeHeader &probe_partition_scheme_header = 
probe_partition_scheme->getPartitionSchemeHeader();
    +
    +    switch (build_partition_scheme_header.getPartitionType()) {
    +      case PartitionSchemeHeader::PartitionType::kRange:
    +        build_needs_repartition = true;
    +
    +        switch (probe_partition_scheme_header.getPartitionType()) {
    +          case PartitionSchemeHeader::PartitionType::kRange:
    +            probe_needs_repartition = true;
    +            break;
    +          case PartitionSchemeHeader::PartitionType::kHash: {
    +            const attribute_id probe_partition_attr = 
probe_partition_scheme_header.getPartitionAttributeId();
    +            if (find(probe_attribute_ids.begin(), 
probe_attribute_ids.end(), probe_partition_attr) !=
    +                    probe_attribute_ids.end()) {
    +              needs_swap = true;
    +            } else {
    +              probe_needs_repartition = true;
    +            }
    +            break;
    +          }
    +        }
    +        break;
    +      case PartitionSchemeHeader::PartitionType::kHash: {
    +        const attribute_id build_partition_attr = 
build_partition_scheme_header.getPartitionAttributeId();
    +        if (find(build_attribute_ids.begin(), build_attribute_ids.end(), 
build_partition_attr) !=
    +                build_attribute_ids.end()) {
    +          // BuildRelation has a useful partition.
    +          switch (probe_partition_scheme_header.getPartitionType()) {
    +            case PartitionSchemeHeader::PartitionType::kRange:
    +              probe_needs_repartition = true;
    +              break;
    +            case PartitionSchemeHeader::PartitionType::kHash: {
    +              if 
(areSamePartitionSchemeHeaders(build_partition_scheme_header, *build_relation,
    +                                                
probe_partition_scheme_header, *probe_relation)) {
    +                if 
(cost_model_for_hash_join_->estimateCardinality(build_physical) >
    +                        
cost_model_for_hash_join_->estimateCardinality(probe_physical)) {
    +                  needs_swap = true;
    +                }
    +              } else {
    +                probe_needs_repartition = true;
    +              }
    +              break;
    +            }
    +          }
    +        } else {
    +          build_needs_repartition = true;
    +
    +          switch (probe_partition_scheme_header.getPartitionType()) {
    +            case PartitionSchemeHeader::PartitionType::kRange:
    +              probe_needs_repartition = true;
    +              break;
    +            case PartitionSchemeHeader::PartitionType::kHash: {
    +              const attribute_id probe_partition_attr = 
probe_partition_scheme_header.getPartitionAttributeId();
    +              if (find(probe_attribute_ids.begin(), 
probe_attribute_ids.end(), probe_partition_attr) !=
    +                      probe_attribute_ids.end()) {
    +                needs_swap = true;
    +              } else {
    +                probe_needs_repartition = true;
    +              }
    +              break;
    +            }
    +          }
    +        }
    +        break;
    +      }
    +    }
    --- End diff --
    
    I would highly recommend two things for the switch statement:
    1. Add several comments in between to describe what's happening. I felt 
lost while reading it.
    2. Moving the switch statement to a separate method.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to