Search in sources :

Example 1 with AliasGenerator

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);
            }
        }
    });
}
Also used : LanguageVisitor(org.teiid.query.sql.LanguageVisitor) AliasGenerator(org.teiid.query.optimizer.relational.AliasGenerator)

Example 2 with AliasGenerator

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);
    }
}
Also used : Command(org.teiid.query.sql.lang.Command) AliasGenerator(org.teiid.query.optimizer.relational.AliasGenerator) Expression(org.teiid.query.sql.symbol.Expression) Reference(org.teiid.query.sql.symbol.Reference) ValueIteratorProviderCollectorVisitor(org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExpressionMappingVisitor(org.teiid.query.sql.visitor.ExpressionMappingVisitor) TeiidException(org.teiid.core.TeiidException)

Example 3 with AliasGenerator

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);
}
Also used : AliasGenerator(org.teiid.query.optimizer.relational.AliasGenerator) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Command(org.teiid.query.sql.lang.Command) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) LanguageObject(org.teiid.query.sql.LanguageObject) HashSet(java.util.HashSet)

Aggregations

AliasGenerator (org.teiid.query.optimizer.relational.AliasGenerator)3 TeiidException (org.teiid.core.TeiidException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 Command (org.teiid.query.sql.lang.Command)2 HashSet (java.util.HashSet)1 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 LanguageObject (org.teiid.query.sql.LanguageObject)1 LanguageVisitor (org.teiid.query.sql.LanguageVisitor)1 Expression (org.teiid.query.sql.symbol.Expression)1 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)1 Reference (org.teiid.query.sql.symbol.Reference)1 ExpressionMappingVisitor (org.teiid.query.sql.visitor.ExpressionMappingVisitor)1 ValueIteratorProviderCollectorVisitor (org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor)1