-
Notifications
You must be signed in to change notification settings - Fork 1.5k
JSqlParserQueryEnhancer fails to parse select query with except or union operator #2578
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
Thank you for raising that issue! I identified two things that need fixing in my opinion. 1. Enhancing the JSqlParserQueryEnhancer In my first implementation I did not notice that there are more implementations of "SelectBody". In total there are 4 of them (see screenshot 1). Right now we only support one of them (PlainSelect) as you pointed out. We should definitely support all of them although for select count(SOME_COLUMN) from SOME_TABLE where REPORTING_DATE = :REPORTING_DATE
except
select SOME_COLUMN from SOME_OTHER_TABLE where REPORTING_DATE = :REPORTING_DATE 2. Make Selection of QueryEnhancer Configurable You are totally right we should make it configurable. Another prime example here is #2564 . I think that this configuration could happen per repository (maybe an annotation like |
Makes sense. |
From a general standpoint, we don't want to introduce lots of configuration options. JSqlParser is supposed to be a single option, chosen by using the If it's easy to add support for this operation @DiegoKrupitza, then fine. We can review that. But if this is going to involve "options", then I'm inclined to say this moves beyond the scope of anything we want to maintain directly inside Spring Data JPA. I realize that you have a hard-coded cast a cited earlier in this ticket. If you wish to add a defensive if-clause that checks |
Thanks, @gregturn for your insight. |
With this commit we now support `ValuesStatement` and `SetOperationList`. This means native queries that use `union` or `except` work now as expected. Furthermore we also support `with` statements in native sql queries. Related tickets spring-projects#2578
With the new PR union and except should be supported, which means a query as stated above should not face any issues anymore. Few of the QueryEnhancer methods return empty string or |
Thanks @DiegoKrupitza! |
We now support `ValuesStatement` and `SetOperationList`. This allows native queries to use `union`, `except`, and `with` statements in native SQL queries. Closes #2578.
Backported to |
Hello Team.
Upgrading to Spring Data 2.7.x and having com.github.jsqlparser in the classpath prevents the application to start if repositories use native queries.
Caused by: java.lang.ClassCastException: class net.sf.jsqlparser.statement.select.SetOperationList cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect (net.sf.jsqlparser.statement.select.SetOperationList and net.sf.jsqlparser.statement.select.PlainSelect
A query similar to
fails to parse because jsqlparser returns a SetOperationList object instead of PlainSelect
This is directly typecasted in class JSqlParserQueryEnhancer
It would be useful if we can give a flag to choose which QueryEnhancer user wants to use. There will be multiple cases where jsqlparser is on the classpath for historical project but either they won't be able to upgrade because of breaking changes in jsqlparser or they do not intend to use is as QueryEnhancer.
The text was updated successfully, but these errors were encountered: