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