private boolean isExpressionNullable(ImmutableExpression expression, ImmutableSet<Variable> nullableVariables) { OperationPredicate functionSymbol = expression.getFunctionSymbol(); if (functionSymbol instanceof ExpressionOperation) { switch((ExpressionOperation) functionSymbol) { case IS_NOT_NULL: case IS_NULL: return false; default: break; } } // TODO: support COALESCE and IF-THEN-ELSE (they will need to use isFilteringNullValue) return hasNullableArgument(expression, nullableVariables); } }
private boolean isExpressionNullable(ImmutableExpression expression, ImmutableSet<Variable> nullableVariables) { OperationPredicate functionSymbol = expression.getFunctionSymbol(); if (functionSymbol instanceof ExpressionOperation) { switch((ExpressionOperation) functionSymbol) { case IS_NOT_NULL: case IS_NULL: return false; default: break; } } // TODO: support COALESCE and IF-THEN-ELSE (they will need to use isFilteringNullValue) return hasNullableArgument(expression, nullableVariables); } }
default Optional<TermType> getOptionalTermType(ImmutableList<Optional<TermType>> actualArgumentTypes) { try { OperationPredicate predicate = getFunctionSymbol(); return predicate.inferTypeFromArgumentTypes(actualArgumentTypes); } catch (IncompatibleTermException e) { throw new IncompatibleTermException(this, e); } } }
/** * This method takes a immutable boolean term and convert it into an old mutable boolean function. */ public static Expression convertToMutableBooleanExpression(ImmutableExpression booleanExpression) { OperationPredicate pred = (OperationPredicate) booleanExpression.getFunctionSymbol(); ImmutableList<Term> otherTerms = booleanExpression.getTerms(); List<Term> mutableList = new ArrayList<>(); Iterator<Term> iterator = otherTerms.iterator(); while (iterator.hasNext()) { Term nextTerm = iterator.next(); if (nextTerm instanceof ImmutableFunctionalTerm) { ImmutableFunctionalTerm term2Change = (ImmutableFunctionalTerm) nextTerm; Function newTerm = convertToMutableFunction(term2Change); mutableList.add(newTerm); } else { mutableList.add(nextTerm); } } Expression mutFunc = TERM_FACTORY.getExpression(pred, mutableList); return mutFunc; }
/** * TODO: inject termFactory and typeFactory * */ default Optional<TermType> getOptionalTermType() throws IncompatibleTermException { try { OperationPredicate predicate = getFunctionSymbol(); return predicate.inferType(getTerms()); } catch (IncompatibleTermException e) { throw new IncompatibleTermException(this, e); } }
/** * This method takes a immutable boolean term and convert it into an old mutable boolean function. */ public Expression convertToMutableBooleanExpression(ImmutableExpression booleanExpression) { OperationPredicate pred = booleanExpression.getFunctionSymbol(); return termFactory.getExpression(pred, convertToMutableTerms(booleanExpression.getTerms())); }
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); }
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); }
.filter(e -> e.getFunctionSymbol().equals(EQ)) .filter(e -> { ImmutableList<? extends ImmutableTerm> arguments = e.getTerms();
.filter(e -> e.getFunctionSymbol().equals(EQ)) .filter(e -> { ImmutableList<? extends ImmutableTerm> arguments = e.getTerms();
@Override public ImmutableExpression normalize(ImmutableExpression expression) { OperationPredicate functionSymbol = expression.getFunctionSymbol(); if (functionSymbol instanceof ExpressionOperation) { switch((ExpressionOperation)functionSymbol) { case ADD: case MULTIPLY: //case AND: //case OR: case EQ: case NEQ: return normalizeCommutative(functionSymbol, expression.getArguments()); default: return normalizeArguments(functionSymbol, expression.getArguments()); } } else { return expression; } }
@Override public ImmutableExpression normalize(ImmutableExpression expression) { OperationPredicate functionSymbol = expression.getFunctionSymbol(); if (functionSymbol instanceof ExpressionOperation) { switch((ExpressionOperation)functionSymbol) { case ADD: case MULTIPLY: //case AND: //case OR: case EQ: case NEQ: return normalizeCommutative(functionSymbol, expression.getTerms()); default: return normalizeArguments(functionSymbol, expression.getTerms()); } } else { return expression; } }