sourceNode.getChildren().clear();
return;
}
String newGroup = newGroupSymbol.getName();
ResultSetInfo rsInfo = sourceNode.getResultSetInfo();
//create the command off of the unresolved group symbol
Query baseQuery = QueryUtil.wrapQuery(new UnaryFromClause(new GroupSymbol(newGroup)), newGroup);
baseQuery.getSelect().clearSymbols();
for (Iterator<ElementSymbol> i = ResolverUtil.resolveElementsInGroup(groupSymbol, planEnv.getGlobalMetadata()).iterator(); i.hasNext();) {
ElementSymbol ses = i.next();
baseQuery.getSelect().addSymbol(new ElementSymbol(newGroup + SingleElementSymbol.SEPARATOR + ses.getShortName()));
}
rsInfo.setCommand(baseQuery);
QueryNode modifiedNode = QueryUtil.getQueryNode(newGroup, planEnv.getGlobalMetadata());
Command command = QueryUtil.getQuery(newGroup, modifiedNode, planEnv);
MappingSourceNode parent = sourceNode.getParentSourceNode();
Collection<ElementSymbol> bindings = QueryUtil.getBindingElements(modifiedNode);
// root source nodes do not have any inputset criteria on them; so there is no use in
// going through the raising the criteria.
// if the original query is not a select.. we are out of luck. we can expand on this later
// versions. make ure bindings are only to parent.
if (parent == null || !canRaiseInputset(command, bindings) || !areBindingsOnlyToNode(modifiedNode, parent)) {
return;
}
// now get the criteria set at the design time; and walk and remove any inputset
// criteria.
Query transformationQuery = (Query)command;
Criteria criteria = transformationQuery.getCriteria();
Criteria nonInputsetCriteria = null;
Criteria inputSetCriteria = null;
for (Iterator<Criteria> i = Criteria.separateCriteriaByAnd(criteria).iterator(); i.hasNext();) {
Criteria conjunct = i.next();
// collect references in the criteria; if there are references; then this is
// set by inputset criteria
Collection<ElementSymbol> references = QueryUtil.getBindingsReferences(conjunct, bindings);
if (references.isEmpty()) {
nonInputsetCriteria = Criteria.combineCriteria(nonInputsetCriteria, conjunct);
}
else {
inputSetCriteria = Criteria.combineCriteria(inputSetCriteria, conjunct);
}
}
// Keep the criteria which is not reference based.
transformationQuery.setCriteria(nonInputsetCriteria);
// check and map/convert the inputset criteria elements to groupName, so that
// this criteria mapped on the baseQuery;
boolean addedProjectedSymbol = convertCriteria(newGroupSymbol, transformationQuery, inputSetCriteria, planEnv.getGlobalMetadata(), sourceNode.getSymbolMap());
if (addedProjectedSymbol && transformationQuery.getSelect().isDistinct()) {
transformationQuery.getSelect().setDistinct(false);
baseQuery.getSelect().setDistinct(true);
}
String inlineViewName = planEnv.getAliasName(newGroup);
transformationQuery = QueryUtil.wrapQuery(new SubqueryFromClause(inlineViewName, transformationQuery), inlineViewName);
// Now that we have the modified Query Node for the group name
// we need to update the metadata.
QueryNode relationalNode = new QueryNode(SQLStringVisitor.getSQLString(transformationQuery));
planEnv.addQueryNodeToMetadata(newGroupSymbol.getMetadataID(), relationalNode);
QueryUtil.markBindingsAsNonExternal(inputSetCriteria, bindings);
baseQuery.setCriteria(inputSetCriteria);
rsInfo.setCriteriaRaised(true);
} catch (Exception e) {
throw new TeiidRuntimeException(e);
}
}