Repository: jena
Updated Branches:
  refs/heads/master db818ea3f -> bea349587


JENA-1520: tdb2.tdbstats: cmd and fix for rdf:type


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

Branch: refs/heads/master
Commit: 55516f717caba7d41c4b78ca298f4c030cedcddf
Parents: d30b3c0
Author: Andy Seaborne <a...@apache.org>
Authored: Thu Apr 12 17:18:29 2018 +0100
Committer: Andy Seaborne <a...@apache.org>
Committed: Thu Apr 12 17:18:29 2018 +0100

----------------------------------------------------------------------
 apache-jena/bat/tdb2_tdbstats.bat               | 18 ++++
 apache-jena/bin/tdb2.tdbstats                   | 89 ++++++++++++++++++++
 apache-jena/cmd-maker                           |  1 +
 .../jena/tdb2/solver/stats/StatsCollector.java  | 18 ++--
 .../tdb2/solver/stats/StatsCollectorBase.java   | 36 ++++----
 .../tdb2/solver/stats/StatsCollectorNodeId.java | 48 +++++------
 6 files changed, 157 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/55516f71/apache-jena/bat/tdb2_tdbstats.bat
----------------------------------------------------------------------
diff --git a/apache-jena/bat/tdb2_tdbstats.bat 
b/apache-jena/bat/tdb2_tdbstats.bat
new file mode 100644
index 0000000..a1d7b07
--- /dev/null
+++ b/apache-jena/bat/tdb2_tdbstats.bat
@@ -0,0 +1,18 @@
+@echo off
+@rem Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0
+
+if "%JENAROOT%" == "" goto :rootNotSet
+set JENA_HOME=%JENAROOT%
+:rootNotSet
+
+if NOT "%JENA_HOME%" == "" goto :okHome
+echo JENA_HOME not set
+exit /B
+
+:okHome
+set JENA_CP=%JENA_HOME%\lib\*;
+set LOGGING=file:%JENA_HOME%/jena-log4j.properties
+
+@rem JVM_ARGS comes from the environment.
+java %JVM_ARGS% -Dlog4j.configuration="%LOGGING%" -cp "%JENA_CP%" 
tdb2.tdbstats %*
+exit /B

http://git-wip-us.apache.org/repos/asf/jena/blob/55516f71/apache-jena/bin/tdb2.tdbstats
----------------------------------------------------------------------
diff --git a/apache-jena/bin/tdb2.tdbstats b/apache-jena/bin/tdb2.tdbstats
new file mode 100644
index 0000000..36363b5
--- /dev/null
+++ b/apache-jena/bin/tdb2.tdbstats
@@ -0,0 +1,89 @@
+#!/bin/sh
+## Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0
+
+resolveLink() {
+  local NAME=$1
+
+  if [ -L "$NAME" ]; then
+    case "$OSTYPE" in
+      darwin*|bsd*)
+        # BSD style readlink behaves differently to GNU readlink
+        # Have to manually follow links
+        while [ -L "$NAME" ]; do
+          NAME=$( cd $NAME && pwd -P ) ;
+        done
+        ;;
+      *)
+        # Assuming standard GNU readlink with -f for
+        # canonicalize and follow
+        NAME=$(readlink -f "$NAME")
+        ;;
+    esac
+  fi
+
+  echo "$NAME"
+}
+
+# If JENA_HOME is empty
+if [ -z "$JENA_HOME" ]; then
+  SCRIPT="$0"
+  # Catch common issue: script has been symlinked
+  if [ -L "$SCRIPT" ]; then
+    SCRIPT=$(resolveLink "$0")
+    # If link is relative
+    case "$SCRIPT" in
+      /*)
+        # Already absolute
+        ;;
+      *)
+        # Relative, make absolute
+        SCRIPT=$( dirname "$0" )/$SCRIPT
+        ;;
+    esac
+  fi
+
+  # Work out root from script location
+  JENA_HOME="$( cd "$( dirname "$SCRIPT" )/.." && pwd )"
+  export JENA_HOME
+fi
+
+# If JENA_HOME is a symbolic link need to resolve
+if [ -L "${JENA_HOME}" ]; then
+  JENA_HOME=$(resolveLink "$JENA_HOME")
+  # If link is relative
+  case "$JENA_HOME" in
+    /*)
+      # Already absolute
+      ;;
+    *)
+      # Relative, make absolute
+      JENA_HOME=$(dirname "$JENA_HOME")
+      ;;
+  esac
+  export JENA_HOME
+fi
+
+# ---- Setup
+# JVM_ARGS : don't set here but it can be set in the environment.
+# Expand JENA_HOME but literal *
+JENA_CP="$JENA_HOME"'/lib/*'
+SOCKS=
+LOGGING="${LOGGING:--Dlog4j.configuration=file:$JENA_HOME/jena-log4j.properties}"
+
+# Platform specific fixup
+# On CYGWIN convert path and end with a ';' 
+case "$(uname)" in
+   CYGWIN*) JENA_CP="$(cygpath -wp "$JENA_CP");";;
+esac
+
+# Respect TMPDIR or TMP (windows?) if present
+# important for tdbloader spill
+if [ -n "$TMPDIR" ]
+       then
+       JVM_ARGS="$JVM_ARGS -Djava.io.tmpdir=\"$TMPDIR\""
+elif [ -n "$TMP" ]
+       then
+       JVM_ARGS="$JVM_ARGS -Djava.io.tmpdir=\"$TMP\""
+fi
+
+java $JVM_ARGS $LOGGING -cp "$JENA_CP" tdb2.tdbstats "$@" 

http://git-wip-us.apache.org/repos/asf/jena/blob/55516f71/apache-jena/cmd-maker
----------------------------------------------------------------------
diff --git a/apache-jena/cmd-maker b/apache-jena/cmd-maker
index 2ce27b6..58e8040 100755
--- a/apache-jena/cmd-maker
+++ b/apache-jena/cmd-maker
@@ -67,6 +67,7 @@ tdb2.tdbdump
 tdb2.tdbcompact
 tdb2.tdbloader
 tdb2.tdbquery
+tdb2.tdbstats
 tdb2.tdbupdate
 EOF
 )

http://git-wip-us.apache.org/repos/asf/jena/blob/55516f71/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollector.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollector.java
 
b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollector.java
index a751bb8..7176ee8 100644
--- 
a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollector.java
+++ 
b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollector.java
@@ -18,19 +18,19 @@
 
 package org.apache.jena.tdb2.solver.stats;
 
-import java.util.Map ;
+import java.util.Map;
 
-import org.apache.jena.graph.Node ;
-import org.apache.jena.sparql.graph.NodeConst ;
+import org.apache.jena.graph.Node;
+import org.apache.jena.sparql.graph.NodeConst;
 
 /** Statistics collector, general purpose, uses Nodes */
-public class StatsCollector extends StatsCollectorBase<Node>
-{
-    public StatsCollector() { super(NodeConst.nodeRDFType) ; }
+public class StatsCollector extends StatsCollectorBase<Node> {
+    public StatsCollector() {
+        super(NodeConst.nodeRDFType);
+    }
 
     @Override
-    protected Map<Node, Integer> convert(Map<Node, Integer> map)
-    {
-        return map ;
+    protected Map<Node, Integer> convert(Map<Node, Integer> map) {
+        return map;
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/55516f71/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorBase.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorBase.java
 
b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorBase.java
index 3de508e..871dcc6 100644
--- 
a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorBase.java
+++ 
b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorBase.java
@@ -25,30 +25,26 @@ import java.util.Map ;
 import org.apache.jena.graph.Node ;
 
 /** Statistics collector, general purpose */
-abstract class StatsCollectorBase<T>
-{
-    private long count = 0 ;
-    private Map<T, Integer> predicates = new HashMap<>(10000) ;
-    private Map<T, Integer> types = new HashMap<>(10000) ;
-    private T typeTrigger ;
-    
-    protected StatsCollectorBase(T typeTrigger)
-    {
-        this.typeTrigger = typeTrigger ;
+abstract class StatsCollectorBase<T> {
+    private long            count      = 0;
+    private Map<T, Integer> predicates = new HashMap<>(10000);
+    private Map<T, Integer> types      = new HashMap<>(10000);
+    private T               typeTrigger;
+
+    protected StatsCollectorBase(T typeTrigger) {
+        this.typeTrigger = typeTrigger;
     }
 
-    public void record(T g, T s, T p, T o)
-    {
-        count++ ;
-               predicates.put(p, predicates.getOrDefault(p, 0) + 1);
+    public void record(T g, T s, T p, T o) {
+        count++;
+        predicates.put(p, predicates.getOrDefault(p, 0) + 1);
         if ( typeTrigger != null && typeTrigger.equals(p) )
-                       types.put(o, types.getOrDefault(o, 0) + 1);
+            types.put(o, types.getOrDefault(o, 0) + 1);
     }
 
-    protected abstract Map<Node, Integer> convert(Map<T, Integer> map) ;
-    
-    public StatsResults results()
-    {
-        return new StatsResults(convert(predicates), convert(types), count) ;
+    protected abstract Map<Node, Integer> convert(Map<T, Integer> map);
+
+    public StatsResults results() {
+        return new StatsResults(convert(predicates), convert(types), count);
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/55516f71/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorNodeId.java
----------------------------------------------------------------------
diff --git 
a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorNodeId.java
 
b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorNodeId.java
index c4b1b9c..ad61b91 100644
--- 
a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorNodeId.java
+++ 
b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorNodeId.java
@@ -18,39 +18,39 @@
 
 package org.apache.jena.tdb2.solver.stats;
 
-import java.util.HashMap ;
-import java.util.Map ;
+import java.util.HashMap;
+import java.util.Map;
 
-import org.apache.jena.graph.Node ;
-import org.apache.jena.sparql.graph.NodeConst ;
+import org.apache.jena.graph.Node;
+import org.apache.jena.sparql.graph.NodeConst;
 import org.apache.jena.tdb2.store.NodeId;
 import org.apache.jena.tdb2.store.nodetable.NodeTable;
 
 /** Statistics collector, aggregates based on NodeId */
-public class StatsCollectorNodeId extends StatsCollectorBase<NodeId>
-{
-    private NodeTable nodeTable ;
-    
-    public StatsCollectorNodeId(NodeTable nodeTable)
-    {
-        super(findRDFType(nodeTable)) ;
-        this.nodeTable = nodeTable ;
+public class StatsCollectorNodeId extends StatsCollectorBase<NodeId> {
+    private NodeTable nodeTable;
+
+    public StatsCollectorNodeId(NodeTable nodeTable) {
+        super(findRDFType(nodeTable));
+        this.nodeTable = nodeTable;
     }
-    
-    private static NodeId findRDFType(NodeTable nodeTable2)
-    {
-        return nodeTable2.getAllocateNodeId(NodeConst.nodeRDFType) ;
+
+    private static NodeId findRDFType(NodeTable nodeTable) {
+        // It may not exist.
+        NodeId nodeId = nodeTable.getNodeIdForNode(NodeConst.nodeRDFType);
+        if ( NodeId.isDoesNotExist(nodeId) )
+            return null;
+        return nodeId;
     }
 
     @Override
-    protected Map<Node, Integer> convert(Map<NodeId, Integer> stats)
-    {
-        Map<Node, Integer> statsNodes = new HashMap<>(1000) ;
-        for ( NodeId p : stats.keySet() )
-        {
-            Node n = nodeTable.getNodeForNodeId(p) ;
-            statsNodes.put(n, stats.get(p)) ;
+    protected Map<Node, Integer> convert(Map<NodeId, Integer> stats) {
+        // Predicate -> Count
+        Map<Node, Integer> statsNodes = new HashMap<>(1000);
+        for ( NodeId p : stats.keySet() ) {
+            Node n = nodeTable.getNodeForNodeId(p);
+            statsNodes.put(n, stats.get(p));
         }
-        return statsNodes ;
+        return statsNodes;
     }
 }

Reply via email to