marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wik...@apache.org
Subject [2/2] marmotta git commit: MARMOTTA-640: fixed to warrantied the exact number of both side of the projections of a union
Date Fri, 10 Jun 2016 14:55:46 GMT
MARMOTTA-640: fixed to warrantied the exact number of both side of the projections of a union


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/7df4029d
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/7df4029d
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/7df4029d

Branch: refs/heads/MARMOTTA-640
Commit: 7df4029df21288cc9f6b1b9c041e7d428b644b8f
Parents: 02209d3
Author: Sergio Fernández <wikier@apache.org>
Authored: Fri Jun 10 16:55:25 2016 +0200
Committer: Sergio Fernández <wikier@apache.org>
Committed: Fri Jun 10 16:55:25 2016 +0200

----------------------------------------------------------------------
 .../marmotta/kiwi/sparql/builder/SQLBuilder.java   | 17 ++++-------------
 .../sparql/builder/collect/PatternCollector.java   |  9 +++++----
 .../kiwi/sparql/builder/model/SQLUnion.java        | 10 +++++-----
 .../sparql/optimizer/DistinctLimitOptimizer.java   |  3 +--
 .../kiwi/sparql/sail/KiWiSparqlSailConnection.java |  2 +-
 5 files changed, 16 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/7df4029d/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 f816fa4..e706a7a 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
@@ -350,7 +350,6 @@ public class SQLBuilder {
 
         }
 
-
         // calculate for each variable the SQL expressions representing them and any necessary
JOIN conditions
         for (SQLFragment f : fragments) {
             for (SQLPattern p : f.getPatterns()) {
@@ -493,8 +492,6 @@ public class SQLBuilder {
         prepareConditions();
     }
 
-
-
     private void prepareConditions() throws UnsatisfiableQueryException {
         // build the where clause as follows:
         // 1. iterate over all patterns and for each resource and literal field in subject,
@@ -628,10 +625,12 @@ public class SQLBuilder {
                 if(v.getLiteralTypeExpression() != null) {
                     projections.add(v.getLiteralTypeExpression() + " AS " + projectedName
+ "_TYPE");
                 }
-                
+
                 if(v.getLiteralLangExpression() != null) {
                     projections.add(v.getLiteralLangExpression() + " AS " + projectedName
+ "_LANG");
                 }
+            } else {
+                projections.add("NULL"); //fix for MARMOTTA-460
             }
         }
 
@@ -643,7 +642,6 @@ public class SQLBuilder {
             }
         }
 
-
         StringBuilder selectClause = new StringBuilder();
 
         if(distinct) {
@@ -828,7 +826,6 @@ public class SQLBuilder {
         return groupClause;
     }
 
-
     private StringBuilder buildLimitClause() {
         // construct limit and offset
         StringBuilder limitClause = new StringBuilder();
@@ -847,12 +844,10 @@ public class SQLBuilder {
         return limitClause;
     }
 
-
     private String evaluateExpression(ValueExpr expr, final ValueType optype) {
         return new ValueExpressionEvaluator(expr, this, optype).build();
     }
 
-
     protected ValueType getProjectionType(ValueExpr expr) {
         if(expr instanceof BNodeGenerator) {
             return ValueType.BNODE;
@@ -905,7 +900,6 @@ public class SQLBuilder {
 
     }
 
-
     private String getLiteralLangExpression(ValueExpr expr) {
         Var langVar = new LiteralTypeExpressionFinder(expr).expr;
 
@@ -931,7 +925,6 @@ public class SQLBuilder {
         return null;
     }
 
-
     /**
      * Construct the SQL query for the given SPARQL query part.
      *
@@ -946,8 +939,7 @@ public class SQLBuilder {
         StringBuilder havingClause = buildHavingClause();
         StringBuilder limitClause  = buildLimitClause();
 
-
-        StringBuilder queryString = new StringBuilder();
+        final StringBuilder queryString = new StringBuilder();
         queryString.append("SELECT ");
 
         if(selectClause.length() > 0) {
@@ -978,7 +970,6 @@ public class SQLBuilder {
 
         queryString.append(limitClause);
 
-
         log.debug("original SPARQL syntax tree:\n {}", query);
         log.debug("constructed SQL query string:\n {}",queryString);
         log.debug("SPARQL -> SQL node variable mappings:\n {}", variables);

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7df4029d/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/PatternCollector.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/PatternCollector.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/PatternCollector.java
index e29e619..c935927 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/PatternCollector.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/PatternCollector.java
@@ -42,7 +42,6 @@ public class PatternCollector extends QueryModelVisitorBase<RuntimeException>
{
 
     int counter = 0;
 
-
     private BindingSet bindings;
     private Dataset dataset;
     private ValueConverter converter;
@@ -77,7 +76,6 @@ public class PatternCollector extends QueryModelVisitorBase<RuntimeException>
{
             parts.getLast().getFilters().add(node.getCondition());
         }
         node.getRightArg().visit(this);
-
     }
 
 
@@ -96,18 +94,21 @@ public class PatternCollector extends QueryModelVisitorBase<RuntimeException>
{
     public void meet(Union node) throws RuntimeException {
         // unions are treated as subqueries, don't continue collection, but add the Union
to the last part
 
-        parts.getLast().getSubqueries().add(new SQLUnion(prefix + "U" + (++counter),node,
bindings, dataset, converter, dialect));
+        final SQLUnion union = new SQLUnion(prefix + "U" + (++counter), node, bindings, dataset,
converter, dialect);
+        parts.getLast().getSubqueries().add(union);
     }
 
     @Override
     public void meet(Projection node) throws RuntimeException {
         // subqueries are represented with a projection inside a JOIN; we don't continue
collection
 
-        parts.getLast().getSubqueries().add(new SQLSubQuery(prefix + "S" + (++counter), node,
bindings, dataset, converter, dialect, projectedVars));
+        parts.getLast().getSubqueries().add(new SQLSubQuery(prefix + "S" + (++counter),
+                                            node, bindings, dataset, converter, dialect,
projectedVars));
     }
 
     @Override
     public void meet(Exists node) throws RuntimeException {
         // stop at exists, it is treated as a subquery in the condition part
     }
+
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7df4029d/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/model/SQLUnion.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/model/SQLUnion.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/model/SQLUnion.java
index 3c62785..de08cf2 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/model/SQLUnion.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/model/SQLUnion.java
@@ -72,15 +72,16 @@ public class SQLUnion extends SQLAbstractSubquery {
             }
         }
 
-        Map<String,SQLVariable> rightVars = new HashMap<>();
+        final Map<String,SQLVariable> rightVars = new HashMap<>();
         for(SQLVariable svr : right.getVariables().values()) {
             if(rightProjected.size() == 0 || rightProjected.contains(svr.getSparqlName()))
{
                 rightVars.put(svr.getSparqlName(), svr);
             }
         }
 
-        // we have to homogenize variable names in both subqueries and make sure they have
the same number of columns
-        Map<String,String> sparqlToSQL = new HashMap<>();
+        // we have to homogenize variable names in both subqueries and make sure they have
the same number of columns;
+        // because MARMOTTA-640, this is also handled in SQLBuilder.buildSelectClause()
+        final Map<String,String> sparqlToSQL = new HashMap<>();
         for(SQLVariable svl : left.getVariables().values()) {
             if(leftProjected.size() == 0 || leftProjected.contains(svl.getSparqlName()))
{
                 if (sparqlToSQL.containsKey(svl.getSparqlName())) {
@@ -102,13 +103,12 @@ public class SQLUnion extends SQLAbstractSubquery {
             }
         }
 
-
         for(SQLVariable svl : leftVars.values()) {
             if(!rightVars.containsKey(svl.getSparqlName())) {
                 SQLVariable svr = new SQLVariable(svl.getName(), svl.getSparqlName());
                 svr.getExpressions().add("NULL");
                 svr.setProjectionType(ValueType.NODE);
-                right.getVariables().put(svl.getSparqlName(),svr);
+                right.getVariables().put(svl.getSparqlName(), svr);
 
                 if(rightProjected.size() > 0) {
                     right.getProjectedVars().add(svl.getSparqlName());

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7df4029d/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/optimizer/DistinctLimitOptimizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/optimizer/DistinctLimitOptimizer.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/optimizer/DistinctLimitOptimizer.java
index ca64a6f..f5e8d8f 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/optimizer/DistinctLimitOptimizer.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/optimizer/DistinctLimitOptimizer.java
@@ -79,7 +79,6 @@ public class DistinctLimitOptimizer implements QueryOptimizer {
             allowed = false;
         }
 
-
         @Override
         public void meet(Union node) throws RuntimeException {
             super.meet(node);
@@ -87,7 +86,6 @@ public class DistinctLimitOptimizer implements QueryOptimizer {
             allowed = false;
         }
 
-
         @Override
         public void meet(Filter node) throws RuntimeException {
             // break traversal
@@ -101,6 +99,7 @@ public class DistinctLimitOptimizer implements QueryOptimizer {
         public boolean isAllowed() {
             return allowed;
         }
+
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7df4029d/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 3c77ead..0d2a35b 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
@@ -70,7 +70,7 @@ public class KiWiSparqlSailConnection extends NotifyingSailConnectionWrapper
{
         }
 
         try {
-            KiWiTripleSource tripleSource = new KiWiTripleSource(this,valueFactory,includeInferred);
+            KiWiTripleSource tripleSource = new KiWiTripleSource(this, valueFactory, includeInferred);
             EvaluationStrategy strategy = new KiWiEvaluationStrategy(tripleSource, dataset,
connection, valueFactory);
 
             new BindingAssigner().optimize(tupleExpr, dataset, bindings);


Mime
View raw message