Search in sources :

Example 1 with TimeBoundaryInfo

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);
    }
}
Also used : TimeBoundaryInfo(com.linkedin.pinot.routing.TimeBoundaryService.TimeBoundaryInfo) FilterQueryMap(com.linkedin.pinot.common.request.FilterQueryMap) ArrayList(java.util.ArrayList) FilterQuery(com.linkedin.pinot.common.request.FilterQuery)

Example 2 with TimeBoundaryInfo

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");
}
Also used : HelixExternalViewBasedTimeBoundaryService(com.linkedin.pinot.routing.HelixExternalViewBasedTimeBoundaryService) ExternalView(org.apache.helix.model.ExternalView) TimeBoundaryInfo(com.linkedin.pinot.routing.TimeBoundaryService.TimeBoundaryInfo) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

TimeBoundaryInfo (com.linkedin.pinot.routing.TimeBoundaryService.TimeBoundaryInfo)2 FilterQuery (com.linkedin.pinot.common.request.FilterQuery)1 FilterQueryMap (com.linkedin.pinot.common.request.FilterQueryMap)1 HelixExternalViewBasedTimeBoundaryService (com.linkedin.pinot.routing.HelixExternalViewBasedTimeBoundaryService)1 ArrayList (java.util.ArrayList)1 ExternalView (org.apache.helix.model.ExternalView)1 AfterTest (org.testng.annotations.AfterTest)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1