You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2014/11/05 13:24:47 UTC
git commit: SPARQL: - implementation of SameTerm - implementation of
BNodeGenerator and IRIFunction - empty literal results have no language
Repository: marmotta
Updated Branches:
refs/heads/develop 4bc783a95 -> 048994403
SPARQL:
- implementation of SameTerm
- implementation of BNodeGenerator and IRIFunction
- empty literal results have no language
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/04899440
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/04899440
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/04899440
Branch: refs/heads/develop
Commit: 048994403681d6141fadcc110cb9d88acf983426
Parents: 4bc783a
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Wed Nov 5 13:25:12 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Wed Nov 5 13:25:12 2014 +0100
----------------------------------------------------------------------
.../marmotta/kiwi/sparql/builder/OPTypes.java | 2 +-
.../kiwi/sparql/builder/ProjectionType.java | 2 +-
.../kiwi/sparql/builder/SQLBuilder.java | 68 ++++++++++++++++--
.../marmotta/kiwi/sparql/builder/SQLClause.java | 5 +-
.../kiwi/sparql/builder/SQLFragment.java | 10 +--
.../kiwi/sparql/builder/VariableFinder.java | 23 ++----
.../evaluation/KiWiEvaluationStrategyImpl.java | 12 ++++
.../persistence/KiWiSparqlConnection.java | 58 +++++++++------
.../sparql/sail/KiWiSparqlSailConnection.java | 8 ++-
.../services/sparql/SparqlServiceImpl.java | 76 +++++---------------
10 files changed, 147 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/OPTypes.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/OPTypes.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/OPTypes.java
index db307b2..858dcde 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/OPTypes.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/OPTypes.java
@@ -23,5 +23,5 @@ package org.apache.marmotta.kiwi.sparql.builder;
* @author Sebastian Schaffert (sschaffert@apache.org)
*/
public enum OPTypes {
- STRING, DOUBLE, INT, DATE, BOOL, VALUE, ANY, URI
+ STRING, DOUBLE, INT, DATE, BOOL, VALUE, ANY, TERM, URI, BNODE
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ProjectionType.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ProjectionType.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ProjectionType.java
index 134b5c2..eff7798 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ProjectionType.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ProjectionType.java
@@ -23,5 +23,5 @@ package org.apache.marmotta.kiwi.sparql.builder;
* @author Sebastian Schaffert (sschaffert@apache.org)
*/
public enum ProjectionType {
- NODE, URI, STRING, INT, DOUBLE, DATE, NONE
+ NODE, URI, BNODE, STRING, INT, DOUBLE, DATE, NONE
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
index fd01c1a..46f601c 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
@@ -120,6 +120,9 @@ public class SQLBuilder {
// a prefix for naming table aliases (needed in case this is a subquery)
private String prefix;
+ // used by BNodeGenerator
+ private static Random anonIdGenerator = new Random();
+
/**
* Create a new SQLBuilder for the given query, initial bindings, dataset, and
* @param query
@@ -195,17 +198,38 @@ public class SQLBuilder {
// find extensions (BIND)
extensions = new ExtensionFinder(query).elements;
+ int variableCount = 0;
+
+
+ // find all variables that have been bound already, even if they do not appear in a pattern
+ for(Var v : new VariableFinder(query).variables) {
+ if(v.hasValue() && !v.getName().startsWith("-const")) {
+ SQLVariable sv = variables.get(v.getName());
+ if(sv == null) {
+ sv = new SQLVariable("V" + (++variableCount), v.getName());
+
+ // select those variables that are really projected and not only needed in a grouping construct
+ if(projectedVars.contains(sv.getSparqlName()) || new SQLProjectionFinder(query,v.getName()).found) {
+ sv.setProjectionType(ProjectionType.NODE);
+ }
+
+ sv.getExpressions().add(""+ converter.convert(v.getValue()).getId());
+
+ addVariable(sv);
+ }
+ }
+ }
+
// find all variables occurring in the patterns and create a map to map them to
// field names in the database query; each variable will have one or several field names,
// one for each pattern it occurs in; field names are constructed automatically by a counter
// and the pattern name to ensure the name is a valid HQL identifier
- int variableCount = 0;
for(SQLFragment f : fragments) {
for (SQLPattern p : f.getPatterns()) {
// build pattern
Var[] fields = p.getFields();
for (int i = 0; i < fields.length; i++) {
- if (fields[i] != null && !fields[i].hasValue()) {
+ if (fields[i] != null && (!fields[i].hasValue() || !fields[i].getName().startsWith("-const"))) {
Var v = fields[i];
SQLVariable sv = variables.get(v.getName());
@@ -299,7 +323,7 @@ public class SQLBuilder {
// build pattern
Var[] fields = p.getFields();
for (int i = 0; i < fields.length; i++) {
- if (fields[i] != null && !fields[i].hasValue()) {
+ if (fields[i] != null && (!fields[i].hasValue() || !fields[i].getName().startsWith("-const"))) {
Var v = fields[i];
SQLVariable sv = variables.get(v.getName());
@@ -767,12 +791,31 @@ public class SQLBuilder {
// get value of argument and express it as string
return evaluateExpression(str.getArg(), OPTypes.STRING);
+ } else if(expr instanceof BNodeGenerator) {
+ BNodeGenerator str = (BNodeGenerator)expr;
+
+ if(str.getNodeIdExpr() != null) {
+ // get value of argument and express it as string
+ return evaluateExpression(str.getNodeIdExpr(), OPTypes.STRING);
+ } else {
+ return "\"" + Long.toHexString(System.currentTimeMillis())+Integer.toHexString(anonIdGenerator.nextInt(1000)) + "\"";
+ }
+ } else if(expr instanceof IRIFunction) {
+ IRIFunction str = (IRIFunction)expr;
+
+ // get value of argument and express it as string
+ return evaluateExpression(str.getArg(), OPTypes.STRING);
} else if(expr instanceof Lang) {
Lang lang = (Lang)expr;
if(lang.getArg() instanceof Var) {
return variables.get(((Var) lang.getArg()).getName()).getAlias() + ".lang";
}
+ } else if(expr instanceof SameTerm) {
+ SameTerm cmp = (SameTerm)expr;
+
+ // covered by value binding in variables
+ return evaluateExpression(cmp.getLeftArg(), OPTypes.TERM) + " = " + evaluateExpression(cmp.getRightArg(), OPTypes.TERM);
} else if(expr instanceof Compare) {
Compare cmp = (Compare)expr;
@@ -791,7 +834,7 @@ public class SQLBuilder {
throw new IllegalArgumentException("operation "+cmp.getOperator()+" is not supported on strings");
}
} else {
- if(ot == OPTypes.ANY) {
+ if(ot == OPTypes.ANY || ot == OPTypes.TERM) {
ot = OPTypes.DOUBLE;
}
@@ -860,7 +903,7 @@ public class SQLBuilder {
ValueExpr arg = ((UnaryValueOperator)expr).getArg();
// operator must be a variable or a constant
- if(arg instanceof ValueConstant) {
+ if (arg instanceof ValueConstant) {
return Boolean.toString(((ValueConstant) arg).getValue() instanceof Literal);
} else if(arg instanceof Var) {
String var = variables.get(((Var) arg).getName()).getAlias();
@@ -903,6 +946,14 @@ public class SQLBuilder {
return var + ".svalue";
case URI:
return var + ".svalue";
+ case TERM:
+ if(var == null) {
+ // might happen in case the variable has been bound to a constant value and not
+ // joined in a pattern query
+ return sv.getExpressions().get(0);
+ } else {
+ return var + ".id";
+ }
case ANY:
return var + ".id";
}
@@ -924,6 +975,7 @@ public class SQLBuilder {
case DATE: return "'" + sqlDateFormat.format(DateUtils.parseDate(val)) + "'";
// in this case we should return a node ID and also need to make sure it actually exists
+ case TERM:
case ANY:
KiWiNode n = converter.convert(((ValueConstant) expr).getValue());
return "" + n.getId();
@@ -1155,7 +1207,11 @@ public class SQLBuilder {
protected ProjectionType getProjectionType(ValueExpr expr) {
- if(expr instanceof FunctionCall) {
+ if(expr instanceof BNodeGenerator) {
+ return ProjectionType.BNODE;
+ } else if(expr instanceof IRIFunction) {
+ return ProjectionType.URI;
+ } else if(expr instanceof FunctionCall) {
return opTypeToProjection(functionRegistry.get(((FunctionCall) expr).getURI()).getReturnType());
} else if(expr instanceof NAryValueOperator) {
return getProjectionType(((NAryValueOperator) expr).getArguments().get(0));
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLClause.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLClause.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLClause.java
index 15164ba..66f0d0f 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLClause.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLClause.java
@@ -64,10 +64,11 @@ public abstract class SQLClause {
StringBuilder onClause = new StringBuilder();
for(Iterator<String> cit = conditions.iterator(); cit.hasNext(); ) {
- if(onClause.length() > 0) {
+ String next = cit.next();
+ if(onClause.length() > 0 && next.length() > 0) {
onClause.append("\n AND ");
}
- onClause.append(cit.next());
+ onClause.append(next);
}
return onClause.toString();
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLFragment.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLFragment.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLFragment.java
index 552f08b..b2d1fac 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLFragment.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLFragment.java
@@ -110,10 +110,11 @@ public class SQLFragment extends SQLClause {
if(conditionPosition == ConditionPosition.JOIN && !it.hasNext()) {
// if this is the last pattern of the fragment, add the filter conditions
for(Iterator<String> cit = getConditions().iterator(); cit.hasNext(); ) {
- if(conditionClause.length() > 0) {
+ String next = cit.next();
+ if(conditionClause.length() > 0 && next.length() > 0) {
conditionClause.append("\n AND ");
}
- conditionClause.append(cit.next());
+ conditionClause.append(next);
}
}
@@ -173,10 +174,11 @@ public class SQLFragment extends SQLClause {
// in case the pattern is the last of the fragment, also add the filter conditions of the fragment
// if this is the last pattern of the fragment, add the filter conditions
for(Iterator<String> cit = getConditions().iterator(); cit.hasNext(); ) {
- if(conditionClause.length() > 0) {
+ String next = cit.next();
+ if(conditionClause.length() > 0 && next.length() > 0) {
conditionClause.append("\n AND ");
}
- conditionClause.append(cit.next());
+ conditionClause.append(next);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/VariableFinder.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/VariableFinder.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/VariableFinder.java
index ab3dbb9..d9161a8 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/VariableFinder.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/VariableFinder.java
@@ -17,7 +17,9 @@
package org.apache.marmotta.kiwi.sparql.builder;
-import org.openrdf.query.algebra.*;
+import org.openrdf.query.algebra.Projection;
+import org.openrdf.query.algebra.TupleExpr;
+import org.openrdf.query.algebra.Var;
import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
import java.util.HashSet;
@@ -30,7 +32,7 @@ import java.util.Set;
*/
public class VariableFinder extends QueryModelVisitorBase<RuntimeException> {
- Set<String> variableNames = new HashSet<>();
+ Set<Var> variables = new HashSet<>();
public VariableFinder(TupleExpr expr) {
expr.visit(this);
@@ -39,27 +41,12 @@ public class VariableFinder extends QueryModelVisitorBase<RuntimeException> {
@Override
public void meet(Var node) throws RuntimeException {
- variableNames.add(node.getName());
- }
-
- @Override
- public void meet(ExtensionElem node) throws RuntimeException {
- variableNames.add(node.getName());
- // don't recurse to the children, as this would project non-grouped elements
- }
-
- @Override
- public void meet(Group node) throws RuntimeException {
- variableNames.addAll(node.getGroupBindingNames());
- // don't recurse to the children, as this would project non-grouped elements
+ variables.add(node);
}
@Override
public void meet(Projection node) throws RuntimeException {
- for(ProjectionElem elem : node.getProjectionElemList().getElements()) {
- variableNames.add(elem.getSourceName());
- }
// stop at projection, subquery
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
index 14e69d8..9737463 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
@@ -83,6 +83,8 @@ public class KiWiEvaluationStrategyImpl extends EvaluationStrategyImpl{
supportedConstructs.add(Var.class);
supportedConstructs.add(Str.class);
supportedConstructs.add(Label.class);
+ supportedConstructs.add(BNodeGenerator.class);
+ supportedConstructs.add(IRIFunction.class);
supportedConstructs.add(IsResource.class);
supportedConstructs.add(IsURI.class);
supportedConstructs.add(IsBNode.class);
@@ -317,6 +319,8 @@ public class KiWiEvaluationStrategyImpl extends EvaluationStrategyImpl{
return isSupported(((Sum) expr).getArg());
} else if(expr instanceof Compare) {
return isSupported(((Compare) expr).getLeftArg()) && isSupported(((Compare) expr).getRightArg());
+ } else if(expr instanceof SameTerm) {
+ return isSupported(((SameTerm) expr).getLeftArg()) && isSupported(((SameTerm) expr).getRightArg());
} else if(expr instanceof MathExpr) {
return isSupported(((MathExpr) expr).getLeftArg()) && isSupported(((MathExpr) expr).getRightArg());
} else if(expr instanceof And) {
@@ -335,6 +339,14 @@ public class KiWiEvaluationStrategyImpl extends EvaluationStrategyImpl{
return isAtomic(((Str) expr).getArg());
} else if(expr instanceof Label) {
return isAtomic(((UnaryValueOperator) expr).getArg());
+ } else if(expr instanceof BNodeGenerator) {
+ if(((BNodeGenerator) expr).getNodeIdExpr() != null) {
+ return isAtomic(((BNodeGenerator) expr).getNodeIdExpr());
+ } else {
+ return true;
+ }
+ } else if(expr instanceof IRIFunction) {
+ return isAtomic(((UnaryValueOperator) expr).getArg());
} else if(expr instanceof Bound) {
return true;
} else if(expr instanceof IsResource) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java
index 7d91d6b..c352e0f 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java
@@ -32,8 +32,8 @@ import org.apache.marmotta.kiwi.sparql.builder.ProjectionType;
import org.apache.marmotta.kiwi.sparql.builder.SQLBuilder;
import org.apache.marmotta.kiwi.sparql.builder.SQLVariable;
import org.apache.marmotta.kiwi.sparql.exception.UnsatisfiableQueryException;
-import org.openrdf.model.Literal;
import org.openrdf.model.URI;
+import org.openrdf.model.impl.BNodeImpl;
import org.openrdf.model.impl.LiteralImpl;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.query.Binding;
@@ -146,6 +146,11 @@ public class KiWiSparqlConnection {
if(svalue != null)
resultRow.addBinding(sv.getSparqlName(), new URIImpl(svalue));
break;
+ case BNODE:
+ svalue = row.getString(sv.getName());
+ if(svalue != null)
+ resultRow.addBinding(sv.getSparqlName(), new BNodeImpl(svalue));
+ break;
case INT:
if(row.getObject(sv.getName()) != null) {
svalue = Integer.toString(row.getInt(sv.getName()));
@@ -164,31 +169,38 @@ public class KiWiSparqlConnection {
if(svalue != null) {
- // retrieve optional type and language information
- String lang = null;
- URI type = null;
- try {
- lang = row.getString(sv.getName() + "_LANG");
- } catch (SQLException ex) {
- }
+ if (svalue.length() > 0) {
+ // retrieve optional type and language information, because string functions
+ // need to preserve this in certain cases, even when constructing new literals
+ String lang = null;
+ URI type = null;
+ try {
+ lang = row.getString(sv.getName() + "_LANG");
+ } catch (SQLException ex) {
+ }
+
+ try {
+ long typeId = row.getLong(sv.getName() + "_TYPE");
+ if (typeId > 0)
+ type = (URI) parent.loadNodeById(typeId);
+ } catch (SQLException ex) {
+ }
+
+ if (lang != null) {
+ resultRow.addBinding(sv.getSparqlName(), new LiteralImpl(svalue, lang));
+ } else if (type != null) {
+ if(type.stringValue().equals(XSD.String.stringValue())) {
+ // string functions on other datatypes than string should yield no binding
+ resultRow.addBinding(sv.getSparqlName(), new LiteralImpl(svalue, type));
+ }
+ } else {
+ resultRow.addBinding(sv.getSparqlName(), new LiteralImpl(svalue));
+ }
- try {
- long typeId = row.getLong(sv.getName() + "_TYPE");
- if (typeId > 0)
- type = (URI) parent.loadNodeById(typeId);
- } catch (SQLException ex) {
- }
-
- Literal v;
- if(lang != null) {
- v = new LiteralImpl(svalue,lang);
- } else if(type != null) {
- v = new LiteralImpl(svalue,type);
} else {
- v = new LiteralImpl(svalue);
+ // string functions that return empty literal should yield no type or language
+ resultRow.addBinding(sv.getSparqlName(), new LiteralImpl(""));
}
-
- resultRow.addBinding(sv.getSparqlName(), v);
}
break;
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSailConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSailConnection.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSailConnection.java
index bb634af..74ddb8d 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSailConnection.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sail/KiWiSparqlSailConnection.java
@@ -76,8 +76,12 @@ public class KiWiSparqlSailConnection extends NotifyingSailConnectionWrapper {
new ConstantOptimizer(strategy).optimize(tupleExpr, dataset, bindings);
new CompareOptimizer().optimize(tupleExpr, dataset, bindings);
new ConjunctiveConstraintSplitter().optimize(tupleExpr, dataset, bindings);
- new DisjunctiveConstraintOptimizer().optimize(tupleExpr, dataset, bindings);
- new SameTermFilterOptimizer().optimize(tupleExpr, dataset, bindings);
+
+ // these are better handled by SQL directly
+ //new DisjunctiveConstraintOptimizer().optimize(tupleExpr, dataset, bindings);
+ //new SameTermFilterOptimizer().optimize(tupleExpr, dataset, bindings);
+
+
new QueryModelNormalizer().optimize(tupleExpr, dataset, bindings);
new QueryJoinOptimizer(new KiWiEvaluationStatistics()).optimize(tupleExpr, dataset, bindings);
new IterativeEvaluationOptimizer().optimize(tupleExpr, dataset, bindings);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/04899440/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
index ac5d5cd..4da7e31 100644
--- a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
@@ -18,28 +18,6 @@
package org.apache.marmotta.platform.sparql.services.sparql;
import info.aduna.lang.FileFormat;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.commons.vocabulary.SPARQL_SD;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
@@ -52,51 +30,26 @@ import org.apache.marmotta.platform.sparql.api.sparql.SparqlService;
import org.apache.marmotta.platform.sparql.services.sparqlio.rdf.SPARQLGraphResultWriter;
import org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml.SPARQLHTMLSettings;
import org.apache.marmotta.platform.sparql.webservices.SparqlWebService;
-import org.openrdf.model.BNode;
-import org.openrdf.model.Resource;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
+import org.openrdf.model.*;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.model.vocabulary.RDF;
-import org.openrdf.query.Binding;
-import org.openrdf.query.BindingSet;
-import org.openrdf.query.BooleanQuery;
-import org.openrdf.query.GraphQuery;
-import org.openrdf.query.MalformedQueryException;
-import org.openrdf.query.Query;
-import org.openrdf.query.QueryEvaluationException;
-import org.openrdf.query.QueryLanguage;
-import org.openrdf.query.QueryResultHandlerException;
-import org.openrdf.query.TupleQuery;
-import org.openrdf.query.TupleQueryResult;
-import org.openrdf.query.TupleQueryResultHandlerException;
-import org.openrdf.query.Update;
-import org.openrdf.query.UpdateExecutionException;
-import org.openrdf.query.parser.ParsedBooleanQuery;
-import org.openrdf.query.parser.ParsedGraphQuery;
-import org.openrdf.query.parser.ParsedQuery;
-import org.openrdf.query.parser.ParsedTupleQuery;
-import org.openrdf.query.parser.QueryParser;
-import org.openrdf.query.parser.QueryParserUtil;
-import org.openrdf.query.resultio.BooleanQueryResultFormat;
-import org.openrdf.query.resultio.BooleanQueryResultWriter;
-import org.openrdf.query.resultio.QueryResultFormat;
-import org.openrdf.query.resultio.QueryResultIO;
-import org.openrdf.query.resultio.QueryResultWriter;
-import org.openrdf.query.resultio.TupleQueryResultFormat;
-import org.openrdf.query.resultio.TupleQueryResultWriter;
+import org.openrdf.query.*;
+import org.openrdf.query.parser.*;
+import org.openrdf.query.resultio.*;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.RepositoryResult;
-import org.openrdf.rio.RDFFormat;
-import org.openrdf.rio.RDFHandlerException;
-import org.openrdf.rio.RDFWriter;
-import org.openrdf.rio.RDFWriterRegistry;
-import org.openrdf.rio.Rio;
-import org.openrdf.rio.UnsupportedRDFormatException;
+import org.openrdf.rio.*;
import org.slf4j.Logger;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.*;
+import java.util.concurrent.*;
+
/**
* Sparql Service implementation
*
@@ -244,6 +197,7 @@ public class SparqlServiceImpl implements SparqlService {
throw new TimeoutException("SPARQL query execution aborted due to timeout (" + configurationService.getIntConfiguration("sparql.timeout",60)+"s)");
} catch (ExecutionException e) {
log.info("SPARQL query execution aborted due to exception");
+ log.debug("exception details",e);
if(e.getCause() instanceof MarmottaException) {
throw (MarmottaException)e.getCause();
} else if(e.getCause() instanceof MalformedQueryException) {
@@ -308,6 +262,7 @@ public class SparqlServiceImpl implements SparqlService {
throw new TimeoutException("SPARQL query execution aborted due to timeout (" + timeoutInSeconds+"s)");
} catch (ExecutionException e) {
log.info("SPARQL query execution aborted due to exception");
+ log.debug("exception details", e);
if(e.getCause() instanceof MarmottaException) {
throw (MarmottaException)e.getCause();
} else if(e.getCause() instanceof MalformedQueryException) {
@@ -372,6 +327,7 @@ public class SparqlServiceImpl implements SparqlService {
throw new TimeoutException("SPARQL query execution aborted due to timeout (" + configurationService.getIntConfiguration("sparql.timeout",60)+"s)");
} catch (ExecutionException e) {
log.info("SPARQL query execution aborted due to exception");
+ log.debug("exception details", e);
if(e.getCause() instanceof MarmottaException) {
throw (MarmottaException)e.getCause();
} else if(e.getCause() instanceof MalformedQueryException) {