throws ServiceException {
queryResultProtos.clear();
nameDataTypePairs.clear();
ScanAction action = plan.getAction();
List<ColumnStruct> columnStructs = action.getNotIndexConditionColumns();
AggregateInfo info = plan.getQueryInfo().getAggregateInfo();
Scan scan = new Scan();
scan.addColumn(Bytes.toBytes(info.getField().getFamily()),
Bytes.toBytes(info.getField().getName()));
for (ColumnStruct col : columnStructs) {
if(info.getField().getFamily().equals(col.getFamilyName())
&& info.getField().getName().equals(col.getColumnName())) {
continue;
}
scan.addColumn(Bytes.toBytes(col.getFamilyName()),
Bytes.toBytes(col.getColumnName()));
}
FilterList filters = new FilterList();
// Filter columnNotNullFilter = new SingleColumnValueFilter(
// Bytes.toBytes(info.getField().getFamily()),
// Bytes.toBytes(info.getField().getName()),
// CompareFilter.CompareOp.NOT_EQUAL,
// HConstants.EMPTY_BYTE_ARRAY
// );
for (ColumnStruct columnStruct : columnStructs) {
SingleColumnValueFilter filter = new SingleColumnValueFilter(
Bytes.toBytes(columnStruct.getFamilyName()),
Bytes.toBytes(columnStruct.getColumnName()),
ParserUtils.convertIntValueToCompareOp(columnStruct.getCompareOp()),
columnStruct.getValue());
filters.addFilter(filter);
}
scan.setFilter(filters);
String tableName = StorageTableNameBuilder.buildEntityTableName(plan.getTableDesc().getTableName());
AggregateType type = info.getAggregateType();
byte[] value = null;
DataType resultDataType = DataType.STRING;
try {
switch (type) {
case COUNT: {
long count = aggregationClient.count(Bytes.toBytes(tableName),
null, scan);
value = Bytes.toBytes(count);
resultDataType = DataType.INT64;
break;
}
case SUM: {
value = getSumValue(tableName, info.getField(), scan);
resultDataType = info.getField().getType();
break;
}
}
} catch (Throwable throwable) {
throw new ServiceException(throwable);
}
ClientProtos.QueryResultProto.Builder builder = ClientProtos.QueryResultProto.newBuilder();
builder.addResult(ProtobufUtil.toStringBytesPair(new KeyValue(Bytes.toBytes(type.getMethodName()),
Bytes.toBytes(info.getField().getFamily()), Bytes.toBytes(type.getMethodName()), value)));
queryResultProtos.add(builder.build());
MetaProtos.DataTypeProtos dataTypeProtos = DataType.convertDataTypeToDataTypeProtos(resultDataType) ;
ClientProtos.StringDataTypePair.Builder stringDataTypePairBuilder = ClientProtos.StringDataTypePair
.newBuilder();