mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
odps sql format support lowercase option
This commit is contained in:
@@ -60,6 +60,8 @@ import com.alibaba.druid.util.JdbcUtils;
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
|
||||
public class SQLUtils {
|
||||
public static FormatOption DEFAULT_FORMAT_OPTION = new FormatOption();
|
||||
public static FormatOption DEFAULT_UPPCASE_FORMAT_OPTION = new FormatOption();
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(SQLUtils.class);
|
||||
|
||||
@@ -128,6 +130,10 @@ public class SQLUtils {
|
||||
public static String formatOdps(String sql) {
|
||||
return format(sql, JdbcUtils.ODPS);
|
||||
}
|
||||
|
||||
public static String formatOdps(String sql, FormatOption option) {
|
||||
return format(sql, JdbcUtils.ODPS, option);
|
||||
}
|
||||
|
||||
public static String formatSQLServer(String sql) {
|
||||
return format(sql, JdbcUtils.SQL_SERVER);
|
||||
@@ -223,17 +229,25 @@ public class SQLUtils {
|
||||
}
|
||||
|
||||
public static String format(String sql, String dbType) {
|
||||
return format(sql, dbType, null);
|
||||
return format(sql, dbType, null, null);
|
||||
}
|
||||
|
||||
public static String format(String sql, String dbType, FormatOption option) {
|
||||
return format(sql, dbType, null, option);
|
||||
}
|
||||
|
||||
public static String format(String sql, String dbType, List<Object> parameters) {
|
||||
return format(sql, dbType, parameters, null);
|
||||
}
|
||||
|
||||
public static String format(String sql, String dbType, List<Object> parameters) {
|
||||
public static String format(String sql, String dbType, List<Object> parameters, FormatOption option) {
|
||||
try {
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
|
||||
parser.setKeepComments(true);
|
||||
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
|
||||
return toSQLString(statementList, dbType, parameters);
|
||||
return toSQLString(statementList, dbType, parameters, option);
|
||||
} catch (ParserException ex) {
|
||||
LOG.warn("format error", ex);
|
||||
return sql;
|
||||
@@ -243,13 +257,21 @@ public class SQLUtils {
|
||||
public static String toSQLString(List<SQLStatement> statementList, String dbType) {
|
||||
return toSQLString(statementList, dbType, null);
|
||||
}
|
||||
|
||||
|
||||
public static String toSQLString(List<SQLStatement> statementList, String dbType, List<Object> parameters) {
|
||||
return toSQLString(statementList, dbType, parameters, null);
|
||||
}
|
||||
|
||||
public static String toSQLString(List<SQLStatement> statementList, String dbType, List<Object> parameters, FormatOption option) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
SQLASTOutputVisitor visitor = createFormatOutputVisitor(out, statementList, dbType);
|
||||
if (parameters != null) {
|
||||
visitor.setParameters(parameters);
|
||||
}
|
||||
|
||||
if (option != null) {
|
||||
visitor.setUppCase(option.isUppCase());
|
||||
}
|
||||
|
||||
for (int i = 0; i < statementList.size(); i++) {
|
||||
SQLStatement stmt = statementList.get(i);
|
||||
@@ -592,4 +614,25 @@ public class SQLUtils {
|
||||
queryBlock.getSelectList().add(selectItem);
|
||||
selectItem.setParent(selectItem);
|
||||
}
|
||||
|
||||
public static class FormatOption {
|
||||
|
||||
private boolean ucase = true;
|
||||
|
||||
public FormatOption() {
|
||||
|
||||
}
|
||||
|
||||
public FormatOption(boolean ucase) {
|
||||
this.ucase = ucase;
|
||||
}
|
||||
|
||||
public boolean isUppCase() {
|
||||
return ucase;
|
||||
}
|
||||
|
||||
public void setUppCase(boolean val) {
|
||||
this.ucase = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public enum SQLBinaryOperator {
|
||||
}
|
||||
|
||||
public final String name;
|
||||
public final String name_lcase;
|
||||
public final int priority;
|
||||
|
||||
SQLBinaryOperator(){
|
||||
@@ -84,6 +85,7 @@ public enum SQLBinaryOperator {
|
||||
|
||||
SQLBinaryOperator(String name, int priority){
|
||||
this.name = name;
|
||||
this.name_lcase = name.toLowerCase();
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
|
||||
@@ -121,9 +121,11 @@ public class SQLJoinTableSource extends SQLTableSourceImpl {
|
||||
CROSS_APPLY("CROSS APPLY");
|
||||
|
||||
public final String name;
|
||||
public final String name_lcase;
|
||||
|
||||
JoinType(String name){
|
||||
this.name = name;
|
||||
this.name_lcase = name.toLowerCase();
|
||||
}
|
||||
|
||||
public static String toString(JoinType joinType) {
|
||||
|
||||
@@ -20,9 +20,11 @@ public enum SQLUnionOperator {
|
||||
DISTINCT("UNION DISTINCT");
|
||||
|
||||
public final String name;
|
||||
public final String name_lcase;
|
||||
|
||||
private SQLUnionOperator(String name){
|
||||
this.name = name;
|
||||
this.name_lcase = name.toLowerCase();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
@@ -79,21 +79,21 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
public boolean visit(OdpsCreateTableStatement x) {
|
||||
if (x.isIfNotExiists()) {
|
||||
print("CREATE TABLE IF NOT EXISTS ");
|
||||
print0(ucase ? "CREATE TABLE IF NOT EXISTS " : "create table if not exists ");
|
||||
} else {
|
||||
print("CREATE TABLE ");
|
||||
print0(ucase ? "CREATE TABLE " : "create table ");
|
||||
}
|
||||
|
||||
x.getName().accept(this);
|
||||
|
||||
if (x.getLike() != null) {
|
||||
print(" LIKE ");
|
||||
print0(ucase ? " LIKE " : " like ");
|
||||
x.getLike().accept(this);
|
||||
}
|
||||
|
||||
int size = x.getTableElementList().size();
|
||||
if (size > 0) {
|
||||
print(" (");
|
||||
print0(" (");
|
||||
incrementIndent();
|
||||
println();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
@@ -101,7 +101,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
element.accept(this);
|
||||
|
||||
if (i != size - 1) {
|
||||
print(",");
|
||||
print(',');
|
||||
}
|
||||
if (this.isPrettyFormat() && element.hasAfterComment()) {
|
||||
print(' ');
|
||||
@@ -114,19 +114,19 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
}
|
||||
decrementIndent();
|
||||
println();
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.getComment() != null) {
|
||||
println();
|
||||
print("COMMENT ");
|
||||
print0(ucase ? "COMMENT " : "comment ");
|
||||
x.getComment().accept(this);
|
||||
}
|
||||
|
||||
int partitionSize = x.getPartitionColumns().size();
|
||||
if (partitionSize > 0) {
|
||||
println();
|
||||
print("PARTITIONED BY (");
|
||||
print0(ucase ? "PARTITIONED BY (" : "partitioned by (");
|
||||
incrementIndent();
|
||||
println();
|
||||
for (int i = 0; i < partitionSize; ++i) {
|
||||
@@ -147,18 +147,18 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
}
|
||||
decrementIndent();
|
||||
println();
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.getLifecycle() != null) {
|
||||
println();
|
||||
print("LIFECYCLE ");
|
||||
print0(ucase ? "LIFECYCLE " : "lifecycle ");
|
||||
x.getLifecycle().accept(this);
|
||||
}
|
||||
|
||||
if (x.getSelect() != null) {
|
||||
println();
|
||||
print("AS");
|
||||
print0(ucase ? "AS" : "as");
|
||||
println();
|
||||
x.getSelect().accept(this);
|
||||
}
|
||||
@@ -185,14 +185,14 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
@Override
|
||||
public boolean visit(OdpsInsertStatement x) {
|
||||
if (x.getFrom() != null) {
|
||||
print("FROM (");
|
||||
print0(ucase ? "FROM (" : "from (");
|
||||
incrementIndent();
|
||||
println();
|
||||
x.getFrom().getSelect().accept(this);
|
||||
decrementIndent();
|
||||
println();
|
||||
print(") ");
|
||||
print(x.getFrom().getAlias());
|
||||
print0(") ");
|
||||
print0(x.getFrom().getAlias());
|
||||
println();
|
||||
}
|
||||
|
||||
@@ -218,29 +218,29 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
println();
|
||||
}
|
||||
if (x.isOverwrite()) {
|
||||
print("INSERT OVERWRITE TABLE ");
|
||||
print0(ucase ? "INSERT OVERWRITE TABLE " : "insert overwrite table ");
|
||||
} else {
|
||||
print("INSERT INTO TABLE ");
|
||||
print0(ucase ? "INSERT INTO TABLE " : "insert into table ");
|
||||
}
|
||||
x.getTableSource().accept(this);
|
||||
|
||||
int partitions = x.getPartitions().size();
|
||||
if (partitions > 0) {
|
||||
print(" PARTITION (");
|
||||
print0(ucase ? " PARTITION (" : " partition (");
|
||||
for (int i = 0; i < partitions; ++i) {
|
||||
if (i != 0) {
|
||||
print(", ");
|
||||
print0(", ");
|
||||
}
|
||||
|
||||
SQLAssignItem assign = x.getPartitions().get(i);
|
||||
assign.getTarget().accept(this);
|
||||
|
||||
if (assign.getValue() != null) {
|
||||
print("=");
|
||||
print('=');
|
||||
assign.getValue().accept(this);
|
||||
}
|
||||
}
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
println();
|
||||
x.getQuery().accept(this);
|
||||
@@ -250,7 +250,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
public boolean visit(SQLCaseExpr x) {
|
||||
incrementIndent();
|
||||
print("CASE ");
|
||||
print0(ucase ? "CASE " : "case ");
|
||||
if (x.getValueExpr() != null) {
|
||||
x.getValueExpr().accept(this);
|
||||
println();
|
||||
@@ -263,13 +263,13 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
if (x.getElseExpr() != null) {
|
||||
println();
|
||||
print("ELSE ");
|
||||
print0(ucase ? "ELSE " : "else ");
|
||||
x.getElseExpr().accept(this);
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
println();
|
||||
print("END");
|
||||
print0(ucase ? "END" : "end");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
public boolean visit(SQLSelectGroupByClause x) {
|
||||
int itemSize = x.getItems().size();
|
||||
if (itemSize > 0) {
|
||||
print("GROUP BY ");
|
||||
print0(ucase ? "GROUP BY " : "group by ");
|
||||
incrementIndent();
|
||||
for (int i = 0; i < itemSize; ++i) {
|
||||
if (i != 0) {
|
||||
@@ -290,7 +290,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
if (x.getHaving() != null) {
|
||||
println();
|
||||
print("HAVING ");
|
||||
print0(ucase ? "HAVING " : "having ");
|
||||
x.getHaving().accept(this);
|
||||
}
|
||||
return false;
|
||||
@@ -309,7 +309,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
}
|
||||
|
||||
println();
|
||||
print(", ");
|
||||
print0(", ");
|
||||
}
|
||||
|
||||
selectItem.accept(this);
|
||||
@@ -324,17 +324,17 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSubqueryTableSource x) {
|
||||
print("(");
|
||||
print('(');
|
||||
incrementIndent();
|
||||
println();
|
||||
x.getSelect().accept(this);
|
||||
decrementIndent();
|
||||
println();
|
||||
print(")");
|
||||
print(')');
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print(' ');
|
||||
print(x.getAlias());
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -345,31 +345,31 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
x.getLeft().accept(this);
|
||||
|
||||
if (x.getJoinType() == JoinType.COMMA) {
|
||||
print(",");
|
||||
print(',');
|
||||
} else {
|
||||
println();
|
||||
printJoinType(x.getJoinType());
|
||||
}
|
||||
print(" ");
|
||||
print(' ');
|
||||
x.getRight().accept(this);
|
||||
|
||||
if (x.getCondition() != null) {
|
||||
println();
|
||||
print("ON ");
|
||||
print0(ucase ? "ON " : "on ");
|
||||
incrementIndent();
|
||||
x.getCondition().accept(this);
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
if (x.getUsing().size() > 0) {
|
||||
print(" USING (");
|
||||
print0(ucase ? " USING (" : " using (");
|
||||
printAndAccept(x.getUsing(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print(" AS ");
|
||||
print(x.getAlias());
|
||||
print0(ucase ? " AS " : " as ");
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -385,7 +385,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
x.getExpr().accept(this);
|
||||
|
||||
println();
|
||||
print("AS (");
|
||||
print0(ucase ? "AS (" : "as (");
|
||||
|
||||
int aliasSize = x.getAliasList().size();
|
||||
if (aliasSize > 5) {
|
||||
@@ -398,17 +398,17 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
if (aliasSize > 5) {
|
||||
println(",");
|
||||
} else {
|
||||
print(", ");
|
||||
print0(", ");
|
||||
}
|
||||
}
|
||||
print(x.getAliasList().get(i));
|
||||
print0(x.getAliasList().get(i));
|
||||
}
|
||||
|
||||
if (aliasSize > 5) {
|
||||
decrementIndent();
|
||||
println();
|
||||
}
|
||||
print(")");
|
||||
print(')');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -420,7 +420,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsShowPartitionsStmt x) {
|
||||
print("SHOW PARTITIONS ");
|
||||
print0(ucase ? "SHOW PARTITIONS " : "show partitions ");
|
||||
x.getTableSource().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -432,7 +432,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsShowStatisticStmt x) {
|
||||
print("SHOW STATISTIC ");
|
||||
print0(ucase ? "SHOW STATISTIC " : "show statistic ");
|
||||
x.getTableSource().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -444,20 +444,20 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsSetLabelStatement x) {
|
||||
print("SET LABEL ");
|
||||
print(x.getLabel());
|
||||
print(" TO ");
|
||||
print0(ucase ? "SET LABEL " : "set label ");
|
||||
print0(x.getLabel());
|
||||
print0(ucase ? " TO " : " to ");
|
||||
|
||||
if (x.getUser() != null) {
|
||||
print("USER ");
|
||||
print0(ucase ? "USER " : "user ");
|
||||
x.getUser().accept(this);
|
||||
} else if (x.getTable() != null) {
|
||||
print("TABLE ");
|
||||
print0(ucase ? "TABLE " : "table ");
|
||||
x.getTable().accept(this);
|
||||
if (x.getColumns().size() > 0) {
|
||||
print("(");
|
||||
print('(');
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
println();
|
||||
}
|
||||
|
||||
print("SELECT ");
|
||||
print0(ucase ? "SELECT " : "select ");
|
||||
|
||||
List<SQLHint> hints = x.getHintsDirect();
|
||||
if (hints != null) {
|
||||
@@ -485,24 +485,24 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
}
|
||||
|
||||
if (SQLSetQuantifier.ALL == x.getDistionOption()) {
|
||||
print("ALL ");
|
||||
print0(ucase ? "ALL " : "all ");
|
||||
} else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) {
|
||||
print("DISTINCT ");
|
||||
print0(ucase ? "DISTINCT " : "distinct ");
|
||||
} else if (SQLSetQuantifier.UNIQUE == x.getDistionOption()) {
|
||||
print("UNIQUE ");
|
||||
print0(ucase ? "UNIQUE " : "unique ");
|
||||
}
|
||||
|
||||
printSelectList(x.getSelectList());
|
||||
|
||||
if (x.getFrom() != null) {
|
||||
println();
|
||||
print("FROM ");
|
||||
print0(ucase ? "FROM " : "from ");
|
||||
x.getFrom().accept(this);
|
||||
}
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
print0(ucase ? "WHERE " : "where ");
|
||||
if (x.getWhere().hasBeforeComment() && isPrettyFormat()) {
|
||||
printlnComments(x.getWhere().getBeforeCommentsDirect());
|
||||
}
|
||||
@@ -527,18 +527,18 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
if (x.getDistributeBy() != null) {
|
||||
println();
|
||||
print("DISTRIBUTE BY ");
|
||||
print0(ucase ? "DISTRIBUTE BY " : "distribute by ");
|
||||
x.getDistributeBy().accept(this);
|
||||
|
||||
if (!x.getSortBy().isEmpty()) {
|
||||
print(" SORT BY ");
|
||||
print0(ucase ? " SORT BY " : " sort by ");
|
||||
printAndAccept(x.getSortBy(), ", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getLimit() != null) {
|
||||
println();
|
||||
print("LIMIT ");
|
||||
print0(ucase ? "LIMIT " : "limit ");
|
||||
x.getLimit().accept(this);
|
||||
}
|
||||
|
||||
@@ -548,7 +548,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
public boolean visit(SQLOrderBy x) {
|
||||
int itemSize = x.getItems().size();
|
||||
if (itemSize > 0) {
|
||||
print("ORDER BY ");
|
||||
print0(ucase ? "ORDER BY " : "order by ");
|
||||
incrementIndent();
|
||||
for (int i = 0; i < itemSize; ++i) {
|
||||
if (i != 0) {
|
||||
@@ -569,16 +569,16 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsAnalyzeTableStatement x) {
|
||||
print("ANALYZE TABLE ");
|
||||
print0(ucase ? "ANALYZE TABLE " : "analyze table ");
|
||||
x.getTable().accept(this);
|
||||
|
||||
if (x.getPartition().size() > 0) {
|
||||
print(" PARTITION (");
|
||||
print0(ucase ? " PARTITION (" : " partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
print(" COMPUTE STATISTICS");
|
||||
print0(ucase ? " COMPUTE STATISTICS" : " compute statistics");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -590,9 +590,9 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsAddStatisticStatement x) {
|
||||
print("ADD STATISTIC ");
|
||||
print0(ucase ? "ADD STATISTIC " : "add statistic ");
|
||||
x.getTable().accept(this);
|
||||
print(" ");
|
||||
print(' ');
|
||||
x.getStatisticClause().accept(this);
|
||||
|
||||
return false;
|
||||
@@ -605,9 +605,9 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsRemoveStatisticStatement x) {
|
||||
print("REMOVE STATISTIC ");
|
||||
print0(ucase ? "REMOVE STATISTIC " : "remove statistic ");
|
||||
x.getTable().accept(this);
|
||||
print(" ");
|
||||
print(' ');
|
||||
x.getStatisticClause().accept(this);
|
||||
|
||||
return false;
|
||||
@@ -620,7 +620,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsStatisticClause.TableCount x) {
|
||||
print("TABLE_COUNT");
|
||||
print0(ucase ? "TABLE_COUNT" : "table_count");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -631,7 +631,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsStatisticClause.ExpressionCondition x) {
|
||||
print("EXPRESSION_CONDITION ");
|
||||
print0(ucase ? "EXPRESSION_CONDITION " : "expression_condition ");
|
||||
x.getExpr().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -643,7 +643,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsStatisticClause.NullValue x) {
|
||||
print("NULL_VALUE ");
|
||||
print0(ucase ? "NULL_VALUE " : "null_value ");
|
||||
x.getColumn().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -655,7 +655,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsStatisticClause.ColumnSum x) {
|
||||
print("COLUMN_SUM ");
|
||||
print0(ucase ? "COLUMN_SUM " : "column_sum ");
|
||||
x.getColumn().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -667,7 +667,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsStatisticClause.ColumnMax x) {
|
||||
print("COLUMN_MAX ");
|
||||
print0(ucase ? "COLUMN_MAX " : "column_max ");
|
||||
x.getColumn().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -679,7 +679,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsStatisticClause.ColumnMin x) {
|
||||
print("COLUMN_MIN ");
|
||||
print0(ucase ? "COLUMN_MIN " : "column_min ");
|
||||
x.getColumn().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -691,19 +691,19 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsReadStatement x) {
|
||||
print("READ ");
|
||||
print0(ucase ? "READ " : "read ");
|
||||
x.getTable().accept(this);
|
||||
|
||||
if (x.getColumns().size() > 0) {
|
||||
print(" (");
|
||||
print0(" (");
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.getPartition().size() > 0) {
|
||||
print(" PARTITION (");
|
||||
print0(ucase ? " PARTITION (" : " partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.getRowCount() != null) {
|
||||
@@ -717,33 +717,34 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
public boolean visit(SQLMethodInvokeExpr x) {
|
||||
if (x.getOwner() != null) {
|
||||
x.getOwner().accept(this);
|
||||
print(":");
|
||||
print(':');
|
||||
}
|
||||
printFunctionName(x.getMethodName());
|
||||
print("(");
|
||||
print('(');
|
||||
printAndAccept(x.getParameters(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void printJoinType(JoinType joinType) {
|
||||
if (joinType.equals(JoinType.LEFT_OUTER_JOIN)) {
|
||||
print("LEFT OUTER JOIN");
|
||||
print0(ucase ? "LEFT OUTER JOIN" : "left outer join");
|
||||
} else if (joinType.equals(JoinType.RIGHT_OUTER_JOIN)) {
|
||||
print("RIGHT OUTER JOIN");
|
||||
print0(ucase ? "RIGHT OUTER JOIN" : "right outer join");
|
||||
} else if (joinType.equals(JoinType.FULL_OUTER_JOIN)) {
|
||||
print("FULL OUTER JOIN");
|
||||
print0(ucase ? "FULL OUTER JOIN" : "full outer join");
|
||||
} else {
|
||||
print(JoinType.toString(joinType));
|
||||
print0(ucase ? joinType.name : joinType.name_lcase);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean visit(SQLDataType x) {
|
||||
print(x.getName().toUpperCase());
|
||||
String dataTypeName = x.getName();
|
||||
print0(ucase ? dataTypeName.toUpperCase() : dataTypeName.toLowerCase());
|
||||
if (x.getArguments().size() > 0) {
|
||||
print("(");
|
||||
print('(');
|
||||
printAndAccept(x.getArguments(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -752,7 +753,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
protected void printFunctionName(String name) {
|
||||
String upperName = name.toUpperCase();
|
||||
if (builtInFunctions.contains(upperName)) {
|
||||
print(upperName);
|
||||
print(ucase ? upperName : name);
|
||||
} else {
|
||||
print(name);
|
||||
}
|
||||
@@ -765,14 +766,14 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsShowGrantsStmt x) {
|
||||
print("SHOW GRANTS");
|
||||
print0(ucase ? "SHOW GRANTS" : "show grants");
|
||||
if (x.getUser() != null) {
|
||||
print(" FOR ");
|
||||
print0(ucase ? " FOR " : " for ");
|
||||
x.getUser().accept(this);
|
||||
}
|
||||
|
||||
if (x.getObjectType() != null) {
|
||||
print(" ON TYPE ");
|
||||
print0(ucase ? " ON TYPE " : " on type ");
|
||||
x.getObjectType().accept(this);
|
||||
}
|
||||
return false;
|
||||
@@ -785,7 +786,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsListStmt x) {
|
||||
print("LIST ");
|
||||
print0(ucase ? "LIST " : "list ");
|
||||
if (x.getObject() != null) {
|
||||
x.getObject().accept(this);
|
||||
}
|
||||
@@ -799,35 +800,35 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsGrantStmt x) {
|
||||
print("GRANT ");
|
||||
print0(ucase ? "GRANT " : "grant ");
|
||||
if (x.isSuper()) {
|
||||
print("SUPER ");
|
||||
print0(ucase ? "SUPER " : "super ");
|
||||
}
|
||||
|
||||
if (x.isLabel()) {
|
||||
print("LABEL ");
|
||||
print0(ucase ? "LABEL " : "label ");
|
||||
x.getLabel().accept(this);;
|
||||
} else {
|
||||
printAndAccept(x.getPrivileges(), ", ");
|
||||
}
|
||||
|
||||
if (x.getOn() != null) {
|
||||
print(" ON ");
|
||||
print0(ucase ? " ON " : " on ");
|
||||
if (x.getObjectType() != null) {
|
||||
print(x.getObjectType().name());
|
||||
print0(ucase ? x.getObjectType().name() : x.getObjectType().name().toLowerCase());
|
||||
print(' ');
|
||||
}
|
||||
x.getOn().accept(this);
|
||||
|
||||
if (x.getColumns().size() > 0) {
|
||||
print("(");
|
||||
print('(');
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getTo() != null) {
|
||||
print(" TO ");
|
||||
print0(ucase ? " TO " : " to ");
|
||||
if (x.getSubjectType() != null) {
|
||||
print(x.getSubjectType().name());
|
||||
print(' ');
|
||||
@@ -836,7 +837,7 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
}
|
||||
|
||||
if (x.getExpire() != null) {
|
||||
print(" WITH EXP ");
|
||||
print0(ucase ? " WITH EXP " : " with exp ");
|
||||
x.getExpire().accept(this);
|
||||
}
|
||||
|
||||
@@ -850,9 +851,9 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsDescStmt x) {
|
||||
print("DESC ");
|
||||
print0(ucase ? "DESC " : "desc ");
|
||||
if (x.getObjectType() != null) {
|
||||
print(x.getObjectType().name());
|
||||
print0(x.getObjectType().name());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
@@ -861,9 +862,9 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
}
|
||||
|
||||
if (x.getPartition().size() > 0) {
|
||||
print(" PARTITION (");
|
||||
print0(ucase ? " PARTITION (" : " partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user