jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject svn commit: r1556180 - in /jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index: IndexFactory.java SetIndexTable.java
Date Tue, 07 Jan 2014 11:15:23 GMT
Author: rvesse
Date: Tue Jan  7 11:15:23 2014
New Revision: 1556180

URL: http://svn.apache.org/r1556180
Log:
Optimize the case of MINUS where there is only a single common variable (relates to JENA-615)

Added:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/SetIndexTable.java
Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/IndexFactory.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/IndexFactory.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/IndexFactory.java?rev=1556180&r1=1556179&r2=1556180&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/IndexFactory.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/IndexFactory.java
Tue Jan  7 11:15:23 2014
@@ -22,7 +22,7 @@ import java.util.Set;
 
 import com.hp.hpl.jena.sparql.core.Var;
 import com.hp.hpl.jena.sparql.engine.QueryIterator;
-import com.hp.hpl.jena.sparql.engine.index.HashIndexTable.MissingBindingException ;
+import com.hp.hpl.jena.sparql.engine.index.HashIndexTable.MissingBindingException;
 
 /**
  * Creates {@link com.hp.hpl.jena.sparql.engine.index.IndexTable}s for use by
@@ -32,13 +32,15 @@ import com.hp.hpl.jena.sparql.engine.ind
  */
 public class IndexFactory {
 
-	public static IndexTable createIndex(Set<Var> commonVars, QueryIterator data)
-	{
-		try {
-			return new HashIndexTable(commonVars, data) ;
-		} catch (MissingBindingException e) {
-			return new LinearIndex(commonVars, data, e.getData(), e.getMap()) ;
-		}
-	}
+    public static IndexTable createIndex(Set<Var> commonVars, QueryIterator data) {
+        try {
+            if (commonVars.size() == 1) {
+                return new SetIndexTable(commonVars, data);
+            } else {
+                return new HashIndexTable(commonVars, data);
+            }
+        } catch (MissingBindingException e) {
+            return new LinearIndex(commonVars, data, e.getData(), e.getMap());
+        }
+    }
 }
-

Added: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/SetIndexTable.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/SetIndexTable.java?rev=1556180&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/SetIndexTable.java
(added)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/index/SetIndexTable.java
Tue Jan  7 11:15:23 2014
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2014 YarcData LLC All Rights Reserved.
+ */
+
+package com.hp.hpl.jena.sparql.engine.index;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.sparql.core.Var;
+import com.hp.hpl.jena.sparql.engine.QueryIterator;
+import com.hp.hpl.jena.sparql.engine.binding.Binding;
+
+/**
+ * An {@link IndexTable} implementation optimized for the case where there is
+ * only a single common variable
+ * 
+ */
+public class SetIndexTable implements IndexTable {
+
+    private Var var;
+    private Set<Node> values = new HashSet<Node>();
+
+    /**
+     * Creates a new index table
+     * 
+     * @param commonVars
+     *            Common Variables
+     * @param data
+     *            Data
+     */
+    public SetIndexTable(Set<Var> commonVars, QueryIterator data) {
+        if (commonVars.size() != 1)
+            throw new IllegalArgumentException("Common Variables must be of size 1");
+
+        this.var = commonVars.iterator().next();
+        while (data.hasNext()) {
+            Binding binding = data.next();
+            Node value = binding.get(this.var);
+
+            if (value == null)
+                continue;
+            this.values.add(value);
+        }
+    }
+
+    @Override
+    public boolean containsCompatibleWithSharedDomain(Binding binding) {
+        Node value = binding.get(this.var);
+        if (value == null)
+            return true;
+        return this.values.contains(value);
+    }
+
+}



Mime
View raw message