Search in sources :

Example 1 with PredicateQueryItem

use of com.yahoo.prelude.query.PredicateQueryItem in project vespa by vespa-engine.

the class PredicateQueryItemTestCase method requireThatItemConstantsAreSet.

@Test
public void requireThatItemConstantsAreSet() {
    PredicateQueryItem item = new PredicateQueryItem();
    assertEquals(Item.ItemType.PREDICATE_QUERY, item.getItemType());
    assertEquals("PREDICATE_QUERY_ITEM", item.getName());
    assertEquals(1, item.getTermCount());
    assertEquals("predicate", item.getIndexName());
    item.setIndexName("foobar");
    assertEquals("foobar", item.getIndexName());
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Test(org.junit.Test)

Example 2 with PredicateQueryItem

use of com.yahoo.prelude.query.PredicateQueryItem in project vespa by vespa-engine.

the class PredicateQueryItemTestCase method requireThatToStringWorks.

@Test
public void requireThatToStringWorks() {
    PredicateQueryItem item = new PredicateQueryItem();
    assertEquals("PREDICATE_QUERY_ITEM ", item.toString());
    item.addFeature("foo", "bar");
    item.addFeature("foo", "baz", 0xffffL);
    assertEquals("PREDICATE_QUERY_ITEM foo=bar, foo=baz[0xffff]", item.toString());
    item.addRangeFeature("foo", 23);
    item.addRangeFeature("foo", 34, 0xfffffffffffffffeL);
    assertEquals("PREDICATE_QUERY_ITEM foo=bar, foo=baz[0xffff], foo:23, foo:34[0xfffffffffffffffe]", item.toString());
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Test(org.junit.Test)

Example 3 with PredicateQueryItem

use of com.yahoo.prelude.query.PredicateQueryItem in project vespa by vespa-engine.

the class PredicateQueryItemTestCase method requireThatPredicateQueryItemWithManyAttributesCanBeEncoded.

@Test
public void requireThatPredicateQueryItemWithManyAttributesCanBeEncoded() {
    PredicateQueryItem item = new PredicateQueryItem();
    assertEquals("PREDICATE_QUERY_ITEM ", item.toString());
    for (int i = 0; i < 200; ++i) {
        item.addFeature("foo", "bar");
    }
    ByteBuffer buffer = ByteBuffer.allocate(10000);
    item.encode(buffer);
    buffer.flip();
    byte[] actual = new byte[buffer.remaining()];
    buffer.get(actual);
    byte[] expectedPrefix = new byte[] { // PREDICATE_QUERY code 23
    23, 9, 'p', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', // 200 features (0x80c8 => 0xc8 == 200)
    (byte) 0x80, // 200 features (0x80c8 => 0xc8 == 200)
    (byte) 0xc8, // key, value, subquery
    3, // key, value, subquery
    'f', // key, value, subquery
    'o', // key, value, subquery
    'o', // key, value, subquery
    3, // key, value, subquery
    'b', // key, value, subquery
    'a', // key, value, subquery
    'r', // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    3, // key, value, subquery
    'f', // key, value, subquery
    'o', // key, value, subquery
    'o', // key, value, subquery
    3, // key, value, subquery
    'b', // key, value, subquery
    'a', // key, value, subquery
    'r', // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    3, // key, value, subquery
    'f', // key, value, subquery
    'o', // key, value, subquery
    'o', // key, value, subquery
    3, // key, value, subquery
    'b', // key, value, subquery
    'a', // key, value, subquery
    'r', // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1 };
    // ...
    assertArrayEquals(expectedPrefix, Arrays.copyOfRange(actual, 0, expectedPrefix.length));
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with PredicateQueryItem

use of com.yahoo.prelude.query.PredicateQueryItem in project vespa by vespa-engine.

the class PredicateQueryItemTestCase method requireThatRangeFeaturesCanBeAdded.

@Test
public void requireThatRangeFeaturesCanBeAdded() {
    PredicateQueryItem item = new PredicateQueryItem();
    assertEquals(0, item.getRangeFeatures().size());
    item.addRangeFeature("foo", 23);
    item.addRangeFeature("foo", 34, 0x12345678L);
    item.addRangeFeature(new PredicateQueryItem.RangeEntry("qux", 43));
    item.addRangeFeature(new PredicateQueryItem.RangeEntry("corge", 54, 0xf00ba));
    assertEquals(4, item.getRangeFeatures().size());
    Iterator<PredicateQueryItem.RangeEntry> it = item.getRangeFeatures().iterator();
    assertEquals(-1, it.next().getSubQueryBitmap());
    assertEquals(0x12345678L, it.next().getSubQueryBitmap());
    assertEquals(-1, it.next().getSubQueryBitmap());
    assertEquals(0xf00baL, it.next().getSubQueryBitmap());
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) Test(org.junit.Test)

Example 5 with PredicateQueryItem

use of com.yahoo.prelude.query.PredicateQueryItem in project vespa by vespa-engine.

the class PredicateQueryItemTestCase method requireThatPredicateQueryItemCanBeEncoded.

@Test
public void requireThatPredicateQueryItemCanBeEncoded() {
    PredicateQueryItem item = new PredicateQueryItem();
    assertEquals("PREDICATE_QUERY_ITEM ", item.toString());
    item.addFeature("foo", "bar");
    item.addFeature("foo", "baz", 0xffffL);
    ByteBuffer buffer = ByteBuffer.allocate(1000);
    item.encode(buffer);
    buffer.flip();
    byte[] actual = new byte[buffer.remaining()];
    buffer.get(actual);
    assertArrayEquals(new byte[] { // PREDICATE_QUERY code 23
    23, 9, 'p', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', // 2 features
    2, // key, value, subquery
    3, // key, value, subquery
    'f', // key, value, subquery
    'o', // key, value, subquery
    'o', // key, value, subquery
    3, // key, value, subquery
    'b', // key, value, subquery
    'a', // key, value, subquery
    'r', // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    3, // key, value, subquery
    'f', // key, value, subquery
    'o', // key, value, subquery
    'o', // key, value, subquery
    3, // key, value, subquery
    'b', // key, value, subquery
    'a', // key, value, subquery
    'z', // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    -1, // key, value, subquery
    -1, // no range features
    0 }, actual);
    item.addRangeFeature("foo", 23);
    item.addRangeFeature("foo", 34, 0xfffffffffffffffeL);
    buffer.clear();
    item.encode(buffer);
    buffer.flip();
    actual = new byte[buffer.remaining()];
    buffer.get(actual);
    assertArrayEquals(new byte[] { // PREDICATE_QUERY code 23
    23, 9, 'p', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', // 2 features
    2, // key, value, subquery
    3, // key, value, subquery
    'f', // key, value, subquery
    'o', // key, value, subquery
    'o', // key, value, subquery
    3, // key, value, subquery
    'b', // key, value, subquery
    'a', // key, value, subquery
    'r', // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    3, // key, value, subquery
    'f', // key, value, subquery
    'o', // key, value, subquery
    'o', // key, value, subquery
    3, // key, value, subquery
    'b', // key, value, subquery
    'a', // key, value, subquery
    'z', // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    -1, // key, value, subquery
    -1, // 2 range features
    2, // key, value, subquery
    3, // key, value, subquery
    'f', // key, value, subquery
    'o', // key, value, subquery
    'o', // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    0, // key, value, subquery
    23, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, // key, value, subquery
    -1, 3, 'f', 'o', 'o', 0, 0, 0, 0, 0, 0, 0, 34, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery
    -2 }, actual);
}
Also used : PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

PredicateQueryItem (com.yahoo.prelude.query.PredicateQueryItem)17 Test (org.junit.Test)12 ByteBuffer (java.nio.ByteBuffer)2 Query (com.yahoo.search.Query)1 Result (com.yahoo.search.Result)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 BigInteger (java.math.BigInteger)1