Skip to content

Commit

Permalink
Add some test
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Nov 26, 2023
1 parent c443db7 commit 000f7f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
/**
* Split the expression to equal, range and residual predicate.
* Should instance when used.
* TODO support complex predicate split
*/
public class PredicatesSplitter {

Expand Down Expand Up @@ -66,6 +67,8 @@ public Void visitComparisonPredicate(ComparisonPredicate comparisonPredicate, Ex
if (leftArgOnlyContainsColumnRef && rightArgOnlyContainsColumnRef) {
equalPredicates.add(comparisonPredicate);
return null;
} else {
residualPredicates.add(comparisonPredicate);
}
} else if ((leftArgOnlyContainsColumnRef && rightArg instanceof Literal)
|| (rightArgOnlyContainsColumnRef && leftArg instanceof Literal)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public Expression visitNamedExpression(NamedExpression namedExpression,

/**
* The Collector for target named expressions
* TODO Collect named expression by targetTypes, tableIdentifiers
*/
public static class NamedExpressionCollector
extends DefaultExpressionVisitor<Void, ExpressionReplaceContext> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public void testSplitPredicates() {
"a = b",
"a > 7 and 10 > d",
"c = d or a = 10");
assetEquals("a = b and c + d = e and a > 7 and 10 > d",
"a = b",
"a > 7 and 10 > d",
"c + d = e");
assetEquals("a = b and c + d = e or a > 7 and 10 > d",
"",
"",
"a = b and c + d = e or a > 7 and 10 > d");
}

private void assetEquals(String expression,
Expand All @@ -67,7 +75,7 @@ private void assetEquals(String expression,
Expression rangeExpression = replaceUnboundSlot(PARSER.parseExpression(expectedRangeExpr), mem);
Assertions.assertEquals(rangeExpression, splitPredicate.getRangePredicate());
} else {
Assertions.assertNull(splitPredicate.getResidualPredicate());
Assertions.assertNull(splitPredicate.getRangePredicate());
}

if (!StringUtils.isEmpty(expectedResidualExpr)) {
Expand Down

0 comments on commit 000f7f7

Please sign in to comment.