@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { for(QueryNode child : query.getChildren(this)) { if (child.isVariableNullable(query, variable)) return true; } return false; }
@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { for(QueryNode child : query.getChildren(this)) { if (child.isVariableNullable(query, variable)) return true; } return false; }
private boolean isChildVariableNullable(IntermediateQuery query, Variable variable) { return query.getFirstChild(this) .map(c -> c.isVariableNullable(query, variable)) .orElseThrow(() -> new InvalidIntermediateQueryException( "A construction node with child variables must have a child")); }
@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { return query.getFirstChild(this) .map(c -> c.isVariableNullable(query, variable)) .orElseThrow(() -> new InvalidIntermediateQueryException("A query modifier node must have a child")); } }
private boolean isChildVariableNullable(IntermediateQuery query, Variable variable) { return query.getFirstChild(this) .map(c -> c.isVariableNullable(query, variable)) .orElseThrow(() -> new InvalidIntermediateQueryException( "A construction node with child variables must have a child")); }
@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { if (isFilteringNullValue(variable)) return false; return query.getFirstChild(this) .map(c -> c.isVariableNullable(query, variable)) .orElseThrow(() -> new InvalidIntermediateQueryException("A filter node must have a child")); }
@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { if (isFilteringNullValue(variable)) return false; return query.getFirstChild(this) .map(c -> c.isVariableNullable(query, variable)) .orElseThrow(() -> new InvalidIntermediateQueryException("A filter node must have a child")); }
private static boolean projectNullableVariable(IntermediateQuery query) { QueryNode rootNode = query.getRootNode(); return query.getProjectionAtom().getVariableStream() .anyMatch(v -> rootNode.isVariableNullable(query, v)); }
@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { QueryNode leftChild = query.getChild(this, LEFT) .orElseThrow(() -> new InvalidIntermediateQueryException("A left child is required")); if (query.getVariables(leftChild).contains(variable)) return leftChild.isVariableNullable(query, variable); QueryNode rightChild = query.getChild(this, RIGHT) .orElseThrow(() -> new InvalidIntermediateQueryException("A right child is required")); if (!query.getVariables(rightChild).contains(variable)) throw new IllegalArgumentException("The variable " + variable + " is not projected by " + this); return false; }
@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { QueryNode leftChild = query.getChild(this, LEFT) .orElseThrow(() -> new InvalidIntermediateQueryException("A left child is required")); if (query.getVariables(leftChild).contains(variable)) return leftChild.isVariableNullable(query, variable); QueryNode rightChild = query.getChild(this, RIGHT) .orElseThrow(() -> new InvalidIntermediateQueryException("A right child is required")); if (!query.getVariables(rightChild).contains(variable)) throw new IllegalArgumentException("The variable " + variable + " is not projected by " + this); return false; }
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 boolean isVariableNullable(IntermediateQuery query, Variable variable) { if (isFilteringNullValue(variable)) return false; // Non-already boolean alsoProjectedByAnotherChild = false; for(QueryNode child : query.getChildren(this)) { if (query.getVariables(child).contains(variable)) { // Joining conditions cannot be null if (alsoProjectedByAnotherChild) return false; if (child.isVariableNullable(query, variable)) alsoProjectedByAnotherChild = true; else return false; } } if (!alsoProjectedByAnotherChild) throw new IllegalArgumentException("The variable " + variable + " is not projected by " + this); return true; }
@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { if (isFilteringNullValue(variable)) return false; // Non-already boolean alsoProjectedByAnotherChild = false; for(QueryNode child : query.getChildren(this)) { if (query.getVariables(child).contains(variable)) { // Joining conditions cannot be null if (alsoProjectedByAnotherChild) return false; if (child.isVariableNullable(query, variable)) alsoProjectedByAnotherChild = true; else return false; } } if (!alsoProjectedByAnotherChild) throw new IllegalArgumentException("The variable " + variable + " is not projected by " + this); return true; }
@Override public IntermediateQuery transform(IntermediateQuery query) throws NotFilterableNullVariableException { QueryNode rootNode = query.getRootNode(); ImmutableList<Variable> nullableProjectedVariables = query.getProjectionAtom().getVariables().stream() .filter(v -> rootNode.isVariableNullable(query, v)) .collect(ImmutableCollectors.toList()); if (nullableProjectedVariables.isEmpty()) return query; ImmutableExpression filterCondition = extractFilteringCondition(query, rootNode, nullableProjectedVariables); return constructQuery(query, rootNode, filterCondition); }
@Override public IntermediateQuery transform(IntermediateQuery query) throws NotFilterableNullVariableException { QueryNode rootNode = query.getRootNode(); ImmutableList<Variable> nullableProjectedVariables = query.getProjectionAtom().getVariables().stream() .filter(v -> rootNode.isVariableNullable(query, v)) .collect(ImmutableCollectors.toList()); if (nullableProjectedVariables.isEmpty()) return query; ImmutableExpression filterCondition = extractFilteringCondition(query, rootNode, nullableProjectedVariables); return constructQuery(query, rootNode, filterCondition); }