From 2619ce0a6fd8bd57b75119f18e2657432ca7ec8a Mon Sep 17 00:00:00 2001 From: manticore-projects Date: Sun, 14 Aug 2022 23:29:18 +0700 Subject: [PATCH] Fixes PR #1524 support hive alter sql (#1609) * Adjust Gradle to JUnit 5 Parallel Test execution Gradle Caching Explicitly request for latest JavaCC 7.0.10 * Do not mark SpeedTest for concurrent execution * Remove unused imports * Adjust Gradle to JUnit 5 Parallel Test execution Gradle Caching Explicitly request for latest JavaCC 7.0.10 * Do not mark SpeedTest for concurrent execution * Remove unused imports * Fixes broken PR #1524 and Commit fb6e950ce0e62ebcd7a44ba9eea679da2b04b2ed --- build.gradle | 2 +- .../net/sf/jsqlparser/parser/JSqlParserCC.jjt | 304 +++++++++--------- 2 files changed, 158 insertions(+), 148 deletions(-) diff --git a/build.gradle b/build.gradle index 036eae1a5..e5e7f0282 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ dependencies { testImplementation 'org.mockito:mockito-junit-jupiter:4.+' // enforce latest version of JavaCC - javacc 'net.java.dev.javacc:javacc:7.0.11' + javacc 'net.java.dev.javacc:javacc:7.0.12' } compileJavacc { diff --git a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt index ba9a6cde8..1c34ba25e 100644 --- a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt +++ b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt @@ -5833,169 +5833,179 @@ AlterExpression AlterExpression(): { ( - (( { alterExp.setOperation(AlterOperation.ADD); } | { alterExp.setOperation(AlterOperation.ALTER); } | { alterExp.setOperation(AlterOperation.MODIFY); }) ( - LOOKAHEAD(2) ( - columnNames=ColumnsNamesList() { alterExp.setPkColumns(columnNames); } - ) constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } - [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] - | - LOOKAHEAD(2) ( - (tk= { alterExp.setUk(true); } | tk=) - sk3 = RelObjectName() - columnNames = ColumnsNamesList() - { - index = new Index().withType(tk.image).withName(sk3).withColumnsNames(columnNames); - alterExp.setIndex(index); - } - constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } - [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] - ) - | - LOOKAHEAD(3) ( - ( LOOKAHEAD(2) { alterExp.hasColumn(true); } )? - - ( - LOOKAHEAD(2) alterExpressionColumnDataType = AlterExpressionColumnDataType() { - alterExp.addColDataType(alterExpressionColumnDataType); - } - | - LOOKAHEAD(3) alterExpressionColumnDropNotNull = AlterExpressionColumnDropNotNull() { - alterExp.addColDropNotNull( alterExpressionColumnDropNotNull); - } - | - LOOKAHEAD(4) "(" - ( alterExpressionColumnDataType = AlterExpressionColumnDataType() { - if (alterExp.getOperation()== AlterOperation.ADD ){ - alterExp.addColDataType(alterExpressionColumnDataType); - } else if(alterExp.getOperation()== AlterOperation.ALTER){ - error_skipto(K_ALTER); - }else if(alterExp.getOperation()== AlterOperation.MODIFY){ - error_skipto(K_MODIFY); - } - } - (LOOKAHEAD(2) "," alterExpressionColumnDataType = AlterExpressionColumnDataType() { alterExp.addColDataType(alterExpressionColumnDataType); }) * - ) - ")" {alterExp.useBrackets(true);} - | - alterExpressionColumnDropDefault = AlterExpressionColumnDropDefault() { - alterExp.addColDropDefault( alterExpressionColumnDropDefault); - } - ) - ) - | ( - "(" alterExpressionColumnDataType = AlterExpressionColumnDataType() { alterExp.addColDataType(alterExpressionColumnDataType); } - ("," alterExpressionColumnDataType = AlterExpressionColumnDataType() { alterExp.addColDataType(alterExpressionColumnDataType); } )* ")" - ) - | - ( (( { alterExp.setUk(true); } | ) (tk= | tk=) { alterExp.setUkName(tk.image); } )? - columnNames=ColumnsNamesList() { alterExp.setUkColumns(columnNames); } - [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }]) - | - //following two choices regarding foreign keys should be merged - ( columnNames=ColumnsNamesList() { alterExp.setFkColumns(columnNames); columnNames = null; } - /* - tk= [ columnNames=ColumnsNamesList() ] - { alterExp.setFkSourceTable(tk.image); alterExp.setFkSourceColumns(columnNames); } - */ - fkTable=Table() [ columnNames=ColumnsNamesList() ] - { - alterExp.setFkSourceSchema(fkTable.getSchemaName()); - alterExp.setFkSourceTable(fkTable.getName()); - alterExp.setFkSourceColumns(columnNames); - } - - [LOOKAHEAD(2) ( (tk= | tk=) action = Action() - { alterExp.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action); } - )] - [LOOKAHEAD(2) ( (tk= | tk=) action = Action() - { alterExp.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action); } - )] + { alterExp.setOperation(AlterOperation.ADD); } + | + { alterExp.setOperation(AlterOperation.ALTER); } + | + { alterExp.setOperation(AlterOperation.MODIFY); } ) - | + ( - sk3=RelObjectName() - - ( ( tk= tk2= - columnNames=ColumnsNamesList() - { - fkIndex = new ForeignKeyIndex() - .withName(sk3) - .withType(tk.image + " " + tk2.image) - .withColumnsNames(columnNames); - columnNames = null; - } - fkTable=Table() [ columnNames=ColumnsNamesList() ] - { - fkIndex.withTable(fkTable).withReferencedColumnNames(columnNames); - alterExp.setIndex(fkIndex); - } - - [LOOKAHEAD(2) ( (tk= | tk=) action = Action() - { fkIndex.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action); } - )] - [LOOKAHEAD(2) ( (tk= | tk=) action = Action() - { fkIndex.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action); } - )] - constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + LOOKAHEAD(2) ( + columnNames=ColumnsNamesList() { alterExp.setPkColumns(columnNames); } ) + + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] | - ( tk= tk2= - columnNames=ColumnsNamesList() - { - index = new NamedConstraint() - .withName(sk3) - .withType(tk.image + " " + tk2.image) - .withColumnsNames(columnNames); - alterExp.setIndex(index); - } - constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } - [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] + LOOKAHEAD(2) ( + (tk= { alterExp.setUk(true); } | tk=) + sk3 = RelObjectName() + columnNames = ColumnsNamesList() + { + index = new Index().withType(tk.image).withName(sk3).withColumnsNames(columnNames); + alterExp.setIndex(index); + } + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] + ) + | + LOOKAHEAD(3) ( + ( LOOKAHEAD(2) { alterExp.hasColumn(true); } )? + + ( + LOOKAHEAD(4) ( + "(" { alterExp.useBrackets(true);} + alterExpressionColumnDataType = AlterExpressionColumnDataType() { + alterExp.addColDataType(alterExpressionColumnDataType); + } + ( + "," + alterExpressionColumnDataType = AlterExpressionColumnDataType() { + alterExp.addColDataType(alterExpressionColumnDataType); + } + )* + ")" + ) + | + LOOKAHEAD(2) alterExpressionColumnDataType = AlterExpressionColumnDataType() { + alterExp.addColDataType(alterExpressionColumnDataType); + } + | + LOOKAHEAD(3) alterExpressionColumnDropNotNull = AlterExpressionColumnDropNotNull() { + alterExp.addColDropNotNull( alterExpressionColumnDropNotNull); + } + | + alterExpressionColumnDropDefault = AlterExpressionColumnDropDefault() { + alterExp.addColDropDefault( alterExpressionColumnDropDefault); + } + ) ) | ( - {Expression exp = null;} ("(" exp = Expression() ")")* { - CheckConstraint checkCs = new CheckConstraint().withName(sk3).withExpression(exp); - alterExp.setIndex(checkCs); - } + "(" alterExpressionColumnDataType = AlterExpressionColumnDataType() { alterExp.addColDataType(alterExpressionColumnDataType); } + ("," alterExpressionColumnDataType = AlterExpressionColumnDataType() { alterExp.addColDataType(alterExpressionColumnDataType); } )* ")" + ) + | + ( (( { alterExp.setUk(true); } | ) (tk= | tk=) { alterExp.setUkName(tk.image); } )? + columnNames=ColumnsNamesList() { alterExp.setUkColumns(columnNames); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }]) + | + //following two choices regarding foreign keys should be merged + ( columnNames=ColumnsNamesList() { alterExp.setFkColumns(columnNames); columnNames = null; } + /* + tk= [ columnNames=ColumnsNamesList() ] + { alterExp.setFkSourceTable(tk.image); alterExp.setFkSourceColumns(columnNames); } + */ + fkTable=Table() [ columnNames=ColumnsNamesList() ] + { + alterExp.setFkSourceSchema(fkTable.getSchemaName()); + alterExp.setFkSourceTable(fkTable.getName()); + alterExp.setFkSourceColumns(columnNames); + } + + [LOOKAHEAD(2) ( (tk= | tk=) action = Action() + { alterExp.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action); } + )] + [LOOKAHEAD(2) ( (tk= | tk=) action = Action() + { alterExp.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action); } + )] ) | ( - tk= (tk2= { alterExp.setUk(true); } | tk2=)? - columnNames=ColumnsNamesList() - { - index = new NamedConstraint() + sk3=RelObjectName() + + ( ( tk= tk2= + columnNames=ColumnsNamesList() + { + fkIndex = new ForeignKeyIndex() + .withName(sk3) + .withType(tk.image + " " + tk2.image) + .withColumnsNames(columnNames); + columnNames = null; + } + fkTable=Table() [ columnNames=ColumnsNamesList() ] + { + fkIndex.withTable(fkTable).withReferencedColumnNames(columnNames); + alterExp.setIndex(fkIndex); + } + + [LOOKAHEAD(2) ( (tk= | tk=) action = Action() + { fkIndex.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action); } + )] + [LOOKAHEAD(2) ( (tk= | tk=) action = Action() + { fkIndex.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action); } + )] + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + ) + | + ( tk= tk2= + columnNames=ColumnsNamesList() + { + index = new NamedConstraint() .withName(sk3) - .withType(tk.image + (tk2!=null?" " + tk2.image:"")) - .withColumnsNames(columnNames); - alterExp.setIndex(index); - } - constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } - [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] + .withType(tk.image + " " + tk2.image) + .withColumnsNames(columnNames); + alterExp.setIndex(index); + } + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] + ) + | + ( + {Expression exp = null;} ("(" exp = Expression() ")")* { + CheckConstraint checkCs = new CheckConstraint().withName(sk3).withExpression(exp); + alterExp.setIndex(checkCs); + } + ) + | + ( + tk= (tk2= { alterExp.setUk(true); } | tk2=)? + columnNames=ColumnsNamesList() + { + index = new NamedConstraint() + .withName(sk3) + .withType(tk.image + (tk2!=null?" " + tk2.image:"")) + .withColumnsNames(columnNames); + alterExp.setIndex(index); + } + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] + ) + | + ( + tk= + columnNames=ColumnsNamesList() + { + index = new NamedConstraint() + .withName(sk3) + .withType(tk.image) + .withColumnsNames(columnNames); + alterExp.setIndex(index); + } + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + ) + ) ) | - ( - tk= - columnNames=ColumnsNamesList() - { - index = new NamedConstraint() - .withName(sk3) - .withType(tk.image) - .withColumnsNames(columnNames); - alterExp.setIndex(index); - } - constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + ( sk3=RelObjectName() + tk= { + alterExp.withColumnName(sk3).withCommentText(tk.image); + } ) - ) - ) - | - ( sk3=RelObjectName() - tk= { - alterExp.withColumnName(sk3).withCommentText(tk.image); - } - ) - ) + ) ) | (