Search in sources :

Example 6 with TeiidProcessingException

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

the class Evaluator method evaluate.

private Object evaluate(ScalarSubquery scalarSubquery, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    Object result = null;
    ValueIterator valueIter;
    try {
        valueIter = evaluateSubquery(scalarSubquery, tuple);
    } catch (TeiidProcessingException e) {
        throw new ExpressionEvaluationException(e);
    }
    if (valueIter.hasNext()) {
        result = valueIter.next();
        if (valueIter.hasNext()) {
            // more than one result value - this is an exception case
            throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30345, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30345, scalarSubquery.getCommand()));
        }
    }
    return result;
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ValueIterator(org.teiid.query.sql.util.ValueIterator) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 7 with TeiidProcessingException

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

the class Evaluator method evaluate.

private Object evaluate(Function function, List<?> tuple) throws BlockedException, TeiidComponentException, ExpressionEvaluationException {
    // Get function based on resolved function info
    FunctionDescriptor fd = function.getFunctionDescriptor();
    // Evaluate args
    Expression[] args = function.getArgs();
    Object[] values = null;
    int start = 0;
    if (fd.requiresContext()) {
        values = new Object[args.length + 1];
        values[0] = context;
        start = 1;
    } else {
        values = new Object[args.length];
    }
    for (int i = 0; i < args.length; i++) {
        values[i + start] = internalEvaluate(args[i], tuple);
        if (values[i + start] instanceof Constant) {
            // $NON-NLS-1$
            throw new AssertionError("Multi-valued constant not allowed to be directly evaluated");
        }
    }
    if (fd.getPushdown() == PushDown.MUST_PUSHDOWN) {
        try {
            return evaluatePushdown(function, tuple, values);
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
    }
    if (fd.getProcedure() != null) {
        try {
            return evaluateProcedure(function, tuple, values);
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
    }
    // Check for special lookup function
    if (function.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)) {
        if (dataMgr == null) {
            throw new ComponentNotFoundException(QueryPlugin.Event.TEIID30342, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30342));
        }
        String codeTableName = (String) values[0];
        String returnElementName = (String) values[1];
        String keyElementName = (String) values[2];
        try {
            return dataMgr.lookupCodeValue(context, codeTableName, returnElementName, keyElementName, values[3]);
        } catch (TeiidProcessingException e) {
            throw new ExpressionEvaluationException(e);
        }
    }
    // Execute function
    return fd.invokeFunction(values, context, null);
}
Also used : ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) ComponentNotFoundException(org.teiid.core.ComponentNotFoundException) ExceptionExpression(org.teiid.query.sql.proc.ExceptionExpression) LanguageObject(org.teiid.query.sql.LanguageObject) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 8 with TeiidProcessingException

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

the class XMLSystemFunctions method saveToBufferManager.

/**
 * This method saves the given XML object to the buffer manager's disk process
 * Documents less than the maxMemorySize will be held directly in memory
 */
public static SQLXMLImpl saveToBufferManager(BufferManager bufferMgr, XMLTranslator translator, CommandContext context) throws TeiidComponentException, TeiidProcessingException {
    boolean success = false;
    // $NON-NLS-1$
    final FileStore lobBuffer = bufferMgr.createFileStore("xml");
    final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(lobBuffer, Streamable.ENCODING);
    try {
        Writer writer = fsisf.getWriter();
        final ExtendedWriter ew = new ExtendedWriter(writer, fsisf);
        translator.translate(ew);
        ew.close();
        success = true;
        return createSQLXML(fsisf, ew, context);
    } catch (IOException e) {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30444, e);
    } catch (TransformerException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30445, e);
    } finally {
        if (!success && lobBuffer != null) {
            lobBuffer.remove();
        }
    }
}
Also used : FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) TeiidComponentException(org.teiid.core.TeiidComponentException) XMLEventWriter(javax.xml.stream.XMLEventWriter) TransformerException(javax.xml.transform.TransformerException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 9 with TeiidProcessingException

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

the class XMLSystemFunctions method jsonToXml.

private static SQLXML jsonToXml(CommandContext context, final String rootName, final Reader r, boolean stream) throws TeiidComponentException, TeiidProcessingException {
    JSONParser parser = new JSONParser();
    final JsonToXmlContentHandler reader = new JsonToXmlContentHandler(rootName, r, parser, threadLocalEventtFactory.get());
    SQLXMLImpl sqlXml = null;
    if (stream) {
        try {
            // jre 1.7 event logic does not set a dummy location and throws an NPE in StAXSource, so we explicitly set a location
            // the streaming result will be directly consumed, so there's no danger that we're stepping on another location
            reader.eventFactory.setLocation(dummyLocation);
            sqlXml = new StAXSQLXML(new StAXSource(reader));
        } catch (XMLStreamException e) {
            throw new TeiidProcessingException(e);
        }
    } else {
        sqlXml = XMLSystemFunctions.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {

            @Override
            public void translate(Writer writer) throws TransformerException, IOException {
                try {
                    XMLOutputFactory factory = getOutputFactory();
                    final XMLEventWriter streamWriter = factory.createXMLEventWriter(writer);
                    streamWriter.add(reader);
                    // woodstox needs a flush rather than a close
                    streamWriter.flush();
                } catch (XMLStreamException e) {
                    throw new TransformerException(e);
                } finally {
                    try {
                        r.close();
                    } catch (IOException e) {
                    }
                }
            }
        }, context);
    }
    XMLType result = new XMLType(sqlXml);
    result.setType(Type.DOCUMENT);
    return result;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StAXSource(javax.xml.transform.stax.StAXSource) TeiidProcessingException(org.teiid.core.TeiidProcessingException) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventWriter(javax.xml.stream.XMLEventWriter) JSONParser(org.teiid.json.simple.JSONParser) XMLEventWriter(javax.xml.stream.XMLEventWriter) TransformerException(javax.xml.transform.TransformerException) StAXSQLXML(org.teiid.util.StAXSQLXML)

Example 10 with TeiidProcessingException

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

the class StringAgg method writeValue.

private void writeValue(Object val) throws TeiidProcessingException {
    try {
        if (binary) {
            if (val instanceof BinaryType) {
                result.getOuputStream().write(((BinaryType) val).getBytesDirect());
                return;
            }
            Blob b = (Blob) val;
            InputStream binaryStream = b.getBinaryStream();
            try {
                ObjectConverterUtil.write(result.getOuputStream(), binaryStream, -1, false);
            } finally {
                binaryStream.close();
            }
        } else {
            if (val instanceof String) {
                result.getWriter().write((String) val);
                return;
            }
            Clob c = (Clob) val;
            Reader characterStream = c.getCharacterStream();
            try {
                ObjectConverterUtil.write(result.getWriter(), characterStream, -1, false);
            } finally {
                characterStream.close();
            }
        }
    } catch (IOException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
    } catch (SQLException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
    }
}
Also used : SerialBlob(javax.sql.rowset.serial.SerialBlob) Blob(java.sql.Blob) BinaryType(org.teiid.core.types.BinaryType) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) Reader(java.io.Reader) IOException(java.io.IOException) Clob(java.sql.Clob) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6