use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class TextTableNode method readChar.
private char readChar() throws TeiidProcessingException {
try {
int c = reader.read();
if (cr) {
if (c == newLine) {
c = reader.read();
}
cr = false;
}
switch(c) {
case '\r':
if (crNewLine) {
cr = true;
textLine++;
return newLine;
}
break;
case -1:
eof = true;
textLine++;
return newLine;
}
if (c == newLine) {
textLine++;
return newLine;
}
return (char) c;
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30179, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30179, systemId));
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class TextTableNode method initReader.
private void initReader() throws ExpressionEvaluationException, BlockedException, TeiidComponentException, TeiidProcessingException {
setReferenceValues(this.table);
ClobType file = (ClobType) getEvaluator(Collections.emptyMap()).evaluate(table.getFile(), null);
if (file == null) {
return;
}
// get the reader
try {
// $NON-NLS-1$
this.systemId = "Unknown";
if (file.getReference() instanceof ClobImpl) {
this.systemId = ((ClobImpl) file.getReference()).getStreamFactory().getSystemId();
if (this.systemId == null) {
// $NON-NLS-1$
this.systemId = "Unknown";
}
}
Reader r = file.getCharacterStream();
if (!(r instanceof BufferedReader)) {
reader = new BufferedReader(r);
} else {
reader = (BufferedReader) r;
}
} catch (SQLException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30180, e);
}
// process the skip field
if (skip <= 0) {
return;
}
while (textLine < skip) {
boolean isHeader = textLine == header;
if (isHeader) {
StringBuilder line = readLine(DataTypeManager.MAX_STRING_LENGTH * 16, false);
if (line == null) {
// just return an empty batch
reset();
return;
}
processHeader(parseLine(line));
} else {
while (readChar() != newLine) {
}
}
}
}
use of org.teiid.core.TeiidProcessingException 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.TeiidProcessingException in project teiid by teiid.
the class AccessNode method openInternal.
private void openInternal() throws TeiidComponentException, TeiidProcessingException {
// TODO: support a partitioning concept with multi-source and full dependent join pushdown
if (subPlans != null) {
if (this.evaluatedPlans == null) {
this.evaluatedPlans = new HashMap<GroupSymbol, SubqueryState>();
for (Map.Entry<GroupSymbol, RelationalPlan> entry : subPlans.entrySet()) {
SubqueryState state = new SubqueryState();
RelationalPlan value = entry.getValue();
value.reset();
state.processor = new QueryProcessor(value, getContext().clone(), getBufferManager(), getDataManager());
state.collector = state.processor.createBatchCollector();
this.evaluatedPlans.put(entry.getKey(), state);
}
}
BlockedException be = null;
for (SubqueryState state : evaluatedPlans.values()) {
try {
state.collector.collectTuples();
} catch (BlockedException e) {
be = e;
}
}
if (be != null) {
throw be;
}
}
/*
* Check to see if we need a multi-source expansion. If the connectorBindingExpression != null, then
* the logic below will handle that case
*/
if (multiSource && connectorBindingExpression == null) {
synchronized (this) {
// the description can be obtained asynchly, so we need to synchronize
VDBMetaData vdb = getContext().getVdb();
ModelMetaData model = vdb.getModel(getModelName());
List<String> sources = model.getSourceNames();
// make sure that we have the right nodes
if (this.getChildCount() != 0 && (this.sourceNames == null || !this.sourceNames.equals(sources))) {
this.childCount--;
this.getChildren()[0] = null;
}
if (this.getChildCount() == 0) {
sourceNames = sources;
RelationalNode node = multiSourceModify(this, connectorBindingExpression, getContext().getMetadata(), sourceNames);
RelationalPlan.connectExternal(node, getContext(), getDataManager(), getBufferManager());
this.addChild(node);
}
}
this.getChildren()[0].open();
return;
}
// Copy command and resolve references if necessary
if (processingCommand == null) {
processingCommand = command;
isUpdate = RelationalNodeUtil.isUpdate(command);
}
boolean needProcessing = true;
if (this.connectorBindingExpression != null && connectorBindingId == null) {
this.connectorBindingId = (String) getEvaluator(Collections.emptyMap()).evaluate(this.connectorBindingExpression, null);
VDBMetaData vdb = getContext().getVdb();
ModelMetaData model = vdb.getModel(getModelName());
List<String> sources = model.getSourceNames();
String replacement = this.connectorBindingId;
if (!sources.contains(this.connectorBindingId)) {
shouldExecute = false;
if (command instanceof StoredProcedure) {
StoredProcedure sp = (StoredProcedure) command;
if (sp.returnParameters() && sp.getProjectedSymbols().size() > sp.getResultSetColumns().size()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30561, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30561, command));
}
}
return;
}
if (!(command instanceof StoredProcedure || command instanceof Insert)) {
processingCommand = (Command) command.clone();
MultiSourceElementReplacementVisitor.visit(replacement, getContext().getMetadata(), processingCommand);
}
}
do {
Command atomicCommand = nextCommand();
if (shouldEvaluate) {
needProcessing = prepareNextCommand(atomicCommand);
nextCommand = null;
} else {
needProcessing = RelationalNodeUtil.shouldExecute(atomicCommand, true);
}
if (needProcessing) {
registerRequest(atomicCommand);
}
// We use an upper limit here to the currency because these commands have potentially large in-memory value sets
} while (!processCommandsIndividually() && hasNextCommand() && this.tupleSources.size() < Math.max(Math.min(MAX_CONCURRENT, this.getContext().getUserRequestSourceConcurrency()), this.getContext().getUserRequestSourceConcurrency() / 2));
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class ObjectTableNode method evaluate.
private void evaluate() throws TeiidComponentException, ExpressionEvaluationException, BlockedException, TeiidProcessingException {
if (result != null) {
return;
}
setReferenceValues(this.table);
Evaluator eval = getEvaluator(Collections.emptyMap());
eval.evaluateParameters(this.table.getPassing(), null, scriptContext.getBindings(ScriptContext.ENGINE_SCOPE));
Object value = evalScript(this.table.getCompiledScript(), this.table.getRowScript());
if (value instanceof Iterable<?>) {
result = ((Iterable<?>) value).iterator();
} else if (value instanceof Iterator<?>) {
result = (Iterator<?>) value;
} else if (value != null && value.getClass().isArray()) {
result = new ReflectiveArrayIterator(value);
} else if (value instanceof Array) {
try {
result = new ReflectiveArrayIterator(((Array) value).getArray());
} catch (SQLException e) {
throw new TeiidProcessingException(e);
}
} else {
result = Arrays.asList(value).iterator();
}
}
Aggregations