|
From: <pm_...@us...> - 2011-12-19 13:27:01
|
Revision: 4501
http://mxquery.svn.sourceforge.net/mxquery/?rev=4501&view=rev
Author: pm_fischer
Date: 2011-12-19 13:26:50 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
- Extend PreparedStatement to expose Projections paths
- Support projection paths in doc() and Child step
- Test cases for simple paths expressions, FLWOR, Conditional, XMark Q1
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java
trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java
trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
Added Paths:
-----------
trunk/MXQuery_Testing/ProjectionTests/
trunk/MXQuery_Testing/ProjectionTests/expectedPaths/
trunk/MXQuery_Testing/ProjectionTests/expectedPaths/XMark01.txt
trunk/MXQuery_Testing/ProjectionTests/queries/
trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/Path1.xq
trunk/MXQuery_Testing/ProjectionTests/queries/Path2.xq
trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -36,6 +36,8 @@
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.IOLib;
import ch.ethz.mxquery.util.LineReader;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
import ch.ethz.mxquery.util.URIUtils;
import ch.ethz.mxquery.xdmio.XDMInputFactory;
import ch.ethz.mxquery.xdmio.XMLSource;
@@ -251,4 +253,12 @@
else
return null;
}
+
+ public ObjectObjectPair getProjectionPaths() {
+ Set returned = new Set();
+ returned.add("/");
+ return new ObjectObjectPair(returned, new Set());
+ }
+
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/ChildIterator.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -15,6 +15,7 @@
package ch.ethz.mxquery.iterators;
+import java.util.Enumeration;
import java.util.Vector;
import ch.ethz.mxquery.contextConfig.Context;
@@ -35,6 +36,8 @@
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
/**
*
@@ -261,5 +264,30 @@
exprCategory = checkExprDefault(subIters,isScripting);
}
}
+
+ public ObjectObjectPair getProjectionPaths() {
+ XDMIterator curSub; // TODO: deal with context item
+ curSub = subIters[0];
+ ObjectObjectPair paths = curSub.getProjectionPaths();
+ Set returnedBelow = (Set)paths.getFirst();
+ Set returned = new Set();
+ Enumeration pathEnum = returnedBelow.elements();
+ while (pathEnum.hasMoreElements()) {
+ String res = (String) pathEnum.nextElement();
+ if (res.endsWith("/"))
+ res = res.substring(0, res.length()-1);
+ if (step_uri != null)
+ res = res+"/{"+step_uri+"}:";
+ if (step_local != null) {
+ if (step_uri == null)
+ res = res+"/";
+ res = res+step_local;
+ }
+ returned.add(res);
+ }
+ return new ObjectObjectPair(returned, paths.getSecond());
+ }
+
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/updatePrimitives/PendingUpdateList.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -387,10 +387,7 @@
throw new DynamicException(ErrorCodes.U0021_UPDATE_DYNAMIC_INVALID_XDM,"Duplicate attribute names in updates",null);
else
seenAttrNames.add(attName);
- } else {
- if (seenAttrNames.size() > 0)
- seenAttrNames = new Set();
- }
+ }
else {
if (seenAttrNames.size() > 0)
seenAttrNames = new Set();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/PreparedStatement.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -23,6 +23,7 @@
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.xdmio.StoreSet;
import ch.ethz.mxquery.xdmio.XDMSerializerSettings;
@@ -143,5 +144,10 @@
* @return null if no output settings in the query, the settings object otherwise
*/
public XDMSerializerSettings getOutputSettings();
+ /**
+ * Get the projection paths for all accessed resources
+ * @return a mapping from resourcename (URI, variable QName) -> Pair (returned, used) Paths
+ */
+ public Hashtable getProjectionPaths();
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:23:24 UTC (rev 4500)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/impl/PreparedStatementImpl.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -17,6 +17,7 @@
import java.util.Enumeration;
import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.ObjectObjectPair;
import java.util.Vector;
@@ -180,4 +181,12 @@
public XDMSerializerSettings getOutputSettings() {
return ser;
}
+
+ public Hashtable getProjectionPaths() {
+ //Preliminary implementation, producing just a single doc
+ ObjectObjectPair paths = iter.getProjectionPaths();
+ Hashtable ht = new Hashtable();
+ ht.put("DOC", paths);
+ return ht;
+ }
}
Added: trunk/MXQuery_Testing/ProjectionTests/expectedPaths/XMark01.txt
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/expectedPaths/XMark01.txt (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/expectedPaths/XMark01.txt 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,2 @@
+/site/people/person/@id
+/site/peope/person/name #
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Cond1.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,3 @@
+if(true)
+then doc("xmark.xml")/site/people/person
+else doc("xmark.xml")/site/open_auctions/open_auctions
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR1.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/FLWOR1.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,2 @@
+for $a in doc("xmark.xml")/site/people/person
+return $a/name
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Path1.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Path1.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Path1.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1 @@
+doc("xmark.xml")/site
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/Path2.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/Path2.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/Path2.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1 @@
+doc("xmark.xml")/site/people/person
\ No newline at end of file
Added: trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq
===================================================================
--- trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq (rev 0)
+++ trunk/MXQuery_Testing/ProjectionTests/queries/XMark01.xq 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,3 @@
+let $auction := doc()
+return for $b in $auction/site/people/person[@id = 'person0']
+return $b/name/text()
\ No newline at end of file
Added: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java (rev 0)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/ProjectionTests.java 2011-12-19 13:26:50 UTC (rev 4501)
@@ -0,0 +1,78 @@
+/**
+ *
+ */
+package ch.ethz.mxquery.test;
+
+import java.util.Enumeration;
+
+
+import ch.ethz.mxquery.query.PreparedStatement;
+import ch.ethz.mxquery.testsuite.XQueryTestBase;
+import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.ObjectObjectPair;
+import ch.ethz.mxquery.util.Set;
+
+
+/**
+ * @author petfisch
+ *
+ */
+public class ProjectionTests extends XQueryTestBase{
+
+ private static final String TEST_PROJECTION_PREFIX = "ProjectionTests";
+ private static final String TEST_PROJECTION_QUERY_PREFIX = TEST_PROJECTION_PREFIX+"/queries/";
+
+ public void test_Path1() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Path1.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+ public void test_Path2() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"Path2.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+ public void test_FLWOR1() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"FLWOR1.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ }
+
+
+ public void test_XMark01() throws Exception{
+ String query = UriToString(TEST_PROJECTION_QUERY_PREFIX+"XMark01.xq");
+ PreparedStatement pi = prepareQuery(query, false,false, false, false, false);
+ Hashtable ht = pi.getProjectionPaths();
+ handleProjectionPaths(ht);
+
+ //assertEquals(resultBuffer.toString().trim(), "false");
+ };
+
+ private void handleProjectionPaths(Hashtable projPaths) {
+ ObjectObjectPair paths = (ObjectObjectPair) projPaths.get("DOC");
+ Set returned = (Set) paths.getFirst();
+ Set used = (Set) paths.getSecond();
+ Enumeration en = returned.elements();
+ while (en.hasMoreElements()) {
+ String curPath = (String) en.nextElement();
+ System.out.println(curPath+" #");
+ }
+ en = used.elements();
+ while (en.hasMoreElements()) {
+ String curPath = (String) en.nextElement();
+ System.out.println(curPath);
+ }
+ };
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|