@Override public int getGroupCount() { final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope); if (selectScope == null) { // Probably "VALUES expr". Treat same as "SELECT expr GROUP BY ()" return 0; } final SqlSelect select = selectScope.getNode(); final SqlNodeList group = select.getGroup(); if (group != null) { int n = 0; for (SqlNode groupItem : group) { if (!(groupItem instanceof SqlNodeList) || ((SqlNodeList) groupItem).size() != 0) { ++n; } } return n; } return validator.isAggregate(select) ? 0 : -1; }
@Override public int getGroupCount() { final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope); if (selectScope == null) { // Probably "VALUES expr". Treat same as "SELECT expr GROUP BY ()" return 0; } final SqlSelect select = selectScope.getNode(); final SqlNodeList group = select.getGroup(); if (group != null) { int n = 0; for (SqlNode groupItem : group) { if (!(groupItem instanceof SqlNodeList) || ((SqlNodeList) groupItem).size() != 0) { ++n; } } return n; } return validator.isAggregate(select) ? 0 : -1; }
private SqlTreeNode convertSelect(SqlSelect query) { SqlTreeNode input = convertFrom(query.getFrom()); SqlTreeNode filter = convertWhere(input, query.getWhere()); if (filter != null) { input = filter; } if (validator.isAggregate(query)) { SqlNodeList groupList = query.getGroup(); input = SqlTreeNodes.group(groupList.getParserPosition(), input, groupList); } else { SqlNodeList selectList = query.getSelectList(); input = SqlTreeNodes.select(query.getParserPosition(), input, selectList); } return convertOrder(query, input); }
cluster.traitSet().canonize(RelCollations.of(collationList)); if (validator.isAggregate(select)) { convertAgg( bb,
cluster.traitSet().canonize(RelCollations.of(collationList)); if (validator.isAggregate(select)) { convertAgg( bb,
cluster.traitSet().canonize(RelCollations.of(collationList)); if (validator.isAggregate(select)) { convertAgg( bb,
cluster.traitSet().canonize(RelCollations.of(collationList)); if (validator.isAggregate(select)) { convertAgg( bb,
@Override public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) { super.validateCall(call, validator, scope, operandScope); final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope); assert selectScope != null; final SqlSelect select = selectScope.getNode(); if (!validator.isAggregate(select)) { throw validator.newValidationError(call, Static.RESOURCE.groupingInAggregate(getName())); } final AggregatingSelectScope aggregatingSelectScope = SqlValidatorUtil.getEnclosingAggregateSelectScope(scope); if (aggregatingSelectScope == null) { // We're probably in the GROUP BY clause throw validator.newValidationError(call, Static.RESOURCE.groupingInWrongClause(getName())); } for (SqlNode operand : call.getOperandList()) { if (scope instanceof OrderByScope) { operand = validator.expandOrderExpr(select, operand); } else { operand = validator.expand(operand, scope); } if (!aggregatingSelectScope.resolved.get().isGroupingExpr(operand)) { throw validator.newValidationError(operand, Static.RESOURCE.groupingArgument(getName())); } } }
@Override public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) { super.validateCall(call, validator, scope, operandScope); final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope); assert selectScope != null; final SqlSelect select = selectScope.getNode(); if (!validator.isAggregate(select)) { throw validator.newValidationError(call, Static.RESOURCE.groupingInAggregate(getName())); } final AggregatingSelectScope aggregatingSelectScope = SqlValidatorUtil.getEnclosingAggregateSelectScope(scope); if (aggregatingSelectScope == null) { // We're probably in the GROUP BY clause throw validator.newValidationError(call, Static.RESOURCE.groupingInWrongClause(getName())); } for (SqlNode operand : call.getOperandList()) { if (scope instanceof OrderByScope) { operand = validator.expandOrderExpr(select, operand); } else { operand = validator.expand(operand, scope); } if (!aggregatingSelectScope.resolved.get().isGroupingExpr(operand)) { throw validator.newValidationError(operand, Static.RESOURCE.groupingArgument(getName())); } } }