Search in sources :

Example 16 with Grouping

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);
}
Also used : Utf8String(com.yahoo.text.Utf8String) BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Grouping(com.yahoo.searchlib.aggregation.Grouping)

Example 17 with Grouping

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;
}
Also used : ArrayList(java.util.ArrayList) Grouping(com.yahoo.searchlib.aggregation.Grouping)

Example 18 with Grouping

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);
            }
        }
    }
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Grouping(com.yahoo.searchlib.aggregation.Grouping)

Example 19 with Grouping

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);
}
Also used : Grouping(com.yahoo.searchlib.aggregation.Grouping)

Example 20 with Grouping

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);
    }
}
Also used : Query(com.yahoo.search.Query) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) Grouping(com.yahoo.searchlib.aggregation.Grouping) Test(org.junit.Test)

Aggregations

Grouping (com.yahoo.searchlib.aggregation.Grouping)24 Query (com.yahoo.search.Query)12 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)12 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)11 Test (org.junit.Test)11 Group (com.yahoo.search.grouping.result.Group)9 StringResultNode (com.yahoo.searchlib.expression.StringResultNode)9 Result (com.yahoo.search.Result)8 Execution (com.yahoo.search.searchchain.Execution)8 HitsAggregationResult (com.yahoo.searchlib.aggregation.HitsAggregationResult)7 MaxAggregationResult (com.yahoo.searchlib.aggregation.MaxAggregationResult)7 MinAggregationResult (com.yahoo.searchlib.aggregation.MinAggregationResult)6 FastHit (com.yahoo.prelude.fastsearch.FastHit)5 Hit (com.yahoo.search.result.Hit)5 CountAggregationResult (com.yahoo.searchlib.aggregation.CountAggregationResult)5 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)4 GroupList (com.yahoo.search.grouping.result.GroupList)4 BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)4 DocumentId (com.yahoo.document.DocumentId)2 GlobalId (com.yahoo.document.GlobalId)2