Skip to content

Commit

Permalink
feat: Update parser to handle RENAME and SYNONYM (#101)
Browse files Browse the repository at this point in the history
This only adds parsing capabilities, implementation of DIFFs is not yet
supported.
  • Loading branch information
nielm committed Apr 30, 2024
1 parent b51fa4c commit 49a08fd
Show file tree
Hide file tree
Showing 17 changed files with 404 additions and 18 deletions.
8 changes: 4 additions & 4 deletions AddingCapabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
4 changes: 4 additions & 0 deletions src/main/jjtree-sources/ddl_keywords.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ TOKEN:
| <PRIMARY: "primary">
| <REFERENCES: "references">
| <REMOTE: "remote">
| <RENAME: "rename">
| <REPLACE: "replace">
| <REVOKE: "revoke">
| <ROLE: "role">
Expand All @@ -175,6 +176,7 @@ TOKEN:
| <STORING: "storing">
| <STREAM: "stream">
| <STRING: "string">
| <SYNONYM: "synonym">
| <TABLE: "table">
| <TIMESTAMP: "timestamp">
| <TOKENLIST: "tokenlist">
Expand Down Expand Up @@ -233,6 +235,7 @@ void pseudoReservedWord() #void :
| <PRIMARY>
| <REFERENCES>
| <REMOTE>
| <RENAME>
| <REPLACE>
| <REVOKE>
| <ROLE>
Expand All @@ -247,6 +250,7 @@ void pseudoReservedWord() #void :
| <STORING>
| <STREAM>
| <STRING>
| <SYNONYM>
| <TABLE>
| <TIMESTAMP>
| <TOKENLIST>
Expand Down
Loading

0 comments on commit 49a08fd

Please sign in to comment.