Search in sources :

Example 1 with PathMapArc

use of net.sf.saxon.expr.parser.PathMap.PathMapArc in project teiid by teiid.

the class PathMapFilter method startElement.

@Override
public void startElement(NodeName elemName, SchemaType typeCode, Location locationId, int properties) throws XPathException {
    MatchContext mc = matchContext.getLast();
    MatchContext newContext = new MatchContext();
    if (mc.elementArcs != null) {
        for (PathMapArc arc : mc.elementArcs) {
            NodeTest test = arc.getNodeTest();
            if (test == null || test.matches(Type.ELEMENT, elemName, typeCode)) {
                newContext.bulidContext(arc.getTarget());
                newContext.matchedElement = true;
                if (arc.getTarget().isAtomized() && arc.getTarget().getArcs().length == 0) {
                    // we must expect the text as there are no further arcs
                    newContext.matchesText = true;
                }
            }
            if (arc.getAxis() == AxisInfo.DESCENDANT || arc.getAxis() == AxisInfo.DESCENDANT_OR_SELF) {
                newContext.processArc(arc);
            }
        }
    }
    matchContext.add(newContext);
    if (newContext.matchedElement) {
        super.startElement(elemName, typeCode, locationId, properties);
    } else if (logTrace) {
        // $NON-NLS-1$
        LogManager.logTrace(LogConstants.CTX_RUNTIME, "Document projection did not match element", elemName.getURI(), ':', elemName.getLocalPart());
    }
}
Also used : PathMapArc(net.sf.saxon.expr.parser.PathMap.PathMapArc) NodeTest(net.sf.saxon.pattern.NodeTest)

Example 2 with PathMapArc

use of net.sf.saxon.expr.parser.PathMap.PathMapArc in project teiid by teiid.

the class SaxonXQueryExpression method validateColumnForStreaming.

private boolean validateColumnForStreaming(AnalysisRecord record, XMLColumn xmlColumn, PathMapArc arc) {
    boolean ancestor = false;
    LinkedList<PathMapArc> arcStack = new LinkedList<PathMapArc>();
    arcStack.add(arc);
    while (!arcStack.isEmpty()) {
        PathMapArc current = arcStack.removeFirst();
        byte axis = current.getAxis();
        if (ancestor) {
            if (current.getTarget().isReturnable()) {
                if (axis != AxisInfo.NAMESPACE && axis != AxisInfo.ATTRIBUTE) {
                    if (record.recordAnnotations()) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM);
                    }
                    return false;
                }
            }
            if (!isValidAncestorAxis[axis]) {
                if (record.recordAnnotations()) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM);
                }
                return false;
            }
        } else if (!AxisInfo.isSubtreeAxis[axis]) {
            if (axis == AxisInfo.PARENT || axis == AxisInfo.ANCESTOR || axis == AxisInfo.ANCESTOR_OR_SELF) {
                if (current.getTarget().isReturnable()) {
                    if (record.recordAnnotations()) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        record.addAnnotation(XQUERY_PLANNING, "The column path contains an invalid reverse axis " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM);
                    }
                    return false;
                }
                ancestor = true;
            } else {
                if (record.recordAnnotations()) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    record.addAnnotation(XQUERY_PLANNING, "The column path may not reference an ancestor or subtree " + xmlColumn.getPath(), "Document streaming will not be used", Priority.MEDIUM);
                }
                return false;
            }
        }
        for (PathMapArc pathMapArc : current.getTarget().getArcs()) {
            arcStack.add(pathMapArc);
        }
    }
    return true;
}
Also used : PathMapArc(net.sf.saxon.expr.parser.PathMap.PathMapArc) LinkedList(java.util.LinkedList)

Example 3 with PathMapArc

use of net.sf.saxon.expr.parser.PathMap.PathMapArc in project teiid by teiid.

the class SaxonXQueryExpression method showArcs.

public static void showArcs(StringBuilder sb, PathMapNode node, int level) {
    for (PathMapArc pathMapArc : node.getArcs()) {
        char[] pad = new char[level * 2];
        Arrays.fill(pad, ' ');
        sb.append(new String(pad));
        sb.append(AxisInfo.axisName[pathMapArc.getAxis()]);
        sb.append(pathMapArc.getNodeTest());
        sb.append('\n');
        node = pathMapArc.getTarget();
        showArcs(sb, node, level + 1);
    }
}
Also used : PathMapArc(net.sf.saxon.expr.parser.PathMap.PathMapArc)

Example 4 with PathMapArc

use of net.sf.saxon.expr.parser.PathMap.PathMapArc in project teiid by teiid.

the class SaxonXQueryExpression method projectColumns.

private PathMapRoot projectColumns(PathMapRoot parentRoot, List<XMLTable.XMLColumn> columns, PathMapNode finalNode, AnalysisRecord record) {
    for (XMLColumn xmlColumn : columns) {
        if (xmlColumn.isOrdinal()) {
            continue;
        }
        Expression internalExpression = xmlColumn.getPathExpression().getInternalExpression();
        PathMap subMap = new PathMap(internalExpression);
        PathMapRoot subContextRoot = null;
        for (PathMapRoot root : subMap.getPathMapRoots()) {
            if (root.getRootExpression() instanceof ContextItemExpression || root.getRootExpression() instanceof RootExpression) {
                if (subContextRoot != null) {
                    if (record.recordAnnotations()) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        record.addAnnotation(XQUERY_PLANNING, "Multiple context items exist in column path " + xmlColumn.getPath(), "Document projection will not be used", Priority.MEDIUM);
                    }
                    return null;
                }
                subContextRoot = root;
            }
        }
        // special case for handling '.', which the pathmap logic doesn't consider as a root
        if (internalExpression instanceof ContextItemExpression) {
            addReturnedArcs(xmlColumn, finalNode);
        }
        if (subContextRoot == null) {
            continue;
        }
        for (PathMapArc arc : subContextRoot.getArcs()) {
            if (streamingPath != null && !validateColumnForStreaming(record, xmlColumn, arc)) {
                streamingPath = null;
            }
            finalNode.createArc(arc.getAxis(), arc.getNodeTest(), arc.getTarget());
        }
        HashSet<PathMapNode> subFinalNodes = new HashSet<PathMapNode>();
        getReturnableNodes(subContextRoot, subFinalNodes);
        for (PathMapNode subNode : subFinalNodes) {
            addReturnedArcs(xmlColumn, subNode);
        }
    }
    // Workaround to rerun the reduction algorithm - by making a copy of the old version
    PathMap newMap = new PathMap(DUMMY_EXPRESSION);
    PathMapRoot newRoot = newMap.makeNewRoot(parentRoot.getRootExpression());
    if (parentRoot.isAtomized()) {
        newRoot.setAtomized();
    }
    if (parentRoot.isReturnable()) {
        newRoot.setReturnable(true);
    }
    if (parentRoot.hasUnknownDependencies()) {
        newRoot.setHasUnknownDependencies();
    }
    for (PathMapArc arc : parentRoot.getArcs()) {
        newRoot.createArc(arc.getAxis(), arc.getNodeTest(), arc.getTarget());
    }
    return newMap.reduceToDownwardsAxes(newRoot);
}
Also used : XMLColumn(org.teiid.query.sql.lang.XMLTable.XMLColumn) PathMapNode(net.sf.saxon.expr.parser.PathMap.PathMapNode) ContextItemExpression(net.sf.saxon.expr.ContextItemExpression) XQueryExpression(net.sf.saxon.query.XQueryExpression) Expression(net.sf.saxon.expr.Expression) XPathExpression(net.sf.saxon.sxpath.XPathExpression) RootExpression(net.sf.saxon.expr.RootExpression) RootExpression(net.sf.saxon.expr.RootExpression) PathMapRoot(net.sf.saxon.expr.parser.PathMap.PathMapRoot) PathMapArc(net.sf.saxon.expr.parser.PathMap.PathMapArc) PathMap(net.sf.saxon.expr.parser.PathMap) ContextItemExpression(net.sf.saxon.expr.ContextItemExpression) HashSet(java.util.HashSet)

Aggregations

PathMapArc (net.sf.saxon.expr.parser.PathMap.PathMapArc)4 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 ContextItemExpression (net.sf.saxon.expr.ContextItemExpression)1 Expression (net.sf.saxon.expr.Expression)1 RootExpression (net.sf.saxon.expr.RootExpression)1 PathMap (net.sf.saxon.expr.parser.PathMap)1 PathMapNode (net.sf.saxon.expr.parser.PathMap.PathMapNode)1 PathMapRoot (net.sf.saxon.expr.parser.PathMap.PathMapRoot)1 NodeTest (net.sf.saxon.pattern.NodeTest)1 XQueryExpression (net.sf.saxon.query.XQueryExpression)1 XPathExpression (net.sf.saxon.sxpath.XPathExpression)1 XMLColumn (org.teiid.query.sql.lang.XMLTable.XMLColumn)1