Skip to content

Commit 49a08fd

Browse files
authored
feat: Update parser to handle RENAME and SYNONYM (#101)
This only adds parsing capabilities, implementation of DIFFs is not yet supported.
1 parent b51fa4c commit 49a08fd

17 files changed

Lines changed: 404 additions & 18 deletions

AddingCapabilities.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ to build the `ddl_keywords.jjt`
1515
`bazel build backend/schema/parser:ddl_keywords_jjt`
1616

1717
1) Compare and synchronize the generated `ddl_keywords.jjt`
18-
in `bazel-bin/bazel-bin/backend/schema/parser/` with
18+
in `bazel-bin//backend/schema/parser/` with
1919
the [ddl_keywords.jjt](src%2Fmain%2Fjjtree-sources%2Fddl_keywords.jjt) in
2020
this repo
2121

@@ -62,9 +62,9 @@ You do not necessarily have to do this for all classes, but for ones which
6262
add new high level parser capabilities such as top level statements, table
6363
options, etc.
6464

65-
5) Optionally, but recommended add test cases to the `DDLParserTest` class to
66-
verify that these unsupported
67-
operations fail during parsing.
65+
5) For each parser capability that has been added, add test cases to the
66+
`src/test/resources/ddlParserUnsupported.txt` file to verify that these
67+
unsupported operations fail during parsing.
6868

6969
## Run a test and fix bugs
7070

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.solutions.spannerddl.parser;
17+
18+
public class ASTadd_synonym extends SimpleNode {
19+
public ASTadd_synonym(int id) {
20+
super(id);
21+
throw new UnsupportedOperationException("Not Implemented");
22+
}
23+
24+
public ASTadd_synonym(DdlParser p, int id) {
25+
super(p, id);
26+
throw new UnsupportedOperationException("Not Implemented");
27+
}
28+
}

src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_database_statement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public ASToptions_clause getOptionsClause() {
3131
}
3232

3333
public String getDbName() {
34-
return AstTreeUtils.tokensToString((ASTdb_name) jjtGetChild(0));
34+
return AstTreeUtils.tokensToString((ASTdatabase_name) jjtGetChild(0));
3535
}
3636

3737
@Override
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.solutions.spannerddl.parser;
17+
18+
public class ASTalter_proto_bundle_statement extends SimpleNode {
19+
public ASTalter_proto_bundle_statement(int id) {
20+
super(id);
21+
throw new UnsupportedOperationException("Not Implemented");
22+
}
23+
24+
public ASTalter_proto_bundle_statement(DdlParser p, int id) {
25+
super(p, id);
26+
throw new UnsupportedOperationException("Not Implemented");
27+
}
28+
}

src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTalter_table_statement.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public String toString() {
5555
ret.append(alterTableAction.jjtGetChild(0));
5656
} else {
5757
throw new IllegalArgumentException(
58-
"Unrecognised Alter Table action in: " + AstTreeUtils.tokensToString(this));
58+
"Unrecognised Alter Table action : "
59+
+ alterTableAction.getClass()
60+
+ " in: "
61+
+ AstTreeUtils.tokensToString(this));
5962
}
6063
return ret.toString();
6164
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.solutions.spannerddl.parser;
17+
18+
public class ASTcreate_proto_bundle_statement extends SimpleNode {
19+
public ASTcreate_proto_bundle_statement(int id) {
20+
super(id);
21+
throw new UnsupportedOperationException("Not Implemented");
22+
}
23+
24+
public ASTcreate_proto_bundle_statement(DdlParser p, int id) {
25+
super(p, id);
26+
throw new UnsupportedOperationException("Not Implemented");
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.solutions.spannerddl.parser;
17+
18+
public class ASTdrop_synonym extends SimpleNode {
19+
public ASTdrop_synonym(int id) {
20+
super(id);
21+
throw new UnsupportedOperationException("Not Implemented");
22+
}
23+
24+
public ASTdrop_synonym(DdlParser p, int id) {
25+
super(p, id);
26+
throw new UnsupportedOperationException("Not Implemented");
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.solutions.spannerddl.parser;
17+
18+
public class ASTrename_op extends SimpleNode {
19+
public ASTrename_op(int id) {
20+
super(id);
21+
throw new UnsupportedOperationException("Not Implemented");
22+
}
23+
24+
public ASTrename_op(DdlParser p, int id) {
25+
super(p, id);
26+
throw new UnsupportedOperationException("Not Implemented");
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.solutions.spannerddl.parser;
17+
18+
public class ASTrename_statement extends SimpleNode {
19+
public ASTrename_statement(int id) {
20+
super(id);
21+
throw new UnsupportedOperationException("Not Implemented");
22+
}
23+
24+
public ASTrename_statement(DdlParser p, int id) {
25+
super(p, id);
26+
throw new UnsupportedOperationException("Not Implemented");
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.solutions.spannerddl.parser;
17+
18+
public class ASTrename_to extends SimpleNode {
19+
public ASTrename_to(int id) {
20+
super(id);
21+
throw new UnsupportedOperationException("Not Implemented");
22+
}
23+
24+
public ASTrename_to(DdlParser p, int id) {
25+
super(p, id);
26+
throw new UnsupportedOperationException("Not Implemented");
27+
}
28+
}

0 commit comments

Comments
 (0)