[teiid-commits] teiid SVN: r2956 - in trunk/engine/src: main/java/org/teiid/query/resolver/util and 3 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Mar 2 11:26:10 EST 2011


Author: shawkins
Date: 2011-03-02 11:26:09 -0500 (Wed, 02 Mar 2011)
New Revision: 2956

Removed:
   trunk/engine/src/main/java/org/teiid/query/sql/util/ElementSymbolOptimizer.java
Modified:
   trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
   trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
   trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
   trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
   trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java
Log:
TEIID-1483 consolidating resolving code with designer by refining the symbol optimization logic

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java	2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java	2011-03-02 16:26:09 UTC (rev 2956)
@@ -29,11 +29,14 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+
 import org.teiid.api.exception.query.QueryMetadataException;
 import org.teiid.api.exception.query.QueryParserException;
 import org.teiid.api.exception.query.QueryResolverException;
 import org.teiid.api.exception.query.QueryValidatorException;
 import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.Assertion;
 import org.teiid.dqp.internal.process.Request;
 import org.teiid.logging.LogManager;
 import org.teiid.query.QueryPlugin;
@@ -445,6 +448,18 @@
             	QueryResolver.resolveCommand(result, qmi, false);
             }
 	        Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
+            
+	        //ensure that null types match the view
+	        List<ElementSymbol> symbols = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
+            List<SingleElementSymbol> projectedSymbols = result.getProjectedSymbols();
+            Assertion.assertTrue(symbols.size() == projectedSymbols.size(), "View " + virtualGroup + " does not have the correct number of projected symbols"); //$NON-NLS-1$ //$NON-NLS-2$
+            for (int i = 0; i < projectedSymbols.size(); i++) {
+            	SingleElementSymbol projectedSymbol = projectedSymbols.get(i);
+            	if (projectedSymbol.getType() != DataTypeManager.DefaultDataClasses.NULL) {
+            		continue;
+            	}
+            	ResolverUtil.setSymbolType(projectedSymbol, symbols.get(i).getType());
+            }
 	        qmi.addToMetadataCache(virtualGroup.getMetadataID(), "transformation/" + cacheString, result.clone()); //$NON-NLS-1$
         }
 		return result;

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java	2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java	2011-03-02 16:26:09 UTC (rev 2956)
@@ -56,6 +56,7 @@
 import org.teiid.query.optimizer.relational.rules.RuleChooseJoinStrategy;
 import org.teiid.query.optimizer.relational.rules.RuleRaiseAccess;
 import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.Command;
 import org.teiid.query.sql.lang.CompareCriteria;
 import org.teiid.query.sql.lang.Criteria;
 import org.teiid.query.sql.lang.FromClause;
@@ -637,38 +638,41 @@
             if(!DataTypeManager.DefaultDataClasses.NULL.equals(symbol.getType()) && symbol.getType() != null) {
                 continue;
             }
-            if(symbol instanceof AliasSymbol) {
-                symbol = ((AliasSymbol)symbol).getSymbol();
-            }
                         
-            Class replacement = DataTypeManager.DefaultDataClasses.STRING;
-            
-            if(symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
-                ExpressionSymbol exprSymbol = (ExpressionSymbol) symbol;
-                Expression expr = exprSymbol.getExpression();
-               	
-                if(expr instanceof Constant) {                	
-                    exprSymbol.setExpression(new Constant(null, replacement));
-                } else if (expr instanceof AbstractCaseExpression) {
-                    ((AbstractCaseExpression)expr).setType(replacement);
-                } else if (expr instanceof ScalarSubquery) {
-                    ((ScalarSubquery)expr).setType(replacement);                                        
-                } else {
-                	try {
-						ResolverUtil.setDesiredType(expr, replacement, symbol);
-					} catch (QueryResolverException e) {
-						//cannot happen
-					}
-                }
-            } else if(symbol instanceof ElementSymbol) {
-                ElementSymbol elementSymbol = (ElementSymbol)symbol;
-                Class elementType = elementSymbol.getType();
-                if(elementType != null && elementType.equals(DataTypeManager.DefaultDataClasses.NULL)) {
-                    elementSymbol.setType(replacement);
-                }
-            }
+            setSymbolType(symbol, DataTypeManager.DefaultDataClasses.STRING);
         }
     }
+
+	public static void setSymbolType(SingleElementSymbol symbol,
+			Class<?> replacement) {
+		if(symbol instanceof AliasSymbol) {
+            symbol = ((AliasSymbol)symbol).getSymbol();
+        }
+		if(symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
+		    ExpressionSymbol exprSymbol = (ExpressionSymbol) symbol;
+		    Expression expr = exprSymbol.getExpression();
+		   	
+		    if(expr instanceof Constant) {                	
+		        exprSymbol.setExpression(new Constant(null, replacement));
+		    } else if (expr instanceof AbstractCaseExpression) {
+		        ((AbstractCaseExpression)expr).setType(replacement);
+		    } else if (expr instanceof ScalarSubquery) {
+		        ((ScalarSubquery)expr).setType(replacement);                                        
+		    } else {
+		    	try {
+					ResolverUtil.setDesiredType(expr, replacement, symbol);
+				} catch (QueryResolverException e) {
+					//cannot happen
+				}
+		    }
+		} else if(symbol instanceof ElementSymbol) {
+		    ElementSymbol elementSymbol = (ElementSymbol)symbol;
+		    Class elementType = elementSymbol.getType();
+		    if(elementType != null && elementType.equals(DataTypeManager.DefaultDataClasses.NULL)) {
+		        elementSymbol.setType(replacement);
+		    }
+		}
+	}
     
     /**
      *  
@@ -723,7 +727,7 @@
     }
 
     
-    private static boolean nameMatchesGroup(String groupContext,
+    public static boolean nameMatchesGroup(String groupContext,
                                             String fullName) {
         //if there is a name match, make sure that it is the full name or a proper qualifier
         if (fullName.endsWith(groupContext)) {
@@ -1091,5 +1095,16 @@
 		}
 		return result;
 	}
+
+	/**
+	 * This method will convert all elements in a command to their fully qualified name.
+	 * @param command Command to convert
+	 */
+	public static void fullyQualifyElements(Command command) {
+	    Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(command, false, true);
+	    for (ElementSymbol element : elements) {
+	        element.setDisplayFullyQualified(true);
+	    }
+	}
     
 }

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java	2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java	2011-03-02 16:26:09 UTC (rev 2956)
@@ -70,6 +70,7 @@
 import org.teiid.query.sql.symbol.SearchedCaseExpression;
 import org.teiid.query.sql.symbol.XMLQuery;
 import org.teiid.query.sql.symbol.XMLSerialize;
+import org.teiid.query.sql.symbol.ElementSymbol.DisplayMode;
 
 
 public class ResolverVisitor extends LanguageVisitor {
@@ -84,12 +85,23 @@
 		}
     }
     
+    private static ThreadLocal<Boolean> determinePartialName = new ThreadLocal<Boolean>() {
+    	protected Boolean initialValue() {
+    		return false;
+    	}
+    };
+    
+    public static void setFindShortName(boolean enabled) {
+    	determinePartialName.set(enabled);
+    }
+    
     private Collection<GroupSymbol> groups;
     private GroupContext externalContext;
     protected QueryMetadataInterface metadata;
     private TeiidComponentException componentException;
     private QueryResolverException resolverException;
     private Map<Function, QueryResolverException> unresolvedFunctions;
+    private boolean findShortName;
     
     /**
      * Constructor for ResolveElementsVisitor.
@@ -100,6 +112,7 @@
         this.groups = internalGroups;
         this.externalContext = externalContext;
         this.metadata = metadata;
+        this.findShortName = determinePartialName.get();
     }
 
 	public void setGroups(Collection<GroupSymbol> groups) {
@@ -110,21 +123,23 @@
         try {
             resolveElementSymbol(obj);
         } catch(QueryMetadataException e) {
-            handleUnresolvedElement(obj, e.getMessage());
+            handleException(handleUnresolvedElement(obj, e.getMessage()));
         } catch(TeiidComponentException e) {
             handleException(e);
-        } 
+        } catch (QueryResolverException e) {
+			handleException(e);
+		} 
     }
 
-    private void handleUnresolvedElement(ElementSymbol symbol, String description) {
+    private QueryResolverException handleUnresolvedElement(ElementSymbol symbol, String description) {
     	UnresolvedSymbolDescription usd = new UnresolvedSymbolDescription(symbol.toString(), description);
         QueryResolverException e = new QueryResolverException(usd.getDescription());
         e.setUnresolvedSymbols(Arrays.asList(usd));
-        handleException(e);
+        return e;
     }
 
     private void resolveElementSymbol(ElementSymbol elementSymbol)
-        throws QueryMetadataException, TeiidComponentException {
+        throws TeiidComponentException, QueryResolverException {
 
         // already resolved
         if(elementSymbol.getMetadataID() != null) {
@@ -139,9 +154,25 @@
         String elementShortName = metadata.getShortElementName(potentialID);
         if (groupContext != null) {
             groupContext = groupContext.toUpperCase();
+        	try {
+				if (findShortName && internalResolveElementSymbol(elementSymbol, null, elementShortName, groupContext)) {
+		    		elementSymbol.setDisplayMode(DisplayMode.SHORT_OUTPUT_NAME);
+		    		return;
+				}
+			} catch (QueryResolverException e) {
+				//ignore
+			} catch (QueryMetadataException e) {
+				//ignore
+			}
         }
         
-        boolean isExternal = false;
+        internalResolveElementSymbol(elementSymbol, groupContext, elementShortName, null);
+   }
+
+	private boolean internalResolveElementSymbol(ElementSymbol elementSymbol,
+			String groupContext, String elementShortName, String expectedGroupContext)
+			throws TeiidComponentException, QueryResolverException {
+		boolean isExternal = false;
         boolean groupMatched = false;
         
         GroupContext root = null;
@@ -183,14 +214,16 @@
                 resolveAgainstGroups(shortCanonicalName, matchedGroups, matches);
                 
                 if (matches.size() > 1) {
-                	if (isExternal && matches.size() == 2 
-                			&& ((isScalar(matches.get(0).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(1).element, ProcedureReservedWords.INPUT))
-                					|| (isScalar(matches.get(1).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(0).element, ProcedureReservedWords.INPUT)))) {
-                		matches.remove();
-                	} else {
-                	    handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0053", elementSymbol)); //$NON-NLS-1$
-                	    return;
+                	if (isExternal && matches.size() == 2) {
+            			if ((isScalar(matches.get(0).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(1).element, ProcedureReservedWords.INPUT))) {
+            				matches.removeLast();
+            				break;
+            			} else if (isScalar(matches.get(1).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(0).element, ProcedureReservedWords.INPUT)) {
+            				matches.removeFirst();
+            				break;
+            			}
                 	}
+            	    throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0053", elementSymbol)); //$NON-NLS-1$
                 }
                 
                 if (matches.size() == 1) {
@@ -204,11 +237,9 @@
         
         if (matches.isEmpty()) {
             if (groupMatched) {
-                handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0054", elementSymbol)); //$NON-NLS-1$
-            } else {
-                handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0051", elementSymbol)); //$NON-NLS-1$
+                throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0054", elementSymbol)); //$NON-NLS-1$
             }
-            return;
+            throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0051", elementSymbol)); //$NON-NLS-1$
         }
         ElementMatch match = matches.getFirst();
         
@@ -216,6 +247,9 @@
         ElementSymbol resolvedSymbol = match.element;
         GroupSymbol resolvedGroup = match.group;
         String oldName = elementSymbol.getOutputName();
+        if (expectedGroupContext != null && !ResolverUtil.nameMatchesGroup(expectedGroupContext, resolvedGroup.getCanonicalName())) {
+        	return false;
+        }
         if (isExternal //convert input to inputs
         		&& isScalar(resolvedSymbol, ProcedureReservedWords.INPUT)) {
         	resolvedSymbol = new ElementSymbol(ProcedureReservedWords.INPUTS + ElementSymbol.SEPARATOR + elementShortName);
@@ -234,7 +268,8 @@
         elementSymbol.setGroupSymbol(resolvedGroup);
         elementSymbol.setName(resolvedSymbol.getName());
         elementSymbol.setOutputName(oldName);
-   }
+        return true;
+	}
     
     private boolean isScalar(ElementSymbol resolvedSymbol, String group) throws QueryMetadataException, TeiidComponentException {
     	return metadata.isScalarGroup(resolvedSymbol.getGroupSymbol().getMetadataID())

Deleted: trunk/engine/src/main/java/org/teiid/query/sql/util/ElementSymbolOptimizer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/util/ElementSymbolOptimizer.java	2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/main/java/org/teiid/query/sql/util/ElementSymbolOptimizer.java	2011-03-02 16:26:09 UTC (rev 2956)
@@ -1,253 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.query.sql.util;
-
-import java.util.*;
-
-import org.teiid.api.exception.query.QueryMetadataException;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.query.metadata.*;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.visitor.CommandCollectorVisitor;
-import org.teiid.query.sql.visitor.ElementCollectorVisitor;
-import org.teiid.query.sql.visitor.GroupCollectorVisitor;
-
-
-/**
- * <p>The ElementSymbolOptimizer can be used to modify the appearance of the elements in a command.  The operations will
- * be performed on the command and all embedded subcommands, but not any further than that.  This
- * class should only be used on commands that have been resolved, as unresolved commands
- * do not contain enough metadata to determine the proper fully qualified or optimized 
- * element form.</p>
- */
-public class ElementSymbolOptimizer {
-
-    /**
-     * Can't construct
-     * @see java.lang.Object#Object()
-     */
-    private ElementSymbolOptimizer() {
-    }
-
-    /**
-     * Get a command and all it's embedded commands recursively
-     * @param command Command to start from
-     * @param commandList Collected commands
-     */
-    private static void getExposedCommands(Command command, List commandList) {
-        // Handle Unions
-        if (command instanceof SetQuery){
-            SetQuery setQuery = (SetQuery)command;
-            for (QueryCommand setQueryCommand : setQuery.getQueryCommands()) {
-                getExposedCommands(setQueryCommand, commandList);
-            }   
-        } else {
-            commandList.add(command);
-
-            List subCommands = CommandCollectorVisitor.getCommands(command);
-            if(subCommands != null && subCommands.size() > 0) {
-                for(int i=0; i<subCommands.size(); i++) {
-                    Command subCommand = (Command) subCommands.get(i);
-                    getExposedCommands(subCommand, commandList);
-                }
-            }
-        }
-    }
-
-    /**
-     * This method will convert all elements in a command to their fully qualified name.
-     * @param command Command to convert
-     */
-    public static void fullyQualifyElements(Command command) {
-        // Determine commands to fully qualify
-        List commandsToQualify = new ArrayList();
-        getExposedCommands(command, commandsToQualify);
-
-        for(int i=0; i<commandsToQualify.size(); i++) {
-            Command currentCommand = (Command) commandsToQualify.get(i);
-            Collection elements = ElementCollectorVisitor.getElements(currentCommand, false);
-            Iterator elementIter = elements.iterator();
-            while(elementIter.hasNext()) {
-                ElementSymbol element = (ElementSymbol) elementIter.next();
-
-                fullyQualifyElement(element);
-            }
-        }
-    }
-
-    /**
-     * Method fullyQualifyElement.
-     * @param element
-     */
-    private static void fullyQualifyElement(ElementSymbol element) {
-        element.setDisplayFullyQualified(true);
-    }
-
-
-    
-    /**    
-     * This method will convert all elements in a command to their shortest possible unambiguous name.
-     * @param command Command to convert
-     */
-    public static void optimizeElements(Command command, QueryMetadataInterface metadata)
-    throws QueryMetadataException, TeiidComponentException{
-                
-        // Determine commands to optimize        
-        List commandsToOptimize = new ArrayList();
-        getExposedCommands(command, commandsToOptimize);
-        
-        for(int i=0; i<commandsToOptimize.size(); i++) {
-            Command currentCommand = (Command) commandsToOptimize.get(i);         
-            TempMetadataAdapter facade = new TempMetadataAdapter(metadata, new TempMetadataStore(currentCommand.getTemporaryMetadata()));
-            Collection externalGroups = currentCommand.getAllExternalGroups();
-            Collection groups = GroupCollectorVisitor.getGroups(currentCommand, false);             
-            
-            optimizeElements(currentCommand, groups, externalGroups, facade);
-        }
-    }
-
-    private static boolean isXMLCommand(Command command, QueryMetadataInterface metadata)
-    throws QueryMetadataException, TeiidComponentException{
-        // Check groups
-        Collection groups = GroupCollectorVisitor.getGroups(command, true);
-        if(groups.size() != 1) {
-            return false;
-        }
-
-        // Check group symbol 
-        GroupSymbol group = (GroupSymbol) groups.iterator().next();
-
-        // check if it is an XML group
-        if (metadata.isXMLGroup(group.getMetadataID())){
-            return true;
-        }
-        
-        return false;
-    } 
-    
-    /**
-     * Method optimizeElements.
-     * @param command
-     * @param elements
-     * @param groups
-     * @param externalGroups
-     * @param facade
-     */
-    private static void optimizeElements(
-        Command command,
-        Collection groups,
-        Collection externalGroups,
-        QueryMetadataInterface metadata) 
-    throws QueryMetadataException, TeiidComponentException {
-            
-        switch(command.getType()) {
-            case Command.TYPE_INSERT:
-            case Command.TYPE_UPDATE:
-            case Command.TYPE_DELETE:
-//                optimizeUpdateCommand(command, groups, externalGroups, metadata);
-            case Command.TYPE_STORED_PROCEDURE:
-//                optimizeStoredProcedure(command, groups, externalGroups, metadata);
-            case Command.TYPE_QUERY:
-                // check for XML
-                optimizeCommand(command, groups, externalGroups, metadata);                
-                break;
-                               
-            case Command.TYPE_UPDATE_PROCEDURE:
-                // for now do nothing
-                break;            
-        }
-    }
-
-    /**
-     * Method optimizeCommand.  XML Commands are not currently optimized.
-     * @param command
-     * @param groups
-     * @param externalGroups
-     * @param metadata
-     */
-    private static void optimizeCommand(
-        Command command,
-        Collection groups,
-        Collection externalGroups,
-        QueryMetadataInterface metadata)
-        throws QueryMetadataException, TeiidComponentException {
-            
-        if (isXMLCommand(command, metadata)){
-            return;
-        }
-        
-        final boolean REMOVE_DUPLICATES = false;
-        Collection elements = ElementCollectorVisitor.getElements(command, REMOVE_DUPLICATES);
-        Map shortNameMap = mapShortNamesToGroups(groups, externalGroups, metadata);
-        
-        Iterator i = elements.iterator();
-        while (i.hasNext()) {
-            ElementSymbol element = (ElementSymbol)i.next();
-            String elementFullName = metadata.getFullName(element.getMetadataID());
-            String shortNameKey = metadata.getShortElementName(elementFullName).toUpperCase();
-            Set groupSet = (Set)shortNameMap.get(shortNameKey);
-            if (groupSet != null && groupSet.size() <= 1){
-                element.setDisplayFullyQualified(false);
-            }
-        }            
-    }
-    
-    /**
-     * Return a Map of String element (or parameter) short names to 
-     * Set of GroupSymbols that have an element with that name
-     * @param groups from Command
-     * @param externalGroups from Command
-     * @param metadata
-     * @return Map of String element (or parameter) short names to 
-     * Set of GroupSymbols that have an element with that name
-     */
-    private static Map mapShortNamesToGroups(Collection groups, Collection externalGroups, QueryMetadataInterface metadata) 
-    throws QueryMetadataException, TeiidComponentException {
-
-        Map result = new HashMap();
-        Collection allGroups = new ArrayList(groups);
-        allGroups.addAll(externalGroups);
-
-        Iterator i = allGroups.iterator();
-        while (i.hasNext()) {
-            GroupSymbol group = (GroupSymbol)i.next();
-            Iterator elemIDs = metadata.getElementIDsInGroupID(group.getMetadataID()).iterator();
-            while (elemIDs.hasNext()) {
-                ElementSymbol element = new ElementSymbol(metadata.getFullName(elemIDs.next()));
-                String shortNameKey = element.getShortName().toUpperCase();
-                Set groupSet = (Set)result.get(shortNameKey);
-                if (groupSet == null){
-                    groupSet = new HashSet();
-                    result.put(shortNameKey, groupSet);
-                }
-                groupSet.add(group);
-            }
-        }
-        
-        return result;
-    }
-}

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java	2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java	2011-03-02 16:26:09 UTC (rev 2956)
@@ -26,6 +26,7 @@
 
 import org.teiid.query.analysis.AnalysisRecord;
 import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.util.ResolverUtil;
 import org.teiid.query.sql.lang.Command;
 import org.teiid.query.sql.lang.CompareCriteria;
 import org.teiid.query.sql.lang.Criteria;
@@ -35,7 +36,6 @@
 import org.teiid.query.sql.symbol.Expression;
 import org.teiid.query.sql.symbol.Function;
 import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.util.ElementSymbolOptimizer;
 import org.teiid.query.unittest.FakeMetadataFactory;
 
 
@@ -43,7 +43,7 @@
     
     public Command helpResolve(String sql) {
         Command cmd = TestResolver.helpResolve(sql, FakeMetadataFactory.example1Cached(), AnalysisRecord.createNonRecordingRecord());
-        ElementSymbolOptimizer.fullyQualifyElements(cmd);
+        ResolverUtil.fullyQualifyElements(cmd);
         return cmd;
     }
     

Modified: trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java	2011-03-01 21:25:23 UTC (rev 2955)
+++ trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java	2011-03-02 16:26:09 UTC (rev 2956)
@@ -32,6 +32,8 @@
 import org.teiid.query.metadata.QueryMetadataInterface;
 import org.teiid.query.parser.QueryParser;
 import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.ResolverUtil;
+import org.teiid.query.resolver.util.ResolverVisitor;
 import org.teiid.query.sql.lang.Command;
 import org.teiid.query.unittest.FakeMetadataFactory;
 
@@ -56,11 +58,16 @@
     }
     
     public void helpTestOptimize(String sql, QueryMetadataInterface metadata, String expected) throws QueryMetadataException, TeiidComponentException, QueryParserException, QueryResolverException {
-    	Command command = helpResolve(sql, metadata);
-        ElementSymbolOptimizer.optimizeElements(command, metadata);
-        String actual = command.toString();
-            
-        assertEquals("Expected different optimized string", expected, actual);             //$NON-NLS-1$
+    	try {
+    		ResolverVisitor.setFindShortName(true);
+	    	Command command = helpResolve(sql, metadata);
+	        String actual = command.toString();
+	            
+	        assertEquals("Expected different optimized string", expected, actual);             //$NON-NLS-1$
+    	}
+        finally {
+        	ResolverVisitor.setFindShortName(false);
+        }
     }
 
     /** Can be optimized */
@@ -98,7 +105,7 @@
     public void testOptimize6() throws Exception {
         helpTestOptimize("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 WHERE e2 > (SELECT AVG(pm1.g2.e2) FROM pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1)", //$NON-NLS-1$
                             FakeMetadataFactory.example1Cached(), 
-                            "SELECT e1, e2 FROM pm1.g1 WHERE e2 > (SELECT AVG(pm1.g2.e2) FROM pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1)"); //$NON-NLS-1$
+                            "SELECT e1, e2 FROM pm1.g1 WHERE e2 > (SELECT AVG(e2) FROM pm1.g2 WHERE pm1.g1.e1 = e1)"); //$NON-NLS-1$
     }
 
     /** alias */
@@ -116,7 +123,7 @@
 
     public void helpTestFullyQualify(String sql, QueryMetadataInterface metadata, String expected) throws QueryParserException, QueryResolverException, TeiidComponentException {
         Command command = helpResolve(sql, metadata);
-        ElementSymbolOptimizer.fullyQualifyElements(command);
+        ResolverUtil.fullyQualifyElements(command);
         String actual = command.toString();
 
         assertEquals("Expected different fully qualified string", expected, actual); //$NON-NLS-1$



More information about the teiid-commits mailing list