mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for mysql connection validation checker, and improved odps sql formatter
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -76,4 +77,10 @@ public class MySqlCharExpr extends SQLCharExpr implements MySqlExpr {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
output(buf);
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.alibaba.druid.sql.dialect.odps.ast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLHint;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
@@ -34,8 +35,8 @@ public class OdpsSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
|
||||
protected List<SQLHint> hints;
|
||||
|
||||
protected SQLExpr distributeBy;
|
||||
protected SQLSelectOrderByItem sortBy;
|
||||
protected SQLExpr distributeBy;
|
||||
protected List<SQLSelectOrderByItem> sortBy = new ArrayList<SQLSelectOrderByItem>(2);
|
||||
|
||||
public OdpsSelectQueryBlock(){
|
||||
|
||||
@@ -57,14 +58,10 @@ public class OdpsSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
this.distributeBy = distributeBy;
|
||||
}
|
||||
|
||||
public SQLSelectOrderByItem getSortBy() {
|
||||
public List<SQLSelectOrderByItem> getSortBy() {
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
public void setSortBy(SQLSelectOrderByItem sortBy) {
|
||||
this.sortBy = sortBy;
|
||||
}
|
||||
|
||||
public SQLExpr getLimit() {
|
||||
return limit;
|
||||
}
|
||||
@@ -138,4 +135,7 @@ public class OdpsSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return SQLUtils.toOdpsString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,15 @@ package com.alibaba.druid.sql.dialect.odps.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLArrayExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
|
||||
import com.alibaba.druid.sql.parser.EOFParserException;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
@@ -131,4 +135,23 @@ public class OdpsExprParser extends SQLExprParser {
|
||||
|
||||
return super.primaryRest(expr);
|
||||
}
|
||||
|
||||
public SQLExpr equalityRest(SQLExpr expr) {
|
||||
if (lexer.token() == Token.EQEQ) {
|
||||
SQLExpr rightExp;
|
||||
lexer.nextToken();
|
||||
try {
|
||||
rightExp = bitOr();
|
||||
} catch (EOFParserException e) {
|
||||
throw new ParserException("EOF, " + expr + "=", e);
|
||||
}
|
||||
rightExp = equalityRest(rightExp);
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp, getDbType());
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
return super.equalityRest(expr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,19 +90,28 @@ public class OdpsSelectParser extends SQLSelectParser {
|
||||
if (identifierEquals("SORT")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
SQLExpr expr = this.expr();
|
||||
|
||||
SQLSelectOrderByItem sortBy = new SQLSelectOrderByItem(expr);
|
||||
|
||||
if (lexer.token() == Token.ASC) {
|
||||
sortBy.setType(SQLOrderingSpecification.ASC);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.DESC) {
|
||||
sortBy.setType(SQLOrderingSpecification.DESC);
|
||||
lexer.nextToken();
|
||||
for (;;) {
|
||||
SQLExpr expr = this.expr();
|
||||
|
||||
SQLSelectOrderByItem sortByItem = new SQLSelectOrderByItem(expr);
|
||||
|
||||
if (lexer.token() == Token.ASC) {
|
||||
sortByItem.setType(SQLOrderingSpecification.ASC);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.DESC) {
|
||||
sortByItem.setType(SQLOrderingSpecification.DESC);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
queryBlock.getSortBy().add(sortByItem);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
queryBlock.setSortBy(sortBy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -526,9 +526,9 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
print("DISTRIBUTE BY ");
|
||||
x.getDistributeBy().accept(this);
|
||||
|
||||
if (x.getSortBy() != null) {
|
||||
if (!x.getSortBy().isEmpty()) {
|
||||
print(" SORT BY ");
|
||||
x.getSortBy().accept(this);
|
||||
printAndAccept(x.getSortBy(), ", ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user