Search in sources :

Example 46 with QueryResolverException

use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.

the class ProcedureContainerResolver method expandCommand.

/**
 * Expand a command by finding and attaching all subcommands to the command.  If
 * some initial resolution must be done for this to be accomplished, that is ok,
 * but it should be kept to a minimum.
 * @param command The command to expand
 * @param useMetadataCommands True if resolver should use metadata commands to completely resolve
 * @param metadata Metadata access
 * @param analysis The analysis record that will be filled in if doing annotation.
 *
 * @throws QueryMetadataException If there is a metadata problem
 * @throws QueryResolverException If the query cannot be resolved
 * @throws TeiidComponentException If there is an internal error
 */
public Command expandCommand(ProcedureContainer procCommand, QueryMetadataInterface metadata, AnalysisRecord analysis) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    // Resolve group so we can tell whether it is an update procedure
    GroupSymbol group = procCommand.getGroup();
    Command subCommand = null;
    String plan = getPlan(metadata, procCommand);
    if (plan == null) {
        return null;
    }
    QueryParser parser = QueryParser.getQueryParser();
    try {
        subCommand = parser.parseProcedure(plan, !(procCommand instanceof StoredProcedure));
    } catch (QueryParserException e) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30060, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30060, group, procCommand.getClass().getSimpleName()));
    }
    return subCommand;
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) QueryParserException(org.teiid.api.exception.query.QueryParserException) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 47 with QueryResolverException

use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.

the class QueryResolver method resolveCommand.

public static TempMetadataStore resolveCommand(Command currentCommand, QueryMetadataInterface metadata, boolean resolveNullLiterals) throws QueryResolverException, TeiidComponentException {
    // $NON-NLS-1$
    LogManager.logTrace(org.teiid.logging.LogConstants.CTX_QUERY_RESOLVER, new Object[] { "Resolving command", currentCommand });
    TempMetadataAdapter resolverMetadata = null;
    try {
        TempMetadataStore discoveredMetadata = currentCommand.getTemporaryMetadata();
        if (discoveredMetadata == null) {
            discoveredMetadata = new TempMetadataStore();
            currentCommand.setTemporaryMetadata(discoveredMetadata);
        }
        resolverMetadata = new TempMetadataAdapter(metadata, discoveredMetadata);
        // Resolve external groups for command
        Collection<GroupSymbol> externalGroups = currentCommand.getAllExternalGroups();
        for (GroupSymbol extGroup : externalGroups) {
            Object metadataID = extGroup.getMetadataID();
            // TODO: this is mainly for XML resolving since it sends external groups in unresolved
            if (metadataID == null || (!(extGroup.getMetadataID() instanceof TempMetadataID) && discoveredMetadata.getTempGroupID(extGroup.getName()) != null)) {
                boolean missing = metadataID == null;
                metadataID = resolverMetadata.getGroupID(extGroup.getName());
                if (missing) {
                    extGroup.setMetadataID(metadataID);
                } else {
                    // we shouldn't modify the existing, just add a shadow group
                    GroupSymbol gs = extGroup.clone();
                    gs.setMetadataID(metadataID);
                    currentCommand.getExternalGroupContexts().addGroup(gs);
                }
            }
        }
        CommandResolver resolver = chooseResolver(currentCommand, resolverMetadata);
        // Resolve this command
        resolver.resolveCommand(currentCommand, resolverMetadata, resolveNullLiterals);
    } catch (QueryMetadataException e) {
        throw new QueryResolverException(e);
    }
    // Flag that this command has been resolved.
    currentCommand.setIsResolved(true);
    return resolverMetadata.getMetadataStore();
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 48 with QueryResolverException

use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.

the class AlterResolver method resolveCommand.

@Override
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    Alter<? extends Command> alter = (Alter<? extends Command>) command;
    ResolverUtil.resolveGroup(alter.getTarget(), metadata);
    int type = Command.TYPE_QUERY;
    boolean viewTarget = true;
    if (alter instanceof AlterTrigger) {
        TriggerEvent event = ((AlterTrigger) alter).getEvent();
        switch(event) {
            case DELETE:
                type = Command.TYPE_DELETE;
                break;
            case INSERT:
                type = Command.TYPE_INSERT;
                break;
            case UPDATE:
                type = Command.TYPE_UPDATE;
                break;
        }
        if (((AlterTrigger) alter).isAfter()) {
            viewTarget = false;
        }
    } else if (alter instanceof AlterProcedure) {
        type = Command.TYPE_STORED_PROCEDURE;
        viewTarget = false;
    }
    if (viewTarget && !QueryResolver.isView(alter.getTarget(), metadata)) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30116, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30116, alter.getTarget()));
    }
    if (alter.getDefinition() != null) {
        QueryResolver.resolveCommand(alter.getDefinition(), alter.getTarget(), type, metadata.getDesignTimeMetadata(), false);
    }
}
Also used : Alter(org.teiid.query.sql.lang.Alter) AlterProcedure(org.teiid.query.sql.lang.AlterProcedure) Command(org.teiid.query.sql.lang.Command) TriggerEvent(org.teiid.metadata.Table.TriggerEvent) AlterTrigger(org.teiid.query.sql.lang.AlterTrigger) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 49 with QueryResolverException

use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.

the class InsertResolver method resolveTypes.

/**
 * @param insert
 * @param values
 * @param usingQuery
 * @throws QueryResolverException
 */
public void resolveTypes(Insert insert, TempMetadataAdapter metadata, List values, boolean usingQuery) throws QueryResolverException {
    List newValues = new ArrayList(values.size());
    // check that # of variables == # of values
    if (values.size() != insert.getVariables().size()) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30127, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30127, insert.getVariables().size(), values.size()));
    }
    Iterator valueIter = values.iterator();
    Iterator<ElementSymbol> varIter = insert.getVariables().iterator();
    while (valueIter.hasNext()) {
        // Walk through both elements and expressions, which should match up
        Expression expression = (Expression) valueIter.next();
        ElementSymbol element = varIter.next();
        if (expression.getType() == null) {
            ResolverUtil.setDesiredType(SymbolMap.getExpression(expression), element.getType(), insert);
        }
        if (element.getType() != null && expression.getType() != null) {
            String elementTypeName = DataTypeManager.getDataTypeName(element.getType());
            if (!usingQuery) {
                newValues.add(ResolverUtil.convertExpression(expression, elementTypeName, metadata));
            } else if (element.getType() != expression.getType() && !DataTypeManager.isImplicitConversion(DataTypeManager.getDataTypeName(expression.getType()), DataTypeManager.getDataTypeName(element.getType()))) {
                // TODO: a special case here is a projected literal
                throw new QueryResolverException(QueryPlugin.Event.TEIID30128, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30128, new Object[] { expression, expression.getType().getName(), element, element.getType().getName() }));
            }
        } else if (element.getType() == null && expression.getType() != null) {
            element.setType(expression.getType());
            newValues.add(expression);
        } else {
            // $NON-NLS-1$
            Assertion.failed("Cannot determine element or expression type");
        }
    }
    if (!usingQuery) {
        insert.setValues(newValues);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Expression(org.teiid.query.sql.symbol.Expression) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 50 with QueryResolverException

use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.

the class SetQueryResolver method resolveSetQuery.

public void resolveSetQuery(TempMetadataAdapter metadata, boolean resolveNullLiterals, SetQuery setQuery, QueryCommand firstCommand, QueryCommand rightCommand) throws QueryResolverException, QueryMetadataException, TeiidComponentException {
    List<Expression> firstProject = firstCommand.getProjectedSymbols();
    List<Class<?>> firstProjectTypes = new ArrayList<Class<?>>();
    for (Expression symbol : firstProject) {
        firstProjectTypes.add(symbol.getType());
    }
    if (firstProject.size() != rightCommand.getProjectedSymbols().size()) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30147, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30147, setQuery.getOperation()));
    }
    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(firstCommand.getTemporaryMetadata().clone());
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) ArrayList(java.util.ArrayList) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Aggregations

QueryResolverException (org.teiid.api.exception.query.QueryResolverException)62 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)13 TempMetadataID (org.teiid.query.metadata.TempMetadataID)11 ExceptionExpression (org.teiid.query.sql.proc.ExceptionExpression)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 TeiidComponentException (org.teiid.core.TeiidComponentException)10 Expression (org.teiid.query.sql.symbol.Expression)10 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)8 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)7 Command (org.teiid.query.sql.lang.Command)6 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)6 QueryParserException (org.teiid.api.exception.query.QueryParserException)5 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)5 LanguageObject (org.teiid.query.sql.LanguageObject)5 List (java.util.List)4 UnresolvedSymbolDescription (org.teiid.api.exception.query.UnresolvedSymbolDescription)4 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)4 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)4 HashSet (java.util.HashSet)3