Search in sources :

Example 16 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class UpdateProcedureResolver method collectDeclareVariable.

private void collectDeclareVariable(DeclareStatement obj, GroupSymbol variables, TempMetadataAdapter metadata, GroupContext externalGroups) throws QueryResolverException, TeiidComponentException {
    ElementSymbol variable = obj.getVariable();
    String typeName = obj.getVariableType();
    GroupSymbol gs = variable.getGroupSymbol();
    if (gs == null) {
        String outputName = variable.getShortName();
        variable.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.VARIABLES));
        variable.setOutputName(outputName);
    } else {
        if (gs.getSchema() != null || !gs.getShortName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) {
            // $NON-NLS-1$
            handleUnresolvableDeclaration(variable, QueryPlugin.Util.getString("ERR.015.010.0031", new Object[] { ProcedureReservedWords.VARIABLES, variable }));
        }
    }
    boolean exists = false;
    try {
        ResolverVisitor.resolveLanguageObject(variable, null, externalGroups, metadata);
        exists = true;
    } catch (QueryResolverException e) {
    // ignore, not already defined
    }
    if (exists) {
        // $NON-NLS-1$
        handleUnresolvableDeclaration(variable, QueryPlugin.Util.getString("ERR.015.010.0032", variable.getOutputName()));
    }
    boolean exception = typeName.equalsIgnoreCase(SQLConstants.NonReserved.EXCEPTION);
    variable.setType(exception ? DataTypeManager.DefaultDataClasses.OBJECT : DataTypeManager.getDataTypeClass(typeName));
    variable.setGroupSymbol(variables);
    TempMetadataID id = new TempMetadataID(variable.getName(), exception ? Exception.class : variable.getType());
    id.setUpdatable(true);
    variable.setMetadataID(id);
    // TODO: this will cause the variables group to loose it's cache of resolved symbols
    metadata.getMetadataStore().addElementToTempGroup(ProcedureReservedWords.VARIABLES, variable.clone());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 17 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class UpdateProcedureResolver method resolveBlock.

public void resolveBlock(CreateProcedureCommand command, Block block, GroupContext originalExternalGroups, TempMetadataAdapter original) throws QueryResolverException, QueryMetadataException, TeiidComponentException {
    // $NON-NLS-1$
    LogManager.logTrace(org.teiid.logging.LogConstants.CTX_QUERY_RESOLVER, new Object[] { "Resolving block", block });
    // create a new variable and metadata context for this block so that discovered metadata is not visible else where
    TempMetadataStore store = original.getMetadataStore().clone();
    TempMetadataAdapter metadata = new TempMetadataAdapter(original.getMetadata(), store);
    GroupContext externalGroups = new GroupContext(originalExternalGroups, null);
    // create a new variables group for this block
    GroupSymbol variables = ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.VARIABLES, store, externalGroups, new LinkedList<Expression>());
    for (Statement statement : block.getStatements()) {
        resolveStatement(command, statement, externalGroups, variables, metadata);
    }
    if (block.getExceptionGroup() != null) {
        // create a new variable and metadata context for this block so that discovered metadata is not visible else where
        store = original.getMetadataStore().clone();
        metadata = new TempMetadataAdapter(original.getMetadata(), store);
        externalGroups = new GroupContext(originalExternalGroups, null);
        // create a new variables group for this block
        variables = ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.VARIABLES, store, externalGroups, new LinkedList<Expression>());
        isValidGroup(metadata, block.getExceptionGroup());
        if (block.getExceptionStatements() != null) {
            ProcedureContainerResolver.addScalarGroup(block.getExceptionGroup(), store, externalGroups, exceptionGroup, false);
            for (Statement statement : block.getExceptionStatements()) {
                resolveStatement(command, statement, externalGroups, variables, metadata);
            }
        }
    }
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) Expression(org.teiid.query.sql.symbol.Expression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) GroupContext(org.teiid.query.sql.lang.GroupContext) LinkedList(java.util.LinkedList)

Example 18 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class UpdateResolver method resolveProceduralCommand.

/**
 * @see org.teiid.query.resolver.ProcedureContainerResolver#resolveProceduralCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter)
 */
public void resolveProceduralCommand(Command command, TempMetadataAdapter metadata) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    // Cast to known type
    Update update = (Update) command;
    // Resolve elements and functions
    Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
    groups.add(update.getGroup());
    for (SetClause clause : update.getChangeList().getClauses()) {
        ResolverVisitor.resolveLanguageObject(clause.getSymbol(), groups, null, metadata);
    }
    QueryResolver.resolveSubqueries(command, metadata, groups);
    ResolverVisitor.resolveLanguageObject(update, groups, update.getExternalGroupContexts(), metadata);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Update(org.teiid.query.sql.lang.Update) HashSet(java.util.HashSet) SetClause(org.teiid.query.sql.lang.SetClause)

Example 19 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class ProcedureContainerResolver method addScalarGroup.

public static GroupSymbol addScalarGroup(String name, TempMetadataStore metadata, GroupContext externalGroups, List<? extends Expression> symbols, boolean[] updatable) {
    GroupSymbol variables = new GroupSymbol(name);
    externalGroups.addGroup(variables);
    TempMetadataID tid = metadata.addTempGroup(name, symbols);
    tid.setMetadataType(Type.SCALAR);
    int i = 0;
    for (TempMetadataID cid : tid.getElements()) {
        cid.setMetadataType(Type.SCALAR);
        cid.setUpdatable(updatable[i++]);
    }
    variables.setMetadataID(tid);
    return variables;
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID)

Example 20 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class QueryResolver method resolveView.

public static QueryNode resolveView(GroupSymbol virtualGroup, QueryNode qnode, String cacheString, QueryMetadataInterface qmi, boolean logValidation) throws TeiidComponentException, QueryMetadataException, QueryResolverException, QueryValidatorException {
    qmi = qmi.getDesignTimeMetadata();
    // $NON-NLS-1$
    cacheString = "transformation/" + cacheString;
    QueryNode cachedNode = (QueryNode) qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
    if (cachedNode == null) {
        Command result = qnode.getCommand();
        List<String> bindings = null;
        if (result == null) {
            try {
                result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());
            } catch (QueryParserException e) {
                throw new QueryResolverException(QueryPlugin.Event.TEIID30065, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30065, virtualGroup));
            }
            bindings = qnode.getBindings();
        } else {
            result = (Command) result.clone();
        }
        if (bindings != null && !bindings.isEmpty()) {
            QueryResolver.resolveWithBindingMetadata(result, qmi, qnode, true);
        } else {
            QueryResolver.resolveCommand(result, qmi, false);
        }
        Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
        validateProjectedSymbols(virtualGroup, qmi, result);
        cachedNode = new QueryNode(qnode.getQuery());
        cachedNode.setCommand(result);
        if (isView(virtualGroup, qmi)) {
            String updatePlan = qmi.getUpdatePlan(virtualGroup.getMetadataID());
            String deletePlan = qmi.getDeletePlan(virtualGroup.getMetadataID());
            String insertPlan = qmi.getInsertPlan(virtualGroup.getMetadataID());
            // the elements must be against the view and not the alias
            if (virtualGroup.getDefinition() != null) {
                GroupSymbol group = new GroupSymbol(virtualGroup.getNonCorrelationName());
                group.setMetadataID(virtualGroup.getMetadataID());
                virtualGroup = group;
            }
            List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
            UpdateValidator validator = new UpdateValidator(qmi, determineType(insertPlan), determineType(updatePlan), determineType(deletePlan));
            validator.validate(result, elements);
            UpdateInfo info = validator.getUpdateInfo();
            if (logValidation && qmi.groupSupports(virtualGroup.getMetadataID(), SupportConstants.Group.UPDATE)) {
                if (info.isInherentInsert() && validator.getInsertReport().hasItems()) {
                    LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getInsertReport().getFailureMessage(), SQLConstants.Reserved.INSERT, qmi.getFullName(virtualGroup.getMetadataID())));
                }
                if (info.isInherentUpdate() && validator.getUpdateReport().hasItems()) {
                    LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getUpdateReport().getFailureMessage(), SQLConstants.Reserved.UPDATE, qmi.getFullName(virtualGroup.getMetadataID())));
                }
                if (info.isInherentDelete() && validator.getDeleteReport().hasItems()) {
                    LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getDeleteReport().getFailureMessage(), SQLConstants.Reserved.DELETE, qmi.getFullName(virtualGroup.getMetadataID())));
                }
            }
            cachedNode.setUpdateInfo(info);
        }
        qmi.addToMetadataCache(virtualGroup.getMetadataID(), cacheString, cachedNode);
    }
    return cachedNode;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ValidationVisitor(org.teiid.query.validator.ValidationVisitor) QueryParserException(org.teiid.api.exception.query.QueryParserException) Command(org.teiid.query.sql.lang.Command) QueryNode(org.teiid.query.mapping.relational.QueryNode) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) UpdateValidator(org.teiid.query.validator.UpdateValidator) UpdateInfo(org.teiid.query.validator.UpdateValidator.UpdateInfo)

Aggregations

GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)299 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)146 Test (org.junit.Test)108 ArrayList (java.util.ArrayList)92 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)59 Expression (org.teiid.query.sql.symbol.Expression)52 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 Constant (org.teiid.query.sql.symbol.Constant)48 List (java.util.List)43 HashSet (java.util.HashSet)32 Query (org.teiid.query.sql.lang.Query)31 From (org.teiid.query.sql.lang.From)29 SymbolMap (org.teiid.query.sql.util.SymbolMap)29 Select (org.teiid.query.sql.lang.Select)26 Criteria (org.teiid.query.sql.lang.Criteria)22 TempMetadataID (org.teiid.query.metadata.TempMetadataID)21 LinkedList (java.util.LinkedList)20 Command (org.teiid.query.sql.lang.Command)20 Set (java.util.Set)17 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)17