use of org.teiid.query.optimizer.relational.AliasGenerator in project teiid by teiid.
the class QueryRewriter method removeAlias.
/**
* For backwards compatibility we strip the alias from delete/update
* @param command
* @param group
*/
private void removeAlias(ProcedureContainer command, GroupSymbol group) {
AliasGenerator ag = new AliasGenerator(true);
ag.setCorrelationGroups(Arrays.asList(group.getDefinition()));
command.acceptVisitor(ag);
final GroupSymbol clone = group.clone();
DeepPostOrderNavigator.doVisit(command, new LanguageVisitor() {
public void visit(GroupSymbol obj) {
if (obj.equals(clone) && obj.getMetadataID() == group.getMetadataID()) {
obj.setName(obj.getDefinition());
obj.setDefinition(null);
}
}
});
}
use of org.teiid.query.optimizer.relational.AliasGenerator in project teiid by teiid.
the class CommandBuilder method getCommand.
public org.teiid.language.Command getCommand(String queryString, boolean generateAliases, boolean supportsGroupAlias) {
Command command = null;
try {
command = QueryParser.getQueryParser().parseCommand(queryString);
QueryResolver.resolveCommand(command, metadata);
command = QueryRewriter.rewrite(command, metadata, null);
expandAllSymbol(command);
if (generateAliases) {
command = (Command) command.clone();
command.acceptVisitor(new AliasGenerator(supportsGroupAlias));
}
// the language bridge doesn't expect References
ValueIteratorProviderCollectorVisitor v = new ValueIteratorProviderCollectorVisitor();
v.setCollectLateral(true);
PreOrderNavigator.doVisit(command, v);
for (SubqueryContainer<?> container : v.getValueIteratorProviders()) {
ExpressionMappingVisitor visitor = new ExpressionMappingVisitor(null) {
@Override
public Expression replaceExpression(Expression element) {
if (element instanceof Reference) {
return ((Reference) element).getExpression();
}
return element;
}
};
DeepPostOrderNavigator.doVisit(command, visitor);
}
return languageBridgeFactory.translate(command);
} catch (TeiidException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.query.optimizer.relational.AliasGenerator in project teiid by teiid.
the class TestOptimizer method checkAtomicQueries.
public static void checkAtomicQueries(String[] expectedAtomic, ProcessorPlan plan, QueryMetadataInterface md, CapabilitiesFinder capFinder) {
Set<String> actualQueries = getAtomicQueries(plan);
HashSet<String> expectedQueries = new HashSet<String>();
// Compare atomic queries
for (int i = 0; i < expectedAtomic.length; i++) {
final String sql = expectedAtomic[i];
Command command;
try {
command = helpGetCommand(sql, md, null);
Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroupsIgnoreInlineViews(command, false);
final GroupSymbol symbol = groups.iterator().next();
Object modelId = md.getModelID(symbol.getMetadataID());
boolean supportsGroupAliases = CapabilitiesUtil.supportsGroupAliases(modelId, md, capFinder);
boolean supportsProjection = CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelId, md, capFinder);
command.acceptVisitor(new AliasGenerator(supportsGroupAliases, !supportsProjection));
expectedQueries.add(command.toString());
} catch (Exception err) {
throw new RuntimeException(err);
}
}
// $NON-NLS-1$
assertEquals("Did not get expected atomic queries: ", expectedQueries, actualQueries);
}
Aggregations