use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class EvaluatorIterator method init.
@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) throws IOException {
super.init(source, options, env);
try {
GroupSymbol gs = null;
String query = options.get(QUERYSTRING);
TransformationMetadata tm = createTransformationMetadata(options.get(DDL));
this.criteria = QueryParser.getQueryParser().parseCriteria(query);
this.elementsInExpression = ElementCollectorVisitor.getElements(this.criteria, false);
for (ElementSymbol es : this.elementsInExpression) {
gs = es.getGroupSymbol();
ResolverUtil.resolveGroup(gs, tm);
}
ResolverVisitor.resolveLanguageObject(this.criteria, tm);
this.evaluatorUtil = new EvaluatorUtil(gs);
} catch (QueryParserException e) {
throw new IOException(e);
} catch (ClassNotFoundException e) {
throw new IOException(e);
} catch (QueryResolverException e) {
throw new IOException(e);
} catch (TeiidComponentException e) {
throw new IOException(e);
}
CommandContext cc = new CommandContext();
this.evaluator = new Evaluator(this.evaluatorUtil.getElementMap(), null, cc);
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class Evaluator method internalEvaluate.
protected Object internalEvaluate(Expression expression, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
if (expression instanceof DerivedExpression) {
if (elements != null) {
// Try to evaluate by lookup in the elements map (may work for both ElementSymbol and ExpressionSymbol
Integer index = (Integer) elements.get(expression);
if (index != null) {
return tuple.get(index.intValue());
}
}
// Otherwise this should be an ExpressionSymbol and we just need to dive in and evaluate the expression itself
if (expression instanceof ExpressionSymbol) {
ExpressionSymbol exprSyb = (ExpressionSymbol) expression;
Expression expr = exprSyb.getExpression();
return internalEvaluate(expr, tuple);
}
return getContext(expression).getFromContext(expression);
}
if (expression instanceof Constant) {
Constant c = (Constant) expression;
if (c.isMultiValued()) {
// $NON-NLS-1$
throw new AssertionError("Multi-valued constant not allowed to be directly evaluated");
}
return c.getValue();
} else if (expression instanceof Function) {
return evaluate((Function) expression, tuple);
} else if (expression instanceof CaseExpression) {
return evaluate((CaseExpression) expression, tuple);
} else if (expression instanceof SearchedCaseExpression) {
return evaluate((SearchedCaseExpression) expression, tuple);
} else if (expression instanceof Reference) {
Reference ref = (Reference) expression;
if (ref.isPositional() && ref.getExpression() == null) {
return getContext(ref).getVariableContext().getGlobalValue(ref.getContextSymbol());
}
Object result = getContext(ref.getExpression()).getFromContext(ref.getExpression());
if (ref.getConstraint() != null) {
try {
ref.getConstraint().validate(result);
} catch (QueryValidatorException e) {
throw new ExpressionEvaluationException(e);
}
}
return result;
} else if (expression instanceof Criteria) {
return evaluate((Criteria) expression, tuple);
} else if (expression instanceof ScalarSubquery) {
return evaluate((ScalarSubquery) expression, tuple);
} else if (expression instanceof Criteria) {
return evaluate((Criteria) expression, tuple);
} else if (expression instanceof TextLine) {
return evaluateTextLine(tuple, (TextLine) expression);
} else if (expression instanceof XMLElement) {
return evaluateXMLElement(tuple, (XMLElement) expression);
} else if (expression instanceof XMLForest) {
return evaluateXMLForest(tuple, (XMLForest) expression);
} else if (expression instanceof JSONObject) {
return evaluateJSONObject(tuple, (JSONObject) expression, null);
} else if (expression instanceof XMLSerialize) {
return evaluateXMLSerialize(tuple, (XMLSerialize) expression);
} else if (expression instanceof XMLQuery) {
return evaluateXMLQuery(tuple, (XMLQuery) expression, false);
} else if (expression instanceof QueryString) {
return evaluateQueryString(tuple, (QueryString) expression);
} else if (expression instanceof XMLParse) {
return evaluateXMLParse(tuple, (XMLParse) expression);
} else if (expression instanceof Array) {
Array array = (Array) expression;
List<Expression> exprs = array.getExpressions();
Object[] result = (Object[]) java.lang.reflect.Array.newInstance(array.getComponentType(), exprs.size());
for (int i = 0; i < exprs.size(); i++) {
Object eval = internalEvaluate(exprs.get(i), tuple);
if (eval instanceof ArrayImpl) {
eval = ((ArrayImpl) eval).getValues();
}
result[i] = eval;
}
return new ArrayImpl(result);
} else if (expression instanceof ExceptionExpression) {
return evaluate(tuple, (ExceptionExpression) expression);
} else if (expression instanceof XMLCast) {
return evaluate(tuple, (XMLCast) expression);
} else {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30329, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30329, expression.getClass().getName()));
}
}
use of org.teiid.core.TeiidComponentException 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.TeiidComponentException in project teiid by teiid.
the class DatabaseStore method getSchemaRecord.
public AbstractMetadataRecord getSchemaRecord(String name, Database.ResourceType type) {
TransformationMetadata qmi = getTransformationMetadata();
try {
switch(type) {
case TABLE:
GroupSymbol gs = new GroupSymbol(name);
ResolverUtil.resolveGroup(gs, qmi);
Table t = (Table) gs.getMetadataID();
if (t == null) {
throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31245, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31245, name, getCurrentDatabase().getName(), getCurrentSchema().getName()));
}
return t;
case PROCEDURE:
StoredProcedureInfo sp = qmi.getStoredProcedureInfoForProcedure(name);
if (sp == null) {
throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31213, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31213, name, getCurrentSchema().getName(), getCurrentDatabase().getName()));
}
if (sp.getProcedureID() instanceof Procedure) {
return (Procedure) sp.getProcedureID();
}
return null;
case COLUMN:
Column c = qmi.getElementID(name);
if (c == null) {
throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31223, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31223, name));
}
return c;
case DATABASE:
return getCurrentDatabase();
case SCHEMA:
Schema schema = qmi.getModelID(name);
if (schema == null) {
throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31234, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31234, name, getCurrentDatabase().getName()));
}
return schema;
case SERVER:
Server server = getCurrentDatabase().getServer(name);
if (server == null) {
throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31220, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31220, name, getCurrentDatabase().getName()));
}
return server;
case DATAWRAPPER:
DataWrapper dw = getCurrentDatabase().getDataWrapper(name);
if (dw == null) {
throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31247, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31247, name, getCurrentDatabase().getName()));
}
return dw;
default:
break;
}
} catch (TeiidComponentException e) {
throw new MetadataException(e);
} catch (QueryResolverException e) {
throw new MetadataException(e);
}
return null;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class AutoGenDataService method registerRequest.
@Override
public ConnectorWork registerRequest(AtomicRequestMessage message) throws TeiidComponentException {
List projectedSymbols = (message.getCommand()).getProjectedSymbols();
List[] results = createResults(projectedSymbols, rows, useIntCounter);
if (RelationalNodeUtil.isUpdate(message.getCommand())) {
results = new List[] { Arrays.asList(1) };
}
final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results);
msg.setFinalRow(rows);
return new ConnectorWork() {
boolean returnedInitial;
@Override
public boolean isDataAvailable() {
return dataAvailable;
}
@Override
public AtomicResultsMessage more() throws TranslatorException {
if (dataNotAvailable != null) {
int delay = dataNotAvailable;
dataNotAvailable = null;
DataNotAvailableException dnae = new DataNotAvailableException(delay);
dnae.setStrict(strict);
throw dnae;
}
if (addWarning) {
msg.setWarnings(Arrays.asList(new Exception()));
}
if (!returnedInitial) {
returnedInitial = true;
return msg;
}
// $NON-NLS-1$
throw new RuntimeException("Should not be called");
}
@Override
public void execute() throws TranslatorException {
executeCount.incrementAndGet();
if (sleep > 0) {
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
if (latch != null) {
try {
latch.countDown();
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
if (throwExceptionOnExecute) {
// $NON-NLS-1$
throw new TranslatorException("Connector Exception");
}
}
@Override
public void close() {
closeCount.incrementAndGet();
}
@Override
public void cancel(boolean abnormal) {
}
@Override
public CacheDirective getCacheDirective() {
return cacheDirective;
}
@Override
public boolean isForkable() {
return true;
}
@Override
public boolean isThreadBound() {
return threadBound;
}
@Override
public AtomicRequestID getId() {
return null;
}
};
}
Aggregations