Search in sources :

Example 1 with GtPredicate

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

the class GeneralParserTest method testComplexCaseWhen.

@Test
public void testComplexCaseWhen() {
    FunctionExpression result = (FunctionExpression) parse("" + "CONCAT(\n" + "    COALESCE(\n" + "        CONCAT(\n" + "            NULLIF(\n" + "                CONCAT(\n" + "                    CASE WHEN LENGTH(COALESCE(zip, '')) > 0 OR LENGTH(COALESCE(city, '')) > 0 THEN COALESCE(CONCAT(NULLIF(street, ''), ', '), '') ELSE COALESCE(street, '') END,\n" + "                    CASE WHEN LENGTH(COALESCE(city, '')) > 0 THEN COALESCE(CONCAT(NULLIF(zip, ''), ' '), '') ELSE COALESCE(zip, '') END,\n" + "                    COALESCE(city, '')\n" + "                ),\n" + "                ''\n" + "            ),\n" + "            ' - '\n" + "        ),\n" + "        ''\n" + "    ),\n" + "    'test'" + ")");
    FunctionExpression expected = function("CONCAT", function("COALESCE", function("CONCAT", function("NULLIF", function("CONCAT", new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new GtPredicate(function("LENGTH", function("COALESCE", path("zip"), _string(""))), _int("0")), new GtPredicate(function("LENGTH", function("COALESCE", path("city"), _string(""))), _int("0"))), function("COALESCE", function("CONCAT", function("NULLIF", path("street"), _string("")), _string(", ")), _string("")))), function("COALESCE", path("street"), _string(""))), new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new GtPredicate(function("LENGTH", function("COALESCE", path("city"), _string(""))), _int("0")), function("COALESCE", function("CONCAT", function("NULLIF", path("zip"), _string("")), _string(" ")), _string("")))), function("COALESCE", path("zip"), _string(""))), function("COALESCE", path("city"), _string(""))), _string("")), _string(" - ")), _string("")), _string("test"));
    assertEquals(expected, result);
}
Also used : GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) Test(org.junit.Test)

Example 2 with GtPredicate

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

the class GeneralParserTest method testDateFunctions.

@Test
public void testDateFunctions() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN a = b THEN CURRENT_DATE WHEN a > b THEN CURRENT_TIME ELSE CURRENT_TIMESTAMP END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new EqPredicate(path("a"), path("b")), function("CURRENT_DATE")), new WhenClauseExpression(new GtPredicate(path("a"), path("b")), function("CURRENT_TIME"))), function("CURRENT_TIMESTAMP"));
    assertEquals(expected, result);
}
Also used : GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Test(org.junit.Test)

Example 3 with GtPredicate

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

the class LogicOptimizationTest method testMaintainNegationStructure.

@Test
public void testMaintainNegationStructure() {
    Predicate result = parsePredicate("NOT(NOT(a > b))", false);
    Predicate expected = wrapNot(not(new GtPredicate(path("a"), path("b"))));
    assertEquals(expected, result);
}
Also used : GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) 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 GtPredicate

use of com.blazebit.persistence.parser.predicate.GtPredicate 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 5 with GtPredicate

use of com.blazebit.persistence.parser.predicate.GtPredicate 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)

Aggregations

GtPredicate (com.blazebit.persistence.parser.predicate.GtPredicate)12 Test (org.junit.Test)12 Predicate (com.blazebit.persistence.parser.predicate.Predicate)8 CompoundPredicate (com.blazebit.persistence.parser.predicate.CompoundPredicate)6 LtPredicate (com.blazebit.persistence.parser.predicate.LtPredicate)5 EqPredicate (com.blazebit.persistence.parser.predicate.EqPredicate)2 Expression (com.blazebit.persistence.parser.expression.Expression)1 GeneralCaseExpression (com.blazebit.persistence.parser.expression.GeneralCaseExpression)1 WhenClauseExpression (com.blazebit.persistence.parser.expression.WhenClauseExpression)1 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