private ImmutableSet<Variable> extractRequiredAndCooccuringVariables(IntermediateQuery query, InnerJoinNode joinNode) { Stream<Variable> requiredVariablesByAncestorStream = Stream.concat( query.getVariablesRequiredByAncestors(joinNode).stream(), joinNode.getRequiredVariables(query).stream()); /* * NB: looks fro into multiple occurrences of a variable within the same data node */ Stream<Variable> innerCooccuringVariableStream = query.getChildren(joinNode).stream() .filter(c -> c instanceof ExtensionalDataNode) .map(c -> (ExtensionalDataNode) c) .flatMap(c -> // Multiset c.getProjectionAtom().getArguments().stream() .filter(t -> t instanceof Variable) .map(v -> (Variable) v) .collect(ImmutableCollectors.toMultiset()) .entrySet().stream() .filter(e -> e.getCount() > 1) .map(Multiset.Entry::getElement)); return Stream.concat(requiredVariablesByAncestorStream, innerCooccuringVariableStream) .collect(ImmutableCollectors.toSet()); }
private ImmutableSet<Variable> extractRequiredAndCooccuringVariables(IntermediateQuery query, InnerJoinNode joinNode) { Stream<Variable> requiredVariablesByAncestorStream = Stream.concat( query.getVariablesRequiredByAncestors(joinNode).stream(), joinNode.getRequiredVariables(query).stream()); /* * NB: looks fro into multiple occurrences of a variable within the same data node */ Stream<Variable> innerCooccuringVariableStream = query.getChildren(joinNode).stream() .filter(c -> c instanceof DataNode) .map(c -> (DataNode) c) .flatMap(c -> // Multiset c.getProjectionAtom().getArguments().stream() .filter(t -> t instanceof Variable) .map(v -> (Variable) v) .collect(ImmutableCollectors.toMultiset()) .entrySet().stream() .filter(e -> e.getCount() > 1) .map(Multiset.Entry::getElement)); return Stream.concat(requiredVariablesByAncestorStream, innerCooccuringVariableStream) .collect(ImmutableCollectors.toSet()); }