Skip to content

CCJSqlParserUtil fails on different variable names #1462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DiegoKrupitza opened this issue Jan 22, 2022 · 6 comments · Fixed by #1382
Closed

CCJSqlParserUtil fails on different variable names #1462

DiegoKrupitza opened this issue Jan 22, 2022 · 6 comments · Fixed by #1382

Comments

@DiegoKrupitza
Copy link

Describe the bug
When I want to parse the following query

select p from Customer c join c.productOrder p where p.delayed = true

using (Select) CCJSqlParserUtil.parse(query); I get the following error:

net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "." "."
    at line 1, column 55.

Was expecting one of:

    "&"
    "::"
    ";"
    "<<"
    ">>"
    "COLLATE"
    "CONNECT"
    "EMIT"
    "GROUP"
    "HAVING"
    "START"
    "["
    "^"
    "|"
    <EOF>

	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatement(CCJSqlParserUtil.java:190)
	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:63)
	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:38)
	at org.springframework.data.jpa.repository.query.JSqlParserQueryUtils.parseSelectStatement(JSqlParserQueryUtils.java:111)
	... 71 more

Although when I try to parse the following query

select p from Customer c join c.productOrder p where p.delaye = true

everything works as expected.

It is quite stragne that only the difference between delayed and delaye makes the parsing to fail. Maybe I am getting something wrong but I think an identifier should not make such a huge difference.

To Reproduce
See above

Expected behavior
Both queries should be parse without failing.

System

  • Database you are using: No DB just calling CCJSqlParserUtil.parse(query)
  • Java Version: Azul Zulu 1.8.0_322
  • JSqlParser version: 4.3.0
@manticore-projects
Copy link
Contributor

Greetings,

DELAYED is a reserved keyword\token and needs to be quoted properly.
I have sent a PR #1382 dealing with keywords in a more comprehensive way, but it is pending approval.

@DiegoKrupitza
Copy link
Author

Thank you for the PR! I am just curious why it got detected as a keyword, since it also starts with a table alias. 🤔
Therefore it should be an identifier and not a keyword. Maybe there is within the grammar of the parser something strange?

@manticore-projects
Copy link
Contributor

The challenge is like that:

  1. you will need to define Tokens in order to trigger certain productions
  2. then you will need to define exceptions, whenever those Tokens are not meant to trigger a production -- manually and one by one

Step 1 is straight forward and everyone is fast to define a new token when a certain feature is needed and added.
But Step 2 is quite cumbersome and has to be done manually -- while nobody is really aware, what people will want to use as object names in the DB and SQL.

The next problem is performance: Step 2 often results in additional LOOKAHEAD which are not too welcome because they exponentially increase the Parser Time.

Please keep in mind: JSQLParser is a "generated parser", very flexible and agnostic to the RDBMS.
There is a good reason for the specific RDBMS to rely on "handwritten parsers".

@DiegoKrupitza
Copy link
Author

The challenge is like that:

  1. you will need to define Tokens in order to trigger certain productions
  2. then you will need to define exceptions, whenever those Tokens are not meant to trigger a production -- manually and one by one

Step 1 is straight forward and everyone is fast to define a new token when a certain feature is needed and added. But Step 2 is quite cumbersome and has to be done manually -- while nobody is really aware, what people will want to use as object names in the DB and SQL.

The next problem is performance: Step 2 often results in additional LOOKAHEAD which are not too welcome because they exponentially increase the Parser Time.

Please keep in mind: JSQLParser is a "generated parser", very flexible and agnostic to the RDBMS. There is a good reason for the specific RDBMS to rely on "handwritten parsers".

Ok thank you for clarifying!

@manticore-projects
Copy link
Contributor

Btw, the PR #1382 solves your challenge, I have just tested it.
(Solves it by semi-automatic generation of Step 2 described above, allowing all tokens where possible.)

@DiegoKrupitza
Copy link
Author

Btw, the PR #1382 solves your challenge, I have just tested it. (Solves it by semi-automatic generation of Step 2 described above, allowing all tokens where possible.)

That is perfect! 👍 Keep the great work up!

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 a pull request may close this issue.

2 participants