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

Support querying over non-primitive JSON collections #31095

Closed
wants to merge 1 commit into from

Conversation

roji
Copy link
Member

@roji roji commented Jun 16, 2023

See notes below.

Note that some tests are failing - @maumar if you'd like to take a look. I also think we should add test coverage generally - if you'd like on it that would also be great (though I'd be happy to as well).

Closes #28616

@roji roji requested a review from maumar June 16, 2023 19:19
@roji roji marked this pull request as draft June 16, 2023 19:19
Copy link
Member Author

@roji roji left a comment

Choose a reason for hiding this comment

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

One more general comment...

We added element access inside JSON for preview1; this PR adds element access also after other LINQ operators (e.g. Where(x => x.JsonColumn.SomeCollection.Where(y => y > 3).ElementAt(2))). We have two very different paths for translating this: the former works in SharedTypeEntityExpandingExpressionVisitor, the latter uses the generalized TranslateElementAtOrDefault (also used for e.g. primitive collections). This isn't necessary a problem, but we may want to think about a single translation path.

// FROM (SELECT value ->> 'a' AS a, value ->> 'b' AS b FROM json_each(<JSON column>, <path>)) AS j
// WHERE j.a = 8;

// Unfortunately, while the subquery projects the entity, our EntityProjectionExpression currently supports only bare
Copy link
Member Author

Choose a reason for hiding this comment

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

This SQLite implementation was a real PITA... It's hacky but probably "good enough" for now... We should try to make the query pipeline more flexible/powerful to improve this though.

@@ -448,4 +609,22 @@ private static SqlExpression ApplyTypeMappingOnColumn(SqlExpression expression,

_ => expression
};

private class FakeMemberInfo : MemberInfo
Copy link
Member Author

Choose a reason for hiding this comment

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

This is 🤮 🤮 🤮

The problem is that SelectExpression supports either projecting an entity (EntityProjectionExpression), or a single column, or an anonymous type with MemberInfos as the ProjectionMember keys. We should allow ProjectionMember to just be strings.

@roji roji force-pushed the NonPrimitiveJsonCollections branch from 3fb1c46 to 847dc09 Compare June 19, 2023 11:37
@roji roji force-pushed the NonPrimitiveJsonCollections branch from 847dc09 to 4aeceab Compare July 17, 2023 21:59
@roji
Copy link
Member Author

roji commented Jul 17, 2023

@maumar freshly rebased for your reviewing pleasure.


foreach (var (property, column) in jsonQueryExpression.KeyPropertyMap)
{
_identifier.Add((column, property.GetKeyValueComparer()));
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not good enough - key property map only contains the PK of owning entity. It doesn't contain the synthesized "element counter" (since there is nothing to map to), so this is not sufficient identifier.

@roji
Copy link
Member Author

roji commented Jul 31, 2023

Closing in favor of #31369 which builds on top of this.

@roji roji closed this Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support LINQ querying of non-primitive collections within JSON
2 participants