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());
}
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);
}
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);
}
Aggregations