private static Expression someExpression(Expression expression1, Expression expression2) { return new ComparisonExpression(GREATER_THAN, expression1, expression2); }
private static ComparisonExpression equals(Expression expression1, Expression expression2) { return new ComparisonExpression(ComparisonExpression.Operator.EQUAL, expression1, expression2); }
private static Expression isGreaterThan(Symbol symbol, long value) { return new ComparisonExpression( ComparisonExpression.Operator.GREATER_THAN, symbol.toSymbolReference(), bigint(value)); }
private static Expression isGreaterThan(Symbol symbol, long value) { return new ComparisonExpression( ComparisonExpression.Operator.GREATER_THAN, symbol.toSymbolReference(), bigint(value)); }
private FilterNode addFilterForExcept(AggregationNode aggregation, Symbol firstSource, List<Symbol> remainingSources) { ImmutableList.Builder<Expression> predicatesBuilder = ImmutableList.builder(); predicatesBuilder.add(new ComparisonExpression(GREATER_THAN_OR_EQUAL, firstSource.toSymbolReference(), new GenericLiteral("BIGINT", "1"))); for (Symbol symbol : remainingSources) { predicatesBuilder.add(new ComparisonExpression(EQUAL, symbol.toSymbolReference(), new GenericLiteral("BIGINT", "0"))); } return new FilterNode(idAllocator.getNextId(), aggregation, ExpressionUtils.and(predicatesBuilder.build())); }
private FilterNode addFilterForExcept(AggregationNode aggregation, Symbol firstSource, List<Symbol> remainingSources) { ImmutableList.Builder<Expression> predicatesBuilder = ImmutableList.builder(); predicatesBuilder.add(new ComparisonExpression(GREATER_THAN_OR_EQUAL, firstSource.toSymbolReference(), new GenericLiteral("BIGINT", "1"))); for (Symbol symbol : remainingSources) { predicatesBuilder.add(new ComparisonExpression(EQUAL, symbol.toSymbolReference(), new GenericLiteral("BIGINT", "0"))); } return new FilterNode(idAllocator.getNextId(), aggregation, ExpressionUtils.and(predicatesBuilder.build())); }
@Override protected ExtractionResult visitBetweenPredicate(BetweenPredicate node, Boolean complement) { // Re-write as two comparison expressions return process(and( new ComparisonExpression(GREATER_THAN_OR_EQUAL, node.getValue(), node.getMin()), new ComparisonExpression(LESS_THAN_OR_EQUAL, node.getValue(), node.getMax())), complement); }
@Override protected ExtractionResult visitBetweenPredicate(BetweenPredicate node, Boolean complement) { // Re-write as two comparison expressions return process(and( new ComparisonExpression(GREATER_THAN_OR_EQUAL, node.getValue(), node.getMin()), new ComparisonExpression(LESS_THAN_OR_EQUAL, node.getValue(), node.getMax())), complement); }
private FilterNode addFilterForIntersect(AggregationNode aggregation) { ImmutableList<Expression> predicates = aggregation.getAggregations().keySet().stream() .map(column -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, column.toSymbolReference(), new GenericLiteral("BIGINT", "1"))) .collect(toImmutableList()); return new FilterNode(idAllocator.getNextId(), aggregation, ExpressionUtils.and(predicates)); }
private FilterNode addFilterForIntersect(AggregationNode aggregation) { ImmutableList<Expression> predicates = aggregation.getAggregations().keySet().stream() .map(column -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, column.toSymbolReference(), new GenericLiteral("BIGINT", "1"))) .collect(toImmutableList()); return new FilterNode(idAllocator.getNextId(), aggregation, ExpressionUtils.and(predicates)); }
private Expression combineRangeWithExcludedPoints(Type type, SymbolReference reference, Range range, List<Expression> excludedPoints) { if (excludedPoints.isEmpty()) { return processRange(type, range, reference); } Expression excludedPointsExpression = new NotExpression(new InPredicate(reference, new InListExpression(excludedPoints))); if (excludedPoints.size() == 1) { excludedPointsExpression = new ComparisonExpression(NOT_EQUAL, reference, getOnlyElement(excludedPoints)); } return combineConjuncts(processRange(type, range, reference), excludedPointsExpression); }
private static IfExpression createIfExpression(Expression left, Expression right, ComparisonExpression.Operator operator, Expression result, Type trueValueType) { return new IfExpression( new ComparisonExpression(operator, left, right), result, new Cast(new NullLiteral(), trueValueType.getTypeSignature().toString())); } }
private static IfExpression createIfExpression(Expression left, Expression right, ComparisonExpression.Operator operator, Expression result, Type trueValueType) { return new IfExpression( new ComparisonExpression(operator, left, right), result, new Cast(new NullLiteral(), trueValueType.getTypeSignature().toString())); } }
@Override public Result apply(SampleNode sample, Captures captures, Context context) { return Result.ofPlanNode(new FilterNode( sample.getId(), sample.getSource(), new ComparisonExpression( ComparisonExpression.Operator.LESS_THAN, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of()), new DoubleLiteral(Double.toString(sample.getSampleRatio()))))); } }
private Expression combineRangeWithExcludedPoints(Type type, SymbolReference reference, Range range, List<Expression> excludedPoints) { if (excludedPoints.isEmpty()) { return processRange(type, range, reference); } Expression excludedPointsExpression = new NotExpression(new InPredicate(reference, new InListExpression(excludedPoints))); if (excludedPoints.size() == 1) { excludedPointsExpression = new ComparisonExpression(NOT_EQUAL, reference, getOnlyElement(excludedPoints)); } return combineConjuncts(processRange(type, range, reference), excludedPointsExpression); }
@Override public Result apply(SampleNode sample, Captures captures, Context context) { return Result.ofPlanNode(new FilterNode( sample.getId(), sample.getSource(), new ComparisonExpression( ComparisonExpression.Operator.LESS_THAN, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of()), new DoubleLiteral(Double.toString(sample.getSampleRatio()))))); } }
private ComparisonExpression createEqualsExpression(Symbol left, Symbol right) { return new ComparisonExpression(EQUAL, left.toSymbolReference(), right.toSymbolReference()); }
@Override public Node visitComparison(SqlBaseParser.ComparisonContext context) { return new ComparisonExpression( getLocation(context.comparisonOperator()), getComparisonOperator(((TerminalNode) context.comparisonOperator().getChild(0)).getSymbol()), (Expression) visit(context.value), (Expression) visit(context.right)); }
@Override public Node visitComparison(SqlBaseParser.ComparisonContext context) { return new ComparisonExpression( getLocation(context.comparisonOperator()), getComparisonOperator(((TerminalNode) context.comparisonOperator().getChild(0)).getSymbol()), (Expression) visit(context.value), (Expression) visit(context.right)); }
@Test public void testDelete() { assertStatement("DELETE FROM t", new Delete(table(QualifiedName.of("t")), Optional.empty())); assertStatement("DELETE FROM \"awesome table\"", new Delete(table(QualifiedName.of("awesome table")), Optional.empty())); assertStatement("DELETE FROM t WHERE a = b", new Delete(table(QualifiedName.of("t")), Optional.of( new ComparisonExpression(ComparisonExpression.Operator.EQUAL, new Identifier("a"), new Identifier("b"))))); }