use of net.sf.saxon.expr.ContextItemExpression 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);
}
Aggregations