-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement DruidPartialDataRequestHandler (#287)
- Loading branch information
Showing
5 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../src/main/java/com/yahoo/bard/webservice/web/handlers/DruidPartialDataRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2017 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.web.handlers; | ||
|
||
import com.yahoo.bard.webservice.config.SystemConfig; | ||
import com.yahoo.bard.webservice.config.SystemConfigProvider; | ||
import com.yahoo.bard.webservice.druid.model.query.DruidAggregationQuery; | ||
import com.yahoo.bard.webservice.web.DataApiRequest; | ||
import com.yahoo.bard.webservice.web.responseprocessors.DruidPartialDataResponseProcessor; | ||
import com.yahoo.bard.webservice.web.responseprocessors.ResponseProcessor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* A request handler that builds responses for Druid partial data | ||
* <p> | ||
* The handler inject "uncoveredIntervalsLimit: $druid_uncovered_interval_limit" context to Druid query. | ||
*/ | ||
public class DruidPartialDataRequestHandler implements DataRequestHandler { | ||
|
||
private static final SystemConfig SYSTEM_CONFIG = SystemConfigProvider.getInstance(); | ||
|
||
private final DataRequestHandler next; | ||
private final int druidUncoveredIntervalLimit = SYSTEM_CONFIG.getIntProperty( | ||
SYSTEM_CONFIG.getPackageVariableName("druid_uncovered_interval_limit"), 0 | ||
); | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param next Next Handler in the chain | ||
*/ | ||
public DruidPartialDataRequestHandler(@NotNull DataRequestHandler next) { | ||
this.next = next; | ||
} | ||
|
||
@Override | ||
public boolean handleRequest( | ||
RequestContext context, | ||
DataApiRequest request, | ||
DruidAggregationQuery<?> druidQuery, | ||
ResponseProcessor response | ||
) { | ||
return next.handleRequest( | ||
context, | ||
request, | ||
druidQuery.withContext( | ||
druidQuery.getContext().withUncoveredIntervalsLimit(druidUncoveredIntervalLimit) | ||
), | ||
new DruidPartialDataResponseProcessor(response) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...t/groovy/com/yahoo/bard/webservice/web/handlers/DruidPartialDataRequestHandlerSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2017 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.web.handlers | ||
|
||
import com.yahoo.bard.webservice.config.SystemConfig | ||
import com.yahoo.bard.webservice.config.SystemConfigProvider | ||
import com.yahoo.bard.webservice.druid.model.datasource.DataSource | ||
import com.yahoo.bard.webservice.druid.model.filter.Filter | ||
import com.yahoo.bard.webservice.druid.model.having.Having | ||
import com.yahoo.bard.webservice.druid.model.orderby.LimitSpec | ||
import com.yahoo.bard.webservice.druid.model.query.DruidAggregationQuery | ||
import com.yahoo.bard.webservice.druid.model.query.Granularity | ||
import com.yahoo.bard.webservice.druid.model.query.GroupByQuery | ||
import com.yahoo.bard.webservice.druid.model.query.QueryContext | ||
import com.yahoo.bard.webservice.web.DataApiRequest | ||
import com.yahoo.bard.webservice.web.responseprocessors.DruidPartialDataResponseProcessor | ||
import com.yahoo.bard.webservice.web.responseprocessors.ResponseProcessor | ||
|
||
import spock.lang.Specification | ||
|
||
class DruidPartialDataRequestHandlerSpec extends Specification { | ||
private static final SystemConfig SYSTEM_CONFIG = SystemConfigProvider.getInstance(); | ||
|
||
def "New query context is passed to next handler"() { | ||
given: | ||
SystemConfig systemConfig = SystemConfigProvider.getInstance() | ||
String uncoveredKey = SYSTEM_CONFIG.getPackageVariableName("druid_uncovered_interval_limit") | ||
systemConfig.setProperty(uncoveredKey, '10') | ||
|
||
DataRequestHandler nextHandler = Mock(DataRequestHandler) | ||
ResponseProcessor responseProcessor = Mock(ResponseProcessor) | ||
RequestContext requestContext = Mock(RequestContext) | ||
DruidAggregationQuery druidQuery = Mock(DruidAggregationQuery) | ||
QueryContext queryContext = Mock(QueryContext) | ||
DataApiRequest apiRequest = Mock(DataApiRequest) | ||
|
||
druidQuery.getContext() >> queryContext | ||
|
||
DruidPartialDataRequestHandler druidPartialDataRequestHandler = new DruidPartialDataRequestHandler( | ||
nextHandler | ||
) | ||
|
||
when: | ||
druidPartialDataRequestHandler.handleRequest(requestContext, apiRequest, druidQuery, responseProcessor) | ||
|
||
then: | ||
1 * druidQuery.withContext(queryContext) >> druidQuery | ||
1 * queryContext.withUncoveredIntervalsLimit(10) >> queryContext | ||
1 * nextHandler.handleRequest(requestContext, apiRequest, druidQuery, _ as DruidPartialDataResponseProcessor) | ||
|
||
cleanup: | ||
systemConfig.clearProperty(uncoveredKey) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters