Search in sources :

Example 6 with Constant

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

the class PredicateUtilsTest method extractColumnRefFromExpressionTest.

@Test
public void extractColumnRefFromExpressionTest() {
    TiTableInfo table = createTable();
    Constant c1 = Constant.create(1, IntegerType.INT);
    Constant c2 = Constant.create(2, IntegerType.INT);
    ColumnRef col1 = ColumnRef.create("c1", table);
    ColumnRef col2 = ColumnRef.create("c2", table);
    ColumnRef col3 = ColumnRef.create("c3", table);
    ColumnRef col4 = ColumnRef.create("c4", table);
    ColumnRef col5 = ColumnRef.create("c5", table);
    Set<ColumnRef> baseline = ImmutableSet.of(col1, col2, col3, col4, col5);
    Expression expression = and(c1, and(c2, and(col1, and(divide(col4, and(plus(col1, c1), minus(col2, col5))), col3))));
    Set<ColumnRef> columns = PredicateUtils.extractColumnRefFromExpression(expression);
    assertEquals(baseline, columns);
}
Also used : Expression(com.pingcap.tikv.expression.Expression) Constant(com.pingcap.tikv.expression.Constant) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) ColumnRef(com.pingcap.tikv.expression.ColumnRef) Test(org.junit.Test)

Example 7 with Constant

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

the class TiDAGRequestTest method testSerializable.

@Test
public void testSerializable() throws Exception {
    TiTableInfo table = createTable();
    TiDAGRequest selReq = new TiDAGRequest(TiDAGRequest.PushDownType.NORMAL);
    Constant c1 = Constant.create(1L, IntegerType.BIGINT);
    Constant c2 = Constant.create(2L, IntegerType.BIGINT);
    ColumnRef col1 = ColumnRef.create("c1", table);
    ColumnRef col2 = ColumnRef.create("c2", table);
    ColumnRef col3 = ColumnRef.create("c3", table);
    AggregateFunction sum = AggregateFunction.newCall(FunctionType.Sum, col1, col1.getDataType());
    AggregateFunction min = AggregateFunction.newCall(FunctionType.Min, col1, col1.getDataType());
    selReq.addRequiredColumn(col1).addRequiredColumn(col2).addRequiredColumn(col3).addAggregate(sum).addAggregate(min).addFilters(ImmutableList.of(plus(c1, c2))).addGroupByItem(ByItem.create(ColumnRef.create("c2", table), true)).addOrderByItem(ByItem.create(ColumnRef.create("c3", table), false)).setTableInfo(table).setStartTs(new TiTimestamp(0, 666)).setTruncateMode(TiDAGRequest.TruncateMode.IgnoreTruncation).setDistinct(true).setIndexInfo(table.getIndices().get(0)).setHaving(lessEqual(col3, c2)).setLimit(100).addRanges(ImmutableMap.of(table.getId(), ImmutableList.of(Coprocessor.KeyRange.newBuilder().setStart(ByteString.copyFromUtf8("startkey")).setEnd(ByteString.copyFromUtf8("endkey")).build())));
    ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(byteOutStream);
    oos.writeObject(selReq);
    ByteArrayInputStream byteInStream = new ByteArrayInputStream(byteOutStream.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(byteInStream);
    TiDAGRequest derselReq = (TiDAGRequest) ois.readObject();
    assertTrue(selectRequestEquals(selReq, derselReq));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Constant(com.pingcap.tikv.expression.Constant) AggregateFunction(com.pingcap.tikv.expression.AggregateFunction) ColumnRef(com.pingcap.tikv.expression.ColumnRef) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

Constant (com.pingcap.tikv.expression.Constant)7 Expression (com.pingcap.tikv.expression.Expression)6 Test (org.junit.Test)6 ColumnRef (com.pingcap.tikv.expression.ColumnRef)5 TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)4 IndexMatcher (com.pingcap.tikv.expression.visitor.IndexMatcher)2 TiIndexColumn (com.pingcap.tikv.meta.TiIndexColumn)2 TiIndexInfo (com.pingcap.tikv.meta.TiIndexInfo)2 Range (com.google.common.collect.Range)1 AggregateFunction (com.pingcap.tikv.expression.AggregateFunction)1 ComparisonBinaryExpression (com.pingcap.tikv.expression.ComparisonBinaryExpression)1 NormalizedPredicate (com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate)1 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)1 LogicalBinaryExpression (com.pingcap.tikv.expression.LogicalBinaryExpression)1 CompoundKey (com.pingcap.tikv.key.CompoundKey)1 Key (com.pingcap.tikv.key.Key)1 TypedKey (com.pingcap.tikv.key.TypedKey)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1