-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Try to optionally use JSqlParser for parsing SQL #2409
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
Comments
I think having two different parsers, as you already said, might confuse users. That's why I was thinking to first introduces the new parsers and deprecate the old one. |
There are two problems with this:
|
ok this makes sense. It will take some time since right now it is exam season. |
We introduced `JSQLParser/JSqlParser` to the project so SQL can be easily parsed with out any hassle. This commit only focuses on the first two methods inside `JSqlParserQueryUtils` that is the JSqlParser counterpart of `QueryUtils`. Related tickets spring-projects#2409
This commit only focuses on sorting methods inside `JSqlParserQueryUtils` that is the JSqlParser counterpart of `QueryUtils`. Related tickets spring-projects#2409
Inside `JSqlParserQueryUtils` it is now possible to create count queries with `createCountQueryFor(...)`. Furthermore, the `getProjection(...)` method utilizes the power of the JSQlParser. Related tickets spring-projects#2409
So I now translated the most important methods from So far I can see I did not miss anything SQL related but it would be nice if someone could look over it. |
Although JSqlParser is great for parsing the SQL there are still some limitations. I think this should be included into the final documentation. Due to this "bug" I had to adjust few test cases. |
HTH |
|
|
Ok thank you! I will take a look at this later! 👍 PS: the first line of your response is still within the "quote" of my message |
I think we should clearly state somewhere that parsing errors could still happen, although the query is valid sql and that this could be due to some internals of the JSqlParser. So that the user knows that a possible short term fix could be to use a different query or use the "custom parser". |
Ok I can open a PR later but it is still a draft. |
I understand the urge. But really any piece of non-trivial software has bugs and putting disclaimers in the documentation everywhere makes it just hard to read. If you want it documented, a StackOverflow question and answer might be a better option. |
For further processing we somehow need to know if the given `StringQuery` is a native query or not, since based on that information we can decide if we use the JSqlParser for parsing or the custom parser. Related tickets spring-projects#2409
`QueryUtils` can now decide at runtime if a given query can be processed using the JSqlParser or the (default) custom parser implementation, that can parse more than just standard SQL queries. JSqlParser is selected if the query qualifies as a native query (which means it does not use any special features such as SpEL and is marked with `nativeQuery=true`). Related tickets spring-projects#2409
@schauder Nevertheless all the important methods within QueryUtils are not either using JSqlParser or the default implementation (the custom parser). The PR is actually completed but before I remove the "DRAFT" I would like to get some feedback since its quite a lot of code and I want to keep the quality high. PR can be found here: #2417 |
Related tickets spring-projects#2409
…ts`. Since all the testcases in this class will never qualify as a native query for `StringQuery` we can hardcode the `false`. Related tickets spring-projects#2409
Queries often need to be enhanced for example with an "order by" or a "where" clause and `QueryEnhancer` provides a simple inferface that handles all the enhancements. Since native queries can be parsed and processed more efficiently with JSqlParser there is a `QueryEnhancer` implementation using JSqlParser. On the other side there is a default implementation using the custom written parser `DefaultQueryEnhancer`. If a given query cannot be identified as a native one the `DefaultQueryEnhancer` is used. Related tickets spring-projects#2409
It does not make sense to allow difference queries after initialising the implementation of `QueryEnhancer` with a given `DeclaredQuery`. Therefore, the API now does not allow the usage of a different `DeclaredQuery`. Related tickets spring-projects#2409
Since all the methods within `JSqlParserQueryUtils` were only used by `JSqlParserQueryEnhancer` it makes more sense to just implement it there. Additionally we introduced the `JSqlParserUtils` class which is there for operations that a commonly used when working with JSqlParser (for example generating a count function object). Related tickets spring-projects#2409
We introduced `JSQLParser/JSqlParser` to the project so SQL can be easily parsed with out any hassle. This commit only focuses on the first two methods inside `JSqlParserQueryUtils` that is the JSqlParser counterpart of `QueryUtils`. Related tickets #2409
This PR introduces the usage of JSqlParser in spring-data-jpa for native queries. As discussed in spring-projects#2409 the current parser has few SQL related bugs. Closes spring-projects#2409
Introduce a library that makes it possible to parse native SQL statements. See #2409.
Introduce a library that makes it possible to parse native SQL statements. See #2409.
Merged to |
Introduce a library that makes it possible to parse native SQL statements. See #2409.
https://github.com/JSQLParser/JSqlParser Seems to be a decent solution to the problem of SQL parsing.
We also have a lot of issue related to SQL and JPQL parsing.
Therefore we want to:
The downside of having two parser implementations is, that it might get confusing, what is going on for the user.
Therefore we should:
The text was updated successfully, but these errors were encountered: