in tablestore/src/main/java/com/alicloud/openservices/tablestore/core/protocol/ResponseFactory.java [444:530]
public static ComputeSplitsBySizeResponse createComputeSplitsBySizeResponse(ResponseContentWithMeta response,
OtsInternalApi.ComputeSplitPointsBySizeResponse computeSplitPointsBySizeResponse) {
ComputeSplitsBySizeResponse result = new ComputeSplitsBySizeResponse(response.getMeta());
ConsumedCapacity consumedCapacity = new ConsumedCapacity(
OTSProtocolParser.parseCapacityUnit(computeSplitPointsBySizeResponse.getConsumed().getCapacityUnit()));
result.setConsumedCapacity(consumedCapacity);
List<com.alicloud.openservices.tablestore.core.protocol.OtsInternalApi.PrimaryKeySchema> schemaList
= computeSplitPointsBySizeResponse
.getSchemaList();
for (com.alicloud.openservices.tablestore.core.protocol.OtsInternalApi.PrimaryKeySchema pks : schemaList) {
if (pks.hasOption()) {
result.addPrimaryKeySchema(pks.getName(), OTSProtocolParser.toPrimaryKeyType(pks.getType()),
OTSProtocolParser.toPrimaryKeyOption(pks.getOption()));
} else {
result.addPrimaryKeySchema(pks.getName(), OTSProtocolParser.toPrimaryKeyType(pks.getType()));
}
}
List<PrimaryKeyColumn> infStartColumns = new ArrayList<PrimaryKeyColumn>();
List<PrimaryKeyColumn> infEndColumns = new ArrayList<PrimaryKeyColumn>();
for (PrimaryKeySchema pks : result.getPrimaryKeySchema()) {
infEndColumns.add(new PrimaryKeyColumn(pks.getName(), PrimaryKeyValue.INF_MAX));
infStartColumns.add(new PrimaryKeyColumn(pks.getName(), PrimaryKeyValue.INF_MIN));
}
PrimaryKey infStart = new PrimaryKey(infStartColumns);
PrimaryKey infEnd = new PrimaryKey(infEndColumns);
PrimaryKey lastStartPoint = infStart;
for (int iter = 0; iter < computeSplitPointsBySizeResponse.getSplitPointsCount(); ++iter) {
Split split = new Split();
split.setLowerBound(lastStartPoint);
Row row = null;
try {
ByteString bss = computeSplitPointsBySizeResponse.getSplitPoints(iter);
PlainBufferCodedInputStream inputStream = new PlainBufferCodedInputStream(
new PlainBufferInputStream(bss.asReadOnlyByteBuffer()));
List<PlainBufferRow> rows = inputStream.readRowsWithHeader();
if (rows.size() <= 0) {
throw new ClientException("The parsed response rows' length is zero.");
}
row = PlainBufferConversion.toRow(rows.get(0));
} catch (Exception e) {
throw new ClientException("Failed to parse row data.", e);
}
PrimaryKey primaryKeys = row.getPrimaryKey();
List<PrimaryKeyColumn> pkcl = new ArrayList<PrimaryKeyColumn>();
for (PrimaryKeyColumn pkcc : primaryKeys.getPrimaryKeyColumns()) {
pkcl.add(pkcc);
}
for (int loc = pkcl.size(); loc < result.getPrimaryKeySchema().size(); ++loc) {
pkcl.add(new PrimaryKeyColumn(result.getPrimaryKeySchema().get(loc).getName(),
PrimaryKeyValue.INF_MIN));
}
primaryKeys = new PrimaryKey(pkcl);
split.setUpperBound(primaryKeys);
lastStartPoint = primaryKeys;
result.addSplit(split);
}
// To insert the last split element.
Split split = new Split();
split.setLowerBound(lastStartPoint);
split.setUpperBound(infEnd);
result.addSplit(split);
int splitPointIter = 0;
for (SplitLocation sl : computeSplitPointsBySizeResponse.getLocationsList()) {
for (long sli = 0; sli < sl.getRepeat(); ++sli) {
if (splitPointIter >= result.getSplits().size()) {
throw new ClientException(
"The location list's length is not correct. Location list size: " + splitPointIter
+ ". Split list size: " + result.getSplits().size());
}
result.getSplits().get(splitPointIter).setLocation(sl.getLocation());
++splitPointIter;
}
}
if (splitPointIter != result.getSplits().size()) {
throw new ClientException("The location list's length is not correct. Location list size: " + splitPointIter
+ ". Split list size: " + result.getSplits().size());
}
return result;
}