Search in sources :

Example 1 with ServiceParams

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);
    }
}
Also used : Timer(com.codahale.metrics.Timer) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 2 with ServiceParams

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);
    }
}
Also used : Timer(com.codahale.metrics.Timer) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 3 with ServiceParams

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);
    }
}
Also used : Timer(com.codahale.metrics.Timer) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 4 with ServiceParams

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;
}
Also used : IGroupMemberNode(com.bigdata.rdf.sparql.ast.IGroupMemberNode) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) TermNode(com.bigdata.rdf.sparql.ast.TermNode) URI(org.openrdf.model.URI)

Example 5 with 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());
}
Also used : IVariableOrConstant(com.bigdata.bop.IVariableOrConstant) URIImpl(org.openrdf.model.impl.URIImpl) Ontology(org.wikidata.query.rdf.common.uri.Ontology) LoggerFactory(org.slf4j.LoggerFactory) AbstractServiceFactory(com.bigdata.rdf.sparql.ast.eval.AbstractServiceFactory) BigdataServiceCall(com.bigdata.rdf.sparql.ast.service.BigdataServiceCall) IVariableOrConstant(com.bigdata.bop.IVariableOrConstant) BigdataNativeServiceOptions(com.bigdata.rdf.sparql.ast.service.BigdataNativeServiceOptions) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) URI(org.openrdf.model.URI) Path(java.nio.file.Path) GraphPatternGroup(com.bigdata.rdf.sparql.ast.GraphPatternGroup) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) ServiceRegistry(com.bigdata.rdf.sparql.ast.service.ServiceRegistry) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) IGroupMemberNode(com.bigdata.rdf.sparql.ast.IGroupMemberNode) StandardCharsets(java.nio.charset.StandardCharsets) BD(com.bigdata.rdf.store.BD) ServiceNode(com.bigdata.rdf.sparql.ast.service.ServiceNode) Paths(java.nio.file.Paths) TermNode(com.bigdata.rdf.sparql.ast.TermNode) IVariable(com.bigdata.bop.IVariable) Timer(com.codahale.metrics.Timer) Mediawiki(org.wikidata.query.rdf.common.uri.Mediawiki) IServiceOptions(com.bigdata.rdf.sparql.ast.service.IServiceOptions) ServiceCallCreateParams(com.bigdata.rdf.sparql.ast.service.ServiceCallCreateParams) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) IVariable(com.bigdata.bop.IVariable)

Aggregations

ServiceParams (com.bigdata.rdf.sparql.ast.eval.ServiceParams)9 Test (org.junit.Test)7 Timer (com.codahale.metrics.Timer)6 Closeable (java.io.Closeable)5 IVariableOrConstant (com.bigdata.bop.IVariableOrConstant)2 IGroupMemberNode (com.bigdata.rdf.sparql.ast.IGroupMemberNode)2 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)2 TermNode (com.bigdata.rdf.sparql.ast.TermNode)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 URI (org.openrdf.model.URI)2 IVariable (com.bigdata.bop.IVariable)1 GraphPatternGroup (com.bigdata.rdf.sparql.ast.GraphPatternGroup)1 VarNode (com.bigdata.rdf.sparql.ast.VarNode)1 AbstractServiceFactory (com.bigdata.rdf.sparql.ast.eval.AbstractServiceFactory)1 BigdataNativeServiceOptions (com.bigdata.rdf.sparql.ast.service.BigdataNativeServiceOptions)1 BigdataServiceCall (com.bigdata.rdf.sparql.ast.service.BigdataServiceCall)1 IServiceOptions (com.bigdata.rdf.sparql.ast.service.IServiceOptions)1 ServiceCallCreateParams (com.bigdata.rdf.sparql.ast.service.ServiceCallCreateParams)1 ServiceNode (com.bigdata.rdf.sparql.ast.service.ServiceNode)1 ServiceRegistry (com.bigdata.rdf.sparql.ast.service.ServiceRegistry)1