public static Expression or(Expression... expressions) { return or(Arrays.asList(expressions)); }
public static Expression or(Expression... expressions) { return or(Arrays.asList(expressions)); }
public static Expression combineDisjunctsWithDefault(Collection<Expression> expressions, Expression emptyDefault) { requireNonNull(expressions, "expressions is null"); List<Expression> disjuncts = expressions.stream() .flatMap(e -> ExpressionUtils.extractDisjuncts(e).stream()) .filter(e -> !e.equals(FALSE_LITERAL)) .collect(toList()); disjuncts = removeDuplicates(disjuncts); if (disjuncts.contains(TRUE_LITERAL)) { return TRUE_LITERAL; } return disjuncts.isEmpty() ? emptyDefault : or(disjuncts); }
public static Expression combineDisjunctsWithDefault(Collection<Expression> expressions, Expression emptyDefault) { requireNonNull(expressions, "expressions is null"); List<Expression> disjuncts = expressions.stream() .flatMap(e -> ExpressionUtils.extractDisjuncts(e).stream()) .filter(e -> !e.equals(FALSE_LITERAL)) .collect(toList()); disjuncts = removeDuplicates(disjuncts); if (disjuncts.contains(TRUE_LITERAL)) { return TRUE_LITERAL; } return disjuncts.isEmpty() ? emptyDefault : or(disjuncts); }
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()); }; }
@Override protected ExtractionResult visitInPredicate(InPredicate node, Boolean complement) { if (!(node.getValueList() instanceof InListExpression)) { return super.visitInPredicate(node, complement); } InListExpression valueList = (InListExpression) node.getValueList(); checkState(!valueList.getValues().isEmpty(), "InListExpression should never be empty"); ImmutableList.Builder<Expression> disjuncts = ImmutableList.builder(); for (Expression expression : valueList.getValues()) { disjuncts.add(new ComparisonExpression(EQUAL, node.getValue(), expression)); } ExtractionResult extractionResult = process(or(disjuncts.build()), complement); // preserve original IN predicate as remaining predicate if (extractionResult.tupleDomain.isAll()) { Expression originalPredicate = node; if (complement) { originalPredicate = new NotExpression(originalPredicate); } return new ExtractionResult(extractionResult.tupleDomain, originalPredicate); } return extractionResult; }
@Override protected ExtractionResult visitInPredicate(InPredicate node, Boolean complement) { if (!(node.getValueList() instanceof InListExpression)) { return super.visitInPredicate(node, complement); } InListExpression valueList = (InListExpression) node.getValueList(); checkState(!valueList.getValues().isEmpty(), "InListExpression should never be empty"); ImmutableList.Builder<Expression> disjuncts = ImmutableList.builder(); for (Expression expression : valueList.getValues()) { disjuncts.add(new ComparisonExpression(EQUAL, node.getValue(), expression)); } ExtractionResult extractionResult = process(or(disjuncts.build()), complement); // preserve original IN predicate as remaining predicate if (extractionResult.tupleDomain.isAll()) { Expression originalPredicate = node; if (complement) { originalPredicate = new NotExpression(originalPredicate); } return new ExtractionResult(extractionResult.tupleDomain, originalPredicate); } return extractionResult; }
normalizeConjuncts(equals(DE, EE), lessThan(FE, bigintLiteral(100)), or(equals(AE, DE), isNull(AE))));
normalizeConjuncts(equals(DE, EE), lessThan(FE, bigintLiteral(100)), or(equals(AE, DE), isNull(AE))));
normalizeConjuncts(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), or(equals(AE, DE), isNull(DE))));
normalizeConjuncts(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), or(equals(AE, DE), isNull(DE))));
assertEquals(toPredicate(tupleDomain), or(lessThan(C_BIGINT, bigintLiteral(1L)), isNull(C_BIGINT))); assertEquals(toPredicate(tupleDomain), or(equal(C_COLOR, colorLiteral(COLOR_VALUE_1)), isNull(C_COLOR))); assertEquals(toPredicate(tupleDomain), or(not(equal(C_COLOR, colorLiteral(COLOR_VALUE_1))), isNull(C_COLOR)));
assertEquals(toPredicate(tupleDomain), or(lessThan(C_BIGINT, bigintLiteral(1L)), isNull(C_BIGINT))); assertEquals(toPredicate(tupleDomain), or(equal(C_COLOR, colorLiteral(COLOR_VALUE_1)), isNull(C_COLOR))); assertEquals(toPredicate(tupleDomain), or(not(equal(C_COLOR, colorLiteral(COLOR_VALUE_1))), isNull(C_COLOR)));
or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(3L)), (between(C_BIGINT, bigintLiteral(5L), bigintLiteral(7L))), (between(C_BIGINT, bigintLiteral(9L), bigintLiteral(11L))))); assertEquals(toPredicate(tupleDomain), or(and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))), between(C_BIGINT, bigintLiteral(7L), bigintLiteral(9L)))); assertEquals(toPredicate(tupleDomain), or( and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThan(C_BIGINT, bigintLiteral(9L))),
or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(3L)), (between(C_BIGINT, bigintLiteral(5L), bigintLiteral(7L))), (between(C_BIGINT, bigintLiteral(9L), bigintLiteral(11L))))); assertEquals(toPredicate(tupleDomain), or(and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))), between(C_BIGINT, bigintLiteral(7L), bigintLiteral(9L)))); assertEquals(toPredicate(tupleDomain), or( and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThan(C_BIGINT, bigintLiteral(9L))),