Skip to content

Commit

Permalink
leverage federate query
Browse files Browse the repository at this point in the history
  • Loading branch information
ocorby committed Jun 3, 2022
1 parent dcbbb94 commit 568a2a8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
36 changes: 21 additions & 15 deletions corese-core/src/main/java/fr/inria/corese/core/load/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 568a2a8

Please sign in to comment.