/** * TODO: implement it seriously */ private IQTree liftSliceChild(SliceNode newChildRoot, IQTree newChild, IQProperties currentIQProperties) { return iqFactory.createUnaryIQTree(this, newChild, currentIQProperties.declareLifted()); }
private IQTree convertResults2IQTree(ImmutableSet<Variable> projectedVariables, ChildLiftingState liftingState, IQProperties currentIQProperties) { AscendingSubstitutionNormalization ascendingNormalization = normalizeAscendingSubstitution( liftingState.getComposedAscendingSubstitution(), projectedVariables); Optional<ConstructionNode> topConstructionNode = ascendingNormalization.generateTopConstructionNode(); IQTree subTree = ascendingNormalization.normalizeChild( Optional.of(liftingState.rightChild) .filter(rightChild -> !rightChild.isDeclaredAsEmpty()) .filter(rightChild -> !(rightChild.getRootNode() instanceof TrueNode)) // LJ .map(rightChild -> (IQTree) iqFactory.createBinaryNonCommutativeIQTree( iqFactory.createLeftJoinNode(liftingState.ljCondition), liftingState.leftChild, liftingState.rightChild, currentIQProperties.declareLifted())) // Left child .orElse(liftingState.leftChild)); return topConstructionNode .map(n -> (IQTree) iqFactory.createUnaryIQTree(n, subTree, currentIQProperties.declareLifted())) .orElse(subTree); }
private IQTree createJoinOrFilterOrTrue(ImmutableList<IQTree> currentChildren, Optional<ImmutableExpression> currentJoiningCondition, IQProperties currentIQProperties) { switch (currentChildren.size()) { case 0: return iqFactory.createTrueNode(); case 1: IQTree uniqueChild = currentChildren.get(0); return currentJoiningCondition .map(e -> (IQTree) iqFactory.createUnaryIQTree(iqFactory.createFilterNode(e), uniqueChild)) .orElse(uniqueChild); default: InnerJoinNode newJoinNode = currentJoiningCondition.equals(getOptionalFilterCondition()) ? this : changeOptionalFilterCondition(currentJoiningCondition); return iqFactory.createNaryIQTree(newJoinNode, currentChildren, currentIQProperties.declareLifted()); } }
@Override public IQTree liftBinding(IQTree child, VariableGenerator variableGenerator, IQProperties currentIQProperties) { IQTree newChild = child.liftBinding(variableGenerator); QueryNode newChildRoot = newChild.getRootNode(); if (newChildRoot instanceof ConstructionNode) return liftBindingConstructionChild(newChild, (ConstructionNode) newChildRoot, currentIQProperties); else if (newChildRoot instanceof DistinctNode) return newChild; else if (newChildRoot instanceof EmptyNode) return newChild; else return iqFactory.createUnaryIQTree(this, newChild, currentIQProperties.declareLifted()); }
return iqFactory.createNaryIQTree(this, liftedChildren, currentIQProperties.declareLifted()); return iqFactory.createNaryIQTree(this, liftedChildren, currentIQProperties.declareLifted());
private IQTree liftBindingConstructionChild(IQTree child, ConstructionNode constructionNode, IQProperties currentIQProperties) { IQProperties liftedProperties = currentIQProperties.declareLifted();
/** * Blocks substitutions */ @Override public IQTree liftBinding(IQTree child, VariableGenerator variableGenerator, IQProperties currentIQProperties) { IQTree newChild = child.liftBinding(variableGenerator); QueryNode newChildRoot = newChild.getRootNode(); if (newChildRoot instanceof SliceNode) return liftSliceChild((SliceNode) newChildRoot, newChild, currentIQProperties); else if (newChildRoot instanceof EmptyNode) return newChild; else return iqFactory.createUnaryIQTree(this, newChild, currentIQProperties.declareLifted()); }
/** * Projects away variables only for child construction nodes */ private IQTree projectAwayUnnecessaryVariables(IQTree child, IQProperties currentIQProperties) { if (child.getRootNode() instanceof ConstructionNode) { ConstructionNode constructionNode = (ConstructionNode) child.getRootNode(); AscendingSubstitutionNormalization normalization = normalizeAscendingSubstitution( constructionNode.getSubstitution(), projectedVariables); Optional<ConstructionNode> proposedConstructionNode = normalization.generateTopConstructionNode(); if (proposedConstructionNode .filter(c -> c.isSyntacticallyEquivalentTo(constructionNode)) .isPresent()) return child; IQTree grandChild = normalization.normalizeChild(((UnaryIQTree) child).getChild()); return proposedConstructionNode .map(c -> (IQTree) iqFactory.createUnaryIQTree(c, grandChild, currentIQProperties.declareLifted())) .orElse(grandChild); } else return child; }
private IQTree liftBindingAfterPropagatingCondition(IQTree childIQTree, VariableGenerator variableGenerator, IQProperties currentIQProperties) { IQTree liftedChildIQTree = childIQTree.liftBinding(variableGenerator); QueryNode childRoot = liftedChildIQTree.getRootNode(); if (childRoot instanceof ConstructionNode) return liftBinding((ConstructionNode) childRoot, (UnaryIQTree) liftedChildIQTree, currentIQProperties, variableGenerator); else if (liftedChildIQTree.isDeclaredAsEmpty()) { return liftedChildIQTree; } else return iqFactory.createUnaryIQTree(this, liftedChildIQTree, currentIQProperties.declareLifted()); }
@Override public IQTree liftBinding(IQTree childIQTree, VariableGenerator variableGenerator, IQProperties currentIQProperties) { IQTree liftedChildIQTree = childIQTree.liftBinding(variableGenerator); QueryNode liftedChildRoot = liftedChildIQTree.getRootNode(); if (liftedChildRoot instanceof ConstructionNode) return liftBinding((ConstructionNode) liftedChildRoot, (UnaryIQTree) liftedChildIQTree, currentIQProperties); else if (liftedChildIQTree.isDeclaredAsEmpty()) { return iqFactory.createEmptyNode(projectedVariables); } else return iqFactory.createUnaryIQTree(this, liftedChildIQTree, currentIQProperties.declareLifted()); }
.map(iqFactory::createConstructionNode)) .map(constructionNode -> (IQTree) iqFactory.createUnaryIQTree(constructionNode, newJoinIQ, currentIQProperties.declareLifted())) .orElse(newJoinIQ);
IQTree grandChildIQTree = liftedChildIQ.getChild(); IQProperties liftedProperties = currentIQProperties.declareLifted();
private IQTree liftBinding(ConstructionNode childConstructionNode, UnaryIQTree childIQ, IQProperties currentIQProperties) { AscendingSubstitutionNormalization ascendingNormalization = normalizeAscendingSubstitution( childConstructionNode.getSubstitution().composeWith(substitution), projectedVariables); ImmutableSubstitution<ImmutableTerm> newSubstitution = ascendingNormalization.getAscendingSubstitution(); IQTree grandChildIQTree = ascendingNormalization.normalizeChild(childIQ.getChild()); ConstructionNode newConstructionNode = iqFactory.createConstructionNode(projectedVariables, newSubstitution); return iqFactory.createUnaryIQTree(newConstructionNode, grandChildIQTree, currentIQProperties.declareLifted()); }
@Override public IQTree liftBinding(IQTree child, VariableGenerator variableGenerator, IQProperties currentIQProperties) { IQTree newChild = child.liftBinding(variableGenerator); QueryNode newChildRoot = newChild.getRootNode(); IQProperties liftedProperties = currentIQProperties.declareLifted(); if (newChildRoot instanceof ConstructionNode) return liftChildConstructionNode((ConstructionNode) newChildRoot, (UnaryIQTree) newChild, liftedProperties); else if (newChildRoot instanceof EmptyNode) return newChild; else if (newChildRoot instanceof DistinctNode) { return iqFactory.createUnaryIQTree( (DistinctNode) newChildRoot, iqFactory.createUnaryIQTree(this, ((UnaryIQTree)newChild).getChild(), liftedProperties), liftedProperties); } else return iqFactory.createUnaryIQTree(this, newChild, liftedProperties); }