Search in sources :

Example 71 with TeiidRuntimeException

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();
}
Also used : XPathException(net.sf.saxon.trans.XPathException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TupleBatch(org.teiid.common.buffer.TupleBatch) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 72 with TeiidRuntimeException

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;
}
Also used : XPathExpression(net.sf.saxon.sxpath.XPathExpression) XPathException(net.sf.saxon.trans.XPathException) ArrayImpl(org.teiid.core.types.ArrayImpl) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) XMLColumn(org.teiid.query.sql.lang.XMLTable.XMLColumn) Item(net.sf.saxon.om.Item) XMLType(org.teiid.core.types.XMLType) PushBackSequenceIterator(org.teiid.query.xquery.saxon.PushBackSequenceIterator) SequenceIterator(net.sf.saxon.om.SequenceIterator) LanguageObject(org.teiid.query.sql.LanguageObject) PushBackSequenceIterator(org.teiid.query.xquery.saxon.PushBackSequenceIterator) XPathDynamicContext(net.sf.saxon.sxpath.XPathDynamicContext)

Example 73 with TeiidRuntimeException

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();
                        }
                    }
                }
            }
        });
    }
}
Also used : RequestWorkItem(org.teiid.dqp.internal.process.RequestWorkItem) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 74 with TeiidRuntimeException

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);
    }
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) ExpressionMappingVisitor(org.teiid.query.sql.visitor.ExpressionMappingVisitor) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) ResolverVisitor(org.teiid.query.resolver.util.ResolverVisitor) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 75 with TeiidRuntimeException

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;
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4