private ImmutableSet<Variable> getNullableVariables() { if (nullableVariables == null) nullableVariables = nullableGroups.stream() .flatMap(Collection::stream) .collect(ImmutableCollectors.toSet()); return nullableVariables; }
private <T> ImmutableSet<T> computeIntersection(ImmutableSet<T> s1, ImmutableSet<T> s2) { return s1.stream() .filter(s2::contains) .collect(ImmutableCollectors.toSet()); }
private ImmutableSet<SQLPPTriplesMap> splitMappingAxioms(List<SQLPPTriplesMap> mappingAxioms) { /* * Delimiter string d used for assigning ids to split mapping axioms. * If a mapping axiom with id j is split into multiple ones, * each of then will have "j"+"d"+int as an identifier */ String delimiterSubstring = getSplitMappingAxiomIdDelimiterSubstring(mappingAxioms); return mappingAxioms.stream() .flatMap(m -> splitMappingAxiom(m, delimiterSubstring).stream()) .collect(ImmutableCollectors.toSet()); }
@Override public ImmutableSet<Variable> getLocalVariables() { return comparators.stream() .flatMap(c -> c.getTerm().getVariableStream()) .collect(ImmutableCollectors.toSet()); }
protected static ImmutableSet<Variable> union(ImmutableSet<Variable> set1, ImmutableSet<Variable> set2) { return Stream.concat( set1.stream(), set2.stream()) .collect(ImmutableCollectors.toSet()); }
protected static ImmutableSet<Variable> union(ImmutableSet<Variable> set1, ImmutableSet<Variable> set2) { return Stream.concat( set1.stream(), set2.stream()) .collect(ImmutableCollectors.toSet()); }
public ImmutableSet<Variable> computeNewProjectedVariables( ImmutableSubstitution<? extends ImmutableTerm> descendingSubstitution, ImmutableSet<Variable> projectedVariables) { ImmutableSet<Variable> tauDomain = descendingSubstitution.getDomain(); Stream<Variable> remainingVariableStream = projectedVariables.stream() .filter(v -> !tauDomain.contains(v)); Stream<Variable> newVariableStream = descendingSubstitution.getImmutableMap().entrySet().stream() .filter(e -> projectedVariables.contains(e.getKey())) .map(Map.Entry::getValue) .flatMap(ImmutableTerm::getVariableStream); return Stream.concat(newVariableStream, remainingVariableStream) .collect(ImmutableCollectors.toSet()); }
private ImmutableSet<ForeignKeyConstraint> extractMatchedFKs( ImmutableMultimap<DatabaseRelationDefinition, ImmutableList<? extends VariableOrGroundTerm>> leftRelationArgumentMultimap, ImmutableList<? extends VariableOrGroundTerm> rightArguments, DatabaseRelationDefinition rightRelation) { return leftRelationArgumentMultimap.asMap().entrySet().stream() .flatMap(e -> extractMatchedFKsForARelation(e.getKey(), e.getValue(), rightArguments, rightRelation)) .collect(ImmutableCollectors.toSet()); }
private static ImmutableSet<Variable> extractChildVariables(ImmutableSet<Variable> projectedVariables, ImmutableSubstitution<ImmutableTerm> substitution) { ImmutableSet<Variable> variableDefinedByBindings = substitution.getDomain(); Stream<Variable> variablesRequiredByBindings = substitution.getImmutableMap().values().stream() .flatMap(ImmutableTerm::getVariableStream); //return only the variables that are also used in the bindings for the child of the construction node return Stream.concat(projectedVariables.stream(), variablesRequiredByBindings) .filter(v -> !variableDefinedByBindings.contains(v)) .collect(ImmutableCollectors.toSet()); }
private void checkExpression(JoinOrFilterNode node, ImmutableExpression expression) { ImmutableSet<Variable> unboundVariables = expression.getVariableStream() .filter(v -> !(query.getChildren(node).stream() .flatMap(c -> query.getVariables(c).stream()) .collect(ImmutableCollectors.toSet()) .contains(v))) .collect(ImmutableCollectors.toSet()); if (!unboundVariables.isEmpty()) { throw new InvalidIntermediateQueryException("Expression " + expression + " of " + expression + " uses unbound variables (" + unboundVariables + ").\n" + query); } }
@Override public ImmutableSet<Attribute> getDependents() { return getRelation().getAttributes().stream() .filter(a -> !attributes.contains(a)) .collect(ImmutableCollectors.toSet()); }
@Override public ImmutableSet<Attribute> getDependents() { return getRelation().getAttributes().stream() .filter(a -> !attributes.contains(a)) .collect(ImmutableCollectors.toSet()); }
private void checkExpression(JoinOrFilterNode node, ImmutableExpression expression) { ImmutableSet<Variable> unboundVariables = expression.getVariableStream() .filter(v -> !(query.getChildren(node).stream() .flatMap(c -> query.getVariables(c).stream()) .collect(ImmutableCollectors.toSet()) .contains(v))) .collect(ImmutableCollectors.toSet()); if (!unboundVariables.isEmpty()) { throw new InvalidIntermediateQueryException("Expression " + expression + " of " + expression + " uses unbound variables (" + unboundVariables + ").\n" + query); } }
@Override public ImmutableSet<Variable> getVariables() { if (rootNode instanceof ExplicitVariableProjectionNode) return ((ExplicitVariableProjectionNode) rootNode).getVariables(); else return children.stream() .flatMap(c -> c.getVariables().stream()) .collect(ImmutableCollectors.toSet()); }
private ImmutableSet<UniqueConstraint> extractMatchedUCs( ImmutableMultimap<RelationDefinition, ImmutableList<? extends VariableOrGroundTerm>> leftRelationArgumentMultimap, ImmutableList<? extends VariableOrGroundTerm> rightArguments, RelationDefinition rightRelation) { /* * When the left and right relations are the same */ return leftRelationArgumentMultimap.get(rightRelation).stream() .flatMap(leftArguments -> rightRelation.getUniqueConstraints().stream() .filter(uc -> isUcMatching(uc, leftArguments, rightArguments))) .collect(ImmutableCollectors.toSet()); }
private ImmutableSet<DataNode> findRedundantNodes(IntermediateQuery query, InnerJoinNode joinNode, ImmutableMultimap<RelationDefinition, ExtensionalDataNode> dataNodeMap) { return dataNodeMap.keySet().stream() .flatMap(r -> r.getForeignKeys().stream() .flatMap(c -> selectRedundantNodesForConstraint(r, c, query, joinNode, dataNodeMap))) .collect(ImmutableCollectors.toSet()); }
private ImmutableSet<DataNode> findRedundantNodes(IntermediateQuery query, InnerJoinNode joinNode, ImmutableMultimap<DatabaseRelationDefinition, DataNode> dataNodeMap) { return dataNodeMap.keySet().stream() .flatMap(r -> r.getForeignKeys().stream() .flatMap(c -> selectRedundantNodesForConstraint(r, c, query, joinNode, dataNodeMap))) .collect(ImmutableCollectors.toSet()); }
private Optional<RightProvenance> createProvenanceElements(Map.Entry<Variable, Constant> provenanceVariableDefinition, IQTree rightTree) { Variable rightProvenanceVariable = provenanceVariableDefinition.getKey(); ImmutableSet<Variable> newRightProjectedVariables = Stream.concat(Stream.of(rightProvenanceVariable), rightTree.getVariables().stream()) .collect(ImmutableCollectors.toSet()); ConstructionNode newRightConstructionNode = iqFactory.createConstructionNode( newRightProjectedVariables, substitutionFactory.getSubstitution(rightProvenanceVariable, provenanceVariableDefinition.getValue())); return Optional.of(new RightProvenance(rightProvenanceVariable, newRightConstructionNode)); }
private IQTree liftUnionChild(int childIndex, NaryIQTree newUnionChild, ImmutableList<IQTree> initialChildren) { UnionNode newUnionNode = iqFactory.createUnionNode(initialChildren.stream() .flatMap(c -> c.getVariables().stream()) .collect(ImmutableCollectors.toSet())); return iqFactory.createNaryIQTree(newUnionNode, newUnionChild.getChildren().stream() .map(unionGrandChild -> createJoinSubtree(childIndex, unionGrandChild, initialChildren)) .collect(ImmutableCollectors.toList())); }
@Override public ImmutableSet<Variable> getRequiredVariables(IntermediateQuery query) { ImmutableMultiset<Variable> childrenVariableBag = query.getChildren(this).stream() .flatMap(c -> query.getVariables(c).stream()) .collect(ImmutableCollectors.toMultiset()); Stream<Variable> cooccuringVariableStream = childrenVariableBag.entrySet().stream() .filter(e -> e.getCount() > 1) .map(Multiset.Entry::getElement); return Stream.concat(cooccuringVariableStream, getLocallyRequiredVariables().stream()) .collect(ImmutableCollectors.toSet()); }