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

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


     */
    long[] values = {60, 80, 40, 50, 0, 20, 10, 70, 30, 90};
    int[] ids = {7, 80, 81, 200, 235, 490, 601, 698, 888, 965};
    index = fillIndex(values, ids);
    for (int i = 0; i < values.length; i++) {
      IntSet lookupResult = index.lookup(Bytes.toBytes(values[i]));
      Assert.assertEquals(1, lookupResult.size());
      Assert.assertEquals(true, lookupResult.contains(ids[i]));
    }
    Assert.assertTrue(index.lookup(Bytes.toBytes(35L)).isEmpty());

    /**
     * All the entries have the samae value
     */
    values = new long[]{100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
    index = fillIndex(values, ids);
    IntSet lookupResult = index.lookup(Bytes.toBytes(100L));
    Assert.assertEquals(10, lookupResult.size());
    for (int id : ids) {
      Assert.assertEquals(true, lookupResult.contains(id));
    }
    Assert.assertTrue(index.lookup(Bytes.toBytes(35L)).isEmpty());

    /**
     * Some of the entries have one value on the others have another value
     */
    values = new long[]{100, 99, 50, 99, 100, 50, 100, 100, 99, 99};
    index = fillIndex(values, ids);
    lookupResult = index.lookup(Bytes.toBytes(100L));
    Assert.assertEquals(4, lookupResult.size());
    for (int id : new int[]{7, 235, 601, 698}) {
      Assert.assertEquals(true, lookupResult.contains(id));
    }

    lookupResult = index.lookup(Bytes.toBytes(99L));
    Assert.assertEquals(4, lookupResult.size());
    for (int id : new int[]{80, 200, 888, 965}) {
      Assert.assertEquals(true, lookupResult.contains(id));
    }

    lookupResult = index.lookup(Bytes.toBytes(50L));
    Assert.assertEquals(2, lookupResult.size());
    for (int id : new int[]{81, 490}) {
      Assert.assertEquals(true, lookupResult.contains(id));
    }
    Assert.assertTrue(index.lookup(Bytes.toBytes(35L)).isEmpty());
  }
View Full Code Here


        expression.getClass().getName());
    }
  }

  protected IntSet evaluate(IdxSearchContext searchContext, And and) {
    IntSet result = null;
    for (Expression expression : and.getChildren()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Intersecting expression:");
      }
      IntSet childResult = evaluate(searchContext, expression);
      if (result == null) {
        result = childResult;
      } else if (childResult != null) {
        result = result.intersect(childResult);
      }
View Full Code Here

    }
    return result;
  }

  protected IntSet evaluate(IdxSearchContext searchContext, Or or) {
    IntSet result = null;
    for (Expression expression : or.getChildren()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Uniting expression:");
      }
      IntSet childResult = evaluate(searchContext, expression);
      if (result == null) {
        result = childResult;
      } else if (childResult != null) {
        result = result.unite(childResult);
      }
View Full Code Here

    if (index == null) throw new IllegalStateException(
            String.format("Could not find an index for column: '%s', qualifier: '%s'",
                    Bytes.toString(comparison.getColumnName()),
                    Bytes.toString(comparison.getQualifier())));

    IntSet matched = null;
    switch (comparison.getOperator()) {
      case EQ:
        matched = index.lookup(comparison.getValue());
        break;
      case GT:
        matched = index.tail(comparison.getValue(), false);
        break;
      case GTE:
        matched = index.tail(comparison.getValue(), true);
        break;
      case LT:
        matched = index.head(comparison.getValue(), false);
        break;
      case LTE:
        matched = index.head(comparison.getValue(), true);
        break;
    }

    if (LOG.isDebugEnabled() && matched != null) {
      LOG.debug(String.format("Evaluation of comparison on column: '%s', " +
          "qualifier: '%s', operator: %s, value: '%s' yielded %s matches",
          Bytes.toString(comparison.getColumnName()),
          Bytes.toString(comparison.getQualifier()),
          comparison.getOperator(),
          index.probeToString(comparison.getValue()), matched.size()));
    }

    return matched != null ? matched : null;
  }
View Full Code Here

      int interval = (int) Math.round(Math.sqrt(indexSize));
      int precalcSize = indexSize / interval +
        Integer.signum(indexSize % interval);

      IntSet[] tails = new IntSet[precalcSize];
      IntSet currentTail = IntSetBuilder.newEmptyIntSet(numKeyValues);
      for (int i = indexSize - 1; i >= 0; i--) {
        currentTail = currentTail.unite(valueStore[i]);
        if (i % interval == 0) {
          tails[i / interval] = currentTail;
          currentTail = currentTail.clone();
        }
      }

      IntSet[] heads = new IntSet[precalcSize];
      IntSet currentHead = IntSetBuilder.newEmptyIntSet(numKeyValues);
      for (int i = 0; i < indexSize; i++) {
        currentHead = currentHead.unite(valueStore[i]);
        if (i % interval == 0) {
          heads[i / interval] = currentHead;
          currentHead = currentHead.clone();
        }
      }

      return new CompleteIndex(keyStore, valueStore, heads, tails,
        numKeyValues, interval);
View Full Code Here

    } else {
      totalIndexedScans.incrementAndGet();
      // Grab a new search context
      IdxSearchContext searchContext = indexManager.newSearchContext();
      // use the expression evaluator to determine the final set of ints
      IntSet matchedExpression = expressionEvaluator.evaluate(searchContext,
        expression);
      if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("%s rows matched the index expression",
          matchedExpression.size()));
      }
      return new IdxRegionScanner(scan, searchContext, matchedExpression);
    }
  }
View Full Code Here

    }
    if (index < 0) {
      index = -index;
    }
    int tailIndex = index / precalcInterval + 1;
    IntSet result = tailIndex < tails.length ?
      tails[tailIndex].clone() :
      IntSetBuilder.newEmptyIntSet(numKeyValues);
    int stopIndex = Math.min(tailIndex * precalcInterval, valueStore.length);
    for (int i = index; i < stopIndex; i++) {
      result = result.unite(valueStore[i]);
    }
    return result;
  }
View Full Code Here

    if (index < 0) {
      index = -(index + 1);
    }

    int headIndex = (index - 1) / precalcInterval;
    IntSet result = headIndex > 0 ?
      heads[headIndex].clone() :
      IntSetBuilder.newEmptyIntSet(numKeyValues);
    int startIndex = Math.max(headIndex * precalcInterval, 0);
    for (int i = startIndex; i < index; i++) {
      result = result.unite(valueStore[i]);
    }
    return result;
  }
View Full Code Here

    searchContext.indices.put(Pair.of(column, qualifier), index);

    // perform the test
    IdxExpressionEvaluator evaluator = new IdxExpressionEvaluator();
    Expression exp = Expression.comparison(column, qualifier, Comparison.Operator.EQ, value);
    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);
    EasyMock.verify(index);
  }
View Full Code Here

    // 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).finish(100);
    EasyMock.expect(index1.head(value1, false)).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(6, 7, 8, 9, 10).finish(100);
    EasyMock.expect(index2.tail(value2, false)).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.or(
        Expression.comparison(column1, qualifier1, Comparison.Operator.LT, value1),
        Expression.comparison(column2, qualifier2, Comparison.Operator.GT, 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);
    for (int i = 1; i <= 10; i++) {
      Assert.assertTrue("The resulting IntSet should contain " + i, intSet.contains(i));
    }
    EasyMock.verify(index1, index2);
  }
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.