use of com.linkedin.pinot.routing.TimeBoundaryService.TimeBoundaryInfo in project pinot by linkedin.
the class BrokerRequestHandler method attachTimeBoundary.
/**
* Attach time boundary to a broker request.
*
* @param hybridTableName hybrid table name.
* @param brokerRequest original broker request.
* @param isOfflineRequest flag for offline/realtime request.
*/
private void attachTimeBoundary(@Nonnull String hybridTableName, @Nonnull BrokerRequest brokerRequest, boolean isOfflineRequest) {
TimeBoundaryInfo timeBoundaryInfo = _timeBoundaryService.getTimeBoundaryInfoFor(TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(hybridTableName));
if (timeBoundaryInfo == null || timeBoundaryInfo.getTimeColumn() == null || timeBoundaryInfo.getTimeValue() == null) {
LOGGER.warn("No time boundary attached for table: {}", hybridTableName);
return;
}
// Create a range filter based on the request type.
String timeValue = timeBoundaryInfo.getTimeValue();
FilterQuery timeFilterQuery = new FilterQuery();
timeFilterQuery.setOperator(FilterOperator.RANGE);
timeFilterQuery.setColumn(timeBoundaryInfo.getTimeColumn());
timeFilterQuery.setNestedFilterQueryIds(new ArrayList<Integer>());
List<String> values = new ArrayList<>();
if (isOfflineRequest) {
values.add("(*\t\t" + timeValue + ")");
} else {
values.add("[" + timeValue + "\t\t*)");
}
timeFilterQuery.setValue(values);
timeFilterQuery.setId(-1);
// Attach the range filter to the current filter.
FilterQuery currentFilterQuery = brokerRequest.getFilterQuery();
if (currentFilterQuery != null) {
FilterQuery andFilterQuery = new FilterQuery();
andFilterQuery.setOperator(FilterOperator.AND);
List<Integer> nestedFilterQueryIds = new ArrayList<>();
nestedFilterQueryIds.add(currentFilterQuery.getId());
nestedFilterQueryIds.add(timeFilterQuery.getId());
andFilterQuery.setNestedFilterQueryIds(nestedFilterQueryIds);
andFilterQuery.setId(-2);
FilterQueryMap filterSubQueryMap = brokerRequest.getFilterSubQueryMap();
filterSubQueryMap.putToFilterQueryMap(timeFilterQuery.getId(), timeFilterQuery);
filterSubQueryMap.putToFilterQueryMap(andFilterQuery.getId(), andFilterQuery);
brokerRequest.setFilterQuery(andFilterQuery);
brokerRequest.setFilterSubQueryMap(filterSubQueryMap);
} else {
FilterQueryMap filterSubQueryMap = new FilterQueryMap();
filterSubQueryMap.putToFilterQueryMap(timeFilterQuery.getId(), timeFilterQuery);
brokerRequest.setFilterQuery(timeFilterQuery);
brokerRequest.setFilterSubQueryMap(filterSubQueryMap);
}
}
use of com.linkedin.pinot.routing.TimeBoundaryService.TimeBoundaryInfo in project pinot by linkedin.
the class TimeBoundaryServiceTest method testExternalViewBasedTimeBoundaryService.
@Test
public void testExternalViewBasedTimeBoundaryService() throws Exception {
addingTableToPropertyStore("testResource0");
addingTableToPropertyStore("testResource1");
HelixExternalViewBasedTimeBoundaryService tbs = new HelixExternalViewBasedTimeBoundaryService(_propertyStore);
addingSegmentsToPropertyStore(5, _propertyStore, "testResource0");
ExternalView externalView = constructExternalView("testResource0");
tbs.updateTimeBoundaryService(externalView);
TimeBoundaryInfo tbi = tbs.getTimeBoundaryInfoFor("testResource0");
Assert.assertEquals(tbi.getTimeColumn(), "timestamp");
Assert.assertEquals(tbi.getTimeValue(), "4");
addingSegmentsToPropertyStore(50, _propertyStore, "testResource1");
externalView = constructExternalView("testResource1");
tbs.updateTimeBoundaryService(externalView);
tbi = tbs.getTimeBoundaryInfoFor("testResource1");
Assert.assertEquals(tbi.getTimeColumn(), "timestamp");
Assert.assertEquals(tbi.getTimeValue(), "49");
addingSegmentsToPropertyStore(50, _propertyStore, "testResource0");
externalView = constructExternalView("testResource0");
tbs.updateTimeBoundaryService(externalView);
tbi = tbs.getTimeBoundaryInfoFor("testResource0");
Assert.assertEquals(tbi.getTimeColumn(), "timestamp");
Assert.assertEquals(tbi.getTimeValue(), "49");
}
Aggregations