Search in sources :

Example 6 with TempMetadataID

use of org.teiid.query.metadata.TempMetadataID 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 7 with TempMetadataID

use of org.teiid.query.metadata.TempMetadataID 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 8 with TempMetadataID

use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.

the class DataTierTupleSource method checkForUpdates.

private void checkForUpdates(AtomicResultsMessage results, Command command, EventDistributor distributor, int commandIndex, long ts) {
    if (!RelationalNodeUtil.isUpdate(command) || !(command instanceof ProcedureContainer)) {
        return;
    }
    ProcedureContainer pc = (ProcedureContainer) command;
    GroupSymbol gs = pc.getGroup();
    Integer zero = Integer.valueOf(0);
    if (results.getResults().length <= commandIndex || zero.equals(results.getResults()[commandIndex].get(0))) {
        return;
    }
    Object metadataId = gs.getMetadataID();
    if (metadataId == null) {
        return;
    }
    if (!(metadataId instanceof Table)) {
        if (metadataId instanceof TempMetadataID) {
            TempMetadataID tid = (TempMetadataID) metadataId;
            if (tid.getTableData().getModel() != null) {
                tid.getTableData().dataModified((Integer) results.getResults()[commandIndex].get(0));
            }
        }
        return;
    }
    Table t = (Table) metadataId;
    t.setLastDataModification(ts);
    if (distributor != null) {
        distributor.dataModification(this.workItem.getDqpWorkContext().getVdbName(), this.workItem.getDqpWorkContext().getVdbVersion(), t.getParent().getName(), t.getName());
    }
}
Also used : Table(org.teiid.metadata.Table) ProcedureContainer(org.teiid.query.sql.lang.ProcedureContainer) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID)

Example 9 with TempMetadataID

use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.

the class DefaultAuthorizationValidator method validate.

@Override
public boolean validate(String[] originalSql, Command command, QueryMetadataInterface metadata, CommandContext commandContext, CommandType commandType) throws QueryValidatorException, TeiidComponentException {
    boolean modified = false;
    if (policyDecider != null && policyDecider.validateCommand(commandContext)) {
        if (ignoreUnathorizedInAsterisk(command, commandContext)) {
            Query query = (Query) command;
            HashMap<String, LanguageObject> map = null;
            for (Expression ex : query.getSelect().getSymbols()) {
                if (ex instanceof MultipleElementSymbol) {
                    MultipleElementSymbol mes = (MultipleElementSymbol) ex;
                    if (map == null) {
                        map = new HashMap<String, LanguageObject>();
                    }
                    for (Iterator<ElementSymbol> iter = mes.getElementSymbols().iterator(); iter.hasNext(); ) {
                        ElementSymbol es = iter.next();
                        Object metadataObject = es.getMetadataID();
                        if (metadataObject instanceof MultiSourceElement || metadataObject instanceof TempMetadataID) {
                            continue;
                        }
                        map.clear();
                        AuthorizationValidationVisitor.addToNameMap(metadataObject, es, map, commandContext.getMetadata());
                        Set<String> results = this.policyDecider.getInaccessibleResources(PermissionType.READ, map.keySet(), Context.QUERY, commandContext);
                        if (!results.isEmpty()) {
                            // remove from the select
                            iter.remove();
                            modified = true;
                        }
                    }
                }
            }
            if (query.getProjectedSymbols().isEmpty()) {
                throw new QueryValidatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31151));
            }
        }
        AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(this.policyDecider, commandContext);
        Request.validateWithVisitor(visitor, metadata, command);
    }
    return modified;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) Query(org.teiid.query.sql.lang.Query) TempMetadataID(org.teiid.query.metadata.TempMetadataID) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) Expression(org.teiid.query.sql.symbol.Expression) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) LanguageObject(org.teiid.query.sql.LanguageObject) LanguageObject(org.teiid.query.sql.LanguageObject) MultiSourceElement(org.teiid.dqp.internal.process.multisource.MultiSourceElement)

Example 10 with TempMetadataID

use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.

the class LanguageBridgeFactory method translate.

public With translate(List<WithQueryCommand> with) {
    if (with == null || with.isEmpty()) {
        return null;
    }
    With result = new With();
    ArrayList<WithItem> items = new ArrayList<WithItem>(with.size());
    for (WithQueryCommand withQueryCommand : with) {
        WithItem item = new WithItem();
        GroupSymbol group = withQueryCommand.getGroupSymbol();
        if (withQueryCommand.getCommand() != null && excludeWithName != null && excludeWithName.equalsIgnoreCase(group.getName())) {
            group = RulePlaceAccess.recontextSymbol(withQueryCommand.getGroupSymbol(), commandContext.getGroups());
            group.setDefinition(null);
            if (remappedGroups == null) {
                remappedGroups = new IdentityHashMap<Object, GroupSymbol>();
            }
            this.remappedGroups.put(group.getMetadataID(), group);
        }
        item.setTable(translate(group));
        if (withQueryCommand.getColumns() != null) {
            List<ColumnReference> translatedElements = new ArrayList<ColumnReference>(withQueryCommand.getColumns().size());
            for (ElementSymbol es : withQueryCommand.getColumns()) {
                ColumnReference cr = translate(es);
                translatedElements.add(cr);
                if (withQueryCommand.getCommand() == null) {
                    // we want to convey the metadata to the source layer if possible
                    Object mid = es.getMetadataID();
                    if (mid instanceof TempMetadataID) {
                        TempMetadataID tid = (TempMetadataID) mid;
                        mid = tid.getOriginalMetadataID();
                    }
                    if (mid instanceof Column) {
                        cr.setMetadataObject((Column) mid);
                    }
                }
            }
            item.setColumns(translatedElements);
        }
        if (withQueryCommand.getCommand() != null) {
            item.setSubquery(translate(withQueryCommand.getCommand()));
        } else {
            item.setDependentValues(new TupleBufferList(withQueryCommand.getTupleBuffer()));
        }
        item.setRecusive(withQueryCommand.isRecursive());
        items.add(item);
    }
    result.setItems(items);
    return result;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) BaseColumn(org.teiid.metadata.BaseColumn) Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Aggregations

TempMetadataID (org.teiid.query.metadata.TempMetadataID)48 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)21 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)16 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)12 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Test (org.junit.Test)7 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)6 HashSet (java.util.HashSet)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 TeiidComponentException (org.teiid.core.TeiidComponentException)5 TeiidProcessingException (org.teiid.core.TeiidProcessingException)5 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 LanguageObject (org.teiid.query.sql.LanguageObject)4 CacheHint (org.teiid.query.sql.lang.CacheHint)4 Expression (org.teiid.query.sql.symbol.Expression)4 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)3 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)3