[teiid-commits] teiid SVN: r2109 - in trunk: engine/src/main/java/com/metamatrix/common and 16 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon May 10 13:42:45 EDT 2010


Author: shawkins
Date: 2010-05-10 13:42:42 -0400 (Mon, 10 May 2010)
New Revision: 2109

Added:
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLAttributes.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLElement.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLForest.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLNamespaces.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java
Removed:
   trunk/engine/src/main/java/com/metamatrix/common/log/
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.java
Modified:
   trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
   trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
   trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java
   trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
   trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
   trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
   trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
   trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
   trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
   trunk/engine/src/test/java/com/metamatrix/query/function/source/TestXMLSystemFunctions.java
   trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
Log:
TEIID-171 adding support for xmlnamespaces and refining languageobjects for the other functions

Modified: trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml	2010-05-10 17:42:42 UTC (rev 2109)
@@ -1972,8 +1972,9 @@
           </row>
           <row>
             <entry>
-              <para><code>XMLELEMENT([NAME] name [, &lt;ATTR&gt;][, exp]*)</code>
-               		ATTR:=<code>XMLATTRIBUTES(exp [AS name] [, exp [AS name]]*)</code></para>
+              <para><code>XMLELEMENT([NAME] name [, &lt;NSP&gt;] [, &lt;ATTR&gt;][, exp]*)</code></para>
+              <para>ATTR:=<code>XMLATTRIBUTES(exp [AS name] [, exp [AS name]]*)</code></para>
+              <para>NSP:=<code>XMLNAMESPACES((uri AS prefix | DEFAULT uri | NO DEFAULTS))+</code></para>
             </entry>
             <entry>
               <para>Returns an XML element with the given name and content.  If the content value is of a type other than xml, 
@@ -1985,7 +1986,7 @@
               </para>
             </entry>
             <entry>
-              <para>Name is an identifier.  exp can be any type. Return value is xml.
+              <para>Name, prefix are identifiers. uri is a string literal. exp can be any type. Return value is xml.
               </para>
             </entry>
           </row>
@@ -2004,11 +2005,12 @@
           </row>
           <row>
             <entry>
-              <para><code>XMLFOREST(exp [AS name], [exp [AS name]]*)</code></para>
+              <para><code>XMLFOREST(exp [AS name] [, &lt;NSP&gt;] [, exp [AS name]]*)</code></para>
             </entry>
             <entry>
               <para>Returns an concatination of an XML element for each non-null expression exp.  If a name is not supplied, the expression must be a column reference, in which case the element name will be the column name.
               </para>
+              <para>See XMLELEMENT for the definition of NSP - XMLNAMESPACES.</para>
             </entry>
             <entry>
               <para>Name is an identifier. Exp can be any type. Return value is xml.

Modified: trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -23,6 +23,7 @@
 package com.metamatrix.query.eval;
 
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -73,10 +74,13 @@
 import com.metamatrix.query.sql.symbol.ExpressionSymbol;
 import com.metamatrix.query.sql.symbol.Function;
 import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
 import com.metamatrix.query.sql.symbol.ScalarSubquery;
 import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.XMLElement;
+import com.metamatrix.query.sql.symbol.XMLForest;
+import com.metamatrix.query.sql.symbol.XMLNamespaces;
+import com.metamatrix.query.sql.symbol.XMLNamespaces.NamespaceItem;
 import com.metamatrix.query.sql.util.ValueIterator;
 import com.metamatrix.query.sql.util.ValueIteratorSource;
 import com.metamatrix.query.util.CommandContext;
@@ -233,7 +237,7 @@
     	if (leftValue == rightValue) {
     		return 0;
     	}
-        return ((Comparable)leftValue).compareTo(rightValue);
+        return ((Comparable<Object>)leftValue).compareTo(rightValue);
     }
 
 	public Boolean evaluate(MatchCriteria criteria, List tuple)
@@ -561,32 +565,65 @@
 		   return internalEvaluate(ref.getExpression(), tuple);
 	   } else if(expression instanceof ScalarSubquery) {
 	       return evaluate((ScalarSubquery) expression, tuple);
-	   } else if (expression instanceof SQLXMLFunction){
-		   SQLXMLFunction function = (SQLXMLFunction)expression;
+	   } else if (expression instanceof XMLElement){
+		   XMLElement function = (XMLElement)expression;
+		   List<Expression> content = function.getContent();
+		   List<Object> values = new ArrayList<Object>(content.size());
+		   for (Expression exp : content) {
+			   values.add(internalEvaluate(exp, tuple));
+		   }
+		   try {
+			   NameValuePair<Object>[] attributes = null;
+			   if (function.getAttributes() != null) {
+				   attributes = getNameValuePairs(tuple, function.getAttributes().getArgs());
+			   }
+			   return XMLSystemFunctions.xmlElement(context, function.getName(), namespaces(function.getNamespaces()), attributes, values);
+		   } catch (MetaMatrixProcessingException e) {
+			   throw new FunctionExecutionException(e, e.getMessage());
+		   }
+	   } else if (expression instanceof XMLForest){
+		   XMLForest function = (XMLForest)expression;
 		   List<SingleElementSymbol> args = function.getArgs();
-		   NameValuePair[] nameValuePairs = new NameValuePair[args.size()];
-		   for(int i=0; i < args.size(); i++) {
-			   SingleElementSymbol symbol = args.get(i);
-			   String name = symbol.getShortName();
-			   Expression ex = symbol;
-			   if (symbol instanceof AliasSymbol) {
-				   ex = ((AliasSymbol)symbol).getSymbol();
-			   }
-			   nameValuePairs[i] = new NameValuePair(name, internalEvaluate(ex, tuple));
-		   } 
-		   if (FunctionLibrary.XMLFOREST.equalsIgnoreCase(function.getName())) {
-			   try {
-				   return XMLSystemFunctions.xmlForest(context, nameValuePairs);
-			   } catch (MetaMatrixProcessingException e) {
-				   throw new FunctionExecutionException(e, e.getMessage());
-			   }
-		   } 
-		   return nameValuePairs;
+		   NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args); 
+		   
+		   try {
+			   return XMLSystemFunctions.xmlForest(context, namespaces(function.getNamespaces()), nameValuePairs);
+		   } catch (MetaMatrixProcessingException e) {
+			   throw new FunctionExecutionException(e, e.getMessage());
+		   }
 	   } else {
 	       throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0016, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0016, expression.getClass().getName()));
 	   }
 	}
+
+	private NameValuePair<Object>[] getNameValuePairs(List tuple, List<SingleElementSymbol> args)
+			throws ExpressionEvaluationException, BlockedException, MetaMatrixComponentException {
+		NameValuePair<Object>[] nameValuePairs = new NameValuePair[args.size()];
+		for (int i = 0; i < args.size(); i++) {
+			SingleElementSymbol symbol = args.get(i);
+			String name = symbol.getShortName();
+			Expression ex = symbol;
+			if (symbol instanceof AliasSymbol) {
+				ex = ((AliasSymbol) symbol).getSymbol();
+			}
+			nameValuePairs[i] = new NameValuePair<Object>(name, internalEvaluate(ex, tuple));
+		}
+		return nameValuePairs;
+	}
 	
+	private NameValuePair<String>[] namespaces(XMLNamespaces namespaces) {
+		if (namespaces == null) {
+			return null;
+		}
+	    List<NamespaceItem> args = namespaces.getNamespaceItems();
+	    NameValuePair<String>[] nameValuePairs = new NameValuePair[args.size()];
+	    for(int i=0; i < args.size(); i++) {
+	    	NamespaceItem item = args.get(i);
+	    	nameValuePairs[i] = new NameValuePair<String>(item.getPrefix(), item.getUri());
+	    } 
+	    return nameValuePairs;
+	}
+	
 	private Object evaluate(CaseExpression expr, List tuple)
 	throws ExpressionEvaluationException, BlockedException, MetaMatrixComponentException {
 	    Object exprVal = internalEvaluate(expr.getExpression(), tuple);

Modified: trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -87,9 +87,11 @@
 
     public static final String SPACE = "space"; //$NON-NLS-1$
     
-    public static final String XMLFOREST = "xmlforest"; //$NON-NLS-1$
-    public static final String XMLATTRIBUTES = "xmlattributes"; //$NON-NLS-1$
-    
+    public static final String XMLFOREST = "XMLFOREST"; //$NON-NLS-1$
+    public static final String XMLATTRIBUTES = "XMLATTRIBUTES"; //$NON-NLS-1$
+    public static final String XMLNAMESPACES = "XMLNAMESPACES"; //$NON-NLS-1$
+    public static final String XMLELEMENT = "XMLELEMENT"; //$NON-NLS-1$
+	
     // Function tree for system functions (never reloaded)
     private FunctionTree systemFunctions;
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -169,7 +169,6 @@
         addXpathQueryFunction();
         addXpathValueFunction();
         addXslTransformFunction();
-        addXmlElement();
         addXmlConcat();
         addXmlComment();
         addXmlPi();
@@ -965,14 +964,6 @@
                 new FunctionParameter("result", DataTypeManager.DefaultDataTypes.CLOB, QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );       //$NON-NLS-1$ //$NON-NLS-2$
     }
     
-    private void addXmlElement() {
-        functions.add(new FunctionMethod(SourceSystemFunctions.XMLELEMENT, QueryPlugin.Util.getString("SystemSource.xmlelement_description"), XML, FunctionMethod.CAN_PUSHDOWN, XML_FUNCTION_CLASS, "xmlElement", //$NON-NLS-1$ //$NON-NLS-2$  
-                            new FunctionParameter[] { 
-                                new FunctionParameter("name", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xmlelement_param1")), //$NON-NLS-1$ //$NON-NLS-2$
-                                new FunctionParameter("value", DataTypeManager.DefaultDataTypes.OBJECT, QueryPlugin.Util.getString("SystemSource.xmlelement_param2"), true)}, //$NON-NLS-1$ //$NON-NLS-2$ 
-                            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xmlement_result")), true, FunctionMethod.DETERMINISTIC ) );       //$NON-NLS-1$ //$NON-NLS-2$
-    }
-    
     private void addXmlComment() {
         functions.add(new FunctionMethod(SourceSystemFunctions.XMLCOMMENT, QueryPlugin.Util.getString("SystemSource.xmlcomment_description"), XML, XML_FUNCTION_CLASS, "xmlComment", //$NON-NLS-1$ //$NON-NLS-2$  
                             new FunctionParameter[] { 

Modified: trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -32,7 +32,10 @@
 import java.sql.SQLXML;
 import java.sql.Timestamp;
 import java.util.Calendar;
+import java.util.Collections;
+import java.util.List;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.EventFilter;
@@ -85,11 +88,11 @@
  */
 public class XMLSystemFunctions {
 	
-	public static class NameValuePair {
+	public static class NameValuePair<T> {
 		String name;
-		Object value;
+		T value;
 		
-		public NameValuePair(String name, Object value) {
+		public NameValuePair(String name, T value) {
 			this.name = name;
 			this.value = value;
 		}
@@ -153,7 +156,7 @@
 		}
     }
 		
-	public static XMLType xmlForest(final CommandContext context, final NameValuePair[] values) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+	public static XMLType xmlForest(final CommandContext context, final NameValuePair[] namespaces, final NameValuePair[] values) throws MetaMatrixComponentException, MetaMatrixProcessingException {
 		boolean valueExists = false;
 		for (NameValuePair nameValuePair : values) {
 			if (nameValuePair.value != null) {
@@ -178,7 +181,7 @@
 						if (nameValuePair.value == null) {
 							continue;
 						}
-						addElement(nameValuePair.name, writer, eventWriter, eventFactory, nameValuePair.value);
+						addElement(nameValuePair.name, writer, eventWriter, eventFactory, namespaces, null, Collections.singletonList(nameValuePair.value));
 					}
 				} catch (XMLStreamException e) {
 					throw new TransformerException(e);
@@ -199,7 +202,7 @@
 	 * @throws MetaMatrixProcessingException 
 	 */
 	public static XMLType xmlElement(CommandContext context, final String name, 
-			final Object... contents) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+			final NameValuePair<String>[] namespaces, final NameValuePair<?>[] attributes, final List<?> contents) throws MetaMatrixComponentException, MetaMatrixProcessingException {
 		XMLType result = new XMLType(XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
 			
 			@Override
@@ -209,7 +212,7 @@
 					XMLOutputFactory factory = XMLOutputFactory.newInstance();
 					XMLEventWriter eventWriter = factory.createXMLEventWriter(writer);
 					XMLEventFactory eventFactory = XMLEventFactory.newInstance();
-					addElement(name, writer, eventWriter, eventFactory, contents);
+					addElement(name, writer, eventWriter, eventFactory, namespaces, attributes, contents);
 				} catch (XMLStreamException e) {
 					throw new TransformerException(e);
 				} 
@@ -221,21 +224,32 @@
 	}
 	
 	private static void addElement(final String name, Writer writer, XMLEventWriter eventWriter, XMLEventFactory eventFactory,
-			Object... contents) throws XMLStreamException, IOException, TransformerException {
+			NameValuePair<String> namespaces[], NameValuePair<?> attributes[], List<?> contents) throws XMLStreamException, IOException, TransformerException {
 		eventWriter.add(eventFactory.createStartElement("", null, name)); //$NON-NLS-1$
-		int start = 0;
-		if (contents.length > 0 && contents[0] instanceof NameValuePair[]) {
-			for (NameValuePair nameValuePair : (NameValuePair[])contents[0]) {
+		if (namespaces != null) {
+			for (NameValuePair<String> nameValuePair : namespaces) {
+				if (nameValuePair.name == null) {
+					if (nameValuePair.value == null) {
+						eventWriter.add(eventFactory.createNamespace(XMLConstants.NULL_NS_URI));
+					} else {
+						eventWriter.add(eventFactory.createNamespace(nameValuePair.value));
+					} 
+				} else {
+					eventWriter.add(eventFactory.createNamespace(nameValuePair.name, nameValuePair.value));
+				}
+			}
+		}
+		if (attributes != null) {
+			for (NameValuePair<?> nameValuePair : attributes) {
 				if (nameValuePair.value != null) {
 					eventWriter.add(eventFactory.createAttribute(new QName(nameValuePair.name), getStringValue(nameValuePair.value)));
 				}
 			}
-			start = 1;
 		}
 		//add empty chars to close the start tag
 		eventWriter.add(eventFactory.createCharacters("")); //$NON-NLS-1$ 
-		for (int i = start; i < contents.length; i++) {
-			convertValue(writer, eventWriter, eventFactory, contents[i]);
+		for (Object object : contents) {
+			convertValue(writer, eventWriter, eventFactory, object);
 		}
 		eventWriter.add(eventFactory.createEndElement("", null, name)); //$NON-NLS-1$
 	}

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -60,9 +60,12 @@
 import com.metamatrix.query.sql.symbol.CaseExpression;
 import com.metamatrix.query.sql.symbol.Function;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
 import com.metamatrix.query.sql.symbol.ScalarSubquery;
 import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
+import com.metamatrix.query.sql.symbol.XMLAttributes;
+import com.metamatrix.query.sql.symbol.XMLElement;
+import com.metamatrix.query.sql.symbol.XMLForest;
+import com.metamatrix.query.sql.symbol.XMLNamespaces;
 import com.metamatrix.query.sql.util.SymbolMap;
 import com.metamatrix.query.sql.visitor.EvaluatableVisitor;
 import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
@@ -96,10 +99,25 @@
     }
     
     @Override
-    public void visit(SQLXMLFunction obj) {
+    public void visit(XMLAttributes obj) {
     	markInvalid();
     }
     
+    @Override
+    public void visit(XMLNamespaces obj) {
+    	markInvalid();
+    }
+    
+    @Override
+    public void visit(XMLForest obj) {
+    	markInvalid();
+    }
+    
+    @Override
+    public void visit(XMLElement obj) {
+    	markInvalid();
+    }
+    
     public void visit(AggregateSymbol obj) {
         try {
             if(! CapabilitiesUtil.supportsAggregateFunction(modelID, obj, metadata, capFinder)) {

Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -135,7 +135,6 @@
 import com.metamatrix.query.sql.symbol.Function;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
 import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
 import com.metamatrix.query.sql.symbol.ScalarSubquery;
 import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -126,5 +126,8 @@
     public void visit(SetClauseList obj) {}
     public void visit(SetClause obj) {}
     public void visit(OrderByItem obj) {}
-    public void visit(SQLXMLFunction obj) {}
+    public void visit(XMLElement obj) {}
+    public void visit(XMLAttributes obj) {}
+    public void visit(XMLForest obj) {}
+    public void visit(XMLNamespaces obj) {}
 }

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -92,8 +92,11 @@
 import com.metamatrix.query.sql.symbol.Reference;
 import com.metamatrix.query.sql.symbol.ScalarSubquery;
 import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.XMLAttributes;
+import com.metamatrix.query.sql.symbol.XMLElement;
+import com.metamatrix.query.sql.symbol.XMLForest;
+import com.metamatrix.query.sql.symbol.XMLNamespaces;
 import com.metamatrix.query.sql.util.SymbolMap;
 
 
@@ -511,8 +514,9 @@
     }
     
     @Override
-    public void visit(SQLXMLFunction obj) {
+    public void visit(XMLForest obj) {
     	preVisitVisitor(obj);
+    	visitNode(obj.getNamespaces());
     	//we just want the underlying expressions, not the wrapping alias/expression symbols
     	for (SingleElementSymbol symbol : obj.getArgs()) {
         	visitNode(SymbolMap.getExpression(symbol));
@@ -520,6 +524,31 @@
         postVisitVisitor(obj);
     }
     
+    @Override
+    public void visit(XMLAttributes obj) {
+    	preVisitVisitor(obj);
+    	//we just want the underlying expressions, not the wrapping alias/expression symbols
+    	for (SingleElementSymbol symbol : obj.getArgs()) {
+        	visitNode(SymbolMap.getExpression(symbol));
+		}
+        postVisitVisitor(obj);
+    }
+    
+    @Override
+    public void visit(XMLElement obj) {
+    	preVisitVisitor(obj);
+    	visitNode(obj.getNamespaces());
+    	visitNode(obj.getAttributes());
+    	visitNodes(obj.getContent());
+    	postVisitVisitor(obj);
+    }
+    
+    @Override
+    public void visit(XMLNamespaces obj) {
+    	preVisitVisitor(obj);
+    	postVisitVisitor(obj);
+    }
+    
     public static void doVisit(LanguageObject object, LanguageVisitor visitor, boolean order) {
         PreOrPostOrderNavigator nav = new PreOrPostOrderNavigator(visitor, order);
         object.acceptVisitor(nav);

Deleted: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.sql.symbol;
-
-import java.util.List;
-
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.LanguageVisitor;
-import com.metamatrix.query.sql.visitor.SQLStringVisitor;
-
-/**
- * Represents XMLATTRIBUTES or XMLFOREST name value pairs
- */
-public class SQLXMLFunction implements Expression {
-
-	private static final long serialVersionUID = -3348922701950966494L;
-	private List<SingleElementSymbol> args;
-	private String name;
-	
-	public SQLXMLFunction(String name, List<SingleElementSymbol> args) {
-		this.name = name;
-		this.args = args;
-	}
-	
-	public List<SingleElementSymbol> getArgs() {
-		return args;
-	}
-	
-	public String getName() {
-		return name;
-	}
-
-	@Override
-	public Class<?> getType() {
-		return DataTypeManager.DefaultDataClasses.XML;
-	}
-
-	@Override
-	public boolean isResolved() {
-		for (SingleElementSymbol arg : args) {
-			if (!arg.isResolved()) {
-				return false;
-			}
-		}
-		return true;
-	}
-
-	@Override
-	public void acceptVisitor(LanguageVisitor visitor) {
-		visitor.visit(this);
-	}
-	
-	@Override
-	public SQLXMLFunction clone() {
-		return new SQLXMLFunction(name, LanguageObject.Util.deepClone(args, SingleElementSymbol.class));
-	}
-	
-	@Override
-	public int hashCode() {
-		return HashCodeUtil.hashCode(name.toUpperCase().hashCode(), args.hashCode());
-	}
-	
-	public boolean equals(Object obj) {
-		if (!(obj instanceof SQLXMLFunction)) {
-			return false;
-		}
-		SQLXMLFunction other = (SQLXMLFunction)obj;
-		return name.equalsIgnoreCase(other.name) && args.equals(other.args);
-	}
-	
-	@Override
-	public String toString() {
-		return SQLStringVisitor.getSQLString(this);
-	}
-	
-}

Added: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLAttributes.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLAttributes.java	                        (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLAttributes.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.sql.symbol;
+
+import java.util.List;
+
+import com.metamatrix.core.util.HashCodeUtil;
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.visitor.SQLStringVisitor;
+
+/**
+ * Represents XMLATTRIBUTES name value pairs
+ */
+public class XMLAttributes implements LanguageObject {
+
+	private static final long serialVersionUID = -3348922701950966494L;
+	private List<SingleElementSymbol> args;
+	
+	public XMLAttributes(List<SingleElementSymbol> args) {
+		this.args = args;
+	}
+	
+	public List<SingleElementSymbol> getArgs() {
+		return args;
+	}
+	
+	@Override
+	public XMLAttributes clone() {
+		XMLAttributes clone = new XMLAttributes(LanguageObject.Util.deepClone(args, SingleElementSymbol.class));
+		return clone;
+	}
+	
+	@Override
+	public int hashCode() {
+		return HashCodeUtil.hashCode(args.hashCode());
+	}
+	
+	public boolean equals(Object obj) {
+		if (obj == this) {
+			return true;
+		}
+		if (!(obj instanceof XMLAttributes)) {
+			return false;
+		}
+		XMLAttributes other = (XMLAttributes)obj;
+		return args.equals(other.args);
+	}
+
+	@Override
+	public void acceptVisitor(LanguageVisitor visitor) {
+		visitor.visit(this);
+	}
+	
+	@Override
+	public String toString() {
+		return SQLStringVisitor.getSQLString(this);
+	}
+	
+}


Property changes on: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLAttributes.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLElement.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLElement.java	                        (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLElement.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.sql.symbol;
+
+import java.util.List;
+
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.core.util.EquivalenceUtil;
+import com.metamatrix.core.util.HashCodeUtil;
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.visitor.SQLStringVisitor;
+
+/**
+ * Represents XMLATTRIBUTES/XMLFOREST name value pairs
+ */
+public class XMLElement implements Expression {
+
+	private static final long serialVersionUID = -3348922701950966494L;
+	private String name;
+	private XMLNamespaces namespaces;
+	private XMLAttributes attributes;
+	private List<Expression> content;
+	
+	public XMLElement(String name, List<Expression> content) {
+		this.name = name;
+		this.content = content;
+	}
+	
+	public XMLAttributes getAttributes() {
+		return attributes;
+	}
+	
+	public XMLNamespaces getNamespaces() {
+		return namespaces;
+	}
+	
+	public void setAttributes(XMLAttributes attributes) {
+		this.attributes = attributes;
+	}
+	
+	public void setNamespaces(XMLNamespaces namespaces) {
+		this.namespaces = namespaces;
+	}
+	
+	public List<Expression> getContent() {
+		return content;
+	}
+	
+	public String getName() {
+		return name;
+	}
+	
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+	public void setContent(List<Expression> args) {
+		this.content = args;
+	}
+
+	@Override
+	public Class<?> getType() {
+		return DataTypeManager.DefaultDataClasses.XML;
+	}
+
+	@Override
+	public boolean isResolved() {
+		for (Expression arg : content) {
+			if (!arg.isResolved()) {
+				return false;
+			}
+		}
+		return true;
+	}
+	
+	@Override
+	public void acceptVisitor(LanguageVisitor visitor) {
+		visitor.visit(this);
+	}
+		
+	@Override
+	public XMLElement clone() {
+		XMLElement clone = new XMLElement(name, LanguageObject.Util.deepClone(content, Expression.class));
+		if (namespaces != null) {
+			clone.setNamespaces(namespaces.clone());
+		}
+		if (attributes != null) {
+			clone.setAttributes(attributes.clone());
+		}
+		return clone;
+	}
+	
+	@Override
+	public int hashCode() {
+		return HashCodeUtil.hashCode(name.toUpperCase().hashCode(), content.hashCode());
+	}
+	
+	public boolean equals(Object obj) {
+		if (obj == this) {
+			return true;
+		}
+		if (!(obj instanceof XMLElement)) {
+			return false;
+		}
+		XMLElement other = (XMLElement)obj;
+		return name.equalsIgnoreCase(other.name) && content.equals(other.content) && EquivalenceUtil.areEqual(this.namespaces, other.namespaces);
+	}
+	
+	@Override
+	public String toString() {
+		return SQLStringVisitor.getSQLString(this);
+	}
+	
+}


Property changes on: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLElement.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLForest.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLForest.java	                        (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLForest.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.sql.symbol;
+
+import java.util.List;
+
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.core.util.EquivalenceUtil;
+import com.metamatrix.core.util.HashCodeUtil;
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.visitor.SQLStringVisitor;
+
+public class XMLForest implements Expression {
+
+	private static final long serialVersionUID = -3348922701950966494L;
+	private List<SingleElementSymbol> args;
+	private XMLNamespaces namespaces;
+	
+	public XMLForest(List<SingleElementSymbol> args) {
+		this.args = args;
+	}
+	
+	public XMLNamespaces getNamespaces() {
+		return namespaces;
+	}
+	
+	public void setNamespaces(XMLNamespaces namespaces) {
+		this.namespaces = namespaces;
+	}
+	
+	public List<SingleElementSymbol> getArgs() {
+		return args;
+	}
+
+	@Override
+	public Class<?> getType() {
+		return DataTypeManager.DefaultDataClasses.XML;
+	}
+
+	@Override
+	public boolean isResolved() {
+		for (SingleElementSymbol arg : args) {
+			if (!arg.isResolved()) {
+				return false;
+			}
+		}
+		return true;
+	}
+	
+	@Override
+	public void acceptVisitor(LanguageVisitor visitor) {
+		visitor.visit(this);
+	}
+		
+	@Override
+	public XMLForest clone() {
+		XMLForest clone = new XMLForest(LanguageObject.Util.deepClone(args, SingleElementSymbol.class));
+		return clone;
+	}
+	
+	@Override
+	public int hashCode() {
+		return HashCodeUtil.hashCode(args.hashCode());
+	}
+	
+	public boolean equals(Object obj) {
+		if (obj == this) {
+			return true;
+		}
+		if (!(obj instanceof XMLForest)) {
+			return false;
+		}
+		XMLForest other = (XMLForest)obj;
+		return args.equals(other.args);
+	}
+	
+	@Override
+	public String toString() {
+		return SQLStringVisitor.getSQLString(this);
+	}
+	
+}


Property changes on: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLForest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLNamespaces.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLNamespaces.java	                        (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLNamespaces.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.sql.symbol;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.metamatrix.core.util.EquivalenceUtil;
+import com.metamatrix.core.util.HashCodeUtil;
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.visitor.SQLStringVisitor;
+
+public class XMLNamespaces implements LanguageObject {
+	
+	private static final long serialVersionUID = 681076404921001047L;
+
+	public static class NamespaceItem {
+		private String uri;
+		private String prefix;
+		
+		public NamespaceItem(String uri, String prefix) {
+			this.uri = uri;
+			this.prefix = prefix;
+		}
+		
+		public NamespaceItem(String defaultNamepace) {
+			this.uri = defaultNamepace;
+		}
+		
+		public NamespaceItem() {
+		}
+		
+		public String getUri() {
+			return uri;
+		}
+		
+		public String getPrefix() {
+			return prefix;
+		}
+		
+		@Override
+		public int hashCode() {
+			return HashCodeUtil.hashCode(0, this.uri, this.prefix);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+			if (obj == this) {
+				return true;
+			}
+			if (!(obj instanceof NamespaceItem)) {
+				return false;
+			}
+			NamespaceItem other = (NamespaceItem)obj;
+			return EquivalenceUtil.areEqual(this.uri, other.uri) &&
+				EquivalenceUtil.areEqual(this.prefix, other.prefix);
+		}
+	}
+
+	private List<NamespaceItem> namespaceItems;
+	
+	
+	public XMLNamespaces(List<NamespaceItem> namespaceItems) {
+		this.namespaceItems = namespaceItems;
+	}
+	
+	public List<NamespaceItem> getNamespaceItems() {
+		return namespaceItems;
+	}
+	
+	@Override
+	public XMLNamespaces clone() {
+		XMLNamespaces clone = new XMLNamespaces(new ArrayList<NamespaceItem>(namespaceItems));
+		return clone;
+	}
+	
+	@Override
+	public int hashCode() {
+		return HashCodeUtil.hashCode(namespaceItems.hashCode());
+	}
+	
+	public boolean equals(Object obj) {
+		if (obj == this) {
+			return true;
+		}
+		if (!(obj instanceof XMLNamespaces)) {
+			return false;
+		}
+		XMLNamespaces other = (XMLNamespaces)obj;
+		return namespaceItems.equals(other.namespaceItems);
+	}
+
+	@Override
+	public void acceptVisitor(LanguageVisitor visitor) {
+		visitor.visit(this);
+	}
+	
+	@Override
+	public String toString() {
+		return SQLStringVisitor.getSQLString(this);
+	}
+	
+}


Property changes on: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/XMLNamespaces.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -45,7 +45,6 @@
 import com.metamatrix.query.sql.symbol.ExpressionSymbol;
 import com.metamatrix.query.sql.symbol.Function;
 import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
 import com.metamatrix.query.sql.symbol.ScalarSubquery;
 
 /**
@@ -172,9 +171,6 @@
 	}
 
 	public static final boolean isEvaluatable(LanguageObject obj, EvaluationLevel target) {
-		if (obj instanceof SQLXMLFunction && (FunctionLibrary.XMLATTRIBUTES.equalsIgnoreCase(((SQLXMLFunction)obj).getName()))) {
-			return false; //we want to preserve xmlattributes unless the parent xmlelement can be evaluated
-		}
         EvaluatableVisitor visitor = new EvaluatableVisitor();
         visitor.targetLevel = target;
         PreOrderNavigator.doVisit(obj, visitor);

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -57,9 +57,10 @@
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.ExpressionSymbol;
 import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
 import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.XMLAttributes;
+import com.metamatrix.query.sql.symbol.XMLForest;
 
 /**
  * It is important to use a Post Navigator with this class, 
@@ -86,9 +87,14 @@
     }
     
     @Override
-    public void visit(SQLXMLFunction obj) {
+    public void visit(XMLForest obj) {
     	replaceSymbols(obj.getArgs(), true);
     }
+    
+    @Override
+    public void visit(XMLAttributes obj) {
+    	replaceSymbols(obj.getArgs(), true);
+    }
 
     private void replaceSymbols(List symbols, boolean alias) {
         for (int i = 0; i < symbols.size(); i++) {

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -35,6 +35,7 @@
 
 import com.metamatrix.common.types.DataTypeManager;
 import com.metamatrix.core.util.StringUtil;
+import com.metamatrix.query.function.FunctionLibrary;
 import com.metamatrix.query.sql.LanguageObject;
 import com.metamatrix.query.sql.LanguageVisitor;
 import com.metamatrix.query.sql.lang.BetweenCriteria;
@@ -109,7 +110,11 @@
 import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
 import com.metamatrix.query.sql.symbol.SelectSymbol;
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
+import com.metamatrix.query.sql.symbol.XMLAttributes;
+import com.metamatrix.query.sql.symbol.XMLElement;
+import com.metamatrix.query.sql.symbol.XMLForest;
+import com.metamatrix.query.sql.symbol.XMLNamespaces;
+import com.metamatrix.query.sql.symbol.XMLNamespaces.NamespaceItem;
 
 /**
  * <p>The SQLStringVisitor will visit a set of language objects and return the
@@ -1243,7 +1248,7 @@
             }
             parts.add(")"); //$NON-NLS-1$
 
-		} else if (name.equalsIgnoreCase(SourceSystemFunctions.XMLELEMENT) || name.equalsIgnoreCase(SourceSystemFunctions.XMLPI)){
+		} else if (name.equalsIgnoreCase(SourceSystemFunctions.XMLPI)){
 			parts.add(name);
 			parts.add("(NAME "); //$NON-NLS-1$
 			outputDisplayName((String)((Constant)args[0]).getValue());
@@ -1538,15 +1543,74 @@
         parts.add(registerNode(obj.getCommand()));
         parts.add(")"); //$NON-NLS-1$
     }
-
+    
     @Override
-    public void visit(SQLXMLFunction obj) {
-    	parts.add(obj.getName());
+    public void visit(XMLAttributes obj) {
+    	parts.add(FunctionLibrary.XMLATTRIBUTES);
     	parts.add("("); //$NON-NLS-1$
     	registerNodes(obj.getArgs().toArray(new LanguageObject[obj.getArgs().size()]), 0);
     	parts.add(")"); //$NON-NLS-1$
     }
     
+    @Override
+    public void visit(XMLElement obj) {
+    	parts.add(FunctionLibrary.XMLELEMENT);
+    	parts.add("(NAME "); //$NON-NLS-1$
+    	outputDisplayName(obj.getName());
+    	if (obj.getNamespaces() != null) {
+    		parts.add(", "); //$NON-NLS-1$
+    		parts.add(registerNode(obj.getNamespaces()));
+    	}
+    	if (obj.getAttributes() != null) {
+    		parts.add(", "); //$NON-NLS-1$
+    		parts.add(registerNode(obj.getAttributes()));
+    	}
+    	if (!obj.getContent().isEmpty()) {
+    		parts.add(", "); //$NON-NLS-1$
+    	}
+		registerNodes(obj.getContent().toArray(new LanguageObject[obj.getContent().size()]), 0);
+    	parts.add(")"); //$NON-NLS-1$
+    }
+    
+    @Override
+    public void visit(XMLForest obj) {
+    	parts.add(FunctionLibrary.XMLFOREST);
+    	parts.add("("); //$NON-NLS-1$
+    	if (obj.getNamespaces() != null) {
+    		parts.add(registerNode(obj.getNamespaces()));
+    		parts.add(", "); //$NON-NLS-1$
+    	}
+    	registerNodes(obj.getArgs().toArray(new LanguageObject[obj.getArgs().size()]), 0);
+    	parts.add(")"); //$NON-NLS-1$
+    }
+    
+    @Override
+    public void visit(XMLNamespaces obj) {
+    	parts.add(FunctionLibrary.XMLNAMESPACES);
+    	parts.add("("); //$NON-NLS-1$
+    	for (Iterator<NamespaceItem> items = obj.getNamespaceItems().iterator(); items.hasNext();) {
+    		NamespaceItem item = items.next();
+    		if (item.getPrefix() == null) {
+    			if (item.getUri() == null) {
+    				parts.add("NO DEFAULT"); //$NON-NLS-1$
+    			} else {
+	    			parts.add("DEFAULT '"); //$NON-NLS-1$
+	        		parts.add(escapeStringValue(item.getUri(), "'")); //$NON-NLS-1$
+	        		parts.add("'"); //$NON-NLS-1$
+    			}
+    		} else {
+    			parts.add("'"); //$NON-NLS-1$
+    			parts.add(escapeStringValue(item.getUri(), "'")); //$NON-NLS-1$
+    			parts.add("' AS "); //$NON-NLS-1$
+        		outputDisplayName(item.getPrefix());
+    		}
+    		if (items.hasNext()) {
+    			parts.add(", "); //$NON-NLS-1$
+    		}
+    	}
+    	parts.add(")"); //$NON-NLS-1$
+    }
+    
     public void visit(Limit obj) {
         parts.add(SQLReservedWords.LIMIT);
         if (obj.getOffset() != null) {

Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -100,8 +100,9 @@
 import com.metamatrix.query.sql.symbol.Function;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
 import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.XMLAttributes;
+import com.metamatrix.query.sql.symbol.XMLForest;
 import com.metamatrix.query.sql.util.SymbolMap;
 import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
 import com.metamatrix.query.sql.visitor.CommandCollectorVisitor;
@@ -1140,12 +1141,21 @@
     }
     
     @Override
-    public void visit(SQLXMLFunction obj) {
+    public void visit(XMLAttributes obj) {
     	for (SingleElementSymbol arg : obj.getArgs()) {
     		if (arg instanceof ExpressionSymbol) {
     			handleValidationError("ValidationVisitor.expression_requires_name", arg); //$NON-NLS-1$
     		}
 		}
     }
+    
+    @Override
+    public void visit(XMLForest obj) {
+    	for (SingleElementSymbol arg : obj.getArgs()) {
+    		if (arg instanceof ExpressionSymbol) {
+    			handleValidationError("ValidationVisitor.expression_requires_name", arg); //$NON-NLS-1$
+    		}
+		}
+    }
         
 }

Modified: trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj	2010-05-10 17:42:42 UTC (rev 2109)
@@ -2977,32 +2977,10 @@
 		]
 		<RPAREN>
 	)  			
-	| ( funcToken = <XMLELEMENT>
-		<LPAREN>
-		(
-		 LOOKAHEAD(<ID>, { "name".equalsIgnoreCase(getToken(1).image) }) <ID> expression = idExpression()
-		 |
-		 expression = idExpression()
-		)
-		{
-			args.add(expression);	
-			expression = null;
-		}
-		[
-			LOOKAHEAD(2) <COMMA> expression = sqlXmlFunction(info)
-			{
-				args.add(expression);	
-				expression = null;
-			}	
-		]
-		(<COMMA> expression=expression(info)
-		{
-			args.add(expression);
-			expression = null;
-		}
-		)*
-		<RPAREN>
-	)
+	| expression = xmlElement(info)
+	  {
+	  	return expression;
+	  }
 	| ( funcToken = <XMLPI>
 		<LPAREN>
 		(
@@ -3023,13 +3001,10 @@
 		]
 		<RPAREN>
 	)
-	|
-	LOOKAHEAD(<XMLFOREST>) (
-		expression = sqlXmlFunction(info)
+	|	expression = xmlForest(info)
 		{
 			return expression;
 		}
-	)  				
 	|
 	(	funcName = id()
 		{ 
@@ -3059,17 +3034,51 @@
 			
 		return new Function(funcName, (Expression[])args.toArray(new Expression[args.size()]));
 	}
+}
+
+XMLElement xmlElement(ParseInfo info) :
+{
+	String name = null;
+	ArrayList content = new ArrayList();
+	XMLNamespaces xmlNamespaces = null;
+	XMLAttributes xmlAttributes = null;
+	Expression expression = null;
+}
+{
+	<XMLELEMENT> <LPAREN>
+	(
+	 LOOKAHEAD(<ID>, { "name".equalsIgnoreCase(getToken(1).image) }) <ID> name = id()
+	 |
+	 name = id()
+	)
+	[
+		LOOKAHEAD(2) <COMMA> xmlNamespaces = xmlNamespaces(info)
+	]
+	[
+		LOOKAHEAD(2) <COMMA> xmlAttributes = xmlAttributes(info)
+	]
+	(<COMMA> expression=expression(info)
+	{
+		content.add(expression);
+		expression = null;
+	}
+	)*
+	<RPAREN>
+	{
+		XMLElement result = new XMLElement(name, content);
+		result.setNamespaces(xmlNamespaces);
+		result.setAttributes(xmlAttributes);
+		return result;
+	}
 }	
 
-SQLXMLFunction sqlXmlFunction(ParseInfo info) :
+XMLAttributes xmlAttributes(ParseInfo info) :
 {
 	Expression expression = null;
 	ArrayList args = new ArrayList();
-	Token funcToken = null;
 }
 {
- 	(funcToken = <XMLFOREST> | funcToken = <XMLATTRIBUTES>)
-	<LPAREN>
+ 	<XMLATTRIBUTES> <LPAREN>
 	expression = selectExpression(info)
 	{
 		args.add(expression);
@@ -3083,10 +3092,86 @@
 	)*
 	<RPAREN>  		
 	{
-		return new SQLXMLFunction(funcToken.image, args);
+		return new XMLAttributes(args);
 	}
 }
 
+XMLForest xmlForest(ParseInfo info) :
+{
+	Expression expression = null;
+	XMLNamespaces xmlNamespaces = null;
+	ArrayList args = new ArrayList();
+}
+{
+ 	<XMLFOREST> <LPAREN>
+	[
+		xmlNamespaces = xmlNamespaces(info) <COMMA>
+	]
+	expression = selectExpression(info)
+	{
+		args.add(expression);
+		expression = null;
+	}
+	(<COMMA> expression=selectExpression(info)
+	 {
+		args.add(expression);
+		expression = null;
+	 }
+	)*
+	<RPAREN>  		
+	{
+		XMLForest result = new XMLForest(args);
+		result.setNamespaces(xmlNamespaces);
+		return result;
+	}
+}		
+		
+XMLNamespaces xmlNamespaces(ParseInfo info) :
+{
+	ArrayList namespaces = new ArrayList();
+	XMLNamespaces.NamespaceItem item = null;
+}
+{
+ 	<XMLNAMESPACES> <LPAREN>
+	item = namespaceItem(info)
+	{
+		namespaces.add(item);
+	}
+	(<COMMA> item = namespaceItem(info)
+	 {
+		 namespaces.add(item);
+	 }
+	)*
+	<RPAREN>  		
+	{
+		return new XMLNamespaces(namespaces);
+	}
+}
+
+XMLNamespaces.NamespaceItem namespaceItem(ParseInfo info) :
+{
+	String uri = null;
+	String prefix = null;
+}
+{
+	(
+		uri = stringVal() <AS> prefix = id()
+		{
+			return new XMLNamespaces.NamespaceItem(uri, prefix);
+		}
+	) | (
+		<NO> <DEFAULT_KEYWORD>
+		{
+			return new XMLNamespaces.NamespaceItem();
+		}
+	) | (
+		<DEFAULT_KEYWORD> uri = stringVal()
+		{
+			return new XMLNamespaces.NamespaceItem(uri);
+		}
+	)
+}
+
 Constant idExpression() :
 {
 	String id = null;

Modified: trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -1341,36 +1341,6 @@
         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name></Item></Items></Catalog></Catalogs>", xml);
     }
 	
-	@Test public void testInvokeXmlElement() throws Exception {
-        CommandContext c = new CommandContext();
-        c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
-        XMLType result = (XMLType)helpInvokeMethod("xmlelement", new Class[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.OBJECT, DataTypeManager.DefaultDataClasses.OBJECT}, 
-        		new Object[] {"foo", "<bar>", DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.XML)}, c);
-        
-        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
-        assertEquals("<foo>&lt;bar&gt;<Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs></foo>", xml);
-    }
-	
-	@Test public void testInvokeXmlElementWithFragment() throws Exception {
-        CommandContext c = new CommandContext();
-        c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
-        XMLType result = (XMLType)helpInvokeMethod("xmlelement", new Class[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.OBJECT, DataTypeManager.DefaultDataClasses.OBJECT}, 
-        		new Object[] {"foo", "<bar>", DataTypeManager.transformValue("<Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.XML)}, c);
-        
-        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
-        assertEquals("<foo>&lt;bar&gt;<Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs></foo>", xml);
-    }
-	
-	@Test public void testInvokeXmlElement2() throws Exception {
-        CommandContext c = new CommandContext();
-        c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
-        XMLType result = (XMLType)helpInvokeMethod("xmlelement", new Class[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.OBJECT}, 
-        		new Object[] {"foo", new Timestamp(0)}, c);
-        
-        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
-        assertEquals("<foo>1969-12-31T18:00:00</foo>", xml);
-    }
-	
 	@Test public void testInvokeXmlConcat() throws Exception {
         CommandContext c = new CommandContext();
         c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());

Modified: trunk/engine/src/test/java/com/metamatrix/query/function/source/TestXMLSystemFunctions.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/source/TestXMLSystemFunctions.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/test/java/com/metamatrix/query/function/source/TestXMLSystemFunctions.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -28,11 +28,15 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
+import java.sql.Timestamp;
+import java.util.TimeZone;
 
 import javax.xml.xpath.XPathExpressionException;
 
 import org.jdom.Attribute;
 import org.jdom.Element;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.metamatrix.api.exception.query.FunctionExecutionException;
@@ -205,5 +209,17 @@
         final String xpath = "//*:ReadOnly"; //$NON-NLS-1$
         helpTestXpathValue(xmlFilePath,xpath,null, "false"); //$NON-NLS-1$
     }
+    
+	@Test public void testInvokeXmlElement2() throws Exception {
+		assertEquals("1969-12-31T18:00:00", XMLSystemFunctions.getStringValue(new Timestamp(0)));
+    }
+	
+	@BeforeClass static public void setUpOnce() {
+		TimeZone.setDefault(TimeZone.getTimeZone("GMT-6:00"));
+	}
+	
+	@AfterClass static public void tearDownOnce() {
+		TimeZone.setDefault(null);
+	}
 
 }

Modified: trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -106,7 +106,10 @@
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 import com.metamatrix.query.sql.symbol.TestCaseExpression;
 import com.metamatrix.query.sql.symbol.TestSearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.SQLXMLFunction;
+import com.metamatrix.query.sql.symbol.XMLAttributes;
+import com.metamatrix.query.sql.symbol.XMLElement;
+import com.metamatrix.query.sql.symbol.XMLForest;
+import com.metamatrix.query.sql.symbol.XMLNamespaces;
 
 @SuppressWarnings("nls")
 public class TestParser {
@@ -2947,25 +2950,6 @@
                  query);        
     }
 
-    /** SELECT neato."cheese brain" FROM neato */
-    public void XXX_testSpacesInIdentifiers() {
-        GroupSymbol g = new GroupSymbol("neato"); //$NON-NLS-1$
-        From from = new From();
-        from.addGroup(g);
-
-        Select select = new Select();
-        ElementSymbol symbol = new ElementSymbol("cheese brain"); //$NON-NLS-1$
-        symbol.setGroupSymbol(g);
-        select.addSymbol(symbol);
-        
-        Query query = new Query();
-        query.setSelect(select);
-        query.setFrom(from);
-        helpTest("SELECT neato.\"cheese brain\" FROM neato",  //$NON-NLS-1$
-                 "SELECT neato.\"cheese brain\" FROM neato",  //$NON-NLS-1$
-                 query);        
-    }
-    
     /** SELECT a, b FROM (SELECT c FROM m.g) AS y */
     @Test public void testSubquery1() {
         GroupSymbol g = new GroupSymbol("m.g"); //$NON-NLS-1$
@@ -6719,28 +6703,35 @@
     }
     
     @Test public void testXmlElement() throws Exception {
-    	Function f = new Function("xmlelement", new Expression[] {new Constant("table"), new Constant("x")});
-    	helpTestExpression("xmlelement(name \"table\", 'x')", "xmlelement(NAME \"table\", 'x')", f);
+    	XMLElement f = new XMLElement("table", Arrays.asList((Expression)new Constant("x")));
+    	helpTestExpression("xmlelement(name \"table\", 'x')", "XMLELEMENT(NAME \"table\", 'x')", f);
     }
 
     @Test public void testXmlElement1() throws Exception {
-    	Function f = new Function("xmlelement", new Expression[] {new Constant("table"), new Constant("x")});
-    	helpTestExpression("xmlelement(\"table\", 'x')", "xmlelement(NAME \"table\", 'x')", f);
+    	XMLElement f = new XMLElement("table", Arrays.asList((Expression)new Constant("x")));
+    	helpTestExpression("xmlelement(\"table\", 'x')", "XMLELEMENT(NAME \"table\", 'x')", f);
     }
     
     @Test public void testXmlElementWithAttributes() throws Exception {
-    	Function f = new Function("xmlelement", new Expression[] {new Constant("y"), new SQLXMLFunction("xmlattributes", Arrays.asList((SingleElementSymbol)new AliasSymbol("val", new ExpressionSymbol("", new Constant("a")))))});
-    	helpTestExpression("xmlelement(y, xmlattributes('a' as val))", "xmlelement(NAME y, xmlattributes('a' AS val))", f);
+    	XMLElement f = new XMLElement("y", new ArrayList<Expression>());
+    	f.setAttributes(new XMLAttributes(Arrays.asList((SingleElementSymbol)new AliasSymbol("val", new ExpressionSymbol("", new Constant("a"))))));
+    	helpTestExpression("xmlelement(y, xmlattributes('a' as val))", "XMLELEMENT(NAME y, XMLATTRIBUTES('a' AS val))", f);
     }
     
     @Test public void testXmlForest() throws Exception {
-    	SQLXMLFunction f = new SQLXMLFunction("xmlforest", Arrays.asList((SingleElementSymbol)new AliasSymbol("table", new ElementSymbol("a"))));
-    	helpTestExpression("xmlforest(a as \"table\")", "xmlforest(a AS \"table\")", f);
+    	XMLForest f = new XMLForest(Arrays.asList((SingleElementSymbol)new AliasSymbol("table", new ElementSymbol("a"))));
+    	helpTestExpression("xmlforest(a as \"table\")", "XMLFOREST(a AS \"table\")", f);
     }
     
     @Test public void testXmlPi() throws Exception {
     	Function f = new Function("xmlpi", new Expression[] {new Constant("a"), new ElementSymbol("val")});
     	helpTestExpression("xmlpi(NAME a, val)", "xmlpi(NAME a, val)", f);
     }
+    
+    @Test public void testXmlNamespaces() throws Exception {
+    	XMLForest f = new XMLForest(Arrays.asList((SingleElementSymbol)new AliasSymbol("table", new ElementSymbol("a"))));
+    	f.setNamespaces(new XMLNamespaces(Arrays.asList(new XMLNamespaces.NamespaceItem(), new XMLNamespaces.NamespaceItem("x", "http://foo"))));
+    	helpTestExpression("xmlforest(xmlnamespaces(no default, 'http://foo' as x), a as \"table\")", "XMLFOREST(XMLNAMESPACES(NO DEFAULT, 'http://foo' AS x), a AS \"table\")", f);
+    }
 
 }

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -7482,93 +7482,6 @@
         
         helpProcess(plan, dataManager, expected);
     }
-    
-    @Test public void testXmlElement() {
-        String sql = "SELECT xmlelement(e1, e2) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
         
-        List[] expected = new List[] {
-        		Arrays.asList("<e1>1</e1>"),
-        		Arrays.asList("<e1>0</e1>"),
-        		Arrays.asList("<e1>0</e1>"),
-        		Arrays.asList("<e1>3</e1>"),
-        		Arrays.asList("<e1>2</e1>"),
-                Arrays.asList("<e1>1</e1>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithConcat() {
-        String sql = "SELECT xmlelement(e1, e2, xmlconcat(xmlelement(x), xmlelement(y, e3))) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<e1>1<x></x><y>false</y></e1>"),
-        		Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
-        		Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
-        		Arrays.asList("<e1>3<x></x><y>true</y></e1>"),
-        		Arrays.asList("<e1>2<x></x><y>false</y></e1>"),
-                Arrays.asList("<e1>1<x></x><y>true</y></e1>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithForest() {
-        String sql = "SELECT xmlelement(x, xmlforest(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<x><e2>1</e2><val>1</val></x>"), //note e1 is not present, because it's null
-        		Arrays.asList("<x><e1>a</e1><e2>0</e2><val>1</val></x>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithAttributes() {
-        String sql = "SELECT xmlelement(x, xmlattributes(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<x e2=\"1\" val=\"1\"></x>"), //note e1 is not present, because it's null
-        		Arrays.asList("<x e1=\"a\" e2=\"0\" val=\"1\"></x>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithPi() {
-        String sql = "SELECT xmlelement(x, xmlpi(name e1, '  1'))"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<x><?e1 1?></x>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
     private static final boolean DEBUG = false;
 }

Added: trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java	                        (rev 0)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -0,0 +1,174 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.processor;
+
+import static com.metamatrix.query.processor.TestProcessor.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+import com.metamatrix.query.unittest.FakeMetadataFactory;
+
+ at SuppressWarnings("nls")
+public class TestSQLXMLProcessing {
+	
+	@Test public void testXmlElementTextContent() throws Exception {
+		String sql = "SELECT xmlelement(foo, '<bar>', convert('<bar1/>', xml))"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<foo>&lt;bar&gt;<bar1/></foo>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+	
+	/**
+	 * Repeat of the above test, but with a document declaration.  Because of the way we do event filtering, we end
+	 * up with a slightly different, but equivalent answer.
+	 */
+	@Test public void testXmlElementTextContent1() throws Exception {
+		String sql = "SELECT xmlelement(foo, '<bar>', convert('<?xml version=\"1.0\" encoding=\"UTF-8\"?><bar1/>', xml))"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<foo>&lt;bar&gt;<bar1></bar1></foo>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+	}
+	
+    @Test public void testXmlElement() {
+        String sql = "SELECT xmlelement(e1, e2) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<e1>1</e1>"),
+        		Arrays.asList("<e1>0</e1>"),
+        		Arrays.asList("<e1>0</e1>"),
+        		Arrays.asList("<e1>3</e1>"),
+        		Arrays.asList("<e1>2</e1>"),
+                Arrays.asList("<e1>1</e1>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithConcat() {
+        String sql = "SELECT xmlelement(e1, e2, xmlconcat(xmlelement(x), xmlelement(y, e3))) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<e1>1<x></x><y>false</y></e1>"),
+        		Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
+        		Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
+        		Arrays.asList("<e1>3<x></x><y>true</y></e1>"),
+        		Arrays.asList("<e1>2<x></x><y>false</y></e1>"),
+                Arrays.asList("<e1>1<x></x><y>true</y></e1>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithForest() {
+        String sql = "SELECT xmlelement(x, xmlforest(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<x><e2>1</e2><val>1</val></x>"), //note e1 is not present, because it's null
+        		Arrays.asList("<x><e1>a</e1><e2>0</e2><val>1</val></x>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithAttributes() {
+        String sql = "SELECT xmlelement(x, xmlattributes(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<x e2=\"1\" val=\"1\"></x>"), //note e1 is not present, because it's null
+        		Arrays.asList("<x e1=\"a\" e2=\"0\" val=\"1\"></x>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithPi() {
+        String sql = "SELECT xmlelement(x, xmlpi(name e1, '  1'))"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<x><?e1 1?></x>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithNamespaces() {
+        String sql = "SELECT xmlelement(x, xmlnamespaces(no default, 'http://foo' as x, 'http://foo1' as y), xmlattributes(e1), e2) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<x xmlns=\"\" xmlns:x=\"http://foo\" xmlns:y=\"http://foo1\">1</x>"), //note e1 is not present, because it's null
+        		Arrays.asList("<x xmlns=\"\" xmlns:x=\"http://foo\" xmlns:y=\"http://foo1\" e1=\"a\">0</x>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+
+}


Property changes on: trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java	2010-05-10 01:46:37 UTC (rev 2108)
+++ trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java	2010-05-10 17:42:42 UTC (rev 2109)
@@ -1963,6 +1963,10 @@
         helpValidate("SELECT xmlelement(name a, xmlattributes('1'))", new String[] {"'1'"}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 	
+	@Test public void testValidateNoExpressionName1() {        
+        helpValidate("SELECT xmlforest('1')", new String[] {"'1'"}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
+	}
+	
     @Test public void testXpathValueValid_defect15088() {
         String userSql = "SELECT xpathValue('<?xml version=\"1.0\" encoding=\"utf-8\" ?><a><b><c>test</c></b></a>', 'a/b/c')"; //$NON-NLS-1$
         helpValidate(userSql, new String[] {}, FakeMetadataFactory.exampleBQTCached());        



More information about the teiid-commits mailing list