Search in sources :

Example 21 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class MetaDataProcessor method createProjectedSymbolMetadata.

private Map<Integer, Object>[] createProjectedSymbolMetadata(Command originalCommand) throws TeiidComponentException {
    Map<Integer, Object>[] columnMetadata;
    // Allow command to use temporary metadata
    TempMetadataStore tempMetadata = originalCommand.getTemporaryMetadata();
    if (tempMetadata != null && tempMetadata.getData().size() > 0) {
        TempMetadataAdapter tempFacade = new TempMetadataAdapter(this.metadata, tempMetadata);
        this.metadata = tempFacade;
    }
    List<Expression> projectedSymbols = originalCommand.getProjectedSymbols();
    columnMetadata = new Map[projectedSymbols.size()];
    Iterator<Expression> symbolIter = projectedSymbols.iterator();
    for (int i = 0; symbolIter.hasNext(); i++) {
        Expression symbol = symbolIter.next();
        String shortColumnName = Symbol.getShortName(Symbol.getOutputName(symbol));
        if (symbol instanceof AliasSymbol) {
            symbol = ((AliasSymbol) symbol).getSymbol();
        }
        try {
            columnMetadata[i] = createColumnMetadata(shortColumnName, symbol);
        } catch (QueryMetadataException e) {
            throw new TeiidComponentException(QueryPlugin.Event.TEIID30559, e);
        }
    }
    return columnMetadata;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) Expression(org.teiid.query.sql.symbol.Expression) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) HashMap(java.util.HashMap) Map(java.util.Map) SymbolMap(org.teiid.query.sql.util.SymbolMap) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

Example 22 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class LanguageBridgeFactory method translate.

public NamedTable translate(GroupSymbol symbol) {
    String alias = null;
    String fullGroup = symbol.getOutputName();
    if (symbol.getOutputDefinition() != null) {
        alias = symbol.getOutputName();
        fullGroup = symbol.getOutputDefinition();
        if (remappedGroups != null) {
            GroupSymbol remappedGroup = remappedGroups.get(symbol.getMetadataID());
            if (remappedGroup != null && remappedGroup != symbol) {
                fullGroup = remappedGroup.getName();
            }
        }
    }
    fullGroup = removeSchemaName(fullGroup);
    NamedTable group = new NamedTable(fullGroup, alias, null);
    try {
        group.setMetadataObject(metadataFactory.getGroup(symbol.getMetadataID()));
    } catch (QueryMetadataException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30487, e);
    } catch (TeiidComponentException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30488, e);
    }
    return group;
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 23 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class AuthorizationValidationVisitor method validateEntitlements.

/**
 * Validate query entitlements
 */
protected void validateEntitlements(Query obj) {
    // If query contains SELECT INTO, validate INTO portion
    Into intoObj = obj.getInto();
    if (intoObj != null) {
        GroupSymbol intoGroup = intoObj.getGroup();
        Collection<LanguageObject> intoElements = new LinkedList<LanguageObject>();
        intoElements.add(intoGroup);
        try {
            intoElements.addAll(ResolverUtil.resolveElementsInGroup(intoGroup, getMetadata()));
        } catch (QueryMetadataException err) {
            handleException(err, intoGroup);
        } catch (TeiidComponentException err) {
            handleException(err, intoGroup);
        }
        validateEntitlements(intoElements, DataPolicy.PermissionType.CREATE, Context.INSERT);
    }
    // Validate this query's entitlements
    Collection<LanguageObject> entitledObjects = new ArrayList<LanguageObject>(GroupCollectorVisitor.getGroupsIgnoreInlineViews(obj, true));
    entitledObjects.addAll(ElementCollectorVisitor.getElements(obj, true));
    if (entitledObjects.size() == 0) {
        return;
    }
    validateEntitlements(entitledObjects, DataPolicy.PermissionType.READ, Context.QUERY);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 24 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class ConnectorWorkItem method convertToRuntimeType.

static Object convertToRuntimeType(BufferManager bm, Object value, Class<?> desiredType, CommandContext context) throws TransformationException {
    if (desiredType != DataTypeManager.DefaultDataClasses.XML || !(value instanceof Source)) {
        if (value instanceof DataSource) {
            final DataSource ds = (DataSource) value;
            try {
                // Teiid uses the datasource interface in a degenerate way that
                // reuses the stream, so we test for that here
                InputStream initial = ds.getInputStream();
                InputStream other = null;
                try {
                    other = ds.getInputStream();
                } catch (IOException e) {
                // likely streaming
                }
                if (other != null && initial != other) {
                    initial.close();
                    other.close();
                    if (value instanceof InputStreamFactory) {
                        return asLob((InputStreamFactory) value, desiredType);
                    }
                    return asLob(new InputStreamFactory() {

                        @Override
                        public InputStream getInputStream() throws IOException {
                            return ds.getInputStream();
                        }
                    }, desiredType);
                }
                // $NON-NLS-1$
                FileStore fs = bm.createFileStore("bytes");
                // TODO: guess at the encoding from the content type
                FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
                SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf);
                if (context != null) {
                    context.addCreatedLob(fsisf);
                }
                return asLob(is.getInputStreamFactory(), desiredType);
            } catch (IOException e) {
                throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage());
            }
        }
        if (value instanceof InputStreamFactory) {
            return asLob((InputStreamFactory) value, desiredType);
        }
        if (value instanceof GeometryInputSource) {
            GeometryInputSource gis = (GeometryInputSource) value;
            try {
                InputStream is = gis.getEwkb();
                if (is != null) {
                    return GeometryUtils.geometryFromEwkb(is, gis.getSrid());
                }
            } catch (Exception e) {
                throw new TransformationException(e);
            }
            try {
                Reader r = gis.getGml();
                if (r != null) {
                    return GeometryUtils.geometryFromGml(r, gis.getSrid());
                }
            } catch (Exception e) {
                throw new TransformationException(e);
            }
        }
    }
    if (value instanceof Source) {
        if (!(value instanceof InputStreamFactory)) {
            if (value instanceof StreamSource) {
                StreamSource ss = (StreamSource) value;
                InputStream is = ss.getInputStream();
                Reader r = ss.getReader();
                if (is == null && r != null) {
                    is = new ReaderInputStream(r, Streamable.CHARSET);
                }
                // $NON-NLS-1$
                final FileStore fs = bm.createFileStore("xml");
                final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
                value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory();
                if (context != null) {
                    context.addCreatedLob(fsisf);
                }
            } else if (value instanceof StAXSource) {
                // TODO: do this lazily.  if the first access to get the STaXSource, then
                // it's more efficient to let the processing happen against STaX
                StAXSource ss = (StAXSource) value;
                try {
                    // $NON-NLS-1$
                    final FileStore fs = bm.createFileStore("xml");
                    final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
                    value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory();
                    if (context != null) {
                        context.addCreatedLob(fsisf);
                    }
                } catch (XMLStreamException e) {
                    throw new TransformationException(e);
                }
            } else {
                // maybe dom or some other source we want to get out of memory
                StandardXMLTranslator sxt = new StandardXMLTranslator((Source) value);
                SQLXMLImpl sqlxml;
                try {
                    sqlxml = XMLSystemFunctions.saveToBufferManager(bm, sxt, context);
                } catch (TeiidComponentException e) {
                    throw new TransformationException(e);
                } catch (TeiidProcessingException e) {
                    throw new TransformationException(e);
                }
                return new XMLType(sqlxml);
            }
        }
        return new XMLType(new SQLXMLImpl((InputStreamFactory) value));
    }
    return DataTypeManager.convertToRuntimeType(value, desiredType != DataTypeManager.DefaultDataClasses.OBJECT);
}
Also used : SaveOnReadInputStream(org.teiid.dqp.internal.process.SaveOnReadInputStream) XMLInputStream(org.teiid.util.XMLInputStream) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) XMLInputStream(org.teiid.util.XMLInputStream) SaveOnReadInputStream(org.teiid.dqp.internal.process.SaveOnReadInputStream) ReaderInputStream(org.teiid.core.util.ReaderInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) GeometryInputSource(org.teiid.GeometryInputSource) Reader(java.io.Reader) IOException(java.io.IOException) StAXSource(javax.xml.transform.stax.StAXSource) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) GeometryInputSource(org.teiid.GeometryInputSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StAXSource(javax.xml.transform.stax.StAXSource) DataSource(javax.activation.DataSource) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) ResourceException(javax.resource.ResourceException) TeiidComponentException(org.teiid.core.TeiidComponentException) XMLStreamException(javax.xml.stream.XMLStreamException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) DataSource(javax.activation.DataSource) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FileStore(org.teiid.common.buffer.FileStore) ReaderInputStream(org.teiid.core.util.ReaderInputStream) XMLStreamException(javax.xml.stream.XMLStreamException) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 25 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class CachedFinder method findCapabilities.

/**
 * Find capabilities used the cache if possible, otherwise do the lookup.
 */
public SourceCapabilities findCapabilities(String modelName) throws TeiidComponentException {
    SourceCapabilities caps = userCache.get(modelName);
    if (caps != null) {
        return caps;
    }
    ModelMetaData model = vdb.getModel(modelName);
    List<String> sourceNames = model.getSourceNames();
    if (sourceNames.isEmpty()) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30499, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30499, modelName));
    }
    TeiidException cause = null;
    for (String sourceName : sourceNames) {
        // TOOD: in multi-source mode it may be necessary to compute minimal capabilities across the sources
        ConnectorManager mgr = this.connectorRepo.getConnectorManager(sourceName);
        if (mgr == null) {
            throw new TeiidComponentException(QueryPlugin.Event.TEIID30497, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30497, sourceName, modelName, sourceName));
        }
        try {
            caps = mgr.getCapabilities();
            break;
        } catch (TeiidException e) {
            cause = e;
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_DQP, e, "Could not obtain capabilities for" + sourceName);
        }
    }
    if (caps == null) {
        InvalidCaps ic = new InvalidCaps();
        ic.setSourceProperty(Capability.INVALID_EXCEPTION, cause);
        caps = ic;
    }
    userCache.put(modelName, caps);
    return caps;
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) SourceCapabilities(org.teiid.query.optimizer.capabilities.SourceCapabilities) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) TeiidException(org.teiid.core.TeiidException)

Aggregations

TeiidComponentException (org.teiid.core.TeiidComponentException)109 TeiidProcessingException (org.teiid.core.TeiidProcessingException)33 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)23 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)23 ArrayList (java.util.ArrayList)18 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)17 BlockedException (org.teiid.common.buffer.BlockedException)16 IOException (java.io.IOException)15 List (java.util.List)14 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)13 Test (org.junit.Test)12 LanguageObject (org.teiid.query.sql.LanguageObject)12 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)11 CommandContext (org.teiid.query.util.CommandContext)11 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)10 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)9 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 HashMap (java.util.HashMap)7 TeiidException (org.teiid.core.TeiidException)7 LogonException (org.teiid.client.security.LogonException)6