}
@Override
public ResultInterface query(int limit, ResultTarget target) {
boolean addRowToResultTarget = true;
ResultInterface result;
if (isExecuteDirec()) {
result = super.query(limit, target);
addRowToResultTarget = false;
} else if (localRegionNames != null && localRegionNames.length != 0) {
if (localRegionNames.length == 1) {
whereClauseSupport.setRegionName(localRegionNames[0]);
result = super.query(limit, target);
addRowToResultTarget = false;
} else {
sqlRoutingInfo = new SQLRoutingInfo();
sqlRoutingInfo.localRegions = Arrays.asList(localRegionNames);
result = CommandParallel.executeQuery(session, sqlRoutingInfo, this, limit, false);
}
} else {
try {
sqlRoutingInfo = HBaseUtils.getSQLRoutingInfo((HBaseSession) session, whereClauseSupport, this);
} catch (Exception e) {
throw DbException.convert(e);
}
if (sqlRoutingInfo.localRegion != null) {
whereClauseSupport.setRegionName(sqlRoutingInfo.localRegion);
result = super.query(limit, target);
addRowToResultTarget = false;
} else if (sqlRoutingInfo.remoteCommand != null) {
result = sqlRoutingInfo.remoteCommand.executeQuery(limit, false);
} else {
result = CommandParallel.executeQuery(session, sqlRoutingInfo, this, limit, false);
}
}
if (addRowToResultTarget && target != null) {
while (result.next()) {
target.addRow(result.currentRow());
}
result.reset();
}
return result;
}