Search in sources :

Example 1 with LtPredicate

use of com.blazebit.persistence.parser.predicate.LtPredicate in project blaze-persistence by Blazebit.

the class GeneralParserTest method testNot1.

@Test
public void testNot1() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN NOT(x.a = y.a) OR c.a < 9 AND b - c = 2 THEN 0 ELSE 1 END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new EqPredicate(path("x", "a"), path("y", "a"), true), new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, new LtPredicate(path("c", "a"), _int("9")), new EqPredicate(subtract(path("b"), path("c")), _int("2")))), _int("0"))), _int("1"));
    assertEquals(expected, result);
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Test(org.junit.Test)

Example 2 with LtPredicate

use of com.blazebit.persistence.parser.predicate.LtPredicate in project blaze-persistence by Blazebit.

the class LogicOptimizationTest method testOptimizeNegationStructure2.

@Test
public void testOptimizeNegationStructure2() {
    Predicate result = parsePredicateOptimized("NOT(NOT(a > b) OR a < x)", false);
    Predicate expected = new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, new GtPredicate(path("a"), path("b")), new LtPredicate(path("a"), path("x"), true));
    assertEquals(expected, result);
}
Also used : GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) Test(org.junit.Test)

Example 3 with LtPredicate

use of com.blazebit.persistence.parser.predicate.LtPredicate in project blaze-persistence by Blazebit.

the class LogicOptimizationTest method testOptimizeNegationStructure3.

@Test
public void testOptimizeNegationStructure3() {
    Predicate result = parsePredicateOptimized("NOT(NOT(a > b) AND a < x)", false);
    Predicate expected = new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new GtPredicate(path("a"), path("b")), new LtPredicate(path("a"), path("x"), true));
    assertEquals(expected, result);
}
Also used : GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) Test(org.junit.Test)

Example 4 with LtPredicate

use of com.blazebit.persistence.parser.predicate.LtPredicate in project blaze-persistence by Blazebit.

the class GeneralParserTest method testNot3.

@Test
public void testNot3() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CaSe WHEN NoT(x.a = y.a OR c.a < 9 and b - c = 2) THeN 0 eLsE 1 ENd");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(not(new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new EqPredicate(path("x", "a"), path("y", "a")), new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, new LtPredicate(path("c", "a"), _int("9")), new EqPredicate(subtract(path("b"), path("c")), _int("2"))))), _int("0"))), _int("1"));
    assertEquals(expected, result);
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Test(org.junit.Test)

Example 5 with LtPredicate

use of com.blazebit.persistence.parser.predicate.LtPredicate in project blaze-persistence by Blazebit.

the class GeneralParserTest method testCaseWhenAndOr.

@Test
public void testCaseWhenAndOr() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN x.a = y.a OR c.a < 9 AND b - c = 2 THEN 0 ELSE 1 END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new EqPredicate(path("x", "a"), path("y", "a")), new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, new LtPredicate(path("c", "a"), _int("9")), new EqPredicate(subtract(path("b"), path("c")), _int("2")))), _int("0"))), _int("1"));
    assertEquals(expected, result);
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Test(org.junit.Test)

Aggregations

CompoundPredicate (com.blazebit.persistence.parser.predicate.CompoundPredicate)6 LtPredicate (com.blazebit.persistence.parser.predicate.LtPredicate)6 Test (org.junit.Test)6 EqPredicate (com.blazebit.persistence.parser.predicate.EqPredicate)4 GtPredicate (com.blazebit.persistence.parser.predicate.GtPredicate)3 Predicate (com.blazebit.persistence.parser.predicate.Predicate)3 BetweenPredicate (com.blazebit.persistence.parser.predicate.BetweenPredicate)1 InPredicate (com.blazebit.persistence.parser.predicate.InPredicate)1 IsNullPredicate (com.blazebit.persistence.parser.predicate.IsNullPredicate)1 LikePredicate (com.blazebit.persistence.parser.predicate.LikePredicate)1 MemberOfPredicate (com.blazebit.persistence.parser.predicate.MemberOfPredicate)1