use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class QueryPacket method encodeBody.
public void encodeBody(ByteBuffer buffer) {
queryPacketData = new QueryPacketData();
final int relativeZero = buffer.position();
boolean sendSessionKey = query.getGroupingSessionCache() || query.getRanking().getQueryCache();
int featureFlag = getFeatureInt(sendSessionKey);
buffer.putInt(featureFlag);
ignoreableOffset = buffer.position() - relativeZero;
IntegerCompressor.putCompressedPositiveNumber(getOffset(), buffer);
IntegerCompressor.putCompressedPositiveNumber(getHits(), buffer);
// Safety to avoid sending down 0 or negative number
buffer.putInt(Math.max(1, (int) query.getTimeLeft()));
ignoreableSize = buffer.position() - relativeZero - ignoreableOffset;
buffer.putInt(getFlagInt());
int startOfFieldToSave = buffer.position();
Item.putString(query.getRanking().getProfile(), buffer);
queryPacketData.setRankProfile(buffer, startOfFieldToSave);
if ((featureFlag & QF_PROPERTIES) != 0) {
startOfFieldToSave = buffer.position();
query.encodeAsProperties(buffer, true);
queryPacketData.setPropertyMaps(buffer, startOfFieldToSave);
}
if ((featureFlag & QF_SORTSPEC) != 0) {
int sortSpecLengthPosition = buffer.position();
buffer.putInt(0);
int sortSpecLength = query.getRanking().getSorting().encode(buffer);
buffer.putInt(sortSpecLengthPosition, sortSpecLength);
}
if ((featureFlag & QF_GROUPSPEC) != 0) {
List<Grouping> groupingList = GroupingExecutor.getGroupingList(query);
BufferSerializer gbuf = new BufferSerializer(new GrowableByteBuffer());
gbuf.putInt(null, groupingList.size());
for (Grouping g : groupingList) {
g.serialize(gbuf);
}
gbuf.getBuf().flip();
byte[] blob = new byte[gbuf.getBuf().limit()];
gbuf.getBuf().get(blob);
buffer.putInt(blob.length);
buffer.put(blob);
}
sessionOffset = buffer.position() - relativeZero;
if (sendSessionKey) {
Utf8String key = query.getSessionId(true).asUtf8String();
sessionSize = key.getByteLength();
buffer.putInt(key.getByteLength());
buffer.put(key.getBytes());
}
if ((featureFlag & QF_LOCATION) != 0) {
startOfFieldToSave = buffer.position();
int locationLengthPosition = buffer.position();
buffer.putInt(0);
int locationLength = query.getRanking().getLocation().encode(buffer);
buffer.putInt(locationLengthPosition, locationLength);
queryPacketData.setLocation(buffer, startOfFieldToSave);
}
startOfFieldToSave = buffer.position();
int stackItemPosition = buffer.position();
// Number of stack items written below
buffer.putInt(0);
int stackLengthPosition = buffer.position();
buffer.putInt(0);
int stackPosition = buffer.position();
int stackItemCount = query.encode(buffer);
int stackLength = buffer.position() - stackPosition;
buffer.putInt(stackItemPosition, stackItemCount);
buffer.putInt(stackLengthPosition, stackLength);
queryPacketData.setQueryStack(buffer, startOfFieldToSave);
}
use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class GroupingExecutor method getGroupingListForPassN.
/**
* Returns a list of {@link Grouping} objects that are to be used for the given pass.
*
* @param groupingMap The map of all grouping objects.
* @param pass The pass about to be performed.
* @return A list of grouping objects.
*/
private List<Grouping> getGroupingListForPassN(Map<Integer, Grouping> groupingMap, int pass) {
List<Grouping> ret = new ArrayList<>();
for (Grouping grouping : groupingMap.values()) {
if (grouping.useSinglePass()) {
if (pass == 0) {
grouping.setFirstLevel(0);
grouping.setLastLevel(grouping.getLevels().size());
// more levels to go
ret.add(grouping);
}
} else {
if (pass <= grouping.getLevels().size()) {
grouping.setFirstLevel(pass);
grouping.setLastLevel(pass);
// more levels to go
ret.add(grouping);
}
}
}
return ret;
}
use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class VdsVisitor method mergeGroupingMaps.
private void mergeGroupingMaps(Map<Integer, byte[]> newGroupingMap) {
if (log.isLoggable(LogLevel.SPAM)) {
log.log(LogLevel.SPAM, "mergeGroupingMaps: newGroupingMap = " + newGroupingMap);
}
for (Integer key : newGroupingMap.keySet()) {
byte[] value = newGroupingMap.get(key);
Grouping newGrouping = new Grouping();
if (log.isLoggable(LogLevel.SPAM)) {
log.log(LogLevel.SPAM, "Received group with key " + key + " and size " + value.length);
}
BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer(ByteBuffer.wrap(value)));
newGrouping.deserialize(buf);
if (buf.getBuf().hasRemaining()) {
throw new IllegalArgumentException("Failed deserializing grouping. There are still data left. Position = " + buf.position() + ", limit = " + buf.getBuf().limit());
}
synchronized (groupingMap) {
if (groupingMap.containsKey(key)) {
Grouping grouping = groupingMap.get(key);
grouping.merge(newGrouping);
} else {
groupingMap.put(key, newGrouping);
}
}
}
}
use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class VdsVisitor method getGroupings.
@Override
public final List<Grouping> getGroupings() {
Collection<Grouping> groupings = groupingMap.values();
for (Grouping g : groupings) {
g.postMerge();
}
Grouping[] array = groupings.toArray(new Grouping[groupings.size()]);
return Arrays.asList(array);
}
use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatRequestsAreTransformed.
@Test
public void requireThatRequestsAreTransformed() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(max(bar))))"));
try {
newExecution(new GroupingExecutor(), new GroupingListThrower()).search(query);
fail();
} catch (GroupingListException e) {
assertNotNull(e.lst);
assertEquals(1, e.lst.size());
Grouping grp = e.lst.get(0);
assertNotNull(grp);
}
}
Aggregations