private static IsNullPredicate isNull(Expression expression) { return new IsNullPredicate(expression); }
private static IsNullPredicate isNull(Expression expression) { return new IsNullPredicate(expression); }
private static IsNullPredicate isNull(Expression expression) { return new IsNullPredicate(expression); }
private static IsNullPredicate isNull(Expression expression) { return new IsNullPredicate(expression); }
@Override public Expression rewriteIsNotNullPredicate(IsNotNullPredicate node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Expression value = treeRewriter.rewrite(node.getValue(), context); return new NotExpression(new IsNullPredicate(value)); }
@Override public Expression rewriteIsNotNullPredicate(IsNotNullPredicate node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Expression value = treeRewriter.rewrite(node.getValue(), context); return new NotExpression(new IsNullPredicate(value)); }
private static Expression isNotNull(Expression expression) { return new NotExpression(new IsNullPredicate(expression)); }
private static Expression isNotNull(Expression expression) { return new NotExpression(new IsNullPredicate(expression)); }
public static Function<Expression, Expression> expressionOrNullSymbols(final Predicate<Symbol>... nullSymbolScopes) { return expression -> { ImmutableList.Builder<Expression> resultDisjunct = ImmutableList.builder(); resultDisjunct.add(expression); for (Predicate<Symbol> nullSymbolScope : nullSymbolScopes) { List<Symbol> symbols = SymbolsExtractor.extractUnique(expression).stream() .filter(nullSymbolScope) .collect(toImmutableList()); if (Iterables.isEmpty(symbols)) { continue; } ImmutableList.Builder<Expression> nullConjuncts = ImmutableList.builder(); for (Symbol symbol : symbols) { nullConjuncts.add(new IsNullPredicate(symbol.toSymbolReference())); } resultDisjunct.add(and(nullConjuncts.build())); } return or(resultDisjunct.build()); }; }
public static Function<Expression, Expression> expressionOrNullSymbols(final Predicate<Symbol>... nullSymbolScopes) { return expression -> { ImmutableList.Builder<Expression> resultDisjunct = ImmutableList.builder(); resultDisjunct.add(expression); for (Predicate<Symbol> nullSymbolScope : nullSymbolScopes) { List<Symbol> symbols = SymbolsExtractor.extractUnique(expression).stream() .filter(nullSymbolScope) .collect(toImmutableList()); if (Iterables.isEmpty(symbols)) { continue; } ImmutableList.Builder<Expression> nullConjuncts = ImmutableList.builder(); for (Symbol symbol : symbols) { nullConjuncts.add(new IsNullPredicate(symbol.toSymbolReference())); } resultDisjunct.add(and(nullConjuncts.build())); } return or(resultDisjunct.build()); }; }
private static IsNullPredicate isNull(Symbol symbol) { return new IsNullPredicate(symbol.toSymbolReference()); }
private static IsNullPredicate isNull(Symbol symbol) { return new IsNullPredicate(symbol.toSymbolReference()); }
private Expression toPredicate(Domain domain, SymbolReference reference) { if (domain.getValues().isNone()) { return domain.isNullAllowed() ? new IsNullPredicate(reference) : FALSE_LITERAL; } if (domain.getValues().isAll()) { return domain.isNullAllowed() ? TRUE_LITERAL : new NotExpression(new IsNullPredicate(reference)); } List<Expression> disjuncts = new ArrayList<>(); disjuncts.addAll(domain.getValues().getValuesProcessor().transform( ranges -> extractDisjuncts(domain.getType(), ranges, reference), discreteValues -> extractDisjuncts(domain.getType(), discreteValues, reference), allOrNone -> { throw new IllegalStateException("Case should not be reachable"); })); // Add nullability disjuncts if (domain.isNullAllowed()) { disjuncts.add(new IsNullPredicate(reference)); } return combineDisjunctsWithDefault(disjuncts, TRUE_LITERAL); }
private Expression toPredicate(Domain domain, SymbolReference reference) { if (domain.getValues().isNone()) { return domain.isNullAllowed() ? new IsNullPredicate(reference) : FALSE_LITERAL; } if (domain.getValues().isAll()) { return domain.isNullAllowed() ? TRUE_LITERAL : new NotExpression(new IsNullPredicate(reference)); } List<Expression> disjuncts = new ArrayList<>(); disjuncts.addAll(domain.getValues().getValuesProcessor().transform( ranges -> extractDisjuncts(domain.getType(), ranges, reference), discreteValues -> extractDisjuncts(domain.getType(), discreteValues, reference), allOrNone -> { throw new IllegalStateException("Case should not be reachable"); })); // Add nullability disjuncts if (domain.isNullAllowed()) { disjuncts.add(new IsNullPredicate(reference)); } return combineDisjunctsWithDefault(disjuncts, TRUE_LITERAL); }
@Override public Node visitNullPredicate(SqlBaseParser.NullPredicateContext context) { Expression child = (Expression) visit(context.value); if (context.NOT() == null) { return new IsNullPredicate(getLocation(context), child); } return new IsNotNullPredicate(getLocation(context), child); }
@Override protected Object visitIsNullPredicate(IsNullPredicate node, Object context) { Object value = process(node.getValue(), context); if (value instanceof Expression) { return new IsNullPredicate(toExpression(value, type(node.getValue()))); } return value == null; }
@Override protected Object visitIsNullPredicate(IsNullPredicate node, Object context) { Object value = process(node.getValue(), context); if (value instanceof Expression) { return new IsNullPredicate(toExpression(value, type(node.getValue()))); } return value == null; }
@Override public Node visitNullPredicate(SqlBaseParser.NullPredicateContext context) { Expression child = (Expression) visit(context.value); if (context.NOT() == null) { return new IsNullPredicate(getLocation(context), child); } return new IsNotNullPredicate(getLocation(context), child); }
@Test public void testNormalize() { assertNormalize(new ComparisonExpression(EQUAL, name("a"), new LongLiteral("1"))); assertNormalize(new IsNullPredicate(name("a"))); assertNormalize(new NotExpression(new LikePredicate(name("a"), new StringLiteral("x%"), Optional.empty()))); assertNormalize( new NotExpression(new ComparisonExpression(EQUAL, name("a"), new LongLiteral("1"))), new ComparisonExpression(NOT_EQUAL, name("a"), new LongLiteral("1"))); assertNormalize( new NotExpression(new ComparisonExpression(NOT_EQUAL, name("a"), new LongLiteral("1"))), new ComparisonExpression(EQUAL, name("a"), new LongLiteral("1"))); // Cannot normalize IS DISTINCT FROM yet assertNormalize(new NotExpression(new ComparisonExpression(IS_DISTINCT_FROM, name("a"), new LongLiteral("1")))); }
@Test public void testNormalize() { assertNormalize(new ComparisonExpression(EQUAL, name("a"), new LongLiteral("1"))); assertNormalize(new IsNullPredicate(name("a"))); assertNormalize(new NotExpression(new LikePredicate(name("a"), new StringLiteral("x%"), Optional.empty()))); assertNormalize( new NotExpression(new ComparisonExpression(EQUAL, name("a"), new LongLiteral("1"))), new ComparisonExpression(NOT_EQUAL, name("a"), new LongLiteral("1"))); assertNormalize( new NotExpression(new ComparisonExpression(NOT_EQUAL, name("a"), new LongLiteral("1"))), new ComparisonExpression(EQUAL, name("a"), new LongLiteral("1"))); // Cannot normalize IS DISTINCT FROM yet assertNormalize(new NotExpression(new ComparisonExpression(IS_DISTINCT_FROM, name("a"), new LongLiteral("1")))); }