Skip to content

NH-3801 #436

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

Merged
merged 2 commits into from
Jul 7, 2015
Merged

NH-3801 #436

merged 2 commits into from
Jul 7, 2015

Conversation

PleasantD
Copy link
Contributor

  • Conditional statements are now generated in SQL for select clauses
  • Case statements in the select clause don't generate unexpected or implicit joins for the test expression
  • Combined the logic from SelectJoinDetector and ResultOperatorAndOrderByJoinDetector, also handles case statement join logic
  • Removed most of the changes from NH-3797 (pull request NH 3797 #432) as they are now unnecessary because the select clause now does the right thing

PleasantD added 2 commits July 7, 2015 08:50
…lauses

- Conditional statements are now generated in SQL for select clauses
- Case statements in the select clause don't generate unexpected or implicit joins for the test expression
- Combined the logic from SelectJoinDetector and ResultOperatorAndOrderByJoinDetector, also handles case statement join logic
- Removed most of the changes from NH-3797 (pull request nhibernate#432) as they are now unnecessary because the select clause now does the right thing
@PleasantD
Copy link
Contributor Author

Please include in milestone 4.1.0, and as usual, let me know if there are any problems or missing tests

@PleasantD
Copy link
Contributor Author

I think this pull request will have merge issues with #434, which I can fix once one of them has been merged.

@hazzik
Copy link
Member

hazzik commented Jul 7, 2015

@PleasantD which should be merged first?

@hazzik hazzik added this to the 4.1.0 milestone Jul 7, 2015
@hazzik
Copy link
Member

hazzik commented Jul 7, 2015

In GroupByTests.GroupByComputedValue instead of having that SQL generated

select 
    cast(case when order0_.CustomerId is null then @p0 else @p1 end as INT) as col_0_0_, 
    cast(count(*) as INT) as col_1_0_
from Orders order0_ 
group by cast(case when order0_.CustomerId is null then @p0 else @p1 end as INT) 

We should wrap case into subselect, so this will allow this query to work on some databases (SQL Server via ODBC, Firebird, Sql Server CE). What do you think?

Also there are few test failing for Oracle:

*** Tests new (failed) since last recorded results ***
FAIL - NHibernate.Test.Linq.ByMethod.GroupByTests.GroupByComputedValueInObjectArrayWithJoinInRightSideOfCase
FAIL - NHibernate.Test.Linq.JoinTests.OrderLinesWithSelectingCustomerNameInCaseShouldProduceTwoJoins
FAIL - NHibernate.Test.Linq.JoinTests.OrderLinesWithSelectingCustomerNameInCaseShouldProduceTwoJoinsAlternate

*** Tests broken since last recorded results ***
FAIL - NHibernate.Test.NHSpecificTest.NH2378.Fixture.ShortEntityCanBeQueryCorrectlyUsingLinqProvider

@PleasantD
Copy link
Contributor Author

I'd maybe recommend merging this first, then I'll fix #434. That's what I did locally to build a prerelease.

@PleasantD
Copy link
Contributor Author

Yes, ideally we need to wrap the case into a subselect.
How do I do this? Do I have to modify the QueryModel?

On Tue, Jul 7, 2015 at 2:47 PM, Alexander Zaytsev notifications@github.com
wrote:

In GroupByTests.GroupByComputedValue instead of having that SQL generated

select
cast(case when order0_.CustomerId is null then @p0 else @p1 end as INT) as col_0_0_,
cast(count(*) as INT) as col_1_0_
from Orders order0_
group by cast(case when order0_.CustomerId is null then @p0 else @p1 end as INT)

We should wrap case into subselect, so this will allow this query to work
on some databases (SQL Server via ODBC, Firebird, Sql Server CE). What do
you think?

Also there are few test failing for Oracle:

*** Tests new (failed) since last recorded results ***
FAIL -
NHibernate.Test.Linq.ByMethod.GroupByTests.GroupByComputedValueInObjectArrayWithJoinInRightSideOfCase
FAIL -
NHibernate.Test.Linq.JoinTests.OrderLinesWithSelectingCustomerNameInCaseShouldProduceTwoJoins
FAIL -
NHibernate.Test.Linq.JoinTests.OrderLinesWithSelectingCustomerNameInCaseShouldProduceTwoJoinsAlternate

*** Tests broken since last recorded results ***
FAIL -
NHibernate.Test.NHSpecificTest.NH2378.Fixture.ShortEntityCanBeQueryCorrectlyUsingLinqProvider


Reply to this email directly or view it on GitHub
#436 (comment)
.

Duncan Munro, Software Developer
duncan@pleasantsolutions.com | PleasantSolutions.com
http://www.PleasantSolutions.com
[image: Pleasant Solutions]

@hazzik
Copy link
Member

hazzik commented Jul 7, 2015

Yes, ideally we need to wrap the case into a subselect.
How do I do this? Do I have to modify the QueryModel?

I did not check the solution yet, and do not really know how exactly does it work, but, probably, in that case we shall not flatten subquery if we have case in a group by.

@hazzik
Copy link
Member

hazzik commented Jul 7, 2015

  • Combined the logic from SelectJoinDetector and ResultOperatorAndOrderByJoinDetector, also handles case statement join logic

There might be a reason why I left them separated.

@PleasantD
Copy link
Contributor Author

The oracle issue seems to be that the parameter doesn't match the charset of the DB. Although that seems to only affect the Oracle Managed build. Could that be a configuration issue?

@PleasantD
Copy link
Contributor Author

The SelectJoinDetector and ResultOperatorAndOrderByJoinDetector used to have (slightly) different logic. But as I was adding the modifications to allow the SelectJoinDetector to bypass joins for the conditional test expression, I found that the logic basically began to overlap. By unifying it you get a JoinDetector that can decide on a more granular level if it needs to create joins for entities.

@hazzik
Copy link
Member

hazzik commented Jul 7, 2015

Could that be a configuration issue?

No

@hazzik
Copy link
Member

hazzik commented Jul 7, 2015

Could that be a configuration issue?

No

The problem that case got casted to the default type of string, which is NVARCHAR2(255) in this case.

hazzik added a commit that referenced this pull request Jul 7, 2015
@hazzik hazzik merged commit 99e0bfc into nhibernate:master Jul 7, 2015
@hazzik
Copy link
Member

hazzik commented Jul 7, 2015

Merged, thanks

@hazzik
Copy link
Member

hazzik commented Jul 8, 2015

@PleasantD the oracle fails are related to https://nhibernate.jira.com/browse/NH-3787

@PleasantD PleasantD deleted the NH-3801 branch March 6, 2017 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants