use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class UpdateProcedureResolver method collectDeclareVariable.
private void collectDeclareVariable(DeclareStatement obj, GroupSymbol variables, TempMetadataAdapter metadata, GroupContext externalGroups) throws QueryResolverException, TeiidComponentException {
ElementSymbol variable = obj.getVariable();
String typeName = obj.getVariableType();
GroupSymbol gs = variable.getGroupSymbol();
if (gs == null) {
String outputName = variable.getShortName();
variable.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.VARIABLES));
variable.setOutputName(outputName);
} else {
if (gs.getSchema() != null || !gs.getShortName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) {
// $NON-NLS-1$
handleUnresolvableDeclaration(variable, QueryPlugin.Util.getString("ERR.015.010.0031", new Object[] { ProcedureReservedWords.VARIABLES, variable }));
}
}
boolean exists = false;
try {
ResolverVisitor.resolveLanguageObject(variable, null, externalGroups, metadata);
exists = true;
} catch (QueryResolverException e) {
// ignore, not already defined
}
if (exists) {
// $NON-NLS-1$
handleUnresolvableDeclaration(variable, QueryPlugin.Util.getString("ERR.015.010.0032", variable.getOutputName()));
}
boolean exception = typeName.equalsIgnoreCase(SQLConstants.NonReserved.EXCEPTION);
variable.setType(exception ? DataTypeManager.DefaultDataClasses.OBJECT : DataTypeManager.getDataTypeClass(typeName));
variable.setGroupSymbol(variables);
TempMetadataID id = new TempMetadataID(variable.getName(), exception ? Exception.class : variable.getType());
id.setUpdatable(true);
variable.setMetadataID(id);
// TODO: this will cause the variables group to loose it's cache of resolved symbols
metadata.getMetadataStore().addElementToTempGroup(ProcedureReservedWords.VARIABLES, variable.clone());
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class WindowFunctionProjectNode method saveInput.
/**
* Save the input generating any necessary expressions and adding a row id
* @param collectedExpressions
* @return
* @throws TeiidComponentException
* @throws TeiidProcessingException
*/
private void saveInput() throws TeiidComponentException, TeiidProcessingException {
if (inputTs == null) {
List<Expression> collectedExpressions = new ArrayList<Expression>(expressionIndexes.keySet());
Evaluator eval = new Evaluator(elementMap, getDataManager(), getContext());
final RelationalNode sourceNode = this.getChildren()[0];
inputTs = new ProjectingTupleSource(sourceNode, eval, collectedExpressions, elementMap) {
int index = 0;
@Override
public List<Object> nextTuple() throws TeiidComponentException, TeiidProcessingException {
List<Object> tuple = super.nextTuple();
if (tuple != null) {
tuple.add(index++);
}
return tuple;
}
};
List<ElementSymbol> schema = new ArrayList<ElementSymbol>(collectedExpressions.size() + 1);
int index = 0;
for (Expression ex : collectedExpressions) {
ElementSymbol es = new ElementSymbol(String.valueOf(index++));
es.setType(ex.getType());
schema.add(es);
}
// add in the row id
ElementSymbol es = new ElementSymbol(String.valueOf(index++));
es.setType(DataTypeManager.DefaultDataClasses.INTEGER);
schema.add(es);
tb = this.getBufferManager().createTupleBuffer(schema, this.getConnectionID(), TupleSourceType.PROCESSOR);
}
List<?> tuple = null;
while ((tuple = inputTs.nextTuple()) != null) {
tb.addTuple(tuple);
}
tb.close();
inputTs.closeSource();
inputTs = null;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class XMLTableNode method evaluate.
private void evaluate(final boolean useFinalBuffer) throws TeiidComponentException, ExpressionEvaluationException, BlockedException, TeiidProcessingException {
if (result != null || this.buffer != null) {
return;
}
setReferenceValues(this.table);
final HashMap<String, Object> parameters = new HashMap<String, Object>();
Evaluator eval = getEvaluator(Collections.emptyMap());
eval.evaluateParameters(this.table.getPassing(), null, parameters);
final Object contextItem;
if (parameters.containsKey(null)) {
contextItem = parameters.remove(null);
// null context item mean no rows
if (contextItem == null) {
result = new Result();
result.iter = EmptyIterator.emptyIterator();
streaming = false;
return;
}
} else {
contextItem = null;
}
if (this.table.getXQueryExpression().isStreaming()) {
if (this.buffer == null) {
this.buffer = this.getBufferManager().createTupleBuffer(getOutputElements(), getConnectionID(), TupleSourceType.PROCESSOR);
if (!useFinalBuffer) {
this.buffer.setForwardOnly(true);
}
}
Runnable r = new Runnable() {
@Override
public void run() {
try {
XQueryEvaluator.evaluateXQuery(table.getXQueryExpression(), contextItem, parameters, XMLTableNode.this, getContext());
} catch (TeiidRuntimeException e) {
if (e != EARLY_TERMINATION) {
asynchException = e;
}
} catch (Throwable e) {
asynchException = new TeiidRuntimeException(e);
} finally {
synchronized (XMLTableNode.this) {
if (buffer != null && asynchException == null) {
try {
buffer.close();
} catch (TeiidComponentException e) {
asynchException = new TeiidRuntimeException(e);
}
}
state = State.DONE;
XMLTableNode.this.notifyAll();
}
}
}
};
this.getContext().getExecutor().execute(r);
return;
}
try {
result = XQueryEvaluator.evaluateXQuery(this.table.getXQueryExpression(), contextItem, parameters, null, this.getContext());
} catch (TeiidRuntimeException e) {
unwrapException(e);
}
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class QueryResolver method parseBindings.
/**
* Bindings are a poor mans input parameters. They are represented in legacy metadata
* by ElementSymbols and placed positionally into the command or by alias symbols
* and matched by names.
* @param planNode
* @return
* @throws TeiidComponentException
*/
public static List<Expression> parseBindings(QueryNode planNode) throws TeiidComponentException {
Collection<String> bindingsCol = planNode.getBindings();
if (bindingsCol == null) {
return Collections.emptyList();
}
List<Expression> parsedBindings = new ArrayList<Expression>(bindingsCol.size());
for (Iterator<String> bindings = bindingsCol.iterator(); bindings.hasNext(); ) {
try {
Expression binding = QueryParser.getQueryParser().parseSelectExpression(bindings.next());
parsedBindings.add(binding);
} catch (QueryParserException err) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30063, err);
}
}
return parsedBindings;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class QueryProcessor method nextBatchDirect.
private TupleBatch nextBatchDirect() throws BlockedException, TeiidProcessingException, TeiidComponentException {
boolean done = false;
TupleBatch result = null;
try {
init();
long currentTime = System.currentTimeMillis();
Assertion.assertTrue(!processorClosed);
while (currentTime < context.getTimeSliceEnd() || context.isNonBlocking()) {
if (requestCanceled) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, this.context.getRequestId()));
}
if (currentTime > context.getTimeoutEnd()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30161, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30161));
}
result = processPlan.nextBatch();
if (continuous) {
result.setRowOffset(rowOffset);
if (result.getTerminationFlag()) {
result.setTermination(TupleBatch.ITERATION_TERMINATED);
List<Object> terminationTuple = Arrays.asList(new Object[this.getOutputElements().size()]);
result.getTuples().add(terminationTuple);
this.context.getTupleSourceCache().close();
this.processPlan.close();
this.processPlan.reset();
this.context.incrementReuseCount();
this.open = false;
}
rowOffset = result.getEndRow() + 1;
}
if (result.getTermination() != TupleBatch.NOT_TERMINATED) {
if (result.getTerminationFlag()) {
done = true;
}
break;
}
if (result.getRowCount() > 0) {
break;
}
}
} catch (BlockedException e) {
throw e;
} catch (TeiidException e) {
closeProcessing();
if (e instanceof TeiidProcessingException) {
throw (TeiidProcessingException) e;
}
if (e instanceof TeiidComponentException) {
throw (TeiidComponentException) e;
}
throw new TeiidComponentException(QueryPlugin.Event.TEIID30162, e);
}
if (done) {
closeProcessing();
}
if (result == null) {
RequestWorkItem workItem = this.getContext().getWorkItem();
if (workItem != null) {
// if we have a workitem (non-test scenario) then before
// throwing exprired time slice we need to indicate there's more work
workItem.moreWork();
}
throw EXPIRED_TIME_SLICE;
}
return result;
}
Aggregations