Skip to content

Replace jsqlparser with antlr gramma#1298

Merged
jfallows merged 26 commits intoaklivity:developfrom
akrambek:feature/antlr-gramma
Oct 22, 2024
Merged

Replace jsqlparser with antlr gramma#1298
jfallows merged 26 commits intoaklivity:developfrom
akrambek:feature/antlr-gramma

Conversation

@akrambek
Copy link
Contributor

@akrambek akrambek commented Oct 15, 2024

Fixes #1301

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general we tend to use mixed case even for acronyms in class names, so PostgreSqlLexer.g4 not PostgreSQLLexer.g4 etc.

Comment on lines +51 to +57
public void reportAmbiguity(Parser recognizer,
DFA dfa,
int startIndex,
int stopIndex,
boolean exact,
BitSet ambigAlts,
ATNConfigSet configs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting, also other methods.

public class ParserDispatchingErrorListener implements ANTLRErrorListener
{
@SuppressWarnings("checkstyle:MemberName")
Parser _parent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on here with the non-standard field naming?

String msg,
RecognitionException e)
{
var foo = new ProxyErrorListener(_parent.getErrorListeners());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foo?

Comment on lines +45 to +58
public SQLTableCommandListener.TableInfo parseTable(
String sql)
{
CharStream input = CharStreams.fromString(sql);
lexer.reset();
lexer.setInputStream(input);

tokens.setTokenSource(lexer);
parser.setTokenStream(tokens);

walker.walk(tableCommand, parser.root());

return tableCommand.tableInfo();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

import org.antlr.v4.runtime.TokenStream;

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
public abstract class PostgreSQLParserBase extends Parser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public abstract class PostgreSQLParserBase extends Parser
public abstract class PostgreSqlParserBase extends Parser

String tableName,
Map<String, String> columns,
Set<String> primaryKeys
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This close paren should be on previous line, like methods.

@akrambek akrambek marked this pull request as ready for review October 18, 2024 18:02
<include>org/junit/**</include>
<include>com/google/**</include>
<include>org/checkerframework/**</include>
<include>com/github/jsqlparser/**</include>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<artifactId>jsqlparser</artifactId>
<groupId>io.aklivity.zilla</groupId>
<artifactId>binding-pgsql</artifactId>
<scope>provided</scope>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This provided scope should be removed - similar to openapi dependency in openapi-asyncapi binding.

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;

public abstract class PostgreSqlLexerBase extends Lexer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this generated? If so then we shouldn't need to check it in.
Same for any other generated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not auto generated the gramma is written around that

https://github.com/antlr/grammars-v4/tree/master/sql/postgresql/Java


public class SqlCreateStreamListener extends PostgreSqlParserBaseListener
{
private String name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the non-final fields below the final fields, makes it easier to read the intent of the code.

* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package io.aklivity.zilla.runtime.binding.pgsql.parser.module;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why module as the subpackage name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't understand the question

Comment on lines +18 to +19
String name,
String select)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String name,
String select)
String name,
String select)


exports io.aklivity.zilla.runtime.binding.pgsql.parser;
exports io.aklivity.zilla.runtime.binding.pgsql.parser.listener;
exports io.aklivity.zilla.runtime.binding.pgsql.parser.module;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exports io.aklivity.zilla.runtime.binding.pgsql.parser.module;
exports io.aklivity.zilla.runtime.binding.pgsql.parser.model;

Perhaps you meant model?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah thanks!

.build()
.build()}
write "CREATE FUNCTION gcd(int , int)\n"
write "CREATE FUNCTION gcd(int, int)\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this changed because it didn't work with the space?
If so, then is the grammar perhaps too strict?

read "CREATE FUNCTION key_value(bytea)\n"
"RETURNS struct < key varchar , value varchar >\n"
"AS key_value\n"
"RETURNS struct<key varchar, value varchar>\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here about spaces? Checking if they are no longer permitted or not.

@jfallows jfallows merged commit 9e34ab8 into aklivity:develop Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace jsqlparser with antlr grammar

2 participants