Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

OGM-1472 Rework of rendering JPQL into Ignite SQL #19

Closed
wants to merge 6 commits into from

Conversation

Salauyou
Copy link
Contributor

@Salauyou Salauyou commented May 25, 2018

Instead of using built-in renderer with QueryRendererDelegate and predicate factory, let's take query tree produced by HQL parser and build Ignite SQL by recursively traversing this tree. This would allow to use in JPQL queries expressions of any complexity, not limited to simple "[not] path-operator-literal/parameter" predicates (see https://hibernate.atlassian.net/browse/OGM-750).

In this pull request, is also added support of standard JPQL functions: concat, upper, lower, trim etc.

@Salauyou Salauyou changed the title OGM-1472 Rework of JPQL query rendering OGM-1472 Rework of rendering JPQL into Ignite SQL May 25, 2018
@DavideD
Copy link
Member

DavideD commented May 25, 2018

Thanks @Salauyou. It looks very interesting. I will have a look at it soon. @schernolyas Maybe you can have a look at this as well?

@DavideD DavideD assigned DavideD and unassigned DavideD May 25, 2018
@DavideD DavideD self-requested a review May 25, 2018 08:06
@schernolyas
Copy link
Contributor

Hi @DavideD !
I will review the PR.
Thanks @Salauyou.

@DavideD
Copy link
Member

DavideD commented May 25, 2018

Thanks a lot

@Salauyou
Copy link
Contributor Author

@schernolyas As I know, you're working on supporting querying by associations (which requires joins), so I'd like you to review if it would be easy to add such support. I tried not to change IgnitePropertyHelper much, but made some changes in #getPropertyIdentifier method.

for ( Map.Entry<String, TypedGridValue> entry : queryParameters.getNamedParameters().entrySet() ) {
indexedParameters.add( entry.getValue().getValue() );
List<Object> parameterValues;
if ( !queryParameters.getPositionalParameters().isEmpty() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you remove support of named parameters. I think it is correct because Ignite SQL supports positional parameters only.

Copy link
Contributor Author

@Salauyou Salauyou May 26, 2018

Choose a reason for hiding this comment

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

Not exactly, I just changed the way how they are processeed.
When a named paremeter is met in query tree, it is rendered as positional parameter (?1, ?2,...) and its value is put into indexedParameters list, converted into required type if needed:

https://github.com/hibernate/hibernate-ogm-ignite/pull/19/files#diff-da618dd5efc808e46fc719107962e23dR133

https://github.com/hibernate/hibernate-ogm-ignite/pull/19/files/41c0ec042f6830b93e4e1dad3727478fc440c8d8#diff-91422a3fdcdd42857c788abc0e71c75eR87

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simply saying, when some :param is met in JPQL, you print it in SQL as ?n and put its value n-th in the list of values. So when SQL is executed, parameters' positions exactly match those in initial JPQL.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok @Salauyou . Thanks for comment

EntityManager em = getFactory().createEntityManager();
em.getTransaction().begin();

List<Movie> movies = em.createQuery( "from Movie where upper(title) = :title", Movie.class )
Copy link
Contributor

Choose a reason for hiding this comment

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

You use named parameter, aren't you? Where do you support it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Named params are fully supported in JPQL, especially since JPA encourages to prefer named params over positional.

https://github.com/hibernate/hibernate-ogm-ignite/pull/19/files#diff-da618dd5efc808e46fc719107962e23dR133

Copy link
Contributor

@schernolyas schernolyas left a comment

Choose a reason for hiding this comment

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

I haven't critical questions to the implementation.

@schernolyas
Copy link
Contributor

Hi @DavideD !

Could you please review the PR?

@DavideD
Copy link
Member

DavideD commented Jun 6, 2018

Thanks @Salauyou

Could you rebase this on the current master? There are some conflicts

It bothers me a bit that this dialect is using a different approach for parsing the query instead of using the AstParser provided by the hibernate HQL parser project. In theory you should have updated that project so that these changes could be used by the other dialects as well.

@Salauyou
Copy link
Contributor Author

Salauyou commented Jun 6, 2018

@DavideD Thanks for feedback. I endorse your doubts.

Regarding HQL parser -- it is still used, partially. Parsing JPQL into tree is made with built-in parser, but rendering into SQL is made by own code because of QueryRendererDelegate by-design limitations (e.g.: https://hibernate.atlassian.net/browse/OGM-750). I see it as temporary solution.

For me, HQL parser project needs development. But I'm not sure about making proposals because I don't participate in discussion, and many other sides should be involved in such discussion, at least developers of other OGM dialects. Also, I don't know whether other dialects require and can support query functionality that Ignite supports.

@DavideD
Copy link
Member

DavideD commented Jun 7, 2018

Hi @Salauyou, I would like to merge this but because I applied the other PR first now there are some conflicts. Could you rebase to the latest branch and resolve them?

Thanks

@Salauyou
Copy link
Contributor Author

Salauyou commented Jun 9, 2018

@DavideD @schernolyas Conflicts resolved, ready to merge. Sorry for late reply.

@schernolyas
Copy link
Contributor

Hi @Salauyou !
A lot of thanks! I think we can merge the PR.

Hi @DavideD !

Could you please merge the PR?

@schernolyas
Copy link
Contributor

Hi @DavideD !

Could you please review and merge the PR ?

@DavideD
Copy link
Member

DavideD commented Jul 4, 2018

@Salauyou THanks for solving the conflicts, one thing to keep in mind for the future is that in our projects we always rebase the branch on master and never have a merge commit in the log. If you are not familiar with rebasing, you can find an explanation here: https://git-scm.com/book/en/v2/Git-Branching-Rebasing

I will take care of it this time, but keep it in mind if you plan to send future PR, please.

@DavideD
Copy link
Member

DavideD commented Jul 4, 2018

The benefinit of rebasing is that the log looks much nicer and easier to read

@Salauyou
Copy link
Contributor Author

Salauyou commented Jul 4, 2018

@DavideD very useful remark, thanks. I've got it

@DavideD
Copy link
Member

DavideD commented Jul 6, 2018

Rebased and merged #19

@DavideD DavideD closed this Jul 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants