Author: andy
Date: Thu May 23 19:57:59 2013
New Revision: 1485840
URL: http://svn.apache.org/r1485840
Log:
Tool to analyse the stats optimization step.
Added:
jena/Scratch/AFS/Jena-Dev/trunk/src/dev/tdbreorder.java
Added: jena/Scratch/AFS/Jena-Dev/trunk/src/dev/tdbreorder.java
URL:
http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/tdbreorder.java?rev=1485840&view=auto
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/dev/tdbreorder.java (added)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/dev/tdbreorder.java Thu May 23 19:57:59
2013
@@ -0,0 +1,90 @@
+/**
+ * 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 dev;
+
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.atlas.logging.Log ;
+
+import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.algebra.op.OpBGP ;
+import com.hp.hpl.jena.sparql.algebra.op.OpQuadPattern ;
+import com.hp.hpl.jena.sparql.core.BasicPattern ;
+import com.hp.hpl.jena.sparql.engine.optimizer.StatsMatcher ;
+import com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderLib ;
+import com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
+import
com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderTransformationBase ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.tdb.sys.Names ;
+
+public class tdbreorder
+{
+ public static void main(String[] args) {
+ if ( args.length != 2 ) {
+ System.err.println("Usage: PATTERN STATS") ;
+ System.exit(1) ;
+ }
+ Log.enable(StatsMatcher.class) ;
+ Log.enable(ReorderTransformationBase.class) ;
+
+ if ( args.length != 2 )
+ {
+ System.err.println("Usage: op stats") ;
+ System.exit(1) ;
+ }
+
+ String pattern = args[0] ;
+ String statsFile = args[1] ;
+
+ Op op = SSE.readOp(pattern) ;
+
+ BasicPattern bgp ;
+ if ( op instanceof OpQuadPattern ) {
+ bgp = ((OpQuadPattern)op).getBasicPattern() ;
+ } else if ( op instanceof OpBGP ) {
+ bgp = ((OpBGP)op).getPattern() ;
+ }
+ else {
+ System.err.println("Not a quad or triple pattern") ;
+ System.exit(2) ;
+ bgp = null ;
+ }
+
+ ReorderTransformation reorder = chooseReorder(statsFile) ;
+ //ReorderTransformation reorder = ReorderLib.fixed() ;
+ BasicPattern bgp2 = reorder.reorder(bgp) ;
+
+ System.out.println() ;
+ System.out.println(bgp) ;
+ System.out.println(" ======== >>>>>>>>") ;
+ System.out.println(bgp2) ;
+ }
+
+ private static ReorderTransformation chooseReorder(String filename)
+ {
+ if ( filename.equals(Names.optFixed) )
+ return ReorderLib.fixed() ;
+ if ( filename.equals(Names.optNone) )
+ return ReorderLib.identity() ;
+ if ( FileOps.exists(filename) )
+ return ReorderLib.weighted(filename) ;
+ else
+ throw new RuntimeException("No such file: "+filename) ;
+ }
+}
+