Skip to content

Commit

Permalink
TEIID-4448 correcting setting the predicate as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Sep 15, 2016
1 parent 016d5c7 commit 26bb1b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.EvaluatableVisitor;
import org.teiid.query.sql.visitor.GroupsUsedByElementsVisitor;
import org.teiid.query.util.CommandContext;
Expand Down Expand Up @@ -123,9 +122,9 @@ public PlanNode execute(PlanNode plan, QueryMetadataInterface metadata, Capabili
* @param tgtMap
* @param joinCriteria
* @param combinedCriteria
* @return true if the copy was successful
* @return number of remaining groups if the copy was successful
*/
private boolean copyCriteria(Criteria crit,
private Integer copyCriteria(Criteria crit,
Map<Expression, Expression> tgtMap,
List<Criteria> joinCriteria,
Set<Criteria> combinedCriteria,
Expand All @@ -140,21 +139,21 @@ private boolean copyCriteria(Criteria crit,
tgtCrit = FrameUtil.convertCriteria(tgtCrit, tgtMap, metadata, true);
} catch (QueryPlannerException err) {
LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, err, "Could not remap target criteria in RuleCopyCriteria"); //$NON-NLS-1$
return false;
return null;
}

if (tgtCrit instanceof IsNullCriteria && ((IsNullCriteria)tgtCrit).isNegated()) {
return false;
return null;
}

int endGroups = GroupsUsedByElementsVisitor.getGroups(tgtCrit).size();

if (checkForGroupReduction) {
if (endGroups >= startGroups) {
return false;
return null;
}
} else if (endGroups > startGroups) {
return false;
return null;
}

boolean isNew = combinedCriteria.add(tgtCrit);
Expand All @@ -173,7 +172,7 @@ private boolean copyCriteria(Criteria crit,
}
}
if (!use) {
return false;
return null;
}
}

Expand All @@ -187,12 +186,12 @@ private boolean copyCriteria(Criteria crit,
((CompareCriteria)tgtCrit).setOptional(true);
}
}
return true;
} else if (checkForGroupReduction) {
return true;
return endGroups;
} else if (checkForGroupReduction && endGroups < 2) {
return endGroups;
}

return false;
return null;
}

/**
Expand Down Expand Up @@ -332,9 +331,11 @@ private boolean createCriteria(boolean copyingJoinCriteria, Collection<Criteria>
while (i.hasNext()) {
Criteria crit = i.next();

if (copyCriteria(crit, srcToTgt, newJoinCrits, combinedCriteria, copyingJoinCriteria, metadata, underAccess)) {
Integer endGroups = copyCriteria(crit, srcToTgt, newJoinCrits, combinedCriteria, copyingJoinCriteria, metadata, underAccess);

if (endGroups != null) {
changedTree = true;
if (copyingJoinCriteria) {
if (copyingJoinCriteria && endGroups < 2) {
if (crit instanceof CompareCriteria) {
CompareCriteria cc = (CompareCriteria)crit;
//don't remove theta criteria, just mark it as optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1452,4 +1452,14 @@ private void helpTestNullDependent(String expressionSQL,
helpProcess(plan, createCommandContext(), dataManager, null);
}

@Test public void testCopyCriteriaMultiway() throws Exception {
String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla, bqt2.smalla, bqt1.smallb where bqt1.smalla.intnum = bqt2.smalla.intnum and cast(bqt1.smalla.stringkey as integer) = coalesce(bqt2.smalla.intkey, bqt1.smallb.intkey) and bqt2.smalla.intkey = 1"; //$NON-NLS-1$

ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.IntKey FROM BQT1.SmallB AS g_0", "SELECT g_0.IntNum AS c_0, g_0.IntKey AS c_1 FROM BQT2.SmallA AS g_0 WHERE g_0.IntKey = 1 ORDER BY c_0", "SELECT g_0.IntNum AS c_0, g_0.StringKey AS c_1, g_0.IntKey AS c_2 FROM BQT1.SmallA AS g_0 ORDER BY c_0"});

RelationalPlan relationalPlan = (RelationalPlan)plan;
JoinNode joinNode = (JoinNode) relationalPlan.getRootNode().getChildren()[0];
assertNotNull(joinNode.getJoinCriteria());
}

}

0 comments on commit 26bb1b5

Please sign in to comment.