You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/06/02 12:41:04 UTC

[1/6] jena git commit: Not used directly in DISTINCT evaluation anymore. javadoc corrected.

Repository: jena
Updated Branches:
  refs/heads/master cb18f7482 -> bcba645a5


Not used directly in DISTINCT evaluation anymore. javadoc corrected.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/2a9b731f
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/2a9b731f
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/2a9b731f

Branch: refs/heads/master
Commit: 2a9b731f65a964a030c977d63890b56d5204f51f
Parents: cb18f74
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 2 11:10:37 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 2 11:10:37 2015 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/jena/atlas/data/DistinctDataNet.java | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/2a9b731f/jena-arq/src/main/java/org/apache/jena/atlas/data/DistinctDataNet.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/data/DistinctDataNet.java b/jena-arq/src/main/java/org/apache/jena/atlas/data/DistinctDataNet.java
index 61a4405..5853138 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/data/DistinctDataNet.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/data/DistinctDataNet.java
@@ -37,8 +37,7 @@ import org.apache.jena.atlas.lib.FileOps ;
  * added was known to be distinct.  This will normally only work until the first spill.  After that,
  * the system may not be able to tell for sure, and will thus return false.  When you are finished
  * adding items, you may call {@link #netIterator()} to get any distinct items that are in the
- * spill files but were not indicated as distinct previously.  This is useful for a distinct
- * operator that streams results until it exceeds the spill threshold.
+ * spill files but were not indicated as distinct previously.
  */
 public class DistinctDataNet<E> extends DistinctDataBag<E>
 {


[4/6] jena git commit: Note that TopN limit must be less than the spill-to-disk for Distinct.

Posted by an...@apache.org.
Note that TopN limit must be less than the spill-to-disk for Distinct.

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

Branch: refs/heads/master
Commit: a5f3c8e2254d3594a56c01c945b257cbce7d48c8
Parents: 244ebeb
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 2 11:34:08 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 2 11:34:08 2015 +0100

----------------------------------------------------------------------
 .../org/apache/jena/sparql/algebra/optimize/TransformTopN.java     | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/a5f3c8e2/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java
index 56c2f08..2c49133 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java
@@ -40,6 +40,8 @@ import org.apache.jena.sparql.util.Symbol ;
  */
 public class TransformTopN extends TransformCopy {
 
+    // This must be less than ARQ.spillToDiskThreshold.
+    // Otherwise DISTINCT ends up reordering. 
 	private static final int defaultTopNSortingThreshold = 1000;
 	public static final Symbol externalSortBufferSize = ARQConstants.allocSymbol("topNSortingThreshold") ;
 


[6/6] jena git commit: Set the threshold correctly.

Posted by an...@apache.org.
Set the threshold correctly.

Use a data bag, not a data net, as we don't use the early notification
of uniqueness anymore.  See JENA-949.

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

Branch: refs/heads/master
Commit: bcba645a561866545705c0e73beae143a15fb3d9
Parents: fecd978
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 2 11:39:05 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 2 11:39:05 2015 +0100

----------------------------------------------------------------------
 .../engine/iterator/QueryIterDistinct.java      | 45 ++++++++++----------
 .../iterator/AbstractTestDistinctReduced.java   |  1 -
 2 files changed, 23 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/bcba645a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterDistinct.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterDistinct.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterDistinct.java
index a88cb39..d373ce6 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterDistinct.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterDistinct.java
@@ -20,13 +20,12 @@ package org.apache.jena.sparql.engine.iterator ;
 
 import java.util.* ;
 
-import org.apache.jena.atlas.data.BagFactory ;
-import org.apache.jena.atlas.data.DistinctDataNet ;
-import org.apache.jena.atlas.data.ThresholdPolicy ;
-import org.apache.jena.atlas.data.ThresholdPolicyFactory ;
+import org.apache.jena.atlas.data.* ;
 import org.apache.jena.atlas.lib.InternalErrorException ;
+import org.apache.jena.query.ARQ ;
 import org.apache.jena.query.SortCondition ;
 import org.apache.jena.riot.system.SerializationFactoryFinder ;
+import org.apache.jena.sparql.ARQException ;
 import org.apache.jena.sparql.engine.ExecutionContext ;
 import org.apache.jena.sparql.engine.QueryIterator ;
 import org.apache.jena.sparql.engine.binding.Binding ;
@@ -39,23 +38,23 @@ import org.apache.jena.sparql.engine.binding.BindingProjectNamed ;
  * {@link DistinctDataNet}, then yield   
  * not  return any results until the input iterator has been exhausted.
  * 
- * @see DistinctDataNet
+ * @see DistinctDataBag
  */
 public class QueryIterDistinct extends QueryIter1
 {
-    private int Threshold1 = 3 ;
-    private DistinctDataNet<Binding> db = null ;
+    private long memThreshold = Long.MAX_VALUE ;    // Default "off" value.
+    private DistinctDataBag<Binding> db = null ;
     private Iterator<Binding> iterator = null ;
     private Set<Binding> seen = new HashSet<>() ;
     private Binding slot = null ;
 
-    public QueryIterDistinct(QueryIterator qIter, ExecutionContext context) {
-        super(qIter, context) ;
-    }
-    
-    public QueryIterDistinct(QueryIterator qIter, ExecutionContext context, int threshold1) {
-        super(qIter, context) ;
-        this.Threshold1 = threshold1 ;
+    public QueryIterDistinct(QueryIterator qIter, ExecutionContext execCxt) {
+        super(qIter, execCxt) ;
+        if ( execCxt != null ) {
+            memThreshold = execCxt.getContext().getLong(ARQ.spillToDiskThreshold, memThreshold) ;
+            if ( memThreshold < 0 )
+                throw new ARQException("BAd spillToDiskThreshold: "+memThreshold) ;
+        }
     }
     
     @Override
@@ -67,7 +66,7 @@ public class QueryIterDistinct extends QueryIter1
             return iterator.hasNext() ;
        
         // At this point, we are currently in the initial pre-threshold mode.
-        if ( seen.size() >= Threshold1 ) {
+        if ( seen.size() < memThreshold ) {
             Binding b = getInputNextUnseen() ;
             if ( b == null )
                 return false ;
@@ -76,18 +75,19 @@ public class QueryIterDistinct extends QueryIter1
             return true ;
         }
         
-        // Hit the threashold.
+        // Hit the threshold.
         loadDataBag() ;
-        // Switch to iterating from the databad.  
+        // Switch to iterating from the data bag.  
         iterator = db.iterator() ;
         // Leave slot null.
         return iterator.hasNext() ;
     }
     
+    /** Load the data bag with. Filter incoming by the already seen in-memory elements */  
     private void loadDataBag() {
         ThresholdPolicy<Binding> policy = ThresholdPolicyFactory.policyFromContext(super.getExecContext().getContext()) ;
         Comparator<Binding> comparator = new BindingComparator(new ArrayList<SortCondition>(), super.getExecContext()) ;
-        this.db = BagFactory.newDistinctNet(policy, SerializationFactoryFinder.bindingSerializationFactory(), comparator) ;
+        this.db = BagFactory.newDistinctBag(policy, SerializationFactoryFinder.bindingSerializationFactory(), comparator) ;
         for(;;) {
             Binding b = getInputNextUnseen() ;
             if ( b == null )
@@ -96,9 +96,10 @@ public class QueryIterDistinct extends QueryIter1
         }
     }
     
-    // Return the next binding from the input filtered by seen.
-    // This does not update seen.
-    // Returns null on end of input.
+    /** Return the next binding from the input filtered by seen.
+     * This does not update seen.
+     * Returns null on end of input.
+    */
     private Binding getInputNextUnseen() {
         while( getInput().hasNext() ) {
             Binding b = getInputNext() ;
@@ -109,7 +110,7 @@ public class QueryIterDistinct extends QueryIter1
         return null ;
     }
 
-    // Return the next wrapped binding from the input.
+    /** Return the binding from the input, hiding any variables to be ignored. */
     private Binding getInputNext() {
         Binding b = getInput().next() ;
         // Hide unnamed and internal variables.

http://git-wip-us.apache.org/repos/asf/jena/blob/bcba645a/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/AbstractTestDistinctReduced.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/AbstractTestDistinctReduced.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/AbstractTestDistinctReduced.java
index d9b5ec3..ac37b63 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/AbstractTestDistinctReduced.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/AbstractTestDistinctReduced.java
@@ -77,7 +77,6 @@ public abstract class AbstractTestDistinctReduced extends BaseTest {
         distinct(data, results) ;
     }
 
-
     private void distinct(List<String> data, List<String> results) {
         // Distinct Iterators are not required to preserve order.
         List<Binding> input = build(data) ;


[3/6] jena git commit: Use Context::getLong.

Posted by an...@apache.org.
Use Context::getLong.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/244ebeb8
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/244ebeb8
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/244ebeb8

Branch: refs/heads/master
Commit: 244ebeb84a3e9a7e3e11ce59c537e399a8e2b9cf
Parents: faa8b59
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 2 11:11:32 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 2 11:11:32 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/jena/atlas/data/ThresholdPolicyFactory.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/244ebeb8/jena-arq/src/main/java/org/apache/jena/atlas/data/ThresholdPolicyFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/data/ThresholdPolicyFactory.java b/jena-arq/src/main/java/org/apache/jena/atlas/data/ThresholdPolicyFactory.java
index 226de58..7d2354f 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/data/ThresholdPolicyFactory.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/data/ThresholdPolicyFactory.java
@@ -70,7 +70,7 @@ public class ThresholdPolicyFactory
      */
     public static <E> ThresholdPolicy<E> policyFromContext(Context context)
     {
-        long threshold = (Long) context.get(ARQ.spillToDiskThreshold, defaultThreshold) ;
+        long threshold = context.getLong(ARQ.spillToDiskThreshold, defaultThreshold) ;
         if ( threshold >= 0 )
         {
             return count(threshold);


[2/6] jena git commit: Add getInt and getLong.

Posted by an...@apache.org.
Add getInt and getLong.

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

Branch: refs/heads/master
Commit: faa8b59dd897baa847099803f85de6dff17ff41f
Parents: 2a9b731
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 2 11:11:12 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 2 11:11:12 2015 +0100

----------------------------------------------------------------------
 .../org/apache/jena/sparql/util/Context.java    | 404 +++++++++++--------
 .../apache/jena/sparql/core/TestContext.java    | 102 +++--
 2 files changed, 299 insertions(+), 207 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/faa8b59d/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
index f8c8ed9..6593271 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
@@ -1,94 +1,105 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
  */
 
-package org.apache.jena.sparql.util;
+package org.apache.jena.sparql.util ;
 
 import java.util.* ;
 
 import org.apache.jena.atlas.lib.Callback ;
+import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.sparql.ARQConstants ;
 import org.apache.jena.sparql.ARQException ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 
-/** A class for setting and keeping named values.  Used to pass 
- *  implementation-specific parameters across general
- *  interfaces. */  
+/**
+ * A class for setting and keeping named values. Used to pass
+ * implementation-specific parameters across general interfaces.
+ */
+
+public class Context {
+    public static final Context      emptyContext = new Context(true) ;
+
+    protected Map<Symbol, Object>    context      = new HashMap<>() ;
+    protected List<Callback<Symbol>> callbacks    = new ArrayList<>() ;
+    protected boolean                readonly     = false ;
 
-public class Context
-{
-    public static final Context emptyContext = new Context(true) ;
-    
-    protected Map<Symbol, Object> context = new HashMap<>() ;
-    protected List<Callback<Symbol>> callbacks = new ArrayList<>() ;
-    protected boolean readonly = false ;
-    
     /** Create an empty context */
-    public Context()
-    { }
-    
+    public Context() {}
+
     /* Create an empty context, mark it's readonly state */
-    private Context(boolean readonly)
-    { 
+    private Context(boolean readonly) {
         this.readonly = readonly ;
     }
 
-    /** Create a context and initialize it with a copy of the named values of another one.
-     *  Shallow copy: the values themselves are not copied
-     */ 
-    public Context(Context cxt)
-    { putAll(cxt) ; }
-    
-    /** Return a copy of this context.  Modifications of the copy 
-     * do not affect the original context.
-     */ 
-    public Context copy() { return new Context(this) ; }
-    
+    /**
+     * Create a context and initialize it with a copy of the named values of
+     * another one. Shallow copy: the values themselves are not copied
+     */
+    public Context(Context cxt) {
+        putAll(cxt) ;
+    }
+
+    /**
+     * Return a copy of this context. Modifications of the copy do not affect
+     * the original context.
+     */
+    public Context copy() {
+        return new Context(this) ;
+    }
+
     // -- basic operations
-    
-    /** Get the object value of a property or null */ 
-    public Object get(Symbol property) { return context.get(property) ; }
-    
-    /** Get the object value of a property - return the default value if not present . */ 
-    public Object get(Symbol property, Object defaultValue)
-    { 
+
+    /** Get the object value of a property or null */
+    public Object get(Symbol property) {
+        return context.get(property) ;
+    }
+
+    /**
+     * Get the object value of a property - return the default value if not
+     * present .
+     */
+    public Object get(Symbol property, Object defaultValue) {
         Object x = context.get(property) ;
         if ( x == null )
             return defaultValue ;
         return x ;
     }
-    
+
     /** Store a named value - overwrites any previous set value */
-    public void put(Symbol property, Object value) { _put(property, value) ; doCallbacks(property) ; }
-    
+    public void put(Symbol property, Object value) {
+        _put(property, value) ;
+        doCallbacks(property) ;
+    }
+
     /** Store a named value - overwrites any previous set value */
-    public void set(Symbol property, Object value) { _put(property, value) ; doCallbacks(property) ; }
-    
-    private void _put(Symbol property, Object value)
-    {
+    public void set(Symbol property, Object value) {
+        _put(property, value) ;
+        doCallbacks(property) ;
+    }
+
+    private void _put(Symbol property, Object value) {
         if ( readonly )
             throw new ARQException("Context is readonly") ;
-        context.put(property, value) ; 
+        context.put(property, value) ;
     }
 
     /** Store a named value - overwrites any previous set value */
-    public void   set(Symbol property, boolean value)
-    { 
+    public void set(Symbol property, boolean value) {
         if ( value )
             setTrue(property) ;
         else
@@ -96,34 +107,45 @@ public class Context
     }
 
     /** Store a named value only if it is not currently set */
-    public void  setIfUndef(Symbol property, Object value)
-    { 
+    public void setIfUndef(Symbol property, Object value) {
         Object x = context.get(property) ;
         if ( x == null )
             put(property, value) ;
     }
 
     /** Remove any value associated with a property */
-    public void remove(Symbol property) { context.remove(property) ; doCallbacks(property) ; }
+    public void remove(Symbol property) {
+        context.remove(property) ;
+        doCallbacks(property) ;
+    }
 
     /** Remove any value associated with a property - alternative method name */
-    public void unset(Symbol property) { context.remove(property) ; doCallbacks(property) ; }
-    
+    public void unset(Symbol property) {
+        context.remove(property) ;
+        doCallbacks(property) ;
+    }
+
     // ---- Helpers
-    
+
     // -- Existence
-    
+
     /** Is a property set? */
-    public boolean isDefined(Symbol property) { return context.containsKey(property) ; }
+    public boolean isDefined(Symbol property) {
+        return context.containsKey(property) ;
+    }
 
     /** Is a property not set? */
-    public boolean isUndef(Symbol property) { return ! isDefined(property) ; }
-    
+    public boolean isUndef(Symbol property) {
+        return !isDefined(property) ;
+    }
+
     // -- as string
 
-    /** Get the value a string (uses .toString() if the value is not null) - supply a default string value */
-    public String getAsString(Symbol property, String defaultValue)
-    {
+    /**
+     * Get the value a string (uses .toString() if the value is not null) -
+     * supply a default string value
+     */
+    public String getAsString(Symbol property, String defaultValue) {
         String x = getAsString(property) ;
         if ( x == null )
             return defaultValue ;
@@ -131,87 +153,119 @@ public class Context
     }
 
     /** Get the value a string (uses .toString() if the value is not null) */
-    public String getAsString(Symbol property)
-    { 
+    public String getAsString(Symbol property) {
         Object x = context.get(property) ;
         if ( x == null )
             return null ;
         return x.toString() ;
     }
+    
+    /** Get the value as a a long value. The context entry can be a string, Integer or Long. */
+    public int getInt(Symbol symbol, int defaultValue) {
+        if (  isUndef(symbol) )
+            return defaultValue ; 
+        Object obj = context.get(symbol) ;
+        if ( obj instanceof String ) {
+            return Integer.parseInt((String)obj) ;
+        } else if ( obj instanceof Integer ) {
+            return ((Integer)obj).intValue() ;
+        } else {
+            throw new ARQException("Value for "+symbol+" is not a recoginized class: "+Lib.className(obj)) ;
+        }
+    }
 
-    public void putAll(Context other)
-    {
+    /** Get the value as a a long value. The context entry can be a string, Integer or Long. */
+    public long getLong(Symbol symbol, long defaultValue) {
+        if (  isUndef(symbol) )
+            return defaultValue ; 
+        Object obj = context.get(symbol) ;
+        if ( obj instanceof String ) {
+            return Long.parseLong((String)obj) ;
+        } else if ( obj instanceof Integer ) {
+            return ((Integer)obj).intValue() ;
+        } else if ( obj instanceof Long ) {
+            return ((Long)obj) ;
+        } else {
+            throw new ARQException("Value for "+symbol+" is not a recoginized class: "+Lib.className(obj)) ;
+        }
+    }
+    
+    public void putAll(Context other) {
         if ( readonly )
             throw new ARQException("Context is readonly") ;
-        if ( other != null )
-        {
+        if ( other != null ) {
             for ( Map.Entry<Symbol, Object> e : other.context.entrySet() )
                 put(e.getKey(), e.getValue()) ;
         }
     }
-    
+
     // -- true/false
-    
+
     /** Set propety value to be true */
-    public void setTrue(Symbol property) { set(property, Boolean.TRUE) ; } 
-    
+    public void setTrue(Symbol property) {
+        set(property, Boolean.TRUE) ;
+    }
+
     /** Set propety value to be false */
-    public void setFalse(Symbol property) { set(property, Boolean.FALSE) ; } 
+    public void setFalse(Symbol property) {
+        set(property, Boolean.FALSE) ;
+    }
 
     /** Is the value 'true' (either set to the string "true" or Boolean.TRUE) */
-    public boolean isTrue(Symbol property)
-    { return isTrue(property, false) ; } 
-    
-    /** Is the value 'true' (either set to the string "true" or Boolean.TRUE) 
-     * or undefined? 
+    public boolean isTrue(Symbol property) {
+        return isTrue(property, false) ;
+    }
+
+    /**
+     * Is the value 'true' (either set to the string "true" or Boolean.TRUE) or
+     * undefined?
      */
-    public boolean isTrueOrUndef(Symbol property)
-    { return isTrue(property, true) ; }
-    
-    private boolean isTrue(Symbol property, boolean dft)
-    {
+    public boolean isTrueOrUndef(Symbol property) {
+        return isTrue(property, true) ;
+    }
+
+    private boolean isTrue(Symbol property, boolean dft) {
         Object x = get(property) ;
         if ( x == null )
             return dft ;
-        if ( x instanceof String )
-        {
+        if ( x instanceof String ) {
             String s = (String)x ;
-            if ( s.equalsIgnoreCase("true") ) 
+            if ( s.equalsIgnoreCase("true") )
                 return true ;
         }
         return x.equals(Boolean.TRUE) ;
     }
-    
+
     /** Is the value 'false' (either set to the string "false" or Boolean.FALSE) */
-    public boolean isFalse(Symbol property)
-    { return isFalse(property, false) ; } 
-    
-    /** Is the value 'false' (either set to the string "false" or Boolean.FALSE) 
-     * or undefined 
+    public boolean isFalse(Symbol property) {
+        return isFalse(property, false) ;
+    }
+
+    /**
+     * Is the value 'false' (either set to the string "false" or Boolean.FALSE)
+     * or undefined
      */
-    public boolean isFalseOrUndef(Symbol property)
-    { return isFalse(property, true) ; }
-    
-    private boolean isFalse(Symbol property, boolean dft)
-    {
+    public boolean isFalseOrUndef(Symbol property) {
+        return isFalse(property, true) ;
+    }
+
+    private boolean isFalse(Symbol property, boolean dft) {
         Object x = get(property) ;
         if ( x == null )
             return dft ;
-        if ( x instanceof String )
-        {
+        if ( x instanceof String ) {
             String s = (String)x ;
-            if ( s.equalsIgnoreCase("false") ) 
+            if ( s.equalsIgnoreCase("false") )
                 return true ;
         }
         return x.equals(Boolean.FALSE) ;
     }
 
-    // -- Test for value 
+    // -- Test for value
 
     /** Test whether a named value is a specific value (.equals) */
-    
-    public boolean hasValue(Symbol property, Object value)
-    {
+
+    public boolean hasValue(Symbol property, Object value) {
         Object x = get(property) ;
         if ( x == null && value == null )
             return true ;
@@ -221,96 +275,106 @@ public class Context
     }
 
     /** Test whether a named value (as a string) has a specific string form */
-    
-    public boolean hasValueAsString(Symbol property, String value)
-    {
-        return  hasValueAsString(property, value, false) ;
+
+    public boolean hasValueAsString(Symbol property, String value) {
+        return hasValueAsString(property, value, false) ;
     }
-    
-    /** Test whether a named value (as a string) has a specific string form - can ignore case */
-    public boolean hasValueAsString(Symbol property, String value, boolean ignoreCase)
-    {
+
+    /**
+     * Test whether a named value (as a string) has a specific string form - can
+     * ignore case
+     */
+    public boolean hasValueAsString(Symbol property, String value, boolean ignoreCase) {
         String s = getAsString(property) ;
         if ( s == null && value == null )
             return true ;
         if ( s == null || value == null )
             return false ;
-        
+
         if ( ignoreCase )
             return s.equalsIgnoreCase(value) ;
         return s.equals(value) ;
     }
-    
-    /** Set of properties (as Symbols) currently defined */  
-    public Set<Symbol> keys() { return context.keySet() ; }
 
-    /** Return the number of context items */ 
-    public int size() { return context.size() ; }
+    /** Set of properties (as Symbols) currently defined */
+    public Set<Symbol> keys() {
+        return context.keySet() ;
+    }
+
+    /** Return the number of context items */
+    public int size() {
+        return context.size() ;
+    }
+
+    // @Override
+    // public int hashCode()
+    // {
+    // return context.hashCode() ;
+    // }
+    //
+    // @Override
+    // public boolean equals(Object other)
+    // {
+    // if ( this == other ) return true ;
+    //
+    // if ( ! ( other instanceof Context ) ) return false ;
+    // Context cxt = (Context)other ;
+    // return context.equals(cxt.context) ;
+    // }
 
-    
-//    @Override
-//    public int hashCode()
-//    {
-//        return context.hashCode() ;
-//    }
-//    
-//    @Override
-//    public boolean equals(Object other)
-//    {
-//        if ( this == other ) return true ;
-//
-//        if ( ! ( other instanceof Context ) ) return false ;
-//        Context cxt = (Context)other ;
-//        return context.equals(cxt.context) ;
-//    }
-    
     // ---- Callbacks
-    public void addCallback(Callback<Symbol> m) { callbacks.add(m) ; }
-    public void removeCallback(Callback<Symbol> m) { callbacks.remove(m) ; }
-    public List<Callback<Symbol>> getCallbacks() { return callbacks ; }
-    
-    private void doCallbacks(Symbol symbol)
-    {
-        for ( Callback<Symbol> c : callbacks )
-        {
+    public void addCallback(Callback<Symbol> m) {
+        callbacks.add(m) ;
+    }
+
+    public void removeCallback(Callback<Symbol> m) {
+        callbacks.remove(m) ;
+    }
+
+    public List<Callback<Symbol>> getCallbacks() {
+        return callbacks ;
+    }
+
+    private void doCallbacks(Symbol symbol) {
+        for ( Callback<Symbol> c : callbacks ) {
             c.apply(symbol) ;
         }
     }
-    
+
     @Override
-    public String toString()
-    {
+    public String toString() {
         String x = "" ;
         String sep = "" ;
-        for ( Symbol s : keys() )
-        {
+        for ( Symbol s : keys() ) {
             Object value = get(s) ;
             x = x + sep + s + " = " + value ;
             sep = "\n" ;
         }
         return x ;
     }
-    
+
     // Put any per-dataset execution global configuration state here.
-    public static Context setupContext(Context context, DatasetGraph dataset)
-    {
+    public static Context setupContext(Context context, DatasetGraph dataset) {
         if ( context == null )
-            context = ARQ.getContext() ;    // Already copied?
+            context = ARQ.getContext() ; // Already copied?
         context = context.copy() ;
 
         if ( dataset != null && dataset.getContext() != null )
             // Copy per-dataset settings.
             context.putAll(dataset.getContext()) ;
-        
+
         context.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime()) ;
-        
+
         // Allocators.
-//        context.set(ARQConstants.sysVarAllocNamed, new VarAlloc(ARQConstants.allocVarMarkerExec)) ;
-//        context.set(ARQConstants.sysVarAllocAnon,  new VarAlloc(ARQConstants.allocVarAnonMarkerExec)) ;
-        // Add VarAlloc for variables and bNodes (this is not the parse name). 
-        // More added later e.g. query (if there is a query), algebra form (in setOp)
-        
-        return context ; 
+        // context.set(ARQConstants.sysVarAllocNamed, new
+        // VarAlloc(ARQConstants.allocVarMarkerExec)) ;
+        // context.set(ARQConstants.sysVarAllocAnon, new
+        // VarAlloc(ARQConstants.allocVarAnonMarkerExec)) ;
+        // Add VarAlloc for variables and bNodes (this is not the parse name).
+        // More added later e.g. query (if there is a query), algebra form (in
+        // setOp)
+
+        return context ;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/faa8b59d/jena-arq/src/test/java/org/apache/jena/sparql/core/TestContext.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/core/TestContext.java b/jena-arq/src/test/java/org/apache/jena/sparql/core/TestContext.java
index 0be5927..5dc0e46 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/core/TestContext.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/core/TestContext.java
@@ -1,38 +1,40 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
  */
 
-package org.apache.jena.sparql.core;
+package org.apache.jena.sparql.core ;
 
 import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.sparql.ARQException ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.Symbol ;
 import org.junit.Test ;
 
-public class TestContext extends BaseTest
-{
+public class TestContext extends BaseTest {
     static Symbol p1 = Symbol.create("p1") ;
     static Symbol p2 = Symbol.create("p2") ;
-    
-    @Test public void testCxt1() { Context cxt = new Context(); }
-    
-    @Test public void testCxt2()
-    { 
-        Context cxt = new Context();
+
+    @Test
+    public void testCxt1() {
+        Context cxt = new Context() ;
+    }
+
+    @Test
+    public void testCxt2() {
+        Context cxt = new Context() ;
         assertTrue("Defined in empty context", !cxt.isDefined(p1)) ;
         cxt.set(p1, "v") ;
         assertTrue("Not defined after .set", cxt.isDefined(p1)) ;
@@ -40,41 +42,67 @@ public class TestContext extends BaseTest
         assertSame("Not the same", "v", v) ;
     }
 
-    @Test public void testCxt3()
-    { 
-        Context cxt = new Context();
+    @Test
+    public void testCxt3() {
+        Context cxt = new Context() ;
         cxt.set(p1, "v") ;
         cxt.setIfUndef(p1, "w") ;
         Object v = cxt.get(p1) ;
         assertSame("Not as first set", "v", v) ;
     }
 
-    @Test public void testCxt4()
-    { 
-        Context cxt = new Context();
+    @Test
+    public void testCxt4() {
+        Context cxt = new Context() ;
         cxt.set(p1, "true") ;
         assertTrue("Not true", cxt.isTrue(p1)) ;
         assertTrue("Not true or undef", cxt.isTrueOrUndef(p1)) ;
-        
+
         assertTrue("Not false or undef", cxt.isFalseOrUndef(p2)) ;
         assertTrue("False when undef", !cxt.isFalse(p2)) ;
     }
 
-    @Test public void testCxt5()
-    { 
-        Context cxt = new Context();
+    @Test
+    public void testCxt5() {
+        Context cxt = new Context() ;
         cxt.set(p1, "false") ;
         assertTrue("Not false", cxt.isFalse(p1)) ;
         assertTrue("Not false or undef", cxt.isFalseOrUndef(p1)) ;
     }
-    
-    @Test public void testCxt6()
-    { 
-        Context cxt = new Context();
+
+    @Test
+    public void testCxt6() {
+        Context cxt = new Context() ;
         cxt.setTrue(p1) ;
         assertTrue("Not true", cxt.isTrue(p1)) ;
         String x = cxt.getAsString(p1) ;
         assertEquals("Not string 'true'", "true", x) ;
     }
 
+    @Test
+    public void testCxt7() {
+        Context cxt = new Context() ;
+        assertEquals(-1, cxt.getInt(p1, -1)) ;
+        cxt.set(p1, 1) ;
+        int x = cxt.getInt(p1, -1) ;
+        assertEquals(1, x) ;
+    }
+    
+    @Test
+    public void testCxt8() {
+        Context cxt = new Context() ;
+        assertEquals(-1L, cxt.getLong(p1, -1L)) ;
+        cxt.set(p1, 1L) ;
+        long x = cxt.getLong(p1, -2L) ;
+        assertEquals(1L, x) ;
+    }
+    
+    @Test(expected=ARQException.class)
+    public void testCxt9() {
+        Context cxt = new Context() ;
+        assertEquals(-1L, cxt.getLong(p1, -1L)) ;
+        cxt.set(p1, 1L) ;
+        // Bad. Long for Integer.
+        cxt.getInt(p1, -2) ;
+    }
 }


[5/6] jena git commit: Tests for with and without a threshold.

Posted by an...@apache.org.
Tests for with and without a threshold.

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

Branch: refs/heads/master
Commit: fecd9783264f874503885330a29d3be56b612b8d
Parents: a5f3c8e
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 2 11:34:41 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 2 11:34:41 2015 +0100

----------------------------------------------------------------------
 .../engine/iterator/TS_QueryIterators.java      |  1 +
 .../engine/iterator/TestDistinctDataBag.java    |  8 +---
 .../iterator/TestDistinctDataBagLimited.java    | 40 ++++++++++++++++++++
 3 files changed, 43 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/fecd9783/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TS_QueryIterators.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TS_QueryIterators.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TS_QueryIterators.java
index 2d3148c..d0eb2ac 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TS_QueryIterators.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TS_QueryIterators.java
@@ -26,6 +26,7 @@ import org.junit.runners.Suite ;
     TestQueryIterSort.class
     , TestDistinctMem.class
     , TestDistinctDataBag.class 
+    , TestDistinctDataBagLimited.class 
 })
 public class TS_QueryIterators {
 

http://git-wip-us.apache.org/repos/asf/jena/blob/fecd9783/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBag.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBag.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBag.java
index 1b70334..34fa75d 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBag.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBag.java
@@ -20,20 +20,16 @@ package org.apache.jena.sparql.engine.iterator;
 
 import java.util.List ;
 
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
 import org.apache.jena.sparql.engine.QueryIterator ;
 import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.util.Context ;
 
 public class TestDistinctDataBag extends AbstractTestDistinctReduced {
 
     @Override
     protected QueryIterator createQueryIter(List<Binding> data) {
         QueryIterator qIter = new QueryIterPlainWrapper(data.iterator()) ;
-        Context cxt = new Context() ;
-        cxt.set(ARQ.spillToDiskThreshold, 2L);
-        return new QueryIterDistinct(qIter, new ExecutionContext(cxt, null, null, null)) ;
+        // Default setting - no threshold.
+        return new QueryIterDistinct(qIter, null) ;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/fecd9783/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBagLimited.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBagLimited.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBagLimited.java
new file mode 100644
index 0000000..b528525
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/iterator/TestDistinctDataBagLimited.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.iterator;
+
+import java.util.List ;
+
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.util.Context ;
+
+public class TestDistinctDataBagLimited extends AbstractTestDistinctReduced {
+
+    @Override
+    protected QueryIterator createQueryIter(List<Binding> data) {
+        QueryIterator qIter = new QueryIterPlainWrapper(data.iterator()) ;
+        Context cxt = new Context() ;
+        cxt.set(ARQ.spillToDiskThreshold, 2L);
+        return new QueryIterDistinct(qIter, new ExecutionContext(cxt, null, null, null)) ;
+    }
+
+}
+