Search in sources :

Example 1 with Not

use of com.pingcap.tikv.expression.Not in project tispark by pingcap.

the class PartAndFilterExprRewriterTest method TestRewrite.

@Test
public void TestRewrite() {
    Expression col = ColumnRef.create("y", DateType.DATE);
    Expression col2 = ColumnRef.create("a", IntegerType.INT);
    Expression partExpr = new FuncCallExpr(col, Type.YEAR);
    DateTime date = DateTime.parse("1995-10-10");
    // rewrite right hand side's constant. Apply year to it.
    Expression exprToBeRewrited = LogicalBinaryExpression.or(ComparisonBinaryExpression.equal(col, Constant.create(date, DateType.DATE)), ComparisonBinaryExpression.greaterEqual(col2, Constant.create(5, IntegerType.INT)));
    PartAndFilterExprRewriter expressionRewriter = new PartAndFilterExprRewriter(partExpr);
    Expression rewrote = expressionRewriter.rewrite(exprToBeRewrited);
    assertEquals("[[y@DATE EQUAL 1995] OR [a@LONG GREATER_EQUAL 5]]", rewrote.toString());
    // not support case
    partExpr = new Not(col);
    exprToBeRewrited = ComparisonBinaryExpression.equal(col, Constant.create("1995-10-10"));
    expressionRewriter = new PartAndFilterExprRewriter(partExpr);
    rewrote = expressionRewriter.rewrite(exprToBeRewrited);
    assertNull(rewrote);
    assertTrue(expressionRewriter.isUnsupportedPartFnFound());
    // rewrite left hand. Rewrite year(y) to y.
    Expression year = new FuncCallExpr(col, Type.YEAR);
    exprToBeRewrited = ComparisonBinaryExpression.lessEqual(year, Constant.create("1995", IntegerType.INT));
    rewrote = expressionRewriter.rewrite(exprToBeRewrited);
    assertEquals("[y@DATE LESS_EQUAL \"1995\"]", rewrote.toString());
    // simple column case. No rewriting happens.
    exprToBeRewrited = ComparisonBinaryExpression.lessEqual(col, Constant.create(1, IntegerType.INT));
    expressionRewriter = new PartAndFilterExprRewriter(col);
    rewrote = expressionRewriter.rewrite(exprToBeRewrited);
    assertEquals("[y@DATE LESS_EQUAL 1]", rewrote.toString());
}
Also used : Not(com.pingcap.tikv.expression.Not) Expression(com.pingcap.tikv.expression.Expression) ComparisonBinaryExpression(com.pingcap.tikv.expression.ComparisonBinaryExpression) LogicalBinaryExpression(com.pingcap.tikv.expression.LogicalBinaryExpression) DateTime(org.joda.time.DateTime) FuncCallExpr(com.pingcap.tikv.expression.FuncCallExpr) Test(org.junit.Test)

Aggregations

ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)1 Expression (com.pingcap.tikv.expression.Expression)1 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)1 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)1 Not (com.pingcap.tikv.expression.Not)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1