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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations