improved oracle sql parser

This commit is contained in:
高铁
2019-11-03 21:12:49 +08:00
parent 1cdd3f28eb
commit bd8e80bdd8
3 changed files with 26 additions and 5 deletions
@@ -829,7 +829,8 @@ public class OracleSelectParser extends SQLSelectParser {
tableSource.setAlias(tableAlias(true));
} else if ((tableSource.getAlias() == null) || (tableSource.getAlias().length() == 0)) {
if (lexer.token() != Token.LEFT && lexer.token() != Token.RIGHT && lexer.token() != Token.FULL) {
tableSource.setAlias(tableAlias());
final String tableAlias = tableAlias();
tableSource.setAlias(tableAlias);
}
}
@@ -866,10 +867,19 @@ public class OracleSelectParser extends SQLSelectParser {
joinType = SQLJoinTableSource.JoinType.FULL_OUTER_JOIN;
}
boolean natural = lexer.identifierEquals(FnvHash.Constants.NATURAL);
if (natural) {
lexer.nextToken();
}
if (lexer.token() == Token.INNER) {
lexer.nextToken();
accept(Token.JOIN);
joinType = SQLJoinTableSource.JoinType.INNER_JOIN;
if (natural) {
joinType = SQLJoinTableSource.JoinType.NATURAL_INNER_JOIN;
} else {
joinType = SQLJoinTableSource.JoinType.INNER_JOIN;
}
}
if (lexer.token() == Token.CROSS) {
lexer.nextToken();
@@ -879,7 +889,11 @@ public class OracleSelectParser extends SQLSelectParser {
if (lexer.token() == Token.JOIN) {
lexer.nextToken();
joinType = SQLJoinTableSource.JoinType.JOIN;
if (natural) {
joinType = SQLJoinTableSource.JoinType.NATURAL_JOIN;
} else {
joinType = SQLJoinTableSource.JoinType.JOIN;
}
}
if (lexer.token() == (Token.COMMA)) {
@@ -894,7 +908,8 @@ public class OracleSelectParser extends SQLSelectParser {
SQLTableSource right;
right = parseTableSourcePrimary();
right.setAlias(this.tableAlias());
String tableAlias = tableAlias();
right.setAlias(tableAlias);
join.setRight(right);
if (lexer.token() == Token.ON) {
@@ -918,6 +933,10 @@ public class OracleSelectParser extends SQLSelectParser {
parsePivot(join);
return parseTableSourceRest(join);
} else {
if (lexer.identifierEquals(FnvHash.Constants.PIVOT)) {
parsePivot(tableSource);
}
}
return tableSource;
@@ -135,7 +135,8 @@ public class SQLParser {
return ident;
} else if (hash == FnvHash.Constants.DISTRIBUTE
|| hash == FnvHash.Constants.SORT
|| hash == FnvHash.Constants.CLUSTER) {
|| hash == FnvHash.Constants.CLUSTER
) {
Lexer.SavePoint mark = lexer.mark();
lexer.nextToken();
if (lexer.token == Token.BY) {
@@ -693,5 +693,6 @@ public final class FnvHash {
long MODEL = fnv1a_64_lower("MODEL");
long DIMENSION = fnv1a_64_lower("DIMENSION");
long KEEP = fnv1a_64_lower("KEEP");
long PIVOT = fnv1a_64_lower("PIVOT");
}
}