Search in sources :

Example 6 with RangePredicate

use of com.linkedin.pinot.core.common.predicate.RangePredicate in project pinot by linkedin.

the class RangeMergeOptimizer method intersectRanges.

/**
   * Helper method to compute intersection of two ranges.
   * Assumes that values are 'long'. This is OK as this feature is used only for time-column.
   *
   * @param range1 First range
   * @param range2 Second range
   * @return Intersection of the given ranges.
   */
public static List<String> intersectRanges(List<String> range1, List<String> range2) {
    // Build temporary range predicates to parse the string range values.
    RangePredicate predicate1 = new RangePredicate(DUMMY_STRING, range1);
    RangePredicate predicate2 = new RangePredicate(DUMMY_STRING, range2);
    String lowerString1 = predicate1.getLowerBoundary();
    String upperString1 = predicate1.getUpperBoundary();
    long lower1 = (lowerString1.equals(RangePredicate.UNBOUNDED)) ? Long.MIN_VALUE : Long.valueOf(lowerString1);
    long upper1 = (upperString1.equals(RangePredicate.UNBOUNDED)) ? Long.MAX_VALUE : Long.valueOf(upperString1);
    String lowerString2 = predicate2.getLowerBoundary();
    String upperString2 = predicate2.getUpperBoundary();
    long lower2 = (lowerString2.equals(RangePredicate.UNBOUNDED)) ? Long.MIN_VALUE : Long.valueOf(lowerString2);
    long upper2 = (upperString2.equals(RangePredicate.UNBOUNDED)) ? Long.MAX_VALUE : Long.valueOf(upperString2);
    final StringBuilder stringBuilder = new StringBuilder();
    if (lower1 > lower2) {
        stringBuilder.append((predicate1.includeLowerBoundary() ? RangePredicate.LOWER_INCLUSIVE : RangePredicate.LOWER_EXCLUSIVE));
        stringBuilder.append(lower1);
    } else if (lower1 < lower2) {
        stringBuilder.append((predicate2.includeLowerBoundary() ? RangePredicate.LOWER_INCLUSIVE : RangePredicate.LOWER_EXCLUSIVE));
        stringBuilder.append(lower2);
    } else {
        if (lower1 == Long.MIN_VALUE) {
            // lower1 == lower2
            // * always has '('
            stringBuilder.append(RangePredicate.LOWER_EXCLUSIVE + RangePredicate.UNBOUNDED);
        } else {
            stringBuilder.append((predicate1.includeLowerBoundary() && predicate2.includeLowerBoundary()) ? RangePredicate.LOWER_INCLUSIVE : RangePredicate.LOWER_EXCLUSIVE);
            stringBuilder.append(lower1);
        }
    }
    stringBuilder.append(RangePredicate.DELIMITER);
    if (upper1 < upper2) {
        stringBuilder.append(upper1);
        stringBuilder.append((predicate1.includeUpperBoundary() ? RangePredicate.UPPER_INCLUSIVE : RangePredicate.UPPER_EXCLUSIVE));
    } else if (upper1 > upper2) {
        stringBuilder.append(upper2);
        stringBuilder.append((predicate2.includeUpperBoundary() ? RangePredicate.UPPER_INCLUSIVE : RangePredicate.UPPER_EXCLUSIVE));
    } else {
        if (upper1 == Long.MAX_VALUE) {
            // upper1 == upper2
            // * always has ')'
            stringBuilder.append(RangePredicate.UNBOUNDED + RangePredicate.UPPER_EXCLUSIVE);
        } else {
            stringBuilder.append(upper1);
            stringBuilder.append((predicate1.includeUpperBoundary() && predicate2.includeUpperBoundary()) ? RangePredicate.UPPER_INCLUSIVE : RangePredicate.UPPER_EXCLUSIVE);
        }
    }
    return Collections.singletonList(stringBuilder.toString());
}
Also used : RangePredicate(com.linkedin.pinot.core.common.predicate.RangePredicate)

Example 7 with RangePredicate

use of com.linkedin.pinot.core.common.predicate.RangePredicate in project pinot by linkedin.

the class RealtimeSegmentTest method testNoRangeMatchFilteringMetricPredicateWithInvIdx.

@Test
public void testNoRangeMatchFilteringMetricPredicateWithInvIdx() throws Exception {
    DataSource ds1 = segmentWithInvIdx.getDataSource("count");
    List<String> rhs = new ArrayList<String>();
    rhs.add("[0\t\t100)");
    Predicate predicate = new RangePredicate("count", rhs);
    BitmapBasedFilterOperator op = new BitmapBasedFilterOperator(predicate, ds1, 0, segmentWithInvIdx.getRawDocumentCount() - 1);
    Block b = op.nextBlock();
    BlockDocIdIterator iterator = b.getBlockDocIdSet().iterator();
    int counter = 0;
    int docId = iterator.next();
    while (docId != Constants.EOF) {
        // shouldn't reach here.
        Assert.assertTrue(false);
        docId = iterator.next();
        counter++;
    }
    Assert.assertEquals(counter, 0);
}
Also used : RangePredicate(com.linkedin.pinot.core.common.predicate.RangePredicate) BitmapBasedFilterOperator(com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator) ArrayList(java.util.ArrayList) Block(com.linkedin.pinot.core.common.Block) DataSource(com.linkedin.pinot.core.common.DataSource) RangePredicate(com.linkedin.pinot.core.common.predicate.RangePredicate) NEqPredicate(com.linkedin.pinot.core.common.predicate.NEqPredicate) EqPredicate(com.linkedin.pinot.core.common.predicate.EqPredicate) Predicate(com.linkedin.pinot.core.common.Predicate) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) Test(org.testng.annotations.Test) RealtimeSegmentImplTest(com.linkedin.pinot.core.realtime.impl.kafka.RealtimeSegmentImplTest)

Example 8 with RangePredicate

use of com.linkedin.pinot.core.common.predicate.RangePredicate in project pinot by linkedin.

the class RealtimeSegmentTest method testRangeMatchFilteringMetricPredicateWithInvIdx.

@Test
public void testRangeMatchFilteringMetricPredicateWithInvIdx() throws Exception {
    DataSource ds1 = segmentWithInvIdx.getDataSource("count");
    List<String> rhs = new ArrayList<String>();
    rhs.add("[0\t\t*)");
    Predicate predicate = new RangePredicate("count", rhs);
    BitmapBasedFilterOperator op = new BitmapBasedFilterOperator(predicate, ds1, 0, segmentWithInvIdx.getRawDocumentCount() - 1);
    Block b = op.nextBlock();
    BlockDocIdIterator iterator = b.getBlockDocIdSet().iterator();
    DataSource ds2 = segmentWithInvIdx.getDataSource("count");
    BlockSingleValIterator blockValIterator = (BlockSingleValIterator) ds2.nextBlock().getBlockValueSet().iterator();
    int docId = iterator.next();
    int counter = 0;
    while (docId != Constants.EOF) {
        blockValIterator.skipTo(docId);
        Assert.assertEquals(ds1.getDictionary().get(blockValIterator.nextIntVal()), 890662862);
        docId = iterator.next();
        counter++;
    }
    Assert.assertEquals(counter, 100000);
}
Also used : RangePredicate(com.linkedin.pinot.core.common.predicate.RangePredicate) BitmapBasedFilterOperator(com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator) BlockSingleValIterator(com.linkedin.pinot.core.common.BlockSingleValIterator) ArrayList(java.util.ArrayList) Block(com.linkedin.pinot.core.common.Block) DataSource(com.linkedin.pinot.core.common.DataSource) RangePredicate(com.linkedin.pinot.core.common.predicate.RangePredicate) NEqPredicate(com.linkedin.pinot.core.common.predicate.NEqPredicate) EqPredicate(com.linkedin.pinot.core.common.predicate.EqPredicate) Predicate(com.linkedin.pinot.core.common.Predicate) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) Test(org.testng.annotations.Test) RealtimeSegmentImplTest(com.linkedin.pinot.core.realtime.impl.kafka.RealtimeSegmentImplTest)

Aggregations

RangePredicate (com.linkedin.pinot.core.common.predicate.RangePredicate)8 EqPredicate (com.linkedin.pinot.core.common.predicate.EqPredicate)5 NEqPredicate (com.linkedin.pinot.core.common.predicate.NEqPredicate)5 Block (com.linkedin.pinot.core.common.Block)4 BlockDocIdIterator (com.linkedin.pinot.core.common.BlockDocIdIterator)4 DataSource (com.linkedin.pinot.core.common.DataSource)4 Predicate (com.linkedin.pinot.core.common.Predicate)4 RealtimeSegmentImplTest (com.linkedin.pinot.core.realtime.impl.kafka.RealtimeSegmentImplTest)4 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 FilterOperator (com.linkedin.pinot.common.request.FilterOperator)2 BlockSingleValIterator (com.linkedin.pinot.core.common.BlockSingleValIterator)2 BitmapBasedFilterOperator (com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator)2 ScanBasedFilterOperator (com.linkedin.pinot.core.operator.filter.ScanBasedFilterOperator)2 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)1 FilterQueryTree (com.linkedin.pinot.common.utils.request.FilterQueryTree)1 InPredicate (com.linkedin.pinot.core.common.predicate.InPredicate)1 NotInPredicate (com.linkedin.pinot.core.common.predicate.NotInPredicate)1 RegexPredicate (com.linkedin.pinot.core.common.predicate.RegexPredicate)1 ColumnMetadata (com.linkedin.pinot.core.segment.index.ColumnMetadata)1