@Override protected Object visitArithmeticBinary(ArithmeticBinaryExpression node, Object context) { Object left = process(node.getLeft(), context); if (left == null) { return null; } Object right = process(node.getRight(), context); if (right == null) { return null; } if (hasUnresolvedValue(left, right)) { return new ArithmeticBinaryExpression(node.getOperator(), toExpression(left, type(node.getLeft())), toExpression(right, type(node.getRight()))); } return invokeOperator(OperatorType.valueOf(node.getOperator().name()), types(node.getLeft(), node.getRight()), ImmutableList.of(left, right)); }
@Override protected String visitArithmeticBinary(ArithmeticBinaryExpression node, Void context) { return formatBinaryExpression(node.getOperator().getValue(), node.getLeft(), node.getRight()); }
private static Expression multiply(Expression expression1, Expression expression2) { return new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, expression1, expression2); }
@Override protected Object visitArithmeticBinary(ArithmeticBinaryExpression node, Object context) { Object left = process(node.getLeft(), context); if (left == null) { return null; } Object right = process(node.getRight(), context); if (right == null) { return null; } if (hasUnresolvedValue(left, right)) { return new ArithmeticBinaryExpression(node.getType(), toExpression(left, expressionTypes.get(node.getLeft())), toExpression(right, expressionTypes.get(node.getRight()))); } return invokeOperator(OperatorType.valueOf(node.getType().name()), types(node.getLeft(), node.getRight()), ImmutableList.of(left, right)); }
@Override protected Void visitArithmeticBinary(ArithmeticBinaryExpression node, Integer indentLevel) { print(indentLevel, node.getType().toString()); super.visitArithmeticBinary(node, indentLevel + 1); return null; }
@Override protected Void visitArithmeticBinary(ArithmeticBinaryExpression node, Integer indentLevel) { print(indentLevel, node.getOperator().toString()); super.visitArithmeticBinary(node, indentLevel + 1); return null; }
@Override protected Type visitArithmeticBinary(ArithmeticBinaryExpression node, StackableAstVisitorContext<Context> context) { return getOperator(context, node, OperatorType.valueOf(node.getOperator().name()), node.getLeft(), node.getRight()); }
private static Expression add(Expression expression1, Expression expression2) { return new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.ADD, expression1, expression2); }
@Override protected Void visitArithmeticBinary(ArithmeticBinaryExpression node, Integer indentLevel) { print(indentLevel, node.getOperator().toString()); super.visitArithmeticBinary(node, indentLevel + 1); return null; }
@Override protected Boolean visitArithmeticBinary(ArithmeticBinaryExpression actual, Node expectedExpression) { if (expectedExpression instanceof ArithmeticBinaryExpression) { ArithmeticBinaryExpression expected = (ArithmeticBinaryExpression) expectedExpression; if (actual.getOperator() == expected.getOperator()) { return process(actual.getLeft(), expected.getLeft()) && process(actual.getRight(), expected.getRight()); } } return false; }
public static Expression rewriteGroupingOperation(GroupingOperation expression, List<Set<Integer>> groupingSets, Map<NodeRef<Expression>, FieldId> columnReferenceFields, Optional<Symbol> groupIdSymbol) { requireNonNull(groupIdSymbol, "groupIdSymbol is null"); // No GroupIdNode and a GROUPING() operation imply a single grouping, which // means that any columns specified as arguments to GROUPING() will be included // in the group and none of them will be aggregated over. Hence, re-write the // GroupingOperation to a constant literal of 0. // See SQL:2011:4.16.2 and SQL:2011:6.9.10. if (groupingSets.size() == 1) { return new LongLiteral("0"); } else { checkState(groupIdSymbol.isPresent(), "groupId symbol is missing"); RelationId relationId = columnReferenceFields.get(NodeRef.of(expression.getGroupingColumns().get(0))).getRelationId(); List<Integer> columns = expression.getGroupingColumns().stream() .map(NodeRef::of) .peek(groupingColumn -> checkState(columnReferenceFields.containsKey(groupingColumn), "the grouping column is not in the columnReferencesField map")) .map(columnReferenceFields::get) .map(fieldId -> translateFieldToInteger(fieldId, relationId)) .collect(toImmutableList()); List<Expression> groupingResults = groupingSets.stream() .map(groupingSet -> String.valueOf(calculateGrouping(groupingSet, columns))) .map(LongLiteral::new) .collect(toImmutableList()); // It is necessary to add a 1 to the groupId because the underlying array is indexed starting at 1 return new SubscriptExpression( new ArrayConstructor(groupingResults), new ArithmeticBinaryExpression(ADD, groupIdSymbol.get().toSymbolReference(), new GenericLiteral("BIGINT", "1"))); } }
@Override protected RowExpression visitArithmeticBinary(ArithmeticBinaryExpression node, Void context) { RowExpression left = process(node.getLeft(), context); RowExpression right = process(node.getRight(), context); return call( arithmeticExpressionSignature(node.getOperator(), getType(node), left.getType(), right.getType()), getType(node), left, right); }