@Override public boolean isSyntacticallyEquivalentTo(QueryNode node) { return (node instanceof LeftJoinNode) && ((LeftJoinNode) node).getOptionalFilterCondition().equals(this.getOptionalFilterCondition()); }
@Override public IQTree transformLeftJoin(IQTree tree, LeftJoinNode rootNode, IQTree leftChild, IQTree rightChild) { return transformBinaryNonCommutativeNode(rootNode.acceptNodeTransformer(nodeTransformer), leftChild, rightChild); }
@Override public LeftJoinNode transform(LeftJoinNode leftJoinNode) { return leftJoinNode.clone(); }
private LeftJoinNode liftCondition(LeftJoinNode leftJoinNode, QueryNode leftChild, DataNode rightChild, ImmutableSet<Variable> requiredVariablesAboveLJ, QueryTreeComponent treeComponent, Optional<ImmutableSubstitution<ImmutableTerm>> remainingRightSubstitution, VariableGenerator variableGenerator, IntermediateQuery query) { ImmutableExpression ljCondition = leftJoinNode.getOptionalFilterCondition() .orElseThrow(() -> new IllegalArgumentException("The LJ is expected to have a joining condition")); ImmutableSet<Variable> leftVariables = query.getVariables(leftChild); ImmutableSet<Variable> requiredRightVariables = requiredVariablesAboveLJ.stream() .filter(v -> !leftVariables.contains(v)) .collect(ImmutableCollectors.toSet()); // Special case: ljCondition = IS_NOT_NULL(x) and x is a specific right variable // --> x will not be affected by the condition ImmutableSet<Variable> rightVariablesToUpdate = Optional.of(ljCondition) .filter(c -> c.getFunctionSymbol().equals(IS_NOT_NULL)) .map(c -> c.getArguments().get(0)) .filter(t -> t instanceof Variable) .map(v -> (Variable) v) .map(specialVariable -> requiredRightVariables.stream() .filter(v -> !v.equals(specialVariable)) .collect(ImmutableCollectors.toSet())) .orElse(requiredRightVariables); LeftJoinNode newLeftJoinNode = leftJoinNode.changeOptionalFilterCondition(Optional.empty()); treeComponent.replaceNode(leftJoinNode, newLeftJoinNode); return (rightVariablesToUpdate.isEmpty() && (!remainingRightSubstitution.isPresent())) ? newLeftJoinNode : updateConditionalVariables(rightVariablesToUpdate, rightChild, newLeftJoinNode, ljCondition, query, treeComponent, remainingRightSubstitution, variableGenerator); }
/** * NB: removes the construction node if present, without inserting its substitution (will be propagated later) */ private LeftJoinNode updateRightNodesAndLJ(LeftJoinNode leftJoinNode, DataNodeAndSubstitution rightComponent, Optional<ImmutableExpression> newLJCondition, Optional<DataNode> proposedRightDataNode, QueryTreeComponent treeComponent) { rightComponent.constructionNode .ifPresent(n -> treeComponent.replaceNodeByChild(n, Optional.empty())); rightComponent.filterNode .ifPresent(n -> treeComponent.replaceNodeByChild(n, Optional.empty())); proposedRightDataNode .ifPresent(n -> treeComponent.replaceNode(rightComponent.dataNode, n)); LeftJoinNode newLeftJoinNode = leftJoinNode.changeOptionalFilterCondition(newLJCondition); treeComponent.replaceNode(leftJoinNode, newLeftJoinNode); return newLeftJoinNode; }
private LeftJoinNode liftCondition(LeftJoinNode leftJoinNode, QueryNode leftChild, DataNode rightChild, ImmutableSet<Variable> requiredVariablesAboveLJ, QueryTreeComponent treeComponent, Optional<ImmutableSubstitution<ImmutableTerm>> remainingRightSubstitution, VariableGenerator variableGenerator, IntermediateQuery query) { ImmutableExpression ljCondition = leftJoinNode.getOptionalFilterCondition() .orElseThrow(() -> new IllegalArgumentException("The LJ is expected to have a joining condition")); ImmutableSet<Variable> leftVariables = query.getVariables(leftChild); ImmutableSet<Variable> requiredRightVariables = requiredVariablesAboveLJ.stream() .filter(v -> !leftVariables.contains(v)) .collect(ImmutableCollectors.toSet()); // Special case: ljCondition = IS_NOT_NULL(x) and x is a specific right variable // --> x will not be affected by the condition ImmutableSet<Variable> rightVariablesToUpdate = Optional.of(ljCondition) .filter(c -> c.getFunctionSymbol().equals(IS_NOT_NULL)) .map(c -> c.getTerms().get(0)) .filter(t -> t instanceof Variable) .map(v -> (Variable) v) .map(specialVariable -> requiredRightVariables.stream() .filter(v -> !v.equals(specialVariable)) .collect(ImmutableCollectors.toSet())) .orElse(requiredRightVariables); LeftJoinNode newLeftJoinNode = leftJoinNode.changeOptionalFilterCondition(Optional.empty()); treeComponent.replaceNode(leftJoinNode, newLeftJoinNode); return (rightVariablesToUpdate.isEmpty() && (!remainingRightSubstitution.isPresent())) ? newLeftJoinNode : updateConditionalVariables(rightVariablesToUpdate, rightChild, newLeftJoinNode, ljCondition, query, treeComponent, remainingRightSubstitution, variableGenerator); }
/** * NB: removes the construction node if present, without inserting its substitution (will be propagated later) */ private LeftJoinNode updateRightNodesAndLJ(LeftJoinNode leftJoinNode, DataNodeAndSubstitution rightComponent, Optional<ImmutableExpression> newLJCondition, Optional<DataNode> proposedRightDataNode, QueryTreeComponent treeComponent) { rightComponent.constructionNode .ifPresent(n -> treeComponent.replaceNodeByChild(n, Optional.empty())); rightComponent.filterNode .ifPresent(n -> treeComponent.replaceNodeByChild(n, Optional.empty())); proposedRightDataNode .ifPresent(n -> treeComponent.replaceNode(rightComponent.dataNode, n)); LeftJoinNode newLeftJoinNode = leftJoinNode.changeOptionalFilterCondition(newLJCondition); treeComponent.replaceNode(leftJoinNode, newLeftJoinNode); return newLeftJoinNode; }
@Override public boolean isEquivalentTo(QueryNode queryNode) { return queryNode instanceof LeftJoinNode && getOptionalFilterCondition().equals(((LeftJoinNode) queryNode).getOptionalFilterCondition()); }
@Override public LeftJoinNode transform(LeftJoinNode leftJoinNode) { return leftJoinNode.clone(); }
@Override public boolean isSyntacticallyEquivalentTo(QueryNode node) { return (node instanceof LeftJoinNode) && ((LeftJoinNode) node).getOptionalFilterCondition().equals(this.getOptionalFilterCondition()); }
@Override public LeftJoinNode transform(LeftJoinNode leftJoinNode) { return iqFactory.createLeftJoinNode(renameOptionalBooleanExpression( leftJoinNode.getOptionalFilterCondition())); }
@Override public void visit(LeftJoinNode leftJoinNode) { if (query.getChildren(leftJoinNode).size() != 2) { throw new InvalidIntermediateQueryException("LEFTJOIN node " + leftJoinNode + " does not have 2 children.\n" + query); } leftJoinNode.getOptionalFilterCondition() .ifPresent(e -> checkExpression(leftJoinNode, e)); }
@Override public void visit(LeftJoinNode leftJoinNode) { if (query.getChildren(leftJoinNode).size() != 2) { throw new InvalidIntermediateQueryException("LEFTJOIN node " + leftJoinNode + " does not have 2 children.\n" + query); } leftJoinNode.getOptionalFilterCondition() .ifPresent(e -> checkExpression(leftJoinNode, e)); }
@Override public LeftJoinNode transform(LeftJoinNode leftJoinNode) { return iqFactory.createLeftJoinNode(renameOptionalBooleanExpression( leftJoinNode.getOptionalFilterCondition())); }
private IQTree liftLJJoin(BinaryNonCommutativeIQTree queryTree, IQTree newLeftChild, IQTree newRightChild, VariableGenerator variableGenerator) { LeftJoinNode leftJoinNode = (LeftJoinNode) queryTree.getRootNode(); BinaryNonCommutativeIQTree newQueryTree = newLeftChild.equals(queryTree.getLeftChild()) && newRightChild.equals(queryTree.getRightChild()) ? queryTree : iqFactory.createBinaryNonCommutativeIQTree(leftJoinNode, newLeftChild, newRightChild); return extractCandidateVariables(queryTree, leftJoinNode.getOptionalFilterCondition(), ImmutableList.of(newLeftChild, newRightChild)) .filter(v -> newLeftChild.getVariables().contains(v)) .map(newQueryTree::liftIncompatibleDefinitions) .filter(t -> !t.equals(queryTree)) .findFirst() .orElse(newQueryTree) .liftBinding(variableGenerator); }
@Override public IQTree transformLeftJoin(IQTree tree, LeftJoinNode rootNode, IQTree leftChild, IQTree rightChild) { ImmutableList<IQTree> children = ImmutableList.of(leftChild, rightChild); ImmutableList<InjectiveVar2VarSubstitution> substitutions = computeSubstitutions(children); if (substitutions.stream().allMatch(ImmutableSubstitution::isEmpty)) return tree; ImmutableList<IQTree> updatedChildren = updateJoinChildren(substitutions, children); return iqFactory.createUnaryIQTree( iqFactory.createConstructionNode(tree.getVariables()), iqFactory.createBinaryNonCommutativeIQTree( iqFactory.createLeftJoinNode( Optional.of( updateJoinCondition( rootNode.getOptionalFilterCondition(), substitutions ))), updatedChildren.get(0), updatedChildren.get(1) )); }
@Override public IQTree transformLeftJoin(IQTree tree, LeftJoinNode rootNode, IQTree leftChild, IQTree rightChild) { Optional<ImmutableExpression> leftChildChildExpression = getOptionalChildExpression(leftChild); Optional<ImmutableExpression> rightChildExpression = getOptionalChildExpression(rightChild); if(leftChildChildExpression.isPresent() || rightChildExpression.isPresent()) { IQTree leftJoinTree = iqFactory.createBinaryNonCommutativeIQTree( rightChildExpression.isPresent() ? iqFactory.createLeftJoinNode( Optional.of( updateJoinCondition( rootNode.getOptionalFilterCondition(), ImmutableList.of(rightChildExpression.get()) ))) : rootNode, trimRootFilter(leftChild), trimRootFilter(rightChild) ); return leftChildChildExpression.isPresent() ? iqFactory.createUnaryIQTree(iqFactory.createFilterNode(leftChildChildExpression.get()), leftJoinTree) : leftJoinTree; } return tree; }
Stream.of(leftJoinNode.getOptionalFilterCondition(), .orElse(normalizedLeftJoin)); if (leftJoinNodeToUpgrade.getOptionalFilterCondition().isPresent()) throw new MinorOntopInternalBugException("Bug: at this point the lj must not have a joining condition");
Stream.of(leftJoinNode.getOptionalFilterCondition(), .orElse(normalizedLeftJoin)); if (leftJoinNodeToUpgrade.getOptionalFilterCondition().isPresent()) throw new MinorOntopInternalBugException("Bug: at this point the lj must not have a joining condition");
Optional<ImmutableExpression> filter = ((LeftJoinNode) node).getOptionalFilterCondition(); List<QueryNode> listnode = te.getChildren(node);