[teiid-commits] teiid SVN: r2100 - in trunk: common-core/src/main/java/com/metamatrix/common/types and 41 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu May 6 13:17:47 EDT 2010


Author: shawkins
Date: 2010-05-06 13:17:44 -0400 (Thu, 06 May 2010)
New Revision: 2100

Added:
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.java
Modified:
   trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java
   trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java
   trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java
   trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java
   trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java
   trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java
   trunk/common-core/src/test/java/com/metamatrix/common/types/basic/TestStringToXmlTransform.java
   trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java
   trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java
   trunk/connectors/connector-xml-file/src/main/java/org/teiid/connector/xml/file/FileProcedureExecution.java
   trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/TestElementCollector.java
   trunk/documentation/reference/src/main/docbook/en-US/content/grammar.xml
   trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
   trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
   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/RelationalPlanner.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/QueryUtil.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/xml/XMLUtil.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/xml/XMLValueTranslator.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/xquery/XQueryPlan.java
   trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitor.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/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java
   trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
   trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
   trunk/engine/src/test/java/com/metamatrix/cdk/CommandBuilder.java
   trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/batch/TestBatchedUpdatePlanner.java
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java
   trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestInstructions.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java
   trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
   trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
Log:
TEIID-171 refining support for the xmlelement function, adding xmlattributes, xmlconcat, and xmlforest

Modified: trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -68,10 +68,10 @@
     
     private static final <T> T transform(Object value, Class<T> targetType, Class<?> runtimeType, String typeName) throws SQLException {
     	if (value == null || targetType.isAssignableFrom(value.getClass())) {
-    		return (T)value;
+    		return targetType.cast(value);
     	}
     	try {
-    		return (T)DataTypeManager.transformValue(DataTypeManager.convertToRuntimeType(value), runtimeType);
+    		return targetType.cast(DataTypeManager.transformValue(DataTypeManager.convertToRuntimeType(value), runtimeType));
     	} catch (TransformationException e) {
     		String valueStr = value.toString();
     		if (valueStr.length() > 20) {

Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -449,7 +449,7 @@
 	 * @param type
 	 * @return true if yes; false otherwise
 	 */
-	public static boolean isLOB(Class type) {
+	public static boolean isLOB(Class<?> type) {
 		return DataTypeManager.DefaultDataClasses.BLOB.equals(type)
 				|| DataTypeManager.DefaultDataClasses.CLOB.equals(type)
 				|| DataTypeManager.DefaultDataClasses.XML.equals(type);

Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -22,13 +22,13 @@
 
 package com.metamatrix.common.types;
 
-import com.metamatrix.api.exception.MetaMatrixException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 
 /**
  * The exception is thrown when an error occurs during data transformation,
  * typically a formatting error or an invalid input type.
  */
-public class TransformationException extends MetaMatrixException {
+public class TransformationException extends MetaMatrixProcessingException {
 
     /**
      * No-Arg Constructor

Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -44,8 +44,14 @@
  * only SQLXML interface on top of this.
  */
 public final class XMLType extends Streamable<SQLXML> implements SQLXML {
-
+	
+	public enum Type {
+		UNKNOWN, DOCUMENT, FRAGMENT, SIBLINGS
+	}
+	
 	private static final long serialVersionUID = -7922647237095135723L;
+	
+	private transient Type type = Type.UNKNOWN;
     
     public XMLType(){
         
@@ -90,5 +96,14 @@
 	public <T extends Result> T setResult(Class<T> resultClass)
 			throws SQLException {
 		return this.reference.setResult(resultClass);
-	}      
+	} 
+	
+	public Type getType() {
+		return type;
+	}
+	
+	public void setType(Type type) {
+		this.type = type;
+	}
+	
 }

Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -37,6 +37,7 @@
 import com.metamatrix.common.types.Transform;
 import com.metamatrix.common.types.TransformationException;
 import com.metamatrix.common.types.XMLType;
+import com.metamatrix.common.types.XMLType.Type;
 import com.metamatrix.common.util.ReaderInputStream;
 import com.metamatrix.core.CorePlugin;
 
@@ -66,21 +67,25 @@
         Reader reader = null;
         try {
         	reader = source.getCharacterStream();
-            StringToSQLXMLTransform.isXml(reader);
+        	XMLType result = null;
+            Type type = StringToSQLXMLTransform.isXml(reader);
             if (source.getReference() instanceof ClobImpl) {
             	ClobImpl clob = (ClobImpl)source.getReference();
-            	return new XMLType(new SQLXMLImpl(clob.getStreamFactory()));
-            } 
-            return new XMLType(new SQLXMLImpl(new InputStreamFactory(Streamable.ENCODING) {
-            	@Override
-            	public InputStream getInputStream() throws IOException {
-            		try {
-						return new ReaderInputStream(source.getCharacterStream(), Charset.forName(Streamable.ENCODING));
-					} catch (SQLException e) {
-						throw new IOException(e);
-					}
-            	}
-            }));
+            	result = new XMLType(new SQLXMLImpl(clob.getStreamFactory()));
+            } else {
+            	result = new XMLType(new SQLXMLImpl(new InputStreamFactory(Streamable.ENCODING) {
+	            	@Override
+	            	public InputStream getInputStream() throws IOException {
+	            		try {
+							return new ReaderInputStream(source.getCharacterStream(), Charset.forName(Streamable.ENCODING));
+						} catch (SQLException e) {
+							throw new IOException(e);
+						}
+	            	}
+            	}));
+            }
+            result.setType(type);
+            return result;
         } catch (SQLException e) {
             throw new TransformationException(e, CorePlugin.Util.getString("failed_convert", new Object[] {getSourceType().getName(), getTargetType().getName()})); //$NON-NLS-1$            
         } finally {

Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -26,17 +26,16 @@
 import java.io.Reader;
 import java.io.StringReader;
 
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.events.XMLEvent;
 
-import org.xml.sax.InputSource;
-import org.xml.sax.helpers.DefaultHandler;
-
 import com.metamatrix.common.types.DataTypeManager;
 import com.metamatrix.common.types.SQLXMLImpl;
 import com.metamatrix.common.types.Transform;
 import com.metamatrix.common.types.TransformationException;
 import com.metamatrix.common.types.XMLType;
+import com.metamatrix.common.types.XMLType.Type;
 import com.metamatrix.core.CorePlugin;
 
 public class StringToSQLXMLTransform extends Transform {
@@ -52,15 +51,23 @@
 	public Object transformDirect(Object value) throws TransformationException {
         String xml = (String)value;
         Reader reader = new StringReader(xml);
-        isXml(reader);
-        return new XMLType(new SQLXMLImpl(xml));
+        Type type = isXml(reader);
+        XMLType result = new XMLType(new SQLXMLImpl(xml));
+        result.setType(type);
+        return result;
 	}
 
-	static void isXml(Reader reader) throws TransformationException {
-		SAXParserFactory spf = SAXParserFactory.newInstance();
+	static Type isXml(Reader reader) throws TransformationException {
+		Type type = Type.FRAGMENT;
+		XMLInputFactory inputFactory = XMLInputFactory.newInstance();
         try{        
-             SAXParser sp = spf.newSAXParser();
-             sp.parse(new InputSource(reader), new DefaultHandler());
+             XMLEventReader xmlReader = inputFactory.createXMLEventReader(reader);
+             while (xmlReader.hasNext()) {
+            	 XMLEvent event = xmlReader.nextEvent();
+            	 if  (event.isStartDocument() && event.getLocation().getColumnNumber() != 1) {
+            		 type = Type.DOCUMENT;
+            	 }
+             }
         } catch (Exception e){
             throw new TransformationException(e, CorePlugin.Util.getString("invalid_string")); //$NON-NLS-1$
         } finally {
@@ -69,6 +76,7 @@
 			} catch (IOException e) {
 			}
         }
+        return type;
 	}
 
 	/**

Modified: trunk/common-core/src/test/java/com/metamatrix/common/types/basic/TestStringToXmlTransform.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/types/basic/TestStringToXmlTransform.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/common-core/src/test/java/com/metamatrix/common/types/basic/TestStringToXmlTransform.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -27,7 +27,6 @@
 
 import java.sql.SQLXML;
 
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.metamatrix.common.types.TransformationException;
@@ -58,14 +57,4 @@
        transform.transformDirect(xml);
     }    
     
-    @Ignore("TODO: allow for fragments in the xml type")
-    @Test public void testXMLFragment() throws Exception {
-        String xml = "<name>ABC</name>" + //$NON-NLS-1$
-                     "<age>32</age>"; //$NON-NLS-1$
-                     
-       StringToSQLXMLTransform transform = new StringToSQLXMLTransform();
-       
-       transform.transformDirect(xml);
-    }    
-
 }

Modified: trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -138,5 +138,6 @@
 	public static final String XPATHVALUE = "xpathvalue"; //$NON-NLS-1$
 	public static final String XSLTRANSFORM = "xsltransform"; //$NON-NLS-1$
 	public static final String XMLELEMENT = "xmlelement"; //$NON-NLS-1$
+	public static final String XMLCONCAT = "xmlconcat"; //$NON-NLS-1$
 
 }

Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -425,12 +425,7 @@
      */
     @Test public void test_sdo_within_distance3() throws Exception {
         String input = "SELECT INTKEY FROM BQT1.SMALLA WHERE sdo_within_distance(STRINGKEY, 'SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL)', 'DISTANCE=25.0 UNIT=NAUT_MILE') = true"; //$NON-NLS-1$
-        // using ? for bind value as r marks the criteria as bindEligible 
-        // due to literal of type Object appearing in left side of criteria.  
-        // The literal Object is a result of the sdo_within_distance function 
-        // signature being sdo_within_distance(string, object, string) : string 
-        // as the signature was the best match for this query.
-        String output = "SELECT SmallA.IntKey FROM SmallA WHERE sdo_within_distance(SmallA.StringKey, SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL), 'DISTANCE=25.0 UNIT=NAUT_MILE') = ?";  //$NON-NLS-1$
+        String output = "SELECT SmallA.IntKey FROM SmallA WHERE sdo_within_distance(SmallA.StringKey, SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL), 'DISTANCE=25.0 UNIT=NAUT_MILE') = 'true'";  //$NON-NLS-1$
 
         TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, UDF,
                 input, output, 
@@ -446,12 +441,7 @@
      */
     @Test public void test_sdo_within_distance4() throws Exception {
         String input = "SELECT INTKEY FROM BQT1.SMALLA WHERE sdo_within_distance('SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL)', 'SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL)', 'DISTANCE=25.0 UNIT=NAUT_MILE') = true"; //$NON-NLS-1$
-        // using ? for bind value as r marks the criteria as bindEligible 
-        // due to literal of type Object appearing in left side of criteria.  
-        // The literal Object is a result of the sdo_within_distance function 
-        // signature being sdo_within_distance(string, object, string) : string 
-        // as the signature was the best match for this query.
-        String output = "SELECT SmallA.IntKey FROM SmallA WHERE sdo_within_distance(SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL), SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL), 'DISTANCE=25.0 UNIT=NAUT_MILE') = ?";  //$NON-NLS-1$
+        String output = "SELECT SmallA.IntKey FROM SmallA WHERE sdo_within_distance(SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL), SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(90.0, -45.0, NULL), NULL, NULL), 'DISTANCE=25.0 UNIT=NAUT_MILE') = 'true'";  //$NON-NLS-1$
 
         TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, UDF,
                 input, output, 

Modified: trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/TestElementCollector.java
===================================================================
--- trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/TestElementCollector.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/connectors/connector-xml/src/test/java/com/metamatrix/connector/xml/TestElementCollector.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -11,10 +11,10 @@
 
 import junit.framework.TestCase;
 
-import org.teiid.connector.basic.TypeFacilityImpl;
 import org.teiid.connector.language.Select;
 
 import com.metamatrix.common.types.InputStreamFactory;
+import com.metamatrix.common.types.SQLXMLImpl;
 import com.metamatrix.connector.xml.base.ExecutionInfo;
 import com.metamatrix.connector.xml.base.ProxyObjectFactory;
 import com.metamatrix.connector.xml.base.QueryAnalyzer;
@@ -23,6 +23,7 @@
 import com.metamatrix.connector.xml.streaming.ReaderFactory;
 import com.metamatrix.connector.xml.streaming.StreamingRowCollector;
 
+ at SuppressWarnings("nls")
 public class TestElementCollector extends TestCase {
 
 	StreamingRowCollector builder;
@@ -80,6 +81,6 @@
 				return in;
 			}
 		};
-		return (SQLXML)new TypeFacilityImpl().convertToRuntimeType(isf);
+		return new SQLXMLImpl(isf);
 	}
 }

Modified: trunk/connectors/connector-xml-file/src/main/java/org/teiid/connector/xml/file/FileProcedureExecution.java
===================================================================
--- trunk/connectors/connector-xml-file/src/main/java/org/teiid/connector/xml/file/FileProcedureExecution.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/connectors/connector-xml-file/src/main/java/org/teiid/connector/xml/file/FileProcedureExecution.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -41,6 +41,7 @@
 import org.teiid.connector.metadata.runtime.RuntimeMetadata;
 
 import com.metamatrix.common.types.InputStreamFactory;
+import com.metamatrix.common.types.SQLXMLImpl;
 
 
 /** 
@@ -94,7 +95,7 @@
         
         String encoding = this.config.getCharacterEncodingScheme();
         
-        returnValue = (SQLXML)this.config.getTypeFacility().convertToRuntimeType(new InputStreamFactory(encoding) {
+        returnValue = new SQLXMLImpl(new InputStreamFactory(encoding) {
 			
 			@Override
 			public InputStream getInputStream() throws IOException {

Modified: trunk/documentation/reference/src/main/docbook/en-US/content/grammar.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/grammar.xml	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/grammar.xml	2010-05-06 17:17:44 UTC (rev 2100)
@@ -121,7 +121,6 @@
 | &lt;DAY: "day"&gt;
 | &lt;DEALLOCATE: "deallocate"&gt;
 | &lt;DEFAULT_KEYWORD: "default"&gt;
-| &lt;DEBUG: "debug"&gt;
 | &lt;DECLARE: "declare"&gt;
 | &lt;DELETE: "delete"&gt;
 | &lt;DESC: "desc"&gt;
@@ -211,7 +210,6 @@
 | &lt;OVERLAPS: "OVERLAPS"&gt;
 | &lt;PARAMETER: "parameter"&gt;
 | &lt;PARTITION: "partition"&gt;
-| &lt;PLANONLY: "planonly"&gt;
 | &lt;PRECISION: "precision"&gt;
 | &lt;PREPARE: "prepare"&gt;
 | &lt;PRIMARY: "primary"&gt;
@@ -237,7 +235,6 @@
 | &lt;SENSITIVE: "sensitive"&gt;
 | &lt;SESSION_USER: "session_user"&gt;
 | &lt;SET: "set"&gt;
-| &lt;SHOWPLAN: "showplan"&gt;
 | &lt;SIMILAR: "similar"&gt;
 | &lt;SPECIFIC: "specific"&gt;
 | &lt;SOME: "some"&gt;
@@ -551,45 +548,53 @@
 <row>
 <entry align="right" valign="top"><para><anchor id="prod52" xreflabel="selectSymbol"/>selectSymbol</para></entry>
 <entry align="left" valign="top"><para>::= 
-( ( &lt;ALL_IN_GROUP&gt; ) | ( <link linkend="prod16">expression</link> ) ( ( &lt;AS&gt; )? ( <link linkend="prod2">id</link> ) )? )</para></entry></row>
+( <link linkend="prod53">selectExpression</link> | <link linkend="prod54">allInGroupSymbol</link> )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod53" xreflabel="aggregateSymbol"/>aggregateSymbol</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod53" xreflabel="selectExpression"/>selectExpression</para></entry>
 <entry align="left" valign="top"><para>::= 
+( <link linkend="prod16">expression</link> ( ( &lt;AS&gt; )? ( <link linkend="prod2">id</link> ) )? )</para></entry></row>
+<row>
+<entry align="right" valign="top"><para><anchor id="prod54" xreflabel="allInGroupSymbol"/>allInGroupSymbol</para></entry>
+<entry align="left" valign="top"><para>::= 
+( &lt;ALL_IN_GROUP&gt; )</para></entry></row>
+<row>
+<entry align="right" valign="top"><para><anchor id="prod55" xreflabel="aggregateSymbol"/>aggregateSymbol</para></entry>
+<entry align="left" valign="top"><para>::= 
 ( ( &lt;COUNT&gt; &lt;LPAREN&gt; &lt;STAR&gt; &lt;RPAREN&gt; ) | ( ( &lt;COUNT&gt; | &lt;SUM&gt; | &lt;AVG&gt; | &lt;MIN&gt; | &lt;MAX&gt; ) &lt;LPAREN&gt; ( &lt;DISTINCT&gt; )? <link linkend="prod16">expression</link> &lt;RPAREN&gt; ) )</para></entry></row>
 <row>
 <entry align="right" valign="top"><para><anchor id="prod49" xreflabel="from"/>from</para></entry>
 <entry align="left" valign="top"><para>::= 
-&lt;FROM&gt; ( <link linkend="prod54">tableReference</link> ( &lt;COMMA&gt; <link linkend="prod54">tableReference</link> )* )</para></entry></row>
+&lt;FROM&gt; ( <link linkend="prod56">tableReference</link> ( &lt;COMMA&gt; <link linkend="prod56">tableReference</link> )* )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod54" xreflabel="tableReference"/>tableReference</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod56" xreflabel="tableReference"/>tableReference</para></entry>
 <entry align="left" valign="top"><para>::= 
-( ( &lt;LBRACE&gt; &lt;OJ&gt; <link linkend="prod55">tableReferenceUnescaped</link> &lt;RBRACE&gt; ) | <link linkend="prod55">tableReferenceUnescaped</link> )</para></entry></row>
+( ( &lt;LBRACE&gt; &lt;OJ&gt; <link linkend="prod57">tableReferenceUnescaped</link> &lt;RBRACE&gt; ) | <link linkend="prod57">tableReferenceUnescaped</link> )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod55" xreflabel="tableReferenceUnescaped"/>tableReferenceUnescaped</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod57" xreflabel="tableReferenceUnescaped"/>tableReferenceUnescaped</para></entry>
 <entry align="left" valign="top"><para>::= 
-( <link linkend="prod56">joinedTable</link> | <link linkend="prod57">tablePrimary</link> )</para></entry></row>
+( <link linkend="prod58">joinedTable</link> | <link linkend="prod59">tablePrimary</link> )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod56" xreflabel="joinedTable"/>joinedTable</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod58" xreflabel="joinedTable"/>joinedTable</para></entry>
 <entry align="left" valign="top"><para>::= 
-<link linkend="prod57">tablePrimary</link> ( ( <link linkend="prod58">crossJoin</link> | <link linkend="prod59">qualifiedJoin</link> ) )+</para></entry></row>
+<link linkend="prod59">tablePrimary</link> ( ( <link linkend="prod60">crossJoin</link> | <link linkend="prod61">qualifiedJoin</link> ) )+</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod58" xreflabel="crossJoin"/>crossJoin</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod60" xreflabel="crossJoin"/>crossJoin</para></entry>
 <entry align="left" valign="top"><para>::= 
-( ( &lt;CROSS&gt; | &lt;UNION&gt; ) &lt;JOIN&gt; <link linkend="prod57">tablePrimary</link> )</para></entry></row>
+( ( &lt;CROSS&gt; | &lt;UNION&gt; ) &lt;JOIN&gt; <link linkend="prod59">tablePrimary</link> )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod59" xreflabel="qualifiedJoin"/>qualifiedJoin</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod61" xreflabel="qualifiedJoin"/>qualifiedJoin</para></entry>
 <entry align="left" valign="top"><para>::= 
-( ( ( &lt;RIGHT&gt; ( &lt;OUTER&gt; )? ) | ( &lt;LEFT&gt; ( &lt;OUTER&gt; )? ) | ( &lt;FULL&gt; ( &lt;OUTER&gt; )? ) | &lt;INNER&gt; )? &lt;JOIN&gt; <link linkend="prod54">tableReference</link> &lt;ON&gt; <link linkend="prod28">criteria</link> )</para></entry></row>
+( ( ( &lt;RIGHT&gt; ( &lt;OUTER&gt; )? ) | ( &lt;LEFT&gt; ( &lt;OUTER&gt; )? ) | ( &lt;FULL&gt; ( &lt;OUTER&gt; )? ) | &lt;INNER&gt; )? &lt;JOIN&gt; <link linkend="prod56">tableReference</link> &lt;ON&gt; <link linkend="prod28">criteria</link> )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod57" xreflabel="tablePrimary"/>tablePrimary</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod59" xreflabel="tablePrimary"/>tablePrimary</para></entry>
 <entry align="left" valign="top"><para>::= 
-( <link linkend="prod60">unaryFromClause</link> | <link linkend="prod61">subqueryFromClause</link> | ( &lt;LPAREN&gt; <link linkend="prod56">joinedTable</link> &lt;RPAREN&gt; ) ) ( ( &lt;MAKEDEP&gt; ) | ( &lt;MAKENOTDEP&gt; ) )?</para></entry></row>
+( <link linkend="prod62">unaryFromClause</link> | <link linkend="prod63">subqueryFromClause</link> | ( &lt;LPAREN&gt; <link linkend="prod58">joinedTable</link> &lt;RPAREN&gt; ) ) ( ( &lt;MAKEDEP&gt; ) | ( &lt;MAKENOTDEP&gt; ) )?</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod61" xreflabel="subqueryFromClause"/>subqueryFromClause</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod63" xreflabel="subqueryFromClause"/>subqueryFromClause</para></entry>
 <entry align="left" valign="top"><para>::= 
 &lt;LPAREN&gt; ( <link linkend="prod7">queryExpression</link> | <link linkend="prod8">storedProcedure</link> ) &lt;RPAREN&gt; ( &lt;AS&gt; )? <link linkend="prod2">id</link></para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod60" xreflabel="unaryFromClause"/>unaryFromClause</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod62" xreflabel="unaryFromClause"/>unaryFromClause</para></entry>
 <entry align="left" valign="top"><para>::= 
 ( &lt;ID&gt; ( ( &lt;AS&gt; )? <link linkend="prod2">id</link> )? )</para></entry></row>
 <row>
@@ -599,69 +604,69 @@
 <row>
 <entry align="right" valign="top"><para><anchor id="prod28" xreflabel="criteria"/>criteria</para></entry>
 <entry align="left" valign="top"><para>::= 
-<link linkend="prod62">compoundCritOr</link></para></entry></row>
+<link linkend="prod64">compoundCritOr</link></para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod62" xreflabel="compoundCritOr"/>compoundCritOr</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod64" xreflabel="compoundCritOr"/>compoundCritOr</para></entry>
 <entry align="left" valign="top"><para>::= 
-<link linkend="prod63">compoundCritAnd</link> ( &lt;OR&gt; <link linkend="prod63">compoundCritAnd</link> )*</para></entry></row>
+<link linkend="prod65">compoundCritAnd</link> ( &lt;OR&gt; <link linkend="prod65">compoundCritAnd</link> )*</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod63" xreflabel="compoundCritAnd"/>compoundCritAnd</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod65" xreflabel="compoundCritAnd"/>compoundCritAnd</para></entry>
 <entry align="left" valign="top"><para>::= 
-<link linkend="prod64">notCrit</link> ( &lt;AND&gt; <link linkend="prod64">notCrit</link> )*</para></entry></row>
+<link linkend="prod66">notCrit</link> ( &lt;AND&gt; <link linkend="prod66">notCrit</link> )*</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod64" xreflabel="notCrit"/>notCrit</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod66" xreflabel="notCrit"/>notCrit</para></entry>
 <entry align="left" valign="top"><para>::= 
-( &lt;NOT&gt; )? <link linkend="prod65">primary</link></para></entry></row>
+( &lt;NOT&gt; )? <link linkend="prod67">primary</link></para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod65" xreflabel="primary"/>primary</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod67" xreflabel="primary"/>primary</para></entry>
 <entry align="left" valign="top"><para>::= 
-( <link linkend="prod66">predicate</link> | ( &lt;LPAREN&gt; <link linkend="prod28">criteria</link> &lt;RPAREN&gt; ) )</para></entry></row>
+( <link linkend="prod68">predicate</link> | ( &lt;LPAREN&gt; <link linkend="prod28">criteria</link> &lt;RPAREN&gt; ) )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod66" xreflabel="predicate"/>predicate</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod68" xreflabel="predicate"/>predicate</para></entry>
 <entry align="left" valign="top"><para>::= 
-( <link linkend="prod67">subqueryCompareCriteria</link> | <link linkend="prod68">compareCrit</link> | <link linkend="prod69">matchCrit</link> | <link linkend="prod70">betweenCrit</link> | <link linkend="prod71">setCrit</link> | <link linkend="prod72">existsCriteria</link> | <link linkend="prod30">hasCriteria</link> | <link linkend="prod34">translateCriteria</link> | <link linkend="prod73">isNullCrit</link> )</para></entry></row>
+( <link linkend="prod69">subqueryCompareCriteria</link> | <link linkend="prod70">compareCrit</link> | <link linkend="prod71">matchCrit</link> | <link linkend="prod72">betweenCrit</link> | <link linkend="prod73">setCrit</link> | <link linkend="prod74">existsCriteria</link> | <link linkend="prod30">hasCriteria</link> | <link linkend="prod34">translateCriteria</link> | <link linkend="prod75">isNullCrit</link> )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod68" xreflabel="compareCrit"/>compareCrit</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod70" xreflabel="compareCrit"/>compareCrit</para></entry>
 <entry align="left" valign="top"><para>::= 
 <link linkend="prod16">expression</link> ( &lt;EQ&gt; | &lt;NE&gt; | &lt;NE2&gt; | &lt;LT&gt; | &lt;LE&gt; | &lt;GT&gt; | &lt;GE&gt; ) <link linkend="prod16">expression</link></para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod74" xreflabel="subquery"/>subquery</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod76" xreflabel="subquery"/>subquery</para></entry>
 <entry align="left" valign="top"><para>::= 
 &lt;LPAREN&gt; ( <link linkend="prod7">queryExpression</link> | <link linkend="prod8">storedProcedure</link> ) &lt;RPAREN&gt;</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod67" xreflabel="subqueryCompareCriteria"/>subqueryCompareCriteria</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod69" xreflabel="subqueryCompareCriteria"/>subqueryCompareCriteria</para></entry>
 <entry align="left" valign="top"><para>::= 
-<link linkend="prod16">expression</link> ( &lt;EQ&gt; | &lt;NE&gt; | &lt;NE2&gt; | &lt;LT&gt; | &lt;LE&gt; | &lt;GT&gt; | &lt;GE&gt; ) ( &lt;ANY&gt; | &lt;SOME&gt; | &lt;ALL&gt; ) <link linkend="prod74">subquery</link></para></entry></row>
+<link linkend="prod16">expression</link> ( &lt;EQ&gt; | &lt;NE&gt; | &lt;NE2&gt; | &lt;LT&gt; | &lt;LE&gt; | &lt;GT&gt; | &lt;GE&gt; ) ( &lt;ANY&gt; | &lt;SOME&gt; | &lt;ALL&gt; ) <link linkend="prod76">subquery</link></para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod69" xreflabel="matchCrit"/>matchCrit</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod71" xreflabel="matchCrit"/>matchCrit</para></entry>
 <entry align="left" valign="top"><para>::= 
-( <link linkend="prod16">expression</link> ( &lt;NOT&gt; )? &lt;LIKE&gt; <link linkend="prod16">expression</link> ( <link linkend="prod75">escapeChar</link> | ( &lt;LBRACE&gt; <link linkend="prod75">escapeChar</link> &lt;RBRACE&gt; ) )? )</para></entry></row>
+( <link linkend="prod16">expression</link> ( &lt;NOT&gt; )? &lt;LIKE&gt; <link linkend="prod16">expression</link> ( <link linkend="prod77">escapeChar</link> | ( &lt;LBRACE&gt; <link linkend="prod77">escapeChar</link> &lt;RBRACE&gt; ) )? )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod75" xreflabel="escapeChar"/>escapeChar</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod77" xreflabel="escapeChar"/>escapeChar</para></entry>
 <entry align="left" valign="top"><para>::= 
 &lt;ESCAPE&gt; <link linkend="prod1">stringVal</link></para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod70" xreflabel="betweenCrit"/>betweenCrit</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod72" xreflabel="betweenCrit"/>betweenCrit</para></entry>
 <entry align="left" valign="top"><para>::= 
 <link linkend="prod16">expression</link> ( &lt;NOT&gt; )? &lt;BETWEEN&gt; <link linkend="prod16">expression</link> &lt;AND&gt; <link linkend="prod16">expression</link></para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod73" xreflabel="isNullCrit"/>isNullCrit</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod75" xreflabel="isNullCrit"/>isNullCrit</para></entry>
 <entry align="left" valign="top"><para>::= 
 <link linkend="prod16">expression</link> &lt;IS&gt; ( &lt;NOT&gt; )? &lt;NULL&gt;</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod71" xreflabel="setCrit"/>setCrit</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod73" xreflabel="setCrit"/>setCrit</para></entry>
 <entry align="left" valign="top"><para>::= 
-<link linkend="prod16">expression</link> ( &lt;NOT&gt; )? &lt;IN&gt; ( ( <link linkend="prod74">subquery</link> ) | ( &lt;LPAREN&gt; <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* &lt;RPAREN&gt; ) )</para></entry></row>
+<link linkend="prod16">expression</link> ( &lt;NOT&gt; )? &lt;IN&gt; ( ( <link linkend="prod76">subquery</link> ) | ( &lt;LPAREN&gt; <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* &lt;RPAREN&gt; ) )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod72" xreflabel="existsCriteria"/>existsCriteria</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod74" xreflabel="existsCriteria"/>existsCriteria</para></entry>
 <entry align="left" valign="top"><para>::= 
-&lt;EXISTS&gt; <link linkend="prod74">subquery</link></para></entry></row>
+&lt;EXISTS&gt; <link linkend="prod76">subquery</link></para></entry></row>
 <row>
 <entry align="right" valign="top"><para><anchor id="prod50" xreflabel="groupBy"/>groupBy</para></entry>
 <entry align="left" valign="top"><para>::= 
-&lt;GROUP&gt; &lt;BY&gt; ( <link linkend="prod76">groupByItem</link> ( &lt;COMMA&gt; <link linkend="prod76">groupByItem</link> )* )</para></entry></row>
+&lt;GROUP&gt; &lt;BY&gt; ( <link linkend="prod78">groupByItem</link> ( &lt;COMMA&gt; <link linkend="prod78">groupByItem</link> )* )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod76" xreflabel="groupByItem"/>groupByItem</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod78" xreflabel="groupByItem"/>groupByItem</para></entry>
 <entry align="left" valign="top"><para>::= 
 <link linkend="prod16">expression</link></para></entry></row>
 <row>
@@ -671,9 +676,9 @@
 <row>
 <entry align="right" valign="top"><para><anchor id="prod43" xreflabel="orderby"/>orderby</para></entry>
 <entry align="left" valign="top"><para>::= 
-&lt;ORDER&gt; &lt;BY&gt; <link linkend="prod77">sortKey</link> ( &lt;ASC&gt; | &lt;DESC&gt; )? ( &lt;COMMA&gt; <link linkend="prod77">sortKey</link> ( &lt;ASC&gt; | &lt;DESC&gt; )? )*</para></entry></row>
+&lt;ORDER&gt; &lt;BY&gt; <link linkend="prod79">sortKey</link> ( &lt;ASC&gt; | &lt;DESC&gt; )? ( &lt;COMMA&gt; <link linkend="prod79">sortKey</link> ( &lt;ASC&gt; | &lt;DESC&gt; )? )*</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod77" xreflabel="sortKey"/>sortKey</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod79" xreflabel="sortKey"/>sortKey</para></entry>
 <entry align="left" valign="top"><para>::= 
 <link linkend="prod16">expression</link></para></entry></row>
 <row>
@@ -683,57 +688,65 @@
 <row>
 <entry align="right" valign="top"><para><anchor id="prod37" xreflabel="option"/>option</para></entry>
 <entry align="left" valign="top"><para>::= 
-&lt;OPTION&gt; ( &lt;SHOWPLAN&gt; | &lt;PLANONLY&gt; | &lt;DEBUG&gt; | &lt;MAKEDEP&gt; <link linkend="prod2">id</link> ( &lt;COMMA&gt; <link linkend="prod2">id</link> )* | &lt;MAKENOTDEP&gt; <link linkend="prod2">id</link> ( &lt;COMMA&gt; <link linkend="prod2">id</link> )* | &lt;NOCACHE&gt; ( <link linkend="prod2">id</link> ( &lt;COMMA&gt; <link linkend="prod2">id</link> )* )? )*</para></entry></row>
+&lt;OPTION&gt; ( &lt;MAKEDEP&gt; <link linkend="prod2">id</link> ( &lt;COMMA&gt; <link linkend="prod2">id</link> )* | &lt;MAKENOTDEP&gt; <link linkend="prod2">id</link> ( &lt;COMMA&gt; <link linkend="prod2">id</link> )* | &lt;NOCACHE&gt; ( <link linkend="prod2">id</link> ( &lt;COMMA&gt; <link linkend="prod2">id</link> )* )? )*</para></entry></row>
 <row>
 <entry align="right" valign="top"><para><anchor id="prod16" xreflabel="expression"/>expression</para></entry>
 <entry align="left" valign="top"><para>::= 
-<link linkend="prod78">concatExpression</link></para></entry></row>
+<link linkend="prod80">concatExpression</link></para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod78" xreflabel="concatExpression"/>concatExpression</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod80" xreflabel="concatExpression"/>concatExpression</para></entry>
 <entry align="left" valign="top"><para>::= 
-( <link linkend="prod79">plusExpression</link> ( &lt;CONCAT_OP&gt; <link linkend="prod79">plusExpression</link> )* )</para></entry></row>
+( <link linkend="prod81">plusExpression</link> ( &lt;CONCAT_OP&gt; <link linkend="prod81">plusExpression</link> )* )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod79" xreflabel="plusExpression"/>plusExpression</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod81" xreflabel="plusExpression"/>plusExpression</para></entry>
 <entry align="left" valign="top"><para>::= 
-( <link linkend="prod80">timesExpression</link> ( <link linkend="prod81">plusOperator</link> <link linkend="prod80">timesExpression</link> )* )</para></entry></row>
+( <link linkend="prod82">timesExpression</link> ( <link linkend="prod83">plusOperator</link> <link linkend="prod82">timesExpression</link> )* )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod81" xreflabel="plusOperator"/>plusOperator</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod83" xreflabel="plusOperator"/>plusOperator</para></entry>
 <entry align="left" valign="top"><para>::= 
 ( &lt;PLUS&gt; | &lt;MINUS&gt; )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod80" xreflabel="timesExpression"/>timesExpression</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod82" xreflabel="timesExpression"/>timesExpression</para></entry>
 <entry align="left" valign="top"><para>::= 
-( <link linkend="prod82">basicExpression</link> ( <link linkend="prod83">timesOperator</link> <link linkend="prod82">basicExpression</link> )* )</para></entry></row>
+( <link linkend="prod84">basicExpression</link> ( <link linkend="prod85">timesOperator</link> <link linkend="prod84">basicExpression</link> )* )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod83" xreflabel="timesOperator"/>timesOperator</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod85" xreflabel="timesOperator"/>timesOperator</para></entry>
 <entry align="left" valign="top"><para>::= 
 ( &lt;STAR&gt; | &lt;SLASH&gt; )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod82" xreflabel="basicExpression"/>basicExpression</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod84" xreflabel="basicExpression"/>basicExpression</para></entry>
 <entry align="left" valign="top"><para>::= 
-( &lt;QMARK&gt; | <link linkend="prod84">literal</link> | ( &lt;LBRACE&gt; &lt;FN&gt; <link linkend="prod85">function</link> &lt;RBRACE&gt; ) | ( <link linkend="prod53">aggregateSymbol</link> ) | ( <link linkend="prod85">function</link> ) | ( &lt;ID&gt; ) | ( &lt;LPAREN&gt; <link linkend="prod16">expression</link> &lt;RPAREN&gt; ) | <link linkend="prod74">subquery</link> | <link linkend="prod86">caseExpression</link> | <link linkend="prod87">searchedCaseExpression</link> )</para></entry></row>
+( &lt;QMARK&gt; | <link linkend="prod86">literal</link> | ( &lt;LBRACE&gt; &lt;FN&gt; <link linkend="prod87">function</link> &lt;RBRACE&gt; ) | ( <link linkend="prod55">aggregateSymbol</link> ) | ( <link linkend="prod87">function</link> ) | ( &lt;ID&gt; ) | ( &lt;LPAREN&gt; <link linkend="prod16">expression</link> &lt;RPAREN&gt; ) | <link linkend="prod76">subquery</link> | <link linkend="prod88">caseExpression</link> | <link linkend="prod89">searchedCaseExpression</link> )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod86" xreflabel="caseExpression"/>caseExpression</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod88" xreflabel="caseExpression"/>caseExpression</para></entry>
 <entry align="left" valign="top"><para>::= 
 &lt;CASE&gt; <link linkend="prod16">expression</link> ( &lt;WHEN&gt; <link linkend="prod16">expression</link> &lt;THEN&gt; <link linkend="prod16">expression</link> )+ ( &lt;ELSE&gt; <link linkend="prod16">expression</link> )? &lt;END&gt;</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod87" xreflabel="searchedCaseExpression"/>searchedCaseExpression</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod89" xreflabel="searchedCaseExpression"/>searchedCaseExpression</para></entry>
 <entry align="left" valign="top"><para>::= 
 &lt;CASE&gt; ( &lt;WHEN&gt; <link linkend="prod28">criteria</link> &lt;THEN&gt; <link linkend="prod16">expression</link> )+ ( &lt;ELSE&gt; <link linkend="prod16">expression</link> )? &lt;END&gt;</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod85" xreflabel="function"/>function</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod87" xreflabel="function"/>function</para></entry>
 <entry align="left" valign="top"><para>::= 
-( ( &lt;CONVERT&gt; &lt;LPAREN&gt; <link linkend="prod16">expression</link> &lt;COMMA&gt; <link linkend="prod31">dataType</link> &lt;RPAREN&gt; ) | ( &lt;CAST&gt; &lt;LPAREN&gt; <link linkend="prod16">expression</link> &lt;AS&gt; <link linkend="prod31">dataType</link> &lt;RPAREN&gt; ) | ( ( &lt;TIMESTAMPADD&gt; | &lt;TIMESTAMPDIFF&gt; ) &lt;LPAREN&gt; <link linkend="prod88">intervalType</link> &lt;COMMA&gt; <link linkend="prod16">expression</link> &lt;COMMA&gt; <link linkend="prod16">expression</link> &lt;RPAREN&gt; ) | ( ( &lt;LEFT&gt; | &lt;RIGHT&gt; | &lt;CHAR&gt; | &lt;USER&gt; | &lt;YEAR&gt; | &lt;MONTH&gt; | &lt;HOUR&gt; | &lt;MINUTE&gt; | &lt;SECOND&gt; ) &lt;LPAREN&gt; ( <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* )? &lt;RPAREN&gt; ) | ( ( &lt;INSERT&gt; ) &lt;LPAREN&gt; ( <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* )? &lt;RPAREN&gt; ) | ( ( &lt;TRANSLAT!
 E&gt; ) &lt;LPAREN&gt; ( <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* )? &lt;RPAREN&gt; ) | ( <link linkend="prod2">id</link> &lt;LPAREN&gt; ( <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* )? &lt;RPAREN&gt; ) )</para></entry></row>
+( ( &lt;CONVERT&gt; &lt;LPAREN&gt; <link linkend="prod16">expression</link> &lt;COMMA&gt; <link linkend="prod31">dataType</link> &lt;RPAREN&gt; ) | ( &lt;CAST&gt; &lt;LPAREN&gt; <link linkend="prod16">expression</link> &lt;AS&gt; <link linkend="prod31">dataType</link> &lt;RPAREN&gt; ) | ( ( &lt;TIMESTAMPADD&gt; | &lt;TIMESTAMPDIFF&gt; ) &lt;LPAREN&gt; <link linkend="prod90">intervalType</link> &lt;COMMA&gt; <link linkend="prod16">expression</link> &lt;COMMA&gt; <link linkend="prod16">expression</link> &lt;RPAREN&gt; ) | ( ( &lt;LEFT&gt; | &lt;RIGHT&gt; | &lt;CHAR&gt; | &lt;USER&gt; | &lt;YEAR&gt; | &lt;MONTH&gt; | &lt;HOUR&gt; | &lt;MINUTE&gt; | &lt;SECOND&gt; | &lt;XMLCONCAT&gt; ) &lt;LPAREN&gt; ( <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* )? &lt;RPAREN&gt; ) | ( ( &lt;INSERT&gt; ) &lt;LPAREN&gt; ( <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* )? &lt;RPAREN&gt; !
 ) | ( ( &lt;TRANSLATE&gt; ) &lt;LPAREN&gt; ( <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* )? &lt;RPAREN&gt; ) | ( &lt;XMLELEMENT&gt; &lt;LPAREN&gt; ( &lt;ID&gt; <link linkend="prod91">idExpression</link> | <link linkend="prod91">idExpression</link> ) ( &lt;COMMA&gt; <link linkend="prod92">sqlXmlFunction</link> )? ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* &lt;RPAREN&gt; ) | ( <link linkend="prod92">sqlXmlFunction</link> ) | ( <link linkend="prod2">id</link> &lt;LPAREN&gt; ( <link linkend="prod16">expression</link> ( &lt;COMMA&gt; <link linkend="prod16">expression</link> )* )? &lt;RPAREN&gt; ) )</para></entry></row>
 <row>
+<entry align="right" valign="top"><para><anchor id="prod92" xreflabel="sqlXmlFunction"/>sqlXmlFunction</para></entry>
+<entry align="left" valign="top"><para>::= 
+( &lt;XMLFOREST&gt; | &lt;XMLATTRIBUTES&gt; ) &lt;LPAREN&gt; <link linkend="prod53">selectExpression</link> ( &lt;COMMA&gt; <link linkend="prod53">selectExpression</link> )* &lt;RPAREN&gt;</para></entry></row>
+<row>
+<entry align="right" valign="top"><para><anchor id="prod91" xreflabel="idExpression"/>idExpression</para></entry>
+<entry align="left" valign="top"><para>::= 
+<link linkend="prod2">id</link></para></entry></row>
+<row>
 <entry align="right" valign="top"><para><anchor id="prod31" xreflabel="dataType"/>dataType</para></entry>
 <entry align="left" valign="top"><para>::= 
 ( &lt;STRING&gt; | &lt;VARCHAR&gt; | &lt;BOOLEAN&gt; | &lt;BYTE&gt; | &lt;TINYINT&gt; | &lt;SHORT&gt; | &lt;SMALLINT&gt; | &lt;CHAR&gt; | &lt;INTEGER&gt; | &lt;LONG&gt; | &lt;BIGINT&gt; | &lt;BIGINTEGER&gt; | &lt;FLOAT&gt; | &lt;REAL&gt; | &lt;DOUBLE&gt; | &lt;BIGDECIMAL&gt; | &lt;DECIMAL&gt; | &lt;DATE&gt; | &lt;TIME&gt; | &lt;TIMESTAMP&gt; | &lt;OBJECT&gt; | &lt;BLOB&gt; | &lt;CLOB&gt; | &lt;XML&gt; )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod88" xreflabel="intervalType"/>intervalType</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod90" xreflabel="intervalType"/>intervalType</para></entry>
 <entry align="left" valign="top"><para>::= 
 ( &lt;SQL_TSI_FRAC_SECOND&gt; | &lt;SQL_TSI_SECOND&gt; | &lt;SQL_TSI_MINUTE&gt; | &lt;SQL_TSI_HOUR&gt; | &lt;SQL_TSI_DAY&gt; | &lt;SQL_TSI_WEEK&gt; | &lt;SQL_TSI_MONTH&gt; | &lt;SQL_TSI_QUARTER&gt; | &lt;SQL_TSI_YEAR&gt; )</para></entry></row>
 <row>
-<entry align="right" valign="top"><para><anchor id="prod84" xreflabel="literal"/>literal</para></entry>
+<entry align="right" valign="top"><para><anchor id="prod86" xreflabel="literal"/>literal</para></entry>
 <entry align="left" valign="top"><para>::= 
 ( <link linkend="prod1">stringVal</link> | &lt;INTEGERVAL&gt; | &lt;FLOATVAL&gt; | &lt;FALSE&gt; | &lt;TRUE&gt; | &lt;UNKNOWN&gt; | &lt;NULL&gt; | ( ( &lt;BOOLEANTYPE&gt; | &lt;TIMESTAMPTYPE&gt; | &lt;DATETYPE&gt; | &lt;TIMETYPE&gt; ) <link linkend="prod1">stringVal</link> &lt;RBRACE&gt; ) )</para></entry></row>
 </tbody>

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-05 17:03:24 UTC (rev 2099)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml	2010-05-06 17:17:44 UTC (rev 2100)
@@ -1950,30 +1950,58 @@
             </entry>
             <entry>
               <para>Takes a document and an xsl stylesheet and returns a
-                clob of the result.</para>
+                clob of the result.  If either argument is null, the result is null.</para>
             </entry>
             <entry>
-              <para>Doc, xsl in {xml}. Return value is a clob.
+              <para>Doc, xsl in {string, xml}. Return value is a clob.
               </para>
             </entry>
           </row>
           <row>
             <entry>
-              <para><code>XMLELEMENT(name [, content]*)</code></para>
+              <para><code>XMLELEMENT([NAME] name [, &lt;ATTR&gt;][, exp]*)</code>
+               		ATTR:=<code>XMLATTRIBUTES(exp [AS name] [, exp [AS name]]*)</code></para>
             </entry>
             <entry>
-              <para>Returns an XML element with the given name and conent.  If the content value is of a type other than xml, 
+              <para>Returns an XML element with the given name and content.  If the content value is of a type other than xml, 
               it will be escaped when added to the parent element.  Null content values are ignored.  
               Whitespace in XML or the string values of the content is preserved, but no whitespace is added between content values.</para>
-              <para>Example: with an xml_value of &lt;doc/&gt;, <code>xmlelement('myelement', 1, '&lt;2/&gt;', xml_value)</code>
-              		Returns: <code>&lt;myelement&gt;1&amp;lt;2/&amp;gt;&lt;doc/&gt;&gt;</code>
+              <para>If a attribute name is not supplied, the expression must be a column reference, in which case the attribute name will be the column name. Null attribute values are ignored.</para>
+              <para>Example: with an xml_value of &lt;doc/&gt;, <code>xmlelement('elem', 1, '&lt;2/&gt;', xml_value)</code>
+              		Returns: <code>&lt;elem&gt;1&amp;lt;2/&amp;gt;&lt;doc/&gt;&lt;elem/&gt;</code>
               </para>
             </entry>
             <entry>
-              <para>Name in {string}.  Content can be any type. Return value is xml.
+              <para>Name is an identifier.  exp can be any type. Return value is xml.
               </para>
             </entry>
           </row>
+          <row>
+            <entry>
+              <para><code>XMLCONCAT(xml [, other]*)</code></para>
+            </entry>
+            <entry>
+              <para>Returns an XML with the concatination of the given xml types.  If a value is null, it will be ignored.
+              </para>
+            </entry>
+            <entry>
+              <para>Name is an identifier.  Content can be any type. Return value is xml.
+              </para>
+            </entry>
+          </row>
+          <row>
+            <entry>
+              <para><code>XMLFOREST(exp [AS name], [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>
+            </entry>
+            <entry>
+              <para>Name is an identifier.  exp can be any type. Return value is xml.
+              </para>
+            </entry>
+          </row>
         </tbody>
       </tgroup>
     </informaltable>

Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -44,6 +44,7 @@
 import javax.xml.transform.Source;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.common.buffer.BatchManager;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.buffer.FileStore;
@@ -364,6 +365,7 @@
     
 	@Override
 	public void initialize() throws MetaMatrixComponentException {
+		//TODO: remove me - connectors should be able to do this statefully
 		DataTypeManager.addSourceTransform(Source.class, new SourceTransform<Source, XMLType>() {
 			@Override
 			public XMLType transform(Source value) {
@@ -376,12 +378,14 @@
 					sqlxml = XMLUtil.saveToBufferManager(BufferManagerImpl.this, sxt, Streamable.STREAMING_BATCH_SIZE_IN_BYTES);
 				} catch (MetaMatrixComponentException e) {
 					throw new MetaMatrixRuntimeException(e);
+				} catch (MetaMatrixProcessingException e) {
+					throw new MetaMatrixRuntimeException(e);
 				}
 				return new XMLType(sqlxml);
 			}
 		});
 	}
-    
+	
     @Override
     public void releaseBuffers(int count) {
     	if (count < 1) {

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -37,6 +37,7 @@
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.CriteriaEvaluationException;
 import com.metamatrix.api.exception.query.ExpressionEvaluationException;
+import com.metamatrix.api.exception.query.FunctionExecutionException;
 import com.metamatrix.common.buffer.BlockedException;
 import com.metamatrix.common.types.Sequencable;
 import com.metamatrix.core.util.Assertion;
@@ -45,6 +46,8 @@
 import com.metamatrix.query.function.FunctionDescriptor;
 import com.metamatrix.query.function.FunctionLibrary;
 import com.metamatrix.query.function.metadata.FunctionMethod;
+import com.metamatrix.query.function.source.XMLSystemFunctions;
+import com.metamatrix.query.function.source.XMLSystemFunctions.NameValuePair;
 import com.metamatrix.query.processor.ProcessorDataManager;
 import com.metamatrix.query.sql.LanguageObject;
 import com.metamatrix.query.sql.lang.AbstractSetCriteria;
@@ -62,6 +65,7 @@
 import com.metamatrix.query.sql.lang.SubqueryContainer;
 import com.metamatrix.query.sql.lang.SubquerySetCriteria;
 import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.AliasSymbol;
 import com.metamatrix.query.sql.symbol.CaseExpression;
 import com.metamatrix.query.sql.symbol.Constant;
 import com.metamatrix.query.sql.symbol.ContextReference;
@@ -69,6 +73,7 @@
 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;
@@ -556,6 +561,27 @@
 		   return internalEvaluate(ref.getExpression(), tuple);
 	   } else if(expression instanceof ScalarSubquery) {
 	       return evaluate((ScalarSubquery) expression, tuple);
+	   } else if (expression instanceof SQLXMLFunction){
+		   SQLXMLFunction function = (SQLXMLFunction)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;
 	   } else {
 	       throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0016, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0016, expression.getClass().getName()));
 	   }
@@ -636,7 +662,7 @@
 			} catch (MetaMatrixProcessingException e) {
 				throw new ExpressionEvaluationException(e, e.getMessage());
 			}
-	    } 
+	    }
 	    
 		// Execute function
 		Object result = fd.invokeFunction(values);

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -87,6 +87,9 @@
 
     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$
+    
     // 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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -169,6 +169,7 @@
         addXpathFunction();
         addXslTransformFunction();
         addXmlElement();
+        addXmlConcat();
         
         addSecurityFunctions();
         
@@ -903,16 +904,41 @@
                                 new FunctionParameter("document", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$ //$NON-NLS-2$
                                 new FunctionParameter("xsl", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$ 
                             new FunctionParameter("result", DataTypeManager.DefaultDataTypes.CLOB, QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );       //$NON-NLS-1$ //$NON-NLS-2$
+        functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM, QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML, XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$  
+                new FunctionParameter[] { 
+                    new FunctionParameter("document", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$ //$NON-NLS-2$
+                    new FunctionParameter("xsl", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$ 
+                new FunctionParameter("result", DataTypeManager.DefaultDataTypes.CLOB, QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );       //$NON-NLS-1$ //$NON-NLS-2$
+        
+        functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM, QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML, XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$  
+                new FunctionParameter[] { 
+                    new FunctionParameter("document", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$ //$NON-NLS-2$
+                    new FunctionParameter("xsl", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$ 
+                new FunctionParameter("result", DataTypeManager.DefaultDataTypes.CLOB, QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) );       //$NON-NLS-1$ //$NON-NLS-2$
+        
+        functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM, QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML, XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$  
+                new FunctionParameter[] { 
+                    new FunctionParameter("document", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xsltransform_param1")), //$NON-NLS-1$ //$NON-NLS-2$
+                    new FunctionParameter("xsl", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xsltransform_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$ 
+                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.xsltransform_description"), XML, XML_FUNCTION_CLASS, "xmlElement", //$NON-NLS-1$ //$NON-NLS-2$  
+        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")) ) );       //$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 addXmlConcat() {
+        functions.add(new FunctionMethod(SourceSystemFunctions.XMLCONCAT, QueryPlugin.Util.getString("SystemSource.xmlconcat_description"), XML, FunctionMethod.CAN_PUSHDOWN, XML_FUNCTION_CLASS, "xmlConcat", //$NON-NLS-1$ //$NON-NLS-2$  
+                            new FunctionParameter[] { 
+                                new FunctionParameter("param1", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xmlconcat_param1")), //$NON-NLS-1$ //$NON-NLS-2$
+                                new FunctionParameter("param2", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xmlconcat_param2"), true)}, //$NON-NLS-1$ //$NON-NLS-2$ 
+                            new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xmlconcat_result")), true, FunctionMethod.DETERMINISTIC ) );       //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
     private void addTimeZoneFunctions() {
         functions.add(new FunctionMethod(SourceSystemFunctions.MODIFYTIMEZONE, QueryPlugin.Util.getString("SystemSource.modifyTimeZone_description"), DATETIME, FUNCTION_CLASS, "modifyTimeZone", //$NON-NLS-1$ //$NON-NLS-2$ 
                             new FunctionParameter[] { 
@@ -970,7 +996,7 @@
      * @return Class reference  
      * @throws ClassNotFoundException If class could not be found
      */
-    public Class getInvocationClass(String className) throws ClassNotFoundException {
+    public Class<?> getInvocationClass(String className) throws ClassNotFoundException {
         return Class.forName(className);    
     }
 }

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -22,14 +22,19 @@
 
 package com.metamatrix.query.function.source;
 
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.Writer;
 import java.sql.SQLException;
 import java.sql.SQLXML;
+import java.sql.Timestamp;
+import java.util.Calendar;
 
+import javax.xml.namespace.QName;
 import javax.xml.stream.EventFilter;
+import javax.xml.stream.FactoryConfigurationError;
 import javax.xml.stream.XMLEventFactory;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLEventWriter;
@@ -47,6 +52,7 @@
 import net.sf.saxon.trans.XPathException;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.FunctionExecutionException;
 import com.metamatrix.common.types.ClobType;
 import com.metamatrix.common.types.DataTypeManager;
@@ -54,8 +60,10 @@
 import com.metamatrix.common.types.TransformationException;
 import com.metamatrix.common.types.XMLTranslator;
 import com.metamatrix.common.types.XMLType;
+import com.metamatrix.common.types.XMLType.Type;
 import com.metamatrix.internal.core.xml.XPathHelper;
 import com.metamatrix.query.QueryPlugin;
+import com.metamatrix.query.function.FunctionMethods;
 import com.metamatrix.query.processor.xml.XMLUtil;
 import com.metamatrix.query.util.CommandContext;
 
@@ -65,6 +73,31 @@
  * @since 4.2
  */
 public class XMLSystemFunctions {
+	
+	public static class NameValuePair {
+		String name;
+		Object value;
+		
+		public NameValuePair(String name, Object value) {
+			this.name = name;
+			this.value = value;
+		}
+	}
+	
+    //YEAR 0 in the server timezone. used to determine negative years
+    public static long YEAR_ZERO;
+    static String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; //$NON-NLS-1$
+    
+    static String TIMESTAMP_MICROZEROS = "000000000"; //$NON-NLS-1$
+    
+    static {
+        Calendar cal = Calendar.getInstance();
+    
+        for (int i = 0; i <= Calendar.MILLISECOND; i++) {
+            cal.set(i, 0);
+        }
+        YEAR_ZERO = cal.getTimeInMillis();
+    }
 
     public static Object xpathValue(Object document, Object xpathStr) throws FunctionExecutionException {
         Reader stream = null;
@@ -89,7 +122,19 @@
             throw new FunctionExecutionException(QueryPlugin.Util.getString("XMLSystemFunctions.wrap_exception", xpathStr, e.getMessage())); //$NON-NLS-1$
         }
     }
-    
+
+	public static ClobType xslTransform(CommandContext context, String xmlResults, String styleSheet) throws Exception {
+		return xslTransform(context, DataTypeManager.transformValue(xmlResults, DataTypeManager.DefaultDataClasses.XML), DataTypeManager.transformValue(styleSheet, DataTypeManager.DefaultDataClasses.XML));
+	}
+
+	public static ClobType xslTransform(CommandContext context, String xmlResults, XMLType styleSheet) throws Exception {
+		return xslTransform(context, DataTypeManager.transformValue(xmlResults, DataTypeManager.DefaultDataClasses.XML), styleSheet);
+	}
+
+	public static ClobType xslTransform(CommandContext context, XMLType xmlResults, String styleSheet) throws Exception {
+		return xslTransform(context, xmlResults, DataTypeManager.transformValue(styleSheet, DataTypeManager.DefaultDataClasses.XML));
+	}
+
 	public static ClobType xslTransform(CommandContext context, XMLType xmlResults, XMLType styleSheet) throws Exception {
     	Reader styleSheetReader = styleSheet.getCharacterStream();
     	final Source styleSource = new StreamSource(styleSheetReader);
@@ -103,6 +148,7 @@
 				public void translate(Writer writer) throws TransformerException {
 	                TransformerFactory factory = TransformerFactory.newInstance();
 	                Transformer transformer = factory.newTransformer(styleSource);
+	                //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
 	                // Feed the resultant I/O stream into the XSLT processor
 					transformer.transform(xmlSource, new StreamResult(writer));
 				}
@@ -119,17 +165,55 @@
 			}
 		}
     }
+		
+	public static XMLType xmlForest(final CommandContext context, final NameValuePair[] values) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+		boolean valueExists = false;
+		for (NameValuePair nameValuePair : values) {
+			if (nameValuePair.value != null) {
+				valueExists = true;
+				break;
+			}
+		}
+		if (!valueExists) {
+			return null;
+		}
+
+		XMLType result = new XMLType(XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
+			
+			@Override
+			public void translate(Writer writer) throws TransformerException,
+					IOException {
+				try {
+					XMLOutputFactory factory = XMLOutputFactory.newInstance();
+					XMLEventWriter eventWriter = factory.createXMLEventWriter(writer);
+					XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+					for (NameValuePair nameValuePair : values) {
+						if (nameValuePair.value == null) {
+							continue;
+						}
+						addElement(nameValuePair.name, writer, eventWriter, eventFactory, nameValuePair.value);
+					}
+				} catch (XMLStreamException e) {
+					throw new TransformerException(e);
+				} 
+			}
+		}, context.getStreamingBatchSize()));
+		result.setType(Type.SIBLINGS);
+		return result;
+	}
 	
 	/**
-	 * Basic support for xmlelement.  Attributes are not yet supported.
+	 * Basic support for xmlelement.  namespaces are not yet supported.
 	 * @param context
 	 * @param name
 	 * @param contents
 	 * @return
 	 * @throws MetaMatrixComponentException
+	 * @throws MetaMatrixProcessingException 
 	 */
-	public static XMLType xmlElement(CommandContext context, final String name, final Object... contents) throws MetaMatrixComponentException {
-		return new XMLType(XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
+	public static XMLType xmlElement(CommandContext context, final String name, 
+			final Object... contents) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+		XMLType result = new XMLType(XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
 			
 			@Override
 			public void translate(Writer writer) throws TransformerException,
@@ -138,48 +222,162 @@
 					XMLOutputFactory factory = XMLOutputFactory.newInstance();
 					XMLEventWriter eventWriter = factory.createXMLEventWriter(writer);
 					XMLEventFactory eventFactory = XMLEventFactory.newInstance();
-					eventWriter.add(eventFactory.createStartElement("", null, name)); //$NON-NLS-1$
-					for (Object object : contents) {
-						if (object == null) {
-							continue;
-						}
-						if (object instanceof XMLType) {
-							Reader r = null;
-							try {
-								r = ((XMLType)object).getCharacterStream();
-								XMLInputFactory inputFactory = XMLInputFactory.newInstance();
-								XMLEventReader xmlEventReader = inputFactory.createFilteredReader(inputFactory.createXMLEventReader(r), new EventFilter() {
-									
-									@Override
-									public boolean accept(XMLEvent event) {
-										return !event.isStartDocument() && !event.isEndDocument();
-									}
-								});
-								eventWriter.add(xmlEventReader);
-							} catch (SQLException e) {
-								throw new IOException(e);
-							} finally {
-								if (r != null) {
-									r.close();
-								}
-							}
-						} else {
-							try {
-								String result = DataTypeManager.transformValue(object, DataTypeManager.DefaultDataClasses.STRING);
-								eventWriter.add(eventFactory.createCharacters(result));
-							} catch (TransformationException e) {
-								throw new TransformerException(e);
-							}
-						}
-					}
-					eventWriter.add(eventFactory.createEndElement("", null, name)); //$NON-NLS-1$
+					addElement(name, writer, eventWriter, eventFactory, contents);
 				} catch (XMLStreamException e) {
 					throw new TransformerException(e);
-				} finally {
-					
+				} 
+			}
+
+		}, context.getStreamingBatchSize()));
+		result.setType(Type.FRAGMENT);
+		return result;
+	}
+	
+	private static void addElement(final String name, Writer writer, XMLEventWriter eventWriter, XMLEventFactory eventFactory,
+			Object... 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 (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]);
+		}
+		eventWriter.add(eventFactory.createEndElement("", null, name)); //$NON-NLS-1$
+	}
+	
+	public static XMLType xmlConcat(CommandContext context, final XMLType xml, final Object... other) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+		XMLType result = new XMLType(XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
+			
+			@Override
+			public void translate(Writer writer) throws TransformerException,
+					IOException {
+				try {
+					XMLOutputFactory factory = XMLOutputFactory.newInstance();
+					XMLEventWriter eventWriter = factory.createXMLEventWriter(writer);
+					XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+					convertValue(writer, eventWriter, eventFactory, xml);
+					for (Object object : other) {
+						convertValue(writer, eventWriter, eventFactory, object);
+					}
+				} catch (XMLStreamException e) {
+					throw new TransformerException(e);
+				} 
+			}
 		}, context.getStreamingBatchSize()));
+		result.setType(Type.SIBLINGS);
+		return result;
 	}
 	
+	static String getStringValue(Object object) throws TransformerException {
+		if (object instanceof Timestamp) {
+			try {
+				return timestampToDateTime((Timestamp)object);
+			} catch (FunctionExecutionException e) {
+				throw new TransformerException(e);
+			}
+		}
+		try {
+			return DataTypeManager.transformValue(object, DataTypeManager.DefaultDataClasses.STRING);
+		} catch (TransformationException e) {
+			throw new TransformerException(e);
+		}
+	}
+	
+	static void convertValue(Writer writer, XMLEventWriter eventWriter, XMLEventFactory eventFactory, Object object) throws IOException,
+			FactoryConfigurationError, XMLStreamException,
+			TransformerException {
+		if (object == null) {
+			return;
+		}
+		if (object instanceof XMLType) {
+			XMLType xml = (XMLType)object;
+			Reader r = null;
+			try {
+				r = xml.getCharacterStream();
+				if (!(r instanceof BufferedReader)) {
+					r = new BufferedReader(r);
+				}
+				switch(xml.getType()) {
+				case FRAGMENT:
+				case SIBLINGS: //write the value directly to the writer
+					eventWriter.flush();
+					int chr = -1;
+					while ((chr = r.read()) != -1) {
+						writer.write(chr);
+					}
+					break;
+				case UNKNOWN:  //assume a document
+				case DOCUMENT: //filter the doc declaration
+					XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+					XMLEventReader eventReader = inputFactory.createXMLEventReader(r);
+		        	eventReader = inputFactory.createFilteredReader(eventReader, new EventFilter() {
+						@Override
+						public boolean accept(XMLEvent event) {
+							return !event.isStartDocument() && !event.isEndDocument();
+						}
+					});
+		        	eventWriter.add(eventReader);
+		        	break;
+				}
+			} catch (SQLException e) {
+				throw new IOException(e);
+			} finally {
+				if (r != null) {
+					r.close();
+				}
+			}
+		} else {
+			String val = getStringValue(object);
+			eventWriter.add(eventFactory.createCharacters(val));
+		}
+		//TODO: blob - with base64 encoding
+		//TODO: full clob?
+	}
+
+	/**
+	 * Formats a timestamp to an xs:dateTime.  This uses DATETIME_FORMAT
+	 * with a trailing string for nanoseconds (without right zeros). 
+	 */
+	public static String timestampToDateTime(Timestamp time) throws FunctionExecutionException {
+	    String result = FunctionMethods.format(time, DATETIME_FORMAT);
+	    int nanos = time.getNanos();
+	    if (nanos == 0) {
+	        return result;
+	    }
+	    
+	    StringBuffer resultBuffer = new StringBuffer();
+	    boolean first = true;
+	    int i = 0;
+	    for (; i < 9 && nanos > 0; i++) {
+	        int digit = nanos%10;
+	        if (first) {
+	            if (digit > 0) {
+	                resultBuffer.insert(0, digit);
+	                first = false;
+	            }
+	        } else {
+	            resultBuffer.insert(0, digit);
+	        }
+	        nanos /= 10;
+	    }
+	    if (i < 9) {
+	        resultBuffer.insert(0, TIMESTAMP_MICROZEROS.substring(i));
+	    }
+	    resultBuffer.insert(0, "."); //$NON-NLS-1$
+	    resultBuffer.insert(0, result);
+	    if (time.getTime() < YEAR_ZERO) {
+	        resultBuffer.insert(0, "-"); //$NON-NLS-1$
+	    }
+	    return resultBuffer.toString();
+	    
+	}
+	
 }

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -36,11 +36,11 @@
 import org.teiid.dqp.internal.process.Request;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
 import com.metamatrix.api.exception.query.QueryParserException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
 import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.common.log.LogConstants;
 import com.metamatrix.common.log.LogManager;
 import com.metamatrix.core.id.IDGenerator;
@@ -144,10 +144,8 @@
         PlanNode plan;
 		try {
 			plan = generatePlan(command);
-		} catch (QueryResolverException e) {
+		} catch (MetaMatrixProcessingException e) {
 			throw new QueryPlannerException(e, e.getMessage());
-		} catch (QueryValidatorException e) {
-			throw new QueryPlannerException(e, e.getMessage());
 		}
 
 		if(debug) {
@@ -371,7 +369,7 @@
         return plan;
     }
 	
-	public PlanNode generatePlan(Command cmd) throws QueryPlannerException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+	public PlanNode generatePlan(Command cmd) throws MetaMatrixComponentException, MetaMatrixProcessingException {
 		//cascade the option clause nocache
 		Option savedOption = option;
 		option = cmd.getOption();
@@ -423,7 +421,7 @@
         return result;
 	}
 
-	PlanNode createUpdatePlan(Command command) throws QueryPlannerException, MetaMatrixComponentException, QueryResolverException, QueryValidatorException {
+	PlanNode createUpdatePlan(Command command) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         // Create top project node - define output columns for stored query / procedure
         PlanNode projectNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
 
@@ -462,8 +460,7 @@
 
 	private void addNestedProcedure(PlanNode sourceNode,
 			ProcedureContainer container) throws MetaMatrixComponentException,
-			QueryMetadataException, QueryResolverException,
-			QueryValidatorException, QueryPlannerException {
+			QueryMetadataException, MetaMatrixProcessingException {
 		//plan any subqueries in criteria/parameters/values
 		for (SubqueryContainer subqueryContainer : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(container)) {
     		ProcessorPlan plan = QueryOptimizer.optimizePlan(subqueryContainer.getCommand(), metadata, null, capFinder, analysisRecord, context);
@@ -490,7 +487,7 @@
 		}
 	}
 
-    PlanNode createStoredProcedurePlan(StoredProcedure storedProc) throws QueryPlannerException, QueryResolverException, QueryValidatorException, QueryMetadataException, MetaMatrixComponentException {
+    PlanNode createStoredProcedurePlan(StoredProcedure storedProc) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
         // Create top project node - define output columns for stored query / procedure
         PlanNode projectNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
 
@@ -514,7 +511,7 @@
     }
 
 	PlanNode createQueryPlan(QueryCommand command)
-		throws QueryPlannerException, MetaMatrixComponentException, QueryResolverException, QueryValidatorException {
+		throws MetaMatrixComponentException, MetaMatrixProcessingException {
         // Build canonical plan
     	PlanNode node = null;
         if(command instanceof Query) {
@@ -545,7 +542,7 @@
     }
 
     private PlanNode createQueryPlan(Query query)
-		throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException, QueryResolverException, QueryValidatorException {
+		throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
 
         PlanNode plan = null;
 
@@ -616,11 +613,10 @@
      * as internal
      * @throws MetaMatrixComponentException 
      * @throws QueryMetadataException 
-     * @throws QueryValidatorException 
-     * @throws QueryResolverException 
+     * @throws MetaMatrixProcessingException 
      */
     void buildTree(FromClause clause, PlanNode parent)
-        throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException, QueryResolverException, QueryValidatorException {
+        throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
         
         PlanNode node = null;
         
@@ -694,9 +690,7 @@
     }
 
 	private void addNestedCommand(PlanNode node,
-			GroupSymbol group, Command nestedCommand, Command toPlan, boolean merge) throws QueryPlannerException,
-			MetaMatrixComponentException, QueryResolverException,
-			QueryValidatorException, QueryMetadataException {
+			GroupSymbol group, Command nestedCommand, Command toPlan, boolean merge) throws MetaMatrixComponentException, QueryMetadataException, MetaMatrixProcessingException {
 		if (nestedCommand instanceof QueryCommand) {
 			//remove unnecessary order by
         	QueryCommand queryCommand = (QueryCommand)nestedCommand;
@@ -871,7 +865,7 @@
     }
 	
     private Command resolveVirtualGroup(GroupSymbol virtualGroup)
-    throws QueryMetadataException, MetaMatrixComponentException, QueryResolverException, QueryValidatorException {
+    throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
     	
         QueryNode qnode = null;
         

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -60,6 +60,7 @@
 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.util.SymbolMap;
@@ -94,6 +95,11 @@
         this.caps = caps;
     }
     
+    @Override
+    public void visit(SQLXMLFunction obj) {
+    	markInvalid();
+    }
+    
     public void visit(AggregateSymbol obj) {
         try {
             if(! CapabilitiesUtil.supportsAggregateFunction(modelID, obj, metadata, capFinder)) {

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -32,10 +32,11 @@
 import java.util.Set;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.core.MetaMatrixRuntimeException;
 import com.metamatrix.core.util.Assertion;
 import com.metamatrix.query.execution.QueryExecPlugin;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
@@ -282,8 +283,10 @@
         // Simplify criteria if possible
         try {
             return QueryRewriter.rewriteCriteria(criteria, null, null, metadata);
-        } catch(QueryValidatorException e) {
+        } catch(MetaMatrixProcessingException e) {
             throw new QueryPlannerException(e, QueryExecPlugin.Util.getString(ErrorMessageKeys.OPTIMIZER_0023, criteria));
+        } catch (MetaMatrixComponentException e) {
+        	throw new MetaMatrixRuntimeException(e);
         }
     }
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/JoinUtil.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -26,7 +26,7 @@
 import java.util.List;
 import java.util.Set;
 
-import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.api.exception.MetaMatrixException;
 import com.metamatrix.core.util.Assertion;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
@@ -140,7 +140,7 @@
         Criteria simplifiedCrit = (Criteria)replaceWithNullValues(innerGroups, crit);
         try {
             simplifiedCrit = QueryRewriter.rewriteCriteria(simplifiedCrit, null, null, metadata);
-        } catch (QueryValidatorException err) {
+        } catch (MetaMatrixException err) {
             //log the exception
             return true;
         }
@@ -153,7 +153,7 @@
         Expression simplifiedExpression = (Expression)replaceWithNullValues(innerGroups, expr);
         try {
             simplifiedExpression = QueryRewriter.rewriteExpression(simplifiedExpression, null, null, metadata);
-        } catch (QueryValidatorException err) {
+        } catch (MetaMatrixException err) {
             //log the exception
             return true;
         }

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/QueryUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/QueryUtil.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/QueryUtil.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -31,11 +31,11 @@
 import java.util.Map;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
 import com.metamatrix.api.exception.query.QueryParserException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
 import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.query.analysis.AnalysisRecord;
 import com.metamatrix.query.execution.QueryExecPlugin;
 import com.metamatrix.query.mapping.relational.QueryNode;
@@ -112,13 +112,14 @@
      * @param query The query to rewrite
      * @param planEnv The planner environment
      * @throws QueryPlannerException
+     * @throws MetaMatrixComponentException 
      * @since 4.3
      */
     static Command rewriteQuery(Command query, QueryMetadataInterface metadata, CommandContext context) 
-        throws QueryPlannerException {
+        throws QueryPlannerException, MetaMatrixComponentException {
         try {
             return QueryRewriter.rewrite(query, metadata, context);
-        } catch(QueryValidatorException e) {
+        } catch(MetaMatrixProcessingException e) {
             throw new QueryPlannerException(e, e.getMessage());
         }
     }

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/xml/XMLUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/xml/XMLUtil.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/xml/XMLUtil.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -31,6 +31,7 @@
 import javax.xml.transform.TransformerException;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.buffer.FileStore;
 import com.metamatrix.common.buffer.FileStore.FileStoreOutputStream;
@@ -50,7 +51,7 @@
      * Documents less than the maxMemorySize will be held directly in memory
      */
     public static SQLXMLImpl saveToBufferManager(BufferManager bufferMgr, XMLTranslator translator, int maxMemorySize) 
-        throws MetaMatrixComponentException {        
+        throws MetaMatrixComponentException, MetaMatrixProcessingException {        
         boolean success = false;
         final FileStore lobBuffer = bufferMgr.createFileStore("xml"); //$NON-NLS-1$
         try{  
@@ -66,7 +67,7 @@
         } catch(IOException e) {
             throw new MetaMatrixComponentException(e);
         } catch(TransformerException e) {
-            throw new MetaMatrixComponentException(e);
+            throw new MetaMatrixProcessingException(e);
         } finally {
         	if (!success && lobBuffer != null) {
         		lobBuffer.remove();

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/xml/XMLValueTranslator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/xml/XMLValueTranslator.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/xml/XMLValueTranslator.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -24,23 +24,23 @@
 
 import java.math.BigInteger;
 import java.sql.Timestamp;
-import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.query.FunctionExecutionException;
 import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.common.types.TransformationException;
 import com.metamatrix.query.function.FunctionMethods;
+import com.metamatrix.query.function.source.XMLSystemFunctions;
 
 
 /**
  * This class will make a minimal effort to output xsd formatted values for a given
- * builtin type.  It will not attempt to narrrow or otherwise fit most values into
+ * built-in type.  It will not attempt to narrow or otherwise fit most values into
  * their output space (months can be greater than 12, nonNegative numbers can be 
  * negative, etc.)
  */
-final class XMLValueTranslator {
+public final class XMLValueTranslator {
 
     private static String NEGATIVE_INFINITY = "-INF"; //$NON-NLS-1$
     private static String POSITIVE_INFINITY = "INF"; //$NON-NLS-1$
@@ -48,22 +48,7 @@
     private static String GMONTHDAY_FORMAT = "--MM-dd"; //$NON-NLS-1$
     private static String GYEAR_FORMAT = "0000"; //$NON-NLS-1$
     private static String GYEARMONTH_FORMAT = "yyyy-MM"; //$NON-NLS-1$
-    private static String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; //$NON-NLS-1$
     
-    //YEAR 0 in the server timezone. used to determine negative years
-    private static long YEAR_ZERO;
-    
-    static {
-        Calendar cal = Calendar.getInstance();
-    
-        for (int i = 0; i <= Calendar.MILLISECOND; i++) {
-            cal.set(i, 0);
-        }
-        YEAR_ZERO = cal.getTimeInMillis();
-    }
-    
-    private static String TIMESTAMP_MICROZEROS = "000000000"; //$NON-NLS-1$
-    
     public static final String DATETIME    = "dateTime"; //$NON-NLS-1$
     public static final String DOUBLE      = "double"; //$NON-NLS-1$
     public static final String FLOAT       = "float"; //$NON-NLS-1$
@@ -75,7 +60,7 @@
     
     public static final String STRING = "string"; //$NON-NLS-1$
     
-    private static final Map TYPE_CODE_MAP;
+    private static final Map<String, Integer> TYPE_CODE_MAP;
     
     private static final int DATETIME_CODE = 0;
     private static final int DOUBLE_CODE = 1;
@@ -87,7 +72,7 @@
     private static final int GYEARMONTH_CODE = 7;
         
     static {
-        TYPE_CODE_MAP = new HashMap(20);
+        TYPE_CODE_MAP = new HashMap<String, Integer>(20);
         TYPE_CODE_MAP.put(DATETIME, new Integer(DATETIME_CODE));
         TYPE_CODE_MAP.put(DOUBLE, new Integer(DOUBLE_CODE));
         TYPE_CODE_MAP.put(FLOAT, new Integer(FLOAT_CODE));
@@ -112,14 +97,15 @@
      * @param builtInType The design-time atomic built-in type (or null if none)
      * @return String representing the value
      * @throws FunctionExecutionException 
+     * @throws TransformationException 
      * @since 5.0
      */
-    static String translateToXMLValue(Object value, Class runtimeType, String builtInType) throws MetaMatrixComponentException, FunctionExecutionException {
+    public static String translateToXMLValue(Object value, Class<?> runtimeType, String builtInType) throws FunctionExecutionException, TransformationException {
         if (value == null) {
             return null;
         }
         
-        Integer typeCode = (Integer)TYPE_CODE_MAP.get(builtInType);
+        Integer typeCode = TYPE_CODE_MAP.get(builtInType);
         
         String valueStr = null;
         
@@ -131,7 +117,7 @@
             
             switch (type) {
                 case DATETIME_CODE:
-                    valueStr = timestampToDateTime((Timestamp)value);
+                    valueStr = XMLSystemFunctions.timestampToDateTime((Timestamp)value);
                     break;
                 case DOUBLE_CODE:
                     valueStr = doubleToDouble((Double)value);
@@ -178,62 +164,25 @@
     private static String timestampTogYearMonth(Object value) throws FunctionExecutionException {
         String valueStr;
         Timestamp time = (Timestamp)value;
-        valueStr = (String)FunctionMethods.format(time, GYEARMONTH_FORMAT);
-        if (time.getTime() < YEAR_ZERO) {
+        valueStr = FunctionMethods.format(time, GYEARMONTH_FORMAT);
+        if (time.getTime() < XMLSystemFunctions.YEAR_ZERO) {
             valueStr = "-" + valueStr; //$NON-NLS-1$
         }
         return valueStr;
     }
     
     /**
-     * Formats a timestamp to an xs:dateTime.  This uses DATETIME_FORMAT
-     * with a trailing string for nanoseconds (without right zeros). 
-     */
-    static String timestampToDateTime(Timestamp time) throws FunctionExecutionException {
-        String result = (String)FunctionMethods.format(time, DATETIME_FORMAT);
-        int nanos = time.getNanos();
-        if (nanos == 0) {
-            return result;
-        }
-        
-        StringBuffer resultBuffer = new StringBuffer();
-        boolean first = true;
-        int i = 0;
-        for (; i < 9 && nanos > 0; i++) {
-            int digit = nanos%10;
-            if (first) {
-                if (digit > 0) {
-                    resultBuffer.insert(0, digit);
-                    first = false;
-                }
-            } else {
-                resultBuffer.insert(0, digit);
-            }
-            nanos /= 10;
-        }
-        if (i < 9) {
-            resultBuffer.insert(0, TIMESTAMP_MICROZEROS.substring(i));
-        }
-        resultBuffer.insert(0, "."); //$NON-NLS-1$
-        resultBuffer.insert(0, result);
-        if (time.getTime() < YEAR_ZERO) {
-            resultBuffer.insert(0, "-"); //$NON-NLS-1$
-        }
-        return resultBuffer.toString();
-        
-    }
-    
-    /**
      * Translate any non-null value to a string by using the Object toString() method.
      * This works in any case where the Java string representation of an object is the 
      * same as the expected XML Schema output form.
      *   
      * @param value Value returned from a mapping class
      * @return String content to put in XML output
+     * @throws TransformationException 
      * @since 5.0
      */
-    static String defaultTranslation(Object value) {
-        return value.toString();
+    static String defaultTranslation(Object value) throws TransformationException {
+        return DataTypeManager.transformValue(value, DataTypeManager.DefaultDataClasses.STRING);
     }
     
     /**
@@ -243,9 +192,10 @@
      *  
      * @param f Runtime float
      * @return String representing xs:float
+     * @throws TransformationException 
      * @since 5.0
      */
-    static String floatToFloat(Float f) {
+    static String floatToFloat(Float f) throws TransformationException {
         if(f.floatValue() == Float.NEGATIVE_INFINITY) {
             return NEGATIVE_INFINITY;
         } else if(f.floatValue() == Float.POSITIVE_INFINITY) {
@@ -261,9 +211,10 @@
      *  
      * @param d Runtime double
      * @return String representing xs:double
+     * @throws TransformationException 
      * @since 5.0
      */
-    static String doubleToDouble(Double d) {
+    static String doubleToDouble(Double d) throws TransformationException {
         if(d.doubleValue() == Double.NEGATIVE_INFINITY) {
             return NEGATIVE_INFINITY;
         } else if(d.doubleValue() == Double.POSITIVE_INFINITY) {

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/xquery/XQueryPlan.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/xquery/XQueryPlan.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/xquery/XQueryPlan.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -139,8 +139,9 @@
      * memory "atomically" (from the XQueryEngine layer).
      * @param rawResults
      * @return
+     * @throws MetaMatrixProcessingException 
      */
-    private TupleBatch packResultsIntoBatch(XMLTranslator translator) throws MetaMatrixComponentException{
+    private TupleBatch packResultsIntoBatch(XMLTranslator translator) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         List rows = new ArrayList(1);
         List row = new ArrayList(1);
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitor.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -497,7 +497,7 @@
 	            setDesiredType(args[i], newType, function);
 	                                
 	            //only currently typed expressions need conversions
-	            if (types[i] != null) {
+	            if (types[i] != null && newType != DataTypeManager.DefaultDataClasses.OBJECT) {
 	                function.insertConversion(i, conversions[i]);
 	            }
 	        } 

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -48,7 +48,6 @@
 import com.metamatrix.api.exception.MetaMatrixException;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.CriteriaEvaluationException;
-import com.metamatrix.api.exception.query.ExpressionEvaluationException;
 import com.metamatrix.api.exception.query.FunctionExecutionException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
 import com.metamatrix.api.exception.query.QueryResolverException;
@@ -136,6 +135,7 @@
 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;
@@ -192,26 +192,10 @@
     	QueryRewriter queryRewriter = new QueryRewriter(metadata, context, null);
     	queryRewriter.dataMgr = dataMgr;
     	queryRewriter.rewriteSubcommands = true;
-    	try {
-    		return queryRewriter.rewriteCommand(command, false);
-    	} catch (MetaMatrixRuntimeException err) {
-    		Throwable e = err.getChild();
-            
-            if (e == null) {
-                throw err;
-            }
-            
-            if(e instanceof ExpressionEvaluationException) {
-                throw (ExpressionEvaluationException) e;
-            } else if(e instanceof MetaMatrixComponentException) {
-                throw (MetaMatrixComponentException) e;                    
-            } else {
-                throw new MetaMatrixComponentException(e, e.getMessage());    
-            }
-    	}
+		return queryRewriter.rewriteCommand(command, false);
     }
 
-	public static Command rewrite(Command command, CreateUpdateProcedureCommand procCommand, QueryMetadataInterface metadata, CommandContext context, Map variableValues, int commandType) throws QueryValidatorException {
+	public static Command rewrite(Command command, CreateUpdateProcedureCommand procCommand, QueryMetadataInterface metadata, CommandContext context, Map variableValues, int commandType) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		QueryRewriter rewriter = new QueryRewriter(metadata, context, procCommand);
 		rewriter.rewriteSubcommands = true;
 		rewriter.variables = variableValues;
@@ -219,7 +203,7 @@
 		return rewriter.rewriteCommand(command, false);
 	}
     
-	public static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context) throws QueryValidatorException {
+	public static Command rewrite(Command command, QueryMetadataInterface metadata, CommandContext context) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		return rewrite(command, null, metadata, context, null, Command.TYPE_UNKNOWN);
     }
 
@@ -231,7 +215,7 @@
      * @return
      * @throws QueryValidatorException
      */
-	private Command rewriteCommand(Command command, boolean removeOrderBy) throws QueryValidatorException {
+	private Command rewriteCommand(Command command, boolean removeOrderBy) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		QueryMetadataInterface oldMetadata = metadata;
 		CreateUpdateProcedureCommand oldProcCommand = procCommand;
         
@@ -287,20 +271,12 @@
 	}
     
 	private Command rewriteUpdateProcedure(CreateUpdateProcedureCommand command)
-								 throws QueryValidatorException {
+								 throws MetaMatrixComponentException, MetaMatrixProcessingException{
         Map oldVariables = variables;
-        try {
-        	if (command.getUserCommand() != null) {
-	            variables = QueryResolver.getVariableValues(command.getUserCommand(), metadata);                        
-	            commandType = command.getUserCommand().getType();
-        	}
-        } catch (QueryMetadataException err) {
-            throw new QueryValidatorException(err, err.getMessage());
-        } catch (QueryResolverException err) {
-            throw new QueryValidatorException(err, err.getMessage());
-        } catch (MetaMatrixComponentException err) {
-            throw new QueryValidatorException(err, err.getMessage());
-        }
+    	if (command.getUserCommand() != null) {
+            variables = QueryResolver.getVariableValues(command.getUserCommand(), metadata);                        
+            commandType = command.getUserCommand().getType();
+    	}
 
 		Block block = rewriteBlock(command.getBlock());
         command.setBlock(block);
@@ -311,7 +287,7 @@
 	}
 
 	private Block rewriteBlock(Block block)
-								 throws QueryValidatorException {
+								 throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		List statements = block.getStatements();
         Iterator stmtIter = statements.iterator();
 
@@ -333,7 +309,7 @@
 	 }
 
 	private Object rewriteStatement(Statement statement)
-								 throws QueryValidatorException {
+								 throws MetaMatrixComponentException, MetaMatrixProcessingException{
 
         // evaluate the HAS Criteria on the procedure and rewrite
 		int stmtType = statement.getType();
@@ -434,7 +410,7 @@
      * @param assStmt
      * @throws QueryValidatorException
      */
-    private void rewriteSubqueryContainer(SubqueryContainer container, boolean removeOrderBy) throws QueryValidatorException {
+    private void rewriteSubqueryContainer(SubqueryContainer container, boolean removeOrderBy) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         if (rewriteSubcommands && container.getCommand() != null && container.getCommand().getProcessorPlan() == null) {
         	container.setCommand(rewriteCommand(container.getCommand(), removeOrderBy));
         }
@@ -552,7 +528,7 @@
 	 * virtual group.</p>
 	 */
 	private Criteria rewriteCriteria(TranslateCriteria transCrit)
-			 throws QueryValidatorException {
+			 throws MetaMatrixComponentException, MetaMatrixProcessingException{
 
 		// criteria translated
 		Criteria translatedCriteria = null;
@@ -607,7 +583,7 @@
 		// apply any implicit conversions
 		try {
             ResolverVisitor.resolveLanguageObject(translatedCriteria, metadata);
-		} catch(Exception ex) {
+		} catch(MetaMatrixException ex) {
             throw new QueryValidatorException(ex, ErrorMessageKeys.REWRITER_0002, QueryExecPlugin.Util.getString(ErrorMessageKeys.REWRITER_0002, translatedCriteria));
 		}
 
@@ -615,7 +591,7 @@
 	}
 
 	private Command rewriteQuery(Query query)
-             throws QueryValidatorException {
+             throws MetaMatrixComponentException, MetaMatrixProcessingException{
         
         // Rewrite from clause
         From from = query.getFrom();
@@ -672,7 +648,7 @@
 	 * @return
 	 * @throws QueryValidatorException
 	 */
-	private Query rewriteGroupBy(Query query) throws QueryValidatorException {
+	private Query rewriteGroupBy(Query query) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		if (query.getGroupBy() == null) {
 			return query;
 		}
@@ -723,11 +699,7 @@
         Query outerQuery = null;
         try {
             outerQuery = QueryRewriter.createInlineViewQuery(new GroupSymbol("X"), query, metadata, query.getSelect().getProjectedSymbols()); //$NON-NLS-1$
-        } catch (QueryMetadataException err) {
-            throw new QueryValidatorException(err, err.getMessage());
-        } catch (QueryResolverException err) {
-            throw new QueryValidatorException(err, err.getMessage());
-        } catch (MetaMatrixComponentException err) {
+        } catch (MetaMatrixException err) {
             throw new MetaMatrixRuntimeException(err);
         }
         Iterator iter = outerQuery.getSelect().getProjectedSymbols().iterator();
@@ -751,7 +723,7 @@
 		return query;
 	}
     
-    private void rewriteExpressions(LanguageObject obj) throws QueryValidatorException {
+    private void rewriteExpressions(LanguageObject obj) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         if (obj == null) {
             return;
         }
@@ -763,7 +735,7 @@
             public Expression replaceExpression(Expression element) {
                 try {
                     return rewriteExpressionDirect(element);
-                } catch (QueryValidatorException err) {
+                } catch (MetaMatrixException err) {
                     throw new MetaMatrixRuntimeException(err);
                 }
             }
@@ -771,9 +743,12 @@
         try {
             PostOrderNavigator.doVisit(obj, visitor);
         } catch (MetaMatrixRuntimeException err) {
-            if (err.getChild() instanceof QueryValidatorException) {
-                throw (QueryValidatorException)err.getChild();
+            if (err.getChild() instanceof MetaMatrixComponentException) {
+                throw (MetaMatrixComponentException)err.getChild();
             } 
+            if (err.getChild() instanceof MetaMatrixProcessingException) {
+                throw (MetaMatrixProcessingException)err.getChild();
+            } 
             throw err;
         }
     }
@@ -783,9 +758,9 @@
      * Unrelated order by expressions will cause the creation of nested inline views.
      *  
      * @param query
-     * @throws QueryValidatorException 
+     * @throws MetaMatrixComponentException, MetaMatrixProcessingException
      */
-    public QueryCommand rewriteOrderBy(QueryCommand queryCommand) throws QueryValidatorException {
+    public QueryCommand rewriteOrderBy(QueryCommand queryCommand) throws MetaMatrixComponentException, MetaMatrixProcessingException{
     	final OrderBy orderBy = queryCommand.getOrderBy();
         if (orderBy == null) {
             return queryCommand;
@@ -852,13 +827,9 @@
 		    }
 		    ExpressionMappingVisitor.mapExpressions(orderBy, expressionMap);
 		    //now the order by should only contain element symbols
-		} catch (QueryResolverException e) {
-			throw new QueryValidatorException(e, e.getMessage());
-		} catch (QueryMetadataException e) {
-			throw new QueryValidatorException(e, e.getMessage());
-		} catch (MetaMatrixComponentException e) {
-			throw new QueryValidatorException(e, e.getMessage());
-		}
+		} catch (MetaMatrixException err) {
+            throw new MetaMatrixRuntimeException(err);
+        }
 		List symbols = top.getSelect().getSymbols();
 		top.getSelect().setSymbols(symbols.subList(0, originalSymbolCount));
 		top.setInto(into);
@@ -874,7 +845,7 @@
      * @param query
      * @throws QueryValidatorException
      */
-    private Insert rewriteSelectInto(Query query) throws QueryValidatorException {
+    private Insert rewriteSelectInto(Query query) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         Into into = query.getInto();
         try {
             List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class);
@@ -889,7 +860,7 @@
 		}
     }
 
-	private Insert correctDatatypes(Insert insert) throws QueryValidatorException {
+	private Insert correctDatatypes(Insert insert) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		boolean needsView = false;
 		for (int i = 0; !needsView && i < insert.getVariables().size(); i++) {
 		    SingleElementSymbol ses = (SingleElementSymbol)insert.getVariables().get(i);
@@ -900,13 +871,9 @@
 		if (needsView) {
 		    try {
 				insert.setQueryExpression(createInlineViewQuery(insert.getGroup(), insert.getQueryExpression(), metadata, insert.getVariables()));
-			} catch (QueryResolverException e) {
-				throw new QueryValidatorException(e, e.getMessage());
-			} catch (QueryMetadataException e) {
-				throw new QueryValidatorException(e, e.getMessage());
-			} catch (MetaMatrixComponentException e) {
-				throw new MetaMatrixRuntimeException(e);
-			}
+			} catch (MetaMatrixException err) {
+	            throw new MetaMatrixRuntimeException(err);
+	        }
 		}
 		return insert;
 	}
@@ -921,7 +888,7 @@
     } 
     
 	private SetQuery rewriteSetQuery(SetQuery setQuery)
-				 throws QueryValidatorException {
+				 throws MetaMatrixComponentException, MetaMatrixProcessingException{
         
         if (setQuery.getProjectedTypes() != null) {
             for (QueryCommand command : setQuery.getQueryCommands()) {
@@ -946,7 +913,7 @@
     }
 
 	private FromClause rewriteFromClause(Query parent, FromClause clause)
-			 throws QueryValidatorException {
+			 throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		if(clause instanceof JoinPredicate) {
 			return rewriteJoinPredicate(parent, (JoinPredicate) clause);
         } else if (clause instanceof SubqueryFromClause) {
@@ -956,7 +923,7 @@
 	}
 
 	private JoinPredicate rewriteJoinPredicate(Query parent, JoinPredicate predicate)
-			 throws QueryValidatorException {
+			 throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		List joinCrits = predicate.getJoinCriteria();
 		if(joinCrits != null && joinCrits.size() > 0) {
 			//rewrite join crits by rewriting a compound criteria
@@ -995,7 +962,7 @@
      * in the procedural language.
      * @return The re-written criteria
      */
-    public static Criteria rewriteCriteria(Criteria criteria, CreateUpdateProcedureCommand procCommand, CommandContext context, QueryMetadataInterface metadata) throws QueryValidatorException {
+    public static Criteria rewriteCriteria(Criteria criteria, CreateUpdateProcedureCommand procCommand, CommandContext context, QueryMetadataInterface metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException{
     	return new QueryRewriter(metadata, context, procCommand).rewriteCriteria(criteria);
     }
 
@@ -1006,7 +973,7 @@
 	 * in the procedural language.
 	 * @return The re-written criteria
 	 */
-    private Criteria rewriteCriteria(Criteria criteria) throws QueryValidatorException {
+    private Criteria rewriteCriteria(Criteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
     	if(criteria instanceof CompoundCriteria) {
             return rewriteCriteria((CompoundCriteria)criteria, true);
 		} else if(criteria instanceof NotCriteria) {
@@ -1043,7 +1010,7 @@
 	}
 
 	private Criteria rewriteDependentSetCriteria(DependentSetCriteria dsc)
-			throws QueryValidatorException {
+			throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		if (dataMgr == null) {
 			return rewriteCriteria(dsc);
 		}
@@ -1076,7 +1043,7 @@
     public static Criteria optimizeCriteria(CompoundCriteria criteria, QueryMetadataInterface metadata) {
         try {
             return new QueryRewriter(metadata, null, null).rewriteCriteria(criteria, false);
-        } catch (QueryValidatorException err) {
+        } catch (MetaMatrixException err) {
             //shouldn't happen
             return criteria;
         }
@@ -1085,7 +1052,7 @@
     /** May be simplified if this is an AND and a sub criteria is always
      * false or if this is an OR and a sub criteria is always true
      */
-    private Criteria rewriteCriteria(CompoundCriteria criteria, boolean rewrite) throws QueryValidatorException {
+    private Criteria rewriteCriteria(CompoundCriteria criteria, boolean rewrite) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         List<Criteria> crits = criteria.getCriteria();
         int operator = criteria.getOperator();
 
@@ -1141,7 +1108,7 @@
         }
 	}
     
-    private Criteria evaluateCriteria(Criteria crit) throws QueryValidatorException {
+    private Criteria evaluateCriteria(Criteria crit) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         if(EvaluatableVisitor.isFullyEvaluatable(crit, true)) {
             try {
             	Boolean eval = new Evaluator(Collections.emptyMap(), this.dataMgr, context).evaluateTVL(crit, Collections.emptyList());
@@ -1158,15 +1125,13 @@
                 
             } catch(CriteriaEvaluationException e) {
                 throw new QueryValidatorException(e, ErrorMessageKeys.REWRITER_0001, QueryExecPlugin.Util.getString(ErrorMessageKeys.REWRITER_0001, crit));
-            } catch(MetaMatrixComponentException e) {
-                throw new MetaMatrixRuntimeException(e);
             }
         }
         
         return crit;
     }
 
-	private Criteria rewriteCriteria(NotCriteria criteria) throws QueryValidatorException {
+	private Criteria rewriteCriteria(NotCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		Criteria innerCrit = criteria.getCriteria(); 
         if (innerCrit instanceof CompoundCriteria) {
         	//reduce to only negation of predicates, so that the null/unknown handling criteria is applied appropriately
@@ -1197,7 +1162,7 @@
      * @return
      * @throws QueryValidatorException
      */
-    private Criteria rewriteCriteria(BetweenCriteria criteria) throws QueryValidatorException {
+    private Criteria rewriteCriteria(BetweenCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         CompareCriteria lowerCriteria = new CompareCriteria(criteria.getExpression(),
                                                             criteria.isNegated() ? CompareCriteria.LT: CompareCriteria.GE,
                                                             criteria.getLowerExpression());
@@ -1211,7 +1176,7 @@
         return rewriteCriteria(newCriteria);
     }
 
-	private Criteria rewriteCriteria(CompareCriteria criteria) throws QueryValidatorException {
+	private Criteria rewriteCriteria(CompareCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		Expression leftExpr = rewriteExpressionDirect(criteria.getLeftExpression());
 		Expression rightExpr = rewriteExpressionDirect(criteria.getRightExpression());
 		criteria.setLeftExpression(leftExpr);
@@ -1264,7 +1229,7 @@
      * The thing of primary importance here is that the use of the 'ANY' predicate
      * quantifier is replaced with the canonical and equivalent 'SOME'
      */
-    private Criteria rewriteCriteria(SubqueryCompareCriteria criteria) throws QueryValidatorException {
+    private Criteria rewriteCriteria(SubqueryCompareCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 
         Expression leftExpr = rewriteExpressionDirect(criteria.getLeftExpression());
         
@@ -1283,7 +1248,7 @@
         return criteria;
     }
     
-    private Criteria simplifyWithInverse(CompareCriteria criteria) throws QueryValidatorException {
+    private Criteria simplifyWithInverse(CompareCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         Expression leftExpr = criteria.getLeftExpression();
         
         Function leftFunction = (Function) leftExpr;
@@ -1324,7 +1289,7 @@
      * @return CompareCriteria
      */
     private CompareCriteria simplifyMathematicalCriteria(CompareCriteria criteria)
-    throws QueryValidatorException {
+    throws MetaMatrixComponentException, MetaMatrixProcessingException{
 
         Expression leftExpr = criteria.getLeftExpression();
         Expression rightExpr = criteria.getRightExpression();
@@ -1457,7 +1422,7 @@
      * @throws QueryValidatorException
      * @since 4.2
      */
-    private Criteria simplifyConvertFunction(CompareCriteria crit) throws QueryValidatorException {
+    private Criteria simplifyConvertFunction(CompareCriteria crit) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         Function leftFunction = (Function) crit.getLeftExpression();
         Expression leftExpr = leftFunction.getArgs()[0];
         
@@ -1516,7 +1481,7 @@
      * @throws QueryValidatorException
      * @since 4.2
      */
-	private Criteria simplifyConvertFunction(SetCriteria crit) throws QueryValidatorException {
+	private Criteria simplifyConvertFunction(SetCriteria crit) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         Function leftFunction = (Function) crit.getExpression();
         Expression leftExpr = leftFunction.getArgs()[0];
         String leftExprTypeName = DataTypeManager.getDataTypeName(leftExpr.getType());
@@ -1567,7 +1532,7 @@
         return rewriteCriteria(crit);
     }
         
-    private Criteria simplifyParseFormatFunction(CompareCriteria crit) throws QueryValidatorException {
+    private Criteria simplifyParseFormatFunction(CompareCriteria crit) throws MetaMatrixComponentException, MetaMatrixProcessingException{
     	//TODO: this can be relaxed for order preserving operations
         if(!(crit.getOperator() == CompareCriteria.EQ || crit.getOperator() == CompareCriteria.NE)) {
         	return crit;
@@ -1765,7 +1730,7 @@
        }
     }
     
-    private Criteria rewriteCriteria(MatchCriteria criteria) throws QueryValidatorException {
+    private Criteria rewriteCriteria(MatchCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		criteria.setLeftExpression( rewriteExpressionDirect(criteria.getLeftExpression()));
 		criteria.setRightExpression( rewriteExpressionDirect(criteria.getRightExpression()));
         
@@ -1817,7 +1782,7 @@
 		return FALSE_CRITERIA;
 	}
 	
-    private Criteria rewriteCriteria(AbstractSetCriteria criteria) throws QueryValidatorException {
+    private Criteria rewriteCriteria(AbstractSetCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         criteria.setExpression(rewriteExpressionDirect(criteria.getExpression()));
         
         if (isNull(criteria.getExpression())) {
@@ -1827,7 +1792,7 @@
         return criteria;
     }
 
-	private Criteria rewriteCriteria(SetCriteria criteria) throws QueryValidatorException {
+	private Criteria rewriteCriteria(SetCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		criteria.setExpression(rewriteExpressionDirect(criteria.getExpression()));
         
         if (isNull(criteria.getExpression())) {
@@ -1866,16 +1831,16 @@
 		return criteria;
 	}
 
-	private Criteria rewriteCriteria(IsNullCriteria criteria) throws QueryValidatorException {
+	private Criteria rewriteCriteria(IsNullCriteria criteria) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		criteria.setExpression(rewriteExpressionDirect(criteria.getExpression()));
 		return criteria;
 	}
 	
-	public static Expression rewriteExpression(Expression expression, CreateUpdateProcedureCommand procCommand, CommandContext context, QueryMetadataInterface metadata) throws QueryValidatorException {
+	public static Expression rewriteExpression(Expression expression, CreateUpdateProcedureCommand procCommand, CommandContext context, QueryMetadataInterface metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		return new QueryRewriter(metadata, context, procCommand).rewriteExpressionDirect(expression);
 	}
 
-    private Expression rewriteExpressionDirect(Expression expression) throws QueryValidatorException {
+    private Expression rewriteExpressionDirect(Expression expression) throws MetaMatrixComponentException, MetaMatrixProcessingException{
     	if (expression instanceof Constant) {
     		return expression;
     	}
@@ -1927,16 +1892,17 @@
         	} else {
             	expression = rewriteExpressionDirect(((ExpressionSymbol)expression).getExpression());
         	}
-        } 
-    	if (dataMgr == null || (!(expression instanceof Reference) && !EvaluatableVisitor.isEvaluatable(expression, EvaluationLevel.PROCESSING))) {
-    		return expression;
-    	}
-		Object value;
-        try {
-            value = new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(expression, Collections.emptyList());
-        } catch (MetaMatrixException err) {
-            throw new MetaMatrixRuntimeException(err);
         }
+    	
+        if(dataMgr == null) {
+        	if (!EvaluatableVisitor.isFullyEvaluatable(expression, true)) {
+        		return expression;
+        	}
+		} else if (!(expression instanceof Reference) && !EvaluatableVisitor.isEvaluatable(expression, EvaluationLevel.PROCESSING)) {
+			return expression;
+		}
+    	
+		Object value = new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(expression, Collections.emptyList());
         if (value instanceof Constant) {
         	return (Constant)value; //multi valued substitution
         }
@@ -1973,7 +1939,7 @@
     	FUNCTION_MAP.put(FunctionLibrary.FORMATTIME.toLowerCase(), 9);
     }
     
-	private Expression rewriteFunction(Function function) throws QueryValidatorException {
+	private Expression rewriteFunction(Function function) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		//rewrite alias functions
 		String functionLowerName = function.getName().toLowerCase();
 		String actualName =ALIASED_FUNCTIONS.get(functionLowerName);
@@ -2123,26 +2089,6 @@
             return convertDecodeFunction(function);
         }
         
-        if(EvaluatableVisitor.isFullyEvaluatable(function, true)) {
-            try {
-                Object result = new Evaluator(Collections.emptyMap(), null, context).evaluate(function, Collections.emptyList());
-				Constant constant = new Constant(result, function.getType());
-				return constant;
-			} catch(ExpressionEvaluationException e) {
-                String funcName = function.getName();
-                if(FunctionLibrary.isConvert(function)) {
-                    Expression expr = newArgs[0];
-                    String sourceType = DataTypeManager.getDataTypeName(newArgs[0].getType());
-                    String targetType = (String) ((Constant) newArgs[1]).getValue();
-                    throw new QueryValidatorException(e, ErrorMessageKeys.REWRITER_0004, 
-                        QueryExecPlugin.Util.getString(ErrorMessageKeys.REWRITER_0004, new Object[] {funcName, expr, sourceType, targetType}));
-                        
-                }
-                throw new QueryValidatorException(e, e.getMessage());
-			} catch(MetaMatrixComponentException e) {
-                throw new MetaMatrixRuntimeException(e);
-			}
-		} 
         return function;
 	}
 
@@ -2232,7 +2178,7 @@
     }
 	
     private Expression rewriteCaseExpression(CaseExpression expr)
-        throws QueryValidatorException {
+        throws MetaMatrixComponentException, MetaMatrixProcessingException{
     	List<CompareCriteria> whens = new ArrayList<CompareCriteria>(expr.getWhenCount());
     	for (Expression expression: (List<Expression>)expr.getWhen()) {
     		whens.add(new CompareCriteria((Expression)expr.getExpression().clone(), CompareCriteria.EQ, expression));
@@ -2244,7 +2190,7 @@
     }
 
     private Expression rewriteCaseExpression(SearchedCaseExpression expr)
-        throws QueryValidatorException {
+        throws MetaMatrixComponentException, MetaMatrixProcessingException{
         int whenCount = expr.getWhenCount();
         ArrayList<Criteria> whens = new ArrayList<Criteria>(whenCount);
         ArrayList<Expression> thens = new ArrayList<Expression>(whenCount);
@@ -2265,7 +2211,9 @@
             thens.add(rewriteExpressionDirect(expr.getThenExpression(i)));
         }
 
-        expr.setElseExpression(rewriteExpressionDirect(expr.getElseExpression()));
+        if (expr.getElseExpression() != null) {
+        	expr.setElseExpression(rewriteExpressionDirect(expr.getElseExpression()));
+        }
         
         Expression elseExpr = expr.getElseExpression();
         if(whens.size() == 0) {
@@ -2304,7 +2252,7 @@
         return expr;
     }
         
-    private Command rewriteExec(StoredProcedure storedProcedure) throws QueryValidatorException {
+    private Command rewriteExec(StoredProcedure storedProcedure) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         //After this method, no longer need to display named parameters
         storedProcedure.setDisplayNamedParameters(false);
         
@@ -2315,7 +2263,7 @@
         return storedProcedure;
     }
 
-	private Insert rewriteInsert(Insert insert) throws QueryValidatorException {
+	private Insert rewriteInsert(Insert insert) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         
         if ( insert.getQueryExpression() != null ) {
         	insert.setQueryExpression((QueryCommand)rewriteCommand(insert.getQueryExpression(), true));
@@ -2426,7 +2374,7 @@
         }
     }
 
-	private Update rewriteUpdate(Update update) throws QueryValidatorException {
+	private Update rewriteUpdate(Update update) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		if (commandType == Command.TYPE_UPDATE && variables != null) {
 	        SetClauseList newChangeList = new SetClauseList();
 	        for (SetClause entry : update.getChangeList().getClauses()) {
@@ -2458,9 +2406,9 @@
      * none of them are changing, then this method returns a false, if all of them
      * are changing this returns a true, if some are changing and some are not, then
      * that is an invalid case and the method adds to the list of invalid variables.
-     * @throws QueryValidatorException 
+     * @throws MetaMatrixComponentException, MetaMatrixProcessingException
      */
-    private boolean checkInputVariables(Expression expr) throws QueryValidatorException {
+    private boolean checkInputVariables(Expression expr) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         Boolean result = null;
         for (ElementSymbol var : ElementCollectorVisitor.getElements(expr, false)) {
             String grpName = var.getGroupSymbol().getName();
@@ -2485,7 +2433,7 @@
         return true;
     }
 
-	private Delete rewriteDelete(Delete delete) throws QueryValidatorException {
+	private Delete rewriteDelete(Delete delete) throws MetaMatrixComponentException, MetaMatrixProcessingException{
 		// Rewrite criteria
 		Criteria crit = delete.getCriteria();
 		if(crit != null) {
@@ -2495,7 +2443,7 @@
 		return delete;
 	}
     
-    private Limit rewriteLimitClause(Limit limit) throws QueryValidatorException {
+    private Limit rewriteLimitClause(Limit limit) throws MetaMatrixComponentException, MetaMatrixProcessingException{
         if (limit.getOffset() != null) {
             limit.setOffset(rewriteExpressionDirect(limit.getOffset()));
         }

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -126,4 +126,5 @@
     public void visit(SetClauseList obj) {}
     public void visit(SetClause obj) {}
     public void visit(OrderByItem obj) {}
+    public void visit(SQLXMLFunction 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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -92,6 +92,9 @@
 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.util.SymbolMap;
 
 
 /** 
@@ -507,6 +510,16 @@
         postVisitVisitor(obj);
     }
     
+    @Override
+    public void visit(SQLXMLFunction 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);
+    }
+    
     public static void doVisit(LanguageObject object, LanguageVisitor visitor, boolean order) {
         PreOrPostOrderNavigator nav = new PreOrPostOrderNavigator(visitor, order);
         object.acceptVisitor(nav);

Added: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.java	                        (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -0,0 +1,98 @@
+/*
+ * 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);
+	}
+	
+}


Property changes on: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/SQLXMLFunction.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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -45,6 +45,7 @@
 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;
 
 /**
@@ -171,6 +172,9 @@
 	}
 
 	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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -57,6 +57,7 @@
 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;
 
@@ -83,6 +84,11 @@
     public void visit(Select obj) {
         replaceSymbols(obj.getSymbols(), true);
     }
+    
+    @Override
+    public void visit(SQLXMLFunction 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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -109,6 +109,7 @@
 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;
 
 /**
  * <p>The SQLStringVisitor will visit a set of language objects and return the
@@ -1238,46 +1239,32 @@
 
             if(args != null && args.length > 0) {
                 parts.add(((Constant)args[0]).getValue());
-
-                for(int i=1; i<args.length; i++) {
-                    parts.add(", "); //$NON-NLS-1$
-                    parts.add(registerNode(args[i]));
-                }
+                registerNodes(args, 1);
             }
             parts.add(")"); //$NON-NLS-1$
 
-		} else if (name.equalsIgnoreCase(SourceSystemFunctions.XSLTRANSFORM)){
+		} else if (name.equalsIgnoreCase(SourceSystemFunctions.XMLELEMENT)){
 			parts.add(name);
-			parts.add("("); //$NON-NLS-1$
-
-			parts.add(registerNode(args[0]));
-			parts.add(SPACE);
-			parts.add(SQLReservedWords.USING); 
-			parts.add(SPACE);
-			parts.add(registerNode(args[1]));
-			if (args.length > 2) {
-				parts.add(SPACE);
-				parts.add(SQLReservedWords.AS); 
-				parts.add(SPACE);
-				parts.add(((Constant)args[2]).getValue());
-			}
+			parts.add("(NAME "); //$NON-NLS-1$
+			outputDisplayName((String)((Constant)args[0]).getValue());
+			registerNodes(args, 1);
 			parts.add(")"); //$NON-NLS-1$
 		} else {
 			parts.add(name);
 			parts.add("("); //$NON-NLS-1$
-
-			if(args.length > 0) {
-				for(int i=0; i<args.length; i++) {
-					parts.add(registerNode(args[i]));
-					if(i < (args.length-1)) {
-						parts.add(", "); //$NON-NLS-1$
-					}
-				}
-			}
-
+			registerNodes(args, 0);
 			parts.add(")"); //$NON-NLS-1$
 		}
     }
+    
+    private void registerNodes(LanguageObject[] objects, int begin) {
+    	for (int i = begin; i < objects.length; i++) {
+    		if (i > 0) {
+    			parts.add(", "); //$NON-NLS-1$
+    		}
+			parts.add(registerNode(objects[i]));
+		}
+    }
 
     public void visit(GroupSymbol obj) {
         String alias = null;
@@ -1552,6 +1539,13 @@
         parts.add(")"); //$NON-NLS-1$
     }
 
+    @Override
+    public void visit(SQLXMLFunction obj) {
+    	parts.add(obj.getName());
+    	parts.add("("); //$NON-NLS-1$
+    	registerNodes(obj.getArgs().toArray(new LanguageObject[obj.getArgs().size()]), 0);
+    	parts.add(")"); //$NON-NLS-1$
+    }
     
     public void visit(Limit obj) {
         parts.add(SQLReservedWords.LIMIT);

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -94,6 +94,7 @@
 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.util.SymbolMap;
 import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -1113,5 +1114,14 @@
         	((Reference)limitExpr).setConstraint(new PositiveIntegerConstraint("ValidationVisitor.badlimit2")); //$NON-NLS-1$
         }
     }
+    
+    @Override
+    public void visit(SQLXMLFunction obj) {
+    	for (SingleElementSymbol arg : obj.getArgs()) {
+    		if (arg instanceof ExpressionSymbol) {
+    			handleValidationError("ValidationVisitor.expression_requires_name", arg); //$NON-NLS-1$
+    		}
+		}
+    }
         
 }

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -30,9 +30,9 @@
 import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.ExpressionEvaluationException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
 import com.metamatrix.api.exception.query.QueryResolverException;
 import com.metamatrix.api.exception.query.QueryValidatorException;
@@ -123,13 +123,10 @@
     
     /** 
      * @throws MetaMatrixComponentException 
-     * @throws QueryValidatorException 
-     * @throws QueryResolverException 
-     * @throws QueryParserException 
-     * @throws QueryPlannerException 
+     * @throws MetaMatrixProcessingException 
      * @see org.teiid.dqp.internal.process.Request#generatePlan()
      */
-    protected void generatePlan() throws QueryPlannerException, QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+    protected void generatePlan() throws MetaMatrixComponentException, MetaMatrixProcessingException {
     	String sqlQuery = requestMsg.getCommands()[0];
     	CacheID id = new CacheID(this.workContext, Request.createParseInfo(this.requestMsg), sqlQuery);
         prepPlan = prepPlanCache.get(id);

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -381,12 +381,9 @@
      * 		sets the processor plan
      * 
      * @throws MetaMatrixComponentException
-     * @throws QueryPlannerException
-     * @throws QueryParserException
-     * @throws QueryResolverException
-     * @throws QueryValidatorException
+     * @throws MetaMatrixProcessingException 
      */
-    protected void generatePlan() throws MetaMatrixComponentException, QueryPlannerException, QueryParserException, QueryResolverException, QueryValidatorException {
+    protected void generatePlan() throws MetaMatrixComponentException, MetaMatrixProcessingException {
         Command command = parseCommand();
 
         List<Reference> references = ReferenceCollectorVisitor.getReferences(command);
@@ -449,7 +446,7 @@
     }
 
     public void processRequest() 
-        throws QueryValidatorException, QueryParserException, QueryResolverException, MetaMatrixComponentException, QueryPlannerException {
+        throws MetaMatrixComponentException, MetaMatrixProcessingException {
                     
     	LogManager.logDetail(LogConstants.CTX_DQP, this.requestId, "executing", this.requestMsg.isPreparedStatement()?"prepared":"", this.requestMsg.getCommandString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     	

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -31,7 +31,7 @@
 import org.teiid.dqp.internal.process.DQPWorkContext;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.CriteriaEvaluationException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
 import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.core.id.IDGenerator;
@@ -70,7 +70,7 @@
 		if (node instanceof AccessNode) {
 			try {
 				return multiSourceModify((AccessNode)node);
-			} catch (CriteriaEvaluationException e) {
+			} catch (MetaMatrixProcessingException e) {
 				throw new QueryPlannerException(e, e.getMessage());
 			} 
 		}
@@ -78,7 +78,7 @@
 		return node;
 	}
 	
-	private RelationalNode multiSourceModify(AccessNode accessNode) throws MetaMatrixComponentException, CriteriaEvaluationException {
+	private RelationalNode multiSourceModify(AccessNode accessNode) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         String modelName = accessNode.getModelName();
 
 		if(!this.multiSourceModels.contains(modelName)) {

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj	2010-05-06 17:17:44 UTC (rev 2100)
@@ -16,7 +16,6 @@
 import java.math.BigInteger;
 import java.util.*;
 import com.metamatrix.common.types.*;
-import com.metamatrix.core.util.StringUtil;
 import com.metamatrix.query.QueryPlugin;
 import com.metamatrix.query.sql.LanguageObject;
 import com.metamatrix.query.sql.lang.*;
@@ -1595,50 +1594,65 @@
 
 SelectSymbol selectSymbol(ParseInfo info) :
 {
+	SelectSymbol symbol = null;	
+}
+{
+	(
+		symbol = selectExpression(info)
+		|
+		symbol = allInGroupSymbol()
+	)
+	{
+		return symbol;
+	}
+}
+
+SingleElementSymbol selectExpression(ParseInfo info) :
+{
 	Expression expression = null;
     String alias = null;
-    Token allInGroupToken = null;	
 }
 {
 	(	
-        // Group.*
-        (
-            allInGroupToken = <ALL_IN_GROUP>    
-        ) 
-      | 
-        (
-			// Expression
-			expression=expression(info)	
-		)
+		// Expression
+		expression=expression(info)	
 		[[<AS>] ( alias=id() )
 		]
 	)
-	{
-		// Validate alias
-        if(alias != null) { 
-            alias = validateAlias(alias);
-        }    
-	
-		if(allInGroupToken != null) {
-			// Group.*
-			return new AllInGroupSymbol(normalizeId(allInGroupToken.image));
-		} 
+	{		
 		SingleElementSymbol es = null;
 		if(expression instanceof ElementSymbol) {
 			es = (ElementSymbol) expression;
-		} else if(expression instanceof AggregateSymbol) {
-		    es = (AggregateSymbol)expression;
 		} else {
-			String functionName = generateFunctionName(info, null);
-			es = new ExpressionSymbol(functionName, expression);
+			String func = null;
+			if(expression instanceof AggregateSymbol) {
+		    	es = (AggregateSymbol)expression;
+		    	func = ((AggregateSymbol)expression).getAggregateFunction();
+			} else {
+				String functionName = generateFunctionName(info, null);
+				es = new ExpressionSymbol(functionName, expression);
+			}
 		}
-		if(alias != null) { 
+		if(alias != null) {
+			alias = validateAlias(alias); 
 			return new AliasSymbol(alias, es);
 		}
 		return es;
 	}
 }
 
+AllInGroupSymbol allInGroupSymbol() :
+{
+	Token allInGroupToken = null;
+	
+}
+{
+   	allInGroupToken = <ALL_IN_GROUP>    
+    {
+		return new AllInGroupSymbol(normalizeId(allInGroupToken.image));
+	}
+}
+
 AggregateSymbol aggregateSymbol(ParseInfo info) :
 {
 	Token functionToken = null;
@@ -2836,7 +2850,7 @@
  * @return Parsed function
  * @throws ParseException if parsing failed
  */
-Function function(ParseInfo info) :
+Expression function(ParseInfo info) :
 {
 	String funcName = null;
     
@@ -2904,7 +2918,7 @@
 	(
 		(funcToken = <LEFT> | funcToken = <RIGHT> | funcToken = <CHAR> | funcToken = <USER> 
 		                    | funcToken = <YEAR> | funcToken = <MONTH> | funcToken = <HOUR>
-		                    | funcToken = <MINUTE> | funcToken = <SECOND> | funcToken = <XMLELEMENT>)
+		                    | funcToken = <MINUTE> | funcToken = <SECOND> | funcToken = <XMLCONCAT>)
 		<LPAREN>
 		[
 			expression = expression(info)
@@ -2962,7 +2976,40 @@
 		]
 		<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>
+	)
 	|
+	LOOKAHEAD(<XMLFOREST>) (
+		expression = sqlXmlFunction(info)
+		{
+			return expression;
+		}
+	)  				
+	|
 	(	funcName = id()
 		{ 
 			funcName = validateFunctionName(funcName);
@@ -2989,14 +3036,48 @@
 			funcName = funcToken.image;
 		}
 			
-		Expression[] expressions = new Expression[args.size()];
-		for(int i=0; i<args.size(); i++) {
-			expressions[i] = (Expression) args.get(i);
-		}	
-		return new Function(funcName, expressions);
+		return new Function(funcName, (Expression[])args.toArray(new Expression[args.size()]));
 	}
 }	
 
+SQLXMLFunction sqlXmlFunction(ParseInfo info) :
+{
+	Expression expression = null;
+	ArrayList args = new ArrayList();
+	Token funcToken = null;
+}
+{
+ 	(funcToken = <XMLFOREST> | funcToken = <XMLATTRIBUTES>)
+	<LPAREN>
+	expression = selectExpression(info)
+	{
+		args.add(expression);
+		expression = null;
+	}
+	(<COMMA> expression=selectExpression(info)
+	 {
+		args.add(expression);
+		expression = null;
+	 }
+	)*
+	<RPAREN>  		
+	{
+		return new SQLXMLFunction(funcToken.image, args);
+	}
+}
+
+Constant idExpression() :
+{
+	String id = null;
+}
+{
+	id = id()
+	{
+		return new Constant(id);
+	}
+}
+
+
 /**
  * Parse a data type name - used only in conversion.
  * @return Data type parsed into a constant string object

Modified: trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties	2010-05-06 17:17:44 UTC (rev 2100)
@@ -279,6 +279,7 @@
 ERR.015.012.0025 = Command must project at least one symbol
 ERR.015.012.0026 = Expressions of type OBJECT, CLOB, BLOB, or XML cannot be used in SELECT DISTINCT, ORDER BY, GROUP BY, or non-all set queries: [{0}]
 ERR.015.012.0027 = Expressions of type OBJECT, CLOB, BLOB, or XML cannot be used in comparison: {0}.
+ValidationVisitor.expression_requires_name = Non-column expressions require a name in XMLATTRIBUTES or XMLFOREST
 ValidationVisitor.invalid_lookup_key=Expressions of type OBJECT, CLOB, BLOB, or XML cannot be used as LOOKUP key columns: {0}.
 ValidationVisitor.limit_not_valid_for_xml=The limit clause cannot be used on an XML document query.
 ValidationVisitor.translated_or=Translated user criteria must not contain OR criteria
@@ -775,6 +776,10 @@
 SystemSource.xmlelement_param1=Element name
 SystemSource.xmlelement_param2=Element contents
 SystemSource.xmlelement_result=XML result
+SystemSource.xmlconcat_description=Concat XML types. 
+SystemSource.xmlconcat_param1=First element
+SystemSource.xmlconcat_param2=Other elements
+SystemSource.xmlconcat_result=XML result
 SystemSource.modifyTimeZone_description=Modify the time zone of this timestamp by adding or subtracting time
 SystemSource.modifyTimeZone_param1=Timestamp
 SystemSource.modifyTimeZone_param2=Starting time zone

Modified: trunk/engine/src/test/java/com/metamatrix/cdk/CommandBuilder.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/cdk/CommandBuilder.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/cdk/CommandBuilder.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -29,10 +29,7 @@
 import org.teiid.connector.language.LanguageFactory;
 import org.teiid.dqp.internal.datamgr.language.LanguageBridgeFactory;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.api.exception.MetaMatrixException;
 import com.metamatrix.core.MetaMatrixRuntimeException;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.optimizer.relational.AliasGenerator;
@@ -77,15 +74,9 @@
                 command.acceptVisitor(new AliasGenerator(supportsGroupAlias));
             }
             return new LanguageBridgeFactory(metadata).translate(command);
-        } catch (QueryParserException e) {
+        } catch (MetaMatrixException e) {
             throw new MetaMatrixRuntimeException(e);
-        } catch (QueryResolverException e) {
-            throw new MetaMatrixRuntimeException(e);
-        } catch (MetaMatrixComponentException e) {
-            throw new MetaMatrixRuntimeException(e);
-        } catch (QueryValidatorException e) {
-            throw new MetaMatrixRuntimeException(e);
-        }
+		}
     }
     
     /**

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -27,6 +27,7 @@
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.sql.Date;
+import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.Arrays;
 import java.util.Collection;
@@ -45,7 +46,7 @@
 import com.metamatrix.common.buffer.BufferManagerFactory;
 import com.metamatrix.common.types.ClobType;
 import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.SQLXMLImpl;
+import com.metamatrix.common.types.NullType;
 import com.metamatrix.common.types.XMLType;
 import com.metamatrix.common.util.TimestampWithTimezone;
 import com.metamatrix.core.util.ObjectConverterUtil;
@@ -57,17 +58,17 @@
 public class TestFunctionLibrary {
 
 	// These are just used as shorthand convenience to make unit tests more readable below
-	private static final Class T_STRING = DataTypeManager.DefaultDataClasses.STRING;
-	private static final Class T_INTEGER = DataTypeManager.DefaultDataClasses.INTEGER;
-	private static final Class T_BIG_INTEGER = DataTypeManager.DefaultDataClasses.BIG_INTEGER;
-	private static final Class T_BIG_DECIMAL = DataTypeManager.DefaultDataClasses.BIG_DECIMAL;		
-    private static final Class T_LONG = DataTypeManager.DefaultDataClasses.LONG;
-	private static final Class T_FLOAT = DataTypeManager.DefaultDataClasses.FLOAT;
-    private static final Class T_DOUBLE = DataTypeManager.DefaultDataClasses.DOUBLE;
-	private static final Class T_NULL = DataTypeManager.DefaultDataClasses.NULL;
-	private static final Class T_TIME = DataTypeManager.DefaultDataClasses.TIME;
-	private static final Class T_DATE = DataTypeManager.DefaultDataClasses.DATE;
-	private static final Class T_TIMESTAMP = DataTypeManager.DefaultDataClasses.TIMESTAMP;
+	private static final Class<String> T_STRING = DataTypeManager.DefaultDataClasses.STRING;
+	private static final Class<Integer> T_INTEGER = DataTypeManager.DefaultDataClasses.INTEGER;
+	private static final Class<BigInteger> T_BIG_INTEGER = DataTypeManager.DefaultDataClasses.BIG_INTEGER;
+	private static final Class<BigDecimal> T_BIG_DECIMAL = DataTypeManager.DefaultDataClasses.BIG_DECIMAL;		
+    private static final Class<Long> T_LONG = DataTypeManager.DefaultDataClasses.LONG;
+	private static final Class<Float> T_FLOAT = DataTypeManager.DefaultDataClasses.FLOAT;
+    private static final Class<Double> T_DOUBLE = DataTypeManager.DefaultDataClasses.DOUBLE;
+	private static final Class<NullType> T_NULL = DataTypeManager.DefaultDataClasses.NULL;
+	private static final Class<Time> T_TIME = DataTypeManager.DefaultDataClasses.TIME;
+	private static final Class<Date> T_DATE = DataTypeManager.DefaultDataClasses.DATE;
+	private static final Class<Timestamp> T_TIMESTAMP = DataTypeManager.DefaultDataClasses.TIMESTAMP;
 	
 	private FunctionLibrary library = new FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new UDFSource(Collections.EMPTY_LIST)));
 
@@ -1333,8 +1334,8 @@
         CommandContext c = new CommandContext();
         c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
         ClobType result = (ClobType)helpInvokeMethod("xsltransform", new Class[] {DataTypeManager.DefaultDataClasses.XML, DataTypeManager.DefaultDataClasses.XML}, 
-        		new Object[] {new XMLType(new SQLXMLImpl("<?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>")), 
-        		new XMLType(new SQLXMLImpl("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>"))}, c);
+        		new Object[] {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), 
+        		DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", DataTypeManager.DefaultDataClasses.XML)}, c);
         
         String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
         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);
@@ -1344,10 +1345,39 @@
         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>", new XMLType(new SQLXMLImpl("<?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>"))}, c);
+        		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());
+        XMLType result = (XMLType)helpInvokeMethod("xmlconcat", new Class[] {DataTypeManager.DefaultDataClasses.XML, DataTypeManager.DefaultDataClasses.XML}, 
+        		new Object[] {DataTypeManager.transformValue("<bar/>", DataTypeManager.DefaultDataClasses.XML), 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("<bar/><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>", xml);
+    }
 }

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -62,7 +62,7 @@
 	 * @throws QueryResolverException 
 	 * @throws QueryParserException 
 	 */
-	public void testNonDeterministicPostJoin() throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+	public void testNonDeterministicPostJoin() throws Exception {
 		// source query for one side of a JOIN
 		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 " //$NON-NLS-1$
 				+ "FROM pm1.g1"; //$NON-NLS-1$
@@ -124,7 +124,7 @@
 	 * @throws QueryResolverException 
 	 * @throws QueryParserException 
 	 */
-	public void testNonDeterministicPreJoin() throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+	public void testNonDeterministicPreJoin() throws Exception {
 		// source query for one side of a JOIN
 		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, RAND() AS RandomLeft " //$NON-NLS-1$
 				+ "FROM pm1.g1"; //$NON-NLS-1$
@@ -181,7 +181,7 @@
 	 * @see #testNonDeterministicPostJoin
 	 * @see #testNonDeterministicPreJoin
 	 */
-	public void testNonDeterministicPrePostJoin() throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+	public void testNonDeterministicPrePostJoin() throws Exception {
 		// source query for one side of a JOIN
 		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, RAND() AS RandomLeft " //$NON-NLS-1$
 				+ "FROM pm1.g1"; //$NON-NLS-1$
@@ -237,7 +237,7 @@
 	 * @throws QueryResolverException 
 	 * @throws QueryParserException 
 	 */
-	public void testDeterministicPostJoin() throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+	public void testDeterministicPostJoin()  throws Exception {
 		// source query for one side of a JOIN
 		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 " //$NON-NLS-1$
 				+ "FROM pm1.g1"; //$NON-NLS-1$
@@ -308,7 +308,7 @@
 	 * @throws QueryResolverException 
 	 * @throws QueryParserException 
 	 */
-	public void testDeterministicPreJoin() throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+	public void testDeterministicPreJoin() throws Exception {
 		// source query for one side of a JOIN
 		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, SQRT(100) AS SqrtLeft " //$NON-NLS-1$
 				+ "FROM pm1.g1"; //$NON-NLS-1$
@@ -375,7 +375,7 @@
 	 * @see #testDeterministicPostJoin
 	 * @see #testDeterministicPreJoin
 	 */
-	public void testDeterministicPrePostJoin() throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+	public void testDeterministicPrePostJoin() throws Exception {
 		// sub-query for one side of a JOIN
 		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, SQRT(100) AS SqrtLeft " //$NON-NLS-1$
 				+ "FROM pm1.g1"; //$NON-NLS-1$

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -36,10 +36,8 @@
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.query.QueryParserException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.types.DataTypeManager;
 import com.metamatrix.core.MetaMatrixRuntimeException;
@@ -170,11 +168,11 @@
 	public static ProcessorPlan helpPlan(String sql,
 			QueryMetadataInterface md, String[] expected,
 			CapabilitiesFinder capFinder,
-			ComparisonMode mode) throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+			ComparisonMode mode) throws MetaMatrixComponentException, MetaMatrixProcessingException {
 		return helpPlan(sql, md, null, capFinder, expected, mode);
 	}    
 	
-	public static ProcessorPlan helpPlan(String sql, QueryMetadataInterface md, String[] expectedAtomic, ComparisonMode mode) throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+	public static ProcessorPlan helpPlan(String sql, QueryMetadataInterface md, String[] expectedAtomic, ComparisonMode mode) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         return helpPlan(sql, md, null, getGenericFinder(), expectedAtomic, mode);
     }
 	
@@ -189,14 +187,14 @@
         return helpPlanCommand(command, md, capFinder, null, expectedAtomic, shouldSucceed ? ComparisonMode.CORRECTED_COMMAND_STRING : ComparisonMode.FAILED_PLANNING);
     } 
     
-    public static ProcessorPlan helpPlan(String sql, QueryMetadataInterface md, List bindings, CapabilitiesFinder capFinder, String[] expectedAtomic, ComparisonMode mode) throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
+    public static ProcessorPlan helpPlan(String sql, QueryMetadataInterface md, List bindings, CapabilitiesFinder capFinder, String[] expectedAtomic, ComparisonMode mode) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         Command command = helpGetCommand(sql, md, bindings);
 
         return helpPlanCommand(command, md, capFinder, null, expectedAtomic, mode);
     } 
 
     
-    public static Command helpGetCommand(String sql, QueryMetadataInterface md, List bindings) throws QueryParserException, QueryResolverException, MetaMatrixComponentException, QueryValidatorException { 
+    public static Command helpGetCommand(String sql, QueryMetadataInterface md, List bindings) throws MetaMatrixComponentException, MetaMatrixProcessingException { 
 		if(DEBUG) System.out.println("\n####################################\n" + sql);	 //$NON-NLS-1$
 		Command command = QueryParser.getQueryParser().parseCommand(sql);
 		

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/batch/TestBatchedUpdatePlanner.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/batch/TestBatchedUpdatePlanner.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/batch/TestBatchedUpdatePlanner.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -29,11 +29,9 @@
 import junit.framework.TestCase;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.query.analysis.AnalysisRecord;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.optimizer.QueryOptimizer;
@@ -67,7 +65,7 @@
         super(name);
     }
     
-    public static List<Command> helpGetCommands(String[] sql, QueryMetadataInterface md) throws QueryParserException, QueryResolverException, MetaMatrixComponentException, QueryValidatorException  { 
+    public static List<Command> helpGetCommands(String[] sql, QueryMetadataInterface md) throws MetaMatrixComponentException, MetaMatrixProcessingException  { 
         if(DEBUG) System.out.println("\n####################################\n" + sql);  //$NON-NLS-1$
         List<Command> commands = new ArrayList<Command>(sql.length);
         for (int i = 0; i < sql.length; i++) {
@@ -86,7 +84,7 @@
         return commands;
     }
     
-    private BatchedUpdateCommand helpGetCommand(String[] sql, QueryMetadataInterface md) throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException { 
+    private BatchedUpdateCommand helpGetCommand(String[] sql, QueryMetadataInterface md) throws MetaMatrixComponentException, MetaMatrixProcessingException { 
         BatchedUpdateCommand command = new BatchedUpdateCommand(helpGetCommands(sql, md));
         return command;
     }
@@ -130,11 +128,11 @@
         return new DefaultCapabilitiesFinder(new FakeCapabilities(true));
     }
 
-    private BatchedUpdatePlan helpPlan(String[] sql, QueryMetadataInterface md) throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException, QueryPlannerException, QueryMetadataException {
+    private BatchedUpdatePlan helpPlan(String[] sql, QueryMetadataInterface md) throws MetaMatrixComponentException, QueryMetadataException, MetaMatrixProcessingException {
         return helpPlan(sql, md, getGenericFinder(), true);
     }
     
-    private BatchedUpdatePlan helpPlan(String[] sql, QueryMetadataInterface md, CapabilitiesFinder capFinder, boolean shouldSucceed) throws QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException, QueryPlannerException, QueryMetadataException {
+    private BatchedUpdatePlan helpPlan(String[] sql, QueryMetadataInterface md, CapabilitiesFinder capFinder, boolean shouldSucceed) throws MetaMatrixComponentException, QueryMetadataException, MetaMatrixProcessingException {
         Command command = helpGetCommand(sql, md);
 
         if (capFinder == null){
@@ -156,7 +154,7 @@
         }
     }
     
-    private void helpTestPlanner(String[] sql, boolean[] expectedBatching) throws QueryParserException, QueryResolverException, QueryValidatorException, QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
+    private void helpTestPlanner(String[] sql, boolean[] expectedBatching) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
         BatchedUpdatePlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached());
         List plans = plan.getUpdatePlans();
         assertEquals("Number of child plans did not match expected", expectedBatching.length, plans.size()); //$NON-NLS-1$
@@ -165,7 +163,7 @@
         }
     }    
     
-    private void helpTestPlanner(String[] sql, boolean[] expectedBatching, CapabilitiesFinder capFinder) throws QueryParserException, QueryResolverException, QueryValidatorException, QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
+    private void helpTestPlanner(String[] sql, boolean[] expectedBatching, CapabilitiesFinder capFinder) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
         BatchedUpdatePlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), capFinder, true);
         List plans = plan.getUpdatePlans();
         assertEquals("Number of child plans did not match expected", expectedBatching.length, plans.size()); //$NON-NLS-1$

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -25,10 +25,8 @@
 import junit.framework.TestCase;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
 import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.query.analysis.AnalysisRecord;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
@@ -57,18 +55,14 @@
 
 	// ################ getReplacementClause tests ################### 
 
-    private ProcessorPlan helpPlanProcedure(String procedure, String procedureType) throws QueryParserException, QueryResolverException, QueryValidatorException, QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
+    private ProcessorPlan helpPlanProcedure(String procedure, String procedureType) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
         return helpPlanProcedure(null, procedure, procedureType);
     }
     
 	private ProcessorPlan helpPlanProcedure(String userQuery,
                                             String procedure,
-                                            String procedureType) throws QueryParserException,
-                                                                 QueryResolverException,
-                                                                 MetaMatrixComponentException,
-                                                                 QueryValidatorException,
-                                                                 QueryPlannerException,
-                                                                 QueryMetadataException {
+                                            String procedureType) throws MetaMatrixComponentException,
+                                                                 QueryMetadataException, MetaMatrixProcessingException {
         QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
 
         QueryParser parser = QueryParser.getQueryParser();

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -26,7 +26,8 @@
 
 import org.junit.Test;
 
-import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.parser.QueryParser;
 import com.metamatrix.query.resolver.TestResolver;
@@ -43,7 +44,7 @@
     private Command helpTest(String sql,
                           String expected, 
                           boolean aliasGroups,
-                          QueryMetadataInterface metadata) throws QueryValidatorException {
+                          QueryMetadataInterface metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         Command command = TestResolver.helpResolve(sql, metadata, null);
         command = QueryRewriter.rewrite(command, metadata, null);
         command.acceptVisitor(new AliasGenerator(aliasGroups));

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -27,10 +27,8 @@
 import org.junit.Test;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.optimizer.TestOptimizer;
 import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
@@ -55,7 +53,7 @@
     // HELPERS
     // =====================================================================
     
-    private static Criteria helpGetCriteria(String critString, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, QueryMetadataException, MetaMatrixComponentException, QueryValidatorException{
+    private static Criteria helpGetCriteria(String critString, QueryMetadataInterface metadata) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException{
 
         Criteria result = QueryParser.getQueryParser().parseCriteria(critString);
         QueryResolver.resolveCriteria(result, metadata);

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -28,11 +28,9 @@
 import junit.framework.TestCase;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.common.types.DataTypeManager;
 import com.metamatrix.core.id.IDGenerator;
 import com.metamatrix.core.id.IntegerIDFactory;
@@ -80,7 +78,7 @@
         return preparePlan(command, md, TestOptimizer.getGenericFinder(), null);
     }
 
-    private void helpPlanException(String sql, QueryMetadataInterface md) throws QueryMetadataException, MetaMatrixComponentException, QueryParserException, QueryResolverException, QueryValidatorException {
+    private void helpPlanException(String sql, QueryMetadataInterface md) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
         Command command = TestXMLProcessor.helpGetCommand(sql, md);
 
         try {

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -103,9 +103,12 @@
 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.SingleElementSymbol;
 import com.metamatrix.query.sql.symbol.TestCaseExpression;
 import com.metamatrix.query.sql.symbol.TestSearchedCaseExpression;
+import com.metamatrix.query.sql.symbol.SQLXMLFunction;
 
+ at SuppressWarnings("nls")
 public class TestParser {
 
     static void helpTest(String sql, String expectedString, Command expectedCommand) {
@@ -124,7 +127,15 @@
 		assertEquals("Parse string does not match: ", expectedString, actualString); //$NON-NLS-1$
 		assertEquals("Command objects do not match: ", expectedCommand, actualCommand);				 //$NON-NLS-1$
 	}
-    
+
+	static void helpTestExpression(String sql, String expectedString, Expression expected) throws QueryParserException {
+		Expression	actual = QueryParser.getQueryParser().parseExpression(sql);
+		String actualString = actual.toString();
+
+		assertEquals("Parse string does not match: ", expectedString, actualString); //$NON-NLS-1$
+		assertEquals("Command objects do not match: ", expected, actual);				 //$NON-NLS-1$
+	}
+
     static void helpException(String sql) {
         helpException(sql, null);
     }
@@ -6706,5 +6717,25 @@
         create.setColumns(columns);
         helpTest("Create local TEMPORARY table tempTable (c1 varchar, c2 tinyint, c3 smallint, c4 real, c5 decimal)", "CREATE LOCAL TEMPORARY TABLE tempTable (c1 string, c2 byte, c3 short, c4 float, c5 bigdecimal)", create); //$NON-NLS-1$ 
     }
+    
+    @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);
+    }
 
+    @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);
+    }
+    
+    @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);
+    }
+    
+    @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);
+    }
+
 }

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -25,10 +25,10 @@
 import java.util.Arrays;
 import java.util.List;
 
+import junit.framework.TestCase;
+
 import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.query.optimizer.TestOptimizer;
 import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
 import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
@@ -41,9 +41,7 @@
 import com.metamatrix.query.unittest.FakeMetadataFactory;
 import com.metamatrix.query.unittest.FakeMetadataObject;
 
-import junit.framework.TestCase;
 
-
 public class TestDependentJoins extends TestCase {
     
     /** 
@@ -512,8 +510,7 @@
     }
 
 	private HardcodedDataManager helpTestDependentJoin(boolean unlimitIn)
-			throws QueryParserException, QueryResolverException,
-			QueryValidatorException, MetaMatrixComponentException {
+			throws MetaMatrixComponentException, MetaMatrixProcessingException {
 		FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
         BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
         caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -7487,12 +7487,12 @@
         String sql = "SELECT xmlelement(e1, e2) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
         
         List[] expected = new List[] {
-        		Arrays.asList(new String[] {null}),
-        		Arrays.asList("<a>0</a>"),
-        		Arrays.asList("<a>0</a>"),
-        		Arrays.asList("<a>3</a>"),
-        		Arrays.asList("<b>2</b>"),
-                Arrays.asList("<c>1</c>"),
+        		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();
@@ -7503,5 +7503,57 @@
         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);
+    }
+    
     private static final boolean DEBUG = false;
 }

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestInstructions.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestInstructions.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestInstructions.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -29,9 +29,9 @@
 import junit.framework.TestCase;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryParserException;
 import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.buffer.BufferManagerFactory;
 import com.metamatrix.common.types.DataTypeManager;
@@ -112,7 +112,7 @@
         return new FakeMetadataFacade(store);
     }
     
-    private Command helpGetCommand(String sql, FakeMetadataFacade metadata) throws QueryParserException, QueryResolverException, MetaMatrixComponentException, QueryValidatorException {
+    private Command helpGetCommand(String sql, FakeMetadataFacade metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         // parse
         QueryParser parser = new QueryParser();
         Command command = parser.parseCommand(sql);

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -39,10 +39,7 @@
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.QueryParserException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.buffer.BufferManagerFactory;
 import com.metamatrix.common.buffer.TupleBuffer;
@@ -84,7 +81,6 @@
 import com.metamatrix.query.unittest.FakeMetadataObject;
 import com.metamatrix.query.unittest.FakeMetadataStore;
 import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.util.XMLFormatConstants;
 
 /**
  * Tests XML processing, which involves XMLPlanner making a ProcessorPlan
@@ -2927,7 +2923,7 @@
         return dataMgr;
     }                    
 
-    public static Command helpGetCommand(String sql, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, MetaMatrixComponentException, QueryValidatorException { 
+    public static Command helpGetCommand(String sql, QueryMetadataInterface metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException { 
         QueryParser parser = new QueryParser();
         Command command = parser.parseCommand(sql);
         QueryResolver.resolveCommand(command, metadata);

Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -32,9 +32,7 @@
 import org.junit.Test;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.query.parser.QueryParser;
 import com.metamatrix.query.resolver.QueryResolver;
 import com.metamatrix.query.sql.LanguageObject;
@@ -53,7 +51,7 @@
  */
 public class TestOrderByRewrite  {
     
-    private static Command getCommand(String sql) throws QueryParserException, QueryResolverException, MetaMatrixComponentException, QueryValidatorException {
+    private static Command getCommand(String sql) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         Command command = QueryParser.getQueryParser().parseCommand(sql);
         
         QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());

Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -37,16 +37,18 @@
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.api.exception.query.ExpressionEvaluationException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
 import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.common.buffer.BufferManagerFactory;
 import com.metamatrix.common.types.DataTypeManager;
 import com.metamatrix.common.util.TimestampWithTimezone;
 import com.metamatrix.core.MetaMatrixRuntimeException;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.parser.QueryParser;
 import com.metamatrix.query.resolver.QueryResolver;
+import com.metamatrix.query.resolver.util.ResolverVisitor;
 import com.metamatrix.query.sql.lang.Command;
 import com.metamatrix.query.sql.lang.CompareCriteria;
 import com.metamatrix.query.sql.lang.CompoundCriteria;
@@ -62,6 +64,7 @@
 import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
 import com.metamatrix.query.sql.symbol.Constant;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.ExpressionSymbol;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
 import com.metamatrix.query.sql.symbol.Reference;
@@ -73,7 +76,8 @@
 import com.metamatrix.query.unittest.FakeMetadataObject;
 import com.metamatrix.query.util.CommandContext;
 import com.metamatrix.query.util.ContextProperties;
-
+
+ at SuppressWarnings("nls")
 public class TestQueryRewriter {
 
     private static final String TRUE_STR = "1 = 1"; //$NON-NLS-1$
@@ -102,7 +106,7 @@
         } 
     }   
     
-    private Criteria helpTestRewriteCriteria(String original, String expected, boolean rewrite) throws QueryResolverException, QueryMetadataException, MetaMatrixComponentException, QueryValidatorException {
+    private Criteria helpTestRewriteCriteria(String original, String expected, boolean rewrite) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached(); 
         Criteria expectedCrit = parseCriteria(expected, metadata);
         if (rewrite) {
@@ -120,22 +124,35 @@
         try { 
             actual = QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
             assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
-        } catch(QueryValidatorException e) { 
+        } catch(MetaMatrixException e) { 
         	throw new RuntimeException(e);
         }
         return actual;
-    }    
+    }  
+    
+    private Expression helpTestRewriteExpression(String original, String expected, QueryMetadataInterface metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    	Expression actualExp = QueryParser.getQueryParser().parseExpression(original);
+    	ResolverVisitor.resolveLanguageObject(actualExp, metadata);
+    	CommandContext context = new CommandContext();
+    	context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+    	actualExp = QueryRewriter.rewriteExpression(actualExp, null, context, metadata);
+    	if (expected != null) {
+	    	Expression expectedExp = QueryParser.getQueryParser().parseExpression(expected);
+	    	ResolverVisitor.resolveLanguageObject(expectedExp, metadata);
+	    	assertEquals(expectedExp, actualExp);
+    	}
+    	return actualExp;
+    }
     
-	private String getRewritenProcedure(String procedure, String userUpdateStr, String procedureType) throws QueryParserException, QueryResolverException, MetaMatrixComponentException, QueryValidatorException {
+	private String getRewritenProcedure(String procedure, String userUpdateStr, String procedureType) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
 
         return getRewritenProcedure(userUpdateStr, metadata);
 	}
 
 	private String getRewritenProcedure(String userUpdateStr,
-			QueryMetadataInterface metadata) throws QueryParserException,
-			QueryResolverException, MetaMatrixComponentException,
-			QueryMetadataException, QueryValidatorException {
+			QueryMetadataInterface metadata) throws MetaMatrixComponentException,
+			QueryMetadataException, MetaMatrixProcessingException {
 		ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr); 
         QueryResolver.resolveCommand(userCommand, metadata);
         CreateUpdateProcedureCommand proc = (CreateUpdateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, null);
@@ -399,7 +416,7 @@
         try { 
             QueryRewriter.rewriteCriteria(origCrit, null, null, null);
             fail("Expected failure"); //$NON-NLS-1$
-        } catch(QueryValidatorException e) { 
+        } catch(MetaMatrixException e) { 
             assertEquals("Error Code:ERR.015.001.0003 Message:Error simplifying criteria: PARSEDATE(pm3.g1.e1, '''') = {d'2003-05-01'}", e.getMessage());     //$NON-NLS-1$
         }
     }
@@ -1250,7 +1267,7 @@
 	// elements being set in updates are dropped if INPUT var is not available, unless a default is supplied
     
     //this test fails because the default for E1 'xyz' cannot be converted into a integer
-    @Test(expected=QueryValidatorException.class) public void testRewriteProcedure21() throws Exception {
+    @Test(expected=ExpressionEvaluationException.class) public void testRewriteProcedure21() throws Exception {
         String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
         procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
         procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
@@ -1515,9 +1532,9 @@
         try { 
             QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
             fail("Expected QueryValidatorException due to divide by 0"); //$NON-NLS-1$
-        } catch(QueryValidatorException e) {
+        } catch(MetaMatrixException e) {
         	// looks like message is being wrapped with another exception with same message
-            assertEquals("Error Code:ERR.015.001.0003 Message:Error Code:ERR.015.001.0003 Message:Unable to evaluate (5 / 0): Error Code:ERR.015.001.0003 Message:Error while evaluating function /", e.getMessage());  //$NON-NLS-1$
+            assertEquals("Error Code:ERR.015.001.0003 Message:Unable to evaluate (5 / 0): Error Code:ERR.015.001.0003 Message:Error while evaluating function /", e.getMessage());  //$NON-NLS-1$
         }       
     }
     
@@ -1529,8 +1546,8 @@
         try { 
             QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
             fail("Expected QueryValidatorException due to invalid string"); //$NON-NLS-1$
-        } catch(QueryValidatorException e) {
-            assertEquals("Error Code:ERR.015.009.0004 Message:Unable to convert 'x' of type [string] to the expected type [integer].", e.getMessage()); //$NON-NLS-1$
+        } catch(MetaMatrixException e) {
+            assertEquals("Error Code:ERR.015.001.0003 Message:Unable to evaluate convert('x', integer): Error Code:ERR.015.001.0003 Message:Error while evaluating function convert", e.getMessage()); //$NON-NLS-1$
         }       
     }
     
@@ -1953,7 +1970,7 @@
                                             new Class[] { DataTypeManager.DefaultDataClasses.STRING});
     }
 
-    private void verifyProjectedTypesOnUnionBranches(String unionQuery, Class<?>[] types) throws QueryValidatorException, QueryParserException, QueryResolverException, MetaMatrixComponentException {
+    private void verifyProjectedTypesOnUnionBranches(String unionQuery, Class<?>[] types) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         SetQuery union = (SetQuery)QueryParser.getQueryParser().parseCommand(unionQuery);
         QueryResolver.resolveCommand(union, FakeMetadataFactory.example1Cached());
         
@@ -2248,4 +2265,11 @@
     	QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
     	helpTestRewriteCriteria(original, parseCriteria("convert(timestampadd(SQL_TSI_SECOND, 1, convert(BQT1.SmallA.timevalue, timestamp)), time) = {t'08:02:00'}", metadata), metadata); //$NON-NLS-1$
     }
+    
+    @Test public void testRewriteXmlElement() throws Exception {
+    	String original = "convert(xmlelement(name a, xmlattributes('b' as c)), string)"; //$NON-NLS-1$
+    	QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+    	helpTestRewriteExpression(original, "'<a c=\"b\"></a>'", metadata);
+    }
+    
 }

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-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -1957,5 +1957,9 @@
 	@Test public void testValidateCompareInHaving1() {        
         helpValidate("SELECT e1 FROM test.group GROUP BY e1 HAVING convert(e1, clob) = 'a'", new String[] {"convert(e1, clob) = 'a'"}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
 	}
+	
+	@Test public void testValidateNoExpressionName() {        
+        helpValidate("SELECT xmlelement(name a, xmlattributes('1'))", new String[] {"'1'"}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
+	}
 
 }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -37,6 +37,7 @@
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryParserException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
 import com.metamatrix.api.exception.query.QueryResolverException;
@@ -206,17 +207,13 @@
     }
     
 	static public PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values, SessionAwareCache<PreparedPlan> prepPlanCache)
-			throws MetaMatrixComponentException, QueryParserException,
-			QueryResolverException, QueryValidatorException,
-			QueryPlannerException {    	
+			throws MetaMatrixComponentException, MetaMatrixProcessingException {    	
 		return helpGetProcessorPlan(preparedSql, values, new DefaultCapabilitiesFinder(), FakeMetadataFactory.example1Cached(), prepPlanCache, SESSION_ID, false, false, FakeMetadataFactory.example1VDB());
     }
 	
 	static public PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values,
 			SessionAwareCache<PreparedPlan> prepPlanCache, int conn)
-			throws MetaMatrixComponentException, QueryParserException,
-			QueryResolverException, QueryValidatorException,
-			QueryPlannerException {
+			throws MetaMatrixComponentException, MetaMatrixProcessingException {
 		return helpGetProcessorPlan(preparedSql, values,
 				new DefaultCapabilitiesFinder(), FakeMetadataFactory
 						.example1Cached(), prepPlanCache, conn, false, false, FakeMetadataFactory.example1VDB());
@@ -224,9 +221,7 @@
 
 	static PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values,
 			CapabilitiesFinder capFinder, QueryMetadataInterface metadata, SessionAwareCache<PreparedPlan> prepPlanCache, int conn, boolean callableStatement, boolean limitResults, VDBMetaData vdb)
-			throws MetaMatrixComponentException, QueryParserException,
-			QueryResolverException, QueryValidatorException,
-			QueryPlannerException {
+			throws MetaMatrixComponentException, MetaMatrixProcessingException {
         
         //Create Request
         RequestMessage request = new RequestMessage(preparedSql);

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java	2010-05-05 17:03:24 UTC (rev 2099)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java	2010-05-06 17:17:44 UTC (rev 2100)
@@ -34,10 +34,7 @@
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.dqp.service.AutoGenDataService;
 import com.metamatrix.query.analysis.AnalysisRecord;
@@ -128,11 +125,8 @@
         assertEquals("1", request.context.getEnvironmentProperties().get(ContextProperties.SESSION_ID)); //$NON-NLS-1$
     }
 
-    private Request helpProcessMessage(RequestMessage message, SessionAwareCache<PreparedPlan> cache, DQPWorkContext workContext) throws QueryValidatorException,
-                                                           QueryParserException,
-                                                           QueryResolverException,
-                                                           MetaMatrixComponentException,
-                                                           QueryPlannerException {
+    private Request helpProcessMessage(RequestMessage message, SessionAwareCache<PreparedPlan> cache, DQPWorkContext workContext) throws MetaMatrixComponentException,
+                                                           MetaMatrixProcessingException {
         Request request = null;
         if (cache != null) {
         	request = new PreparedStatementRequest(cache);



More information about the teiid-commits mailing list