From 568a2a8adec4d83d6a518de4d028fcb971145f09 Mon Sep 17 00:00:00 2001 From: corby Date: Fri, 3 Jun 2022 17:02:57 +0200 Subject: [PATCH] leverage federate query --- .../fr/inria/corese/core/load/Service.java | 36 +++++++++++-------- .../corese/core/query/CompileService.java | 29 +++++++++++---- .../corese/core/query/ProviderService.java | 5 ++- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/corese-core/src/main/java/fr/inria/corese/core/load/Service.java b/corese-core/src/main/java/fr/inria/corese/core/load/Service.java index b1b220d7b..c6b52bb78 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/load/Service.java +++ b/corese-core/src/main/java/fr/inria/corese/core/load/Service.java @@ -725,21 +725,7 @@ ASTQuery getAST(Query q) { } void metadata(ASTQuery ast) { - if (!ast.hasLimit()) { - if (ast.hasMetadata(Metadata.LIMIT)) { - ast.setLimit(ast.getMetadata().getDatatypeValue(Metadata.LIMIT).intValue()); - } - // DRAFT: for testing (modify ast ...) - Integer lim = getURL().intValue(LIMIT); - if (lim != -1) { - ast.setLimit(lim); - } - lim = Property.intValue(SERVICE_LIMIT); - if (lim != null) { - ast.setLimit(lim); - } - - } + limit(ast); if (getURL().isGET() || ast.getGlobalAST().hasMetadata(Metadata.GET)) { setPost(false); } @@ -755,6 +741,26 @@ void metadata(ASTQuery ast) { getCreateParser().setShowResult(isShowResult()); } } + + // use case for limit: @federate with one URL -> direct service + void limit(ASTQuery ast) { + if (!ast.hasLimit()) { + if (ast.hasMetadata(Metadata.LIMIT)) { + ast.setLimit(ast.getMetaValue(Metadata.LIMIT).intValue()); + } else { + Integer lim = getURL().intValue(LIMIT); + if (lim != -1) { + ast.setLimit(lim); + } + else { + lim = Property.intValue(SERVICE_LIMIT); + if (lim != null) { + ast.setLimit(lim); + } + } + } + } + } public Binding getBind() { diff --git a/corese-core/src/main/java/fr/inria/corese/core/query/CompileService.java b/corese-core/src/main/java/fr/inria/corese/core/query/CompileService.java index b7408a3f9..62b5d3f53 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/query/CompileService.java +++ b/corese-core/src/main/java/fr/inria/corese/core/query/CompileService.java @@ -1,6 +1,8 @@ package fr.inria.corese.core.query; import fr.inria.corese.compiler.eval.Interpreter; +import fr.inria.corese.core.util.Property; +import static fr.inria.corese.core.util.Property.Value.SERVICE_LIMIT; import java.util.ArrayList; import fr.inria.corese.sparql.api.IDatatype; @@ -28,8 +30,11 @@ import fr.inria.corese.sparql.triple.parser.VariableLocal; import fr.inria.corese.sparql.triple.parser.context.ContextLog; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class CompileService implements URLParam { + static Logger logger = LoggerFactory.getLogger(CompileService.class); public static final String KG_VALUES = NSManager.KGRAM + "values"; public static final String KG_FILTER = NSManager.KGRAM + "filter"; // default binding @@ -93,21 +98,33 @@ public ASTQuery compile(URLServer serv, Query q, Mappings map, CompileServiceRes } } + // q is service query + // ast is query ast void complete(URLServer serv, Query q, ASTQuery ast) { - int myLimit = serv.intValue(LIMIT); - if (myLimit >= 0) { - ast.setLimit(myLimit); - } else { + if (!ast.hasLimit()) { ASTQuery gast = q.getGlobalQuery().getAST(); - if (gast.hasMetadata(Metadata.LIMIT)) { + int myLimit = serv.intValue(LIMIT); + if (myLimit >= 0) { + // service URL parameter limit=n + ast.setLimit(myLimit); + } else if (gast.hasMetadata(Metadata.LIMIT)) { + // limit of outer query of service (if any) int limit = q.getOuterQuery().getAST().getLimit(); - IDatatype dt = gast.getMetadata().getDatatypeValue(Metadata.LIMIT); + // @limit of global query + IDatatype dt = gast.getMetaValue(Metadata.LIMIT); if (dt != null) { limit = dt.intValue(); } + // select lower limit ast.setLimit(Math.min(limit, ast.getLimit())); + } else { + Integer limit = Property.intValue(SERVICE_LIMIT); + if (limit != null) { + ast.setLimit(limit); + } } } + logger.info("Limit: " + ast.getLimit()); } boolean getIsValues(URLServer serv, Query q) { diff --git a/corese-core/src/main/java/fr/inria/corese/core/query/ProviderService.java b/corese-core/src/main/java/fr/inria/corese/core/query/ProviderService.java index 10be81723..3936dbedf 100644 --- a/corese-core/src/main/java/fr/inria/corese/core/query/ProviderService.java +++ b/corese-core/src/main/java/fr/inria/corese/core/query/ProviderService.java @@ -36,8 +36,6 @@ import fr.inria.corese.sparql.triple.parser.Access.Feature; import fr.inria.corese.sparql.triple.parser.Context; import fr.inria.corese.sparql.triple.parser.Metadata; -import static fr.inria.corese.sparql.triple.parser.Metadata.START; -import static fr.inria.corese.sparql.triple.parser.Metadata.UNTIL; import fr.inria.corese.sparql.triple.parser.Triple; import fr.inria.corese.sparql.triple.parser.URLParam; import fr.inria.corese.sparql.triple.parser.URLServer; @@ -474,7 +472,8 @@ Mappings send(URLServer serv, ASTQuery ast, Mappings map, throws EngineException, IOException { if (getGlobalAST().hasMetadata(Metadata.LOOP) || - serv.hasParameter(LOOP)) { + serv.hasParameter(LOOP) || + serv.hasParameter(MODE, LOOP)) { int begin = getValue(serv, START, URLParam.START, 0); int end = getValue(serv, UNTIL, URLParam.UNTIL, Integer.MAX_VALUE); int myLimit = getValue(serv, LIMIT, URLParam.LIMIT, ast.getLimit());