*/
public void resolveProceduralCommand(Command command, TempMetadataAdapter metadata)
throws QueryMetadataException, QueryResolverException, TeiidComponentException {
// Cast to known type
Insert insert = (Insert) command;
if (insert.getValues() != null) {
QueryResolver.resolveSubqueries(command, metadata, null);
//variables and values must be resolved separately to account for implicitly defined temp groups
resolveList(insert.getValues(), metadata, insert.getExternalGroupContexts(), null);
}
//resolve subquery if there
if(insert.getQueryExpression() != null) {
QueryResolver.setChildMetadata(insert.getQueryExpression(), command);
QueryResolver.resolveCommand(insert.getQueryExpression(), metadata.getMetadata(), false);
}
Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
groups.add(insert.getGroup());
// resolve any functions in the values
List values = insert.getValues();
boolean usingQuery = insert.getQueryExpression() != null;
if (usingQuery) {
values = insert.getQueryExpression().getProjectedSymbols();
}
if (insert.getVariables().isEmpty()) {
if (insert.getGroup().isResolved()) {
List variables = ResolverUtil.resolveElementsInGroup(insert.getGroup(), metadata);
for (Iterator i = variables.iterator(); i.hasNext();) {
insert.addVariable((ElementSymbol)((ElementSymbol)i.next()).clone());
}
} else {
for (int i = 0; i < values.size(); i++) {
if (usingQuery) {
SingleElementSymbol ses = (SingleElementSymbol)values.get(i);
ElementSymbol es = new ElementSymbol(ses.getShortName());
es.setType(ses.getType());
insert.addVariable(es);
} else {
insert.addVariable(new ElementSymbol("expr" + i)); //$NON-NLS-1$
}
}
}
} else if (insert.getGroup().isResolved()) {
resolveVariables(metadata, insert, groups);
}
resolveTypes(insert, metadata, values, usingQuery);
if (!insert.getGroup().isResolved()) { //define the implicit temp group
if(insert.getQueryExpression() != null) {
ResolverUtil.resolveImplicitTempGroup(metadata, insert.getGroup(), insert.getQueryExpression().getProjectedSymbols());
}else {
ResolverUtil.resolveImplicitTempGroup(metadata, insert.getGroup(), insert.getVariables());
}
resolveVariables(metadata, insert, groups);
//ensure that the types match
resolveTypes(insert, metadata, values, usingQuery);
}
if (insert.getQueryExpression() != null && metadata.isVirtualGroup(insert.getGroup().getMetadataID())) {
List<Reference> references = new ArrayList<Reference>(insert.getVariables().size());
for (int i = 0; i < insert.getVariables().size(); i++) {
Reference ref = new Reference(i);
ref.setType(((ElementSymbol)insert.getVariables().get(i)).getType());
references.add(ref);
}
insert.setValues(references);
}
}