com.alibaba.druid.sql.ast.expr.SQLAggregateExpr Java Examples
The following examples show how to use
com.alibaba.druid.sql.ast.expr.SQLAggregateExpr.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemFuncGroupConcat.java From dble with GNU General Public License v2.0 | 6 votes |
@Override public SQLExpr toExpression() { SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName()); if (hasWithDistinct()) { aggregate.setOption(SQLAggregateOption.DISTINCT); } if (orders != null) { SQLOrderBy orderBy = new SQLOrderBy(); for (Order order : orders) { SQLSelectOrderByItem orderItem = new SQLSelectOrderByItem(order.getItem().toExpression()); orderItem.setType(order.getSortOrder()); orderBy.addItem(orderItem); } aggregate.putAttribute(ItemFuncKeyWord.ORDER_BY, orderBy); } for (Item arg : args) { aggregate.addArgument(arg.toExpression()); } if (seperator != null) { SQLCharExpr sep = new SQLCharExpr(seperator); aggregate.putAttribute(ItemFuncKeyWord.SEPARATOR, sep); } return aggregate; }
Example #2
Source File: JoinParser.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private String getExprFieldName(SQLAggregateExpr expr){ StringBuilder field = new StringBuilder(); for (SQLExpr item :expr.getArguments()){ field.append(item.toString()); } return expr.getMethodName()+"("+field.toString()+")"; }
Example #3
Source File: JoinParser.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private void parserFields(List<SQLSelectItem> mysqlSelectList){ //显示的字段 String key=""; String value =""; String exprfield = ""; for(SQLSelectItem item : mysqlSelectList) { if (item.getExpr() instanceof SQLAllColumnExpr) { //*解析 setField(item.toString(), item.toString()); } else { if (item.getExpr() instanceof SQLAggregateExpr) { SQLAggregateExpr expr =(SQLAggregateExpr)item.getExpr(); key = getExprFieldName(expr); setField(key, value); }else if(item.getExpr() instanceof SQLMethodInvokeExpr){ key = getMethodInvokeFieldName(item); exprfield=getFieldName(item); // value=item.getAlias(); setField(key, value,exprfield); }else { key=getFieldName(item); value=item.getAlias(); setField(key, value); } } } }
Example #4
Source File: DruidSelectParser.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private HavingCols buildGroupByHaving(SQLExpr having,Map<String, String> aliaColumns ){ if (having == null) { return null; } SQLBinaryOpExpr expr = ((SQLBinaryOpExpr) having); SQLExpr left = expr.getLeft(); SQLBinaryOperator operator = expr.getOperator(); SQLExpr right = expr.getRight(); String leftValue = null;; if (left instanceof SQLAggregateExpr) { leftValue = ((SQLAggregateExpr) left).getMethodName() + "(" + ((SQLAggregateExpr) left).getArguments().get(0) + ")"; String aggrColumnAlias = getAliaColumn(aliaColumns,leftValue); if(aggrColumnAlias != null) { // having聚合函数存在别名 expr.setLeft(new SQLIdentifierExpr(aggrColumnAlias)); leftValue = aggrColumnAlias; } } else if (left instanceof SQLIdentifierExpr) { leftValue = ((SQLIdentifierExpr) left).getName(); } String rightValue = null; if (right instanceof SQLNumericLiteralExpr) { rightValue = right.toString(); }else if(right instanceof SQLTextLiteralExpr){ rightValue = StringUtil.removeBackquote(right.toString()); } return new HavingCols(leftValue,rightValue,operator.getName()); }
Example #5
Source File: ItemSumSum.java From dble with GNU General Public License v2.0 | 5 votes |
@Override public SQLExpr toExpression() { Item arg0 = getArg(0); SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName()); aggregate.addArgument(arg0.toExpression()); if (hasWithDistinct()) { aggregate.setOption(SQLAggregateOption.DISTINCT); } return aggregate; }
Example #6
Source File: ItemSumMin.java From dble with GNU General Public License v2.0 | 5 votes |
@Override public SQLExpr toExpression() { Item arg0 = args.get(0); SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName()); aggregate.addArgument(arg0.toExpression()); return aggregate; }
Example #7
Source File: ItemSumAvg.java From dble with GNU General Public License v2.0 | 5 votes |
@Override public SQLExpr toExpression() { Item arg0 = args.get(0); SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName()); aggregate.addArgument(arg0.toExpression()); if (hasWithDistinct()) { aggregate.setOption(SQLAggregateOption.DISTINCT); } return aggregate; }
Example #8
Source File: ItemSumMax.java From dble with GNU General Public License v2.0 | 5 votes |
@Override public SQLExpr toExpression() { Item arg0 = args.get(0); SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName()); aggregate.addArgument(arg0.toExpression()); return aggregate; }
Example #9
Source File: ItemSumCount.java From dble with GNU General Public License v2.0 | 5 votes |
@Override public SQLExpr toExpression() { SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName()); if (hasWithDistinct()) { for (Item arg : args) aggregate.addArgument(arg.toExpression()); aggregate.setOption(SQLAggregateOption.DISTINCT); } else { Item arg0 = getArg(0); aggregate.addArgument(arg0.toExpression()); } return aggregate; }
Example #10
Source File: ElasticSqlExprParser.java From elasticsearch-sql with Apache License 2.0 | 5 votes |
protected SQLAggregateExpr parseAggregateExprRest(SQLAggregateExpr aggregateExpr) { if (lexer.token() == Token.ORDER) { SQLOrderBy orderBy = this.parseOrderBy(); aggregateExpr.putAttribute("ORDER BY", orderBy); } if (lexer.identifierEquals(FnvHash.Constants.SEPARATOR)) { lexer.nextToken(); SQLExpr seperator = this.primary(); seperator.setParent(aggregateExpr); aggregateExpr.putAttribute("SEPARATOR", seperator); } return aggregateExpr; }