Skip to content

Commit

Permalink
saving
Browse files Browse the repository at this point in the history
  • Loading branch information
asolimando committed Jan 21, 2022
1 parent 18f5e9a commit 55cd8d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/apache/calcite/rex/RexSimplify.java
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,7 @@ private void ensureParanoidOff() {
* Modifies the list in place. */
private RexNode simplifyOrs(List<RexNode> terms, RexUnknownAs unknownAs) {
final SargCollector sargCollector = new SargCollector(rexBuilder, false);
simplifyList(terms, unknownAs);
final List<RexNode> newTerms = new ArrayList<>();
terms.forEach(t -> sargCollector.accept(t, newTerms));
if (sargCollector.needToFix()) {
Expand Down
34 changes: 34 additions & 0 deletions core/src/test/java/org/apache/calcite/rex/RexProgramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,40 @@ private void checkExponentialCnf(int n) {
"IS NOT NULL(?0.int0)");
}

@Test void testHPLO() {
checkSimplify(
and(literal(true),
or(eq(vInt(), literal(1)),
eq(vInt(), literal(2)),
eq(vInt(), literal(3))),
or(and(literal(true),
eq(vInt(), literal(1)),
ge(vIntNotNull(), literal(10))),
and(literal(true),
eq(vInt(), literal(2)),
ge(vIntNotNull(), literal(10)))),
and(ge(vIntNotNull(), literal(10)), le(vIntNotNull(), literal(20)))),
"AND(AND(?0.notNullInt0>=10,?0.notNullInt0=<=20),OR(?0.int0=1, ?0.int0=2)");
}

@Test void testHPLO2() {
checkSimplify(
and(or(and(eq(vInt(), literal(1)),
gt(vIntNotNull(), literal(10))),
and(eq(vInt(), literal(2)),
gt(vIntNotNull(), literal(10)))),
and(ge(vIntNotNull(), literal(10)), le(vIntNotNull(), literal(20)))),
"AND(SEARCH(?0.int0, Sarg[1, 2]), SEARCH(?0.notNullInt0, Sarg[[10..20]]))");
}

@Test void testHPLO3() {
checkSimplify(
and(or(eq(vInt(), literal(1)),
eq(vInt(), literal(2))),
and(ge(vIntNotNull(), literal(10)), le(vIntNotNull(), literal(20)))),
"AND(SEARCH(?0.int0, Sarg[1, 2]), SEARCH(?0.notNullInt0, Sarg[[10..20]]))");
}

@Test void testSimplifyUnknown() {
final RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);
final RelDataType rowType = typeFactory.builder()
Expand Down

0 comments on commit 55cd8d2

Please sign in to comment.