Package org.apache.hadoop.hbase.regionserver.idx.support.sets

Examples of org.apache.hadoop.hbase.regionserver.idx.support.sets.IntSet


    // set up the indices
    byte[] column1 = Bytes.toBytes("column1");
    byte[] qualifier1 = Bytes.toBytes("qualifier1");
    byte[] value1 = Bytes.toBytes("value1");
    IdxIndex index1 = EasyMock.createMock(IdxIndex.class);
    IntSet bitSet1 = new IntSetBuilder().start().addAll(1, 2, 3, 4, 5, 6).finish(100);
    EasyMock.expect(index1.head(value1, true)).andReturn(bitSet1);
    EasyMock.expect(index1.probeToString(value1)).andReturn(Bytes.toString(value1)).anyTimes();
    EasyMock.replay(index1);
    searchContext.indices.put(Pair.of(column1, qualifier1), index1);

    IdxIndex index2 = EasyMock.createMock(IdxIndex.class);
    byte[] column2 = Bytes.toBytes("column2");
    byte[] qualifier2 = Bytes.toBytes("qualifier2");
    byte[] value2 = Bytes.toBytes("value2");
    IntSet bitSet2 = new IntSetBuilder().start().addAll(5, 6, 7, 8, 9, 10).finish(100);
    EasyMock.expect(index2.tail(value2, true)).andReturn(bitSet2);
    EasyMock.expect(index2.probeToString(value2)).andReturn(Bytes.toString(value2)).anyTimes();
    EasyMock.replay(index2);
    searchContext.indices.put(Pair.of(column2, qualifier2), index2);

    // perform the test
    IdxExpressionEvaluator evaluator = new IdxExpressionEvaluator();
    Expression exp = Expression.and(
        Expression.comparison(column1, qualifier1, Comparison.Operator.LTE, value1),
        Expression.comparison(column2, qualifier2, Comparison.Operator.GTE, value2)
    );
    IntSet intSet = evaluator.evaluate(searchContext, exp);

    // assert the evaluator interacted with the indices correctly
    Assert.assertNotNull("The response from the evaluator should not be null", intSet);
    Assert.assertEquals("The resulting IntSet contained the wrong number of results", 2, intSet.size());
    for (int i : new int[]{5, 6}) {
      Assert.assertTrue("The resulting IntSet should contain " + i, intSet.contains(i));
    }
    EasyMock.verify(index1, index2);
  }
View Full Code Here


    // set up the indices
    IdxIndex index1 = EasyMock.createMock(IdxIndex.class);
    byte[] column1 = Bytes.toBytes("column1");
    byte[] qualifier1 = Bytes.toBytes("qualifier1");
    byte[] value1 = Bytes.toBytes("value1");
    IntSet bitSet1 = new IntSetBuilder().start().addAll(1,2,3,4,5,6).finish(100);
    EasyMock.expect(index1.head(value1, true)).andReturn(bitSet1);
    EasyMock.expect(index1.probeToString(value1)).andReturn(Bytes.toString(value1)).anyTimes();
    EasyMock.replay(index1);
    searchContext.indices.put(Pair.of(column1, qualifier1), index1);

    IdxIndex index2 = EasyMock.createMock(IdxIndex.class);
    byte[] column2 = Bytes.toBytes("column2");
    byte[] qualifier2 = Bytes.toBytes("qualifier2");
    byte[] value2 = Bytes.toBytes("value2");
    IntSet bitSet2 = new IntSetBuilder().start().addAll(5, 6, 7, 8, 9, 10).finish(100);
    EasyMock.expect(index2.tail(value2, true)).andReturn(bitSet2);
    EasyMock.expect(index2.probeToString(value2)).andReturn(Bytes.toString(value2)).anyTimes();
    EasyMock.replay(index2);
    searchContext.indices.put(Pair.of(column2, qualifier2), index2);

    IdxIndex index3 = EasyMock.createMock(IdxIndex.class);
    byte[] column3 = Bytes.toBytes("column3");
    byte[] qualifier3 = Bytes.toBytes("qualifier3");
    byte[] value3 = Bytes.toBytes("value3");
    IntSet bitSet3 = new IntSetBuilder().start().addAll(11).finish(100);
    EasyMock.expect(index3.lookup(value3)).andReturn(bitSet3);
    EasyMock.expect(index3.probeToString(value3)).andReturn(Bytes.toString(value3)).anyTimes();
    EasyMock.replay(index3);
    searchContext.indices.put(Pair.of(column3, qualifier3), index3);

    // perform the test
    IdxExpressionEvaluator evaluator = new IdxExpressionEvaluator();
    Expression exp = Expression.or(
        Expression.and(
            Expression.comparison(column1, qualifier1, Comparison.Operator.LTE, value1),
            Expression.comparison(column2, qualifier2, Comparison.Operator.GTE, value2)
        ),
        Expression.comparison(column3, qualifier3, Comparison.Operator.EQ, value3)
    );

    IntSet intSet = evaluator.evaluate(searchContext, exp);

    // assert the evaluator interacted with the indices correctly
    Assert.assertNotNull("The response from the evaluator should not be null", intSet);
    Assert.assertEquals("The resulting IntSet contained the wrong number of results", 3, intSet.size());
    for (int i : new int[]{5, 6, 11}) {
      Assert.assertTrue("The resulting IntSet should contain " + i, intSet.contains(i));
    }
    EasyMock.verify(index1, index2, index3);
  }
View Full Code Here

  /**
   * Test that ensures that a null expression is handled correctly.
   */
  public void testNullExpression() {
    IdxExpressionEvaluator evaluator = new IdxExpressionEvaluator();
    IntSet result = evaluator.evaluate(searchContext, (Expression) null);

    Assert.assertNull("The result should be null", result);
  }
View Full Code Here

   */
  public void testNullIndex() {
    Expression exp = Expression.comparison("column", "qualifier", Comparison.Operator.EQ, Bytes.toBytes("value"));

    IdxExpressionEvaluator evaluator = new IdxExpressionEvaluator();
    IntSet result = null;
    try {
      result = evaluator.evaluate(searchContext, exp);
      Assert.fail("An exception should have been thrown");
    } catch (IllegalStateException e) {
      Assert.assertTrue("Exception did not contain the correct message", e.getMessage().contains("Could not find an index"));
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.regionserver.idx.support.sets.IntSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.