use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class XMLTableNode method nextBatchDirect.
@Override
protected synchronized TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
evaluate(false);
if (streaming) {
while (state == State.BUILDING) {
try {
this.wait();
} catch (InterruptedException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30169, e);
}
}
unwrapException(asynchException);
TupleBatch batch = this.buffer.getBatch(outputRow);
outputRow = batch.getEndRow() + 1;
if (state != State.DONE && !batch.getTerminationFlag()) {
state = hasNextBatch() ? State.AVAILABLE : State.BUILDING;
}
return batch;
}
while (!isBatchFull() && !isLastBatch()) {
if (item == null) {
try {
item = result.iter.next();
} catch (XPathException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30170, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30170, e.getMessage()));
}
rowCount++;
if (item == null) {
terminateBatches();
break;
}
}
addBatchRow(processRow());
if (rowCount == rowLimit) {
terminateBatches();
break;
}
}
return pullBatch();
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class XMLTableNode method processRow.
private List<?> processRow() throws ExpressionEvaluationException, BlockedException, TeiidComponentException, TeiidProcessingException {
List<Object> tuple = new ArrayList<Object>(projectedColumns.size());
for (XMLColumn proColumn : projectedColumns) {
if (proColumn.isOrdinal()) {
if (rowCount > Integer.MAX_VALUE) {
throw new TeiidRuntimeException(new TeiidProcessingException(QueryPlugin.Event.TEIID31174, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31174)));
}
tuple.add((int) rowCount);
} else {
try {
XPathExpression path = proColumn.getPathExpression();
XPathDynamicContext dynamicContext = path.createDynamicContext(item);
final SequenceIterator pathIter = path.iterate(dynamicContext);
Item colItem = pathIter.next();
if (colItem == null) {
if (proColumn.getDefaultExpression() != null) {
tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null));
} else {
tuple.add(null);
}
continue;
}
if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) {
SequenceIterator pushBack = new PushBackSequenceIterator(pathIter, colItem);
XMLType value = table.getXQueryExpression().createXMLType(pushBack, this.getBufferManager(), false, getContext());
tuple.add(value);
continue;
}
if (proColumn.getSymbol().getType().isArray()) {
ArrayList<Object> vals = new ArrayList<Object>();
vals.add(getValue(proColumn.getSymbol().getType().getComponentType(), colItem, this.table.getXQueryExpression().getConfig(), getContext()));
Item next = null;
while ((next = pathIter.next()) != null) {
vals.add(getValue(proColumn.getSymbol().getType().getComponentType(), next, this.table.getXQueryExpression().getConfig(), getContext()));
}
Object value = new ArrayImpl(vals.toArray((Object[]) Array.newInstance(proColumn.getSymbol().getType().getComponentType(), vals.size())));
tuple.add(value);
continue;
} else if (pathIter.next() != null) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30171, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30171, proColumn.getName()));
}
Object value = getValue(proColumn.getSymbol().getType(), colItem, this.table.getXQueryExpression().getConfig(), getContext());
tuple.add(value);
} catch (XPathException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30172, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30172, proColumn.getName()));
}
}
}
item = null;
return tuple;
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class TextTableNode method processAsynch.
private void processAsynch() {
if (!running) {
running = true;
getContext().getExecutor().execute(new Runnable() {
@Override
public void run() {
try {
process();
} catch (TeiidRuntimeException e) {
asynchException = e;
} catch (Throwable e) {
asynchException = new TeiidRuntimeException(e);
} finally {
running = false;
RequestWorkItem workItem = TextTableNode.this.getContext().getWorkItem();
if (workItem != null) {
workItem.moreWork();
} else {
synchronized (TextTableNode.this) {
TextTableNode.this.notifyAll();
}
}
}
}
});
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class SimpleQueryResolver method resolveCommand.
/**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
Query query = (Query) command;
resolveWith(metadata, query);
try {
QueryResolverVisitor qrv = new QueryResolverVisitor(query, metadata);
qrv.visit(query);
ResolverVisitor visitor = (ResolverVisitor) qrv.getVisitor();
visitor.throwException(true);
if (visitor.hasUserDefinedAggregate()) {
ExpressionMappingVisitor emv = new ExpressionMappingVisitor(null) {
public Expression replaceExpression(Expression element) {
if (element instanceof Function && !(element instanceof AggregateSymbol) && ((Function) element).isAggregate()) {
Function f = (Function) element;
AggregateSymbol as = new AggregateSymbol(f.getName(), false, f.getArgs(), null);
as.setType(f.getType());
as.setFunctionDescriptor(f.getFunctionDescriptor());
return as;
}
return element;
}
};
PreOrPostOrderNavigator.doVisit(query, emv, PreOrPostOrderNavigator.POST_ORDER);
}
} catch (TeiidRuntimeException e) {
if (e.getCause() instanceof QueryMetadataException) {
throw (QueryMetadataException) e.getCause();
}
if (e.getCause() instanceof QueryResolverException) {
throw (QueryResolverException) e.getCause();
}
if (e.getCause() instanceof TeiidComponentException) {
throw (TeiidComponentException) e.getCause();
}
throw e;
}
if (query.getLimit() != null) {
ResolverUtil.resolveLimit(query.getLimit());
}
if (query.getOrderBy() != null) {
ResolverUtil.resolveOrderBy(query.getOrderBy(), query, metadata);
}
List<Expression> symbols = query.getSelect().getProjectedSymbols();
if (query.getInto() != null) {
GroupSymbol symbol = query.getInto().getGroup();
ResolverUtil.resolveImplicitTempGroup(metadata, symbol, symbols);
} else if (resolveNullLiterals) {
ResolverUtil.resolveNullLiterals(symbols);
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class RelationalNode method getProjectionIndexes.
/**
* Helper method for all the node that will filter the elements needed for the next node.
*/
public static int[] getProjectionIndexes(Map<? extends Expression, Integer> tupleElements, List<? extends Expression> projectElements) {
int[] result = new int[projectElements.size()];
int i = 0;
for (Expression symbol : projectElements) {
Integer index = tupleElements.get(symbol);
if (index == null) {
// $NON-NLS-1$
throw new TeiidRuntimeException("Planning error. Could not find symbol: " + symbol);
}
result[i++] = index;
}
return result;
}
Aggregations