|
From: <pm_...@us...> - 2012-03-12 07:31:55
|
Revision: 4534
http://mxquery.svn.sourceforge.net/mxquery/?rev=4534&view=rev
Author: pm_fischer
Date: 2012-03-12 07:31:44 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
- push duplicate elimination of projection paths into
PreparedStatementImpl
Modified Paths:
--------------
trunk/MXQuery/midp_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2012-03-12 06:39:25 UTC (rev 4533)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2012-03-12 07:31:44 UTC (rev 4534)
@@ -19,6 +19,7 @@
import java.util.Enumeration;
import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
import java.util.Vector;
@@ -28,6 +29,8 @@
import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.TokenIterator;
import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.XQName;
+import ch.ethz.mxquery.model.AbstractStep;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.VariableHolder;
@@ -176,12 +179,66 @@
public Hashtable getProjectionPaths() throws StaticException {
//Preliminary implementation, producing just a single doc
+ // Eliminate duplicate paths
+ Set distPaths = new Set();
+
ObjectObjectPair paths = iter.getProjectionPaths();
+ Set returned = (Set) paths.getFirst();
+ Set used = (Set) paths.getSecond();
+
+ Set distReturned = new Set();
+ Enumeration en = returned.elements();
+
+ while (en.hasMoreElements()) {
+ Vector curPath = (Vector) en.nextElement();
+ String curPathSum = translateProjectionPath(curPath)+" #";
+ if (!distPaths.contains(curPathSum)) {
+ distPaths.add(curPathSum);
+ distReturned.add(curPath);
+ }
+ }
+
+ Set distUsed = new Set();
+
+ en = used.elements();
+ while (en.hasMoreElements()) {
+ Vector curPath = (Vector) en.nextElement();
+ String curPathSum = translateProjectionPath(curPath);
+ if (!distPaths.contains(curPathSum)) {
+ distPaths.add(curPathSum);
+ distUsed.add(curPath);
+ }
+ }
+
+
Hashtable ht = new Hashtable();
- ht.put("DOC", paths);
+ ht.put("DOC", new ObjectObjectPair(distReturned, distUsed));
return ht;
}
+ private String translateProjectionPath(Vector curPath) throws StaticException {
+ StringBuffer pathString = new StringBuffer();
+ for (int i=0;i<curPath.size();i++) {
+ AbstractStep as = (AbstractStep)curPath.elementAt(i);
+ if (as == AbstractStep.ROOT_STEP)
+ pathString.append("/");
+ else if (as == AbstractStep.KEEP_SUBTREE)
+ pathString.append(" #");
+ else
+ {
+ pathString.append(as.getDirectionString(true));
+ XQName xq = as.getNodeTest().getXQName();
+ if (xq != null)
+ // TODO: What about namespace URIs?
+ pathString.append(xq.toString());
+ else throw new StaticException(ErrorCodes.A0002_EC_NOT_SUPPORTED,"Unsupported node test for projection - please report",QueryLocation.OUTSIDE_QUERY_LOC);
+ if (i<curPath.size()-2 || ( (AbstractStep)curPath.elementAt(curPath.size()-1) != AbstractStep.KEEP_SUBTREE && i<curPath.size()-1) )
+ pathString.append("/");
+ }
+ }
+ return pathString.toString();
+ };
+
public void setProjectionInformation(QName varname,
ObjectObjectPair paths) throws StaticException {
VariableHolder vh = ctx.getVariable(varname);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2012-03-12 06:39:25 UTC (rev 4533)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2012-03-12 07:31:44 UTC (rev 4534)
@@ -18,6 +18,7 @@
import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
import java.util.Vector;
@@ -32,6 +33,7 @@
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
import ch.ethz.mxquery.exceptions.StaticException;
+import ch.ethz.mxquery.model.AbstractStep;
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.query.PreparedStatement;
@@ -185,16 +187,70 @@
public Hashtable getProjectionPaths() throws StaticException {
//Preliminary implementation, producing just a single doc
+ // Eliminate duplicate paths
+ Set distPaths = new Set();
+
ObjectObjectPair paths = iter.getProjectionPaths();
+ Set returned = (Set) paths.getFirst();
+ Set used = (Set) paths.getSecond();
+
+ Set distReturned = new Set();
+ Enumeration en = returned.elements();
+
+ while (en.hasMoreElements()) {
+ Vector curPath = (Vector) en.nextElement();
+ String curPathSum = translateProjectionPath(curPath)+" #";
+ if (!distPaths.contains(curPathSum)) {
+ distPaths.add(curPathSum);
+ distReturned.add(curPath);
+ }
+ }
+
+ Set distUsed = new Set();
+
+ en = used.elements();
+ while (en.hasMoreElements()) {
+ Vector curPath = (Vector) en.nextElement();
+ String curPathSum = translateProjectionPath(curPath);
+ if (!distPaths.contains(curPathSum)) {
+ distPaths.add(curPathSum);
+ distUsed.add(curPath);
+ }
+ }
+
+
Hashtable ht = new Hashtable();
- ht.put("DOC", paths);
+ ht.put("DOC", new ObjectObjectPair(distReturned, distUsed));
return ht;
}
+ private String translateProjectionPath(Vector curPath) throws StaticException {
+ StringBuffer pathString = new StringBuffer();
+ for (int i=0;i<curPath.size();i++) {
+ AbstractStep as = (AbstractStep)curPath.elementAt(i);
+ if (as == AbstractStep.ROOT_STEP)
+ pathString.append("/");
+ else if (as == AbstractStep.KEEP_SUBTREE)
+ pathString.append(" #");
+ else
+ {
+ pathString.append(as.getDirectionString(true));
+ XQName xq = as.getNodeTest().getXQName();
+ if (xq != null)
+ // TODO: What about namespace URIs?
+ pathString.append(xq.toString());
+ else throw new StaticException(ErrorCodes.A0002_EC_NOT_SUPPORTED,"Unsupported node test for projection - please report",QueryLocation.OUTSIDE_QUERY_LOC);
+ if (i<curPath.size()-2 || ( (AbstractStep)curPath.elementAt(curPath.size()-1) != AbstractStep.KEEP_SUBTREE && i<curPath.size()-1) )
+ pathString.append("/");
+ }
+ }
+ return pathString.toString();
+ };
+
public void setProjectionInformation(QName varname,
ObjectObjectPair paths) throws StaticException {
VariableHolder vh = ctx.getVariable(varname);
vh.setProjectionPaths(paths);
}
-
+
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2012-03-12 06:39:25 UTC (rev 4533)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2012-03-12 07:31:44 UTC (rev 4534)
@@ -16,7 +16,9 @@
import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
+import java.util.Enumeration;
import java.util.Vector;
import com.google.gwt.dom.client.Document;
@@ -33,6 +35,7 @@
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
import ch.ethz.mxquery.exceptions.StaticException;
+import ch.ethz.mxquery.model.AbstractStep;
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.query.PreparedStatement;
@@ -180,12 +183,66 @@
}
public Hashtable getProjectionPaths() throws StaticException {
//Preliminary implementation, producing just a single doc
+ // Eliminate duplicate paths
+ Set distPaths = new Set();
+
ObjectObjectPair paths = iter.getProjectionPaths();
+ Set returned = (Set) paths.getFirst();
+ Set used = (Set) paths.getSecond();
+
+ Set distReturned = new Set();
+ Enumeration en = returned.elements();
+
+ while (en.hasMoreElements()) {
+ Vector curPath = (Vector) en.nextElement();
+ String curPathSum = translateProjectionPath(curPath)+" #";
+ if (!distPaths.contains(curPathSum)) {
+ distPaths.add(curPathSum);
+ distReturned.add(curPath);
+ }
+ }
+
+ Set distUsed = new Set();
+
+ en = used.elements();
+ while (en.hasMoreElements()) {
+ Vector curPath = (Vector) en.nextElement();
+ String curPathSum = translateProjectionPath(curPath);
+ if (!distPaths.contains(curPathSum)) {
+ distPaths.add(curPathSum);
+ distUsed.add(curPath);
+ }
+ }
+
+
Hashtable ht = new Hashtable();
- ht.put("DOC", paths);
+ ht.put("DOC", new ObjectObjectPair(distReturned, distUsed));
return ht;
- }
+ }
+ private String translateProjectionPath(Vector curPath) throws StaticException {
+ StringBuffer pathString = new StringBuffer();
+ for (int i=0;i<curPath.size();i++) {
+ AbstractStep as = (AbstractStep)curPath.elementAt(i);
+ if (as == AbstractStep.ROOT_STEP)
+ pathString.append("/");
+ else if (as == AbstractStep.KEEP_SUBTREE)
+ pathString.append(" #");
+ else
+ {
+ pathString.append(as.getDirectionString(true));
+ XQName xq = as.getNodeTest().getXQName();
+ if (xq != null)
+ // TODO: What about namespace URIs?
+ pathString.append(xq.toString());
+ else throw new StaticException(ErrorCodes.A0002_EC_NOT_SUPPORTED,"Unsupported node test for projection - please report",QueryLocation.OUTSIDE_QUERY_LOC);
+ if (i<curPath.size()-2 || ( (AbstractStep)curPath.elementAt(curPath.size()-1) != AbstractStep.KEEP_SUBTREE && i<curPath.size()-1) )
+ pathString.append("/");
+ }
+ }
+ return pathString.toString();
+ };
+
public void setProjectionInformation(QName varname,
ObjectObjectPair paths) throws StaticException {
VariableHolder vh = ctx.getVariable(varname);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|