* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals)
throws QueryMetadataException, QueryResolverException, TeiidComponentException {
SetQuery setQuery = (SetQuery) command;
SimpleQueryResolver.resolveWith(metadata, setQuery);
QueryCommand firstCommand = setQuery.getLeftQuery();
QueryResolver.setChildMetadata(firstCommand, setQuery);
QueryResolver.resolveCommand(firstCommand, metadata.getMetadata(), false);
List<SingleElementSymbol> firstProject = firstCommand.getProjectedSymbols();
List<Class<?>> firstProjectTypes = new ArrayList<Class<?>>();
for (SingleElementSymbol symbol : firstProject) {
firstProjectTypes.add(symbol.getType());
}
QueryCommand rightCommand = setQuery.getRightQuery();
QueryResolver.setChildMetadata(rightCommand, setQuery);
QueryResolver.resolveCommand(rightCommand, metadata.getMetadata(), false);
if (firstProject.size() != rightCommand.getProjectedSymbols().size()) {
throw new QueryResolverException(QueryPlugin.Util.getString("ERR.015.012.0035", setQuery.getOperation())); //$NON-NLS-1$
}
checkSymbolTypes(firstProjectTypes, rightCommand.getProjectedSymbols());
if (resolveNullLiterals) {
for (int i = 0; i < firstProjectTypes.size(); i++) {
Class<?> clazz = firstProjectTypes.get(i);
if (clazz == null || clazz.equals(DataTypeManager.DefaultDataClasses.NULL)) {
firstProjectTypes.set(i, DataTypeManager.DefaultDataClasses.STRING);
}
}
}
setQuery.setProjectedTypes(firstProjectTypes, metadata.getMetadata());
// ORDER BY clause
if(setQuery.getOrderBy() != null) {
//order by elements must use the short name of the projected symbols
ResolverUtil.resolveOrderBy(setQuery.getOrderBy(), setQuery, metadata);
}
setProjectedTypes(setQuery, firstProjectTypes, metadata.getMetadata());
if (setQuery.getLimit() != null) {
ResolverUtil.resolveLimit(setQuery.getLimit());
}
setQuery.setTemporaryMetadata(new HashMap(firstCommand.getTemporaryMetadata()));
}