From 24aef95b7407965dd9833caa79697e9f854011ed Mon Sep 17 00:00:00 2001 From: nielm Date: Tue, 30 Apr 2024 16:57:38 +0200 Subject: [PATCH] feat: Update parser to handle RENAME and SYNONYM This only adds parsing capabilities, implementation of DIFFs is not yet supported. --- AddingCapabilities.md | 8 +- .../spannerddl/parser/ASTadd_synonym.java | 28 +++++++ .../parser/ASTalter_database_statement.java | 2 +- .../ASTalter_proto_bundle_statement.java | 28 +++++++ .../parser/ASTalter_table_statement.java | 5 +- .../ASTcreate_proto_bundle_statement.java | 28 +++++++ .../spannerddl/parser/ASTdrop_synonym.java | 28 +++++++ .../spannerddl/parser/ASTrename_op.java | 28 +++++++ .../parser/ASTrename_statement.java | 28 +++++++ .../spannerddl/parser/ASTrename_to.java | 28 +++++++ .../spannerddl/parser/ASTsequence.java | 28 +++++++ .../spannerddl/parser/ASTsynonym.java | 28 +++++++ .../spannerddl/parser/ASTsynonym_clause.java | 28 +++++++ src/main/jjtree-sources/ddl_keywords.jjt | 4 + src/main/jjtree-sources/ddl_parser.jjt | 73 ++++++++++++++++++- .../spannerddl/parser/DDLParserTest.java | 18 ++--- src/test/resources/ddlParserUnsupported.txt | 32 ++++++++ 17 files changed, 404 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTadd_synonym.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_proto_bundle_statement.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_proto_bundle_statement.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTdrop_synonym.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_op.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_statement.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_to.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsequence.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsynonym.java create mode 100644 src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsynonym_clause.java diff --git a/AddingCapabilities.md b/AddingCapabilities.md index f992867..8466744 100644 --- a/AddingCapabilities.md +++ b/AddingCapabilities.md @@ -15,7 +15,7 @@ to build the `ddl_keywords.jjt` `bazel build backend/schema/parser:ddl_keywords_jjt` 1) Compare and synchronize the generated `ddl_keywords.jjt` -in `bazel-bin/bazel-bin/backend/schema/parser/` with +in `bazel-bin//backend/schema/parser/` with the [ddl_keywords.jjt](src%2Fmain%2Fjjtree-sources%2Fddl_keywords.jjt) in this repo @@ -62,9 +62,9 @@ You do not necessarily have to do this for all classes, but for ones which add new high level parser capabilities such as top level statements, table options, etc. -5) Optionally, but recommended add test cases to the `DDLParserTest` class to -verify that these unsupported -operations fail during parsing. +5) For each parser capability that has been added, add test cases to the +`src/test/resources/ddlParserUnsupported.txt` file to verify that these +unsupported operations fail during parsing. ## Run a test and fix bugs diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTadd_synonym.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTadd_synonym.java new file mode 100644 index 0000000..4f50005 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTadd_synonym.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTadd_synonym extends SimpleNode { + public ASTadd_synonym(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTadd_synonym(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_database_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_database_statement.java index 80d4be1..71bc1d9 100644 --- a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_database_statement.java +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_database_statement.java @@ -31,7 +31,7 @@ public ASToptions_clause getOptionsClause() { } public String getDbName() { - return AstTreeUtils.tokensToString((ASTdb_name) jjtGetChild(0)); + return AstTreeUtils.tokensToString((ASTdatabase_name) jjtGetChild(0)); } @Override diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_proto_bundle_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_proto_bundle_statement.java new file mode 100644 index 0000000..c03bb34 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_proto_bundle_statement.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTalter_proto_bundle_statement extends SimpleNode { + public ASTalter_proto_bundle_statement(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTalter_proto_bundle_statement(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_table_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_table_statement.java index 4f9c14d..6482028 100644 --- a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_table_statement.java +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_table_statement.java @@ -55,7 +55,10 @@ public String toString() { ret.append(alterTableAction.jjtGetChild(0)); } else { throw new IllegalArgumentException( - "Unrecognised Alter Table action in: " + AstTreeUtils.tokensToString(this)); + "Unrecognised Alter Table action : " + + alterTableAction.getClass() + + " in: " + + AstTreeUtils.tokensToString(this)); } return ret.toString(); } diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_proto_bundle_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_proto_bundle_statement.java new file mode 100644 index 0000000..91da270 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTcreate_proto_bundle_statement.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTcreate_proto_bundle_statement extends SimpleNode { + public ASTcreate_proto_bundle_statement(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTcreate_proto_bundle_statement(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTdrop_synonym.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTdrop_synonym.java new file mode 100644 index 0000000..0a6a106 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTdrop_synonym.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTdrop_synonym extends SimpleNode { + public ASTdrop_synonym(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTdrop_synonym(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_op.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_op.java new file mode 100644 index 0000000..64727c3 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_op.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTrename_op extends SimpleNode { + public ASTrename_op(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTrename_op(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_statement.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_statement.java new file mode 100644 index 0000000..2a5296e --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_statement.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTrename_statement extends SimpleNode { + public ASTrename_statement(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTrename_statement(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_to.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_to.java new file mode 100644 index 0000000..4052951 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTrename_to.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTrename_to extends SimpleNode { + public ASTrename_to(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTrename_to(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsequence.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsequence.java new file mode 100644 index 0000000..7f27d93 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsequence.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTsequence extends SimpleNode { + public ASTsequence(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTsequence(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsynonym.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsynonym.java new file mode 100644 index 0000000..6849875 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsynonym.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTsynonym extends SimpleNode { + public ASTsynonym(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTsynonym(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsynonym_clause.java b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsynonym_clause.java new file mode 100644 index 0000000..2cc8607 --- /dev/null +++ b/src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTsynonym_clause.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.solutions.spannerddl.parser; + +public class ASTsynonym_clause extends SimpleNode { + public ASTsynonym_clause(int id) { + super(id); + throw new UnsupportedOperationException("Not Implemented"); + } + + public ASTsynonym_clause(DdlParser p, int id) { + super(p, id); + throw new UnsupportedOperationException("Not Implemented"); + } +} diff --git a/src/main/jjtree-sources/ddl_keywords.jjt b/src/main/jjtree-sources/ddl_keywords.jjt index 47e2200..30dc93b 100755 --- a/src/main/jjtree-sources/ddl_keywords.jjt +++ b/src/main/jjtree-sources/ddl_keywords.jjt @@ -161,6 +161,7 @@ TOKEN: | | | + | | | | @@ -175,6 +176,7 @@ TOKEN: | | | + | | | | @@ -233,6 +235,7 @@ void pseudoReservedWord() #void : | | | + | | | | @@ -247,6 +250,7 @@ void pseudoReservedWord() #void : | | | + | | | | diff --git a/src/main/jjtree-sources/ddl_parser.jjt b/src/main/jjtree-sources/ddl_parser.jjt index 4ffbf8c..c298164 100644 --- a/src/main/jjtree-sources/ddl_parser.jjt +++ b/src/main/jjtree-sources/ddl_parser.jjt @@ -94,6 +94,7 @@ void ddl_statement() : | grant_statement() | revoke_statement() | analyze_statement() + | rename_statement() ) } @@ -103,6 +104,7 @@ void create_statement() #void : { ( create_database_statement() + | create_proto_bundle_statement() | create_table_statement() | create_index_statement() @@ -113,6 +115,39 @@ void create_statement() #void : ) } +void dotted_path() : +{} +{ + ((identifier() #part) (("." identifier() #part)*)) +} + +void create_proto_bundle_statement() : +{} +{ + "(" ( dotted_path() ) + ( LOOKAHEAD(2) "," dotted_path() )* + [","] // ending comma tolerated, python style + ")" +} + +void alter_proto_bundle_statement() : +{} +{ + + [ #insert "(" ( dotted_path() ) + ( LOOKAHEAD(2) "," dotted_path() )* + [","] // ending comma tolerated, python style + ")" ] + [ #update "(" ( dotted_path() ) + ( LOOKAHEAD(2) "," dotted_path() )* + [","] // ending comma tolerated, python style + ")" ] + [ #delete "(" ( dotted_path() ) + ( LOOKAHEAD(2) "," dotted_path() )* + [","] // ending comma tolerated, python style + ")" ] +} + void create_or_replace_statement() : {} { @@ -165,6 +200,7 @@ void table_element() #void : { LOOKAHEAD(3) foreign_key() | LOOKAHEAD(3) check_constraint() + | LOOKAHEAD(3) synonym_clause() | column_def() } @@ -216,6 +252,7 @@ void column_type() : | "<" column_type() ">" | ( "<" struct_fields() ">" | "<>" ) + | dotted_path() } void struct_fields() : @@ -286,6 +323,12 @@ void check_constraint() : "(" expression() #check_constraint_expression ")" } +void synonym_clause() : +{} +{ + "(" qualified_identifier() #synonym ")" +} + void table_interleave_clause() : {} { @@ -333,6 +376,13 @@ void create_index_statement() : } +void create_index_where_clause() : +{} +{ + path() + ( path() )* +} + void index_interleave_clause() : {} { @@ -570,6 +620,7 @@ void drop_statement() : {} { + ( (
#table [ if_exists() ] | #index [ if_exists() ] @@ -580,6 +631,8 @@ void drop_statement() : | #model [ if_exists() ] | #schema [ if_exists() ] ) qualified_identifier() #name + | #proto_bundle #name + ) } void alter_statement() #void : @@ -591,6 +644,7 @@ void alter_statement() #void : | alter_table_statement() | alter_change_stream_statement() | alter_index_statement() + | alter_proto_bundle_statement() | alter_sequence_statement() | alter_model_statement() | alter_schema_statement() @@ -600,7 +654,7 @@ void alter_statement() #void : void alter_database_statement() : {} { - (identifier() #db_name) options_clause() + (identifier() #database_name) options_clause() } void alter_table_statement() : @@ -609,14 +663,18 @@ void alter_table_statement() :
(qualified_identifier() #table_name) ( LOOKAHEAD(3) #drop_constraint identifier() #constraint_name | LOOKAHEAD(3) #drop_row_deletion_policy + | LOOKAHEAD(3) qualified_identifier() #drop_synonym | LOOKAHEAD(3) #drop_column [LOOKAHEAD(2) ] (identifier() #column_name) | LOOKAHEAD(1) #alter_column [LOOKAHEAD(2) ] (identifier() #name) column_def_alter() | LOOKAHEAD(2) #set_on_delete on_delete_clause() + | LOOKAHEAD(2) qualified_identifier() #rename_to + ["," qualified_identifier() #synonym] | LOOKAHEAD(4) foreign_key() | LOOKAHEAD(4) check_constraint() | LOOKAHEAD(4) row_deletion_policy_clause() #add_row_deletion_policy + | LOOKAHEAD(4) qualified_identifier() #add_synonym // ADD COLUMN could mask the above ADD clauses, so putting it at the end. | LOOKAHEAD(1) #add_column [ LOOKAHEAD(6) [ if_not_exists() ] @@ -625,6 +683,18 @@ void alter_table_statement() : ) } +void rename_op() : +{} +{ + qualified_identifier() #from_name qualified_identifier() #to_name +} + +void rename_statement() : +{} +{ +
rename_op() ( "," rename_op() )* +} + void alter_change_stream_statement() : {} { @@ -670,4 +740,3 @@ TOKEN: /* catch unexpected characters; must be last in file */ | : DEFAULT | : DEFAULT } - diff --git a/src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java b/src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java index a249ab2..0361f5e 100644 --- a/src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java +++ b/src/test/java/com/google/cloud/solutions/spannerddl/parser/DDLParserTest.java @@ -17,7 +17,7 @@ package com.google.cloud.solutions.spannerddl.parser; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.io.StringReader; import org.junit.Test; @@ -121,13 +121,14 @@ public void parseCreateIndex() throws ParseException { @Test public void parseDDLCreateTableSyntaxError() { - parseCheckingException( + parseCheckingParseException( "Create table test1 ( col1 int64 )", "Was expecting:\n\n\"primary\" ..."); } @Test public void parseDDLCreateIndexSyntaxError() { - parseCheckingException("Create index index1 on test1", "Was expecting one of:\n\n\"(\" ..."); + parseCheckingParseException( + "Create index index1 on test1", "Was expecting one of:\n\n\"(\" ..."); } @Test @@ -175,13 +176,10 @@ public void doNotNormalizeSQLExpressions() throws ParseException { assertThat(statement).isEqualTo(statement2); } - private static void parseCheckingException(String ddlStatement, String exceptionContains) { - try { - parseAndVerifyToString(ddlStatement); - fail("Expected ParseException not thrown."); - } catch (ParseException e) { - assertThat(e.getMessage()).contains(exceptionContains); - } + private static void parseCheckingParseException(String ddlStatement, String exceptionContains) { + ParseException e = + assertThrows(ParseException.class, () -> parseAndVerifyToString(ddlStatement)); + assertThat(e.getMessage()).contains(exceptionContains); } private static ASTddl_statement parse(String DDLStatement) throws ParseException { diff --git a/src/test/resources/ddlParserUnsupported.txt b/src/test/resources/ddlParserUnsupported.txt index 4ea0ca5..4a5bd44 100644 --- a/src/test/resources/ddlParserUnsupported.txt +++ b/src/test/resources/ddlParserUnsupported.txt @@ -123,4 +123,36 @@ ALTER MODEL IF EXISTS model_name SET OPTIONS ( default_batch_size = 10 ) DROP MODEL IF EXISTS model_name +== Test 16a rename table + +ALTER TABLE table_name RENAME TO new_table_name + +== Test 16b rename table with SYNONYM + +ALTER TABLE table_name RENAME TO new_table_name, ADD SYNONYM table_name + +== Test 16c drop SYNONYM + +ALTER TABLE table_name DROP SYNONYM table_name + +== Test 16d // TODO add SYNONYM + +ALTER TABLE table_name ADD SYNONYM table_name + +== Test 17a // TODO Create proto bundle + +CREATE PROTO BUNDLE (proto.path.name, other.proto.path) + +== Test 17b Alter proto bundle INSERT + +ALTER PROTO BUNDLE INSERT (proto.path.name, other.proto.path) + +== Test 17c Alter proto bundle UPDATE + +ALTER PROTO BUNDLE UPDATE (proto.path.name, other.proto.path) + +== Test 17d Alter proto bundle DELETE + +ALTER PROTO BUNDLE DELETE (proto.path.name, other.proto.path) + ==