Search in sources :

Example 76 with TeiidRuntimeException

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

the class GlobalTableStoreImpl method getState.

@Override
public void getState(OutputStream ostream) {
    try {
        ObjectOutputStream oos = new ObjectOutputStream(ostream);
        for (Map.Entry<String, TempTable> entry : tableStore.getTempTables().entrySet()) {
            sendTable(entry.getKey(), oos, true);
        }
        oos.writeObject(null);
        oos.close();
    } catch (IOException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30217, e);
    } catch (TeiidComponentException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30218, e);
    }
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ObjectOutputStream(java.io.ObjectOutputStream) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SymbolMap(org.teiid.query.sql.util.SymbolMap)

Example 77 with TeiidRuntimeException

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

the class GlobalTableStoreImpl method setState.

@Override
public void setState(InputStream istream) {
    try {
        ObjectInputStream ois = new ObjectInputStream(istream);
        while (true) {
            String tableName = (String) ois.readObject();
            if (tableName == null) {
                break;
            }
            loadTable(tableName, ois);
        }
        ois.close();
    } catch (Exception e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30219, e);
    }
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 78 with TeiidRuntimeException

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

the class XQueryEvaluator method evaluateXMLQuery.

/**
 * @param tuple
 * @param xmlQuery
 * @param exists - check only for the existence of a non-empty result
 * @return Boolean if exists is true, otherwise an XMLType value
 * @throws BlockedException
 * @throws TeiidComponentException
 * @throws FunctionExecutionException
 */
public static Object evaluateXMLQuery(List<?> tuple, XMLQuery xmlQuery, boolean exists, Map<String, Object> parameters, CommandContext context) throws BlockedException, TeiidComponentException, FunctionExecutionException {
    boolean emptyOnEmpty = xmlQuery.getEmptyOnEmpty() == null || xmlQuery.getEmptyOnEmpty();
    Result result = null;
    try {
        XMLQueryRowProcessor rp = null;
        if (xmlQuery.getXQueryExpression().isStreaming()) {
            rp = new XMLQueryRowProcessor(exists, context);
        }
        try {
            Object contextItem = null;
            if (parameters.containsKey(null)) {
                contextItem = parameters.remove(null);
                if (contextItem == null) {
                    return null;
                }
            }
            result = evaluateXQuery(xmlQuery.getXQueryExpression(), contextItem, parameters, rp, context);
            if (result == null) {
                return null;
            }
            if (exists) {
                if (result.iter.next() == null) {
                    return false;
                }
                return true;
            }
        } catch (TeiidRuntimeException e) {
            if (e.getCause() instanceof XPathException) {
                throw (XPathException) e.getCause();
            }
            throw e;
        }
        if (rp != null) {
            if (exists) {
                return rp.hasItem;
            }
            XMLType.Type type = rp.type;
            if (type == null) {
                if (!emptyOnEmpty) {
                    return null;
                }
                type = Type.CONTENT;
            }
            XMLType val = rp.concat.close(context);
            val.setType(rp.type);
            return val;
        }
        return xmlQuery.getXQueryExpression().createXMLType(result.iter, context.getBufferManager(), emptyOnEmpty, context);
    } catch (TeiidProcessingException e) {
        throw new FunctionExecutionException(QueryPlugin.Event.TEIID30333, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30333, e.getMessage()));
    } catch (XPathException e) {
        throw new FunctionExecutionException(QueryPlugin.Event.TEIID30333, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30333, e.getMessage()));
    } finally {
        if (result != null) {
            result.close();
        }
    }
}
Also used : XMLType(org.teiid.core.types.XMLType) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) XPathException(net.sf.saxon.trans.XPathException) Type(org.teiid.core.types.XMLType.Type) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) StreamResult(javax.xml.transform.stream.StreamResult) Result(org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result) QueryResult(net.sf.saxon.query.QueryResult) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 79 with TeiidRuntimeException

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

the class XQueryEvaluator method evaluateXQuery.

public static SaxonXQueryExpression.Result evaluateXQuery(final SaxonXQueryExpression xquery, Object context, Map<String, Object> parameterValues, final RowProcessor processor, CommandContext commandContext) throws TeiidProcessingException, TeiidComponentException {
    DynamicQueryContext dynamicContext = new DynamicQueryContext(xquery.config);
    SaxonXQueryExpression.Result result = new SaxonXQueryExpression.Result();
    try {
        for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
            try {
                Object value = entry.getValue();
                Sequence s = null;
                if (value instanceof SQLXML) {
                    value = XMLSystemFunctions.convertToSource(value);
                    result.sources.add((Source) value);
                    Source source = wrapStax((Source) value);
                    s = xquery.config.buildDocumentTree(source).getRootNode();
                } else if (value instanceof java.util.Date) {
                    s = XQueryEvaluator.convertToAtomicValue(value);
                } else if (value instanceof BinaryType) {
                    s = new HexBinaryValue(((BinaryType) value).getBytesDirect());
                }
                dynamicContext.setParameter(StructuredQName.fromClarkName(entry.getKey()), s);
            } catch (TransformerException e) {
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30148, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30148, entry.getKey()));
            }
        }
        if (context != null) {
            Source source = XMLSystemFunctions.convertToSource(context);
            result.sources.add(source);
            source = wrapStax(source);
            if (xquery.contextRoot != null) {
                // create our own filter as this logic is not provided in the free saxon
                AugmentedSource sourceInput = AugmentedSource.makeAugmentedSource(source);
                sourceInput.addFilter(new FilterFactory() {

                    @Override
                    public ProxyReceiver makeFilter(Receiver arg0) {
                        return new PathMapFilter(xquery.contextRoot, arg0);
                    }
                });
                source = sourceInput;
                // use streamable processing instead
                if (xquery.streamingPath != null && processor != null) {
                    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
                        // $NON-NLS-1$
                        LogManager.logDetail(LogConstants.CTX_DQP, "Using stream processing for evaluation of", xquery.xQueryString);
                    }
                    // set to non-blocking in case default expression evaluation blocks
                    boolean isNonBlocking = commandContext.isNonBlocking();
                    commandContext.setNonBlocking(true);
                    final StreamingTransform myTransform = new StreamingTransform() {

                        public Nodes transform(Element elem) {
                            processor.processRow(XQueryEvaluator.wrap(elem, xquery.config));
                            return NONE;
                        }
                    };
                    Builder builder = new Builder(new SaxonReader(xquery.config, sourceInput), false, new StreamingPathFilter(xquery.streamingPath, xquery.namespaceMap).createNodeFactory(null, myTransform));
                    try {
                        // the builder is hard wired to parse the source, but the api will throw an exception if the stream is null
                        builder.build(FAKE_IS);
                        return result;
                    } catch (ParsingException e) {
                        if (e.getCause() instanceof TeiidRuntimeException) {
                            RelationalNode.unwrapException((TeiidRuntimeException) e.getCause());
                        }
                        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
                    } catch (IOException e) {
                        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
                    } finally {
                        if (!isNonBlocking) {
                            commandContext.setNonBlocking(false);
                        }
                    }
                }
            }
            TreeInfo doc;
            try {
                doc = xquery.config.buildDocumentTree(source);
            } catch (XPathException e) {
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
            }
            dynamicContext.setContextItem(doc.getRootNode());
        }
        try {
            result.iter = xquery.xQuery.iterator(dynamicContext);
            return result;
        } catch (TransformerException e) {
            throw new TeiidProcessingException(QueryPlugin.Event.TEIID30152, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30152));
        }
    } finally {
        if (result.iter == null) {
            result.close();
        }
    }
}
Also used : XPathException(net.sf.saxon.trans.XPathException) Element(nu.xom.Element) Builder(nu.xom.Builder) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StAXSource(javax.xml.transform.stax.StAXSource) AugmentedSource(net.sf.saxon.lib.AugmentedSource) FilterFactory(net.sf.saxon.event.FilterFactory) StreamingPathFilter(nux.xom.xquery.StreamingPathFilter) StreamResult(javax.xml.transform.stream.StreamResult) Result(org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result) QueryResult(net.sf.saxon.query.QueryResult) TeiidProcessingException(org.teiid.core.TeiidProcessingException) DynamicQueryContext(net.sf.saxon.query.DynamicQueryContext) ParsingException(nu.xom.ParsingException) TransformerException(javax.xml.transform.TransformerException) BinaryType(org.teiid.core.types.BinaryType) HexBinaryValue(net.sf.saxon.value.HexBinaryValue) Receiver(net.sf.saxon.event.Receiver) ProxyReceiver(net.sf.saxon.event.ProxyReceiver) Sequence(net.sf.saxon.om.Sequence) IOException(java.io.IOException) SQLXML(java.sql.SQLXML) Result(org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result) StreamingTransform(nux.xom.xquery.StreamingTransform) TreeInfo(net.sf.saxon.om.TreeInfo) Map(java.util.Map) AugmentedSource(net.sf.saxon.lib.AugmentedSource) ProxyReceiver(net.sf.saxon.event.ProxyReceiver)

Example 80 with TeiidRuntimeException

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

the class CommandBuilder method getCommand.

public org.teiid.language.Command getCommand(String queryString, boolean generateAliases, boolean supportsGroupAlias) {
    Command command = null;
    try {
        command = QueryParser.getQueryParser().parseCommand(queryString);
        QueryResolver.resolveCommand(command, metadata);
        command = QueryRewriter.rewrite(command, metadata, null);
        expandAllSymbol(command);
        if (generateAliases) {
            command = (Command) command.clone();
            command.acceptVisitor(new AliasGenerator(supportsGroupAlias));
        }
        // the language bridge doesn't expect References
        ValueIteratorProviderCollectorVisitor v = new ValueIteratorProviderCollectorVisitor();
        v.setCollectLateral(true);
        PreOrderNavigator.doVisit(command, v);
        for (SubqueryContainer<?> container : v.getValueIteratorProviders()) {
            ExpressionMappingVisitor visitor = new ExpressionMappingVisitor(null) {

                @Override
                public Expression replaceExpression(Expression element) {
                    if (element instanceof Reference) {
                        return ((Reference) element).getExpression();
                    }
                    return element;
                }
            };
            DeepPostOrderNavigator.doVisit(command, visitor);
        }
        return languageBridgeFactory.translate(command);
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : Command(org.teiid.query.sql.lang.Command) AliasGenerator(org.teiid.query.optimizer.relational.AliasGenerator) Expression(org.teiid.query.sql.symbol.Expression) Reference(org.teiid.query.sql.symbol.Reference) ValueIteratorProviderCollectorVisitor(org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExpressionMappingVisitor(org.teiid.query.sql.visitor.ExpressionMappingVisitor) TeiidException(org.teiid.core.TeiidException)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4