Skip to content

Commit bd8e80b

Browse files
committed
improved oracle sql parser
1 parent 1cdd3f2 commit bd8e80b

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleSelectParser.java

+23-4
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@ protected SQLTableSource parseTableSourceRest(OracleSelectTableSource tableSourc
829829
tableSource.setAlias(tableAlias(true));
830830
} else if ((tableSource.getAlias() == null) || (tableSource.getAlias().length() == 0)) {
831831
if (lexer.token() != Token.LEFT && lexer.token() != Token.RIGHT && lexer.token() != Token.FULL) {
832-
tableSource.setAlias(tableAlias());
832+
final String tableAlias = tableAlias();
833+
tableSource.setAlias(tableAlias);
833834
}
834835
}
835836

@@ -866,10 +867,19 @@ protected SQLTableSource parseTableSourceRest(OracleSelectTableSource tableSourc
866867
joinType = SQLJoinTableSource.JoinType.FULL_OUTER_JOIN;
867868
}
868869

870+
boolean natural = lexer.identifierEquals(FnvHash.Constants.NATURAL);
871+
if (natural) {
872+
lexer.nextToken();
873+
}
874+
869875
if (lexer.token() == Token.INNER) {
870876
lexer.nextToken();
871877
accept(Token.JOIN);
872-
joinType = SQLJoinTableSource.JoinType.INNER_JOIN;
878+
if (natural) {
879+
joinType = SQLJoinTableSource.JoinType.NATURAL_INNER_JOIN;
880+
} else {
881+
joinType = SQLJoinTableSource.JoinType.INNER_JOIN;
882+
}
873883
}
874884
if (lexer.token() == Token.CROSS) {
875885
lexer.nextToken();
@@ -879,7 +889,11 @@ protected SQLTableSource parseTableSourceRest(OracleSelectTableSource tableSourc
879889

880890
if (lexer.token() == Token.JOIN) {
881891
lexer.nextToken();
882-
joinType = SQLJoinTableSource.JoinType.JOIN;
892+
if (natural) {
893+
joinType = SQLJoinTableSource.JoinType.NATURAL_JOIN;
894+
} else {
895+
joinType = SQLJoinTableSource.JoinType.JOIN;
896+
}
883897
}
884898

885899
if (lexer.token() == (Token.COMMA)) {
@@ -894,7 +908,8 @@ protected SQLTableSource parseTableSourceRest(OracleSelectTableSource tableSourc
894908

895909
SQLTableSource right;
896910
right = parseTableSourcePrimary();
897-
right.setAlias(this.tableAlias());
911+
String tableAlias = tableAlias();
912+
right.setAlias(tableAlias);
898913
join.setRight(right);
899914

900915
if (lexer.token() == Token.ON) {
@@ -918,6 +933,10 @@ protected SQLTableSource parseTableSourceRest(OracleSelectTableSource tableSourc
918933
parsePivot(join);
919934

920935
return parseTableSourceRest(join);
936+
} else {
937+
if (lexer.identifierEquals(FnvHash.Constants.PIVOT)) {
938+
parsePivot(tableSource);
939+
}
921940
}
922941

923942
return tableSource;

src/main/java/com/alibaba/druid/sql/parser/SQLParser.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ protected String tableAlias(boolean must) {
135135
return ident;
136136
} else if (hash == FnvHash.Constants.DISTRIBUTE
137137
|| hash == FnvHash.Constants.SORT
138-
|| hash == FnvHash.Constants.CLUSTER) {
138+
|| hash == FnvHash.Constants.CLUSTER
139+
) {
139140
Lexer.SavePoint mark = lexer.mark();
140141
lexer.nextToken();
141142
if (lexer.token == Token.BY) {

src/main/java/com/alibaba/druid/util/FnvHash.java

+1
Original file line numberDiff line numberDiff line change
@@ -693,5 +693,6 @@ public static interface Constants {
693693
long MODEL = fnv1a_64_lower("MODEL");
694694
long DIMENSION = fnv1a_64_lower("DIMENSION");
695695
long KEEP = fnv1a_64_lower("KEEP");
696+
long PIVOT = fnv1a_64_lower("PIVOT");
696697
}
697698
}

0 commit comments

Comments
 (0)