use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.
the class MWApiServiceFactoryUnitTest method testGetLimitsFromParams_backwardsCompatiblityParams.
@Test
public void testGetLimitsFromParams_backwardsCompatiblityParams() throws IOException {
try (Closeable maxResultsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_RESULTS, null);
Closeable maxContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_CONTINUATIONS, null);
Closeable maxEmptyContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_EMPTY_CONTINUATIONS, null)) {
MWApiServiceFactory factory = new MWApiServiceFactory(new ServiceConfig(), new Timer());
ServiceParams serviceParams = new ServiceParams();
serviceParams.set(MWApiServiceFactory.LIMIT_RESULTS_KEY, createConstant("once"));
MWApiLimits limits = factory.getLimitsFromParams(serviceParams);
assertEquals(10000, limits.limitResults);
assertEquals(0, limits.limitContinuations);
assertEquals(25, limits.limitEmptyContinuations);
}
}
use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.
the class MWApiServiceFactoryUnitTest method testGetLimitsFromParams_nonstandardProperties_customParams.
@Test
public void testGetLimitsFromParams_nonstandardProperties_customParams() throws IOException {
try (Closeable maxResultsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_RESULTS, "7500");
Closeable maxContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_CONTINUATIONS, "50");
Closeable maxEmptyContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_EMPTY_CONTINUATIONS, "10")) {
MWApiServiceFactory factory = new MWApiServiceFactory(new ServiceConfig(), new Timer());
ServiceParams serviceParams = new ServiceParams();
serviceParams.set(MWApiServiceFactory.LIMIT_RESULTS_KEY, createConstant("9000"));
serviceParams.set(MWApiServiceFactory.LIMIT_CONTINUATIONS_KEY, createConstant("75"));
serviceParams.set(MWApiServiceFactory.LIMIT_EMPTY_CONTINUATIONS_KEY, createConstant("20"));
MWApiLimits limits = factory.getLimitsFromParams(serviceParams);
assertEquals(7500, limits.limitResults);
assertEquals(50, limits.limitContinuations);
assertEquals(10, limits.limitEmptyContinuations);
}
}
use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.
the class MWApiServiceFactoryUnitTest method testGetLimitsFromParams_default.
@Test
public void testGetLimitsFromParams_default() throws IOException {
try (Closeable maxResultsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_RESULTS, null);
Closeable maxContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_CONTINUATIONS, null);
Closeable maxEmptyContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_EMPTY_CONTINUATIONS, null)) {
MWApiServiceFactory factory = new MWApiServiceFactory(new ServiceConfig(), new Timer());
ServiceParams serviceParams = new ServiceParams();
MWApiLimits limits = factory.getLimitsFromParams(serviceParams);
assertEquals(10000, limits.limitResults);
assertEquals(1000, limits.limitContinuations);
assertEquals(25, limits.limitEmptyContinuations);
}
}
use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.
the class MWApiServiceFactory method serviceParamsFromNode.
/**
* Get service params from Service Node.
* FIXME: copypaste from ServiceParams.java, should be integrated there
*/
private ServiceParams serviceParamsFromNode(final ServiceNode serviceNode) {
requireNonNull(serviceNode, "Service node is null?");
final GraphPatternGroup<IGroupMemberNode> group = serviceNode.getGraphPattern();
requireNonNull(group, "Group node is null?");
final ServiceParams serviceParams = new ServiceParams();
for (IGroupMemberNode node : group) {
if (node instanceof StatementPatternNode) {
final StatementPatternNode sp = (StatementPatternNode) node;
final TermNode s = sp.s();
if (s.isConstant() && BD.SERVICE_PARAM.equals(s.getValue())) {
if (sp.p().isVariable()) {
throw new RuntimeException("not a valid service param triple pattern, " + "predicate must be constant: " + sp);
}
final URI param = (URI) sp.p().getValue();
serviceParams.add(param, sp.o());
}
}
}
return serviceParams;
}
use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.
the class MWApiServiceFactory method getRequiredBound.
@Override
public Set<IVariable<?>> getRequiredBound(final ServiceNode serviceNode) {
ServiceParams params = serviceParamsFromNode(serviceNode);
ApiTemplate api = getServiceTemplate(params);
Map<String, IVariableOrConstant> potentialVars = api.getInputVars(params);
// Extract params that have variables linked to them
return potentialVars.entrySet().stream().filter(entry -> entry.getValue() != null && entry.getValue().isVar()).map(entry -> (IVariable<?>) entry.getValue()).collect(ImmutableSet.toImmutableSet());
}
Aggregations