Skip to content
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

Query :: error during groupjoin flattening for complex query with multiple joins subquery and LOJ #4749

Closed
maumar opened this issue Mar 10, 2016 · 1 comment
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Mar 10, 2016

query:

from qRoot in ctx.Questions
join qAnswered in
(
    from instance in ctx.ExamInstances
    join answered in ctx.ExamInstanceQuestions
        on instance.StudentId equals 1
    join qVersion in ctx.Questions on answered.QuestionId equals qVersion.Id
    select qVersion
)
    on qRoot.Id equals qAnswered.RootQuestionId ?? qAnswered.Id
    into AnsweredQuestions
from qAnswered in AnsweredQuestions.DefaultIfEmpty()
select qRoot;

model:

        public class MyContext : DbContext
        {
            public DbSet<Question> Questions { get; set; }
            public DbSet<ExamInstance> ExamInstances { get; set; }
            public DbSet<ExamInstanceQuestion> ExamInstanceQuestions { get; set; }
        }

        public class Question
        {
            public int Id { get; set; }
            public int? RootQuestionId { get; set; }
            public DateTime Version { get; set; }
            public Question3582 RootQuestion { get; set; }
        }

        public class ExamInstance
        {
            public int Id { get; set; }
            public int StudentId { get; set; }
        }

        public class ExamInstanceQuestion
        {
            public int Id { get; set; }
            public int ExamInstanceId { get; set; }
            public int QuestionId { get; set; }
            public int? AnswerId { get; set; }
            public ExamInstance3582 ExamInstance { get; set; }
            public Question3582 Question { get; set; }
        }

Expression that is being flatten:

IEnumerable<TransparentIdentifier<Question3582, IEnumerable<ValueBuffer>>> _GroupJoin(
    outer: IEnumerable<Question3582> _ShapedQuery(
        queryContext: Unhandled parameter: queryContext, 
        shaperCommandContext: SelectExpression: 
            SELECT [qRoot].[Id], [qRoot].[RootQuestionId], [qRoot].[Version], [t].[RootQuestionId], [t].[Id]
            FROM [Questions] AS [qRoot]
            LEFT JOIN (
                SELECT [qVersion0].*
                FROM [ExamInstances] AS [instance0]
                INNER JOIN [ExamInstanceQuestions] AS [answered0] ON [instance0].[StudentId] = 1
                INNER JOIN [Questions] AS [qVersion0] ON [answered0].[QuestionId] = [qVersion0].[Id]
            ) AS [t] ON [qRoot].[Id] = COALESCE([t].[RootQuestionId], [t].[Id])
            ORDER BY [qRoot].[Id]
        , 
        shaper: BufferedEntityShaper<Question3582>
    )
    , 
    inner: IEnumerable<ValueBuffer> _Select(
        source: IEnumerable<TransparentIdentifier<TransparentIdentifier<ValueBuffer, ValueBuffer>, ValueBuffer>> _ShapedQuery(
            queryContext: Unhandled parameter: queryContext, 
            shaperCommandContext: SelectExpression: 
                SELECT [t].[RootQuestionId], [t].[Id]
                FROM (
                    SELECT [qVersion0].*
                    FROM [ExamInstances] AS [instance0]
                    INNER JOIN [ExamInstanceQuestions] AS [answered0] ON [instance0].[StudentId] = 1
                    INNER JOIN [Questions] AS [qVersion0] ON [answered0].[QuestionId] = [qVersion0].[Id]
                ) AS [t]
            , 
            shaper: CompositeShaper`3
        )
        , 
        selector: (TransparentIdentifier<TransparentIdentifier<ValueBuffer, ValueBuffer>, ValueBuffer> t1) => t1.Inner
    )
    , 
    outerKeySelector: (Question3582 qRoot) => (Nullable<int>) qRoot.Id, 
    innerKeySelector: (ValueBuffer qAnswered) => (Nullable<int>) object qAnswered.get_Item(0) ?? (Nullable<int>) (int) object qAnswered.get_Item(1), 
    resultSelector: (Question3582 qRoot | IEnumerable<ValueBuffer> AnsweredQuestions) => TransparentIdentifier<Question3582, IEnumerable<ValueBuffer>> CreateTransparentIdentifier(
        outer: qRoot, 
        inner: AnsweredQuestions
    )
)
@rowanmiller rowanmiller added this to the 1.0.0 milestone Mar 11, 2016
@rowanmiller rowanmiller modified the milestones: 1.0.1, 1.0.0 May 10, 2016
@rowanmiller rowanmiller removed the pri0 label Jul 6, 2016
maumar added a commit that referenced this issue Jul 19, 2016
… query with multiple joins subquery and LOJ

Problem was that we tried to lift queries that we shouldn't have - i.e. GroupJoin whose ShapedQuery elements were wrapped in Select. Fix is to check the shape of the expression before performing the lifting - we do similar thing for SelectMany already.
maumar added a commit that referenced this issue Jul 20, 2016
… query with multiple joins subquery and LOJ

Problem was that we tried to lift queries that we shouldn't have - i.e. GroupJoin whose ShapedQuery elements were wrapped in Select. Fix is to check the shape of the expression before performing the lifting - we do similar thing for SelectMany already.

CR: Andrew
maumar added a commit that referenced this issue Jul 20, 2016
… query with multiple joins subquery and LOJ

Problem was that we tried to lift queries that we shouldn't have - i.e. GroupJoin whose ShapedQuery elements were wrapped in Select. Fix is to check the shape of the expression before performing the lifting - we do similar thing for SelectMany already.

CR: Andrew
maumar added a commit that referenced this issue Jul 20, 2016
… query with multiple joins subquery and LOJ

Problem was that we tried to lift queries that we shouldn't have - i.e. GroupJoin whose ShapedQuery elements were wrapped in Select. Fix is to check the shape of the expression before performing the lifting - we do similar thing for SelectMany already.

CR: Andrew
maumar added a commit that referenced this issue Jul 21, 2016
… query with multiple joins subquery and LOJ

Problem was that we tried to lift queries that we shouldn't have - i.e. GroupJoin whose ShapedQuery elements were wrapped in Select. Fix is to check the shape of the expression before performing the lifting - we do similar thing for SelectMany already.

CR: Andrew
@maumar
Copy link
Contributor Author

maumar commented Jul 22, 2016

fixed in 9a34e1d

@maumar maumar closed this as completed Jul 22, 2016
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 22, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants