Search in sources :

Example 1 with PushBackSequenceIterator

use of org.teiid.query.xquery.saxon.PushBackSequenceIterator 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)

Aggregations

ArrayList (java.util.ArrayList)1 Item (net.sf.saxon.om.Item)1 SequenceIterator (net.sf.saxon.om.SequenceIterator)1 XPathDynamicContext (net.sf.saxon.sxpath.XPathDynamicContext)1 XPathExpression (net.sf.saxon.sxpath.XPathExpression)1 XPathException (net.sf.saxon.trans.XPathException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 ArrayImpl (org.teiid.core.types.ArrayImpl)1 XMLType (org.teiid.core.types.XMLType)1 LanguageObject (org.teiid.query.sql.LanguageObject)1 XMLColumn (org.teiid.query.sql.lang.XMLTable.XMLColumn)1 PushBackSequenceIterator (org.teiid.query.xquery.saxon.PushBackSequenceIterator)1