Search in sources :

Example 31 with TempMetadataID

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

the class DataTierManagerImpl method registerRequest.

public TupleSource registerRequest(CommandContext context, Command command, String modelName, final RegisterRequestParameter parameterObject) throws TeiidComponentException, TeiidProcessingException {
    RequestWorkItem workItem = context.getWorkItem();
    Assertion.isNotNull(workItem);
    if (CoreConstants.SYSTEM_MODEL.equals(modelName) || CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName)) {
        return processSystemQuery(context, command, workItem.getDqpWorkContext());
    }
    AtomicRequestMessage aqr = createRequest(workItem, command, modelName, parameterObject.connectorBindingId, parameterObject.nodeID);
    aqr.setCommandContext(context);
    if (parameterObject.fetchSize > 0) {
        aqr.setFetchSize(2 * parameterObject.fetchSize);
    }
    if (parameterObject.limit > 0) {
        aqr.setFetchSize(Math.min(parameterObject.limit, aqr.getFetchSize()));
    }
    aqr.setCopyStreamingLobs(parameterObject.copyStreamingLobs);
    Collection<GroupSymbol> accessedGroups = null;
    if (context.getDataObjects() != null) {
        QueryMetadataInterface metadata = context.getMetadata();
        accessedGroups = GroupCollectorVisitor.getGroupsIgnoreInlineViews(command, false);
        boolean usedModel = false;
        for (GroupSymbol gs : accessedGroups) {
            context.accessedDataObject(gs.getMetadataID());
            // check the source/tables/procs for determinism level
            Object mid = gs.getMetadataID();
            if (mid instanceof TempMetadataID) {
                TempMetadataID tid = (TempMetadataID) mid;
                if (tid.getOriginalMetadataID() != null) {
                    mid = tid.getOriginalMetadataID();
                }
            }
            String specificProp = metadata.getExtensionProperty(mid, AbstractMetadataRecord.RELATIONAL_URI + DDLConstants.DETERMINISM, false);
            if (specificProp == null) {
                if (!usedModel) {
                    Object modelId = metadata.getModelID(mid);
                    String prop = metadata.getExtensionProperty(modelId, AbstractMetadataRecord.RELATIONAL_URI + DDLConstants.DETERMINISM, false);
                    if (prop != null) {
                        usedModel = true;
                        // set model property
                        context.setDeterminismLevel(Determinism.valueOf(prop.toUpperCase()));
                    }
                }
                continue;
            }
            context.setDeterminismLevel(Determinism.valueOf(specificProp.toUpperCase()));
        }
    }
    ConnectorManagerRepository cmr = workItem.getDqpWorkContext().getVDB().getAttachment(ConnectorManagerRepository.class);
    ConnectorManager connectorManager = cmr.getConnectorManager(aqr.getConnectorName());
    if (connectorManager == null) {
        // can happen if sources are removed
        if (RelationalNodeUtil.hasOutputParams(command)) {
            // $NON-NLS-1$
            throw new AssertionError("A source is required to execute a procedure returning parameters");
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        LogManager.logDetail(LogConstants.CTX_DQP, "source", aqr.getConnectorName(), "no longer exists, returning dummy results");
        return CollectionTupleSource.createNullTupleSource();
    }
    ConnectorWork work = connectorManager.registerRequest(aqr);
    if (!work.isForkable()) {
        aqr.setSerial(true);
    }
    CacheID cid = null;
    CacheDirective cd = null;
    if (workItem.getRsCache() != null && command.areResultsCachable()) {
        CachableVisitor cv = new CachableVisitor();
        PreOrPostOrderNavigator.doVisit(command, cv, PreOrPostOrderNavigator.PRE_ORDER, true);
        if (cv.cacheable) {
            try {
                cd = work.getCacheDirective();
            } catch (TranslatorException e) {
                // $NON-NLS-1$
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30504, e, aqr.getConnectorName() + ": " + e.getMessage());
            }
            if (cd != null) {
                if (cd.getScope() == Scope.NONE) {
                    parameterObject.doNotCache = true;
                } else {
                    String cmdString = command.toString();
                    if (cmdString.length() < 100000) {
                        // TODO: this check won't be needed if keys aren't exclusively held in memory
                        cid = new CacheID(workItem.getDqpWorkContext(), ParseInfo.DEFAULT_INSTANCE, cmdString);
                        cid.setParameters(cv.parameters);
                        if (cd.getInvalidation() == null || cd.getInvalidation() == Invalidation.NONE) {
                            CachedResults cr = workItem.getRsCache().get(cid);
                            if (cr != null && (cr.getRowLimit() == 0 || (parameterObject.limit > 0 && cr.getRowLimit() >= parameterObject.limit))) {
                                parameterObject.doNotCache = true;
                                // $NON-NLS-1$
                                LogManager.logDetail(LogConstants.CTX_DQP, "Using cache entry for", cid);
                                work.close();
                                return cr.getResults().createIndexedTupleSource();
                            }
                        } else if (cd.getInvalidation() == Invalidation.IMMEDIATE) {
                            workItem.getRsCache().remove(cid, CachingTupleSource.getDeterminismLevel(cd.getScope()));
                        }
                    }
                }
            } else {
                // $NON-NLS-1$
                LogManager.logTrace(LogConstants.CTX_DQP, aqr.getAtomicRequestID(), "no cache directive");
            }
        } else {
            // $NON-NLS-1$
            LogManager.logTrace(LogConstants.CTX_DQP, aqr.getAtomicRequestID(), "command not cachable");
        }
    }
    DataTierTupleSource dtts = new DataTierTupleSource(aqr, workItem, work, this, parameterObject.limit);
    TupleSource result = dtts;
    TupleBuffer tb = null;
    if (cid != null) {
        tb = getBufferManager().createTupleBuffer(aqr.getCommand().getProjectedSymbols(), aqr.getCommandContext().getConnectionId(), TupleSourceType.PROCESSOR);
        result = new CachingTupleSource(this, tb, (DataTierTupleSource) result, cid, parameterObject, cd, accessedGroups, workItem);
    }
    if (work.isThreadBound()) {
        result = handleThreadBound(workItem, aqr, work, cid, result, dtts, tb);
    } else if (!aqr.isSerial()) {
        dtts.addWork();
    }
    return result;
}
Also used : CachableVisitor(org.teiid.dqp.internal.process.TupleSourceCache.CachableVisitor) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) TempMetadataID(org.teiid.query.metadata.TempMetadataID) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) TeiidProcessingException(org.teiid.core.TeiidProcessingException) CacheDirective(org.teiid.translator.CacheDirective) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) CopyOnReadTupleSource(org.teiid.dqp.internal.process.TupleSourceCache.CopyOnReadTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TranslatorException(org.teiid.translator.TranslatorException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ConnectorWork(org.teiid.dqp.internal.datamgr.ConnectorWork) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage)

Example 32 with TempMetadataID

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

the class LanguageBridgeFactory method translate.

ColumnReference translate(ElementSymbol symbol) {
    ColumnReference element = new ColumnReference(translate(symbol.getGroupSymbol()), Symbol.getShortName(symbol.getOutputName()), null, symbol.getType());
    if (element.getTable().getMetadataObject() == null) {
        // handle procedure resultset columns
        if (symbol.getMetadataID() instanceof TempMetadataID) {
            TempMetadataID tid = (TempMetadataID) symbol.getMetadataID();
            if (tid.getOriginalMetadataID() instanceof Column && !(((Column) tid.getOriginalMetadataID()).getParent() instanceof Table)) {
                element.setMetadataObject(metadataFactory.getElement(tid.getOriginalMetadataID()));
            }
        }
        return element;
    }
    Object mid = symbol.getMetadataID();
    element.setMetadataObject(metadataFactory.getElement(mid));
    return element;
}
Also used : Table(org.teiid.metadata.Table) BaseColumn(org.teiid.metadata.BaseColumn) Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) TempMetadataID(org.teiid.query.metadata.TempMetadataID)

Example 33 with TempMetadataID

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

the class AccessInfo method initExternalList.

private static List<List<String>> initExternalList(List<List<String>> externalNames, Set<? extends Object> accessed) {
    if (externalNames == null) {
        externalNames = new ArrayList<List<String>>(accessed.size());
        for (Object object : accessed) {
            if (object instanceof AbstractMetadataRecord) {
                AbstractMetadataRecord t = (AbstractMetadataRecord) object;
                externalNames.add(Arrays.asList(t.getParent().getName(), t.getName()));
            } else if (object instanceof TempMetadataID) {
                TempMetadataID t = (TempMetadataID) object;
                externalNames.add(Arrays.asList(t.getID()));
            }
        }
    }
    return externalNames;
}
Also used : TempMetadataID(org.teiid.query.metadata.TempMetadataID) ArrayList(java.util.ArrayList) List(java.util.List) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 34 with TempMetadataID

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

the class AccessInfo method restore.

/**
 * Restore reconnects to the live metadata objects
 * @throws TeiidComponentException
 * @throws TeiidProcessingException
 */
void restore() throws TeiidComponentException, TeiidProcessingException {
    if (this.objectsAccessed != null) {
        return;
    }
    VDBMetaData vdb = DQPWorkContext.getWorkContext().getVDB();
    TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
    GlobalTableStore globalStore = vdb.getAttachment(GlobalTableStore.class);
    if (!externalNames.isEmpty()) {
        this.objectsAccessed = new HashSet<Object>(externalNames.size());
        for (List<String> key : this.externalNames) {
            if (key.size() == 1) {
                String matTableName = key.get(0);
                TempMetadataID id = globalStore.getGlobalTempTableMetadataId(matTableName);
                if (id == null) {
                    // if the id is null, then create a local instance
                    String viewFullName = matTableName.substring(RelationalPlanner.MAT_PREFIX.length());
                    id = globalStore.getGlobalTempTableMetadataId(tm.getGroupID(viewFullName));
                }
                this.objectsAccessed.add(id);
            } else {
                Schema s = tm.getMetadataStore().getSchema(key.get(0));
                Modifiable m = s.getTables().get(key.get(1));
                if (m == null) {
                    m = s.getProcedures().get(key.get(1));
                }
                if (m != null) {
                    this.objectsAccessed.add(m);
                }
            }
        }
    } else {
        this.objectsAccessed = Collections.emptySet();
    }
    this.externalNames = null;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) TempMetadataID(org.teiid.query.metadata.TempMetadataID) DataModifiable(org.teiid.metadata.AbstractMetadataRecord.DataModifiable) Modifiable(org.teiid.metadata.AbstractMetadataRecord.Modifiable)

Example 35 with TempMetadataID

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

the class AuthorizationValidationVisitor method validateEntitlements.

/**
 * Check that the user is entitled to access all data elements in the command.
 *
 * @param symbols The collection of <code>Symbol</code>s affected by these actions.
 * @param actionCode The actions to validate for
 * @param auditContext The {@link AuthorizationService} to use when resource auditing is done.
 */
protected void validateEntitlements(Collection<? extends LanguageObject> symbols, DataPolicy.PermissionType actionCode, Context auditContext) {
    Map<String, LanguageObject> nameToSymbolMap = new LinkedHashMap<String, LanguageObject>();
    for (LanguageObject symbol : symbols) {
        try {
            Object metadataID = null;
            if (symbol instanceof ElementSymbol) {
                metadataID = ((ElementSymbol) symbol).getMetadataID();
                if (metadataID instanceof MultiSourceElement || metadataID instanceof TempMetadataID) {
                    continue;
                }
            } else if (symbol instanceof GroupSymbol) {
                GroupSymbol group = (GroupSymbol) symbol;
                metadataID = group.getMetadataID();
                if (metadataID instanceof TempMetadataID) {
                    if (group.isProcedure()) {
                        Map<String, LanguageObject> procMap = new LinkedHashMap<String, LanguageObject>();
                        addToNameMap(((TempMetadataID) metadataID).getOriginalMetadataID(), symbol, procMap, getMetadata());
                        validateEntitlements(PermissionType.EXECUTE, auditContext, procMap);
                    } else if (group.isTempTable() && group.isImplicitTempGroupSymbol()) {
                        validateTemp(actionCode, group.getNonCorrelationName(), false, group, auditContext);
                    }
                    continue;
                }
            }
            addToNameMap(metadataID, symbol, nameToSymbolMap, getMetadata());
        } catch (QueryMetadataException e) {
            handleException(e);
        } catch (TeiidComponentException e) {
            handleException(e);
        }
    }
    validateEntitlements(actionCode, auditContext, nameToSymbolMap);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException) LanguageObject(org.teiid.query.sql.LanguageObject) MultiSourceElement(org.teiid.dqp.internal.process.multisource.MultiSourceElement)

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