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;
}
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);
}
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();
}
}
}
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;
}
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);
}
}
Aggregations