public int addGroupExpr(SqlNode expr) { int ref = lookupGroupExpr(expr); if (ref >= 0) { return ref; } final int index = groupExprs.size(); groupExprs.add(expr); String name = nameMap.get(expr.toString()); RexNode convExpr = bb.convertExpression(expr); addExpr(convExpr, name); if (expr instanceof SqlCall) { SqlCall call = (SqlCall) expr; for (Pair<SqlNode, AuxiliaryConverter> p : SqlStdOperatorTable.convertGroupToAuxiliaryCalls(call)) { addAuxiliaryGroupExpr(p.left, index, p.right); } } return index; }
final AggregatingSelectScope.Resolved r = scope.resolved.get(); for (SqlNode groupExpr : r.groupExprList) { aggConverter.addGroupExpr(groupExpr); List<Pair<RexNode, String>> preExprs = aggConverter.getPreExprs(); aggConverter.getAggCalls()), false);
final int ref = agg.lookupGroupExpr(expandedGroupExpr); if (ref >= 0) { return rexBuilder.makeInputRef(root, ref); final RexNode rex = agg.lookupAggregates((SqlCall) expr); if (rex != null) { return rex;
final AggregatingSelectScope.Resolved r = scope.resolved.get(); for (SqlNode groupExpr : r.groupExprList) { aggConverter.addGroupExpr(groupExpr); List<Pair<RexNode, String>> preExprs = aggConverter.getPreExprs(); aggConverter.getAggCalls()), false);
final AggregatingSelectScope.Resolved r = scope.resolved.get(); for (SqlNode groupExpr : r.groupExprList) { aggConverter.addGroupExpr(groupExpr); List<Pair<RexNode, String>> preExprs = aggConverter.getPreExprs(); aggConverter.getAggCalls()), false);
final int ref = agg.lookupGroupExpr(expandedGroupExpr); if (ref >= 0) { return rexBuilder.makeInputRef(root, ref); final RexNode rex = agg.lookupAggregates((SqlCall) expr); if (rex != null) { return rex;
final int ref = agg.lookupGroupExpr(expandedGroupExpr); if (ref >= 0) { return rexBuilder.makeInputRef(root, ref); final RexNode rex = agg.lookupAggregates((SqlCall) expr); if (rex != null) { return rex;
final AggregatingSelectScope.Resolved r = scope.resolved.get(); for (SqlNode groupExpr : r.groupExprList) { aggConverter.addGroupExpr(groupExpr); List<Pair<RexNode, String>> preExprs = aggConverter.getPreExprs(); aggConverter.getAggCalls()), false);
final int ref = agg.lookupGroupExpr(expandedGroupExpr); if (ref >= 0) { return rexBuilder.makeInputRef(root, ref); final RexNode rex = agg.lookupAggregates((SqlCall) expr); if (rex != null) { return rex;
case FILTER: assert filter == null; translateAgg(call.operand(0), call.operand(1), orderList, outerCall); return; case WITHIN_GROUP: assert orderList == null; translateAgg(call.operand(0), filter, call.operand(1), outerCall); return; argTypes.add(convertedExpr.getType()); args.add(lookupOrCreateGroupExpr(convertedExpr)); rexBuilder.makeCall(SqlStdOperatorTable.IS_TRUE, convertedExpr); filterArg = lookupOrCreateGroupExpr(convertedExpr); .map(fieldCollation -> new RelFieldCollation( lookupOrCreateGroupExpr(fieldCollation.left), fieldCollation.getDirection(), fieldCollation.getNullDirection()))
argTypes.add(convertedExpr.getType()); args.add(lookupOrCreateGroupExpr(convertedExpr)); rexBuilder.makeCall(SqlStdOperatorTable.IS_TRUE, convertedExpr); filterArg = lookupOrCreateGroupExpr(convertedExpr);
argTypes.add(convertedExpr.getType()); args.add(lookupOrCreateGroupExpr(convertedExpr)); rexBuilder.makeCall(SqlStdOperatorTable.IS_TRUE, convertedExpr); filterArg = lookupOrCreateGroupExpr(convertedExpr);
argTypes.add(convertedExpr.getType()); args.add(lookupOrCreateGroupExpr(convertedExpr)); rexBuilder.makeCall(SqlStdOperatorTable.IS_TRUE, convertedExpr); filterArg = lookupOrCreateGroupExpr(convertedExpr);
case FILTER: case WITHIN_GROUP: translateAgg(call); return null; case SELECT: } else { translateAgg(call); return null;
if (!aggregatingSelectScope.resolved.get().indicator) { return rexBuilder.makeExactLiteral( TWO.pow(effectiveArgCount(call)).subtract(BigDecimal.ONE), type); } else { final List<Integer> operands; operands = Lists.newArrayList(); for (SqlNode operand : call.getOperandList()) { final int x = lookupGroupExpr(operand); assert x >= 0; operands.add(x); int shift = operands.size(); for (int operand : operands) { node = bitValue(node, type, operand, --shift);
if (!aggregatingSelectScope.resolved.get().indicator) { return rexBuilder.makeExactLiteral( TWO.pow(effectiveArgCount(call)).subtract(BigDecimal.ONE), type); } else { final List<Integer> operands; operands = Lists.newArrayList(); for (SqlNode operand : call.getOperandList()) { final int x = lookupGroupExpr(operand); assert x >= 0; operands.add(x); int shift = operands.size(); for (int operand : operands) { node = bitValue(node, type, operand, --shift);
public Void visit(SqlCall call) { switch (call.getKind()) { case FILTER: translateAgg((SqlCall) call.operand(0), call.operand(1), call); return null; case SELECT: } else { translateAgg(call, null, call); return null;
public Void visit(SqlCall call) { switch (call.getKind()) { case FILTER: translateAgg((SqlCall) call.operand(0), call.operand(1), call); return null; case SELECT: } else { translateAgg(call, null, call); return null;
public Void visit(SqlCall call) { switch (call.getKind()) { case FILTER: translateAgg((SqlCall) call.operand(0), call.operand(1), call); return null; case SELECT: } else { translateAgg(call, null, call); return null;
/** * Converts the SELECT, GROUP BY and HAVING clauses of an aggregate query. * * <p>This method extracts SELECT, GROUP BY and HAVING clauses, and creates * an {@link AggConverter}, then delegates to {@link #createAggImpl}. * Derived class may override this method to change any of those clauses or * specify a different {@link AggConverter}. * * @param bb Scope within which to resolve identifiers * @param select Query * @param orderExprList Additional expressions needed to implement ORDER BY */ protected void convertAgg( Blackboard bb, SqlSelect select, List<SqlNode> orderExprList) { assert bb.root != null : "precondition: child != null"; SqlNodeList groupList = select.getGroup(); SqlNodeList selectList = select.getSelectList(); SqlNode having = select.getHaving(); final AggConverter aggConverter = new AggConverter(bb, select); createAggImpl( bb, aggConverter, selectList, groupList, having, orderExprList); }