&& queryBlock.getGroupBy().getItems().size() > 0) { return createCountUseSubQuery(select, dbType);
groupBy = new SQLSelectGroupByClause(); groupBy.addItem(this.getExprParser().parseSelectGroupByItem()); if (!(lexer.token() == (Token.COMMA))) { break; for (SQLExpr sqlExpr : groupBy.getItems()) { mySqlGroupBy.addItem(sqlExpr); groupBy = new SQLSelectGroupByClause(); groupBy.setHaving(this.exprParser.expr());
public SQLSelectGroupByClause clone() { SQLSelectGroupByClause x = new SQLSelectGroupByClause(); for (SQLExpr item : items) { SQLExpr item2 = item.clone(); item2.setParent(x); x.items.add(item2); } if (having != null) { x.setHaving(having.clone()); } x.withRollUp = withRollUp; x.withCube = withCube; return x; } }
public boolean visit(SQLSelectGroupByClause x) { boolean rollup = x.isWithRollUp(); boolean cube = x.isWithCube(); int itemSize = x.getItems().size(); if (itemSize > 0) { print0(ucase ? "GROUP BY " : "group by "); x.getItems().get(i).accept(this); if (x.getHaving() != null) { println(); print0(ucase ? "HAVING " : "having "); x.getHaving().accept(this); if (x.isWithRollUp() && !oracle) { print0(ucase ? " WITH ROLLUP" : " with rollup"); if (x.isWithCube() && !oracle) { print0(ucase ? " WITH CUBE" : " with cube");
SQLSelectGroupByClause groupBy = new SQLSelectGroupByClause(); if (lexer.identifierEquals(FnvHash.Constants.ROLLUP)) { lexer.nextToken(); accept(Token.LPAREN); groupBy.setWithRollUp(true); groupBy.setWithCube(true); groupBy.addItem(item); if (groupBy.isWithRollUp() || groupBy.isWithCube()) { accept(Token.RPAREN); groupBy.setHaving(having); groupBy.setWithCube(true); } else if(lexer.identifierEquals(FnvHash.Constants.ROLLUP)) { lexer.nextToken(); groupBy.setWithRollUp(true); } else if (lexer.identifierEquals(FnvHash.Constants.RS) && JdbcConstants.DB2.equals(dbType)) { SQLSelectGroupByClause groupBy = new SQLSelectGroupByClause(); groupBy.setHaving(this.exprParser.expr()); groupBy.addItem(item); groupBy.setWithRollUp(true);
private void parseAggGroupCommon(SchemaConfig schema, SQLStatement stmt, RouteResultset rrs, MySqlSelectQueryBlock mysqlSelectQuery, TableConfig tc) throws SQLException { Map<String, String> aliaColumns = new HashMap<>(); boolean isDistinct = (mysqlSelectQuery.getDistionOption() == SQLSetQuantifier.DISTINCT) || (mysqlSelectQuery.getDistionOption() == SQLSetQuantifier.DISTINCTROW); parseAggExprCommon(schema, rrs, mysqlSelectQuery, aliaColumns, tc, isDistinct); if (rrs.isNeedOptimizer()) { tryAddLimit(schema, tc, mysqlSelectQuery); rrs.setSqlStatement(stmt); return; } // distinct change to group by if (isDistinct) { mysqlSelectQuery.setDistionOption(0); SQLSelectGroupByClause groupBy = new SQLSelectGroupByClause(); for (String fieldName : aliaColumns.keySet()) { groupBy.addItem(new SQLIdentifierExpr(fieldName)); } mysqlSelectQuery.setGroupBy(groupBy); } // setGroupByCols if (mysqlSelectQuery.getGroupBy() != null) { List<SQLExpr> groupByItems = mysqlSelectQuery.getGroupBy().getItems(); String[] groupByCols = buildGroupByCols(groupByItems, aliaColumns); rrs.setGroupByCols(groupByCols); } if (isDistinct) { rrs.changeNodeSqlAfterAddLimit(statementToString(stmt), 0, -1); } }
private void handleGroupBy(SQLSelectGroupByClause groupBy) { for (SQLExpr p : groupBy.getItems()) { if (p instanceof MySqlOrderingExpr) { MySqlOrderingExpr groupitem = (MySqlOrderingExpr) p; SQLExpr q = groupitem.getExpr(); MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, this.charsetIndex, this.metaManager); q.accept(v); this.tableNode = tableNode.groupBy(v.getItem(), groupitem.getType()); } else { MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, this.charsetIndex, this.metaManager); p.accept(v); this.tableNode = tableNode.groupBy(v.getItem(), SQLOrderingSpecification.ASC); } } if (groupBy.isWithRollUp()) { throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "with rollup is not supported yet!"); } if (groupBy.getHaving() != null) { handleHavingCondition(groupBy.getHaving()); } }
groupBy.accept(visitor);
public boolean visit(SQLSelectGroupByClause x) { WallVisitorUtils.checkHaving(this, x.getHaving()); return true; }
@Override public SQLSelectBuilderImpl groupBy(String expr) { SQLSelectQueryBlock queryBlock = getQueryBlock(); SQLSelectGroupByClause groupBy = queryBlock.getGroupBy(); if (groupBy == null) { groupBy = createGroupBy(); queryBlock.setGroupBy(groupBy); } SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType); groupBy.addItem(exprObj); return this; }
protected SQLSelectGroupByClause createGroupBy() { return new SQLSelectGroupByClause(); }
@Override public SQLSelectBuilderImpl having(String expr) { SQLSelectQueryBlock queryBlock = getQueryBlock(); SQLSelectGroupByClause groupBy = queryBlock.getGroupBy(); if (groupBy == null) { groupBy = createGroupBy(); queryBlock.setGroupBy(groupBy); } SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType); groupBy.setHaving(exprObj); return this; }
public boolean visit(SQLSelectGroupByClause x) { boolean rollup = x.isWithRollUp(); boolean cube = x.isWithCube(); int itemSize = x.getItems().size(); if (itemSize > 0) { print0(ucase ? "GROUP BY " : "group by "); x.getItems().get(i).accept(this); if (x.getHaving() != null) { println(); print0(ucase ? "HAVING " : "having "); x.getHaving().accept(this); if (x.isWithRollUp() && !oracle) { print0(ucase ? " WITH ROLLUP" : " with rollup"); if (x.isWithCube() && !oracle) { print0(ucase ? " WITH CUBE" : " with cube");
SQLSelectGroupByClause groupBy = new SQLSelectGroupByClause(); if (lexer.identifierEquals(FnvHash.Constants.ROLLUP)) { lexer.nextToken(); accept(Token.LPAREN); groupBy.setWithRollUp(true); groupBy.setWithCube(true); groupBy.addItem(item); if (groupBy.isWithRollUp() || groupBy.isWithCube()) { accept(Token.RPAREN); groupBy.setHaving(having); groupBy.setWithCube(true); } else if(lexer.identifierEquals(FnvHash.Constants.ROLLUP)) { lexer.nextToken(); groupBy.setWithRollUp(true); } else if (lexer.identifierEquals(FnvHash.Constants.RS) && JdbcConstants.DB2.equals(dbType)) { SQLSelectGroupByClause groupBy = new SQLSelectGroupByClause(); groupBy.setHaving(this.exprParser.expr()); groupBy.addItem(item); groupBy.setWithRollUp(true);
x.getGroupBy().accept(this);
public boolean visit(SQLSelectGroupByClause x) { WallVisitorUtils.checkHaving(this, x.getHaving()); return true; }
public SQLSelectGroupByClause clone() { SQLSelectGroupByClause x = new SQLSelectGroupByClause(); for (SQLExpr item : items) { SQLExpr item2 = item.clone(); item2.setParent(x); x.items.add(item2); } if (having != null) { x.setHaving(having.clone()); } x.withRollUp = withRollUp; x.withCube = withCube; return x; } }
@Override public SQLSelectBuilderImpl groupBy(String expr) { SQLSelectQueryBlock queryBlock = getQueryBlock(); SQLSelectGroupByClause groupBy = queryBlock.getGroupBy(); if (groupBy == null) { groupBy = createGroupBy(); queryBlock.setGroupBy(groupBy); } SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType); groupBy.addItem(exprObj); return this; }
protected SQLSelectGroupByClause createGroupBy() { return new SQLSelectGroupByClause(); }