IGNITE-28526 Fix flaky RexSimplificationPlannerTest.testExtractCommonDisjunctionPart#13011
Open
zstan wants to merge 1 commit intoapache:masterfrom
Open
IGNITE-28526 Fix flaky RexSimplificationPlannerTest.testExtractCommonDisjunctionPart#13011zstan wants to merge 1 commit intoapache:masterfrom
zstan wants to merge 1 commit intoapache:masterfrom
Conversation
|
| boolean firstCall = true; | ||
|
|
||
| @Override public RexNode visitCall(RexCall call) { | ||
| if (firstCall) { |
Contributor
There was a problem hiding this comment.
If we check only first call, why do we need RexShuttle at all?
It can be implemented much simplier by checking only root operator and operands.
But It still will be too specialized and seems that can be used only by one test.
Instead I propose to implement something like condition normalizator (I think it will be useful in future for other tests), it can be implemented for example this way:
private static RexNode normalizeCondition(RexBuilder rexBuilder, RexNode condition) {
return new RexShuttle() {
@Override public RexNode visitCall(RexCall call) {
Pair<SqlOperator, List<RexNode>> normalized = RexNormalize.normalize(call.getOperator(), call.getOperands());
return rexBuilder.makeCall(normalized.getKey(), normalized.getValue());
}
}.apply(condition);
}
And to check condition we can do something like:
protected <T extends RelNode> Predicate<ProjectableFilterableTableScan> satisfyCondition(String condition) {
return node -> {
String normCond = normalizeCondition(node.getCluster().getRexBuilder(), node.condition()).toString();
if (!condition.equals(normCond)) {
lastErrorMsg = "Unexpected condition [expected=" + condition + ", actual=" + normCond + ']';
return false;
}
return true;
};
}
In this case we can check normalized condition like:
.and(satisfyCondition("AND(=($t0, 0), =($t1, 0), SEARCH($t2, Sarg[0, 1, 2]))")));
Contributor
Author
There was a problem hiding this comment.
but ... it doesn`t work as expected (
RexBuilder builder = node.getCluster().getRexBuilder();
RexLiteral l0 = builder.makeExactLiteral(new BigDecimal(0));
RexLocalRef lr0 = new RexLocalRef(0, node.getCluster().getTypeFactory().createJavaType(long.class));
RexLiteral l1 = builder.makeExactLiteral(new BigDecimal(0));
RexLocalRef lr1 = new RexLocalRef(1, node.getCluster().getTypeFactory().createJavaType(long.class));
final RangeSet<Integer> setNone = ImmutableRangeSet.of();
final RangeSet<Integer> setAll = setNone.complement();
final Sarg<Integer> sarg =
Sarg.of(RexUnknownAs.FALSE, setAll);
RexNode intLiteral =
builder.makeLiteral(1, node.getCluster().getTypeFactory().createSqlType(SqlTypeName.INTEGER));
RexNode rexNode =
builder.makeCall(SqlStdOperatorTable.SEARCH, intLiteral,
builder.makeSearchArgumentLiteral(sarg, intLiteral.getType()));
RexLocalRef lr2 = new RexLocalRef(2, node.getCluster().getTypeFactory().createJavaType(long.class));
RexNode r0 = builder.makeCall(SqlStdOperatorTable.EQUALS, lr0, l0);
RexNode r1 = builder.makeCall(SqlStdOperatorTable.EQUALS, lr1, l1);
RexNode r3 = builder.makeCall(SqlStdOperatorTable.EQUALS, lr2, rexNode);
RexNode res = builder.makeCall(SqlStdOperatorTable.AND, r1, r0, r3);
String norm = normalizeExpression(node.getCluster().getRexBuilder(), res).toString();
System.err.println("node >>: " + res);
System.err.println("norm >>: " + norm);
returns:
node >>: AND(=($t1, 0), =($t0, 0), =($t2, SEARCH(1, Sarg[IS NOT NULL])))
norm >>: AND(=($t1, 0), =($t0, 0), =($t2, SEARCH(1, Sarg[IS NOT NULL])))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



plan from failed logs:
plan from common master branch run:
here we can see that conditions are different: filters=[AND(=($t1, 0), =($t0, 0) vs filters=[AND(=($t0, 0), =($t1, 0)