Search in sources :

Example 16 with Expression

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

the class SelectivityCalculator method calcPseudoSelectivity.

public static double calcPseudoSelectivity(ScanSpec spec) {
    Optional<Expression> rangePred = spec.getRangePredicate();
    double cost = 100.0;
    if (spec.getPointPredicates() != null) {
        for (Expression expr : spec.getPointPredicates()) {
            cost *= PseudoCostCalculator.calculateCost(expr);
        }
    }
    if (rangePred.isPresent()) {
        cost *= PseudoCostCalculator.calculateCost(rangePred.get());
    }
    return cost;
}
Also used : Expression(com.pingcap.tikv.expression.Expression)

Example 17 with Expression

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

the class AstBuilder method visitBinaryComparisonPredicate.

@Override
public Expression visitBinaryComparisonPredicate(MySqlParser.BinaryComparisonPredicateContext ctx) {
    Expression left = visitChildren(ctx.left);
    Expression right = visitChildren(ctx.right);
    switch(ctx.comparisonOperator().getText()) {
        case "<":
            return ComparisonBinaryExpression.lessThan(left, right);
        case "<=":
            return ComparisonBinaryExpression.lessEqual(left, right);
        case "=":
            return ComparisonBinaryExpression.equal(left, right);
        case ">":
            return ComparisonBinaryExpression.greaterThan(left, right);
        case ">=":
            return ComparisonBinaryExpression.greaterEqual(left, right);
    }
    throw new UnsupportedSyntaxException(ctx.toString() + ": it is not possible reach to this line of code");
}
Also used : UnsupportedSyntaxException(com.pingcap.tikv.exception.UnsupportedSyntaxException) Expression(com.pingcap.tikv.expression.Expression) ArithmeticBinaryExpression(com.pingcap.tikv.expression.ArithmeticBinaryExpression) ComparisonBinaryExpression(com.pingcap.tikv.expression.ComparisonBinaryExpression) LogicalBinaryExpression(com.pingcap.tikv.expression.LogicalBinaryExpression)

Example 18 with Expression

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

the class TiParserTest method TestYearFunction.

@Test
public void TestYearFunction() {
    String sql = "year(purchased)";
    TiParser parser = new TiParser();
    Expression year = parser.parseExpression(sql);
    Assert.assertEquals("year([purchased])", year.toString());
}
Also used : Expression(com.pingcap.tikv.expression.Expression) ArithmeticBinaryExpression(com.pingcap.tikv.expression.ArithmeticBinaryExpression) Test(org.junit.Test)

Example 19 with Expression

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

the class TiParserTest method TestParseWithTableInfo.

@Test
public void TestParseWithTableInfo() {
    TiTableInfo tableInfo = createTaleInfoWithParts();
    TiParser parser = new TiParser(tableInfo);
    Expression expr = parser.parseExpression("`a` < 5");
    Assert.assertEquals(expr.toString(), "[a@LONG LESS_THAN 5]");
}
Also used : Expression(com.pingcap.tikv.expression.Expression) ArithmeticBinaryExpression(com.pingcap.tikv.expression.ArithmeticBinaryExpression) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) Test(org.junit.Test)

Example 20 with Expression

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

the class TiParserTest method TestParseOR.

@Test
public void TestParseOR() {
    String sql = "1.0";
    TiParser parser = new TiParser();
    Expression constant = parser.parseExpression(sql);
    Assert.assertEquals(Constant.create(1.0, RealType.REAL), constant);
    sql = "id < 1 or id >= 3";
    Expression or = parser.parseExpression(sql);
    Assert.assertEquals(or.toString(), "[[[id] LESS_THAN 1] OR [[id] GREATER_EQUAL 3]]");
    sql = "id < 1 xor id >= 3";
    Expression xor = parser.parseExpression(sql);
    Assert.assertEquals(xor.toString(), "[[[id] LESS_THAN 1] XOR [[id] GREATER_EQUAL 3]]");
}
Also used : Expression(com.pingcap.tikv.expression.Expression) ArithmeticBinaryExpression(com.pingcap.tikv.expression.ArithmeticBinaryExpression) Test(org.junit.Test)

Aggregations

Expression (com.pingcap.tikv.expression.Expression)28 Test (org.junit.Test)16 TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)11 ArithmeticBinaryExpression (com.pingcap.tikv.expression.ArithmeticBinaryExpression)10 ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)9 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)9 TiIndexInfo (com.pingcap.tikv.meta.TiIndexInfo)8 ColumnRef (com.pingcap.tikv.expression.ColumnRef)7 Constant (com.pingcap.tikv.expression.Constant)6 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)6 Expr (com.pingcap.tidb.tipb.Expr)5 StringRegExpression (com.pingcap.tikv.expression.StringRegExpression)4 ArrayList (java.util.ArrayList)4 ImmutableList (com.google.common.collect.ImmutableList)3 Range (com.google.common.collect.Range)3 TiExpressionException (com.pingcap.tikv.exception.TiExpressionException)3 TypedKey (com.pingcap.tikv.key.TypedKey)3 List (java.util.List)3 ScalarFuncSig (com.pingcap.tidb.tipb.ScalarFuncSig)2 UnsupportedSyntaxException (com.pingcap.tikv.exception.UnsupportedSyntaxException)2