use of com.pingcap.tikv.expression.ColumnRef in project tispark by pingcap.
the class TiDAGRequestTest method selectRequestEquals.
private static boolean selectRequestEquals(TiDAGRequest lhs, TiDAGRequest rhs) {
assertEquals(lhs.getFields().size(), rhs.getFields().size());
Map<String, Integer> lhsMap = new HashMap<>();
Map<String, Integer> rhsMap = new HashMap<>();
for (int i = 0; i < lhs.getFields().size(); i++) {
ColumnRef lCol = lhs.getFields().get(i);
ColumnRef rCol = rhs.getFields().get(i);
lhsMap.put(lCol.getName(), i);
rhsMap.put(rCol.getName(), i);
}
for (int i = 0; i < lhs.getFields().size(); i++) {
Expression lhsExpr = lhs.getFields().get(i);
Expression rhsExpr = rhs.getFields().get(i);
Expr lhsExprProto = ProtoConverter.toProto(lhsExpr, lhsMap);
Expr rhsExprProto = ProtoConverter.toProto(rhsExpr, rhsMap);
if (!lhsExprProto.equals(rhsExprProto))
return false;
}
assertEquals(lhs.getAggregates().size(), rhs.getAggregates().size());
for (int i = 0; i < lhs.getAggregates().size(); i++) {
Expression lhsExpr = lhs.getAggregates().get(i);
Expression rhsExpr = rhs.getAggregates().get(i);
Expr lhsExprProto = ProtoConverter.toProto(lhsExpr, lhsMap);
Expr rhsExprProto = ProtoConverter.toProto(rhsExpr, rhsMap);
if (!lhsExprProto.equals(rhsExprProto))
return false;
}
assertEquals(lhs.getGroupByItems().size(), rhs.getGroupByItems().size());
for (int i = 0; i < lhs.getGroupByItems().size(); i++) {
ByItem lhsItem = lhs.getGroupByItems().get(i);
ByItem rhsItem = rhs.getGroupByItems().get(i);
if (!lhsItem.toProto(lhsMap).equals(rhsItem.toProto(rhsMap)))
return false;
}
assertEquals(lhs.getOrderByItems().size(), rhs.getOrderByItems().size());
for (int i = 0; i < lhs.getOrderByItems().size(); i++) {
ByItem lhsItem = lhs.getOrderByItems().get(i);
ByItem rhsItem = rhs.getOrderByItems().get(i);
if (!lhsItem.toProto(lhsMap).equals(rhsItem.toProto(rhsMap)))
return false;
}
assertEquals(lhs.getRangesMaps().size(), rhs.getRangesMaps().size());
assertEquals(lhs.getRangesMaps(), rhs.getRangesMaps());
assertEquals(lhs.getFilters().size(), rhs.getFilters().size());
for (int i = 0; i < lhs.getFilters().size(); i++) {
Expression lhsItem = lhs.getFilters().get(i);
Expression rhsItem = rhs.getFilters().get(i);
Expr lhsExprProto = ProtoConverter.toProto(lhsItem);
Expr rhsExprProto = ProtoConverter.toProto(rhsItem);
if (!lhsExprProto.equals(rhsExprProto))
return false;
}
assertEquals(lhs.getTableInfo().toProto(), rhs.getTableInfo().toProto());
assertEquals(lhs.getLimit(), rhs.getLimit());
assertEquals(lhs.isDistinct(), rhs.isDistinct());
assertEquals(lhs.getIndexInfo().toProto(lhs.getTableInfo()), rhs.getIndexInfo().toProto(rhs.getTableInfo()));
assertEquals(lhs.getStartTs(), rhs.getStartTs());
assertEquals(lhs.getTimeZoneOffset(), rhs.getTimeZoneOffset());
assertEquals(lhs.getFlags(), rhs.getFlags());
return true;
}
Aggregations