Ejemplo n.º 1
0
  /**
   * Check whether a join is valid. Invalid joins are CROSS JOIN, FULL OUTER JOIN, any join without
   * criteria, any join with no equality criteria, and any outer join that has the outer side not
   * the same as the dependent.
   *
   * @param joinNode The join node to check
   * @param sourceNode The access node being considered
   * @param analysisRecord TODO
   * @return True if valid for making dependent
   * @throws TeiidComponentException
   * @throws QueryMetadataException
   */
  boolean isValidJoin(PlanNode joinNode, PlanNode sourceNode, AnalysisRecord analysisRecord)
      throws QueryMetadataException, TeiidComponentException {
    JoinType jtype = (JoinType) joinNode.getProperty(NodeConstants.Info.JOIN_TYPE);

    // Check that join is not a CROSS join or FULL OUTER join
    if (jtype.equals(JoinType.JOIN_CROSS) || jtype.equals(JoinType.JOIN_FULL_OUTER)) {
      sourceNode.recordDebugAnnotation(
          "parent join is CROSS or FULL OUTER",
          null,
          "Rejecting dependent join",
          analysisRecord,
          null); //$NON-NLS-1$ //$NON-NLS-2$
      return false;
    }

    if (!joinNode.getExportedCorrelatedReferences().isEmpty()) {
      sourceNode.recordDebugAnnotation(
          "parent join has a correlated nested table",
          null,
          "Rejecting dependent join",
          analysisRecord,
          null); //$NON-NLS-1$ //$NON-NLS-2$
      return false;
    }

    // Check that join criteria exist
    List jcrit = (List) joinNode.getProperty(NodeConstants.Info.JOIN_CRITERIA);
    if (jcrit == null || jcrit.size() == 0) {
      sourceNode.recordDebugAnnotation(
          "parent join has has no join criteria",
          null,
          "Rejecting dependent join",
          analysisRecord,
          null); //$NON-NLS-1$ //$NON-NLS-2$
      return false;
    }

    if (joinNode.getProperty(NodeConstants.Info.LEFT_EXPRESSIONS) == null) {
      sourceNode.recordDebugAnnotation(
          "parent join has no equa-join predicates",
          null,
          "Rejecting dependent join",
          analysisRecord,
          null); //$NON-NLS-1$ //$NON-NLS-2$
      return false;
    }

    // Check that for a left or right outer join the dependent side must be the inner
    if (jtype.isOuter() && JoinUtil.getInnerSideJoinNodes(joinNode)[0] != sourceNode) {
      sourceNode.recordDebugAnnotation(
          "node is on outer side of the join",
          null,
          "Rejecting dependent join",
          analysisRecord,
          null); //$NON-NLS-1$ //$NON-NLS-2$
      return false;
    }

    return true;
  }