private ImmutableList<Variable> extractNullableVariables(IntermediateQuery query, QueryNode rootNode) { ImmutableSet<Variable> requiredVariables = rootNode instanceof ConstructionNode ? rootNode.getRequiredVariables(query): query.getVariables(rootNode); return requiredVariables.stream() .filter(v -> rootNode.isVariableNullable(query, v)) .collect(ImmutableCollectors.toList()); }
@Override public ImmutableSet<Variable> getVariablesRequiredByAncestors(QueryNode queryNode) { ImmutableSet.Builder<Variable> requiredVariableBuilder = ImmutableSet.builder(); // Non-final Optional<QueryNode> optionalAncestor = getParent(queryNode); while (optionalAncestor.isPresent()) { QueryNode ancestor = optionalAncestor.get(); ancestor.getRequiredVariables(this) .forEach(requiredVariableBuilder::add); if (ancestor instanceof ExplicitVariableProjectionNode) break; optionalAncestor = getParent(ancestor); } ImmutableSet<Variable> requiredVariables = requiredVariableBuilder.build(); /* * Restrict to variables which can actually be provided. * Assumption: variables defined by a node should not appear in its subtree */ return getVariables(queryNode).stream() .filter(requiredVariables::contains) .collect(ImmutableCollectors.toSet()); }
@Override public ImmutableSet<Variable> getVariablesRequiredByAncestors(QueryNode queryNode) { ImmutableSet.Builder<Variable> requiredVariableBuilder = ImmutableSet.builder(); // Non-final Optional<QueryNode> optionalAncestor = getParent(queryNode); while (optionalAncestor.isPresent()) { QueryNode ancestor = optionalAncestor.get(); ancestor.getRequiredVariables(this) .forEach(requiredVariableBuilder::add); if (ancestor instanceof ExplicitVariableProjectionNode) break; optionalAncestor = getParent(ancestor); } ImmutableSet<Variable> requiredVariables = requiredVariableBuilder.build(); /* * Restrict to variables which can actually be provided. * Assumption: variables defined by a node should not appear in its subtree */ return getVariables(queryNode).stream() .filter(requiredVariables::contains) .collect(ImmutableCollectors.toSet()); }