use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class RequestWorkItem method addCancelCode.
private Throwable addCancelCode(Throwable exception) {
String reason = null;
synchronized (this) {
reason = this.cancelReason;
}
if (exception instanceof TeiidException) {
TeiidException te = (TeiidException) exception;
if (SQLStates.QUERY_CANCELED.equals(te.getCode()) && EquivalenceUtil.areEqual(reason, te.getMessage())) {
return exception;
}
}
TeiidProcessingException tpe = new TeiidProcessingException(reason);
tpe.initCause(exception);
tpe.setCode(SQLStates.QUERY_CANCELED);
return tpe;
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class Evaluator method evaluateXMLForest.
private Object evaluateXMLForest(List<?> tuple, XMLForest function) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
List<DerivedColumn> args = function.getArgs();
Evaluator.NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args, true, true);
try {
return XMLSystemFunctions.xmlForest(context, namespaces(function.getNamespaces()), nameValuePairs);
} catch (TeiidProcessingException e) {
throw new FunctionExecutionException(e);
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class Evaluator method evaluate.
private Boolean evaluate(SubqueryCompareCriteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
// Evaluate expression
Object leftValue = null;
try {
leftValue = evaluate(criteria.getLeftExpression(), tuple);
} catch (ExpressionEvaluationException e) {
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30323, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30323, criteria));
}
// Need to be careful to initialize this variable carefully for the case
// where valueIterator has no values, and the block below is not entered.
// If there are no rows, and ALL is the predicate quantifier, the result
// should be true. If SOME is the predicate quantifier, or no quantifier
// is used, the result should be false.
Boolean result = Boolean.FALSE;
if (criteria.getPredicateQuantifier() == SubqueryCompareCriteria.ALL) {
result = Boolean.TRUE;
}
ValueIterator valueIter;
if (criteria.getCommand() != null) {
try {
valueIter = evaluateSubquery(criteria, tuple);
} catch (TeiidProcessingException e) {
throw new ExpressionEvaluationException(e);
}
} else {
Object array = evaluate(criteria.getArrayExpression(), tuple);
final Object[] vals;
if (array instanceof Object[]) {
vals = (Object[]) array;
} else {
ArrayImpl arrayImpl = (ArrayImpl) array;
vals = arrayImpl.getValues();
}
valueIter = new ValueIterator() {
int index = 0;
@Override
public void reset() {
index = 0;
}
@Override
public boolean hasNext() {
return index < vals.length;
}
@Override
public Object next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return vals[index++];
}
};
}
while (valueIter.hasNext()) {
Object value = valueIter.next();
// Shortcut if null
if (leftValue == null) {
return null;
}
if (value != null) {
Boolean comp = compare(criteria.getOperator(), leftValue, value);
switch(criteria.getPredicateQuantifier()) {
case SubqueryCompareCriteria.ALL:
if (Boolean.FALSE.equals(comp)) {
return Boolean.FALSE;
}
break;
case SubqueryCompareCriteria.SOME:
if (Boolean.TRUE.equals(comp)) {
return Boolean.TRUE;
}
break;
default:
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30326, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30326, criteria.getPredicateQuantifier()));
}
} else {
// value is null
switch(criteria.getPredicateQuantifier()) {
case SubqueryCompareCriteria.ALL:
if (Boolean.TRUE.equals(result)) {
result = null;
}
break;
case SubqueryCompareCriteria.SOME:
if (Boolean.FALSE.equals(result)) {
result = null;
}
break;
default:
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30326, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30326, criteria.getPredicateQuantifier()));
}
}
}
return result;
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class StringAgg method getResult.
/**
* @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext)
*/
public Object getResult(CommandContext commandContext) throws TeiidProcessingException {
if (this.result == null) {
this.result = buildResult(commandContext);
}
try {
this.result.getWriter().close();
FileStoreOutputStream fs = this.result.getOuputStream();
fs.close();
if (binary) {
if (fs.bytesWritten()) {
return new BlobType(new BlobImpl(result));
}
return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount())));
}
if (fs.bytesWritten()) {
return new ClobType(new ClobImpl(result, -1));
}
return new ClobType(new ClobImpl(new String(Arrays.copyOf(fs.getBuffer(), fs.getCount()), Streamable.ENCODING)));
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
} catch (SQLException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class TextAgg method buildResult.
private FileStoreInputStreamFactory buildResult(CommandContext context) throws TeiidProcessingException {
try {
// $NON-NLS-1$
FileStore fs = context.getBufferManager().createFileStore("textagg");
FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, textLine.getEncoding() == null ? Streamable.ENCODING : textLine.getEncoding());
Writer w = fisf.getWriter();
if (textLine.isIncludeHeader()) {
Object[] header = TextLine.evaluate(textLine.getExpressions(), new TextLine.ValueExtractor<DerivedColumn>() {
public Object getValue(DerivedColumn t) {
if (t.getAlias() == null && t.getExpression() instanceof ElementSymbol) {
return ((ElementSymbol) t.getExpression()).getShortName();
}
return t.getAlias();
}
}, textLine);
writeList(w, header);
}
w.flush();
return fisf;
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30420, e);
}
}
Aggregations