Repository: marmotta Updated Branches: refs/heads/develop d63fbaedf -> bde0f5179
SPARQL: - avoid creating multiple joins with nodes table for a variable Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/bde0f517 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/bde0f517 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/bde0f517 Branch: refs/heads/develop Commit: bde0f5179a8bd67235e225043cd11d59bbad5cc2 Parents: d63fbae Author: Sebastian Schaffert <[email protected]> Authored: Thu Nov 6 19:17:58 2014 +0100 Committer: Sebastian Schaffert <[email protected]> Committed: Thu Nov 6 19:17:58 2014 +0100 ---------------------------------------------------------------------- .../apache/marmotta/kiwi/sparql/builder/SQLBuilder.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/bde0f517/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 ea2ae56..b6d69c0 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 @@ -251,7 +251,7 @@ public class SQLBuilder { String pName = p.getName(); String vName = sv.getName(); - if (new ConditionFinder(v.getName(), query).found) { + if (sv.getAlias() == null && new ConditionFinder(v.getName(), query).found) { sv.setAlias(pName + "_" + positions[i] + "_" + vName); } @@ -277,7 +277,7 @@ public class SQLBuilder { String sqName = sq.getAlias(); String vName = sv.getName(); - if (new ConditionFinder(sq_v.getSparqlName(), query).found) { + if (sv.getAlias() == null && new ConditionFinder(sq_v.getSparqlName(), query).found) { sv.setAlias(sqName + "_" + vName); } @@ -519,6 +519,7 @@ public class SQLBuilder { // in any filters or functions; in this case, the corresponding field needs to be joined with the NODES table // and we need to mark the pattern accordingly. boolean first = true; + Set<String> joined = new HashSet<>(); for(SQLFragment f : fragments) { if(first && f.getConditionPosition() == SQLFragment.ConditionPosition.JOIN) { // the conditions of the first fragment need to be placed in the WHERE part of the query, because @@ -529,18 +530,21 @@ public class SQLBuilder { for (SQLPattern p : f.getPatterns()) { for(Map.Entry<SQLPattern.TripleColumns, Var> fieldEntry : p.getTripleFields().entrySet()) { - if(fieldEntry.getValue() != null && !fieldEntry.getValue().hasValue() && new ConditionFinder(fieldEntry.getValue().getName(),query).found) { + if(fieldEntry.getValue() != null && !fieldEntry.getValue().hasValue() && !joined.contains(fieldEntry.getValue().getName()) + && new ConditionFinder(fieldEntry.getValue().getName(),query).found) { p.setJoinField(fieldEntry.getKey(), variables.get(fieldEntry.getValue().getName()).getName()); + joined.add(fieldEntry.getValue().getName()); } } } for(SQLAbstractSubquery sq : f.getSubqueries()) { for(SQLVariable sq_v : sq.getQueryVariables()) { - if(new ConditionFinder(sq_v.getSparqlName(),query).found && sq_v.getProjectionType() == ProjectionType.NODE) { + if(!joined.contains(sq_v.getName()) && new ConditionFinder(sq_v.getSparqlName(),query).found && sq_v.getProjectionType() == ProjectionType.NODE) { // this is needed in case we need to JOIN with the NODES table to retrieve values SQLVariable sv = variables.get(sq_v.getSparqlName()); // fetch the name of the variable in the enclosing query sq.getJoinFields().add(new SQLAbstractSubquery.VariableMapping(sv.getName(), sq_v.getName())); + joined.add(sv.getName()); } } }
