use of com.pingcap.tikv.expression.AggregateFunction 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));
}
Aggregations