Search in sources :

Example 11 with TeiidComponentException

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());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 12 with TeiidComponentException

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;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ArrayList(java.util.ArrayList) ProjectingTupleSource(org.teiid.query.processor.relational.GroupingNode.ProjectingTupleSource) Evaluator(org.teiid.query.eval.Evaluator) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Expression(org.teiid.query.sql.symbol.Expression) TeiidComponentException(org.teiid.core.TeiidComponentException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with TeiidComponentException

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);
    }
}
Also used : HashMap(java.util.HashMap) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) XQueryEvaluator(org.teiid.query.xquery.saxon.XQueryEvaluator) Evaluator(org.teiid.query.eval.Evaluator) ConversionResult(net.sf.saxon.type.ConversionResult) Result(org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result)

Example 14 with TeiidComponentException

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;
}
Also used : QueryParserException(org.teiid.api.exception.query.QueryParserException) Expression(org.teiid.query.sql.symbol.Expression) ArrayList(java.util.ArrayList) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 15 with TeiidComponentException

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;
}
Also used : RequestWorkItem(org.teiid.dqp.internal.process.RequestWorkItem) TeiidComponentException(org.teiid.core.TeiidComponentException) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException)

Aggregations

TeiidComponentException (org.teiid.core.TeiidComponentException)109 TeiidProcessingException (org.teiid.core.TeiidProcessingException)33 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)23 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)23 ArrayList (java.util.ArrayList)18 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)17 BlockedException (org.teiid.common.buffer.BlockedException)16 IOException (java.io.IOException)15 List (java.util.List)14 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)13 Test (org.junit.Test)12 LanguageObject (org.teiid.query.sql.LanguageObject)12 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)11 CommandContext (org.teiid.query.util.CommandContext)11 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)10 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)9 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 HashMap (java.util.HashMap)7 TeiidException (org.teiid.core.TeiidException)7 LogonException (org.teiid.client.security.LogonException)6